Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/types.h> |
Stefan Richter | fd2f3bd | 2007-03-11 22:51:24 +0100 | [diff] [blame] | 34 | #include <linux/slab.h> |
Stefan Richter | 17a19b7 | 2007-09-15 14:50:25 +0200 | [diff] [blame] | 35 | #include <asm/atomic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Stefan Richter | fd2f3bd | 2007-03-11 22:51:24 +0100 | [diff] [blame] | 37 | #define CSR1212_MALLOC(size) kmalloc((size), GFP_KERNEL) |
| 38 | #define CSR1212_FREE(ptr) kfree(ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #define CSR1212_SUCCESS (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | /* CSR 1212 key types */ |
| 44 | #define CSR1212_KV_TYPE_IMMEDIATE 0 |
| 45 | #define CSR1212_KV_TYPE_CSR_OFFSET 1 |
| 46 | #define CSR1212_KV_TYPE_LEAF 2 |
| 47 | #define CSR1212_KV_TYPE_DIRECTORY 3 |
| 48 | |
| 49 | |
| 50 | /* CSR 1212 key ids */ |
| 51 | #define CSR1212_KV_ID_DESCRIPTOR 0x01 |
| 52 | #define CSR1212_KV_ID_BUS_DEPENDENT_INFO 0x02 |
| 53 | #define CSR1212_KV_ID_VENDOR 0x03 |
| 54 | #define CSR1212_KV_ID_HARDWARE_VERSION 0x04 |
| 55 | #define CSR1212_KV_ID_MODULE 0x07 |
| 56 | #define CSR1212_KV_ID_NODE_CAPABILITIES 0x0C |
| 57 | #define CSR1212_KV_ID_EUI_64 0x0D |
| 58 | #define CSR1212_KV_ID_UNIT 0x11 |
| 59 | #define CSR1212_KV_ID_SPECIFIER_ID 0x12 |
| 60 | #define CSR1212_KV_ID_VERSION 0x13 |
| 61 | #define CSR1212_KV_ID_DEPENDENT_INFO 0x14 |
| 62 | #define CSR1212_KV_ID_UNIT_LOCATION 0x15 |
| 63 | #define CSR1212_KV_ID_MODEL 0x17 |
| 64 | #define CSR1212_KV_ID_INSTANCE 0x18 |
| 65 | #define CSR1212_KV_ID_KEYWORD 0x19 |
| 66 | #define CSR1212_KV_ID_FEATURE 0x1A |
| 67 | #define CSR1212_KV_ID_EXTENDED_ROM 0x1B |
| 68 | #define CSR1212_KV_ID_EXTENDED_KEY_SPECIFIER_ID 0x1C |
| 69 | #define CSR1212_KV_ID_EXTENDED_KEY 0x1D |
| 70 | #define CSR1212_KV_ID_EXTENDED_DATA 0x1E |
| 71 | #define CSR1212_KV_ID_MODIFIABLE_DESCRIPTOR 0x1F |
| 72 | #define CSR1212_KV_ID_DIRECTORY_ID 0x20 |
| 73 | #define CSR1212_KV_ID_REVISION 0x21 |
| 74 | |
| 75 | |
| 76 | /* IEEE 1212 Address space map */ |
| 77 | #define CSR1212_ALL_SPACE_BASE (0x000000000000ULL) |
| 78 | #define CSR1212_ALL_SPACE_SIZE (1ULL << 48) |
| 79 | #define CSR1212_ALL_SPACE_END (CSR1212_ALL_SPACE_BASE + CSR1212_ALL_SPACE_SIZE) |
| 80 | |
| 81 | #define CSR1212_MEMORY_SPACE_BASE (0x000000000000ULL) |
| 82 | #define CSR1212_MEMORY_SPACE_SIZE ((256ULL * (1ULL << 40)) - (512ULL * (1ULL << 20))) |
| 83 | #define CSR1212_MEMORY_SPACE_END (CSR1212_MEMORY_SPACE_BASE + CSR1212_MEMORY_SPACE_SIZE) |
| 84 | |
| 85 | #define CSR1212_PRIVATE_SPACE_BASE (0xffffe0000000ULL) |
| 86 | #define CSR1212_PRIVATE_SPACE_SIZE (256ULL * (1ULL << 20)) |
| 87 | #define CSR1212_PRIVATE_SPACE_END (CSR1212_PRIVATE_SPACE_BASE + CSR1212_PRIVATE_SPACE_SIZE) |
| 88 | |
| 89 | #define CSR1212_REGISTER_SPACE_BASE (0xfffff0000000ULL) |
| 90 | #define CSR1212_REGISTER_SPACE_SIZE (256ULL * (1ULL << 20)) |
| 91 | #define CSR1212_REGISTER_SPACE_END (CSR1212_REGISTER_SPACE_BASE + CSR1212_REGISTER_SPACE_SIZE) |
| 92 | |
| 93 | #define CSR1212_CSR_ARCH_REG_SPACE_BASE (0xfffff0000000ULL) |
| 94 | #define CSR1212_CSR_ARCH_REG_SPACE_SIZE (512) |
| 95 | #define CSR1212_CSR_ARCH_REG_SPACE_END (CSR1212_CSR_ARCH_REG_SPACE_BASE + CSR1212_CSR_ARCH_REG_SPACE_SIZE) |
| 96 | #define CSR1212_CSR_ARCH_REG_SPACE_OFFSET (CSR1212_CSR_ARCH_REG_SPACE_BASE - CSR1212_REGISTER_SPACE_BASE) |
| 97 | |
| 98 | #define CSR1212_CSR_BUS_DEP_REG_SPACE_BASE (0xfffff0000200ULL) |
| 99 | #define CSR1212_CSR_BUS_DEP_REG_SPACE_SIZE (512) |
| 100 | #define CSR1212_CSR_BUS_DEP_REG_SPACE_END (CSR1212_CSR_BUS_DEP_REG_SPACE_BASE + CSR1212_CSR_BUS_DEP_REG_SPACE_SIZE) |
| 101 | #define CSR1212_CSR_BUS_DEP_REG_SPACE_OFFSET (CSR1212_CSR_BUS_DEP_REG_SPACE_BASE - CSR1212_REGISTER_SPACE_BASE) |
| 102 | |
| 103 | #define CSR1212_CONFIG_ROM_SPACE_BASE (0xfffff0000400ULL) |
| 104 | #define CSR1212_CONFIG_ROM_SPACE_SIZE (1024) |
| 105 | #define CSR1212_CONFIG_ROM_SPACE_END (CSR1212_CONFIG_ROM_SPACE_BASE + CSR1212_CONFIG_ROM_SPACE_SIZE) |
| 106 | #define CSR1212_CONFIG_ROM_SPACE_OFFSET (CSR1212_CONFIG_ROM_SPACE_BASE - CSR1212_REGISTER_SPACE_BASE) |
| 107 | |
| 108 | #define CSR1212_UNITS_SPACE_BASE (0xfffff0000800ULL) |
| 109 | #define CSR1212_UNITS_SPACE_SIZE ((256ULL * (1ULL << 20)) - 2048) |
| 110 | #define CSR1212_UNITS_SPACE_END (CSR1212_UNITS_SPACE_BASE + CSR1212_UNITS_SPACE_SIZE) |
| 111 | #define CSR1212_UNITS_SPACE_OFFSET (CSR1212_UNITS_SPACE_BASE - CSR1212_REGISTER_SPACE_BASE) |
| 112 | |
Ben Collins | 6737231 | 2006-06-12 18:15:31 -0400 | [diff] [blame] | 113 | #define CSR1212_INVALID_ADDR_SPACE -1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Stefan Richter | 6c88e47 | 2007-03-11 22:47:34 +0100 | [diff] [blame] | 115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | /* Config ROM image structures */ |
| 117 | struct csr1212_bus_info_block_img { |
Stefan Richter | 982610b | 2007-03-11 22:49:34 +0100 | [diff] [blame] | 118 | u8 length; |
| 119 | u8 crc_length; |
| 120 | u16 crc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | /* Must be last */ |
Stefan Richter | 982610b | 2007-03-11 22:49:34 +0100 | [diff] [blame] | 123 | u32 data[0]; /* older gcc can't handle [] which is standard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | struct csr1212_leaf { |
| 127 | int len; |
Stefan Richter | 982610b | 2007-03-11 22:49:34 +0100 | [diff] [blame] | 128 | u32 *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | struct csr1212_dentry { |
| 132 | struct csr1212_dentry *next, *prev; |
| 133 | struct csr1212_keyval *kv; |
| 134 | }; |
| 135 | |
| 136 | struct csr1212_directory { |
| 137 | int len; |
| 138 | struct csr1212_dentry *dentries_head, *dentries_tail; |
| 139 | }; |
| 140 | |
| 141 | struct csr1212_keyval { |
| 142 | struct { |
Stefan Richter | 982610b | 2007-03-11 22:49:34 +0100 | [diff] [blame] | 143 | u8 type; |
| 144 | u8 id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } key; |
| 146 | union { |
Stefan Richter | 982610b | 2007-03-11 22:49:34 +0100 | [diff] [blame] | 147 | u32 immediate; |
| 148 | u32 csr_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | struct csr1212_leaf leaf; |
| 150 | struct csr1212_directory directory; |
| 151 | } value; |
| 152 | struct csr1212_keyval *associate; |
Stefan Richter | 17a19b7 | 2007-09-15 14:50:25 +0200 | [diff] [blame] | 153 | atomic_t refcnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
| 155 | /* used in generating and/or parsing CSR image */ |
| 156 | struct csr1212_keyval *next, *prev; /* flat list of CSR elements */ |
Stefan Richter | 982610b | 2007-03-11 22:49:34 +0100 | [diff] [blame] | 157 | u32 offset; /* position in CSR from 0xffff f000 0000 */ |
| 158 | u8 valid; /* flag indicating keyval has valid data*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | |
| 162 | struct csr1212_cache_region { |
| 163 | struct csr1212_cache_region *next, *prev; |
Stefan Richter | 982610b | 2007-03-11 22:49:34 +0100 | [diff] [blame] | 164 | u32 offset_start; /* inclusive */ |
| 165 | u32 offset_end; /* exclusive */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | struct csr1212_csr_rom_cache { |
| 169 | struct csr1212_csr_rom_cache *next, *prev; |
| 170 | struct csr1212_cache_region *filled_head, *filled_tail; |
| 171 | struct csr1212_keyval *layout_head, *layout_tail; |
| 172 | size_t size; |
Stefan Richter | 982610b | 2007-03-11 22:49:34 +0100 | [diff] [blame] | 173 | u32 offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | struct csr1212_keyval *ext_rom; |
| 175 | size_t len; |
| 176 | |
| 177 | /* Must be last */ |
Stefan Richter | 982610b | 2007-03-11 22:49:34 +0100 | [diff] [blame] | 178 | u32 data[0]; /* older gcc can't handle [] which is standard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | }; |
| 180 | |
| 181 | struct csr1212_csr { |
| 182 | size_t bus_info_len; /* bus info block length in bytes */ |
| 183 | size_t crc_len; /* crc length in bytes */ |
Harvey Harrison | debb480 | 2008-12-13 15:02:34 -0800 | [diff] [blame] | 184 | __be32 *bus_info_data; /* bus info data incl bus name and EUI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
| 186 | void *private; /* private, bus specific data */ |
| 187 | struct csr1212_bus_ops *ops; |
| 188 | |
| 189 | struct csr1212_keyval *root_kv; |
| 190 | |
| 191 | int max_rom; /* max bytes readable in Config ROM region */ |
| 192 | |
| 193 | /* Items below used for image parsing and generation */ |
| 194 | struct csr1212_csr_rom_cache *cache_head, *cache_tail; |
| 195 | }; |
| 196 | |
| 197 | struct csr1212_bus_ops { |
| 198 | /* This function is used by csr1212 to read additional information |
| 199 | * from remote nodes when parsing a Config ROM (i.e., read Config ROM |
| 200 | * entries located in the Units Space. Must return 0 on success |
| 201 | * anything else indicates an error. */ |
Stefan Richter | 982610b | 2007-03-11 22:49:34 +0100 | [diff] [blame] | 202 | int (*bus_read) (struct csr1212_csr *csr, u64 addr, |
Stefan Richter | 0bed181 | 2008-12-13 23:12:06 +0100 | [diff] [blame] | 203 | void *buffer, void *private); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
| 205 | /* This function is used by csr1212 to allocate a region in units space |
| 206 | * in the event that Config ROM entries don't all fit in the predefined |
| 207 | * 1K region. The void *private parameter is private member of struct |
| 208 | * csr1212_csr. */ |
Stefan Richter | 982610b | 2007-03-11 22:49:34 +0100 | [diff] [blame] | 209 | u64 (*allocate_addr_range) (u64 size, u32 alignment, void *private); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
| 211 | /* This function is used by csr1212 to release a region in units space |
| 212 | * that is no longer needed. */ |
Stefan Richter | 982610b | 2007-03-11 22:49:34 +0100 | [diff] [blame] | 213 | void (*release_addr) (u64 addr, void *private); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | }; |
| 215 | |
| 216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | /* Descriptor Leaf manipulation macros */ |
| 218 | #define CSR1212_DESCRIPTOR_LEAF_TYPE_SHIFT 24 |
| 219 | #define CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID_MASK 0xffffff |
Stefan Richter | 982610b | 2007-03-11 22:49:34 +0100 | [diff] [blame] | 220 | #define CSR1212_DESCRIPTOR_LEAF_OVERHEAD (1 * sizeof(u32)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
| 222 | #define CSR1212_DESCRIPTOR_LEAF_TYPE(kv) \ |
Stefan Richter | c868ae2 | 2007-03-14 00:26:38 +0100 | [diff] [blame] | 223 | (be32_to_cpu((kv)->value.leaf.data[0]) >> \ |
| 224 | CSR1212_DESCRIPTOR_LEAF_TYPE_SHIFT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | #define CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID(kv) \ |
Stefan Richter | 7fb9add | 2007-03-11 22:49:05 +0100 | [diff] [blame] | 226 | (be32_to_cpu((kv)->value.leaf.data[0]) & \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID_MASK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
| 230 | /* Text Descriptor Leaf manipulation macros */ |
| 231 | #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_SHIFT 28 |
| 232 | #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_MASK 0xf /* after shift */ |
| 233 | #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_SHIFT 16 |
| 234 | #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_MASK 0xfff /* after shift */ |
| 235 | #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE_MASK 0xffff |
Stefan Richter | 982610b | 2007-03-11 22:49:34 +0100 | [diff] [blame] | 236 | #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_OVERHEAD (1 * sizeof(u32)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
| 238 | #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH(kv) \ |
Stefan Richter | 7fb9add | 2007-03-11 22:49:05 +0100 | [diff] [blame] | 239 | (be32_to_cpu((kv)->value.leaf.data[1]) >> \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH_SHIFT) |
| 241 | #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET(kv) \ |
Stefan Richter | 7fb9add | 2007-03-11 22:49:05 +0100 | [diff] [blame] | 242 | ((be32_to_cpu((kv)->value.leaf.data[1]) >> \ |
| 243 | CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_SHIFT) & \ |
| 244 | CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET_MASK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE(kv) \ |
Stefan Richter | 7fb9add | 2007-03-11 22:49:05 +0100 | [diff] [blame] | 246 | (be32_to_cpu((kv)->value.leaf.data[1]) & \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE_MASK) |
| 248 | #define CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA(kv) \ |
| 249 | (&((kv)->value.leaf.data[2])) |
| 250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | /* The following 2 function are for creating new Configuration ROM trees. The |
| 253 | * first function is used for both creating local trees and parsing remote |
| 254 | * trees. The second function adds pertinent information to local Configuration |
| 255 | * ROM trees - namely data for the bus information block. */ |
| 256 | extern struct csr1212_csr *csr1212_create_csr(struct csr1212_bus_ops *ops, |
| 257 | size_t bus_info_size, |
| 258 | void *private); |
| 259 | extern void csr1212_init_local_csr(struct csr1212_csr *csr, |
Stefan Richter | 982610b | 2007-03-11 22:49:34 +0100 | [diff] [blame] | 260 | const u32 *bus_info_data, int max_rom); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
| 262 | |
Stefan Richter | 6c88e47 | 2007-03-11 22:47:34 +0100 | [diff] [blame] | 263 | /* Destroy a Configuration ROM tree and release all memory taken by the tree. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | extern void csr1212_destroy_csr(struct csr1212_csr *csr); |
| 265 | |
| 266 | |
| 267 | /* The following set of functions are fore creating new keyvals for placement in |
| 268 | * a Configuration ROM tree. Code that creates new keyvals with these functions |
| 269 | * must release those keyvals with csr1212_release_keyval() when they are no |
| 270 | * longer needed. */ |
Stefan Richter | 982610b | 2007-03-11 22:49:34 +0100 | [diff] [blame] | 271 | extern struct csr1212_keyval *csr1212_new_immediate(u8 key, u32 value); |
| 272 | extern struct csr1212_keyval *csr1212_new_directory(u8 key); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | extern struct csr1212_keyval *csr1212_new_string_descriptor_leaf(const char *s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
| 275 | |
Stefan Richter | 6c88e47 | 2007-03-11 22:47:34 +0100 | [diff] [blame] | 276 | /* The following function manages association between keyvals. Typically, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | * Descriptor Leaves and Directories will be associated with another keyval and |
| 278 | * it is desirable for the Descriptor keyval to be place immediately after the |
Stefan Richter | 6c88e47 | 2007-03-11 22:47:34 +0100 | [diff] [blame] | 279 | * keyval that it is associated with. |
| 280 | * Take care with subsequent ROM modifications: There is no function to remove |
| 281 | * previously specified associations. |
| 282 | */ |
Stefan Richter | 64ff712 | 2007-03-11 22:50:13 +0100 | [diff] [blame] | 283 | extern void csr1212_associate_keyval(struct csr1212_keyval *kv, |
| 284 | struct csr1212_keyval *associate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | |
| 287 | /* The following functions manage the association of a keyval and directories. |
| 288 | * A keyval may be attached to more than one directory. */ |
| 289 | extern int csr1212_attach_keyval_to_directory(struct csr1212_keyval *dir, |
| 290 | struct csr1212_keyval *kv); |
| 291 | extern void csr1212_detach_keyval_from_directory(struct csr1212_keyval *dir, |
| 292 | struct csr1212_keyval *kv); |
| 293 | |
| 294 | |
Stefan Richter | 6c88e47 | 2007-03-11 22:47:34 +0100 | [diff] [blame] | 295 | /* Creates a complete Configuration ROM image in the list of caches available |
| 296 | * via csr->cache_head. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | extern int csr1212_generate_csr_image(struct csr1212_csr *csr); |
| 298 | |
| 299 | |
| 300 | /* This is a convience function for reading a block of data out of one of the |
| 301 | * caches in the csr->cache_head list. */ |
Stefan Richter | 982610b | 2007-03-11 22:49:34 +0100 | [diff] [blame] | 302 | extern int csr1212_read(struct csr1212_csr *csr, u32 offset, void *buffer, |
| 303 | u32 len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
| 305 | |
| 306 | /* The following functions are in place for parsing Configuration ROM images. |
| 307 | * csr1212_parse_keyval() is used should there be a need to directly parse a |
| 308 | * Configuration ROM directly. */ |
| 309 | extern int csr1212_parse_keyval(struct csr1212_keyval *kv, |
| 310 | struct csr1212_csr_rom_cache *cache); |
| 311 | extern int csr1212_parse_csr(struct csr1212_csr *csr); |
| 312 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
| 314 | /* This function allocates a new cache which may be used for either parsing or |
| 315 | * generating sub-sets of Configuration ROM images. */ |
Stefan Richter | c1a37f2 | 2007-03-14 00:20:53 +0100 | [diff] [blame] | 316 | static inline struct csr1212_csr_rom_cache * |
| 317 | csr1212_rom_cache_malloc(u32 offset, size_t size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | { |
| 319 | struct csr1212_csr_rom_cache *cache; |
| 320 | |
Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 321 | cache = CSR1212_MALLOC(sizeof(*cache) + size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | if (!cache) |
| 323 | return NULL; |
| 324 | |
| 325 | cache->next = NULL; |
| 326 | cache->prev = NULL; |
| 327 | cache->filled_head = NULL; |
| 328 | cache->filled_tail = NULL; |
| 329 | cache->layout_head = NULL; |
| 330 | cache->layout_tail = NULL; |
| 331 | cache->offset = offset; |
| 332 | cache->size = size; |
| 333 | cache->ext_rom = NULL; |
| 334 | |
| 335 | return cache; |
| 336 | } |
| 337 | |
| 338 | |
| 339 | /* This function ensures that a keyval contains data when referencing a keyval |
| 340 | * created by parsing a Configuration ROM. */ |
Stefan Richter | c1a37f2 | 2007-03-14 00:20:53 +0100 | [diff] [blame] | 341 | extern struct csr1212_keyval * |
| 342 | csr1212_get_keyval(struct csr1212_csr *csr, struct csr1212_keyval *kv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
| 344 | |
| 345 | /* This function increments the reference count for a keyval should there be a |
| 346 | * need for code to retain a keyval that has been parsed. */ |
| 347 | static inline void csr1212_keep_keyval(struct csr1212_keyval *kv) |
| 348 | { |
Stefan Richter | 17a19b7 | 2007-09-15 14:50:25 +0200 | [diff] [blame] | 349 | atomic_inc(&kv->refcnt); |
| 350 | smp_mb__after_atomic_inc(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | |
| 354 | /* This function decrements a keyval's reference count and will destroy the |
| 355 | * keyval when there are no more users of the keyval. This should be called by |
| 356 | * any code that calls csr1212_keep_keyval() or any of the keyval creation |
| 357 | * routines csr1212_new_*(). */ |
Stefan Richter | c1a37f2 | 2007-03-14 00:20:53 +0100 | [diff] [blame] | 358 | extern void csr1212_release_keyval(struct csr1212_keyval *kv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
| 360 | |
| 361 | /* |
| 362 | * This macro allows for looping over the keyval entries in a directory and it |
| 363 | * ensures that keyvals from remote ConfigROMs are parsed properly. |
| 364 | * |
Stefan Richter | c868ae2 | 2007-03-14 00:26:38 +0100 | [diff] [blame] | 365 | * struct csr1212_csr *_csr points to the CSR associated with dir. |
| 366 | * struct csr1212_keyval *_kv points to the current keyval (loop index). |
| 367 | * struct csr1212_keyval *_dir points to the directory to be looped. |
| 368 | * struct csr1212_dentry *_pos is used internally for indexing. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | * |
| 370 | * kv will be NULL upon exit of the loop. |
| 371 | */ |
Stefan Richter | c868ae2 | 2007-03-14 00:26:38 +0100 | [diff] [blame] | 372 | #define csr1212_for_each_dir_entry(_csr, _kv, _dir, _pos) \ |
| 373 | for (csr1212_get_keyval((_csr), (_dir)), \ |
| 374 | _pos = (_dir)->value.directory.dentries_head, \ |
| 375 | _kv = (_pos) ? csr1212_get_keyval((_csr), _pos->kv) : NULL;\ |
| 376 | (_kv) && (_pos); \ |
| 377 | (_kv->associate == NULL) ? \ |
| 378 | ((_pos = _pos->next), (_kv = (_pos) ? \ |
| 379 | csr1212_get_keyval((_csr), _pos->kv) : \ |
| 380 | NULL)) : \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | (_kv = csr1212_get_keyval((_csr), _kv->associate))) |
| 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | #endif /* __CSR1212_H__ */ |