1 The MGMT ethernet driver uses these new functions.
3 Signed-off-by: David Daney <ddaney@caviumnetworks.com>
5 arch/mips/cavium-octeon/executive/cvmx-bootmem.c | 101 ++++++++++++++++++++++
6 arch/mips/include/asm/octeon/cvmx-bootmem.h | 85 ++++++++++++++++++
7 2 files changed, 186 insertions(+), 0 deletions(-)
9 --- a/arch/mips/cavium-octeon/executive/cvmx-bootmem.c
10 +++ b/arch/mips/cavium-octeon/executive/cvmx-bootmem.c
11 @@ -97,6 +97,32 @@ void *cvmx_bootmem_alloc(uint64_t size,
12 return cvmx_bootmem_alloc_range(size, alignment, 0, 0);
15 +void *cvmx_bootmem_alloc_named_range(uint64_t size, uint64_t min_addr,
16 + uint64_t max_addr, uint64_t align,
21 + addr = cvmx_bootmem_phy_named_block_alloc(size, min_addr, max_addr,
24 + return cvmx_phys_to_ptr(addr);
29 +void *cvmx_bootmem_alloc_named_address(uint64_t size, uint64_t address,
32 + return cvmx_bootmem_alloc_named_range(size, address, address + size,
36 +void *cvmx_bootmem_alloc_named(uint64_t size, uint64_t alignment, char *name)
38 + return cvmx_bootmem_alloc_named_range(size, 0, 0, alignment, name);
41 int cvmx_bootmem_free_named(char *name)
43 return cvmx_bootmem_phy_named_block_free(name, 0);
44 @@ -584,3 +610,78 @@ int cvmx_bootmem_phy_named_block_free(ch
45 cvmx_bootmem_unlock();
46 return named_block_ptr != NULL; /* 0 on failure, 1 on success */
49 +int64_t cvmx_bootmem_phy_named_block_alloc(uint64_t size, uint64_t min_addr,
55 + int64_t addr_allocated;
56 + struct cvmx_bootmem_named_block_desc *named_block_desc_ptr;
59 + cvmx_dprintf("cvmx_bootmem_phy_named_block_alloc: size: 0x%llx, min: "
60 + "0x%llx, max: 0x%llx, align: 0x%llx, name: %s\n",
61 + (unsigned long long)size,
62 + (unsigned long long)min_addr,
63 + (unsigned long long)max_addr,
64 + (unsigned long long)alignment,
67 + if (cvmx_bootmem_desc->major_version != 3) {
68 + cvmx_dprintf("ERROR: Incompatible bootmem descriptor version: "
69 + "%d.%d at addr: %p\n",
70 + (int)cvmx_bootmem_desc->major_version,
71 + (int)cvmx_bootmem_desc->minor_version,
77 + * Take lock here, as name lookup/block alloc/name add need to
80 + if (!(flags & CVMX_BOOTMEM_FLAG_NO_LOCKING))
81 + cvmx_spinlock_lock((cvmx_spinlock_t *)&(cvmx_bootmem_desc->lock));
83 + /* Get pointer to first available named block descriptor */
84 + named_block_desc_ptr =
85 + cvmx_bootmem_phy_named_block_find(NULL,
86 + flags | CVMX_BOOTMEM_FLAG_NO_LOCKING);
89 + * Check to see if name already in use, return error if name
90 + * not available or no more room for blocks.
92 + if (cvmx_bootmem_phy_named_block_find(name,
93 + flags | CVMX_BOOTMEM_FLAG_NO_LOCKING) || !named_block_desc_ptr) {
94 + if (!(flags & CVMX_BOOTMEM_FLAG_NO_LOCKING))
95 + cvmx_spinlock_unlock((cvmx_spinlock_t *)&(cvmx_bootmem_desc->lock));
101 + * Round size up to mult of minimum alignment bytes We need
102 + * the actual size allocated to allow for blocks to be
103 + * coallesced when they are freed. The alloc routine does the
104 + * same rounding up on all allocations.
106 + size = __ALIGN_MASK(size, (CVMX_BOOTMEM_ALIGNMENT_SIZE - 1));
108 + addr_allocated = cvmx_bootmem_phy_alloc(size, min_addr, max_addr,
110 + flags | CVMX_BOOTMEM_FLAG_NO_LOCKING);
111 + if (addr_allocated >= 0) {
112 + named_block_desc_ptr->base_addr = addr_allocated;
113 + named_block_desc_ptr->size = size;
114 + strncpy(named_block_desc_ptr->name, name,
115 + cvmx_bootmem_desc->named_block_name_len);
116 + named_block_desc_ptr->name[cvmx_bootmem_desc->named_block_name_len - 1] = 0;
119 + if (!(flags & CVMX_BOOTMEM_FLAG_NO_LOCKING))
120 + cvmx_spinlock_unlock((cvmx_spinlock_t *)&(cvmx_bootmem_desc->lock));
121 + return addr_allocated;
123 --- a/arch/mips/include/asm/octeon/cvmx-bootmem.h
124 +++ b/arch/mips/include/asm/octeon/cvmx-bootmem.h
125 @@ -183,6 +183,64 @@ extern void *cvmx_bootmem_alloc_range(ui
126 * Returns 0 on failure,
132 + * Allocate a block of memory from the free list that was passed
133 + * to the application by the bootloader, and assign it a name in the
134 + * global named block table. (part of the cvmx_bootmem_descriptor_t structure)
135 + * Named blocks can later be freed.
137 + * @size: Size in bytes of block to allocate
138 + * @alignment: Alignment required - must be power of 2
139 + * @name: name of block - must be less than CVMX_BOOTMEM_NAME_LEN bytes
141 + * Returns a pointer to block of memory, NULL on error
143 +extern void *cvmx_bootmem_alloc_named(uint64_t size, uint64_t alignment,
149 + * Allocate a block of memory from the free list that was passed
150 + * to the application by the bootloader, and assign it a name in the
151 + * global named block table. (part of the cvmx_bootmem_descriptor_t structure)
152 + * Named blocks can later be freed.
154 + * @size: Size in bytes of block to allocate
155 + * @address: Physical address to allocate memory at. If this
156 + * memory is not available, the allocation fails.
157 + * @name: name of block - must be less than CVMX_BOOTMEM_NAME_LEN
160 + * Returns a pointer to block of memory, NULL on error
162 +extern void *cvmx_bootmem_alloc_named_address(uint64_t size, uint64_t address,
168 + * Allocate a block of memory from a specific range of the free list
169 + * that was passed to the application by the bootloader, and assign it
170 + * a name in the global named block table. (part of the
171 + * cvmx_bootmem_descriptor_t structure) Named blocks can later be
172 + * freed. If request cannot be satisfied within the address range
173 + * specified, NULL is returned
175 + * @size: Size in bytes of block to allocate
176 + * @min_addr: minimum address of range
177 + * @max_addr: maximum address of range
178 + * @align: Alignment of memory to be allocated. (must be a power of 2)
179 + * @name: name of block - must be less than CVMX_BOOTMEM_NAME_LEN bytes
181 + * Returns a pointer to block of memory, NULL on error
183 +extern void *cvmx_bootmem_alloc_named_range(uint64_t size, uint64_t min_addr,
184 + uint64_t max_addr, uint64_t align,
187 extern int cvmx_bootmem_free_named(char *name);
190 @@ -224,6 +282,33 @@ int64_t cvmx_bootmem_phy_alloc(uint64_t
194 + * Allocates a named block of physical memory from the free list, at
195 + * (optional) requested address and alignment.
197 + * @param size size of region to allocate. All requests are rounded
198 + * up to be a multiple CVMX_BOOTMEM_ALIGNMENT_SIZE
200 + * @param min_addr Minimum address that block can occupy.
201 + * @param max_addr Specifies the maximum address_min (inclusive) that
202 + * the allocation can use.
203 + * @param alignment Requested alignment of the block. If this
204 + * alignment cannot be met, the allocation fails.
205 + * This must be a power of 2. (Note: Alignment of
206 + * CVMX_BOOTMEM_ALIGNMENT_SIZE bytes is required, and
207 + * internally enforced. Requested alignments of less
208 + * than CVMX_BOOTMEM_ALIGNMENT_SIZE are set to
209 + * CVMX_BOOTMEM_ALIGNMENT_SIZE.)
210 + * @param name name to assign to named block
211 + * @param flags Flags to control options for the allocation.
213 + * @return physical address of block allocated, or -1 on failure
215 +int64_t cvmx_bootmem_phy_named_block_alloc(uint64_t size, uint64_t min_addr,
217 + uint64_t alignment,
218 + char *name, uint32_t flags);
221 * Finds a named memory block by name.
222 * Also used for finding an unused entry in the named block table.