cvmx-bootmem.c revision 215990
1/***********************license start***************
2 * Copyright (c) 2003-2010  Cavium Networks (support@cavium.com). All rights
3 * reserved.
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 *   * Redistributions of source code must retain the above copyright
11 *     notice, this list of conditions and the following disclaimer.
12 *
13 *   * Redistributions in binary form must reproduce the above
14 *     copyright notice, this list of conditions and the following
15 *     disclaimer in the documentation and/or other materials provided
16 *     with the distribution.
17
18 *   * Neither the name of Cavium Networks nor the names of
19 *     its contributors may be used to endorse or promote products
20 *     derived from this software without specific prior written
21 *     permission.
22
23 * This Software, including technical data, may be subject to U.S. export  control
24 * laws, including the U.S. Export Administration Act and its  associated
25 * regulations, and may be subject to export or import  regulations in other
26 * countries.
27
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM  NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
39
40
41
42
43
44
45/**
46 * @file
47 * Simple allocate only memory allocator.  Used to allocate memory at application
48 * start time.
49 *
50 * <hr>$Revision: 52119 $<hr>
51 *
52 */
53#ifdef CVMX_BUILD_FOR_LINUX_KERNEL
54#include <linux/module.h>
55#include <asm/octeon/cvmx.h>
56#include <asm/octeon/cvmx-bootmem.h>
57#else
58#if !defined(__FreeBSD__) || !defined(_KERNEL)
59#include "executive-config.h"
60#endif
61#include "cvmx.h"
62#include "cvmx-bootmem.h"
63#endif
64typedef uint32_t cvmx_spinlock_t;
65
66
67//#define DEBUG
68
69#define ULL unsigned long long
70#undef	MAX
71#define MAX(a, b)  (((a) > (b)) ? (a) : (b))
72
73#undef	MIN
74#define MIN(a, b)  (((a) < (b)) ? (a) : (b))
75
76#define ALIGN_ADDR_UP(addr, align)     (((addr) + (~(align))) & (align))
77
78/**
79 * This is the physical location of a cvmx_bootmem_desc_t
80 * structure in Octeon's memory. Note that dues to addressing
81 * limits or runtime environment it might not be possible to
82 * create a C pointer to this structure.
83 */
84static CVMX_SHARED uint64_t cvmx_bootmem_desc_addr = 0;
85
86/**
87 * This macro returns the size of a member of a structure.
88 * Logically it is the same as "sizeof(s::field)" in C++, but
89 * C lacks the "::" operator.
90 */
91#define SIZEOF_FIELD(s, field) sizeof(((s*)NULL)->field)
92
93/**
94 * This macro returns a member of the cvmx_bootmem_desc_t
95 * structure. These members can't be directly addressed as
96 * they might be in memory not directly reachable. In the case
97 * where bootmem is compiled with LINUX_HOST, the structure
98 * itself might be located on a remote Octeon. The argument
99 * "field" is the member name of the cvmx_bootmem_desc_t to read.
100 * Regardless of the type of the field, the return type is always
101 * a uint64_t.
102 */
103#define CVMX_BOOTMEM_DESC_GET_FIELD(field)                          \
104    __cvmx_bootmem_desc_get(cvmx_bootmem_desc_addr,                 \
105        offsetof(cvmx_bootmem_desc_t, field),                       \
106        SIZEOF_FIELD(cvmx_bootmem_desc_t, field))
107
108/**
109 * This macro writes a member of the cvmx_bootmem_desc_t
110 * structure. These members can't be directly addressed as
111 * they might be in memory not directly reachable. In the case
112 * where bootmem is compiled with LINUX_HOST, the structure
113 * itself might be located on a remote Octeon. The argument
114 * "field" is the member name of the cvmx_bootmem_desc_t to write.
115 */
116#define CVMX_BOOTMEM_DESC_SET_FIELD(field, value)                   \
117    __cvmx_bootmem_desc_set(cvmx_bootmem_desc_addr,                 \
118        offsetof(cvmx_bootmem_desc_t, field),                       \
119        SIZEOF_FIELD(cvmx_bootmem_desc_t, field), value)
120
121/**
122 * This macro returns a member of the
123 * cvmx_bootmem_named_block_desc_t structure. These members can't
124 * be directly addressed as they might be in memory not directly
125 * reachable. In the case where bootmem is compiled with
126 * LINUX_HOST, the structure itself might be located on a remote
127 * Octeon. The argument "field" is the member name of the
128 * cvmx_bootmem_named_block_desc_t to read. Regardless of the type
129 * of the field, the return type is always a uint64_t. The "addr"
130 * parameter is the physical address of the structure.
131 */
132#define CVMX_BOOTMEM_NAMED_GET_FIELD(addr, field)                   \
133    __cvmx_bootmem_desc_get(addr,                                   \
134        offsetof(cvmx_bootmem_named_block_desc_t, field),           \
135        SIZEOF_FIELD(cvmx_bootmem_named_block_desc_t, field))
136
137/**
138 * This macro writes a member of the cvmx_bootmem_named_block_desc_t
139 * structure. These members can't be directly addressed as
140 * they might be in memory not directly reachable. In the case
141 * where bootmem is compiled with LINUX_HOST, the structure
142 * itself might be located on a remote Octeon. The argument
143 * "field" is the member name of the
144 * cvmx_bootmem_named_block_desc_t to write. The "addr" parameter
145 * is the physical address of the structure.
146 */
147#define CVMX_BOOTMEM_NAMED_SET_FIELD(addr, field, value)            \
148    __cvmx_bootmem_desc_set(addr,                                   \
149        offsetof(cvmx_bootmem_named_block_desc_t, field),           \
150        SIZEOF_FIELD(cvmx_bootmem_named_block_desc_t, field), value)
151
152/**
153 * This function is the implementation of the get macros defined
154 * for individual structure members. The argument are generated
155 * by the macros inorder to read only the needed memory.
156 *
157 * @param base   64bit physical address of the complete structure
158 * @param offset Offset from the beginning of the structure to the member being
159 *               accessed.
160 * @param size   Size of the structure member.
161 *
162 * @return Value of the structure member promoted into a uint64_t.
163 */
164static inline uint64_t __cvmx_bootmem_desc_get(uint64_t base, int offset, int size)
165{
166    base = (1ull << 63) | (base + offset);
167    switch (size)
168    {
169        case 4:
170            return cvmx_read64_uint32(base);
171        case 8:
172            return cvmx_read64_uint64(base);
173        default:
174            return 0;
175    }
176}
177
178/**
179 * This function is the implementation of the set macros defined
180 * for individual structure members. The argument are generated
181 * by the macros in order to write only the needed memory.
182 *
183 * @param base   64bit physical address of the complete structure
184 * @param offset Offset from the beginning of the structure to the member being
185 *               accessed.
186 * @param size   Size of the structure member.
187 * @param value  Value to write into the structure
188 */
189static inline void __cvmx_bootmem_desc_set(uint64_t base, int offset, int size, uint64_t value)
190{
191    base = (1ull << 63) | (base + offset);
192    switch (size)
193    {
194        case 4:
195            cvmx_write64_uint32(base, value);
196            break;
197        case 8:
198            cvmx_write64_uint64(base, value);
199            break;
200        default:
201            break;
202    }
203}
204
205/**
206 * This function retrieves the string name of a named block. It is
207 * more complicated than a simple memcpy() since the named block
208 * descriptor may not be directly accessable.
209 *
210 * @param addr   Physical address of the named block descriptor
211 * @param str    String to receive the named block string name
212 * @param len    Length of the string buffer, which must match the length
213 *               stored in the bootmem descriptor.
214 */
215static void CVMX_BOOTMEM_NAMED_GET_NAME(uint64_t addr, char *str, int len)
216{
217#ifndef CVMX_BUILD_FOR_LINUX_HOST
218    int l = len;
219    char *ptr = str;
220    addr |= (1ull << 63);
221    addr += offsetof(cvmx_bootmem_named_block_desc_t, name);
222    while (l--)
223        *ptr++ = cvmx_read64_uint8(addr++);
224    str[len] = 0;
225#else
226    extern void octeon_remote_read_mem(void *buffer, uint64_t physical_address, int length);
227    addr += offsetof(cvmx_bootmem_named_block_desc_t, name);
228    octeon_remote_read_mem(str, addr, len);
229    str[len] = 0;
230#endif
231}
232
233/**
234 * This function stores the string name of a named block. It is
235 * more complicated than a simple memcpy() since the named block
236 * descriptor may not be directly accessable.
237 *
238 * @param addr   Physical address of the named block descriptor
239 * @param str    String to store into the named block string name
240 * @param len    Length of the string buffer, which must match the length
241 *               stored in the bootmem descriptor.
242 */
243static void CVMX_BOOTMEM_NAMED_SET_NAME(uint64_t addr, const char *str, int len)
244{
245#ifndef CVMX_BUILD_FOR_LINUX_HOST
246    int l = len;
247    addr |= (1ull << 63);
248    addr += offsetof(cvmx_bootmem_named_block_desc_t, name);
249    while (l--)
250    {
251        if (l)
252            cvmx_write64_uint8(addr++, *str++);
253        else
254            cvmx_write64_uint8(addr++, 0);
255    }
256#else
257    extern void octeon_remote_write_mem(uint64_t physical_address, const void *buffer, int length);
258    char zero = 0;
259    addr += offsetof(cvmx_bootmem_named_block_desc_t, name);
260    octeon_remote_write_mem(addr, str, len-1);
261    octeon_remote_write_mem(addr+len-1, &zero, 1);
262#endif
263}
264
265/* See header file for descriptions of functions */
266
267/* Wrapper functions are provided for reading/writing the size and next block
268** values as these may not be directly addressible (in 32 bit applications, for instance.)
269*/
270/* Offsets of data elements in bootmem list, must match cvmx_bootmem_block_header_t */
271#define NEXT_OFFSET 0
272#define SIZE_OFFSET 8
273static void cvmx_bootmem_phy_set_size(uint64_t addr, uint64_t size)
274{
275    cvmx_write64_uint64((addr + SIZE_OFFSET) | (1ull << 63), size);
276}
277static void cvmx_bootmem_phy_set_next(uint64_t addr, uint64_t next)
278{
279    cvmx_write64_uint64((addr + NEXT_OFFSET) | (1ull << 63), next);
280}
281static uint64_t cvmx_bootmem_phy_get_size(uint64_t addr)
282{
283    return(cvmx_read64_uint64((addr + SIZE_OFFSET) | (1ull << 63)));
284}
285static uint64_t cvmx_bootmem_phy_get_next(uint64_t addr)
286{
287    return(cvmx_read64_uint64((addr + NEXT_OFFSET) | (1ull << 63)));
288}
289
290/**
291 * Check the version information on the bootmem descriptor
292 *
293 * @param exact_match
294 *               Exact major version to check against. A zero means
295 *               check that the version supports named blocks.
296 *
297 * @return Zero if the version is correct. Negative if the version is
298 *         incorrect. Failures also cause a message to be displayed.
299 */
300static int __cvmx_bootmem_check_version(int exact_match)
301{
302    int major_version;
303#ifdef CVMX_BUILD_FOR_LINUX_HOST
304    if (!cvmx_bootmem_desc_addr)
305        cvmx_bootmem_desc_addr = cvmx_read64_uint64(0x24100);
306#endif
307    major_version = CVMX_BOOTMEM_DESC_GET_FIELD(major_version);
308    if ((major_version > 3) || (exact_match && major_version != exact_match))
309    {
310        cvmx_dprintf("ERROR: Incompatible bootmem descriptor version: %d.%d at addr: 0x%llx\n",
311            major_version, (int)CVMX_BOOTMEM_DESC_GET_FIELD(minor_version),
312            (ULL)cvmx_bootmem_desc_addr);
313        return -1;
314    }
315    else
316        return 0;
317}
318
319/**
320 * Get the low level bootmem descriptor lock. If no locking
321 * is specified in the flags, then nothing is done.
322 *
323 * @param flags  CVMX_BOOTMEM_FLAG_NO_LOCKING means this functions should do
324 *               nothing. This is used to support nested bootmem calls.
325 */
326static inline void __cvmx_bootmem_lock(uint32_t flags)
327{
328    if (!(flags & CVMX_BOOTMEM_FLAG_NO_LOCKING))
329    {
330#ifndef CVMX_BUILD_FOR_LINUX_HOST
331        /* Unfortunately we can't use the normal cvmx-spinlock code as the
332            memory for the bootmem descriptor may be not accessable by a C
333            pointer. We use a 64bit XKPHYS address to access the memory
334            directly */
335        uint64_t lock_addr = (1ull << 63) | (cvmx_bootmem_desc_addr + offsetof(cvmx_bootmem_desc_t, lock));
336        unsigned int tmp;
337
338        __asm__ __volatile__(
339        ".set noreorder         \n"
340        "1: ll   %[tmp], 0(%[addr])\n"
341        "   bnez %[tmp], 1b     \n"
342        "   li   %[tmp], 1      \n"
343        "   sc   %[tmp], 0(%[addr])\n"
344        "   beqz %[tmp], 1b     \n"
345        "   nop                \n"
346        ".set reorder           \n"
347        : [tmp] "=&r" (tmp)
348        : [addr] "r" (lock_addr)
349        : "memory");
350#endif
351    }
352}
353
354/**
355 * Release the low level bootmem descriptor lock. If no locking
356 * is specified in the flags, then nothing is done.
357 *
358 * @param flags  CVMX_BOOTMEM_FLAG_NO_LOCKING means this functions should do
359 *               nothing. This is used to support nested bootmem calls.
360 */
361static inline void __cvmx_bootmem_unlock(uint32_t flags)
362{
363    if (!(flags & CVMX_BOOTMEM_FLAG_NO_LOCKING))
364    {
365#ifndef CVMX_BUILD_FOR_LINUX_HOST
366        /* Unfortunately we can't use the normal cvmx-spinlock code as the
367            memory for the bootmem descriptor may be not accessable by a C
368            pointer. We use a 64bit XKPHYS address to access the memory
369            directly */
370        uint64_t lock_addr = (1ull << 63) | (cvmx_bootmem_desc_addr + offsetof(cvmx_bootmem_desc_t, lock));
371
372        CVMX_SYNCW;
373        __asm__ __volatile__("sw $0, 0(%[addr])\n"
374        :: [addr] "r" (lock_addr)
375        : "memory");
376        CVMX_SYNCW;
377#endif
378    }
379}
380
381/* Some of the cvmx-bootmem functions dealing with C pointers are not supported
382    when we are compiling for CVMX_BUILD_FOR_LINUX_HOST. This ifndef removes
383    these functions when they aren't needed */
384#ifndef CVMX_BUILD_FOR_LINUX_HOST
385/* This functions takes an address range and adjusts it as necessary to
386** match the ABI that is currently being used.  This is required to ensure
387** that bootmem_alloc* functions only return valid pointers for 32 bit ABIs */
388static int __cvmx_validate_mem_range(uint64_t *min_addr_ptr, uint64_t *max_addr_ptr)
389{
390
391#if defined(__linux__) && defined(CVMX_ABI_N32)
392    {
393        extern uint64_t linux_mem32_min;
394        extern uint64_t linux_mem32_max;
395        /* For 32 bit Linux apps, we need to restrict the allocations to the range
396        ** of memory configured for access from userspace.  Also, we need to add mappings
397        ** for the data structures that we access.*/
398
399        /* Narrow range requests to be bounded by the 32 bit limits.  octeon_phy_mem_block_alloc()
400        ** will reject inconsistent req_size/range requests, so we don't repeat those checks here.
401        ** If max unspecified, set to 32 bit maximum. */
402        *min_addr_ptr = MIN(MAX(*min_addr_ptr, linux_mem32_min), linux_mem32_max);
403        if (!*max_addr_ptr)
404            *max_addr_ptr = linux_mem32_max;
405        else
406            *max_addr_ptr = MAX(MIN(*max_addr_ptr, linux_mem32_max), linux_mem32_min);
407    }
408#elif defined(CVMX_ABI_N32)
409    {
410        uint32_t max_phys = 0x0FFFFFFF;  /* Max physical address when 1-1 mappings not used */
411#if CVMX_USE_1_TO_1_TLB_MAPPINGS
412        max_phys = 0x7FFFFFFF;
413#endif
414        /* We are are running standalone simple executive, so we need to limit the range
415        ** that we allocate from */
416
417        /* Narrow range requests to be bounded by the 32 bit limits.  octeon_phy_mem_block_alloc()
418        ** will reject inconsistent req_size/range requests, so we don't repeat those checks here.
419        ** If max unspecified, set to 32 bit maximum. */
420        *min_addr_ptr = MIN(MAX(*min_addr_ptr, 0x0), max_phys);
421        if (!*max_addr_ptr)
422            *max_addr_ptr = max_phys;
423        else
424            *max_addr_ptr = MAX(MIN(*max_addr_ptr, max_phys), 0x0);
425    }
426#endif
427
428    return 0;
429}
430
431
432void *cvmx_bootmem_alloc_range(uint64_t size, uint64_t alignment, uint64_t min_addr, uint64_t max_addr)
433{
434    int64_t address;
435
436    __cvmx_validate_mem_range(&min_addr, &max_addr);
437    address = cvmx_bootmem_phy_alloc(size, min_addr, max_addr, alignment, 0);
438
439    if (address > 0)
440        return cvmx_phys_to_ptr(address);
441    else
442        return NULL;
443}
444#ifdef CVMX_BUILD_FOR_LINUX_KERNEL
445EXPORT_SYMBOL(cvmx_bootmem_alloc_range);
446#endif
447
448void *cvmx_bootmem_alloc_address(uint64_t size, uint64_t address, uint64_t alignment)
449{
450    return cvmx_bootmem_alloc_range(size, alignment, address, address + size);
451}
452
453
454void *cvmx_bootmem_alloc(uint64_t size, uint64_t alignment)
455{
456    return cvmx_bootmem_alloc_range(size, alignment, 0, 0);
457}
458#ifdef CVMX_BUILD_FOR_LINUX_KERNEL
459EXPORT_SYMBOL(cvmx_bootmem_alloc);
460#endif
461
462void *cvmx_bootmem_alloc_named_range(uint64_t size, uint64_t min_addr, uint64_t max_addr, uint64_t align, const char *name)
463{
464    int64_t addr;
465
466    __cvmx_validate_mem_range(&min_addr, &max_addr);
467    addr = cvmx_bootmem_phy_named_block_alloc(size, min_addr, max_addr, align, name, 0);
468    if (addr >= 0)
469        return cvmx_phys_to_ptr(addr);
470    else
471        return NULL;
472
473}
474void *cvmx_bootmem_alloc_named_address(uint64_t size, uint64_t address, const char *name)
475{
476    return(cvmx_bootmem_alloc_named_range(size, address, address + size, 0, name));
477}
478void *cvmx_bootmem_alloc_named(uint64_t size, uint64_t alignment, const char *name)
479{
480    return(cvmx_bootmem_alloc_named_range(size, 0, 0, alignment, name));
481}
482
483int cvmx_bootmem_free_named(const char *name)
484{
485    return(cvmx_bootmem_phy_named_block_free(name, 0));
486}
487#endif
488
489const cvmx_bootmem_named_block_desc_t *cvmx_bootmem_find_named_block(const char *name)
490{
491    /* FIXME: Returning a single static object is probably a bad thing */
492    static cvmx_bootmem_named_block_desc_t desc;
493    uint64_t named_addr = cvmx_bootmem_phy_named_block_find(name, 0);
494    if (named_addr)
495    {
496        desc.base_addr = CVMX_BOOTMEM_NAMED_GET_FIELD(named_addr, base_addr);
497        desc.size = CVMX_BOOTMEM_NAMED_GET_FIELD(named_addr, size);
498        strncpy(desc.name, name, sizeof(desc.name));
499        desc.name[sizeof(desc.name)-1] = 0;
500        return &desc;
501    }
502    else
503        return NULL;
504}
505
506void cvmx_bootmem_print_named(void)
507{
508    cvmx_bootmem_phy_named_block_print();
509}
510
511int cvmx_bootmem_init(uint64_t mem_desc_addr)
512{
513    /* Verify that the size of cvmx_spinlock_t meets our assumptions */
514    if (sizeof(cvmx_spinlock_t) != 4)
515    {
516        cvmx_dprintf("ERROR: Unexpected size of cvmx_spinlock_t\n");
517        return(-1);
518    }
519    if (!cvmx_bootmem_desc_addr)
520        cvmx_bootmem_desc_addr = mem_desc_addr;
521    return(0);
522}
523
524
525uint64_t cvmx_bootmem_available_mem(uint64_t min_block_size)
526{
527    return(cvmx_bootmem_phy_available_mem(min_block_size));
528}
529
530
531
532
533
534/*********************************************************************
535** The cvmx_bootmem_phy* functions below return 64 bit physical addresses,
536** and expose more features that the cvmx_bootmem_functions above.  These are
537** required for full memory space access in 32 bit applications, as well as for
538** using some advance features.
539** Most applications should not need to use these.
540**
541**/
542
543
544int64_t cvmx_bootmem_phy_alloc(uint64_t req_size, uint64_t address_min, uint64_t address_max, uint64_t alignment, uint32_t flags)
545{
546
547    uint64_t head_addr;
548    uint64_t ent_addr;
549    uint64_t prev_addr = 0;  /* points to previous list entry, NULL current entry is head of list */
550    uint64_t new_ent_addr = 0;
551    uint64_t desired_min_addr;
552    uint64_t alignment_mask = ~(alignment - 1);
553
554#ifdef DEBUG
555    cvmx_dprintf("cvmx_bootmem_phy_alloc: req_size: 0x%llx, min_addr: 0x%llx, max_addr: 0x%llx, align: 0x%llx\n",
556           (ULL)req_size, (ULL)address_min, (ULL)address_max, (ULL)alignment);
557#endif
558
559    if (__cvmx_bootmem_check_version(0))
560        goto error_out;
561
562    /* Do a variety of checks to validate the arguments.  The allocator code will later assume
563    ** that these checks have been made.  We validate that the requested constraints are not
564    ** self-contradictory before we look through the list of available memory
565    */
566
567    /* 0 is not a valid req_size for this allocator */
568    if (!req_size)
569        goto error_out;
570
571    /* Round req_size up to mult of minimum alignment bytes */
572    req_size = (req_size + (CVMX_BOOTMEM_ALIGNMENT_SIZE - 1)) & ~(CVMX_BOOTMEM_ALIGNMENT_SIZE - 1);
573
574    /* Convert !0 address_min and 0 address_max to special case of range that specifies an exact
575    ** memory block to allocate.  Do this before other checks and adjustments so that this tranformation will be validated */
576    if (address_min && !address_max)
577        address_max = address_min + req_size;
578    else if (!address_min && !address_max)
579        address_max = ~0ull;   /* If no limits given, use max limits */
580
581
582
583
584    /* Enforce minimum alignment (this also keeps the minimum free block
585    ** req_size the same as the alignment req_size */
586    if (alignment < CVMX_BOOTMEM_ALIGNMENT_SIZE)
587    {
588        alignment = CVMX_BOOTMEM_ALIGNMENT_SIZE;
589    }
590    alignment_mask = ~(alignment - 1);
591
592    /* Adjust address minimum based on requested alignment (round up to meet alignment).  Do this here so we can
593    ** reject impossible requests up front. (NOP for address_min == 0) */
594    if (alignment)
595        address_min = (address_min + (alignment - 1)) & ~(alignment - 1);
596
597
598    /* Reject inconsistent args.  We have adjusted these, so this may fail due to our internal changes
599    ** even if this check would pass for the values the user supplied. */
600    if (req_size > address_max - address_min)
601        goto error_out;
602
603    /* Walk through the list entries - first fit found is returned */
604
605    __cvmx_bootmem_lock(flags);
606    head_addr = CVMX_BOOTMEM_DESC_GET_FIELD(head_addr);
607    ent_addr = head_addr;
608    while (ent_addr)
609    {
610        uint64_t usable_base, usable_max;
611        uint64_t ent_size = cvmx_bootmem_phy_get_size(ent_addr);
612
613        if (cvmx_bootmem_phy_get_next(ent_addr) && ent_addr > cvmx_bootmem_phy_get_next(ent_addr))
614        {
615            cvmx_dprintf("Internal bootmem_alloc() error: ent: 0x%llx, next: 0x%llx\n",
616                   (ULL)ent_addr, (ULL)cvmx_bootmem_phy_get_next(ent_addr));
617            goto error_out;
618        }
619
620        /* Determine if this is an entry that can satisify the request */
621        /* Check to make sure entry is large enough to satisfy request */
622        usable_base = ALIGN_ADDR_UP(MAX(address_min, ent_addr), alignment_mask);
623        usable_max = MIN(address_max, ent_addr + ent_size);
624        /* We should be able to allocate block at address usable_base */
625
626        desired_min_addr = usable_base;
627
628        /* Determine if request can be satisfied from the current entry */
629        if ((((ent_addr + ent_size) > usable_base && ent_addr < address_max))
630            && req_size <= usable_max - usable_base)
631        {
632            /* We have found an entry that has room to satisfy the request, so allocate it from this entry */
633
634            /* If end CVMX_BOOTMEM_FLAG_END_ALLOC set, then allocate from the end of this block
635            ** rather than the beginning */
636            if (flags & CVMX_BOOTMEM_FLAG_END_ALLOC)
637            {
638                desired_min_addr = usable_max - req_size;
639                /* Align desired address down to required alignment */
640                desired_min_addr &= alignment_mask;
641            }
642
643            /* Match at start of entry */
644            if (desired_min_addr == ent_addr)
645            {
646                if (req_size < ent_size)
647                {
648                    /* big enough to create a new block from top portion of block */
649                    new_ent_addr = ent_addr + req_size;
650                    cvmx_bootmem_phy_set_next(new_ent_addr, cvmx_bootmem_phy_get_next(ent_addr));
651                    cvmx_bootmem_phy_set_size(new_ent_addr, ent_size - req_size);
652
653                    /* Adjust next pointer as following code uses this */
654                    cvmx_bootmem_phy_set_next(ent_addr, new_ent_addr);
655                }
656
657                /* adjust prev ptr or head to remove this entry from list */
658                if (prev_addr)
659                {
660                    cvmx_bootmem_phy_set_next(prev_addr, cvmx_bootmem_phy_get_next(ent_addr));
661                }
662                else
663                {
664                    /* head of list being returned, so update head ptr */
665                    CVMX_BOOTMEM_DESC_SET_FIELD(head_addr, cvmx_bootmem_phy_get_next(ent_addr));
666                }
667                __cvmx_bootmem_unlock(flags);
668                return(desired_min_addr);
669            }
670
671
672            /* block returned doesn't start at beginning of entry, so we know
673            ** that we will be splitting a block off the front of this one.  Create a new block
674            ** from the beginning, add to list, and go to top of loop again.
675            **
676            ** create new block from high portion of block, so that top block
677            ** starts at desired addr
678            **/
679            new_ent_addr = desired_min_addr;
680            cvmx_bootmem_phy_set_next(new_ent_addr, cvmx_bootmem_phy_get_next(ent_addr));
681            cvmx_bootmem_phy_set_size(new_ent_addr, cvmx_bootmem_phy_get_size(ent_addr) - (desired_min_addr - ent_addr));
682            cvmx_bootmem_phy_set_size(ent_addr, desired_min_addr - ent_addr);
683            cvmx_bootmem_phy_set_next(ent_addr, new_ent_addr);
684            /* Loop again to handle actual alloc from new block */
685        }
686
687        prev_addr = ent_addr;
688        ent_addr = cvmx_bootmem_phy_get_next(ent_addr);
689    }
690error_out:
691    /* We didn't find anything, so return error */
692    __cvmx_bootmem_unlock(flags);
693    return(-1);
694}
695
696
697
698int __cvmx_bootmem_phy_free(uint64_t phy_addr, uint64_t size, uint32_t flags)
699{
700    uint64_t cur_addr;
701    uint64_t prev_addr = 0;  /* zero is invalid */
702    int retval = 0;
703
704#ifdef DEBUG
705    cvmx_dprintf("__cvmx_bootmem_phy_free addr: 0x%llx, size: 0x%llx\n", (ULL)phy_addr, (ULL)size);
706#endif
707    if (__cvmx_bootmem_check_version(0))
708        return(0);
709
710    /* 0 is not a valid size for this allocator */
711    if (!size)
712        return(0);
713
714
715    __cvmx_bootmem_lock(flags);
716    cur_addr = CVMX_BOOTMEM_DESC_GET_FIELD(head_addr);
717    if (cur_addr == 0 || phy_addr < cur_addr)
718    {
719        /* add at front of list - special case with changing head ptr */
720        if (cur_addr && phy_addr + size > cur_addr)
721            goto bootmem_free_done; /* error, overlapping section */
722        else if (phy_addr + size == cur_addr)
723        {
724            /* Add to front of existing first block */
725            cvmx_bootmem_phy_set_next(phy_addr, cvmx_bootmem_phy_get_next(cur_addr));
726            cvmx_bootmem_phy_set_size(phy_addr, cvmx_bootmem_phy_get_size(cur_addr) + size);
727            CVMX_BOOTMEM_DESC_SET_FIELD(head_addr, phy_addr);
728
729        }
730        else
731        {
732            /* New block before first block */
733            cvmx_bootmem_phy_set_next(phy_addr, cur_addr);  /* OK if cur_addr is 0 */
734            cvmx_bootmem_phy_set_size(phy_addr, size);
735            CVMX_BOOTMEM_DESC_SET_FIELD(head_addr, phy_addr);
736        }
737        retval = 1;
738        goto bootmem_free_done;
739    }
740
741    /* Find place in list to add block */
742    while (cur_addr && phy_addr > cur_addr)
743    {
744        prev_addr = cur_addr;
745        cur_addr = cvmx_bootmem_phy_get_next(cur_addr);
746    }
747
748    if (!cur_addr)
749    {
750        /* We have reached the end of the list, add on to end, checking
751        ** to see if we need to combine with last block
752        **/
753        if (prev_addr +  cvmx_bootmem_phy_get_size(prev_addr) == phy_addr)
754        {
755            cvmx_bootmem_phy_set_size(prev_addr, cvmx_bootmem_phy_get_size(prev_addr) + size);
756        }
757        else
758        {
759            cvmx_bootmem_phy_set_next(prev_addr, phy_addr);
760            cvmx_bootmem_phy_set_size(phy_addr, size);
761            cvmx_bootmem_phy_set_next(phy_addr, 0);
762        }
763        retval = 1;
764        goto bootmem_free_done;
765    }
766    else
767    {
768        /* insert between prev and cur nodes, checking for merge with either/both */
769
770        if (prev_addr +  cvmx_bootmem_phy_get_size(prev_addr) == phy_addr)
771        {
772            /* Merge with previous */
773            cvmx_bootmem_phy_set_size(prev_addr, cvmx_bootmem_phy_get_size(prev_addr) + size);
774            if (phy_addr + size == cur_addr)
775            {
776                /* Also merge with current */
777                cvmx_bootmem_phy_set_size(prev_addr, cvmx_bootmem_phy_get_size(cur_addr) + cvmx_bootmem_phy_get_size(prev_addr));
778                cvmx_bootmem_phy_set_next(prev_addr, cvmx_bootmem_phy_get_next(cur_addr));
779            }
780            retval = 1;
781            goto bootmem_free_done;
782        }
783        else if (phy_addr + size == cur_addr)
784        {
785            /* Merge with current */
786            cvmx_bootmem_phy_set_size(phy_addr, cvmx_bootmem_phy_get_size(cur_addr) + size);
787            cvmx_bootmem_phy_set_next(phy_addr, cvmx_bootmem_phy_get_next(cur_addr));
788            cvmx_bootmem_phy_set_next(prev_addr, phy_addr);
789            retval = 1;
790            goto bootmem_free_done;
791        }
792
793        /* It is a standalone block, add in between prev and cur */
794        cvmx_bootmem_phy_set_size(phy_addr, size);
795        cvmx_bootmem_phy_set_next(phy_addr, cur_addr);
796        cvmx_bootmem_phy_set_next(prev_addr, phy_addr);
797
798
799    }
800    retval = 1;
801
802bootmem_free_done:
803    __cvmx_bootmem_unlock(flags);
804    return(retval);
805
806}
807
808
809
810void cvmx_bootmem_phy_list_print(void)
811{
812    uint64_t addr;
813
814    addr = CVMX_BOOTMEM_DESC_GET_FIELD(head_addr);
815    cvmx_dprintf("\n\n\nPrinting bootmem block list, descriptor: 0x%llx,  head is 0x%llx\n",
816           (ULL)cvmx_bootmem_desc_addr, (ULL)addr);
817    cvmx_dprintf("Descriptor version: %d.%d\n",
818        (int)CVMX_BOOTMEM_DESC_GET_FIELD(major_version),
819        (int)CVMX_BOOTMEM_DESC_GET_FIELD(minor_version));
820    if (CVMX_BOOTMEM_DESC_GET_FIELD(major_version) > 3)
821    {
822        cvmx_dprintf("Warning: Bootmem descriptor version is newer than expected\n");
823    }
824    if (!addr)
825    {
826        cvmx_dprintf("mem list is empty!\n");
827    }
828    while (addr)
829    {
830        cvmx_dprintf("Block address: 0x%08qx, size: 0x%08qx, next: 0x%08qx\n",
831               (ULL)addr,
832               (ULL)cvmx_bootmem_phy_get_size(addr),
833               (ULL)cvmx_bootmem_phy_get_next(addr));
834        addr = cvmx_bootmem_phy_get_next(addr);
835    }
836    cvmx_dprintf("\n\n");
837
838}
839
840
841uint64_t cvmx_bootmem_phy_available_mem(uint64_t min_block_size)
842{
843    uint64_t addr;
844
845    uint64_t available_mem = 0;
846
847    __cvmx_bootmem_lock(0);
848    addr = CVMX_BOOTMEM_DESC_GET_FIELD(head_addr);
849    while (addr)
850    {
851        if (cvmx_bootmem_phy_get_size(addr) >= min_block_size)
852            available_mem += cvmx_bootmem_phy_get_size(addr);
853        addr = cvmx_bootmem_phy_get_next(addr);
854    }
855    __cvmx_bootmem_unlock(0);
856    return(available_mem);
857
858}
859
860
861
862uint64_t cvmx_bootmem_phy_named_block_find(const char *name, uint32_t flags)
863{
864    uint64_t result = 0;
865
866#ifdef DEBUG
867    cvmx_dprintf("cvmx_bootmem_phy_named_block_find: %s\n", name);
868#endif
869    __cvmx_bootmem_lock(flags);
870    if (!__cvmx_bootmem_check_version(3))
871    {
872        int i;
873        uint64_t named_block_array_addr = CVMX_BOOTMEM_DESC_GET_FIELD(named_block_array_addr);
874        int num_blocks = CVMX_BOOTMEM_DESC_GET_FIELD(named_block_num_blocks);
875        int name_length = CVMX_BOOTMEM_DESC_GET_FIELD(named_block_name_len);
876        uint64_t named_addr = named_block_array_addr;
877        for (i = 0; i < num_blocks; i++)
878        {
879            uint64_t named_size = CVMX_BOOTMEM_NAMED_GET_FIELD(named_addr, size);
880            if (name && named_size)
881            {
882                char name_tmp[name_length];
883                CVMX_BOOTMEM_NAMED_GET_NAME(named_addr, name_tmp, name_length);
884                if (!strncmp(name, name_tmp, name_length - 1))
885                {
886                    result = named_addr;
887                    break;
888                }
889            }
890            else if (!name && !named_size)
891            {
892                result = named_addr;
893                break;
894            }
895            named_addr += sizeof(cvmx_bootmem_named_block_desc_t);
896        }
897    }
898    __cvmx_bootmem_unlock(flags);
899    return result;
900}
901
902int cvmx_bootmem_phy_named_block_free(const char *name, uint32_t flags)
903{
904    uint64_t named_block_addr;
905
906    if (__cvmx_bootmem_check_version(3))
907        return(0);
908#ifdef DEBUG
909    cvmx_dprintf("cvmx_bootmem_phy_named_block_free: %s\n", name);
910#endif
911
912    /* Take lock here, as name lookup/block free/name free need to be atomic */
913    __cvmx_bootmem_lock(flags);
914
915    named_block_addr = cvmx_bootmem_phy_named_block_find(name, CVMX_BOOTMEM_FLAG_NO_LOCKING);
916    if (named_block_addr)
917    {
918        uint64_t named_addr = CVMX_BOOTMEM_NAMED_GET_FIELD(named_block_addr, base_addr);
919        uint64_t named_size = CVMX_BOOTMEM_NAMED_GET_FIELD(named_block_addr, size);
920#ifdef DEBUG
921        cvmx_dprintf("cvmx_bootmem_phy_named_block_free: %s, base: 0x%llx, size: 0x%llx\n",
922            name, (ULL)named_addr, (ULL)named_size);
923#endif
924        __cvmx_bootmem_phy_free(named_addr, named_size, CVMX_BOOTMEM_FLAG_NO_LOCKING);
925        /* Set size to zero to indicate block not used. */
926        CVMX_BOOTMEM_NAMED_SET_FIELD(named_block_addr, size, 0);
927    }
928    __cvmx_bootmem_unlock(flags);
929    return(!!named_block_addr);  /* 0 on failure, 1 on success */
930}
931
932
933
934
935
936int64_t cvmx_bootmem_phy_named_block_alloc(uint64_t size, uint64_t min_addr, uint64_t max_addr, uint64_t alignment, const char *name, uint32_t flags)
937{
938    int64_t addr_allocated;
939    uint64_t named_block_desc_addr;
940
941#ifdef DEBUG
942    cvmx_dprintf("cvmx_bootmem_phy_named_block_alloc: size: 0x%llx, min: 0x%llx, max: 0x%llx, align: 0x%llx, name: %s\n",
943                 (ULL)size,
944                 (ULL)min_addr,
945                 (ULL)max_addr,
946                 (ULL)alignment,
947                 name);
948#endif
949
950    if (__cvmx_bootmem_check_version(3))
951        return(-1);
952
953    /* Take lock here, as name lookup/block alloc/name add need to be atomic */
954
955    __cvmx_bootmem_lock(flags);
956
957    named_block_desc_addr = cvmx_bootmem_phy_named_block_find(name, flags | CVMX_BOOTMEM_FLAG_NO_LOCKING);
958    if (named_block_desc_addr)
959    {
960        __cvmx_bootmem_unlock(flags);
961        return(-1);
962    }
963
964    /* Get pointer to first available named block descriptor */
965    named_block_desc_addr = cvmx_bootmem_phy_named_block_find(NULL, flags | CVMX_BOOTMEM_FLAG_NO_LOCKING);
966    if (!named_block_desc_addr)
967    {
968        __cvmx_bootmem_unlock(flags);
969        return(-1);
970    }
971
972    /* Round size up to mult of minimum alignment bytes
973    ** We need the actual size allocated to allow for blocks to be coallesced
974    ** when they are freed.  The alloc routine does the same rounding up
975    ** on all allocations. */
976    size = (size + (CVMX_BOOTMEM_ALIGNMENT_SIZE - 1)) & ~(CVMX_BOOTMEM_ALIGNMENT_SIZE - 1);
977
978    addr_allocated = cvmx_bootmem_phy_alloc(size, min_addr, max_addr, alignment, flags | CVMX_BOOTMEM_FLAG_NO_LOCKING);
979    if (addr_allocated >= 0)
980    {
981        CVMX_BOOTMEM_NAMED_SET_FIELD(named_block_desc_addr, base_addr, addr_allocated);
982        CVMX_BOOTMEM_NAMED_SET_FIELD(named_block_desc_addr, size, size);
983        CVMX_BOOTMEM_NAMED_SET_NAME(named_block_desc_addr, name, CVMX_BOOTMEM_DESC_GET_FIELD(named_block_name_len));
984    }
985
986    __cvmx_bootmem_unlock(flags);
987    return(addr_allocated);
988}
989
990
991
992
993void cvmx_bootmem_phy_named_block_print(void)
994{
995    int i;
996    int printed = 0;
997
998    uint64_t named_block_array_addr = CVMX_BOOTMEM_DESC_GET_FIELD(named_block_array_addr);
999    int num_blocks = CVMX_BOOTMEM_DESC_GET_FIELD(named_block_num_blocks);
1000    int name_length = CVMX_BOOTMEM_DESC_GET_FIELD(named_block_name_len);
1001    uint64_t named_block_addr = named_block_array_addr;
1002
1003#ifdef DEBUG
1004    cvmx_dprintf("cvmx_bootmem_phy_named_block_print, desc addr: 0x%llx\n",
1005        (ULL)cvmx_bootmem_desc_addr);
1006#endif
1007    if (__cvmx_bootmem_check_version(3))
1008        return;
1009    cvmx_dprintf("List of currently allocated named bootmem blocks:\n");
1010    for (i = 0; i < num_blocks; i++)
1011    {
1012        uint64_t named_size = CVMX_BOOTMEM_NAMED_GET_FIELD(named_block_addr, size);
1013        if (named_size)
1014        {
1015            char name_tmp[name_length];
1016            uint64_t named_addr = CVMX_BOOTMEM_NAMED_GET_FIELD(named_block_addr, base_addr);
1017            CVMX_BOOTMEM_NAMED_GET_NAME(named_block_addr, name_tmp, name_length);
1018            printed++;
1019            cvmx_dprintf("Name: %s, address: 0x%08qx, size: 0x%08qx, index: %d\n",
1020                   name_tmp, (ULL)named_addr, (ULL)named_size, i);
1021        }
1022        named_block_addr += sizeof(cvmx_bootmem_named_block_desc_t);
1023    }
1024    if (!printed)
1025    {
1026        cvmx_dprintf("No named bootmem blocks exist.\n");
1027    }
1028
1029}
1030
1031
1032/* Real physical addresses of memory regions */
1033#define OCTEON_DDR0_BASE    (0x0ULL)
1034#define OCTEON_DDR0_SIZE    (0x010000000ULL)
1035#define OCTEON_DDR1_BASE    (OCTEON_IS_MODEL(OCTEON_CN6XXX) ? 0x20000000ULL : 0x410000000ULL)
1036#define OCTEON_DDR1_SIZE    (0x010000000ULL)
1037#define OCTEON_DDR2_BASE    (OCTEON_IS_MODEL(OCTEON_CN6XXX) ? 0x30000000ULL : 0x20000000ULL)
1038#define OCTEON_DDR2_SIZE    (OCTEON_IS_MODEL(OCTEON_CN6XXX) ? 0x7d0000000ULL : 0x3e0000000ULL)
1039#define OCTEON_MAX_PHY_MEM_SIZE (OCTEON_IS_MODEL(OCTEON_CN63XX) ? 32*1024*1024*1024ULL : 16*1024*1024*1024ULL)
1040int64_t cvmx_bootmem_phy_mem_list_init(uint64_t mem_size, uint32_t low_reserved_bytes, cvmx_bootmem_desc_t *desc_buffer)
1041{
1042    uint64_t cur_block_addr;
1043    int64_t addr;
1044    int i;
1045
1046#ifdef DEBUG
1047    cvmx_dprintf("cvmx_bootmem_phy_mem_list_init (arg desc ptr: %p, cvmx_bootmem_desc: 0x%llx)\n",
1048        desc_buffer, (ULL)cvmx_bootmem_desc_addr);
1049#endif
1050
1051    /* Descriptor buffer needs to be in 32 bit addressable space to be compatible with
1052    ** 32 bit applications */
1053    if (!desc_buffer)
1054    {
1055        cvmx_dprintf("ERROR: no memory for cvmx_bootmem descriptor provided\n");
1056        return 0;
1057    }
1058
1059    if (mem_size > OCTEON_MAX_PHY_MEM_SIZE)
1060    {
1061        mem_size = OCTEON_MAX_PHY_MEM_SIZE;
1062        cvmx_dprintf("ERROR: requested memory size too large, truncating to maximum size\n");
1063    }
1064
1065    if (cvmx_bootmem_desc_addr)
1066        return 1;
1067
1068    /* Initialize cvmx pointer to descriptor */
1069#ifndef CVMX_BUILD_FOR_LINUX_HOST
1070    cvmx_bootmem_init(cvmx_ptr_to_phys(desc_buffer));
1071#else
1072    cvmx_bootmem_init((unsigned long)desc_buffer);
1073#endif
1074
1075    /* Fill the bootmem descriptor */
1076    CVMX_BOOTMEM_DESC_SET_FIELD(lock, 0);
1077    CVMX_BOOTMEM_DESC_SET_FIELD(flags, 0);
1078    CVMX_BOOTMEM_DESC_SET_FIELD(head_addr, 0);
1079    CVMX_BOOTMEM_DESC_SET_FIELD(major_version, CVMX_BOOTMEM_DESC_MAJ_VER);
1080    CVMX_BOOTMEM_DESC_SET_FIELD(minor_version, CVMX_BOOTMEM_DESC_MIN_VER);
1081    CVMX_BOOTMEM_DESC_SET_FIELD(app_data_addr, 0);
1082    CVMX_BOOTMEM_DESC_SET_FIELD(app_data_size, 0);
1083
1084    /* Set up global pointer to start of list, exclude low 64k for exception vectors, space for global descriptor */
1085    cur_block_addr = (OCTEON_DDR0_BASE + low_reserved_bytes);
1086
1087    if (mem_size <= OCTEON_DDR0_SIZE)
1088    {
1089        __cvmx_bootmem_phy_free(cur_block_addr, mem_size - low_reserved_bytes, 0);
1090        goto frees_done;
1091    }
1092
1093    __cvmx_bootmem_phy_free(cur_block_addr, OCTEON_DDR0_SIZE - low_reserved_bytes, 0);
1094
1095    mem_size -= OCTEON_DDR0_SIZE;
1096
1097    /* Add DDR2 block next if present */
1098    if (mem_size > OCTEON_DDR1_SIZE)
1099    {
1100        __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, OCTEON_DDR1_SIZE, 0);
1101        __cvmx_bootmem_phy_free(OCTEON_DDR2_BASE, mem_size - OCTEON_DDR1_SIZE, 0);
1102    }
1103    else
1104    {
1105        __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, mem_size, 0);
1106
1107    }
1108frees_done:
1109
1110    /* Initialize the named block structure */
1111    CVMX_BOOTMEM_DESC_SET_FIELD(named_block_name_len, CVMX_BOOTMEM_NAME_LEN);
1112    CVMX_BOOTMEM_DESC_SET_FIELD(named_block_num_blocks, CVMX_BOOTMEM_NUM_NAMED_BLOCKS);
1113    CVMX_BOOTMEM_DESC_SET_FIELD(named_block_array_addr, 0);
1114
1115    /* Allocate this near the top of the low 256 MBytes of memory */
1116    addr = cvmx_bootmem_phy_alloc(CVMX_BOOTMEM_NUM_NAMED_BLOCKS * sizeof(cvmx_bootmem_named_block_desc_t),0, 0x10000000, 0 ,CVMX_BOOTMEM_FLAG_END_ALLOC);
1117    if (addr >= 0)
1118        CVMX_BOOTMEM_DESC_SET_FIELD(named_block_array_addr, addr);
1119
1120#ifdef DEBUG
1121    cvmx_dprintf("cvmx_bootmem_phy_mem_list_init: named_block_array_addr: 0x%llx)\n",
1122        (ULL)addr);
1123#endif
1124    if (!addr)
1125    {
1126        cvmx_dprintf("FATAL ERROR: unable to allocate memory for bootmem descriptor!\n");
1127        return(0);
1128    }
1129    for (i=0; i<CVMX_BOOTMEM_NUM_NAMED_BLOCKS; i++)
1130    {
1131        CVMX_BOOTMEM_NAMED_SET_FIELD(addr, base_addr, 0);
1132        CVMX_BOOTMEM_NAMED_SET_FIELD(addr, size, 0);
1133        addr += sizeof(cvmx_bootmem_named_block_desc_t);
1134    }
1135
1136    return(1);
1137}
1138
1139
1140void cvmx_bootmem_lock(void)
1141{
1142    __cvmx_bootmem_lock(0);
1143}
1144
1145void cvmx_bootmem_unlock(void)
1146{
1147    __cvmx_bootmem_unlock(0);
1148}
1149
1150#ifndef CVMX_BUILD_FOR_LINUX_HOST
1151void *__cvmx_bootmem_internal_get_desc_ptr(void)
1152{
1153    return cvmx_phys_to_ptr(cvmx_bootmem_desc_addr);
1154}
1155#endif
1156