This source file includes following definitions.
- nvkm_stropt
- nvkm_boolopt
- nvkm_longopt
- nvkm_dbgopt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #include <core/option.h>
25 #include <core/debug.h>
26
27 const char *
28 nvkm_stropt(const char *optstr, const char *opt, int *arglen)
29 {
30 while (optstr && *optstr != '\0') {
31 int len = strcspn(optstr, ",=");
32 switch (optstr[len]) {
33 case '=':
34 if (!strncasecmpz(optstr, opt, len)) {
35 optstr += len + 1;
36 *arglen = strcspn(optstr, ",=");
37 return *arglen ? optstr : NULL;
38 }
39 optstr++;
40 break;
41 case ',':
42 optstr++;
43 break;
44 default:
45 break;
46 }
47 optstr += len;
48 }
49
50 return NULL;
51 }
52
53 bool
54 nvkm_boolopt(const char *optstr, const char *opt, bool value)
55 {
56 int arglen;
57
58 optstr = nvkm_stropt(optstr, opt, &arglen);
59 if (optstr) {
60 if (!strncasecmpz(optstr, "0", arglen) ||
61 !strncasecmpz(optstr, "no", arglen) ||
62 !strncasecmpz(optstr, "off", arglen) ||
63 !strncasecmpz(optstr, "false", arglen))
64 value = false;
65 else
66 if (!strncasecmpz(optstr, "1", arglen) ||
67 !strncasecmpz(optstr, "yes", arglen) ||
68 !strncasecmpz(optstr, "on", arglen) ||
69 !strncasecmpz(optstr, "true", arglen))
70 value = true;
71 }
72
73 return value;
74 }
75
76 long
77 nvkm_longopt(const char *optstr, const char *opt, long value)
78 {
79 long result = value;
80 int arglen;
81 char *s;
82
83 optstr = nvkm_stropt(optstr, opt, &arglen);
84 if (optstr && (s = kstrndup(optstr, arglen, GFP_KERNEL))) {
85 int ret = kstrtol(s, 0, &value);
86 if (ret == 0)
87 result = value;
88 kfree(s);
89 }
90
91 return result;
92 }
93
94 int
95 nvkm_dbgopt(const char *optstr, const char *sub)
96 {
97 int mode = 1, level = CONFIG_NOUVEAU_DEBUG_DEFAULT;
98
99 while (optstr) {
100 int len = strcspn(optstr, ",=");
101 switch (optstr[len]) {
102 case '=':
103 if (strncasecmpz(optstr, sub, len))
104 mode = 0;
105 optstr++;
106 break;
107 default:
108 if (mode) {
109 if (!strncasecmpz(optstr, "fatal", len))
110 level = NV_DBG_FATAL;
111 else if (!strncasecmpz(optstr, "error", len))
112 level = NV_DBG_ERROR;
113 else if (!strncasecmpz(optstr, "warn", len))
114 level = NV_DBG_WARN;
115 else if (!strncasecmpz(optstr, "info", len))
116 level = NV_DBG_INFO;
117 else if (!strncasecmpz(optstr, "debug", len))
118 level = NV_DBG_DEBUG;
119 else if (!strncasecmpz(optstr, "trace", len))
120 level = NV_DBG_TRACE;
121 else if (!strncasecmpz(optstr, "paranoia", len))
122 level = NV_DBG_PARANOIA;
123 else if (!strncasecmpz(optstr, "spam", len))
124 level = NV_DBG_SPAM;
125 }
126
127 if (optstr[len] != '\0') {
128 optstr++;
129 mode = 1;
130 break;
131 }
132
133 return level;
134 }
135 optstr += len;
136 }
137
138 return level;
139 }