1 /* 2 * Copyright (c) 2015-2019 François Tigeot <ftigeot@wolfpond.org> 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 <sys/stdarg.h> 31 #include <linux/init.h> 32 #include <linux/cache.h> 33 34 #include <sys/types.h> 35 #include <sys/systm.h> 36 37 struct va_format { 38 const char *fmt; 39 va_list *va; 40 }; 41 42 #define printk(...) kprintf(__VA_ARGS__) 43 44 #define KERN_CONT "" 45 #define KERN_EMERG "<0>" 46 #define KERN_ALERT "<1>" 47 #define KERN_CRIT "<2>" 48 #define KERN_ERR "<3>" 49 #define KERN_WARNING "<4>" 50 #define KERN_NOTICE "<5>" 51 #define KERN_INFO "<6>" 52 #define KERN_DEBUG "<7>" 53 54 #ifndef pr_fmt 55 #define pr_fmt(fmt) fmt 56 #endif 57 58 #define pr_emerg(fmt, ...) \ 59 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) 60 #define pr_alert(fmt, ...) \ 61 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) 62 #define pr_crit(fmt, ...) \ 63 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) 64 #define pr_err(fmt, ...) \ 65 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) 66 #define pr_warning(fmt, ...) \ 67 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) 68 #define pr_warn pr_warning 69 #define pr_notice(fmt, ...) \ 70 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) 71 #define pr_info(fmt, ...) \ 72 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) 73 #define pr_cont(fmt, ...) \ 74 printk(KERN_CONT fmt, ##__VA_ARGS__) 75 76 /* pr_devel() should produce zero code unless DEBUG is defined */ 77 #ifdef DEBUG 78 #define pr_devel(fmt, ...) \ 79 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 80 #else 81 #define pr_devel(fmt, ...) \ 82 ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; }) 83 #endif 84 85 #define pr_debug(fmt, ...) \ 86 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 87 88 /* 89 * Print a one-time message (analogous to WARN_ONCE() et al): 90 */ 91 #define printk_once(x...) \ 92 ({ \ 93 static bool __print_once; \ 94 \ 95 if (!__print_once) { \ 96 __print_once = true; \ 97 printk(x); \ 98 } \ 99 }) 100 101 #define pr_info_once(fmt, ...) do { \ 102 static bool __printed_once; \ 103 \ 104 if (!__printed_once) { \ 105 __printed_once = true; \ 106 kprintf(fmt, ##__VA_ARGS__); \ 107 } \ 108 } while (0) 109 110 enum { 111 DUMP_PREFIX_NONE, 112 DUMP_PREFIX_ADDRESS, 113 DUMP_PREFIX_OFFSET 114 }; 115 116 static inline void 117 print_hex_dump(const char *level, const char *prefix_str, int prefix_type, 118 int rowsize, int groupsize, const void *buf, size_t len, bool ascii) 119 { 120 int flags; 121 122 flags = rowsize; 123 if (prefix_type != DUMP_PREFIX_OFFSET) 124 flags |= HD_OMIT_COUNT; 125 if (!ascii) 126 flags |= HD_OMIT_CHARS; 127 128 hexdump(buf, len, prefix_str, flags); 129 } 130 131 #endif /* _LINUX_PRINTK_H_ */ 132