1 | /* $NetBSD: nouveau_core_printk.c,v 1.2 2014/08/06 15:01:33 riastradh Exp $ */ |
2 | |
3 | /* |
4 | * Copyright 2012 Red Hat Inc. |
5 | * |
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
7 | * copy of this software and associated documentation files (the "Software"), |
8 | * to deal in the Software without restriction, including without limitation |
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
10 | * and/or sell copies of the Software, and to permit persons to whom the |
11 | * Software is furnished to do so, subject to the following conditions: |
12 | * |
13 | * The above copyright notice and this permission notice shall be included in |
14 | * all copies or substantial portions of the Software. |
15 | * |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
22 | * OTHER DEALINGS IN THE SOFTWARE. |
23 | * |
24 | * Authors: Ben Skeggs |
25 | */ |
26 | |
27 | #include <sys/cdefs.h> |
28 | __KERNEL_RCSID(0, "$NetBSD: nouveau_core_printk.c,v 1.2 2014/08/06 15:01:33 riastradh Exp $" ); |
29 | |
30 | #include <core/object.h> |
31 | #include <core/client.h> |
32 | #include <core/subdev.h> |
33 | #include <core/printk.h> |
34 | |
35 | int nv_info_debug_level = NV_DBG_INFO_NORMAL; |
36 | |
37 | void |
38 | nv_printk_(struct nouveau_object *object, int level, const char *fmt, ...) |
39 | { |
40 | static const char name[] = { '!', 'E', 'W', ' ', 'D', 'T', 'P', 'S' }; |
41 | const char *pfx; |
42 | char mfmt[256]; |
43 | va_list args; |
44 | |
45 | switch (level) { |
46 | case NV_DBG_FATAL: |
47 | pfx = KERN_CRIT; |
48 | break; |
49 | case NV_DBG_ERROR: |
50 | pfx = KERN_ERR; |
51 | break; |
52 | case NV_DBG_WARN: |
53 | pfx = KERN_WARNING; |
54 | break; |
55 | case NV_DBG_INFO_NORMAL: |
56 | pfx = KERN_INFO; |
57 | break; |
58 | case NV_DBG_DEBUG: |
59 | case NV_DBG_PARANOIA: |
60 | case NV_DBG_TRACE: |
61 | case NV_DBG_SPAM: |
62 | default: |
63 | pfx = KERN_DEBUG; |
64 | break; |
65 | } |
66 | |
67 | if (object && !nv_iclass(object, NV_CLIENT_CLASS)) { |
68 | struct nouveau_object *device = object; |
69 | struct nouveau_object *subdev = object; |
70 | char obuf[64]; |
71 | const char *ofmt = "" ; |
72 | |
73 | if (object->engine) { |
74 | snprintf(obuf, sizeof(obuf), "[0x%08x][%p]" , |
75 | nv_hclass(object), object); |
76 | ofmt = obuf; |
77 | subdev = object->engine; |
78 | device = object->engine; |
79 | } |
80 | |
81 | if (subdev->parent) |
82 | device = subdev->parent; |
83 | |
84 | if (level > nv_subdev(subdev)->debug) |
85 | return; |
86 | |
87 | snprintf(mfmt, sizeof(mfmt), "%snouveau %c[%8s][%s]%s %s" , pfx, |
88 | name[level], nv_subdev(subdev)->name, |
89 | nv_device(device)->name, ofmt, fmt); |
90 | } else |
91 | if (object && nv_iclass(object, NV_CLIENT_CLASS)) { |
92 | if (level > nv_client(object)->debug) |
93 | return; |
94 | |
95 | snprintf(mfmt, sizeof(mfmt), "%snouveau %c[%8s] %s" , pfx, |
96 | name[level], nv_client(object)->name, fmt); |
97 | } else { |
98 | snprintf(mfmt, sizeof(mfmt), "%snouveau: %s" , pfx, fmt); |
99 | } |
100 | |
101 | va_start(args, fmt); |
102 | vprintk(mfmt, args); |
103 | va_end(args); |
104 | } |
105 | |