1 /* 2 * Copyright (c) 2015-2017 François Tigeot 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice unmodified, this list of conditions, and the following 10 * disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #ifndef _LINUX_PRINTK_H_ 28 #define _LINUX_PRINTK_H_ 29 30 #include <linux/cache.h> 31 32 #include <sys/types.h> 33 #include <sys/systm.h> 34 35 struct va_format { 36 const char *fmt; 37 __va_list *va; 38 }; 39 40 #define printk(X...) kprintf(X) 41 42 #define KERN_CONT "" 43 #define KERN_EMERG "<0>" 44 #define KERN_ALERT "<1>" 45 #define KERN_CRIT "<2>" 46 #define KERN_ERR "<3>" 47 #define KERN_WARNING "<4>" 48 #define KERN_NOTICE "<5>" 49 #define KERN_INFO "<6>" 50 #define KERN_DEBUG "<7>" 51 52 #ifndef pr_fmt 53 #define pr_fmt(fmt) fmt 54 #endif 55 56 #define pr_emerg(fmt, ...) \ 57 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) 58 #define pr_alert(fmt, ...) \ 59 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) 60 #define pr_crit(fmt, ...) \ 61 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) 62 #define pr_err(fmt, ...) \ 63 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) 64 #define pr_warning(fmt, ...) \ 65 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) 66 #define pr_warn pr_warning 67 #define pr_notice(fmt, ...) \ 68 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) 69 #define pr_info(fmt, ...) \ 70 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) 71 #define pr_cont(fmt, ...) \ 72 printk(KERN_CONT fmt, ##__VA_ARGS__) 73 74 /* pr_devel() should produce zero code unless DEBUG is defined */ 75 #ifdef DEBUG 76 #define pr_devel(fmt, ...) \ 77 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 78 #else 79 #define pr_devel(fmt, ...) \ 80 ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; }) 81 #endif 82 83 #define pr_debug(fmt, ...) printk(KERN_DEBUG # fmt, ##__VA_ARGS__) 84 85 /* 86 * Print a one-time message (analogous to WARN_ONCE() et al): 87 */ 88 #define printk_once(x...) \ 89 ({ \ 90 static bool __print_once; \ 91 \ 92 if (!__print_once) { \ 93 __print_once = true; \ 94 printk(x); \ 95 } \ 96 }) 97 98 #define pr_info_once(fmt, ...) do { \ 99 static bool __printed_once; \ 100 \ 101 if (!__printed_once) { \ 102 __printed_once = true; \ 103 kprintf(fmt, ##__VA_ARGS__); \ 104 } \ 105 } while (0) 106 107 enum { 108 DUMP_PREFIX_NONE, 109 DUMP_PREFIX_ADDRESS, 110 DUMP_PREFIX_OFFSET 111 }; 112 113 #endif /* _LINUX_PRINTK_H_ */ 114