From b028fb31e9a5d5c2354cc8cd94e57516e4f0f100 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 23 Aug 2014 16:35:52 -0600 Subject: [PATCH] include/nuttx/pgalloc.h and mm/mm_pgalloc.c: Add a simple page allocator based on the existing NuttX granule allocator. I am not certain if the granule allocator is sufficiently deterministic for long range use, but it gets get a page allocator in place for testing very quickly. --- include/nuttx/gran.h | 20 ++-- include/nuttx/pgalloc.h | 201 ++++++++++++++++++++++++++++++++++++ mm/Kconfig | 45 +++++++- mm/Makefile | 6 ++ mm/mm_gran.h | 16 +-- mm/mm_granalloc.c | 2 +- mm/mm_graninit.c | 17 +-- mm/mm_granreserve.c | 2 +- mm/mm_pgalloc.c | 223 ++++++++++++++++++++++++++++++++++++++++ 9 files changed, 503 insertions(+), 29 deletions(-) create mode 100644 include/nuttx/pgalloc.h create mode 100644 mm/mm_pgalloc.c diff --git a/include/nuttx/gran.h b/include/nuttx/gran.h index 4993c5b213..2fae5a49e2 100644 --- a/include/nuttx/gran.h +++ b/include/nuttx/gran.h @@ -52,7 +52,7 @@ * Pre-Processor Definitions ****************************************************************************/ /* Configuration ************************************************************/ -/* CONFIG_GRAN - Enable granual allocator support +/* 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 @@ -62,7 +62,7 @@ * mutual exclusion logic will disable interrupts. While this options is * more invasive to system performance, it will also support use of the * granule allocator from interrupt level logic. - * CONFIG_DEBUG_GRAN - Just like CONFIG_DEBUG_MM, but only generates ouput + * CONFIG_DEBUG_GRAN - Just like CONFIG_DEBUG_MM, but only generates output * from the gran allocation logic. */ @@ -80,7 +80,8 @@ typedef FAR void *GRAN_HANDLE; #ifdef __cplusplus #define EXTERN extern "C" -extern "C" { +extern "C" +{ #else #define EXTERN extern #endif @@ -94,16 +95,17 @@ extern "C" { * 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 memory - * and your hardware has specific memory alignment requirements. + * 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. * - * Geneneral Usage Summary. This is an example using the GCC section + * 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 granual size + * The heap is created by calling gran_initialize. Here the granule size * is set to 64 bytes and the alignment to 16 bytes: * * GRAN_HANDLE handle = gran_initialize(g_dmaheap, DMAHEAP_SIZE, 6, 4); @@ -124,9 +126,9 @@ extern "C" { * 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 diff --git a/include/nuttx/pgalloc.h b/include/nuttx/pgalloc.h new file mode 100644 index 0000000000..ebaa06d12e --- /dev/null +++ b/include/nuttx/pgalloc.h @@ -0,0 +1,201 @@ +/**************************************************************************** + * include/nuttx/pgalloc.h + * Page memory allocator. + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_PGALLOC_H +#define __INCLUDE_NUTTX_PGALLOC_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#ifdef CONFIG_MM_PGALLOC + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ +/* CONFIG_MM_PGALLOC - Enable page allocator support + * CONFIG_MM_PGSIZE - The page size. Must be one of {1024, 2048, + * 4096, 8192, or 16384}. This is easily extensible, but only those + * values are currently support. + * CONFIG_MM_PGPOOL_PADDR - Physical address of the start of the page + * memory pool. This will be aligned to the page size if it is not + * already aligned. + * CONFIG_MM_PGPOOL_SIZE - The size of the page memory pool in bytes. This + * will be aligned if it is not already aligned. + * CONFIG_DEBUG_PGALLOC - Just like CONFIG_DEBUG_MM, but only generates + * output from the page allocation logic. + * + * Dependencies: CONFIG_ARCH_HAVE_MMU and CONFIG_GRAN + */ + +#ifndef CONFIG_MM_PGALLOC_PGSIZE +# define CONFIG_MM_PGALLOC_PGSIZE 4096 +#endif + +#ifndef CONFIG_MM_PGPOOL_PADDR +# error CONFIG_MM_PGPOOL_PADDR must be defined +#endif + +#ifndef CONFIG_MM_PGPOOL_SIZE +# error CONFIG_MM_PGPOOL_SIZE must be defined +#endif + +#if CONFIG_MM_PGSIZE == 1024 +# define MM_PGSIZE 1024 +# define MM_PGSHIFT 10 +#elif CONFIG_MM_PGSIZE == 2048 +# define MM_PGSIZE 2048 +# define MM_PGSHIFT 11 +#elif CONFIG_MM_PGSIZE == 4096 +# define MM_PGSIZE 4096 +# define MM_PGSHIFT 12 +#elif CONFIG_MM_PGSIZE == 8192 +# define MM_PGSIZE 8192 +# define MM_PGSHIFT 13 +#elif CONFIG_MM_PGSIZE == 16384 +# define MM_PGSIZE 16384 +# define MM_PGSHIFT 14 +#else +# error CONFIG_MM_PGSIZE not supported +#endif + +#define MM_PGMASK (MM_PGSIZE - 1) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: mm_pginitialize + * + * Description: + * Initialize the page allocator. + * + * Input Parameters: + * None + * + * Returned Value: + * Mpme + * + ****************************************************************************/ + +void mm_pginitialize(void); + +/**************************************************************************** + * Name: mm_pgreserve + * + * Description: + * Reserve memory in the page memory pool. This will reserve the pages + * that contain the start and end addresses plus all of the pages + * 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: + * start - The address of the beginning of the region to be reserved. + * size - The size of the region to be reserved + * + * Returned Value: + * None + * + ****************************************************************************/ + +void mm_pgreserve(uintptr_t start, size_t size); + +/**************************************************************************** + * Name: mm_pgalloc + * + * Description: + * Allocate page memory from the page memory pool. + * + * Input Parameters: + * npages - The number of pages to allocate, each of size CONFIG_MM_PGSIZE. + * + * Returned Value: + * On success, a non-zero, physical address of the allocated page memory + * is returned. Zero is returned on failure. NOTE: This is an unmapped + * physical address and cannot be used until it is appropriately mapped. + * + ****************************************************************************/ + +uintptr_t mm_pgalloc(unsigned int npages); + +/**************************************************************************** + * Name: mm_pgfree + * + * Description: + * Return page memory to the page memory pool. + * + * Input Parameters: + * paddr - A physical address to a page in the page memory pool previously + * allocated by mm_pgalloc. + * npages - The number of contiguous pages to be return to the page memory + * pool, beginning with the page at paddr; + * + * Returned Value: + * None + * + ****************************************************************************/ + +void mm_pgfree(uintptr_t paddr, unsigned int npages); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_MM_PGALLOC */ +#endif /* __INCLUDE_NUTTX_PGALLOC_H */ diff --git a/mm/Kconfig b/mm/Kconfig index 26f7125e4e..0f7d561024 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -101,7 +101,7 @@ config GRAN bool "Enable Granule Allocator" default n ---help--- - Enable granual allocator support. Allocations will be aligned to the + Enable granule allocator support. Allocations will be aligned to the granule size; allocations will be in units of the granule size. Larger granules will give better performance and less overhead but more losses of memory due to alignment and quantization waste. @@ -136,5 +136,46 @@ config DEBUG_GRAN default n depends on GRAN && DEBUG ---help--- - Just like DEBUG_MM, but only generates ouput from the gran + Just like DEBUG_MM, but only generates output from the gran allocation logic. + +config MM_PGALLOC + bool "Enable Page Allocator" + default n + depends on ARCH_HAVE_MMU + select GRAN + ---help--- + Enable support for a MMU physical page allocator based on the + granule allocator. + +if MM_PGALLOC + +config MM_PGSIZE + int "Page Size" + default 4096 + --help--- + The MMU page size. Must be one of {1024, 2048, 4096, 8192, or + 16384}. This is easily extensible, but only those values are + currently support. + +config MM_PGPOOL_PADDR + hex "Page Memory Pool Start" + ---help--- + Physical address of the start of the page memory pool. This + will be aligned to the page size if it is not already aligned. + +config MM_PGPOOL_SIZE + int "Page Memory Pool Size" + ---help--- + The size of the page memory pool in bytes. This will be aligned + if it is not already aligned. + +config DEBUG_PGALLOC + bool "Page Allocator Debug" + default n + depends on DEBUG + ---help--- + Just like DEBUG_MM, but only generates output from the page + allocation logic. + +endif # MM_PGALLOC diff --git a/mm/Makefile b/mm/Makefile index 56b1157d27..f605fc5d44 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -69,6 +69,12 @@ endif ifeq ($(CONFIG_GRAN),y) CSRCS += mm_graninit.c mm_granreserve.c mm_granalloc.c mm_granmark.c CSRCS += mm_granfree.c mm_grancritical.c + +# A page allocator based on the granule allocator + +ifeq ($(CONFIG_MM_PGALLOC),y) +CSRCS += mm_pgalloc.c +endif endif BINDIR ?= bin diff --git a/mm/mm_gran.h b/mm/mm_gran.h index 657aa68b60..8836a5b429 100644 --- a/mm/mm_gran.h +++ b/mm/mm_gran.h @@ -63,19 +63,19 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG_GRAM -# define gramdbg(format, ...) dbg(format, ##__VA_ARGS__) -# define gramvdbg(format, ...) vdbg(format, ##__VA_ARGS__) +# define grandbg(format, ...) dbg(format, ##__VA_ARGS__) +# define granvdbg(format, ...) vdbg(format, ##__VA_ARGS__) # else -# define gramdbg(format, ...) mdbg(format, ##__VA_ARGS__) -# define gramvdbg(format, ...) mvdbg(format, ##__VA_ARGS__) +# define grandbg(format, ...) mdbg(format, ##__VA_ARGS__) +# define granvdbg(format, ...) mvdbg(format, ##__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG_GRAM -# define gramdbg dbg -# define gramvdbg vdbg +# define grandbg dbg +# define granvdbg vdbg # else -# define gramdbg (void) -# define gramvdbg (void) +# define grandbg (void) +# define granvdbg (void) # endif #endif diff --git a/mm/mm_granalloc.c b/mm/mm_granalloc.c index 71647f954b..6e6d375d1e 100644 --- a/mm/mm_granalloc.c +++ b/mm/mm_granalloc.c @@ -235,7 +235,7 @@ static inline FAR void *gran_common_alloc(FAR struct gran_s *priv, size_t size) } /* Set up for the next time through the loop. Perform a 64 - * bit shift to move to the next gram position andi ncrement + * bit shift to move to the next gran position andi ncrement * to the next candidate allocation address. */ diff --git a/mm/mm_graninit.c b/mm/mm_graninit.c index 89ccd71669..673e65ac74 100644 --- a/mm/mm_graninit.c +++ b/mm/mm_graninit.c @@ -102,7 +102,7 @@ gran_common_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gran, unsigned int alignedsize; unsigned int ngranules; - /* Check parameters if debug is on. Note the size of a granual is + /* Check parameters if debug is on. Note the size of a granule is * limited to 2**31 bytes and that the size of the granule must be greater * than the alignment size. */ @@ -159,16 +159,17 @@ gran_common_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gran, * 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 memory - * and your hardware has specific memory alignment requirements. + * 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. * - * Geneneral Usage Summary. This is an example using the GCC section + * 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 granual size + * 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); @@ -189,9 +190,9 @@ gran_common_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gran, * 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 @@ -199,7 +200,7 @@ gran_common_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gran, * * Returned Value: * On success, a non-NULL handle is returned that may be used with other - * granual allocator interfaces. + * granule allocator interfaces. * ****************************************************************************/ diff --git a/mm/mm_granreserve.c b/mm/mm_granreserve.c index e336a228b2..da2a4a38e4 100644 --- a/mm/mm_granreserve.c +++ b/mm/mm_granreserve.c @@ -93,7 +93,7 @@ static inline void gran_common_reserve(FAR struct gran_s *priv, start &= ~mask; end = (end + mask) & ~mask; - /* Calculate the new size in granuales */ + /* Calculate the new size in granules */ ngranules = ((end - start) >> priv->log2gran) + 1; diff --git a/mm/mm_pgalloc.c b/mm/mm_pgalloc.c new file mode 100644 index 0000000000..f270ce67a7 --- /dev/null +++ b/mm/mm_pgalloc.c @@ -0,0 +1,223 @@ +/**************************************************************************** + * mm/mm_pgalloc.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include + +#include "mm_gran.h" + +#ifdef CONFIG_MM_PGALLOC + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ +/* CONFIG_MM_PGALLOC - Enable page allocator support + * CONFIG_MM_PGSIZE - The page size. Must be one of {1024, 2048, + * 4096, 8192, or 16384}. This is easily extensible, but only those + * values are currently support. + * CONFIG_MM_PGPOOL_PADDR - Physical address of the start of the page + * memory pool. This will be aligned to the page size if it is not + * already aligned. + * CONFIG_MM_PGPOOL_SIZE - The size of the page memory pool in bytes. This + * will be aligned if it is not already aligned. + * CONFIG_DEBUG_PGALLOC - Just like CONFIG_DEBUG_MM, but only generates + * output from the page allocation logic. + * + * Dependencies: CONFIG_ARCH_HAVE_MMU and CONFIG_GRAN + */ + +/* Debug */ + +#ifdef CONFIG_CPP_HAVE_VARARGS +# ifdef CONFIG_DEBUG_PGALLOC +# define pgadbg(format, ...) dbg(format, ##__VA_ARGS__) +# define pgavdbg(format, ...) vdbg(format, ##__VA_ARGS__) +# else +# define pgadbg(format, ...) mdbg(format, ##__VA_ARGS__) +# define pgavdbg(format, ...) mvdbg(format, ##__VA_ARGS__) +# endif +#else +# ifdef CONFIG_DEBUG_PGALLOC +# define pgadbg dbg +# define pgavdbg vdbg +# else +# define pgadbg (void) +# define pgavdbg (void) +# endif +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#ifndef CONFIG_GRAN_SINGLE +/* The state of the page allocator */ + +static GRAN_HANDLE g_pgalloc; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mm_pginitialize + * + * Description: + * Initialize the page allocator. + * + * Input Parameters: + * None + * + * Returned Value: + * Mpme + * + ****************************************************************************/ + +void mm_pginitialize(void) +{ +#ifdef CONFIG_GRAN_SINGLE + int ret; + + ret = gran_initialize((FAR void *)CONFIG_MM_PGPOOL_PADDR, + CONFIG_MM_PGPOOL_SIZE, + MM_PGSHIFT, MM_PGSHIFT); + DEBUGASSERT(ret == OK); + UNUSED(ret); + +#else + g_pgalloc = gran_initialize((FAR void *)CONFIG_MM_PGPOOL_PADDR, + CONFIG_MM_PGPOOL_SIZE, + MM_PGSHIFT, MM_PGSHIFT); + DEBUGASSERT(pg_alloc != NULL); + +#endif +} + +/**************************************************************************** + * Name: mm_pgreserve + * + * Description: + * Reserve memory in the page memory pool. This will reserve the pages + * that contain the start and end addresses plus all of the pages + * 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: + * start - The address of the beginning of the region to be reserved. + * size - The size of the region to be reserved + * + * Returned Value: + * None + * + ****************************************************************************/ + +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 +} + +/**************************************************************************** + * Name: mm_pgalloc + * + * Description: + * Allocate page memory from the page memory pool. + * + * Input Parameters: + * npages - The number of pages to allocate, each of size CONFIG_MM_PGSIZE. + * + * Returned Value: + * On success, a non-zero, physical address of the allocated page memory + * is returned. Zero is returned on failure. NOTE: This is an unmapped + * physical address and cannot be used until it is appropriately mapped. + * + ****************************************************************************/ + +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 +} + +/**************************************************************************** + * Name: mm_pgfree + * + * Description: + * Return page memory to the page memory pool. + * + * Input Parameters: + * paddr - A physical address to a page in the page memory pool previously + * allocated by mm_pgalloc. + * npages - The number of contiguous pages to be return to the page memory + * pool, beginning with the page at paddr; + * + * Returned Value: + * None + * + ****************************************************************************/ + +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 */