aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ieee1394/csr1212.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ieee1394/csr1212.h')
-rw-r--r--drivers/ieee1394/csr1212.h483
1 files changed, 71 insertions, 412 deletions
diff --git a/drivers/ieee1394/csr1212.h b/drivers/ieee1394/csr1212.h
index 17ddd72dee4e..df909ce66304 100644
--- a/drivers/ieee1394/csr1212.h
+++ b/drivers/ieee1394/csr1212.h
@@ -30,94 +30,13 @@
30#ifndef __CSR1212_H__ 30#ifndef __CSR1212_H__
31#define __CSR1212_H__ 31#define __CSR1212_H__
32 32
33
34/* Compatibility layer */
35#ifdef __KERNEL__
36
37#include <linux/types.h> 33#include <linux/types.h>
38#include <linux/slab.h> 34#include <linux/slab.h>
39#include <linux/interrupt.h>
40#include <linux/vmalloc.h>
41#include <asm/pgalloc.h>
42
43#define CSR1212_MALLOC(size) vmalloc((size))
44#define CSR1212_FREE(ptr) vfree(ptr)
45#define CSR1212_BE16_TO_CPU(quad) be16_to_cpu(quad)
46#define CSR1212_CPU_TO_BE16(quad) cpu_to_be16(quad)
47#define CSR1212_BE32_TO_CPU(quad) be32_to_cpu(quad)
48#define CSR1212_CPU_TO_BE32(quad) cpu_to_be32(quad)
49#define CSR1212_BE64_TO_CPU(quad) be64_to_cpu(quad)
50#define CSR1212_CPU_TO_BE64(quad) cpu_to_be64(quad)
51
52#define CSR1212_LE16_TO_CPU(quad) le16_to_cpu(quad)
53#define CSR1212_CPU_TO_LE16(quad) cpu_to_le16(quad)
54#define CSR1212_LE32_TO_CPU(quad) le32_to_cpu(quad)
55#define CSR1212_CPU_TO_LE32(quad) cpu_to_le32(quad)
56#define CSR1212_LE64_TO_CPU(quad) le64_to_cpu(quad)
57#define CSR1212_CPU_TO_LE64(quad) cpu_to_le64(quad)
58
59#include <linux/errno.h>
60#define CSR1212_SUCCESS (0)
61#define CSR1212_EINVAL (-EINVAL)
62#define CSR1212_ENOMEM (-ENOMEM)
63#define CSR1212_ENOENT (-ENOENT)
64#define CSR1212_EIO (-EIO)
65#define CSR1212_EBUSY (-EBUSY)
66
67#else /* Userspace */
68
69#include <sys/types.h>
70#include <malloc.h>
71#define CSR1212_MALLOC(size) malloc(size)
72#define CSR1212_FREE(ptr) free(ptr)
73#include <endian.h>
74#if __BYTE_ORDER == __LITTLE_ENDIAN
75#include <byteswap.h>
76#define CSR1212_BE16_TO_CPU(quad) bswap_16(quad)
77#define CSR1212_CPU_TO_BE16(quad) bswap_16(quad)
78#define CSR1212_BE32_TO_CPU(quad) bswap_32(quad)
79#define CSR1212_CPU_TO_BE32(quad) bswap_32(quad)
80#define CSR1212_BE64_TO_CPU(quad) bswap_64(quad)
81#define CSR1212_CPU_TO_BE64(quad) bswap_64(quad)
82
83#define CSR1212_LE16_TO_CPU(quad) (quad)
84#define CSR1212_CPU_TO_LE16(quad) (quad)
85#define CSR1212_LE32_TO_CPU(quad) (quad)
86#define CSR1212_CPU_TO_LE32(quad) (quad)
87#define CSR1212_LE64_TO_CPU(quad) (quad)
88#define CSR1212_CPU_TO_LE64(quad) (quad)
89#else
90#define CSR1212_BE16_TO_CPU(quad) (quad)
91#define CSR1212_CPU_TO_BE16(quad) (quad)
92#define CSR1212_BE32_TO_CPU(quad) (quad)
93#define CSR1212_CPU_TO_BE32(quad) (quad)
94#define CSR1212_BE64_TO_CPU(quad) (quad)
95#define CSR1212_CPU_TO_BE64(quad) (quad)
96
97#define CSR1212_LE16_TO_CPU(quad) bswap_16(quad)
98#define CSR1212_CPU_TO_LE16(quad) bswap_16(quad)
99#define CSR1212_LE32_TO_CPU(quad) bswap_32(quad)
100#define CSR1212_CPU_TO_LE32(quad) bswap_32(quad)
101#define CSR1212_LE64_TO_CPU(quad) bswap_64(quad)
102#define CSR1212_CPU_TO_LE64(quad) bswap_64(quad)
103#endif
104
105#include <errno.h>
106#define CSR1212_SUCCESS (0)
107#define CSR1212_EINVAL (EINVAL)
108#define CSR1212_ENOMEM (ENOMEM)
109#define CSR1212_ENOENT (ENOENT)
110#define CSR1212_EIO (EIO)
111#define CSR1212_EBUSY (EBUSY)
112
113#endif
114 35
36#define CSR1212_MALLOC(size) kmalloc((size), GFP_KERNEL)
37#define CSR1212_FREE(ptr) kfree(ptr)
115 38
116#define CSR1212_KV_VAL_MASK 0xffffff 39#define CSR1212_SUCCESS (0)
117#define CSR1212_KV_KEY_SHIFT 24
118#define CSR1212_KV_KEY_TYPE_SHIFT 6
119#define CSR1212_KV_KEY_ID_MASK 0x3f
120#define CSR1212_KV_KEY_TYPE_MASK 0x3 /* After shift */
121 40
122 41
123/* CSR 1212 key types */ 42/* CSR 1212 key types */
@@ -190,48 +109,22 @@
190#define CSR1212_UNITS_SPACE_END (CSR1212_UNITS_SPACE_BASE + CSR1212_UNITS_SPACE_SIZE) 109#define CSR1212_UNITS_SPACE_END (CSR1212_UNITS_SPACE_BASE + CSR1212_UNITS_SPACE_SIZE)
191#define CSR1212_UNITS_SPACE_OFFSET (CSR1212_UNITS_SPACE_BASE - CSR1212_REGISTER_SPACE_BASE) 110#define CSR1212_UNITS_SPACE_OFFSET (CSR1212_UNITS_SPACE_BASE - CSR1212_REGISTER_SPACE_BASE)
192 111
193#define CSR1212_EXTENDED_ROM_SIZE (0x10000 * sizeof(u_int32_t))
194
195#define CSR1212_INVALID_ADDR_SPACE -1 112#define CSR1212_INVALID_ADDR_SPACE -1
196 113
114
197/* Config ROM image structures */ 115/* Config ROM image structures */
198struct csr1212_bus_info_block_img { 116struct csr1212_bus_info_block_img {
199 u_int8_t length; 117 u8 length;
200 u_int8_t crc_length; 118 u8 crc_length;
201 u_int16_t crc; 119 u16 crc;
202 120
203 /* Must be last */ 121 /* Must be last */
204 u_int32_t data[0]; /* older gcc can't handle [] which is standard */ 122 u32 data[0]; /* older gcc can't handle [] which is standard */
205};
206
207#define CSR1212_KV_KEY(quad) (CSR1212_BE32_TO_CPU(quad) >> CSR1212_KV_KEY_SHIFT)
208#define CSR1212_KV_KEY_TYPE(quad) (CSR1212_KV_KEY(quad) >> CSR1212_KV_KEY_TYPE_SHIFT)
209#define CSR1212_KV_KEY_ID(quad) (CSR1212_KV_KEY(quad) & CSR1212_KV_KEY_ID_MASK)
210#define CSR1212_KV_VAL(quad) (CSR1212_BE32_TO_CPU(quad) & CSR1212_KV_VAL_MASK)
211
212#define CSR1212_SET_KV_KEY(quad, key) ((quad) = \
213 CSR1212_CPU_TO_BE32(CSR1212_KV_VAL(quad) | ((key) << CSR1212_KV_KEY_SHIFT)))
214#define CSR1212_SET_KV_VAL(quad, val) ((quad) = \
215 CSR1212_CPU_TO_BE32((CSR1212_KV_KEY(quad) << CSR1212_KV_KEY_SHIFT) | (val)))
216#define CSR1212_SET_KV_TYPEID(quad, type, id) ((quad) = \
217 CSR1212_CPU_TO_BE32(CSR1212_KV_VAL(quad) | \
218 (((((type) & CSR1212_KV_KEY_TYPE_MASK) << CSR1212_KV_KEY_TYPE_SHIFT) | \
219 ((id) & CSR1212_KV_KEY_ID_MASK)) << CSR1212_KV_KEY_SHIFT)))
220
221typedef u_int32_t csr1212_quad_t;
222
223
224struct csr1212_keyval_img {
225 u_int16_t length;
226 u_int16_t crc;
227
228 /* Must be last */
229 csr1212_quad_t data[0]; /* older gcc can't handle [] which is standard */
230}; 123};
231 124
232struct csr1212_leaf { 125struct csr1212_leaf {
233 int len; 126 int len;
234 u_int32_t *data; 127 u32 *data;
235}; 128};
236 129
237struct csr1212_dentry { 130struct csr1212_dentry {
@@ -246,12 +139,12 @@ struct csr1212_directory {
246 139
247struct csr1212_keyval { 140struct csr1212_keyval {
248 struct { 141 struct {
249 u_int8_t type; 142 u8 type;
250 u_int8_t id; 143 u8 id;
251 } key; 144 } key;
252 union { 145 union {
253 u_int32_t immediate; 146 u32 immediate;
254 u_int32_t csr_offset; 147 u32 csr_offset;
255 struct csr1212_leaf leaf; 148 struct csr1212_leaf leaf;
256 struct csr1212_directory directory; 149 struct csr1212_directory directory;
257 } value; 150 } value;
@@ -260,15 +153,15 @@ struct csr1212_keyval {
260 153
261 /* used in generating and/or parsing CSR image */ 154 /* used in generating and/or parsing CSR image */
262 struct csr1212_keyval *next, *prev; /* flat list of CSR elements */ 155 struct csr1212_keyval *next, *prev; /* flat list of CSR elements */
263 u_int32_t offset; /* position in CSR from 0xffff f000 0000 */ 156 u32 offset; /* position in CSR from 0xffff f000 0000 */
264 u_int8_t valid; /* flag indicating keyval has valid data*/ 157 u8 valid; /* flag indicating keyval has valid data*/
265}; 158};
266 159
267 160
268struct csr1212_cache_region { 161struct csr1212_cache_region {
269 struct csr1212_cache_region *next, *prev; 162 struct csr1212_cache_region *next, *prev;
270 u_int32_t offset_start; /* inclusive */ 163 u32 offset_start; /* inclusive */
271 u_int32_t offset_end; /* exclusive */ 164 u32 offset_end; /* exclusive */
272}; 165};
273 166
274struct csr1212_csr_rom_cache { 167struct csr1212_csr_rom_cache {
@@ -276,18 +169,18 @@ struct csr1212_csr_rom_cache {
276 struct csr1212_cache_region *filled_head, *filled_tail; 169 struct csr1212_cache_region *filled_head, *filled_tail;
277 struct csr1212_keyval *layout_head, *layout_tail; 170 struct csr1212_keyval *layout_head, *layout_tail;
278 size_t size; 171 size_t size;
279 u_int32_t offset; 172 u32 offset;
280 struct csr1212_keyval *ext_rom; 173 struct csr1212_keyval *ext_rom;
281 size_t len; 174 size_t len;
282 175
283 /* Must be last */ 176 /* Must be last */
284 u_int32_t data[0]; /* older gcc can't handle [] which is standard */ 177 u32 data[0]; /* older gcc can't handle [] which is standard */
285}; 178};
286 179
287struct csr1212_csr { 180struct csr1212_csr {
288 size_t bus_info_len; /* bus info block length in bytes */ 181 size_t bus_info_len; /* bus info block length in bytes */
289 size_t crc_len; /* crc length in bytes */ 182 size_t crc_len; /* crc length in bytes */
290 u_int32_t *bus_info_data; /* bus info data incl bus name and EUI */ 183 u32 *bus_info_data; /* bus info data incl bus name and EUI */
291 184
292 void *private; /* private, bus specific data */ 185 void *private; /* private, bus specific data */
293 struct csr1212_bus_ops *ops; 186 struct csr1212_bus_ops *ops;
@@ -305,52 +198,38 @@ struct csr1212_bus_ops {
305 * from remote nodes when parsing a Config ROM (i.e., read Config ROM 198 * from remote nodes when parsing a Config ROM (i.e., read Config ROM
306 * entries located in the Units Space. Must return 0 on success 199 * entries located in the Units Space. Must return 0 on success
307 * anything else indicates an error. */ 200 * anything else indicates an error. */
308 int (*bus_read) (struct csr1212_csr *csr, u_int64_t addr, 201 int (*bus_read) (struct csr1212_csr *csr, u64 addr,
309 u_int16_t length, void *buffer, void *private); 202 u16 length, void *buffer, void *private);
310 203
311 /* This function is used by csr1212 to allocate a region in units space 204 /* This function is used by csr1212 to allocate a region in units space
312 * in the event that Config ROM entries don't all fit in the predefined 205 * in the event that Config ROM entries don't all fit in the predefined
313 * 1K region. The void *private parameter is private member of struct 206 * 1K region. The void *private parameter is private member of struct
314 * csr1212_csr. */ 207 * csr1212_csr. */
315 u_int64_t (*allocate_addr_range) (u_int64_t size, u_int32_t alignment, 208 u64 (*allocate_addr_range) (u64 size, u32 alignment, void *private);
316 void *private);
317
318 209
319 /* This function is used by csr1212 to release a region in units space 210 /* This function is used by csr1212 to release a region in units space
320 * that is no longer needed. */ 211 * that is no longer needed. */
321 void (*release_addr) (u_int64_t addr, void *private); 212 void (*release_addr) (u64 addr, void *private);
322 213
323 /* This function is used by csr1212 to determine the max read request 214 /* This function is used by csr1212 to determine the max read request
324 * supported by a remote node when reading the ConfigROM space. Must 215 * supported by a remote node when reading the ConfigROM space. Must
325 * return 0, 1, or 2 per IEEE 1212. */ 216 * return 0, 1, or 2 per IEEE 1212. */
326 int (*get_max_rom) (u_int32_t *bus_info, void *private); 217 int (*get_max_rom) (u32 *bus_info, void *private);
327}; 218};
328 219
329 220
330
331
332/* Descriptor Leaf manipulation macros */ 221/* Descriptor Leaf manipulation macros */
333#define CSR1212_DESCRIPTOR_LEAF_TYPE_SHIFT 24 222#define CSR1212_DESCRIPTOR_LEAF_TYPE_SHIFT 24
334#define CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID_MASK 0xffffff 223#define CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID_MASK 0xffffff
335#define CSR1212_DESCRIPTOR_LEAF_OVERHEAD (1 * sizeof(u_int32_t)) 224#define CSR1212_DESCRIPTOR_LEAF_OVERHEAD (1 * sizeof(u32))
336 225
337#define CSR1212_DESCRIPTOR_LEAF_TYPE(kv) \ 226#define CSR1212_DESCRIPTOR_LEAF_TYPE(kv) \
338 (CSR1212_BE32_TO_CPU((kv)->value.leaf.data[0]) >> CSR1212_DESCRIPTOR_LEAF_TYPE_SHIFT) 227 (be32_to_cpu((kv)->value.leaf.data[0]) >> \
228 CSR1212_DESCRIPTOR_LEAF_TYPE_SHIFT)
339#define CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID(kv) \ 229#define CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID(kv) \
340 (CSR1212_BE32_TO_CPU((kv)->value.leaf.data[0]) & \ 230 (be32_to_cpu((kv)->value.leaf.data[0]) & \
341 CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID_MASK) 231 CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID_MASK)
342#define CSR1212_DESCRIPTOR_LEAF_DATA(kv) \ 232
343 (&((kv)->value.leaf.data[1]))
344
345#define CSR1212_DESCRIPTOR_LEAF_SET_TYPE(kv, type) \
346 ((kv)->value.leaf.data[0] = \
347 CSR1212_CPU_TO_BE32(CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID(kv) | \
348 ((type) << CSR1212_DESCRIPTOR_LEAF_TYPE_SHIFT)))
349#define CSR1212_DESCRIPTOR_LEAF_SET_SPECIFIER_ID(kv, spec_id) \
350 ((kv)->value.leaf.data[0] = \
351 CSR1212_CPU_TO_BE32((CSR1212_DESCRIPTOR_LEAF_TYPE(kv) << \
352 CSR1212_DESCRIPTOR_LEAF_TYPE_SHIFT) | \
353 ((spec_id) & CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID_MASK)))
354 233
355/* Text Descriptor Leaf manipulation macros */ 234/* Text Descriptor Leaf manipulation macros */
356#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_SHIFT 28 235#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_SHIFT 28
@@ -358,182 +237,21 @@ struct csr1212_bus_ops {
358#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_SHIFT 16 237#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_SHIFT 16
359#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_MASK 0xfff /* after shift */ 238#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_MASK 0xfff /* after shift */
360#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE_MASK 0xffff 239#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE_MASK 0xffff
361#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_OVERHEAD (1 * sizeof(u_int32_t)) 240#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_OVERHEAD (1 * sizeof(u32))
362 241
363#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH(kv) \ 242#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH(kv) \
364 (CSR1212_BE32_TO_CPU((kv)->value.leaf.data[1]) >> \ 243 (be32_to_cpu((kv)->value.leaf.data[1]) >> \
365 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_SHIFT) 244 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_SHIFT)
366#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET(kv) \ 245#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET(kv) \
367 ((CSR1212_BE32_TO_CPU((kv)->value.leaf.data[1]) >> \ 246 ((be32_to_cpu((kv)->value.leaf.data[1]) >> \
368 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_SHIFT) & \ 247 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_SHIFT) & \
369 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_MASK) 248 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_MASK)
370#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE(kv) \ 249#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE(kv) \
371 (CSR1212_BE32_TO_CPU((kv)->value.leaf.data[1]) & \ 250 (be32_to_cpu((kv)->value.leaf.data[1]) & \
372 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE_MASK) 251 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE_MASK)
373#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA(kv) \ 252#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA(kv) \
374 (&((kv)->value.leaf.data[2])) 253 (&((kv)->value.leaf.data[2]))
375 254
376#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_SET_WIDTH(kv, width) \
377 ((kv)->value.leaf.data[1] = \
378 ((kv)->value.leaf.data[1] & \
379 CSR1212_CPU_TO_BE32(~(CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_MASK << \
380 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_SHIFT))) | \
381 CSR1212_CPU_TO_BE32(((width) & \
382 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_MASK) << \
383 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_SHIFT))
384#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_SET_CHAR_SET(kv, char_set) \
385 ((kv)->value.leaf.data[1] = \
386 ((kv)->value.leaf.data[1] & \
387 CSR1212_CPU_TO_BE32(~(CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_MASK << \
388 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_SHIFT))) | \
389 CSR1212_CPU_TO_BE32(((char_set) & \
390 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_MASK) << \
391 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_SHIFT))
392#define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_SET_LANGUAGE(kv, language) \
393 ((kv)->value.leaf.data[1] = \
394 ((kv)->value.leaf.data[1] & \
395 CSR1212_CPU_TO_BE32(~(CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE_MASK))) | \
396 CSR1212_CPU_TO_BE32(((language) & \
397 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE_MASK)))
398
399
400/* Icon Descriptor Leaf manipulation macros */
401#define CSR1212_ICON_DESCRIPTOR_LEAF_VERSION_MASK 0xffffff
402#define CSR1212_ICON_DESCRIPTOR_LEAF_PALETTE_DEPTH_SHIFT 30
403#define CSR1212_ICON_DESCRIPTOR_LEAF_PALETTE_DEPTH_MASK 0x3 /* after shift */
404#define CSR1212_ICON_DESCRIPTOR_LEAF_COLOR_SPACE_SHIFT 16
405#define CSR1212_ICON_DESCRIPTOR_LEAF_COLOR_SPACE_MASK 0xf /* after shift */
406#define CSR1212_ICON_DESCRIPTOR_LEAF_LANGUAGE_MASK 0xffff
407#define CSR1212_ICON_DESCRIPTOR_LEAF_HSCAN_SHIFT 16
408#define CSR1212_ICON_DESCRIPTOR_LEAF_HSCAN_MASK 0xffff /* after shift */
409#define CSR1212_ICON_DESCRIPTOR_LEAF_VSCAN_MASK 0xffff
410#define CSR1212_ICON_DESCRIPTOR_LEAF_OVERHEAD (3 * sizeof(u_int32_t))
411
412#define CSR1212_ICON_DESCRIPTOR_LEAF_VERSION(kv) \
413 (CSR1212_BE32_TO_CPU((kv)->value.leaf.data[2]) & \
414 CSR1212_ICON_DESCRIPTOR_LEAF_VERSION_MASK)
415
416#define CSR1212_ICON_DESCRIPTOR_LEAF_PALETTE_DEPTH(kv) \
417 (CSR1212_BE32_TO_CPU((kv)->value.leaf.data[3]) >> \
418 CSR1212_ICON_DESCRIPTOR_LEAF_PALETTE_DEPTH_SHIFT)
419
420#define CSR1212_ICON_DESCRIPTOR_LEAF_COLOR_SPACE(kv) \
421 ((CSR1212_BE32_TO_CPU((kv)->value.leaf.data[3]) >> \
422 CSR1212_ICON_DESCRIPTOR_LEAF_COLOR_SPACE_SHIFT) & \
423 CSR1212_ICON_DESCRIPTOR_LEAF_COLOR_SPACE_MASK)
424
425#define CSR1212_ICON_DESCRIPTOR_LEAF_LANGUAGE(kv) \
426 (CSR1212_BE32_TO_CPU((kv)->value.leaf.data[3]) & \
427 CSR1212_ICON_DESCRIPTOR_LEAF_LANGUAGE_MASK)
428
429#define CSR1212_ICON_DESCRIPTOR_LEAF_HSCAN(kv) \
430 ((CSR1212_BE32_TO_CPU((kv)->value.leaf.data[4]) >> \
431 CSR1212_ICON_DESCRIPTOR_LEAF_COLOR_HSCAN_SHIFT) & \
432 CSR1212_ICON_DESCRIPTOR_LEAF_COLOR_HSCAN_MASK)
433
434#define CSR1212_ICON_DESCRIPTOR_LEAF_VSCAN(kv) \
435 (CSR1212_BE32_TO_CPU((kv)->value.leaf.data[4]) & \
436 CSR1212_ICON_DESCRIPTOR_LEAF_VSCAN_MASK)
437
438#define CSR1212_ICON_DESCRIPTOR_LEAF_PALETTE(kv) \
439 (&((kv)->value.leaf.data[5]))
440
441static inline u_int32_t *CSR1212_ICON_DESCRIPTOR_LEAF_PIXELS(struct csr1212_keyval *kv)
442{
443 static const int pd[4] = { 0, 4, 16, 256 };
444 static const int cs[16] = { 4, 2 };
445 int ps = pd[CSR1212_ICON_DESCRIPTOR_LEAF_PALETTE_DEPTH(kv)];
446
447 return &kv->value.leaf.data[5 +
448 (ps * cs[CSR1212_ICON_DESCRIPTOR_LEAF_COLOR_SPACE(kv)]) /
449 sizeof(u_int32_t)];
450}
451
452#define CSR1212_ICON_DESCRIPTOR_LEAF_SET_VERSION(kv, version) \
453 ((kv)->value.leaf.data[2] = \
454 ((kv)->value.leaf.data[2] & \
455 CSR1212_CPU_TO_BE32(~(CSR1212_ICON_DESCRIPTOR_LEAF_VERSION_MASK))) | \
456 CSR1212_CPU_TO_BE32(((version) & \
457 CSR1212_ICON_DESCRIPTOR_LEAF_VERSION_MASK)))
458
459#define CSR1212_ICON_DESCRIPTOR_LEAF_SET_PALETTE_DEPTH(kv, palette_depth) \
460 ((kv)->value.leaf.data[3] = \
461 ((kv)->value.leaf.data[3] & \
462 CSR1212_CPU_TO_BE32(~(CSR1212_ICON_DESCRIPTOR_LEAF_PALETTE_DEPTH_MASK << \
463 CSR1212_ICON_DESCRIPTOR_LEAF_PALETTE_DEPTH_SHIFT))) | \
464 CSR1212_CPU_TO_BE32(((palette_depth) & \
465 CSR1212_ICON_DESCRIPTOR_LEAF_PALETTE_DEPTH_MASK) << \
466 CSR1212_ICON_DESCRIPTOR_LEAF_PALETTE_DEPTH_SHIFT))
467
468#define CSR1212_ICON_DESCRIPTOR_LEAF_SET_COLOR_SPACE(kv, color_space) \
469 ((kv)->value.leaf.data[3] = \
470 ((kv)->value.leaf.data[3] & \
471 CSR1212_CPU_TO_BE32(~(CSR1212_ICON_DESCRIPTOR_LEAF_COLOR_SPACE_MASK << \
472 CSR1212_ICON_DESCRIPTOR_LEAF_COLOR_SPACE_SHIFT))) | \
473 CSR1212_CPU_TO_BE32(((color_space) & \
474 CSR1212_ICON_DESCRIPTOR_LEAF_COLOR_SPACE_MASK) << \
475 CSR1212_ICON_DESCRIPTOR_LEAF_COLOR_SPACE_SHIFT))
476
477#define CSR1212_ICON_DESCRIPTOR_LEAF_SET_LANGUAGE(kv, language) \
478 ((kv)->value.leaf.data[3] = \
479 ((kv)->value.leaf.data[3] & \
480 CSR1212_CPU_TO_BE32(~(CSR1212_ICON_DESCRIPTOR_LEAF_LANGUAGE_MASK))) | \
481 CSR1212_CPU_TO_BE32(((language) & \
482 CSR1212_ICON_DESCRIPTOR_LEAF_LANGUAGE_MASK)))
483
484#define CSR1212_ICON_DESCRIPTOR_LEAF_SET_HSCAN(kv, hscan) \
485 ((kv)->value.leaf.data[4] = \
486 ((kv)->value.leaf.data[4] & \
487 CSR1212_CPU_TO_BE32(~(CSR1212_ICON_DESCRIPTOR_LEAF_HSCAN_MASK << \
488 CSR1212_ICON_DESCRIPTOR_LEAF_HSCAN_SHIFT))) | \
489 CSR1212_CPU_TO_BE32(((hscan) & \
490 CSR1212_ICON_DESCRIPTOR_LEAF_HSCAN_MASK) << \
491 CSR1212_ICON_DESCRIPTOR_LEAF_HSCAN_SHIFT))
492
493#define CSR1212_ICON_DESCRIPTOR_LEAF_SET_VSCAN(kv, vscan) \
494 ((kv)->value.leaf.data[4] = \
495 (((kv)->value.leaf.data[4] & \
496 CSR1212_CPU_TO_BE32(~CSR1212_ICON_DESCRIPTOR_LEAF_VSCAN_MASK))) | \
497 CSR1212_CPU_TO_BE32(((vscan) & \
498 CSR1212_ICON_DESCRIPTOR_LEAF_VSCAN_MASK)))
499
500
501/* Modifiable Descriptor Leaf manipulation macros */
502#define CSR1212_MODIFIABLE_DESCRIPTOR_LEAF_MAX_SIZE_SHIFT 16
503#define CSR1212_MODIFIABLE_DESCRIPTOR_LEAF_MAX_SIZE_MASK 0xffff
504#define CSR1212_MODIFIABLE_DESCRIPTOR_LEAF_ADDR_HI_SHIFT 32
505#define CSR1212_MODIFIABLE_DESCRIPTOR_LEAF_ADDR_HI_MASK 0xffff
506#define CSR1212_MODIFIABLE_DESCRIPTOR_LEAF_ADDR_LO_MASK 0xffffffffULL
507
508#define CSR1212_MODIFIABLE_DESCRIPTOR_MAX_SIZE(kv) \
509 CSR1212_BE16_TO_CPU((kv)->value.leaf.data[0] >> CSR1212_MODIFIABLE_DESCRIPTOR_MAX_SIZE_SHIFT)
510
511#define CSR1212_MODIFIABLE_DESCRIPTOR_ADDRESS(kv) \
512 (CSR1212_BE16_TO_CPU(((u_int64_t)((kv)->value.leaf.data[0])) << \
513 CSR1212_MODIFIABLE_DESCRIPTOR_ADDR_HI_SHIFT) | \
514 CSR1212_BE32_TO_CPU((kv)->value.leaf.data[1]))
515
516#define CSR1212_MODIFIABLE_DESCRIPTOR_SET_MAX_SIZE(kv, size) \
517 ((kv)->value.leaf.data[0] = \
518 ((kv)->value.leaf.data[0] & \
519 CSR1212_CPU_TO_BE32(~(CSR1212_MODIFIABLE_DESCRIPTOR_LEAF_MAX_SIZE_MASK << \
520 CSR1212_MODIFIABLE_DESCRIPTOR_LEAF_MAX_SIZE_SHIFT))) | \
521 CSR1212_CPU_TO_BE32(((size) & \
522 CSR1212_MODIFIABLE_DESCRIPTOR_LEAF_MAX_SIZE_MASK) << \
523 CSR1212_MODIFIABLE_DESCRIPTOR_LEAF_MAX_SIZE_SHIFT))
524
525#define CSR1212_MODIFIABLE_DESCRIPTOR_SET_ADDRESS_HI(kv, addr) \
526 ((kv)->value.leaf.data[0] = \
527 ((kv)->value.leaf.data[0] & \
528 CSR1212_CPU_TO_BE32(~(CSR1212_MODIFIABLE_DESCRIPTOR_LEAF_ADDR_HI_MASK))) | \
529 CSR1212_CPU_TO_BE32(((addr) & \
530 CSR1212_MODIFIABLE_DESCRIPTOR_LEAF_ADDR_HI_MASK)))
531
532#define CSR1212_MODIFIABLE_DESCRIPTOR_SET_ADDRESS_LO(kv, addr) \
533 ((kv)->value.leaf.data[1] = \
534 CSR1212_CPU_TO_BE32(addr & CSR1212_MODIFIABLE_DESCRIPTOR_LEAF_ADDR_LO_MASK))
535
536
537 255
538/* The following 2 function are for creating new Configuration ROM trees. The 256/* The following 2 function are for creating new Configuration ROM trees. The
539 * first function is used for both creating local trees and parsing remote 257 * first function is used for both creating local trees and parsing remote
@@ -543,11 +261,10 @@ extern struct csr1212_csr *csr1212_create_csr(struct csr1212_bus_ops *ops,
543 size_t bus_info_size, 261 size_t bus_info_size,
544 void *private); 262 void *private);
545extern void csr1212_init_local_csr(struct csr1212_csr *csr, 263extern void csr1212_init_local_csr(struct csr1212_csr *csr,
546 const u_int32_t *bus_info_data, int max_rom); 264 const u32 *bus_info_data, int max_rom);
547 265
548 266
549/* The following function destroys a Configuration ROM tree and release all 267/* Destroy a Configuration ROM tree and release all memory taken by the tree. */
550 * memory taken by the tree. */
551extern void csr1212_destroy_csr(struct csr1212_csr *csr); 268extern void csr1212_destroy_csr(struct csr1212_csr *csr);
552 269
553 270
@@ -555,50 +272,20 @@ extern void csr1212_destroy_csr(struct csr1212_csr *csr);
555 * a Configuration ROM tree. Code that creates new keyvals with these functions 272 * a Configuration ROM tree. Code that creates new keyvals with these functions
556 * must release those keyvals with csr1212_release_keyval() when they are no 273 * must release those keyvals with csr1212_release_keyval() when they are no
557 * longer needed. */ 274 * longer needed. */
558extern struct csr1212_keyval *csr1212_new_immediate(u_int8_t key, u_int32_t value); 275extern struct csr1212_keyval *csr1212_new_immediate(u8 key, u32 value);
559extern struct csr1212_keyval *csr1212_new_leaf(u_int8_t key, const void *data, 276extern struct csr1212_keyval *csr1212_new_directory(u8 key);
560 size_t data_len);
561extern struct csr1212_keyval *csr1212_new_csr_offset(u_int8_t key,
562 u_int32_t csr_offset);
563extern struct csr1212_keyval *csr1212_new_directory(u_int8_t key);
564extern struct csr1212_keyval *csr1212_new_extended_immediate(u_int32_t spec,
565 u_int32_t key,
566 u_int32_t value);
567extern struct csr1212_keyval *csr1212_new_extended_leaf(u_int32_t spec,
568 u_int32_t key,
569 const void *data,
570 size_t data_len);
571extern struct csr1212_keyval *csr1212_new_descriptor_leaf(u_int8_t dtype,
572 u_int32_t specifier_id,
573 const void *data,
574 size_t data_len);
575extern struct csr1212_keyval *csr1212_new_textual_descriptor_leaf(u_int8_t cwidth,
576 u_int16_t cset,
577 u_int16_t language,
578 const void *data,
579 size_t data_len);
580extern struct csr1212_keyval *csr1212_new_string_descriptor_leaf(const char *s); 277extern struct csr1212_keyval *csr1212_new_string_descriptor_leaf(const char *s);
581extern struct csr1212_keyval *csr1212_new_icon_descriptor_leaf(u_int32_t version, 278
582 u_int8_t palette_depth, 279
583 u_int8_t color_space, 280/* The following function manages association between keyvals. Typically,
584 u_int16_t language,
585 u_int16_t hscan,
586 u_int16_t vscan,
587 u_int32_t *palette,
588 u_int32_t *pixels);
589extern struct csr1212_keyval *csr1212_new_modifiable_descriptor_leaf(u_int16_t max_size,
590 u_int64_t address);
591extern struct csr1212_keyval *csr1212_new_keyword_leaf(int strc,
592 const char *strv[]);
593
594
595/* The following functions manage association between keyvals. Typically,
596 * Descriptor Leaves and Directories will be associated with another keyval and 281 * Descriptor Leaves and Directories will be associated with another keyval and
597 * it is desirable for the Descriptor keyval to be place immediately after the 282 * it is desirable for the Descriptor keyval to be place immediately after the
598 * keyval that it is associated with.*/ 283 * keyval that it is associated with.
599extern int csr1212_associate_keyval(struct csr1212_keyval *kv, 284 * Take care with subsequent ROM modifications: There is no function to remove
600 struct csr1212_keyval *associate); 285 * previously specified associations.
601extern void csr1212_disassociate_keyval(struct csr1212_keyval *kv); 286 */
287extern void csr1212_associate_keyval(struct csr1212_keyval *kv,
288 struct csr1212_keyval *associate);
602 289
603 290
604/* The following functions manage the association of a keyval and directories. 291/* The following functions manage the association of a keyval and directories.
@@ -609,23 +296,15 @@ extern void csr1212_detach_keyval_from_directory(struct csr1212_keyval *dir,
609 struct csr1212_keyval *kv); 296 struct csr1212_keyval *kv);
610 297
611 298
612/* The following functions create a Configuration ROM image from the tree of 299/* Creates a complete Configuration ROM image in the list of caches available
613 * keyvals provided. csr1212_generate_csr_image() creates a complete image in 300 * via csr->cache_head. */
614 * the list of caches available via csr->cache_head. The other functions are
615 * provided should there be a need to create a flat image without restrictions
616 * placed by IEEE 1212. */
617extern struct csr1212_keyval *csr1212_generate_positions(struct csr1212_csr_rom_cache *cache,
618 struct csr1212_keyval *start_kv,
619 int start_pos);
620extern size_t csr1212_generate_layout_order(struct csr1212_keyval *kv);
621extern void csr1212_fill_cache(struct csr1212_csr_rom_cache *cache);
622extern int csr1212_generate_csr_image(struct csr1212_csr *csr); 301extern int csr1212_generate_csr_image(struct csr1212_csr *csr);
623 302
624 303
625/* This is a convience function for reading a block of data out of one of the 304/* This is a convience function for reading a block of data out of one of the
626 * caches in the csr->cache_head list. */ 305 * caches in the csr->cache_head list. */
627extern int csr1212_read(struct csr1212_csr *csr, u_int32_t offset, void *buffer, 306extern int csr1212_read(struct csr1212_csr *csr, u32 offset, void *buffer,
628 u_int32_t len); 307 u32 len);
629 308
630 309
631/* The following functions are in place for parsing Configuration ROM images. 310/* The following functions are in place for parsing Configuration ROM images.
@@ -635,15 +314,11 @@ extern int csr1212_parse_keyval(struct csr1212_keyval *kv,
635 struct csr1212_csr_rom_cache *cache); 314 struct csr1212_csr_rom_cache *cache);
636extern int csr1212_parse_csr(struct csr1212_csr *csr); 315extern int csr1212_parse_csr(struct csr1212_csr *csr);
637 316
638/* These are internal functions referenced by inline functions below. */
639extern int _csr1212_read_keyval(struct csr1212_csr *csr, struct csr1212_keyval *kv);
640extern void _csr1212_destroy_keyval(struct csr1212_keyval *kv);
641
642 317
643/* This function allocates a new cache which may be used for either parsing or 318/* This function allocates a new cache which may be used for either parsing or
644 * generating sub-sets of Configuration ROM images. */ 319 * generating sub-sets of Configuration ROM images. */
645static inline struct csr1212_csr_rom_cache *csr1212_rom_cache_malloc(u_int32_t offset, 320static inline struct csr1212_csr_rom_cache *
646 size_t size) 321csr1212_rom_cache_malloc(u32 offset, size_t size)
647{ 322{
648 struct csr1212_csr_rom_cache *cache; 323 struct csr1212_csr_rom_cache *cache;
649 324
@@ -667,16 +342,8 @@ static inline struct csr1212_csr_rom_cache *csr1212_rom_cache_malloc(u_int32_t o
667 342
668/* This function ensures that a keyval contains data when referencing a keyval 343/* This function ensures that a keyval contains data when referencing a keyval
669 * created by parsing a Configuration ROM. */ 344 * created by parsing a Configuration ROM. */
670static inline struct csr1212_keyval *csr1212_get_keyval(struct csr1212_csr *csr, 345extern struct csr1212_keyval *
671 struct csr1212_keyval *kv) 346csr1212_get_keyval(struct csr1212_csr *csr, struct csr1212_keyval *kv);
672{
673 if (!kv)
674 return NULL;
675 if (!kv->valid)
676 if (_csr1212_read_keyval(csr, kv) != CSR1212_SUCCESS)
677 return NULL;
678 return kv;
679}
680 347
681 348
682/* This function increments the reference count for a keyval should there be a 349/* This function increments the reference count for a keyval should there be a
@@ -691,37 +358,29 @@ static inline void csr1212_keep_keyval(struct csr1212_keyval *kv)
691 * keyval when there are no more users of the keyval. This should be called by 358 * keyval when there are no more users of the keyval. This should be called by
692 * any code that calls csr1212_keep_keyval() or any of the keyval creation 359 * any code that calls csr1212_keep_keyval() or any of the keyval creation
693 * routines csr1212_new_*(). */ 360 * routines csr1212_new_*(). */
694static inline void csr1212_release_keyval(struct csr1212_keyval *kv) 361extern void csr1212_release_keyval(struct csr1212_keyval *kv);
695{
696 if (kv->refcnt > 1)
697 kv->refcnt--;
698 else
699 _csr1212_destroy_keyval(kv);
700}
701 362
702 363
703/* 364/*
704 * This macro allows for looping over the keyval entries in a directory and it 365 * This macro allows for looping over the keyval entries in a directory and it
705 * ensures that keyvals from remote ConfigROMs are parsed properly. 366 * ensures that keyvals from remote ConfigROMs are parsed properly.
706 * 367 *
707 * _csr is a struct csr1212_csr * that points to CSR associated with dir. 368 * struct csr1212_csr *_csr points to the CSR associated with dir.
708 * _kv is a struct csr1212_keyval * that'll point to the current keyval (loop index). 369 * struct csr1212_keyval *_kv points to the current keyval (loop index).
709 * _dir is a struct csr1212_keyval * that points to the directory to be looped. 370 * struct csr1212_keyval *_dir points to the directory to be looped.
710 * _pos is a struct csr1212_dentry * that is used internally for indexing. 371 * struct csr1212_dentry *_pos is used internally for indexing.
711 * 372 *
712 * kv will be NULL upon exit of the loop. 373 * kv will be NULL upon exit of the loop.
713 */ 374 */
714#define csr1212_for_each_dir_entry(_csr, _kv, _dir, _pos) \ 375#define csr1212_for_each_dir_entry(_csr, _kv, _dir, _pos) \
715 for (csr1212_get_keyval((_csr), (_dir)), \ 376 for (csr1212_get_keyval((_csr), (_dir)), \
716 _pos = (_dir)->value.directory.dentries_head, \ 377 _pos = (_dir)->value.directory.dentries_head, \
717 _kv = (_pos) ? csr1212_get_keyval((_csr), _pos->kv) : NULL; \ 378 _kv = (_pos) ? csr1212_get_keyval((_csr), _pos->kv) : NULL;\
718 (_kv) && (_pos); \ 379 (_kv) && (_pos); \
719 (_kv->associate == NULL) ? \ 380 (_kv->associate == NULL) ? \
720 ((_pos = _pos->next), \ 381 ((_pos = _pos->next), (_kv = (_pos) ? \
721 (_kv = (_pos) ? csr1212_get_keyval((_csr), _pos->kv) : \ 382 csr1212_get_keyval((_csr), _pos->kv) : \
722 NULL)) : \ 383 NULL)) : \
723 (_kv = csr1212_get_keyval((_csr), _kv->associate))) 384 (_kv = csr1212_get_keyval((_csr), _kv->associate)))
724 385
725
726
727#endif /* __CSR1212_H__ */ 386#endif /* __CSR1212_H__ */