blob: 655827527ecc9133f85494ef8db8662fd60090ac [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * csr1212.h -- IEEE 1212 Control and Status Register support for Linux
3 *
4 * Copyright (C) 2003 Francois Retief <fgretief@sun.ac.za>
5 * Steve Kinneberg <kinnebergsteve@acmsystems.com>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
21 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef __CSR1212_H__
31#define __CSR1212_H__
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36#define CSR1212_MALLOC(size) vmalloc((size))
37#define CSR1212_FREE(ptr) vfree(ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#define CSR1212_SUCCESS (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042/* CSR 1212 key types */
43#define CSR1212_KV_TYPE_IMMEDIATE 0
44#define CSR1212_KV_TYPE_CSR_OFFSET 1
45#define CSR1212_KV_TYPE_LEAF 2
46#define CSR1212_KV_TYPE_DIRECTORY 3
47
48
49/* CSR 1212 key ids */
50#define CSR1212_KV_ID_DESCRIPTOR 0x01
51#define CSR1212_KV_ID_BUS_DEPENDENT_INFO 0x02
52#define CSR1212_KV_ID_VENDOR 0x03
53#define CSR1212_KV_ID_HARDWARE_VERSION 0x04
54#define CSR1212_KV_ID_MODULE 0x07
55#define CSR1212_KV_ID_NODE_CAPABILITIES 0x0C
56#define CSR1212_KV_ID_EUI_64 0x0D
57#define CSR1212_KV_ID_UNIT 0x11
58#define CSR1212_KV_ID_SPECIFIER_ID 0x12
59#define CSR1212_KV_ID_VERSION 0x13
60#define CSR1212_KV_ID_DEPENDENT_INFO 0x14
61#define CSR1212_KV_ID_UNIT_LOCATION 0x15
62#define CSR1212_KV_ID_MODEL 0x17
63#define CSR1212_KV_ID_INSTANCE 0x18
64#define CSR1212_KV_ID_KEYWORD 0x19
65#define CSR1212_KV_ID_FEATURE 0x1A
66#define CSR1212_KV_ID_EXTENDED_ROM 0x1B
67#define CSR1212_KV_ID_EXTENDED_KEY_SPECIFIER_ID 0x1C
68#define CSR1212_KV_ID_EXTENDED_KEY 0x1D
69#define CSR1212_KV_ID_EXTENDED_DATA 0x1E
70#define CSR1212_KV_ID_MODIFIABLE_DESCRIPTOR 0x1F
71#define CSR1212_KV_ID_DIRECTORY_ID 0x20
72#define CSR1212_KV_ID_REVISION 0x21
73
74
75/* IEEE 1212 Address space map */
76#define CSR1212_ALL_SPACE_BASE (0x000000000000ULL)
77#define CSR1212_ALL_SPACE_SIZE (1ULL << 48)
78#define CSR1212_ALL_SPACE_END (CSR1212_ALL_SPACE_BASE + CSR1212_ALL_SPACE_SIZE)
79
80#define CSR1212_MEMORY_SPACE_BASE (0x000000000000ULL)
81#define CSR1212_MEMORY_SPACE_SIZE ((256ULL * (1ULL << 40)) - (512ULL * (1ULL << 20)))
82#define CSR1212_MEMORY_SPACE_END (CSR1212_MEMORY_SPACE_BASE + CSR1212_MEMORY_SPACE_SIZE)
83
84#define CSR1212_PRIVATE_SPACE_BASE (0xffffe0000000ULL)
85#define CSR1212_PRIVATE_SPACE_SIZE (256ULL * (1ULL << 20))
86#define CSR1212_PRIVATE_SPACE_END (CSR1212_PRIVATE_SPACE_BASE + CSR1212_PRIVATE_SPACE_SIZE)
87
88#define CSR1212_REGISTER_SPACE_BASE (0xfffff0000000ULL)
89#define CSR1212_REGISTER_SPACE_SIZE (256ULL * (1ULL << 20))
90#define CSR1212_REGISTER_SPACE_END (CSR1212_REGISTER_SPACE_BASE + CSR1212_REGISTER_SPACE_SIZE)
91
92#define CSR1212_CSR_ARCH_REG_SPACE_BASE (0xfffff0000000ULL)
93#define CSR1212_CSR_ARCH_REG_SPACE_SIZE (512)
94#define CSR1212_CSR_ARCH_REG_SPACE_END (CSR1212_CSR_ARCH_REG_SPACE_BASE + CSR1212_CSR_ARCH_REG_SPACE_SIZE)
95#define CSR1212_CSR_ARCH_REG_SPACE_OFFSET (CSR1212_CSR_ARCH_REG_SPACE_BASE - CSR1212_REGISTER_SPACE_BASE)
96
97#define CSR1212_CSR_BUS_DEP_REG_SPACE_BASE (0xfffff0000200ULL)
98#define CSR1212_CSR_BUS_DEP_REG_SPACE_SIZE (512)
99#define CSR1212_CSR_BUS_DEP_REG_SPACE_END (CSR1212_CSR_BUS_DEP_REG_SPACE_BASE + CSR1212_CSR_BUS_DEP_REG_SPACE_SIZE)
100#define CSR1212_CSR_BUS_DEP_REG_SPACE_OFFSET (CSR1212_CSR_BUS_DEP_REG_SPACE_BASE - CSR1212_REGISTER_SPACE_BASE)
101
102#define CSR1212_CONFIG_ROM_SPACE_BASE (0xfffff0000400ULL)
103#define CSR1212_CONFIG_ROM_SPACE_SIZE (1024)
104#define CSR1212_CONFIG_ROM_SPACE_END (CSR1212_CONFIG_ROM_SPACE_BASE + CSR1212_CONFIG_ROM_SPACE_SIZE)
105#define CSR1212_CONFIG_ROM_SPACE_OFFSET (CSR1212_CONFIG_ROM_SPACE_BASE - CSR1212_REGISTER_SPACE_BASE)
106
107#define CSR1212_UNITS_SPACE_BASE (0xfffff0000800ULL)
108#define CSR1212_UNITS_SPACE_SIZE ((256ULL * (1ULL << 20)) - 2048)
109#define CSR1212_UNITS_SPACE_END (CSR1212_UNITS_SPACE_BASE + CSR1212_UNITS_SPACE_SIZE)
110#define CSR1212_UNITS_SPACE_OFFSET (CSR1212_UNITS_SPACE_BASE - CSR1212_REGISTER_SPACE_BASE)
111
Ben Collins67372312006-06-12 18:15:31 -0400112#define CSR1212_INVALID_ADDR_SPACE -1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Stefan Richter6c88e472007-03-11 22:47:34 +0100114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115/* Config ROM image structures */
116struct csr1212_bus_info_block_img {
Stefan Richter982610b2007-03-11 22:49:34 +0100117 u8 length;
118 u8 crc_length;
119 u16 crc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121 /* Must be last */
Stefan Richter982610b2007-03-11 22:49:34 +0100122 u32 data[0]; /* older gcc can't handle [] which is standard */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123};
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125struct csr1212_leaf {
126 int len;
Stefan Richter982610b2007-03-11 22:49:34 +0100127 u32 *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128};
129
130struct csr1212_dentry {
131 struct csr1212_dentry *next, *prev;
132 struct csr1212_keyval *kv;
133};
134
135struct csr1212_directory {
136 int len;
137 struct csr1212_dentry *dentries_head, *dentries_tail;
138};
139
140struct csr1212_keyval {
141 struct {
Stefan Richter982610b2007-03-11 22:49:34 +0100142 u8 type;
143 u8 id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 } key;
145 union {
Stefan Richter982610b2007-03-11 22:49:34 +0100146 u32 immediate;
147 u32 csr_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 struct csr1212_leaf leaf;
149 struct csr1212_directory directory;
150 } value;
151 struct csr1212_keyval *associate;
152 int refcnt;
153
154 /* used in generating and/or parsing CSR image */
155 struct csr1212_keyval *next, *prev; /* flat list of CSR elements */
Stefan Richter982610b2007-03-11 22:49:34 +0100156 u32 offset; /* position in CSR from 0xffff f000 0000 */
157 u8 valid; /* flag indicating keyval has valid data*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158};
159
160
161struct csr1212_cache_region {
162 struct csr1212_cache_region *next, *prev;
Stefan Richter982610b2007-03-11 22:49:34 +0100163 u32 offset_start; /* inclusive */
164 u32 offset_end; /* exclusive */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165};
166
167struct csr1212_csr_rom_cache {
168 struct csr1212_csr_rom_cache *next, *prev;
169 struct csr1212_cache_region *filled_head, *filled_tail;
170 struct csr1212_keyval *layout_head, *layout_tail;
171 size_t size;
Stefan Richter982610b2007-03-11 22:49:34 +0100172 u32 offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 struct csr1212_keyval *ext_rom;
174 size_t len;
175
176 /* Must be last */
Stefan Richter982610b2007-03-11 22:49:34 +0100177 u32 data[0]; /* older gcc can't handle [] which is standard */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178};
179
180struct csr1212_csr {
181 size_t bus_info_len; /* bus info block length in bytes */
182 size_t crc_len; /* crc length in bytes */
Stefan Richter982610b2007-03-11 22:49:34 +0100183 u32 *bus_info_data; /* bus info data incl bus name and EUI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 void *private; /* private, bus specific data */
186 struct csr1212_bus_ops *ops;
187
188 struct csr1212_keyval *root_kv;
189
190 int max_rom; /* max bytes readable in Config ROM region */
191
192 /* Items below used for image parsing and generation */
193 struct csr1212_csr_rom_cache *cache_head, *cache_tail;
194};
195
196struct csr1212_bus_ops {
197 /* This function is used by csr1212 to read additional information
198 * from remote nodes when parsing a Config ROM (i.e., read Config ROM
199 * entries located in the Units Space. Must return 0 on success
200 * anything else indicates an error. */
Stefan Richter982610b2007-03-11 22:49:34 +0100201 int (*bus_read) (struct csr1212_csr *csr, u64 addr,
202 u16 length, void *buffer, void *private);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204 /* This function is used by csr1212 to allocate a region in units space
205 * in the event that Config ROM entries don't all fit in the predefined
206 * 1K region. The void *private parameter is private member of struct
207 * csr1212_csr. */
Stefan Richter982610b2007-03-11 22:49:34 +0100208 u64 (*allocate_addr_range) (u64 size, u32 alignment, void *private);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210 /* This function is used by csr1212 to release a region in units space
211 * that is no longer needed. */
Stefan Richter982610b2007-03-11 22:49:34 +0100212 void (*release_addr) (u64 addr, void *private);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214 /* This function is used by csr1212 to determine the max read request
215 * supported by a remote node when reading the ConfigROM space. Must
216 * return 0, 1, or 2 per IEEE 1212. */
Stefan Richter982610b2007-03-11 22:49:34 +0100217 int (*get_max_rom) (u32 *bus_info, void *private);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218};
219
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221/* Descriptor Leaf manipulation macros */
222#define CSR1212_DESCRIPTOR_LEAF_TYPE_SHIFT 24
223#define CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID_MASK 0xffffff
Stefan Richter982610b2007-03-11 22:49:34 +0100224#define CSR1212_DESCRIPTOR_LEAF_OVERHEAD (1 * sizeof(u32))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226#define CSR1212_DESCRIPTOR_LEAF_TYPE(kv) \
Stefan Richter7fb9add2007-03-11 22:49:05 +0100227 (be32_to_cpu((kv)->value.leaf.data[0]) >> CSR1212_DESCRIPTOR_LEAF_TYPE_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228#define CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID(kv) \
Stefan Richter7fb9add2007-03-11 22:49:05 +0100229 (be32_to_cpu((kv)->value.leaf.data[0]) & \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID_MASK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233/* Text Descriptor Leaf manipulation macros */
234#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_SHIFT 28
235#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_MASK 0xf /* after shift */
236#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_SHIFT 16
237#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_MASK 0xfff /* after shift */
238#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE_MASK 0xffff
Stefan Richter982610b2007-03-11 22:49:34 +0100239#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_OVERHEAD (1 * sizeof(u32))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH(kv) \
Stefan Richter7fb9add2007-03-11 22:49:05 +0100242 (be32_to_cpu((kv)->value.leaf.data[1]) >> \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_SHIFT)
244#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET(kv) \
Stefan Richter7fb9add2007-03-11 22:49:05 +0100245 ((be32_to_cpu((kv)->value.leaf.data[1]) >> \
246 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_SHIFT) & \
247 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_MASK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE(kv) \
Stefan Richter7fb9add2007-03-11 22:49:05 +0100249 (be32_to_cpu((kv)->value.leaf.data[1]) & \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE_MASK)
251#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA(kv) \
252 (&((kv)->value.leaf.data[2]))
253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
255/* The following 2 function are for creating new Configuration ROM trees. The
256 * first function is used for both creating local trees and parsing remote
257 * trees. The second function adds pertinent information to local Configuration
258 * ROM trees - namely data for the bus information block. */
259extern struct csr1212_csr *csr1212_create_csr(struct csr1212_bus_ops *ops,
260 size_t bus_info_size,
261 void *private);
262extern void csr1212_init_local_csr(struct csr1212_csr *csr,
Stefan Richter982610b2007-03-11 22:49:34 +0100263 const u32 *bus_info_data, int max_rom);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265
Stefan Richter6c88e472007-03-11 22:47:34 +0100266/* Destroy a Configuration ROM tree and release all memory taken by the tree. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267extern void csr1212_destroy_csr(struct csr1212_csr *csr);
268
269
270/* The following set of functions are fore creating new keyvals for placement in
271 * a Configuration ROM tree. Code that creates new keyvals with these functions
272 * must release those keyvals with csr1212_release_keyval() when they are no
273 * longer needed. */
Stefan Richter982610b2007-03-11 22:49:34 +0100274extern struct csr1212_keyval *csr1212_new_immediate(u8 key, u32 value);
275extern struct csr1212_keyval *csr1212_new_directory(u8 key);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276extern struct csr1212_keyval *csr1212_new_string_descriptor_leaf(const char *s);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
278
Stefan Richter6c88e472007-03-11 22:47:34 +0100279/* The following function manages association between keyvals. Typically,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 * Descriptor Leaves and Directories will be associated with another keyval and
281 * it is desirable for the Descriptor keyval to be place immediately after the
Stefan Richter6c88e472007-03-11 22:47:34 +0100282 * keyval that it is associated with.
283 * Take care with subsequent ROM modifications: There is no function to remove
284 * previously specified associations.
285 */
Stefan Richter64ff7122007-03-11 22:50:13 +0100286extern void csr1212_associate_keyval(struct csr1212_keyval *kv,
287 struct csr1212_keyval *associate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289
290/* The following functions manage the association of a keyval and directories.
291 * A keyval may be attached to more than one directory. */
292extern int csr1212_attach_keyval_to_directory(struct csr1212_keyval *dir,
293 struct csr1212_keyval *kv);
294extern void csr1212_detach_keyval_from_directory(struct csr1212_keyval *dir,
295 struct csr1212_keyval *kv);
296
297
Stefan Richter6c88e472007-03-11 22:47:34 +0100298/* Creates a complete Configuration ROM image in the list of caches available
299 * via csr->cache_head. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300extern int csr1212_generate_csr_image(struct csr1212_csr *csr);
301
302
303/* This is a convience function for reading a block of data out of one of the
304 * caches in the csr->cache_head list. */
Stefan Richter982610b2007-03-11 22:49:34 +0100305extern int csr1212_read(struct csr1212_csr *csr, u32 offset, void *buffer,
306 u32 len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308
309/* The following functions are in place for parsing Configuration ROM images.
310 * csr1212_parse_keyval() is used should there be a need to directly parse a
311 * Configuration ROM directly. */
312extern int csr1212_parse_keyval(struct csr1212_keyval *kv,
313 struct csr1212_csr_rom_cache *cache);
314extern int csr1212_parse_csr(struct csr1212_csr *csr);
315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317/* This function allocates a new cache which may be used for either parsing or
318 * generating sub-sets of Configuration ROM images. */
Stefan Richterc1a37f22007-03-14 00:20:53 +0100319static inline struct csr1212_csr_rom_cache *
320csr1212_rom_cache_malloc(u32 offset, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
322 struct csr1212_csr_rom_cache *cache;
323
Stefan Richter85511582005-11-07 06:31:45 -0500324 cache = CSR1212_MALLOC(sizeof(*cache) + size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 if (!cache)
326 return NULL;
327
328 cache->next = NULL;
329 cache->prev = NULL;
330 cache->filled_head = NULL;
331 cache->filled_tail = NULL;
332 cache->layout_head = NULL;
333 cache->layout_tail = NULL;
334 cache->offset = offset;
335 cache->size = size;
336 cache->ext_rom = NULL;
337
338 return cache;
339}
340
341
342/* This function ensures that a keyval contains data when referencing a keyval
343 * created by parsing a Configuration ROM. */
Stefan Richterc1a37f22007-03-14 00:20:53 +0100344extern struct csr1212_keyval *
345csr1212_get_keyval(struct csr1212_csr *csr, struct csr1212_keyval *kv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347
348/* This function increments the reference count for a keyval should there be a
349 * need for code to retain a keyval that has been parsed. */
350static inline void csr1212_keep_keyval(struct csr1212_keyval *kv)
351{
352 kv->refcnt++;
353}
354
355
356/* This function decrements a keyval's reference count and will destroy the
357 * keyval when there are no more users of the keyval. This should be called by
358 * any code that calls csr1212_keep_keyval() or any of the keyval creation
359 * routines csr1212_new_*(). */
Stefan Richterc1a37f22007-03-14 00:20:53 +0100360extern void csr1212_release_keyval(struct csr1212_keyval *kv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362
363/*
364 * This macro allows for looping over the keyval entries in a directory and it
365 * ensures that keyvals from remote ConfigROMs are parsed properly.
366 *
367 * _csr is a struct csr1212_csr * that points to CSR associated with dir.
368 * _kv is a struct csr1212_keyval * that'll point to the current keyval (loop index).
369 * _dir is a struct csr1212_keyval * that points to the directory to be looped.
370 * _pos is a struct csr1212_dentry * that is used internally for indexing.
371 *
372 * kv will be NULL upon exit of the loop.
373 */
374#define csr1212_for_each_dir_entry(_csr, _kv, _dir, _pos) \
375 for (csr1212_get_keyval((_csr), (_dir)), \
376 _pos = (_dir)->value.directory.dentries_head, \
377 _kv = (_pos) ? csr1212_get_keyval((_csr), _pos->kv) : NULL; \
378 (_kv) && (_pos); \
379 (_kv->associate == NULL) ? \
380 ((_pos = _pos->next), \
381 (_kv = (_pos) ? csr1212_get_keyval((_csr), _pos->kv) : \
382 NULL)) : \
383 (_kv = csr1212_get_keyval((_csr), _kv->associate)))
384
385
386
387#endif /* __CSR1212_H__ */