internal.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * internal.h - printk internal definitions
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <linux/percpu.h>
  18. typedef __printf(1, 0) int (*printk_func_t)(const char *fmt, va_list args);
  19. int __printf(1, 0) vprintk_default(const char *fmt, va_list args);
  20. #ifdef CONFIG_PRINTK_NMI
  21. extern raw_spinlock_t logbuf_lock;
  22. /*
  23. * printk() could not take logbuf_lock in NMI context. Instead,
  24. * it temporary stores the strings into a per-CPU buffer.
  25. * The alternative implementation is chosen transparently
  26. * via per-CPU variable.
  27. */
  28. DECLARE_PER_CPU(printk_func_t, printk_func);
  29. static inline __printf(1, 0) int vprintk_func(const char *fmt, va_list args)
  30. {
  31. return this_cpu_read(printk_func)(fmt, args);
  32. }
  33. extern atomic_t nmi_message_lost;
  34. static inline int get_nmi_message_lost(void)
  35. {
  36. return atomic_xchg(&nmi_message_lost, 0);
  37. }
  38. #else /* CONFIG_PRINTK_NMI */
  39. static inline __printf(1, 0) int vprintk_func(const char *fmt, va_list args)
  40. {
  41. return vprintk_default(fmt, args);
  42. }
  43. static inline int get_nmi_message_lost(void)
  44. {
  45. return 0;
  46. }
  47. #endif /* CONFIG_PRINTK_NMI */