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 diff --git a/arch/mips/cavium-octeon/executive/cvmx-bootmem.c b/arch/mips/cavium-octeon/executive/cvmx-bootmem.c
10 index 4f5a08b..8972448 100644
11 --- a/arch/mips/cavium-octeon/executive/cvmx-bootmem.c
12 +++ b/arch/mips/cavium-octeon/executive/cvmx-bootmem.c
13 @@ -97,6 +97,32 @@ void *cvmx_bootmem_alloc(uint64_t size, uint64_t alignment)
14 return cvmx_bootmem_alloc_range(size, alignment, 0, 0);
17 +void *cvmx_bootmem_alloc_named_range(uint64_t size, uint64_t min_addr,
18 + uint64_t max_addr, uint64_t align,
23 + addr = cvmx_bootmem_phy_named_block_alloc(size, min_addr, max_addr,
26 + return cvmx_phys_to_ptr(addr);
31 +void *cvmx_bootmem_alloc_named_address(uint64_t size, uint64_t address,
34 + return cvmx_bootmem_alloc_named_range(size, address, address + size,
38 +void *cvmx_bootmem_alloc_named(uint64_t size, uint64_t alignment, char *name)
40 + return cvmx_bootmem_alloc_named_range(size, 0, 0, alignment, name);
43 int cvmx_bootmem_free_named(char *name)
45 return cvmx_bootmem_phy_named_block_free(name, 0);
46 @@ -584,3 +610,78 @@ int cvmx_bootmem_phy_named_block_free(char *name, uint32_t flags)
47 cvmx_bootmem_unlock();
48 return named_block_ptr != NULL; /* 0 on failure, 1 on success */
51 +int64_t cvmx_bootmem_phy_named_block_alloc(uint64_t size, uint64_t min_addr,
57 + int64_t addr_allocated;
58 + struct cvmx_bootmem_named_block_desc *named_block_desc_ptr;
61 + cvmx_dprintf("cvmx_bootmem_phy_named_block_alloc: size: 0x%llx, min: "
62 + "0x%llx, max: 0x%llx, align: 0x%llx, name: %s\n",
63 + (unsigned long long)size,
64 + (unsigned long long)min_addr,
65 + (unsigned long long)max_addr,
66 + (unsigned long long)alignment,
69 + if (cvmx_bootmem_desc->major_version != 3) {
70 + cvmx_dprintf("ERROR: Incompatible bootmem descriptor version: "
71 + "%d.%d at addr: %p\n",
72 + (int)cvmx_bootmem_desc->major_version,
73 + (int)cvmx_bootmem_desc->minor_version,
79 + * Take lock here, as name lookup/block alloc/name add need to
82 + if (!(flags & CVMX_BOOTMEM_FLAG_NO_LOCKING))
83 + cvmx_spinlock_lock((cvmx_spinlock_t *)&(cvmx_bootmem_desc->lock));
85 + /* Get pointer to first available named block descriptor */
86 + named_block_desc_ptr =
87 + cvmx_bootmem_phy_named_block_find(NULL,
88 + flags | CVMX_BOOTMEM_FLAG_NO_LOCKING);
91 + * Check to see if name already in use, return error if name
92 + * not available or no more room for blocks.
94 + if (cvmx_bootmem_phy_named_block_find(name,
95 + flags | CVMX_BOOTMEM_FLAG_NO_LOCKING) || !named_block_desc_ptr) {
96 + if (!(flags & CVMX_BOOTMEM_FLAG_NO_LOCKING))
97 + cvmx_spinlock_unlock((cvmx_spinlock_t *)&(cvmx_bootmem_desc->lock));
103 + * Round size up to mult of minimum alignment bytes We need
104 + * the actual size allocated to allow for blocks to be
105 + * coallesced when they are freed. The alloc routine does the
106 + * same rounding up on all allocations.
108 + size = __ALIGN_MASK(size, (CVMX_BOOTMEM_ALIGNMENT_SIZE - 1));
110 + addr_allocated = cvmx_bootmem_phy_alloc(size, min_addr, max_addr,
112 + flags | CVMX_BOOTMEM_FLAG_NO_LOCKING);
113 + if (addr_allocated >= 0) {
114 + named_block_desc_ptr->base_addr = addr_allocated;
115 + named_block_desc_ptr->size = size;
116 + strncpy(named_block_desc_ptr->name, name,
117 + cvmx_bootmem_desc->named_block_name_len);
118 + named_block_desc_ptr->name[cvmx_bootmem_desc->named_block_name_len - 1] = 0;
121 + if (!(flags & CVMX_BOOTMEM_FLAG_NO_LOCKING))
122 + cvmx_spinlock_unlock((cvmx_spinlock_t *)&(cvmx_bootmem_desc->lock));
123 + return addr_allocated;
125 diff --git a/arch/mips/include/asm/octeon/cvmx-bootmem.h b/arch/mips/include/asm/octeon/cvmx-bootmem.h
126 index 1cbe4b5..8e708bd 100644
127 --- a/arch/mips/include/asm/octeon/cvmx-bootmem.h
128 +++ b/arch/mips/include/asm/octeon/cvmx-bootmem.h
129 @@ -183,6 +183,64 @@ extern void *cvmx_bootmem_alloc_range(uint64_t size, uint64_t alignment,
130 * Returns 0 on failure,
136 + * Allocate a block of memory from the free list that was passed
137 + * to the application by the bootloader, and assign it a name in the
138 + * global named block table. (part of the cvmx_bootmem_descriptor_t structure)
139 + * Named blocks can later be freed.
141 + * @size: Size in bytes of block to allocate
142 + * @alignment: Alignment required - must be power of 2
143 + * @name: name of block - must be less than CVMX_BOOTMEM_NAME_LEN bytes
145 + * Returns a pointer to block of memory, NULL on error
147 +extern void *cvmx_bootmem_alloc_named(uint64_t size, uint64_t alignment,
153 + * Allocate a block of memory from the free list that was passed
154 + * to the application by the bootloader, and assign it a name in the
155 + * global named block table. (part of the cvmx_bootmem_descriptor_t structure)
156 + * Named blocks can later be freed.
158 + * @size: Size in bytes of block to allocate
159 + * @address: Physical address to allocate memory at. If this
160 + * memory is not available, the allocation fails.
161 + * @name: name of block - must be less than CVMX_BOOTMEM_NAME_LEN
164 + * Returns a pointer to block of memory, NULL on error
166 +extern void *cvmx_bootmem_alloc_named_address(uint64_t size, uint64_t address,
172 + * Allocate a block of memory from a specific range of the free list
173 + * that was passed to the application by the bootloader, and assign it
174 + * a name in the global named block table. (part of the
175 + * cvmx_bootmem_descriptor_t structure) Named blocks can later be
176 + * freed. If request cannot be satisfied within the address range
177 + * specified, NULL is returned
179 + * @size: Size in bytes of block to allocate
180 + * @min_addr: minimum address of range
181 + * @max_addr: maximum address of range
182 + * @align: Alignment of memory to be allocated. (must be a power of 2)
183 + * @name: name of block - must be less than CVMX_BOOTMEM_NAME_LEN bytes
185 + * Returns a pointer to block of memory, NULL on error
187 +extern void *cvmx_bootmem_alloc_named_range(uint64_t size, uint64_t min_addr,
188 + uint64_t max_addr, uint64_t align,
191 extern int cvmx_bootmem_free_named(char *name);
194 @@ -224,6 +282,33 @@ int64_t cvmx_bootmem_phy_alloc(uint64_t req_size, uint64_t address_min,
198 + * Allocates a named block of physical memory from the free list, at
199 + * (optional) requested address and alignment.
201 + * @param size size of region to allocate. All requests are rounded
202 + * up to be a multiple CVMX_BOOTMEM_ALIGNMENT_SIZE
204 + * @param min_addr Minimum address that block can occupy.
205 + * @param max_addr Specifies the maximum address_min (inclusive) that
206 + * the allocation can use.
207 + * @param alignment Requested alignment of the block. If this
208 + * alignment cannot be met, the allocation fails.
209 + * This must be a power of 2. (Note: Alignment of
210 + * CVMX_BOOTMEM_ALIGNMENT_SIZE bytes is required, and
211 + * internally enforced. Requested alignments of less
212 + * than CVMX_BOOTMEM_ALIGNMENT_SIZE are set to
213 + * CVMX_BOOTMEM_ALIGNMENT_SIZE.)
214 + * @param name name to assign to named block
215 + * @param flags Flags to control options for the allocation.
217 + * @return physical address of block allocated, or -1 on failure
219 +int64_t cvmx_bootmem_phy_named_block_alloc(uint64_t size, uint64_t min_addr,
221 + uint64_t alignment,
222 + char *name, uint32_t flags);
225 * Finds a named memory block by name.
226 * Also used for finding an unused entry in the named block table.
232 To unsubscribe from this list: send the line "unsubscribe netdev" in
233 the body of a message to majordomo@vger.kernel.org
234 More majordomo info at http://vger.kernel.org/majordomo-info.html