[cavium-octeon] add support for the Cavium Octeon SoC, tested on a Mototech evaluatio...
[openwrt.git] / target / linux / cavium-octeon / patches / 004-named_alloc_function.patch
1 The MGMT ethernet driver uses these new functions.
2
3 Signed-off-by: David Daney <ddaney@caviumnetworks.com>
4 ---
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(-)
8
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);
15 }
16
17 +void *cvmx_bootmem_alloc_named_range(uint64_t size, uint64_t min_addr,
18 + uint64_t max_addr, uint64_t align,
19 + char *name)
20 +{
21 + int64_t addr;
22 +
23 + addr = cvmx_bootmem_phy_named_block_alloc(size, min_addr, max_addr,
24 + align, name, 0);
25 + if (addr >= 0)
26 + return cvmx_phys_to_ptr(addr);
27 + else
28 + return NULL;
29 +}
30 +
31 +void *cvmx_bootmem_alloc_named_address(uint64_t size, uint64_t address,
32 + char *name)
33 +{
34 + return cvmx_bootmem_alloc_named_range(size, address, address + size,
35 + 0, name);
36 +}
37 +
38 +void *cvmx_bootmem_alloc_named(uint64_t size, uint64_t alignment, char *name)
39 +{
40 + return cvmx_bootmem_alloc_named_range(size, 0, 0, alignment, name);
41 +}
42 +
43 int cvmx_bootmem_free_named(char *name)
44 {
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 */
49 }
50 +
51 +int64_t cvmx_bootmem_phy_named_block_alloc(uint64_t size, uint64_t min_addr,
52 + uint64_t max_addr,
53 + uint64_t alignment,
54 + char *name,
55 + uint32_t flags)
56 +{
57 + int64_t addr_allocated;
58 + struct cvmx_bootmem_named_block_desc *named_block_desc_ptr;
59 +
60 +#ifdef DEBUG
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,
67 + name);
68 +#endif
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,
74 + cvmx_bootmem_desc);
75 + return -1;
76 + }
77 +
78 + /*
79 + * Take lock here, as name lookup/block alloc/name add need to
80 + * be atomic.
81 + */
82 + if (!(flags & CVMX_BOOTMEM_FLAG_NO_LOCKING))
83 + cvmx_spinlock_lock((cvmx_spinlock_t *)&(cvmx_bootmem_desc->lock));
84 +
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);
89 +
90 + /*
91 + * Check to see if name already in use, return error if name
92 + * not available or no more room for blocks.
93 + */
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));
98 + return -1;
99 + }
100 +
101 +
102 + /*
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.
107 + */
108 + size = __ALIGN_MASK(size, (CVMX_BOOTMEM_ALIGNMENT_SIZE - 1));
109 +
110 + addr_allocated = cvmx_bootmem_phy_alloc(size, min_addr, max_addr,
111 + alignment,
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;
119 + }
120 +
121 + if (!(flags & CVMX_BOOTMEM_FLAG_NO_LOCKING))
122 + cvmx_spinlock_unlock((cvmx_spinlock_t *)&(cvmx_bootmem_desc->lock));
123 + return addr_allocated;
124 +}
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,
131 * !0 on success
132 */
133 +
134 +
135 +/**
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.
140 + *
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
144 + *
145 + * Returns a pointer to block of memory, NULL on error
146 + */
147 +extern void *cvmx_bootmem_alloc_named(uint64_t size, uint64_t alignment,
148 + char *name);
149 +
150 +
151 +
152 +/**
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.
157 + *
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
162 + * bytes
163 + *
164 + * Returns a pointer to block of memory, NULL on error
165 + */
166 +extern void *cvmx_bootmem_alloc_named_address(uint64_t size, uint64_t address,
167 + char *name);
168 +
169 +
170 +
171 +/**
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
178 + *
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
184 + *
185 + * Returns a pointer to block of memory, NULL on error
186 + */
187 +extern void *cvmx_bootmem_alloc_named_range(uint64_t size, uint64_t min_addr,
188 + uint64_t max_addr, uint64_t align,
189 + char *name);
190 +
191 extern int cvmx_bootmem_free_named(char *name);
192
193 /**
194 @@ -224,6 +282,33 @@ int64_t cvmx_bootmem_phy_alloc(uint64_t req_size, uint64_t address_min,
195 uint32_t flags);
196
197 /**
198 + * Allocates a named block of physical memory from the free list, at
199 + * (optional) requested address and alignment.
200 + *
201 + * @param size size of region to allocate. All requests are rounded
202 + * up to be a multiple CVMX_BOOTMEM_ALIGNMENT_SIZE
203 + * bytes 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.
216 + *
217 + * @return physical address of block allocated, or -1 on failure
218 + */
219 +int64_t cvmx_bootmem_phy_named_block_alloc(uint64_t size, uint64_t min_addr,
220 + uint64_t max_addr,
221 + uint64_t alignment,
222 + char *name, uint32_t flags);
223 +
224 +/**
225 * Finds a named memory block by name.
226 * Also used for finding an unused entry in the named block table.
227 *
228 --
229 1.5.6.5
230
231 --
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
This page took 0.054947 seconds and 5 git commands to generate.