Remove CONFIG_GRAN_SINGLE. It adds no technical benefit (other than some minor reduction in the number of interface arguments) but adds a lot of code complexity. Better without it.
This commit is contained in:
parent
d99f1ca574
commit
62b8026976
@ -69,9 +69,7 @@
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_GRAN_SINGLE
|
||||
static GRAN_HANDLE g_physhandle;
|
||||
#endif
|
||||
static struct z180_cbr_s g_cbrs[CONFIG_MAX_TASKS];
|
||||
|
||||
/****************************************************************************
|
||||
@ -166,14 +164,9 @@ int up_mmuinit(void)
|
||||
* say that 1 page is 1 byte.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
return gran_initialize((FAR void *)Z180_PHYSHEAP_STARTPAGE,
|
||||
Z180_PHYSHEAP_NPAGES, 0, 0);
|
||||
#else
|
||||
g_physhandle = gran_initialize((FAR void *)Z180_PHYSHEAP_STARTPAGE,
|
||||
Z180_PHYSHEAP_NPAGES, 0, 0);
|
||||
return g_physhandle ? OK : -ENOMEM;
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -280,12 +273,8 @@ int up_addrenv_create(size_t textsize, size_t datasize, size_t heapsize,
|
||||
|
||||
/* Now allocate the physical memory to back up the address environment */
|
||||
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
alloc = (uintptr_t)gran_alloc(npages);
|
||||
#else
|
||||
alloc = (uintptr_t)gran_alloc(g_physhandle, npages);
|
||||
#endif
|
||||
if (!alloc)
|
||||
if (alloc == NULL)
|
||||
{
|
||||
serr("ERROR: Failed to allocate %d pages\n", npages);
|
||||
ret = -ENOMEM;
|
||||
@ -337,11 +326,7 @@ int up_addrenv_destroy(FAR group_addrenv_t *addrenv)
|
||||
|
||||
/* Free the physical address space backing up the mapping */
|
||||
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
gran_free((FAR void *)cbr->cbr, cbr->pages);
|
||||
#else
|
||||
gran_free(g_physhandle, (FAR void *)cbr->cbr, cbr->pages);
|
||||
#endif
|
||||
|
||||
/* And make the CBR structure available for re-use */
|
||||
|
||||
|
@ -15,7 +15,6 @@ CONFIG_DISABLE_PTHREAD=y
|
||||
CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS=4
|
||||
CONFIG_EXAMPLES_OSTEST_STACKSIZE=1024
|
||||
CONFIG_EXAMPLES_OSTEST=y
|
||||
CONFIG_GRAN_SINGLE=y
|
||||
CONFIG_GRAN=y
|
||||
CONFIG_HOST_WINDOWS=y
|
||||
CONFIG_MAX_TASKS=8
|
||||
|
@ -2,7 +2,6 @@
|
||||
CONFIG_ARCH_ADDRENV=y
|
||||
CONFIG_ARCH_BOARD_SAMA5D4_EK=y
|
||||
CONFIG_ARCH_BOARD="sama5d4-ek"
|
||||
CONFIG_BOARD_INITIALIZE=y
|
||||
CONFIG_ARCH_BUTTONS=y
|
||||
CONFIG_ARCH_CHIP_ATSAMA5D44=y
|
||||
CONFIG_ARCH_CHIP_SAMA5=y
|
||||
@ -23,19 +22,20 @@ CONFIG_ARCH_TEXT_NPAGES=256
|
||||
CONFIG_ARCH_TEXT_VBASE=0x80000000
|
||||
CONFIG_ARCH="arm"
|
||||
CONFIG_ARMV7A_TOOLCHAIN_CODESOURCERYW=y
|
||||
CONFIG_DRIVERS_AUDIO=y
|
||||
CONFIG_BOARD_INITIALIZE=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=65775
|
||||
CONFIG_BOOT_RUNFROMSDRAM=y
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_DEV_ZERO=y
|
||||
CONFIG_ELF=y
|
||||
CONFIG_DRIVERS_AUDIO=y
|
||||
CONFIG_ELF_STACKSIZE=4096
|
||||
CONFIG_ELF=y
|
||||
CONFIG_EXAMPLES_ELF_SYSCALL=y
|
||||
CONFIG_EXAMPLES_ELF=y
|
||||
CONFIG_EXECFUNCS_SYMTAB="exports"
|
||||
CONFIG_EXPERIMENTAL=y
|
||||
CONFIG_FS_PROCFS=y
|
||||
CONFIG_FS_ROMFS=y
|
||||
CONFIG_GRAN_SINGLE=y
|
||||
CONFIG_HAVE_CXX=y
|
||||
CONFIG_HAVE_CXXINITIALIZE=y
|
||||
CONFIG_HOST_WINDOWS=y
|
||||
|
@ -41,7 +41,6 @@ CONFIG_FAT_LFN=y
|
||||
CONFIG_FS_FAT=y
|
||||
CONFIG_FS_PROCFS=y
|
||||
CONFIG_FS_ROMFS=y
|
||||
CONFIG_GRAN_SINGLE=y
|
||||
CONFIG_HAVE_CXX=y
|
||||
CONFIG_HAVE_CXXINITIALIZE=y
|
||||
CONFIG_HOST_WINDOWS=y
|
||||
|
@ -2,7 +2,7 @@
|
||||
* include/nuttx/mm/gran.h
|
||||
* General purpose granule memory allocator.
|
||||
*
|
||||
* Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2012, 2014, 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -51,12 +51,9 @@
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
/* CONFIG_GRAN - Enable granule allocator support
|
||||
* CONFIG_GRAN_SINGLE - Select if there is only one instance of the
|
||||
* granule allocator (i.e., gran_initialize will be called only once.
|
||||
* In this case, (1) there are a few optimizations that can can be done
|
||||
* and (2) the GRAN_HANDLE is not needed.
|
||||
* CONFIG_GRAN_INTR - Normally mutual exclusive access to granule allocator
|
||||
* data is assured using a semaphore. If this option is set then, instead,
|
||||
* mutual exclusion logic will disable interrupts. While this options is
|
||||
@ -70,9 +67,19 @@
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_GRAN_SINGLE
|
||||
/* An opaque reference to an instance of a granule allocator state */
|
||||
|
||||
typedef FAR void *GRAN_HANDLE;
|
||||
#endif
|
||||
|
||||
/* For in which the state of the granule allocator is returned */
|
||||
|
||||
struct graninfo_s
|
||||
{
|
||||
uint8_t log2gran; /* Log base 2 of the size of one granule */
|
||||
uint16_t ngranules; /* The total number of (aligned) granules in the heap */
|
||||
uint16_t nfree; /* The number of free granules */
|
||||
uint16_t mxfree; /* The longest sequence of free granules */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
@ -110,8 +117,7 @@ extern "C"
|
||||
*
|
||||
* GRAN_HANDLE handle = gran_initialize(g_dmaheap, DMAHEAP_SIZE, 6, 4);
|
||||
*
|
||||
* Then the GRAN_HANDLE can be used to allocate memory (There is no
|
||||
* GRAN_HANDLE if CONFIG_GRAN_SINGLE=y):
|
||||
* Then the GRAN_HANDLE can be used to allocate memory:
|
||||
*
|
||||
* FAR uint8_t *dma_memory = (FAR uint8_t *)gran_alloc(handle, 47);
|
||||
*
|
||||
@ -140,13 +146,8 @@ extern "C"
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
int gran_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gran,
|
||||
uint8_t log2align);
|
||||
#else
|
||||
GRAN_HANDLE gran_initialize(FAR void *heapstart, size_t heapsize,
|
||||
uint8_t log2gran, uint8_t log2align);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: gran_release
|
||||
@ -163,11 +164,7 @@ GRAN_HANDLE gran_initialize(FAR void *heapstart, size_t heapsize,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
void gran_release(void);
|
||||
#else
|
||||
void gran_release(GRAN_HANDLE handle);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: gran_reserve
|
||||
@ -191,11 +188,7 @@ void gran_release(GRAN_HANDLE handle);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
void gran_reserve(uintptr_t start, size_t size);
|
||||
#else
|
||||
void gran_reserve(GRAN_HANDLE handle, uintptr_t start, size_t size);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: gran_alloc
|
||||
@ -212,16 +205,12 @@ void gran_reserve(GRAN_HANDLE handle, uintptr_t start, size_t size);
|
||||
* size - The size of the memory region to allocate.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, either a non-NULL pointer to the allocated memory (if
|
||||
* CONFIG_GRAN_SINGLE) or zero (if !CONFIG_GRAN_SINGLE) is returned.
|
||||
* On success, a non-NULL pointer to the allocated memory is returned;
|
||||
* NULL is returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
FAR void *gran_alloc(size_t size);
|
||||
#else
|
||||
FAR void *gran_alloc(GRAN_HANDLE handle, size_t size);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: gran_free
|
||||
@ -238,11 +227,25 @@ FAR void *gran_alloc(GRAN_HANDLE handle, size_t size);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
void gran_free(FAR void *memory, size_t size);
|
||||
#else
|
||||
void gran_free(GRAN_HANDLE handle, FAR void *memory, size_t size);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: gran_info
|
||||
*
|
||||
* Description:
|
||||
* Return memory to the granule heap.
|
||||
*
|
||||
* Input Parameters:
|
||||
* handle - The handle previously returned by gran_initialize
|
||||
* info - Memory location to return the gran allocator info.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success; a negated errno value is return on
|
||||
* any failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void gran_info(GRAN_HANDLE handle, FAR struct graninfo_s *info);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/mm/shm.h
|
||||
*
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2014, 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -65,10 +65,6 @@
|
||||
# error CONFIG_GRAN must be selected with CONFIG_MM_SHM
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
# error CONFIG_GRAN_SINGLE must NOT be selected with CONFIG_MM_SHM
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_MM_PGALLOC
|
||||
# error CONFIG_MM_PGALLOC must be selected with CONFIG_MM_SHM
|
||||
#endif
|
||||
|
10
mm/Kconfig
10
mm/Kconfig
@ -92,16 +92,6 @@ config GRAN
|
||||
allocation size to 32 granaules. That restriction could be
|
||||
eliminated with some additional coding effort.
|
||||
|
||||
config GRAN_SINGLE
|
||||
bool "Single Granule Allocator"
|
||||
default n
|
||||
depends on GRAN
|
||||
---help---
|
||||
Select if there is only one instance of the granule allocator (i.e.,
|
||||
gran_initialize will be called only once. In this case, (1) there
|
||||
are a few optimizations that can can be done and (2) the GRAN_HANDLE
|
||||
is not needed.
|
||||
|
||||
config GRAN_INTR
|
||||
bool "Interrupt level support"
|
||||
default n
|
||||
|
@ -116,8 +116,7 @@ This directory contains the NuttX memory management logic. This include:
|
||||
|
||||
GRAN_HANDLE handle = gran_initialize(g_dmaheap, DMAHEAP_SIZE, 6, 4);
|
||||
|
||||
Then the GRAN_HANDLE can be used to allocate memory (There is no
|
||||
GRAN_HANDLE if CONFIG_GRAN_SINGLE=y):
|
||||
Then the GRAN_HANDLE can be used to allocate memory:
|
||||
|
||||
FAR uint8_t *dma_memory = (FAR uint8_t *)gran_alloc(handle, 47);
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* mm/mm_gran/mm_gran.h
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2012, 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -102,16 +102,6 @@ struct gran_s
|
||||
uint32_t gat[1]; /* Start of the granule allocation table */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/* State of the single GRAN allocator */
|
||||
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
extern FAR struct gran_s *g_graninfo;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* mm/mm_gran/mm_granalloc.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2012, 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -48,26 +48,32 @@
|
||||
#ifdef CONFIG_GRAN
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: gran_common_alloc
|
||||
* Name: gran_alloc
|
||||
*
|
||||
* Description:
|
||||
* Allocate memory from the granule heap.
|
||||
*
|
||||
* NOTE: The current implementation also restricts the maximum allocation
|
||||
* size to 32 granules. That restriction could be eliminated with some
|
||||
* additional coding effort.
|
||||
*
|
||||
* Input Parameters:
|
||||
* priv - The granule heap state structure.
|
||||
* size - The size of the memory region to allocate.
|
||||
* handle - The handle previously returned by gran_initialize
|
||||
* size - The size of the memory region to allocate.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, a non-NULL pointer to the allocated memory is returned.
|
||||
* On success, a non-NULL pointer to the allocated memory is returned;
|
||||
* NULL is returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline FAR void *gran_common_alloc(FAR struct gran_s *priv, size_t size)
|
||||
FAR void *gran_alloc(GRAN_HANDLE handle, size_t size)
|
||||
{
|
||||
FAR struct gran_s *priv = (FAR struct gran_s *)handle;
|
||||
unsigned int ngranules;
|
||||
size_t tmpmask;
|
||||
uintptr_t alloc;
|
||||
@ -79,7 +85,7 @@ static inline FAR void *gran_common_alloc(FAR struct gran_s *priv, size_t size)
|
||||
int bitidx;
|
||||
int shift;
|
||||
|
||||
DEBUGASSERT(priv && size <= 32 * (1 << priv->log2gran));
|
||||
DEBUGASSERT(priv != NULL && size <= 32 * (1 << priv->log2gran));
|
||||
|
||||
if (priv && size > 0)
|
||||
{
|
||||
@ -248,40 +254,4 @@ static inline FAR void *gran_common_alloc(FAR struct gran_s *priv, size_t size)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: gran_alloc
|
||||
*
|
||||
* Description:
|
||||
* Allocate memory from the granule heap.
|
||||
*
|
||||
* NOTE: The current implementation also restricts the maximum allocation
|
||||
* size to 32 granules. That restriction could be eliminated with some
|
||||
* additional coding effort.
|
||||
*
|
||||
* Input Parameters:
|
||||
* handle - The handle previously returned by gran_initialize
|
||||
* size - The size of the memory region to allocate.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, either a non-NULL pointer to the allocated memory (if
|
||||
* CONFIG_GRAN_SINGLE) or zero (if !CONFIG_GRAN_SINGLE) is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
FAR void *gran_alloc(size_t size)
|
||||
{
|
||||
return gran_common_alloc(g_graninfo, size);
|
||||
}
|
||||
#else
|
||||
FAR void *gran_alloc(GRAN_HANDLE handle, size_t size)
|
||||
{
|
||||
return gran_common_alloc((FAR struct gran_s *)handle, size);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_GRAN */
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* mm/mm_gran/mm_granfree.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2012, 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -48,11 +48,11 @@
|
||||
#ifdef CONFIG_GRAN
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: gran_common_free
|
||||
* Name: gran_free
|
||||
*
|
||||
* Description:
|
||||
* Return memory to the granule heap.
|
||||
@ -66,9 +66,9 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline void gran_common_free(FAR struct gran_s *priv,
|
||||
FAR void *memory, size_t size)
|
||||
void gran_free(GRAN_HANDLE handle, FAR void *memory, size_t size)
|
||||
{
|
||||
FAR struct gran_s *priv = (FAR struct gran_s *)handle;
|
||||
unsigned int granno;
|
||||
unsigned int gatidx;
|
||||
unsigned int gatbit;
|
||||
@ -77,7 +77,7 @@ static inline void gran_common_free(FAR struct gran_s *priv,
|
||||
unsigned int avail;
|
||||
uint32_t gatmask;
|
||||
|
||||
DEBUGASSERT(priv && memory && size <= 32 * (1 << priv->log2gran));
|
||||
DEBUGASSERT(priv != NULL && memory && size <= 32 * (1 << priv->log2gran));
|
||||
|
||||
/* Get exclusive access to the GAT */
|
||||
|
||||
@ -136,35 +136,4 @@ static inline void gran_common_free(FAR struct gran_s *priv,
|
||||
gran_leave_critical(priv);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: gran_free
|
||||
*
|
||||
* Description:
|
||||
* Return memory to the granule heap.
|
||||
*
|
||||
* Input Parameters:
|
||||
* handle - The handle previously returned by gran_initialize
|
||||
* memory - A pointer to memory previoiusly allocated by gran_alloc.
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
void gran_free(FAR void *memory, size_t size)
|
||||
{
|
||||
return gran_common_free(g_graninfo, memory, size);
|
||||
}
|
||||
#else
|
||||
void gran_free(GRAN_HANDLE handle, FAR void *memory, size_t size)
|
||||
{
|
||||
return gran_common_free((FAR struct gran_s *)handle, memory, size);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_GRAN */
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* mm/mm_gran/mm_graninit.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2012, 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -50,46 +50,64 @@
|
||||
#ifdef CONFIG_GRAN
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/* State of the single GRAN allocator */
|
||||
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
FAR struct gran_s *g_graninfo;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: gran_common_initialize
|
||||
* Name: gran_initialize
|
||||
*
|
||||
* Description:
|
||||
* Perform common GRAN initialization.
|
||||
* Set up one granule allocator instance. Allocations will be aligned to
|
||||
* the alignment size (log2align; allocations will be in units of the
|
||||
* granule size (log2gran). Larger granules will give better performance
|
||||
* and less overhead but more losses of memory due to quantization waste.
|
||||
* Additional memory waste can occur from alignment; log2align should be
|
||||
* set to 0 unless you are using the granule allocator to manage DMA
|
||||
* or page-aligned memory and your hardware has specific memory alignment
|
||||
* requirements.
|
||||
*
|
||||
* General Usage Summary. This is an example using the GCC section
|
||||
* attribute to position a DMA heap in memory (logic in the linker script
|
||||
* would assign the section .dmaheap to the DMA memory.
|
||||
*
|
||||
* FAR uint32_t g_dmaheap[DMAHEAP_SIZE] __attribute__((section(.dmaheap)));
|
||||
*
|
||||
* The heap is created by calling gran_initialize(). Here the granule size
|
||||
* is set to 64 bytes (2**6) and the alignment to 16 bytes (2**4):
|
||||
*
|
||||
* GRAN_HANDLE handle = gran_initialize(g_dmaheap, DMAHEAP_SIZE, 6, 4);
|
||||
*
|
||||
* Then the GRAN_HANDLE can be used to allocate memory:
|
||||
*
|
||||
* FAR uint8_t *dma_memory = (FAR uint8_t *)gran_alloc(handle, 47);
|
||||
*
|
||||
* The actual memory allocates will be 64 byte (wasting 17 bytes) and
|
||||
* will be aligned at least to (1 << log2align).
|
||||
*
|
||||
* NOTE: The current implementation also restricts the maximum allocation
|
||||
* size to 32 granules. That restriction could be eliminated with some
|
||||
* additional coding effort.
|
||||
*
|
||||
* Input Parameters:
|
||||
* heapstart - Start of the granule allocation heap
|
||||
* heapsize - Size of heap in bytes
|
||||
* log2gran - Log base 2 of the size of one granule. 0->1 byte,
|
||||
* 1->2 bytes, 2->4 bytes, 3-> 8 bytes, etc.
|
||||
* 1->2 bytes, 2->4 bytes, 3->8 bytes, etc.
|
||||
* log2align - Log base 2 of required alignment. 0->1 byte,
|
||||
* 1->2 bytes, 2->4 bytes, 3-> 8 bytes, etc. Note that
|
||||
* 1->2 bytes, 2->4 bytes, 3->8 bytes, etc. Note that
|
||||
* log2gran must be greater than or equal to log2align
|
||||
* so that all contiguous granules in memory will meet
|
||||
* the minimum alignment requirement. A value of zero
|
||||
* would mean that no alignment is required.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, a non-NULL info structure is returned that may be used with
|
||||
* other granule allocator interfaces.
|
||||
* On success, a non-NULL handle is returned that may be used with other
|
||||
* granule allocator interfaces.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline FAR struct gran_s *
|
||||
gran_common_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gran,
|
||||
uint8_t log2align)
|
||||
GRAN_HANDLE gran_initialize(FAR void *heapstart, size_t heapsize,
|
||||
uint8_t log2gran, uint8_t log2align)
|
||||
{
|
||||
FAR struct gran_s *priv;
|
||||
uintptr_t heapend;
|
||||
@ -139,87 +157,7 @@ gran_common_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gran,
|
||||
#endif
|
||||
}
|
||||
|
||||
return priv;
|
||||
return (GRAN_HANDLE)priv;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: gran_initialize
|
||||
*
|
||||
* Description:
|
||||
* Set up one granule allocator instance. Allocations will be aligned to
|
||||
* the alignment size (log2align; allocations will be in units of the
|
||||
* granule size (log2gran). Larger granules will give better performance
|
||||
* and less overhead but more losses of memory due to quantization waste.
|
||||
* Additional memory waste can occur from alignment; log2align should be
|
||||
* set to 0 unless you are using the granule allocator to manage DMA
|
||||
* or page-aligned memory and your hardware has specific memory alignment
|
||||
* requirements.
|
||||
*
|
||||
* General Usage Summary. This is an example using the GCC section
|
||||
* attribute to position a DMA heap in memory (logic in the linker script
|
||||
* would assign the section .dmaheap to the DMA memory.
|
||||
*
|
||||
* FAR uint32_t g_dmaheap[DMAHEAP_SIZE] __attribute__((section(.dmaheap)));
|
||||
*
|
||||
* The heap is created by calling gran_initialize(). Here the granule size
|
||||
* is set to 64 bytes (2**6) and the alignment to 16 bytes (2**4):
|
||||
*
|
||||
* GRAN_HANDLE handle = gran_initialize(g_dmaheap, DMAHEAP_SIZE, 6, 4);
|
||||
*
|
||||
* Then the GRAN_HANDLE can be used to allocate memory (There is no
|
||||
* GRAN_HANDLE if CONFIG_GRAN_SINGLE=y):
|
||||
*
|
||||
* FAR uint8_t *dma_memory = (FAR uint8_t *)gran_alloc(handle, 47);
|
||||
*
|
||||
* The actual memory allocates will be 64 byte (wasting 17 bytes) and
|
||||
* will be aligned at least to (1 << log2align).
|
||||
*
|
||||
* NOTE: The current implementation also restricts the maximum allocation
|
||||
* size to 32 granules. That restriction could be eliminated with some
|
||||
* additional coding effort.
|
||||
*
|
||||
* Input Parameters:
|
||||
* heapstart - Start of the granule allocation heap
|
||||
* heapsize - Size of heap in bytes
|
||||
* log2gran - Log base 2 of the size of one granule. 0->1 byte,
|
||||
* 1->2 bytes, 2->4 bytes, 3->8 bytes, etc.
|
||||
* log2align - Log base 2 of required alignment. 0->1 byte,
|
||||
* 1->2 bytes, 2->4 bytes, 3->8 bytes, etc. Note that
|
||||
* log2gran must be greater than or equal to log2align
|
||||
* so that all contiguous granules in memory will meet
|
||||
* the minimum alignment requirement. A value of zero
|
||||
* would mean that no alignment is required.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, a non-NULL handle is returned that may be used with other
|
||||
* granule allocator interfaces.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
int gran_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gran,
|
||||
uint8_t log2align)
|
||||
{
|
||||
g_graninfo = gran_common_initialize(heapstart, heapsize, log2gran,
|
||||
log2align);
|
||||
if (!g_graninfo)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
#else
|
||||
GRAN_HANDLE gran_initialize(FAR void *heapstart, size_t heapsize,
|
||||
uint8_t log2gran, uint8_t log2align)
|
||||
{
|
||||
return (GRAN_HANDLE)gran_common_initialize(heapstart, heapsize,
|
||||
log2gran, log2align);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_GRAN */
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* mm/mm_gran/mm_graninit.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2012, 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -49,43 +49,6 @@
|
||||
|
||||
#ifdef CONFIG_GRAN
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/* State of the single GRAN allocator */
|
||||
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
FAR struct gran_s *g_graninfo;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: gran_release_common
|
||||
*
|
||||
* Description:
|
||||
* Perform common GRAN initialization.
|
||||
*
|
||||
* Input Parameters:
|
||||
* priv - Reference to the granule heap structure to be released.
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline void gran_release_common(FAR struct gran_s *priv)
|
||||
{
|
||||
DEBUGASSERT(priv);
|
||||
#ifndef CONFIG_GRAN_INTR
|
||||
nxsem_destroy(&priv->exclsem);
|
||||
#endif
|
||||
kmm_free(priv);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@ -105,17 +68,16 @@ static inline void gran_release_common(FAR struct gran_s *priv)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
void gran_release(void)
|
||||
{
|
||||
gran_release_common(g_graninfo);
|
||||
g_graninfo = NULL;
|
||||
}
|
||||
#else
|
||||
void gran_release(GRAN_HANDLE handle)
|
||||
{
|
||||
gran_release_common(handle);
|
||||
}
|
||||
FAR struct gran_s *priv = (FAR struct gran_s *)handle;
|
||||
|
||||
DEBUGASSERT(priv != NULL);
|
||||
|
||||
#ifndef CONFIG_GRAN_INTR
|
||||
nxsem_destroy(&priv->exclsem);
|
||||
#endif
|
||||
kmm_free(priv);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_GRAN */
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* mm/mm_gran/mm_granreserve.c
|
||||
*
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2014, 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -47,58 +47,6 @@
|
||||
|
||||
#ifdef CONFIG_GRAN
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: gran_common_reserve
|
||||
*
|
||||
* Description:
|
||||
* Reserve memory in the granule heap. This will reserve the granules
|
||||
* that contain the start and end addresses plus all of the granules
|
||||
* in between. This should be done early in the initialization sequence
|
||||
* before any other allocations are made.
|
||||
*
|
||||
* Reserved memory can never be allocated (it can be freed however which
|
||||
* essentially unreserves the memory).
|
||||
*
|
||||
* Input Parameters:
|
||||
* priv - The granule heap state structure.
|
||||
* start - The address of the beginning of the region to be reserved.
|
||||
* size - The size of the region to be reserved
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline void gran_common_reserve(FAR struct gran_s *priv,
|
||||
uintptr_t start, size_t size)
|
||||
{
|
||||
if (size > 0)
|
||||
{
|
||||
uintptr_t mask = (1 << priv->log2gran) - 1;
|
||||
uintptr_t end = start + size - 1;
|
||||
unsigned int ngranules;
|
||||
|
||||
/* Get the aligned (down) start address and the aligned (up) end
|
||||
* address
|
||||
*/
|
||||
|
||||
start &= ~mask;
|
||||
end = (end + mask) & ~mask;
|
||||
|
||||
/* Calculate the new size in granules */
|
||||
|
||||
ngranules = ((end - start) >> priv->log2gran) + 1;
|
||||
|
||||
/* And reserve the granules */
|
||||
|
||||
gran_mark_allocated(priv, start, ngranules);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@ -125,16 +73,33 @@ static inline void gran_common_reserve(FAR struct gran_s *priv,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
void gran_reserve(uintptr_t start, size_t size)
|
||||
{
|
||||
return gran_common_reserve(g_graninfo, start, size);
|
||||
}
|
||||
#else
|
||||
void gran_reserve(GRAN_HANDLE handle, uintptr_t start, size_t size)
|
||||
{
|
||||
return gran_common_reserve((FAR struct gran_s *)handle, start, size);
|
||||
FAR struct gran_s *priv = (FAR struct gran_s *)handle;
|
||||
|
||||
DEBUGASSERT(priv != NULL);
|
||||
|
||||
if (size > 0)
|
||||
{
|
||||
uintptr_t mask = (1 << priv->log2gran) - 1;
|
||||
uintptr_t end = start + size - 1;
|
||||
unsigned int ngranules;
|
||||
|
||||
/* Get the aligned (down) start address and the aligned (up) end
|
||||
* address
|
||||
*/
|
||||
|
||||
start &= ~mask;
|
||||
end = (end + mask) & ~mask;
|
||||
|
||||
/* Calculate the new size in granules */
|
||||
|
||||
ngranules = ((end - start) >> priv->log2gran) + 1;
|
||||
|
||||
/* And reserve the granules */
|
||||
|
||||
gran_mark_allocated(priv, start, ngranules);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_GRAN */
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* mm/mm_gran/mm_pgalloc.c
|
||||
*
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2014, 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -90,11 +90,9 @@
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_GRAN_SINGLE
|
||||
/* The state of the page allocator */
|
||||
|
||||
static GRAN_HANDLE g_pgalloc;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
@ -123,18 +121,8 @@ static GRAN_HANDLE g_pgalloc;
|
||||
|
||||
void mm_pginitialize(FAR void *heap_start, size_t heap_size)
|
||||
{
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
int ret;
|
||||
|
||||
ret = gran_initialize(heap_start, heap_size, MM_PGSHIFT, MM_PGSHIFT);
|
||||
DEBUGASSERT(ret == OK);
|
||||
UNUSED(ret);
|
||||
|
||||
#else
|
||||
g_pgalloc = gran_initialize(heap_start, heap_size, MM_PGSHIFT, MM_PGSHIFT);
|
||||
DEBUGASSERT(pg_alloc != NULL);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -160,11 +148,7 @@ void mm_pginitialize(FAR void *heap_start, size_t heap_size)
|
||||
|
||||
void mm_pgreserve(uintptr_t start, size_t size)
|
||||
{
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
gran_reserve(start, size);
|
||||
#else
|
||||
gran_reserve(g_pgalloc, start, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -185,11 +169,7 @@ void mm_pgreserve(uintptr_t start, size_t size)
|
||||
|
||||
uintptr_t mm_pgalloc(unsigned int npages)
|
||||
{
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
return (uintptr_t)gran_alloc((size_t)1 << MM_PGSHIFT);
|
||||
#else
|
||||
return (uintptr_t)gran_alloc(g_pgalloc, (size_t)1 << MM_PGSHIFT);
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -211,11 +191,7 @@ uintptr_t mm_pgalloc(unsigned int npages)
|
||||
|
||||
void mm_pgfree(uintptr_t paddr, unsigned int npages)
|
||||
{
|
||||
#ifdef CONFIG_GRAN_SINGLE
|
||||
gran_free((FAR void *)paddr, (size_t)npages << MM_PGSHIFT);
|
||||
#else
|
||||
gran_free(g_pgalloc, (FAR void *)paddr, (size_t)npages << MM_PGSHIFT);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* CONFIG_MM_PGALLOC */
|
||||
|
@ -12,9 +12,6 @@ Prerequisites
|
||||
regions must be provided by the MMU.
|
||||
CONFIG_GRAN=y - The granule allocation is the allocation underlying all
|
||||
paged allocations.
|
||||
CONFIG_GRAN_SINGLE=n - Multiple granule allocators are needed: One for
|
||||
the physical page allocation and one virtual page allocator for each
|
||||
process.
|
||||
CONFIG_MM_PGALLOC=y - Enables the physical page allocator
|
||||
CONFIG_MM_PGSIZE - Determines the size of one page that can be mapped by
|
||||
the MMU.
|
||||
|
Loading…
Reference in New Issue
Block a user