ieee1394: drop csr1212's support for external compilation
[deliverable/linux.git] / drivers / ieee1394 / csr1212.h
1 /*
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
33 #include <linux/types.h>
34 #include <linux/vmalloc.h>
35
36 #define CSR1212_MALLOC(size) vmalloc((size))
37 #define CSR1212_FREE(ptr) vfree(ptr)
38
39 #define CSR1212_SUCCESS (0)
40
41
42 /* 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
112 #define CSR1212_INVALID_ADDR_SPACE -1
113
114
115 /* Config ROM image structures */
116 struct csr1212_bus_info_block_img {
117 u_int8_t length;
118 u_int8_t crc_length;
119 u_int16_t crc;
120
121 /* Must be last */
122 u_int32_t data[0]; /* older gcc can't handle [] which is standard */
123 };
124
125 typedef u_int32_t csr1212_quad_t;
126
127 struct csr1212_leaf {
128 int len;
129 u_int32_t *data;
130 };
131
132 struct csr1212_dentry {
133 struct csr1212_dentry *next, *prev;
134 struct csr1212_keyval *kv;
135 };
136
137 struct csr1212_directory {
138 int len;
139 struct csr1212_dentry *dentries_head, *dentries_tail;
140 };
141
142 struct csr1212_keyval {
143 struct {
144 u_int8_t type;
145 u_int8_t id;
146 } key;
147 union {
148 u_int32_t immediate;
149 u_int32_t csr_offset;
150 struct csr1212_leaf leaf;
151 struct csr1212_directory directory;
152 } value;
153 struct csr1212_keyval *associate;
154 int refcnt;
155
156 /* used in generating and/or parsing CSR image */
157 struct csr1212_keyval *next, *prev; /* flat list of CSR elements */
158 u_int32_t offset; /* position in CSR from 0xffff f000 0000 */
159 u_int8_t valid; /* flag indicating keyval has valid data*/
160 };
161
162
163 struct csr1212_cache_region {
164 struct csr1212_cache_region *next, *prev;
165 u_int32_t offset_start; /* inclusive */
166 u_int32_t offset_end; /* exclusive */
167 };
168
169 struct csr1212_csr_rom_cache {
170 struct csr1212_csr_rom_cache *next, *prev;
171 struct csr1212_cache_region *filled_head, *filled_tail;
172 struct csr1212_keyval *layout_head, *layout_tail;
173 size_t size;
174 u_int32_t offset;
175 struct csr1212_keyval *ext_rom;
176 size_t len;
177
178 /* Must be last */
179 u_int32_t data[0]; /* older gcc can't handle [] which is standard */
180 };
181
182 struct csr1212_csr {
183 size_t bus_info_len; /* bus info block length in bytes */
184 size_t crc_len; /* crc length in bytes */
185 u_int32_t *bus_info_data; /* bus info data incl bus name and EUI */
186
187 void *private; /* private, bus specific data */
188 struct csr1212_bus_ops *ops;
189
190 struct csr1212_keyval *root_kv;
191
192 int max_rom; /* max bytes readable in Config ROM region */
193
194 /* Items below used for image parsing and generation */
195 struct csr1212_csr_rom_cache *cache_head, *cache_tail;
196 };
197
198 struct csr1212_bus_ops {
199 /* This function is used by csr1212 to read additional information
200 * from remote nodes when parsing a Config ROM (i.e., read Config ROM
201 * entries located in the Units Space. Must return 0 on success
202 * anything else indicates an error. */
203 int (*bus_read) (struct csr1212_csr *csr, u_int64_t addr,
204 u_int16_t length, void *buffer, void *private);
205
206 /* This function is used by csr1212 to allocate a region in units space
207 * in the event that Config ROM entries don't all fit in the predefined
208 * 1K region. The void *private parameter is private member of struct
209 * csr1212_csr. */
210 u_int64_t (*allocate_addr_range) (u_int64_t size, u_int32_t alignment,
211 void *private);
212
213
214 /* This function is used by csr1212 to release a region in units space
215 * that is no longer needed. */
216 void (*release_addr) (u_int64_t addr, void *private);
217
218 /* This function is used by csr1212 to determine the max read request
219 * supported by a remote node when reading the ConfigROM space. Must
220 * return 0, 1, or 2 per IEEE 1212. */
221 int (*get_max_rom) (u_int32_t *bus_info, void *private);
222 };
223
224
225 /* Descriptor Leaf manipulation macros */
226 #define CSR1212_DESCRIPTOR_LEAF_TYPE_SHIFT 24
227 #define CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID_MASK 0xffffff
228 #define CSR1212_DESCRIPTOR_LEAF_OVERHEAD (1 * sizeof(u_int32_t))
229
230 #define CSR1212_DESCRIPTOR_LEAF_TYPE(kv) \
231 (be32_to_cpu((kv)->value.leaf.data[0]) >> CSR1212_DESCRIPTOR_LEAF_TYPE_SHIFT)
232 #define CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID(kv) \
233 (be32_to_cpu((kv)->value.leaf.data[0]) & \
234 CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID_MASK)
235
236
237 /* Text Descriptor Leaf manipulation macros */
238 #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_SHIFT 28
239 #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_MASK 0xf /* after shift */
240 #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_SHIFT 16
241 #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_MASK 0xfff /* after shift */
242 #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE_MASK 0xffff
243 #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_OVERHEAD (1 * sizeof(u_int32_t))
244
245 #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH(kv) \
246 (be32_to_cpu((kv)->value.leaf.data[1]) >> \
247 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_SHIFT)
248 #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET(kv) \
249 ((be32_to_cpu((kv)->value.leaf.data[1]) >> \
250 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_SHIFT) & \
251 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_MASK)
252 #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE(kv) \
253 (be32_to_cpu((kv)->value.leaf.data[1]) & \
254 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE_MASK)
255 #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA(kv) \
256 (&((kv)->value.leaf.data[2]))
257
258
259 /* The following 2 function are for creating new Configuration ROM trees. The
260 * first function is used for both creating local trees and parsing remote
261 * trees. The second function adds pertinent information to local Configuration
262 * ROM trees - namely data for the bus information block. */
263 extern struct csr1212_csr *csr1212_create_csr(struct csr1212_bus_ops *ops,
264 size_t bus_info_size,
265 void *private);
266 extern void csr1212_init_local_csr(struct csr1212_csr *csr,
267 const u_int32_t *bus_info_data, int max_rom);
268
269
270 /* Destroy a Configuration ROM tree and release all memory taken by the tree. */
271 extern void csr1212_destroy_csr(struct csr1212_csr *csr);
272
273
274 /* The following set of functions are fore creating new keyvals for placement in
275 * a Configuration ROM tree. Code that creates new keyvals with these functions
276 * must release those keyvals with csr1212_release_keyval() when they are no
277 * longer needed. */
278 extern struct csr1212_keyval *csr1212_new_immediate(u_int8_t key, u_int32_t value);
279 extern struct csr1212_keyval *csr1212_new_directory(u_int8_t key);
280 extern struct csr1212_keyval *csr1212_new_string_descriptor_leaf(const char *s);
281
282
283 /* The following function manages association between keyvals. Typically,
284 * Descriptor Leaves and Directories will be associated with another keyval and
285 * it is desirable for the Descriptor keyval to be place immediately after the
286 * keyval that it is associated with.
287 * Take care with subsequent ROM modifications: There is no function to remove
288 * previously specified associations.
289 */
290 extern int csr1212_associate_keyval(struct csr1212_keyval *kv,
291 struct csr1212_keyval *associate);
292
293
294 /* The following functions manage the association of a keyval and directories.
295 * A keyval may be attached to more than one directory. */
296 extern int csr1212_attach_keyval_to_directory(struct csr1212_keyval *dir,
297 struct csr1212_keyval *kv);
298 extern void csr1212_detach_keyval_from_directory(struct csr1212_keyval *dir,
299 struct csr1212_keyval *kv);
300
301
302 /* Creates a complete Configuration ROM image in the list of caches available
303 * via csr->cache_head. */
304 extern int csr1212_generate_csr_image(struct csr1212_csr *csr);
305
306
307 /* This is a convience function for reading a block of data out of one of the
308 * caches in the csr->cache_head list. */
309 extern int csr1212_read(struct csr1212_csr *csr, u_int32_t offset, void *buffer,
310 u_int32_t len);
311
312
313 /* The following functions are in place for parsing Configuration ROM images.
314 * csr1212_parse_keyval() is used should there be a need to directly parse a
315 * Configuration ROM directly. */
316 extern int csr1212_parse_keyval(struct csr1212_keyval *kv,
317 struct csr1212_csr_rom_cache *cache);
318 extern int csr1212_parse_csr(struct csr1212_csr *csr);
319
320 /* These are internal functions referenced by inline functions below. */
321 extern int _csr1212_read_keyval(struct csr1212_csr *csr, struct csr1212_keyval *kv);
322 extern void _csr1212_destroy_keyval(struct csr1212_keyval *kv);
323
324
325 /* This function allocates a new cache which may be used for either parsing or
326 * generating sub-sets of Configuration ROM images. */
327 static inline struct csr1212_csr_rom_cache *csr1212_rom_cache_malloc(u_int32_t offset,
328 size_t size)
329 {
330 struct csr1212_csr_rom_cache *cache;
331
332 cache = CSR1212_MALLOC(sizeof(*cache) + size);
333 if (!cache)
334 return NULL;
335
336 cache->next = NULL;
337 cache->prev = NULL;
338 cache->filled_head = NULL;
339 cache->filled_tail = NULL;
340 cache->layout_head = NULL;
341 cache->layout_tail = NULL;
342 cache->offset = offset;
343 cache->size = size;
344 cache->ext_rom = NULL;
345
346 return cache;
347 }
348
349
350 /* This function ensures that a keyval contains data when referencing a keyval
351 * created by parsing a Configuration ROM. */
352 static inline struct csr1212_keyval *csr1212_get_keyval(struct csr1212_csr *csr,
353 struct csr1212_keyval *kv)
354 {
355 if (!kv)
356 return NULL;
357 if (!kv->valid)
358 if (_csr1212_read_keyval(csr, kv) != CSR1212_SUCCESS)
359 return NULL;
360 return kv;
361 }
362
363
364 /* This function increments the reference count for a keyval should there be a
365 * need for code to retain a keyval that has been parsed. */
366 static inline void csr1212_keep_keyval(struct csr1212_keyval *kv)
367 {
368 kv->refcnt++;
369 }
370
371
372 /* This function decrements a keyval's reference count and will destroy the
373 * keyval when there are no more users of the keyval. This should be called by
374 * any code that calls csr1212_keep_keyval() or any of the keyval creation
375 * routines csr1212_new_*(). */
376 static inline void csr1212_release_keyval(struct csr1212_keyval *kv)
377 {
378 if (kv->refcnt > 1)
379 kv->refcnt--;
380 else
381 _csr1212_destroy_keyval(kv);
382 }
383
384
385 /*
386 * This macro allows for looping over the keyval entries in a directory and it
387 * ensures that keyvals from remote ConfigROMs are parsed properly.
388 *
389 * _csr is a struct csr1212_csr * that points to CSR associated with dir.
390 * _kv is a struct csr1212_keyval * that'll point to the current keyval (loop index).
391 * _dir is a struct csr1212_keyval * that points to the directory to be looped.
392 * _pos is a struct csr1212_dentry * that is used internally for indexing.
393 *
394 * kv will be NULL upon exit of the loop.
395 */
396 #define csr1212_for_each_dir_entry(_csr, _kv, _dir, _pos) \
397 for (csr1212_get_keyval((_csr), (_dir)), \
398 _pos = (_dir)->value.directory.dentries_head, \
399 _kv = (_pos) ? csr1212_get_keyval((_csr), _pos->kv) : NULL; \
400 (_kv) && (_pos); \
401 (_kv->associate == NULL) ? \
402 ((_pos = _pos->next), \
403 (_kv = (_pos) ? csr1212_get_keyval((_csr), _pos->kv) : \
404 NULL)) : \
405 (_kv = csr1212_get_keyval((_csr), _kv->associate)))
406
407
408
409 #endif /* __CSR1212_H__ */
This page took 0.039275 seconds and 6 git commands to generate.