1 /***********************license start********* 1 2 * Author: Cavium Networks 3 * 4 * Contact: support@caviumnetworks.com 5 * This file is part of the OCTEON SDK 6 * 7 * Copyright (c) 2003-2008 Cavium Networks 8 * 9 * This file is free software; you can redistr 10 * it under the terms of the GNU General Publi 11 * published by the Free Software Foundation. 12 * 13 * This file is distributed in the hope that i 14 * AS-IS and WITHOUT ANY WARRANTY; without eve 15 * of MERCHANTABILITY or FITNESS FOR A PARTICU 16 * NONINFRINGEMENT. See the GNU General Publi 17 * details. 18 * 19 * You should have received a copy of the GNU 20 * along with this file; if not, write to the 21 * Foundation, Inc., 51 Franklin St, Fifth Flo 22 * or visit http://www.gnu.org/licenses/. 23 * 24 * This file may also be available under a dif 25 * Contact Cavium Networks for more informatio 26 ***********************license end*********** 27 28 /* 29 * Simple allocate only memory allocator. Use 30 * application start time. 31 */ 32 33 #ifndef __CVMX_BOOTMEM_H__ 34 #define __CVMX_BOOTMEM_H__ 35 /* Must be multiple of 8, changing breaks ABI 36 #define CVMX_BOOTMEM_NAME_LEN 128 37 38 /* Can change without breaking ABI */ 39 #define CVMX_BOOTMEM_NUM_NAMED_BLOCKS 64 40 41 /* minimum alignment of bootmem alloced blocks 42 #define CVMX_BOOTMEM_ALIGNMENT_SIZE (16ull 43 44 /* Flags for cvmx_bootmem_phy_mem* functions * 45 /* Allocate from end of block instead of begin 46 #define CVMX_BOOTMEM_FLAG_END_ALLOC (1 << 0 47 48 /* Don't do any locking. */ 49 #define CVMX_BOOTMEM_FLAG_NO_LOCKING (1 << 1 50 51 /* First bytes of each free physical block of 52 * which is used to maintain the free memory l 53 * only 32 bits, there is a union providing 64 54 * application init code converts addresses to 55 * application starts. 56 */ 57 struct cvmx_bootmem_block_header { 58 /* 59 * Note: these are referenced from ass 60 * bootloader, so this structure shoul 61 * without changing those routines as 62 */ 63 uint64_t next_block_addr; 64 uint64_t size; 65 66 }; 67 68 /* 69 * Structure for named memory blocks. Number 70 * can be changed without affecting compatibil 71 * changes require a bump in the bootmem descr 72 * structure must be naturally 64 bit aligned, 73 * image will be used by both 32 and 64 bit pr 74 */ 75 struct cvmx_bootmem_named_block_desc { 76 /* Base address of named block */ 77 uint64_t base_addr; 78 /* 79 * Size actually allocated for named b 80 * requested). 81 */ 82 uint64_t size; 83 /* name of named block */ 84 char name[CVMX_BOOTMEM_NAME_LEN]; 85 }; 86 87 /* Current descriptor versions */ 88 /* CVMX bootmem descriptor major version */ 89 #define CVMX_BOOTMEM_DESC_MAJ_VER 3 90 91 /* CVMX bootmem descriptor minor version */ 92 #define CVMX_BOOTMEM_DESC_MIN_VER 0 93 94 /* First three members of cvmx_bootmem_desc_t 95 * positions for backwards compatibility. 96 */ 97 struct cvmx_bootmem_desc { 98 #if defined(__BIG_ENDIAN_BITFIELD) || defined( 99 /* spinlock to control access to list 100 uint32_t lock; 101 /* flags for indicating various condit 102 uint32_t flags; 103 uint64_t head_addr; 104 105 /* Incremented when incompatible chang 106 uint32_t major_version; 107 108 /* 109 * Incremented changed when compatible 110 * zero when major incremented. 111 */ 112 uint32_t minor_version; 113 114 uint64_t app_data_addr; 115 uint64_t app_data_size; 116 117 /* number of elements in named blocks 118 uint32_t named_block_num_blocks; 119 120 /* length of name array in bootmem blo 121 uint32_t named_block_name_len; 122 /* address of named memory block descr 123 uint64_t named_block_array_addr; 124 #else /* __LITTLE_EN 125 uint32_t flags; 126 uint32_t lock; 127 uint64_t head_addr; 128 129 uint32_t minor_version; 130 uint32_t major_version; 131 uint64_t app_data_addr; 132 uint64_t app_data_size; 133 134 uint32_t named_block_name_len; 135 uint32_t named_block_num_blocks; 136 uint64_t named_block_array_addr; 137 #endif 138 }; 139 140 /** 141 * Initialize the boot alloc memory structures 142 * normally called inside of cvmx_user_app_ini 143 * 144 * @mem_desc_ptr: Address of the free me 145 */ 146 extern int cvmx_bootmem_init(void *mem_desc_pt 147 148 /** 149 * Allocate a block of memory from the free li 150 * passed to the application by the bootloader 151 * address. This is an allocate-only algorithm 152 * freeing memory is not possible. Allocation 153 * memory cannot be allocated at the specified 154 * 155 * @size: Size in bytes of block to alloc 156 * @address: Physical address to allocate me 157 * available, the allocation 158 * @alignment: Alignment required - must be po 159 * Returns pointer to block of memory, NULL on 160 */ 161 extern void *cvmx_bootmem_alloc_address(uint64 162 uint64 163 164 /** 165 * Frees a previously allocated named bootmem 166 * 167 * @name: name of block to free 168 * 169 * Returns 0 on failure, 170 * !0 on success 171 */ 172 173 174 /** 175 * Allocate a block of memory from the free li 176 * to the application by the bootloader, and a 177 * global named block table. (part of the cvm 178 * Named blocks can later be freed. 179 * 180 * @size: Size in bytes of block to alloc 181 * @alignment: Alignment required - must be po 182 * @name: name of block - must be less th 183 * 184 * Returns a pointer to block of memory, NULL 185 */ 186 extern void *cvmx_bootmem_alloc_named(uint64_t 187 char *na 188 189 /** 190 * Allocate a block of memory from a specific 191 * that was passed to the application by the b 192 * a name in the global named block table. (p 193 * cvmx_bootmem_descriptor_t structure) Named 194 * freed. If request cannot be satisfied with 195 * specified, NULL is returned 196 * 197 * @size: Size in bytes of block to alloc 198 * @min_addr: minimum address of range 199 * @max_addr: maximum address of range 200 * @align: Alignment of memory to be alloc 201 * @name: name of block - must be less th 202 * 203 * Returns a pointer to block of memory, NULL 204 */ 205 extern void *cvmx_bootmem_alloc_named_range(ui 206 ui 207 ch 208 209 /** 210 * Allocate if needed a block of memory from a 211 * free list that was passed to the applicatio 212 * assign it a name in the global named block 213 * cvmx_bootmem_descriptor_t structure) Named 214 * freed. If the requested name block is alre 215 * the pointer to block of memory. If request 216 * within the address range specified, NULL is 217 * 218 * @param size Size in bytes of block to all 219 * @param min_addr minimum address of range 220 * @param max_addr maximum address of range 221 * @param align Alignment of memory to be all 222 * @param name name of block - must be less 223 * @param init Initialization function 224 * 225 * The initialization function is optional, if 226 * is initialized to all zeros when it is crea 227 * 228 * @return pointer to block of memory, NULL on 229 */ 230 void *cvmx_bootmem_alloc_named_range_once(uint 231 uint 232 uint 233 uint 234 char 235 void 236 237 extern int cvmx_bootmem_free_named(char *name) 238 239 /** 240 * Finds a named bootmem block by name. 241 * 242 * @name: name of block to free 243 * 244 * Returns pointer to named block descriptor o 245 * 0 on failure 246 */ 247 struct cvmx_bootmem_named_block_desc *cvmx_boo 248 249 /** 250 * Allocates a block of physical memory from t 251 * (optional) requested address and alignment. 252 * 253 * @req_size: size of region to allocate. All 254 * to be a multiple CVMX_BOOTMEM_AL 255 * 256 * @address_min: Minimum address that block ca 257 * 258 * @address_max: Specifies the maximum address 259 * the allocation can use. 260 * 261 * @alignment: Requested alignment of the bloc 262 * cannot be met, the allocation f 263 * power of 2. (Note: Alignment o 264 * CVMX_BOOTMEM_ALIGNMENT_SIZE byt 265 * internally enforced. Requested 266 * CVMX_BOOTMEM_ALIGNMENT_SIZE are 267 * CVMX_BOOTMEM_ALIGNMENT_SIZE.) 268 * 269 * @flags: Flags to control options for th 270 * 271 * Returns physical address of block allocated 272 */ 273 int64_t cvmx_bootmem_phy_alloc(uint64_t req_si 274 uint64_t addres 275 uint32_t flags) 276 277 /** 278 * Allocates a named block of physical memory 279 * (optional) requested address and alignment. 280 * 281 * @param size size of region to allocate 282 * up to be a multiple CVMX_B 283 * bytes size 284 * @param min_addr Minimum address that block 285 * @param max_addr Specifies the maximum addr 286 * the allocation can use. 287 * @param alignment Requested alignment of the 288 * alignment cannot be met, t 289 * This must be a power of 2. 290 * CVMX_BOOTMEM_ALIGNMENT_SIZ 291 * internally enforced. Requ 292 * than CVMX_BOOTMEM_ALIGNMEN 293 * CVMX_BOOTMEM_ALIGNMENT_SIZ 294 * @param name name to assign to named bl 295 * @param flags Flags to control options f 296 * 297 * @return physical address of block allocated 298 */ 299 int64_t cvmx_bootmem_phy_named_block_alloc(uin 300 uin 301 uin 302 cha 303 304 /** 305 * Frees a block to the bootmem allocator list 306 * be used with care, as the size provided mus 307 * of the block that was allocated, or the lis 308 * corrupted. 309 * 310 * IMPORTANT: This is only intended to be use 311 * frees and initial population of the free me 312 * 313 * 314 * @phy_addr: physical address of block 315 * @size: size of block in bytes. 316 * @flags: flags for passing options 317 * 318 * Returns 1 on success, 319 * 0 on failure 320 */ 321 int __cvmx_bootmem_phy_free(uint64_t phy_addr, 322 323 /** 324 * Locks the bootmem allocator. This is usefu 325 * where multiple allocations must be made wit 326 * This should be used with the CVMX_BOOTMEM_F 327 * 328 */ 329 void cvmx_bootmem_lock(void); 330 331 /** 332 * Unlocks the bootmem allocator. This is use 333 * where multiple allocations must be made wit 334 * This should be used with the CVMX_BOOTMEM_F 335 * 336 */ 337 void cvmx_bootmem_unlock(void); 338 339 extern struct cvmx_bootmem_desc *cvmx_bootmem_ 340 341 #endif /* __CVMX_BOOTMEM_H__ */ 342
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.