1
2#ifndef _LINUX_XBC_H
3#define _LINUX_XBC_H
4
5
6
7
8
9
10#include <linux/kernel.h>
11#include <linux/types.h>
12
13#define BOOTCONFIG_MAGIC "#BOOTCONFIG\n"
14#define BOOTCONFIG_MAGIC_LEN 12
15
16
17struct xbc_node {
18 u16 next;
19 u16 child;
20 u16 parent;
21 u16 data;
22} __attribute__ ((__packed__));
23
24#define XBC_KEY 0
25#define XBC_VALUE (1 << 15)
26
27#define XBC_DATA_MAX (XBC_VALUE - 1)
28
29#define XBC_NODE_MAX 1024
30#define XBC_KEYLEN_MAX 256
31#define XBC_DEPTH_MAX 16
32
33
34struct xbc_node * __init xbc_root_node(void);
35int __init xbc_node_index(struct xbc_node *node);
36struct xbc_node * __init xbc_node_get_parent(struct xbc_node *node);
37struct xbc_node * __init xbc_node_get_child(struct xbc_node *node);
38struct xbc_node * __init xbc_node_get_next(struct xbc_node *node);
39const char * __init xbc_node_get_data(struct xbc_node *node);
40
41
42
43
44
45
46
47static inline __init bool xbc_node_is_value(struct xbc_node *node)
48{
49 return node->data & XBC_VALUE;
50}
51
52
53
54
55
56
57
58static inline __init bool xbc_node_is_key(struct xbc_node *node)
59{
60 return !xbc_node_is_value(node);
61}
62
63
64
65
66
67
68
69static inline __init bool xbc_node_is_array(struct xbc_node *node)
70{
71 return xbc_node_is_value(node) && node->next != 0;
72}
73
74
75
76
77
78
79
80
81static inline __init bool xbc_node_is_leaf(struct xbc_node *node)
82{
83 return xbc_node_is_key(node) &&
84 (!node->child || xbc_node_is_value(xbc_node_get_child(node)));
85}
86
87
88struct xbc_node * __init xbc_node_find_child(struct xbc_node *parent,
89 const char *key);
90
91const char * __init xbc_node_find_value(struct xbc_node *parent,
92 const char *key,
93 struct xbc_node **vnode);
94
95struct xbc_node * __init xbc_node_find_next_leaf(struct xbc_node *root,
96 struct xbc_node *leaf);
97
98const char * __init xbc_node_find_next_key_value(struct xbc_node *root,
99 struct xbc_node **leaf);
100
101
102
103
104
105
106
107
108
109
110
111static inline const char * __init
112xbc_find_value(const char *key, struct xbc_node **vnode)
113{
114 return xbc_node_find_value(NULL, key, vnode);
115}
116
117
118
119
120
121
122
123
124static inline struct xbc_node * __init xbc_find_node(const char *key)
125{
126 return xbc_node_find_child(NULL, key);
127}
128
129
130
131
132
133
134
135
136
137
138#define xbc_array_for_each_value(anode, value) \
139 for (value = xbc_node_get_data(anode); anode != NULL ; \
140 anode = xbc_node_get_next(anode), \
141 value = anode ? xbc_node_get_data(anode) : NULL)
142
143
144
145
146
147
148
149
150#define xbc_node_for_each_child(parent, child) \
151 for (child = xbc_node_get_child(parent); child != NULL ; \
152 child = xbc_node_get_next(child))
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169#define xbc_node_for_each_array_value(node, key, anode, value) \
170 for (value = xbc_node_find_value(node, key, &anode); value != NULL; \
171 anode = xbc_node_get_next(anode), \
172 value = anode ? xbc_node_get_data(anode) : NULL)
173
174
175
176
177
178
179
180
181
182
183#define xbc_node_for_each_key_value(node, knode, value) \
184 for (knode = NULL, value = xbc_node_find_next_key_value(node, &knode);\
185 knode != NULL; value = xbc_node_find_next_key_value(node, &knode))
186
187
188
189
190
191
192
193
194
195#define xbc_for_each_key_value(knode, value) \
196 xbc_node_for_each_key_value(NULL, knode, value)
197
198
199int __init xbc_node_compose_key_after(struct xbc_node *root,
200 struct xbc_node *node, char *buf, size_t size);
201
202
203
204
205
206
207
208
209
210
211
212static inline int __init xbc_node_compose_key(struct xbc_node *node,
213 char *buf, size_t size)
214{
215 return xbc_node_compose_key_after(NULL, node, buf, size);
216}
217
218
219int __init xbc_init(char *buf, const char **emsg, int *epos);
220
221
222
223void __init xbc_destroy_all(void);
224
225
226void __init xbc_debug_dump(void);
227
228#endif
229