From b1f711f790ef46a1421bf21686cdb88254aa78d5 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sat, 3 Jul 2021 21:25:14 +0800 Subject: [PATCH] mm: Move procfs_register_meminfo into common place to avoid the code duplication and ensure the consistent behaviour Signed-off-by: Xiang Xiao --- arch/arm/src/stm32/Make.defs | 4 - arch/arm/src/stm32/stm32_ccm.h | 14 +- arch/arm/src/stm32/stm32_procfs_ccm.c | 335 ----------------- arch/arm/src/stm32f7/Make.defs | 3 - arch/arm/src/stm32f7/stm32_dtcm.h | 14 +- arch/arm/src/stm32f7/stm32_procfs_dtcm.c | 348 ----------------- arch/arm/src/stm32h7/Make.defs | 3 - arch/arm/src/stm32h7/stm32_dtcm.h | 14 +- arch/arm/src/stm32h7/stm32_procfs_dtcm.c | 349 ------------------ arch/risc-v/src/esp32c3/esp32c3_rtcheap.c | 12 +- arch/sim/src/sim/up_heap.c | 15 +- arch/xtensa/src/esp32/esp32_imm.c | 12 +- arch/xtensa/src/esp32/esp32_iramheap.c | 12 +- arch/xtensa/src/esp32/esp32_rtcheap.c | 12 +- .../stm32f746g-disco/src/stm32_bringup.c | 9 - .../stm32f769i-disco/src/stm32_bringup.c | 8 - .../stm32h7/nucleo-h743zi/src/stm32_bringup.c | 8 - .../nucleo-h743zi2/src/stm32_bringup.c | 8 - .../stm32h747i-disco/src/stm32_bringup.c | 8 - include/nuttx/mm/mm.h | 4 +- mm/kmm_heap/kmm_initialize.c | 12 +- mm/mm_heap/mm.h | 6 + mm/mm_heap/mm_initialize.c | 15 +- mm/mm_heap/mm_sbrk.c | 2 +- mm/umm_heap/umm_initialize.c | 15 +- 25 files changed, 43 insertions(+), 1199 deletions(-) delete mode 100644 arch/arm/src/stm32/stm32_procfs_ccm.c delete mode 100644 arch/arm/src/stm32f7/stm32_procfs_dtcm.c delete mode 100644 arch/arm/src/stm32h7/stm32_procfs_dtcm.c diff --git a/arch/arm/src/stm32/Make.defs b/arch/arm/src/stm32/Make.defs index 72852241e0..c013fd08da 100644 --- a/arch/arm/src/stm32/Make.defs +++ b/arch/arm/src/stm32/Make.defs @@ -109,10 +109,6 @@ ifeq ($(CONFIG_BUILD_PROTECTED),y) CHIP_CSRCS += stm32_userspace.c stm32_mpuinit.c endif -ifeq ($(CONFIG_STM32_CCM_PROCFS),y) -CHIP_CSRCS += stm32_procfs_ccm.c -endif - ifeq ($(CONFIG_STM32_HAVE_IP_I2C_V1),y) ifeq ($(CONFIG_STM32_I2C_ALT),y) CHIP_CSRCS += stm32_i2c_alt.c diff --git a/arch/arm/src/stm32/stm32_ccm.h b/arch/arm/src/stm32/stm32_ccm.h index 487cc6ea29..fcf3a7ed4d 100644 --- a/arch/arm/src/stm32/stm32_ccm.h +++ b/arch/arm/src/stm32/stm32_ccm.h @@ -69,7 +69,7 @@ */ #define ccm_initialize() \ - mm_initialize(&g_ccm_heap, (FAR void *)CCM_START, CCM_END-CCM_START) + mm_initialize(&g_ccm_heap, "ccm", (FAR void *)CCM_START, CCM_END-CCM_START) /* The ccm_addregion interface could be used if, for example, you want to * add some other memory region to the CCM heap. I don't really know why @@ -118,18 +118,6 @@ EXTERN struct mm_heap_s g_ccm_heap; } #endif -/**************************************************************************** - * Name: ccm_procfs_register - * - * Description: - * Register the CCM procfs file system entry - * - ****************************************************************************/ - -#ifdef CONFIG_STM32_CCM_PROCFS -int ccm_procfs_register(void); -#endif - #endif /* __ASSEMBLY__ */ #endif /* HAVE_CCM_HEAP */ #endif /* __ARCH_ARM_SRC_STM32_STM32_CCM_H */ diff --git a/arch/arm/src/stm32/stm32_procfs_ccm.c b/arch/arm/src/stm32/stm32_procfs_ccm.c deleted file mode 100644 index 0597bb98e5..0000000000 --- a/arch/arm/src/stm32/stm32_procfs_ccm.c +++ /dev/null @@ -1,335 +0,0 @@ -/**************************************************************************** - * arch/arm/src/stm32/stm32_procfs_ccm.c - * - * Copyright (C) 2014 Pelle Windestam. All rights reserved. - * Author: Pelle Windestam (pelle@windestam.se) - * - * 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 -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include "stm32_ccm.h" - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) && \ - defined(CONFIG_FS_PROCFS_REGISTER) && defined(CONFIG_STM32_CCM_PROCFS) - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define CCM_LINELEN 64 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* This structure describes one open "file" */ - -struct ccm_file_s -{ - struct procfs_file_s base; /* Base open file structure */ - unsigned int linesize; /* Number of valid characters in line[] */ - char line[CCM_LINELEN]; /* Pre-allocated buffer for formatted lines */ -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/* File system methods */ - -static int ccm_open(FAR struct file *filep, FAR const char *relpath, - int oflags, mode_t mode); -static int ccm_close(FAR struct file *filep); -static ssize_t ccm_read(FAR struct file *filep, FAR char *buffer, - size_t buflen); -static int ccm_dup(FAR const struct file *oldp, - FAR struct file *newp); -static int ccm_stat(FAR const char *relpath, FAR struct stat *buf); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* See include/nutts/fs/procfs.h - * We use the old-fashioned kind of initializers so that this will compile - * with any compiler. - */ - -static const struct procfs_operations ccm_procfsoperations = -{ - ccm_open, /* open */ - ccm_close, /* close */ - ccm_read, /* read */ - NULL, /* write */ - ccm_dup, /* dup */ - NULL, /* opendir */ - NULL, /* closedir */ - NULL, /* readdir */ - NULL, /* rewinddir */ - ccm_stat /* stat */ -}; - -static const struct procfs_entry_s g_procfs_ccm = -{ - "ccm", - &ccm_procfsoperations -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: ccm_open - ****************************************************************************/ - -static int ccm_open(FAR struct file *filep, FAR const char *relpath, - int oflags, mode_t mode) -{ - FAR struct ccm_file_s *priv; - - finfo("Open '%s'\n", relpath); - - /* PROCFS is read-only. Any attempt to open with any kind of write - * access is not permitted. - * - * REVISIT: Write-able proc files could be quite useful. - */ - - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) - { - ferr("ERROR: Only O_RDONLY supported\n"); - return -EACCES; - } - - /* "cpuload" is the only acceptable value for the relpath */ - - if (strcmp(relpath, "ccm") != 0) - { - ferr("ERROR: relpath is '%s'\n", relpath); - return -ENOENT; - } - - /* Allocate a container to hold the task and attribute selection */ - - priv = (FAR struct ccm_file_s *)kmm_zalloc(sizeof(struct ccm_file_s)); - if (!priv) - { - ferr("ERROR: Failed to allocate file attributes\n"); - return -ENOMEM; - } - - /* Save the index as the open-specific state in filep->f_priv */ - - filep->f_priv = (FAR void *)priv; - return OK; -} - -/**************************************************************************** - * Name: ccm_close - ****************************************************************************/ - -static int ccm_close(FAR struct file *filep) -{ - FAR struct ccm_file_s *priv; - - /* Recover our private data from the struct file instance */ - - priv = (FAR struct ccm_file_s *)filep->f_priv; - DEBUGASSERT(priv); - - /* Release the file attributes structure */ - - kmm_free(priv); - filep->f_priv = NULL; - return OK; -} - -/**************************************************************************** - * Name: ccm_read - ****************************************************************************/ - -static ssize_t ccm_read(FAR struct file *filep, FAR char *buffer, - size_t buflen) -{ - FAR struct ccm_file_s *priv; - size_t linesize; - size_t copysize; - size_t remaining; - size_t totalsize; - struct mallinfo mem; - off_t offset = filep->f_pos; - - finfo("buffer=%p buflen=%d\n", buffer, (int)buflen); - - /* Recover our private data from the struct file instance */ - - priv = (FAR struct ccm_file_s *)filep->f_priv; - DEBUGASSERT(priv); - - mm_mallinfo(&g_ccm_heap, &mem); - - remaining = buflen; - totalsize = 0; - - linesize = snprintf(priv->line, - CCM_LINELEN, - " total used free largest\n"); - copysize = procfs_memcpy(priv->line, linesize, buffer, remaining, &offset); - totalsize += copysize; - buffer += copysize; - remaining -= copysize; - - if (totalsize >= buflen) - { - return totalsize; - } - - linesize = snprintf(priv->line, - CCM_LINELEN, - "Mem: %11d%11d%11d%11d\n", - mem.arena, - mem.uordblks, - mem.fordblks, - mem.mxordblk); - copysize = procfs_memcpy(priv->line, linesize, buffer, remaining, &offset); - totalsize += copysize; - - /* Update the file offset */ - - if (totalsize > 0) - { - filep->f_pos += totalsize; - } - - return totalsize; -} - -/**************************************************************************** - * Name: ccm_dup - * - * Description: - * Duplicate open file data in the new file structure. - * - ****************************************************************************/ - -static int ccm_dup(FAR const struct file *oldp, FAR struct file *newp) -{ - FAR struct ccm_file_s *oldpriv; - FAR struct ccm_file_s *newpriv; - - finfo("Dup %p->%p\n", oldp, newp); - - /* Recover our private data from the old struct file instance */ - - oldpriv = (FAR struct ccm_file_s *)oldp->f_priv; - DEBUGASSERT(oldpriv); - - /* Allocate a new container to hold the task and attribute selection */ - - newpriv = (FAR struct ccm_file_s *)kmm_zalloc(sizeof(struct ccm_file_s)); - if (!newpriv) - { - ferr("ERROR: Failed to allocate file attributes\n"); - return -ENOMEM; - } - - /* The copy the file attributes from the old attributes to the new */ - - memcpy(newpriv, oldpriv, sizeof(struct ccm_file_s)); - - /* Save the new attributes in the new file structure */ - - newp->f_priv = (FAR void *)newpriv; - return OK; -} - -static int ccm_stat(const char *relpath, struct stat *buf) -{ - if (strcmp(relpath, "ccm") != 0) - { - ferr("ERROR: relpath is '%s'\n", relpath); - return -ENOENT; - } - - buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR; - buf->st_size = 0; - buf->st_blksize = 0; - buf->st_blocks = 0; - - return OK; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: ccm_procfs_register - * - * Description: - * Register the CCM procfs file system entry - * - ****************************************************************************/ - -int ccm_procfs_register(void) -{ - return procfs_register(&g_procfs_ccm); -} - -#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS && - * CONFIG_FS_PROCFS_REGISTER && CONFIG_STM32_CCM_PROCFS */ diff --git a/arch/arm/src/stm32f7/Make.defs b/arch/arm/src/stm32f7/Make.defs index 71c5981c3b..ad69a86c85 100644 --- a/arch/arm/src/stm32f7/Make.defs +++ b/arch/arm/src/stm32f7/Make.defs @@ -104,9 +104,6 @@ endif ifeq ($(CONFIG_ARMV7M_DTCM),y) CHIP_CSRCS += stm32_dtcm.c -ifeq ($(CONFIG_STM32F7_DTCM_PROCFS),y) -CHIP_CSRCS += stm32_procfs_dtcm.c -endif endif ifeq ($(CONFIG_STM32F7_DMA),y) diff --git a/arch/arm/src/stm32f7/stm32_dtcm.h b/arch/arm/src/stm32f7/stm32_dtcm.h index 636d2d9ec6..f4265ba5d4 100644 --- a/arch/arm/src/stm32f7/stm32_dtcm.h +++ b/arch/arm/src/stm32f7/stm32_dtcm.h @@ -69,7 +69,7 @@ */ #define dtcm_initialize() \ - mm_initialize(&g_dtcm_heap, (FAR void *)DTCM_START, DTCM_END-DTCM_START) + mm_initialize(&g_dtcm_heap, "dtcm", (FAR void *)DTCM_START, DTCM_END-DTCM_START) /* The dtcm_addregion interface could be used if, for example, you want to * add some other memory region to the DTCM heap. I don't really know why @@ -118,18 +118,6 @@ EXTERN struct mm_heap_s g_dtcm_heap; } #endif -/**************************************************************************** - * Name: dtcm_procfs_register - * - * Description: - * Register the DTCM procfs file system entry - * - ****************************************************************************/ - -#ifdef CONFIG_STM32F7_DTCM_PROCFS -int dtcm_procfs_register(void); -#endif - #endif /* __ASSEMBLY__ */ #endif /* HAVE_DTCM_HEAP */ #endif /* __ARCH_ARM_SRC_STM32F7_STM32_DTCM_H */ diff --git a/arch/arm/src/stm32f7/stm32_procfs_dtcm.c b/arch/arm/src/stm32f7/stm32_procfs_dtcm.c deleted file mode 100644 index cdc9c93a92..0000000000 --- a/arch/arm/src/stm32f7/stm32_procfs_dtcm.c +++ /dev/null @@ -1,348 +0,0 @@ -/**************************************************************************** - * arch/arm/src/stm32f7/stm32_procfs_dtcm.c - * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Based on STM32 CCM code contributed by Pelle Windestam: - * - * Copyright (C) 2014 Pelle Windestam. All rights reserved. - * Author: Pelle Windestam (pelle@windestam.se) - * - * 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 -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include "stm32_dtcm.h" - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) && \ - defined(CONFIG_FS_PROCFS_REGISTER) && defined(CONFIG_STM32F7_DTCM_PROCFS) - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define DTCM_LINELEN 64 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* This enumeration identifies all of the thread attributes that can be - * accessed via the procfs file system. - */ - -/* This structure describes one open "file" */ - -struct dtcm_file_s -{ - struct procfs_file_s base; /* Base open file structure */ - unsigned int linesize; /* Number of valid characters in line[] */ - char line[DTCM_LINELEN]; /* Pre-allocated buffer for formatted lines */ -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/* File system methods */ - -static int dtcm_open(FAR struct file *filep, FAR const char *relpath, - int oflags, mode_t mode); -static int dtcm_close(FAR struct file *filep); -static ssize_t dtcm_read(FAR struct file *filep, FAR char *buffer, - size_t buflen); -static int dtcm_dup(FAR const struct file *oldp, - FAR struct file *newp); -static int dtcm_stat(FAR const char *relpath, FAR struct stat *buf); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* See include/nutts/fs/procfs.h - * We use the old-fashioned kind of initializers so that this will compile - * with any compiler. - */ - -static const struct procfs_operations dtcm_procfsoperations = -{ - dtcm_open, /* open */ - dtcm_close, /* close */ - dtcm_read, /* read */ - NULL, /* write */ - dtcm_dup, /* dup */ - NULL, /* opendir */ - NULL, /* closedir */ - NULL, /* readdir */ - NULL, /* rewinddir */ - dtcm_stat /* stat */ -}; - -static const struct procfs_entry_s g_procfs_dtcm = -{ - "dtcm", - &dtcm_procfsoperations -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: dtcm_open - ****************************************************************************/ - -static int dtcm_open(FAR struct file *filep, FAR const char *relpath, - int oflags, mode_t mode) -{ - FAR struct dtcm_file_s *priv; - - finfo("Open '%s'\n", relpath); - - /* PROCFS is read-only. Any attempt to open with any kind of write - * access is not permitted. - * - * REVISIT: Write-able proc files could be quite useful. - */ - - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) - { - ferr("ERROR: Only O_RDONLY supported\n"); - return -EACCES; - } - - /* "cpuload" is the only acceptable value for the relpath */ - - if (strcmp(relpath, "dtcm") != 0) - { - ferr("ERROR: relpath is '%s'\n", relpath); - return -ENOENT; - } - - /* Allocate a container to hold the task and attribute selection */ - - priv = (FAR struct dtcm_file_s *)kmm_zalloc(sizeof(struct dtcm_file_s)); - if (!priv) - { - ferr("ERROR: Failed to allocate file attributes\n"); - return -ENOMEM; - } - - /* Save the index as the open-specific state in filep->f_priv */ - - filep->f_priv = (FAR void *)priv; - return OK; -} - -/**************************************************************************** - * Name: dtcm_close - ****************************************************************************/ - -static int dtcm_close(FAR struct file *filep) -{ - FAR struct dtcm_file_s *priv; - - /* Recover our private data from the struct file instance */ - - priv = (FAR struct dtcm_file_s *)filep->f_priv; - DEBUGASSERT(priv); - - /* Release the file attributes structure */ - - kmm_free(priv); - filep->f_priv = NULL; - return OK; -} - -/**************************************************************************** - * Name: dtcm_read - ****************************************************************************/ - -static ssize_t dtcm_read(FAR struct file *filep, FAR char *buffer, - size_t buflen) -{ - FAR struct dtcm_file_s *priv; - size_t linesize; - size_t copysize; - size_t remaining; - size_t totalsize; - struct mallinfo mem; - off_t offset = filep->f_pos; - - finfo("buffer=%p buflen=%d\n", buffer, (int)buflen); - - /* Recover our private data from the struct file instance */ - - priv = (FAR struct dtcm_file_s *)filep->f_priv; - DEBUGASSERT(priv); - - mm_mallinfo(&g_dtcm_heap, &mem); - - remaining = buflen; - totalsize = 0; - - linesize = snprintf(priv->line, - DTCM_LINELEN, - " total used free largest\n"); - copysize = procfs_memcpy(priv->line, linesize, buffer, remaining, &offset); - totalsize += copysize; - buffer += copysize; - remaining -= copysize; - - if (totalsize >= buflen) - { - return totalsize; - } - - linesize = snprintf(priv->line, - DTCM_LINELEN, - "Mem: %11d%11d%11d%11d\n", - mem.arena, - mem.uordblks, - mem.fordblks, - mem.mxordblk); - copysize = procfs_memcpy(priv->line, linesize, buffer, remaining, &offset); - totalsize += copysize; - - /* Update the file offset */ - - if (totalsize > 0) - { - filep->f_pos += totalsize; - } - - return totalsize; -} - -/**************************************************************************** - * Name: dtcm_dup - * - * Description: - * Duplicate open file data in the new file structure. - * - ****************************************************************************/ - -static int dtcm_dup(FAR const struct file *oldp, FAR struct file *newp) -{ - FAR struct dtcm_file_s *oldpriv; - FAR struct dtcm_file_s *newpriv; - - finfo("Dup %p->%p\n", oldp, newp); - - /* Recover our private data from the old struct file instance */ - - oldpriv = (FAR struct dtcm_file_s *)oldp->f_priv; - DEBUGASSERT(oldpriv); - - /* Allocate a new container to hold the task and attribute selection */ - - newpriv = (FAR struct dtcm_file_s *)kmm_zalloc(sizeof(struct dtcm_file_s)); - if (!newpriv) - { - ferr("ERROR: Failed to allocate file attributes\n"); - return -ENOMEM; - } - - /* The copy the file attributes from the old attributes to the new */ - - memcpy(newpriv, oldpriv, sizeof(struct dtcm_file_s)); - - /* Save the new attributes in the new file structure */ - - newp->f_priv = (FAR void *)newpriv; - return OK; -} - -static int dtcm_stat(const char *relpath, struct stat *buf) -{ - if (strcmp(relpath, "dtcm") != 0) - { - ferr("ERROR: relpath is '%s'\n", relpath); - return -ENOENT; - } - - buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR; - buf->st_size = 0; - buf->st_blksize = 0; - buf->st_blocks = 0; - - return OK; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: dtcm_procfs_register - * - * Description: - * Register the DTCM procfs file system entry - * - ****************************************************************************/ - -int dtcm_procfs_register(void) -{ - return procfs_register(&g_procfs_dtcm); -} - -#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS && - * CONFIG_FS_PROCFS_REGISTER && CONFIG_STM32F7_DTCM_PROCFS */ diff --git a/arch/arm/src/stm32h7/Make.defs b/arch/arm/src/stm32h7/Make.defs index 2a24c0d954..6b6801bbcc 100644 --- a/arch/arm/src/stm32h7/Make.defs +++ b/arch/arm/src/stm32h7/Make.defs @@ -101,9 +101,6 @@ endif ifeq ($(CONFIG_ARMV7M_DTCM),y) CHIP_CSRCS += stm32_dtcm.c -ifeq ($(CONFIG_STM32H7_DTCM_PROCFS),y) -CHIP_CSRCS += stm32_procfs_dtcm.c -endif endif ifeq ($(CONFIG_STM32H7_ADC),y) diff --git a/arch/arm/src/stm32h7/stm32_dtcm.h b/arch/arm/src/stm32h7/stm32_dtcm.h index c17106266c..358688a6b2 100644 --- a/arch/arm/src/stm32h7/stm32_dtcm.h +++ b/arch/arm/src/stm32h7/stm32_dtcm.h @@ -61,7 +61,7 @@ */ #define dtcm_initialize() \ - mm_initialize(&g_dtcm_heap, (FAR void *)DTCM_START, DTCM_END-DTCM_START) + mm_initialize(&g_dtcm_heap, "dtcm", (FAR void *)DTCM_START, DTCM_END-DTCM_START) /* The dtcm_addregion interface could be used if, for example, you want to * add some other memory region to the DTCM heap. I don't really know why @@ -110,18 +110,6 @@ EXTERN struct mm_heap_s g_dtcm_heap; } #endif -/**************************************************************************** - * Name: dtcm_procfs_register - * - * Description: - * Register the DTCM procfs file system entry - * - ****************************************************************************/ - -#ifdef CONFIG_STM32H7_DTCM_PROCFS -int dtcm_procfs_register(void); -#endif - #endif /* __ASSEMBLY__ */ #endif /* HAVE_DTCM_HEAP */ #endif /* __ARCH_ARM_SRC_STM32H7_STM32_DTCM_H */ diff --git a/arch/arm/src/stm32h7/stm32_procfs_dtcm.c b/arch/arm/src/stm32h7/stm32_procfs_dtcm.c deleted file mode 100644 index b750d936b5..0000000000 --- a/arch/arm/src/stm32h7/stm32_procfs_dtcm.c +++ /dev/null @@ -1,349 +0,0 @@ -/**************************************************************************** - * arch/arm/src/stm32h7/stm32_procfs_dtcm.c - * - * Copyright (C) 2015, 2019 Gregory Nutt. All rights reserved. - * Authors: Gregory Nutt - * David Sidrane - * - * Based on STM32 CCM code contributed by Pelle Windestam: - * - * Copyright (C) 2014 Pelle Windestam. All rights reserved. - * Author: Pelle Windestam (pelle@windestam.se) - * - * 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 -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include "stm32_dtcm.h" - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) && \ - defined(CONFIG_FS_PROCFS_REGISTER) && defined(CONFIG_STM32H7_DTCM_PROCFS) - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define DTCM_LINELEN 64 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* This enumeration identifies all of the thread attributes that can be - * accessed via the procfs file system. - */ - -/* This structure describes one open "file" */ - -struct dtcm_file_s -{ - struct procfs_file_s base; /* Base open file structure */ - unsigned int linesize; /* Number of valid characters in line[] */ - char line[DTCM_LINELEN]; /* Pre-allocated buffer for formatted lines */ -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/* File system methods */ - -static int dtcm_open(FAR struct file *filep, FAR const char *relpath, - int oflags, mode_t mode); -static int dtcm_close(FAR struct file *filep); -static ssize_t dtcm_read(FAR struct file *filep, FAR char *buffer, - size_t buflen); -static int dtcm_dup(FAR const struct file *oldp, - FAR struct file *newp); -static int dtcm_stat(FAR const char *relpath, FAR struct stat *buf); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* See include/nutts/fs/procfs.h - * We use the old-fashioned kind of initializers so that this will compile - * with any compiler. - */ - -static const struct procfs_operations dtcm_procfsoperations = -{ - dtcm_open, /* open */ - dtcm_close, /* close */ - dtcm_read, /* read */ - NULL, /* write */ - dtcm_dup, /* dup */ - NULL, /* opendir */ - NULL, /* closedir */ - NULL, /* readdir */ - NULL, /* rewinddir */ - dtcm_stat /* stat */ -}; - -static const struct procfs_entry_s g_procfs_dtcm = -{ - "dtcm", - &dtcm_procfsoperations -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: dtcm_open - ****************************************************************************/ - -static int dtcm_open(FAR struct file *filep, FAR const char *relpath, - int oflags, mode_t mode) -{ - FAR struct dtcm_file_s *priv; - - finfo("Open '%s'\n", relpath); - - /* PROCFS is read-only. Any attempt to open with any kind of write - * access is not permitted. - * - * REVISIT: Write-able proc files could be quite useful. - */ - - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) - { - ferr("ERROR: Only O_RDONLY supported\n"); - return -EACCES; - } - - /* "cpuload" is the only acceptable value for the relpath */ - - if (strcmp(relpath, "dtcm") != 0) - { - ferr("ERROR: relpath is '%s'\n", relpath); - return -ENOENT; - } - - /* Allocate a container to hold the task and attribute selection */ - - priv = (FAR struct dtcm_file_s *)kmm_zalloc(sizeof(struct dtcm_file_s)); - if (!priv) - { - ferr("ERROR: Failed to allocate file attributes\n"); - return -ENOMEM; - } - - /* Save the index as the open-specific state in filep->f_priv */ - - filep->f_priv = (FAR void *)priv; - return OK; -} - -/**************************************************************************** - * Name: dtcm_close - ****************************************************************************/ - -static int dtcm_close(FAR struct file *filep) -{ - FAR struct dtcm_file_s *priv; - - /* Recover our private data from the struct file instance */ - - priv = (FAR struct dtcm_file_s *)filep->f_priv; - DEBUGASSERT(priv); - - /* Release the file attributes structure */ - - kmm_free(priv); - filep->f_priv = NULL; - return OK; -} - -/**************************************************************************** - * Name: dtcm_read - ****************************************************************************/ - -static ssize_t dtcm_read(FAR struct file *filep, FAR char *buffer, - size_t buflen) -{ - FAR struct dtcm_file_s *priv; - size_t linesize; - size_t copysize; - size_t remaining; - size_t totalsize; - struct mallinfo mem; - off_t offset = filep->f_pos; - - finfo("buffer=%p buflen=%d\n", buffer, (int)buflen); - - /* Recover our private data from the struct file instance */ - - priv = (FAR struct dtcm_file_s *)filep->f_priv; - DEBUGASSERT(priv); - - mm_mallinfo(&g_dtcm_heap, &mem); - - remaining = buflen; - totalsize = 0; - - linesize = snprintf(priv->line, - DTCM_LINELEN, - " total used free largest\n"); - copysize = procfs_memcpy(priv->line, linesize, buffer, remaining, &offset); - totalsize += copysize; - buffer += copysize; - remaining -= copysize; - - if (totalsize >= buflen) - { - return totalsize; - } - - linesize = snprintf(priv->line, - DTCM_LINELEN, - "Mem: %11d%11d%11d%11d\n", - mem.arena, - mem.uordblks, - mem.fordblks, - mem.mxordblk); - copysize = procfs_memcpy(priv->line, linesize, buffer, remaining, &offset); - totalsize += copysize; - - /* Update the file offset */ - - if (totalsize > 0) - { - filep->f_pos += totalsize; - } - - return totalsize; -} - -/**************************************************************************** - * Name: dtcm_dup - * - * Description: - * Duplicate open file data in the new file structure. - * - ****************************************************************************/ - -static int dtcm_dup(FAR const struct file *oldp, FAR struct file *newp) -{ - FAR struct dtcm_file_s *oldpriv; - FAR struct dtcm_file_s *newpriv; - - finfo("Dup %p->%p\n", oldp, newp); - - /* Recover our private data from the old struct file instance */ - - oldpriv = (FAR struct dtcm_file_s *)oldp->f_priv; - DEBUGASSERT(oldpriv); - - /* Allocate a new container to hold the task and attribute selection */ - - newpriv = (FAR struct dtcm_file_s *)kmm_zalloc(sizeof(struct dtcm_file_s)); - if (!newpriv) - { - ferr("ERROR: Failed to allocate file attributes\n"); - return -ENOMEM; - } - - /* The copy the file attributes from the old attributes to the new */ - - memcpy(newpriv, oldpriv, sizeof(struct dtcm_file_s)); - - /* Save the new attributes in the new file structure */ - - newp->f_priv = (FAR void *)newpriv; - return OK; -} - -static int dtcm_stat(const char *relpath, struct stat *buf) -{ - if (strcmp(relpath, "dtcm") != 0) - { - ferr("ERROR: relpath is '%s'\n", relpath); - return -ENOENT; - } - - buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR; - buf->st_size = 0; - buf->st_blksize = 0; - buf->st_blocks = 0; - - return OK; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: dtcm_procfs_register - * - * Description: - * Register the DTCM procfs file system entry - * - ****************************************************************************/ - -int dtcm_procfs_register(void) -{ - return procfs_register(&g_procfs_dtcm); -} - -#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS && - * CONFIG_FS_PROCFS_REGISTER && CONFIG_STM32H7_DTCM_PROCFS */ diff --git a/arch/risc-v/src/esp32c3/esp32c3_rtcheap.c b/arch/risc-v/src/esp32c3/esp32c3_rtcheap.c index ffcbbcb5ed..5de666f92c 100644 --- a/arch/risc-v/src/esp32c3/esp32c3_rtcheap.c +++ b/arch/risc-v/src/esp32c3/esp32c3_rtcheap.c @@ -25,7 +25,6 @@ #include #include -#include #include #include @@ -63,16 +62,7 @@ void esp32c3_rtcheap_initialize(void) start = (FAR void *)&_srtcheap; size = (size_t)((uintptr_t)&_ertcheap - (uintptr_t)&_srtcheap); - mm_initialize(&g_rtcheap, start, size); - -#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO) - static struct procfs_meminfo_entry_s g_rtc_procfs; - - g_rtc_procfs.name = "rtcheap"; - g_rtc_procfs.mallinfo = (void *)mm_mallinfo; - g_rtc_procfs.user_data = &g_rtcheap; - procfs_register_meminfo(&g_rtc_procfs); -#endif + mm_initialize(&g_rtcheap, "rtcheap", start, size); } /**************************************************************************** diff --git a/arch/sim/src/sim/up_heap.c b/arch/sim/src/sim/up_heap.c index 07796b7d2d..5d3da3eb8e 100644 --- a/arch/sim/src/sim/up_heap.c +++ b/arch/sim/src/sim/up_heap.c @@ -53,6 +53,10 @@ struct mm_heap_impl_s #else struct mm_delaynode_s *mm_delaylist[1]; #endif + +#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO) + struct procfs_meminfo_entry_s mm_procfs; +#endif }; /**************************************************************************** @@ -135,8 +139,8 @@ static void mm_free_delaylist(FAR struct mm_heap_s *heap) * ****************************************************************************/ -void mm_initialize(FAR struct mm_heap_s *heap, FAR void *heap_start, - size_t heap_size) +void mm_initialize(FAR struct mm_heap_s *heap, FAR const char *name, + FAR void *heap_start, size_t heap_size) { FAR struct mm_heap_impl_s *impl; @@ -145,6 +149,13 @@ void mm_initialize(FAR struct mm_heap_s *heap, FAR void *heap_start, memset(impl, 0, sizeof(struct mm_heap_impl_s)); heap->mm_impl = impl; + +#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO) + heap_impl->mm_procfs.name = name; + heap_impl->mm_procfs.mallinfo = (FAR void *)mm_mallinfo; + heap_impl->mm_procfs.user_data = heap; + procfs_register_meminfo(&heap_impl->mm_procfs); +#endif } /**************************************************************************** diff --git a/arch/xtensa/src/esp32/esp32_imm.c b/arch/xtensa/src/esp32/esp32_imm.c index 0ef57a019f..220dbd983c 100644 --- a/arch/xtensa/src/esp32/esp32_imm.c +++ b/arch/xtensa/src/esp32/esp32_imm.c @@ -25,7 +25,6 @@ #include #include -#include #include #include #include @@ -63,16 +62,7 @@ void xtensa_imm_initialize(void) start = (FAR void *)ESP32_IMEM_START; size = CONFIG_XTENSA_IMEM_REGION_SIZE; - mm_initialize(&g_iheap, start, size); - -#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO) - static struct procfs_meminfo_entry_s g_imm_procfs; - - g_imm_procfs.name = "esp32-imem"; - g_imm_procfs.mallinfo = (void *)mm_mallinfo; - g_imm_procfs.user_data = &g_iheap; - procfs_register_meminfo(&g_imm_procfs); -#endif + mm_initialize(&g_iheap, "esp32-imem", start, size); } /**************************************************************************** diff --git a/arch/xtensa/src/esp32/esp32_iramheap.c b/arch/xtensa/src/esp32/esp32_iramheap.c index 56d854cccb..b64c39abd4 100644 --- a/arch/xtensa/src/esp32/esp32_iramheap.c +++ b/arch/xtensa/src/esp32/esp32_iramheap.c @@ -25,7 +25,6 @@ #include #include -#include #include #include @@ -61,16 +60,7 @@ void esp32_iramheap_initialize(void) start = (void *)&_siramheap; size = (size_t)((uintptr_t)&_eiramheap - (uintptr_t)&_siramheap); - mm_initialize(&g_iramheap, start, size); - -#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO) - static struct procfs_meminfo_entry_s g_iram_procfs; - - g_iram_procfs.name = "iramheap"; - g_iram_procfs.mallinfo = (void *)mm_mallinfo; - g_iram_procfs.user_data = &g_iramheap; - procfs_register_meminfo(&g_iram_procfs); -#endif + mm_initialize(&g_iramheap, "iramheap", start, size); } /**************************************************************************** diff --git a/arch/xtensa/src/esp32/esp32_rtcheap.c b/arch/xtensa/src/esp32/esp32_rtcheap.c index 43a12b79de..26d540ebb4 100644 --- a/arch/xtensa/src/esp32/esp32_rtcheap.c +++ b/arch/xtensa/src/esp32/esp32_rtcheap.c @@ -25,7 +25,6 @@ #include #include -#include #include #include @@ -61,16 +60,7 @@ void esp32_rtcheap_initialize(void) start = (void *)&_srtcheap; size = (size_t)((uintptr_t)&_ertcheap - (uintptr_t)&_srtcheap); - mm_initialize(&g_rtcheap, start, size); - -#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO) - static struct procfs_meminfo_entry_s g_rtc_procfs; - - g_rtc_procfs.name = "rtcheap"; - g_rtc_procfs.mallinfo = (void *)mm_mallinfo; - g_rtc_procfs.user_data = &g_rtcheap; - procfs_register_meminfo(&g_rtc_procfs); -#endif + mm_initialize(&g_rtcheap, "rtcheap", start, size); } /**************************************************************************** diff --git a/boards/arm/stm32f7/stm32f746g-disco/src/stm32_bringup.c b/boards/arm/stm32f7/stm32f746g-disco/src/stm32_bringup.c index d1943e1fb7..f4f2789000 100644 --- a/boards/arm/stm32f7/stm32f746g-disco/src/stm32_bringup.c +++ b/boards/arm/stm32f7/stm32f746g-disco/src/stm32_bringup.c @@ -63,15 +63,6 @@ int stm32_bringup(void) int ret; #ifdef CONFIG_FS_PROCFS - -#ifdef CONFIG_STM32_CCM_PROCFS - /* Register the CCM procfs entry. This must be done before the procfs is - * mounted. - */ - - ccm_procfs_register(); -#endif - /* Mount the procfs file system */ ret = nx_mount(NULL, STM32_PROCFS_MOUNTPOINT, "procfs", 0, NULL); diff --git a/boards/arm/stm32f7/stm32f769i-disco/src/stm32_bringup.c b/boards/arm/stm32f7/stm32f769i-disco/src/stm32_bringup.c index 24a1e1f51b..e94ae21c89 100644 --- a/boards/arm/stm32f7/stm32f769i-disco/src/stm32_bringup.c +++ b/boards/arm/stm32f7/stm32f769i-disco/src/stm32_bringup.c @@ -57,14 +57,6 @@ int stm32_bringup(void) int ret = OK; #ifdef CONFIG_FS_PROCFS -#ifdef CONFIG_STM32_CCM_PROCFS - /* Register the CCM procfs entry. This must be done before the procfs is - * mounted. - */ - - ccm_procfs_register(); -#endif - /* Mount the procfs file system */ ret = nx_mount(NULL, STM32_PROCFS_MOUNTPOINT, "procfs", 0, NULL); diff --git a/boards/arm/stm32h7/nucleo-h743zi/src/stm32_bringup.c b/boards/arm/stm32h7/nucleo-h743zi/src/stm32_bringup.c index 72e7a5d02e..1bffd62c54 100644 --- a/boards/arm/stm32h7/nucleo-h743zi/src/stm32_bringup.c +++ b/boards/arm/stm32h7/nucleo-h743zi/src/stm32_bringup.c @@ -150,14 +150,6 @@ int stm32_bringup(void) #endif #ifdef CONFIG_FS_PROCFS -#ifdef CONFIG_STM32_CCM_PROCFS - /* Register the CCM procfs entry. This must be done before the procfs is - * mounted. - */ - - ccm_procfs_register(); -#endif /* CONFIG_STM32_CCM_PROCFS */ - /* Mount the procfs file system */ ret = nx_mount(NULL, STM32_PROCFS_MOUNTPOINT, "procfs", 0, NULL); diff --git a/boards/arm/stm32h7/nucleo-h743zi2/src/stm32_bringup.c b/boards/arm/stm32h7/nucleo-h743zi2/src/stm32_bringup.c index af35df434e..5d81cc4d04 100644 --- a/boards/arm/stm32h7/nucleo-h743zi2/src/stm32_bringup.c +++ b/boards/arm/stm32h7/nucleo-h743zi2/src/stm32_bringup.c @@ -72,14 +72,6 @@ int stm32_bringup(void) UNUSED(ret); #ifdef CONFIG_FS_PROCFS -#ifdef CONFIG_STM32_CCM_PROCFS - /* Register the CCM procfs entry. This must be done before the procfs is - * mounted. - */ - - ccm_procfs_register(); -#endif /* CONFIG_STM32_CCM_PROCFS */ - /* Mount the procfs file system */ ret = nx_mount(NULL, "/proc", "procfs", 0, NULL); diff --git a/boards/arm/stm32h7/stm32h747i-disco/src/stm32_bringup.c b/boards/arm/stm32h7/stm32h747i-disco/src/stm32_bringup.c index 025931eca2..95aeb13a32 100644 --- a/boards/arm/stm32h7/stm32h747i-disco/src/stm32_bringup.c +++ b/boards/arm/stm32h7/stm32h747i-disco/src/stm32_bringup.c @@ -136,14 +136,6 @@ int stm32_bringup(void) #endif #ifdef CONFIG_FS_PROCFS -#ifdef CONFIG_STM32_CCM_PROCFS - /* Register the CCM procfs entry. This must be done before the procfs is - * mounted. - */ - - (void)ccm_procfs_register(); -#endif /* CONFIG_STM32_CCM_PROCFS */ - /* Mount the procfs file system */ ret = nx_mount(NULL, STM32_PROCFS_MOUNTPOINT, "procfs", 0, NULL); diff --git a/include/nuttx/mm/mm.h b/include/nuttx/mm/mm.h index c0cf54f397..1269c5c97c 100644 --- a/include/nuttx/mm/mm.h +++ b/include/nuttx/mm/mm.h @@ -158,8 +158,8 @@ EXTERN struct mm_heap_s g_kmmheap; /* Functions contained in mm_initialize.c ***********************************/ -void mm_initialize(FAR struct mm_heap_s *heap, FAR void *heap_start, - size_t heap_size); +void mm_initialize(FAR struct mm_heap_s *heap, FAR const char *name, + FAR void *heap_start, size_t heap_size); void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart, size_t heapsize); diff --git a/mm/kmm_heap/kmm_initialize.c b/mm/kmm_heap/kmm_initialize.c index 7ff5f66e7c..0ddce8507b 100644 --- a/mm/kmm_heap/kmm_initialize.c +++ b/mm/kmm_heap/kmm_initialize.c @@ -24,7 +24,6 @@ #include -#include #include #ifdef CONFIG_MM_KERNEL_HEAP @@ -59,16 +58,7 @@ struct mm_heap_s g_kmmheap; void kmm_initialize(FAR void *heap_start, size_t heap_size) { - mm_initialize(&g_kmmheap, heap_start, heap_size); - -#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO) - static struct procfs_meminfo_entry_s g_kmm_procfs; - - g_kmm_procfs.name = "Kmem"; - g_kmm_procfs.mallinfo = (void *)mm_mallinfo; - g_kmm_procfs.user_data = &g_kmmheap; - procfs_register_meminfo(&g_kmm_procfs); -#endif + mm_initialize(&g_kmmheap, "Kmem", heap_start, heap_size); } #endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/mm/mm_heap/mm.h b/mm/mm_heap/mm.h index b1d13f6bba..17346c5139 100644 --- a/mm/mm_heap/mm.h +++ b/mm/mm_heap/mm.h @@ -27,6 +27,8 @@ #include +#include + #include #include #include @@ -207,6 +209,10 @@ struct mm_heap_impl_s #else FAR struct mm_delaynode_s *mm_delaylist[1]; #endif + +#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO) + struct procfs_meminfo_entry_s mm_procfs; +#endif }; /* Functions contained in mm_sem.c ******************************************/ diff --git a/mm/mm_heap/mm_initialize.c b/mm/mm_heap/mm_initialize.c index 9ac227b33c..c363417843 100644 --- a/mm/mm_heap/mm_initialize.c +++ b/mm/mm_heap/mm_initialize.c @@ -161,14 +161,14 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart, * ****************************************************************************/ -void mm_initialize(FAR struct mm_heap_s *heap, FAR void *heapstart, - size_t heapsize) +void mm_initialize(FAR struct mm_heap_s *heap, FAR const char *name, + FAR void *heapstart, size_t heapsize) { FAR struct mm_heap_impl_s *heap_impl; uintptr_t heap_adj; int i; - minfo("Heap: start=%p size=%zu\n", heapstart, heapsize); + minfo("Heap: name=%s, start=%p size=%zu\n", name, heapstart, heapsize); /* First ensure the memory to be used is aligned */ @@ -216,4 +216,13 @@ void mm_initialize(FAR struct mm_heap_s *heap, FAR void *heapstart, /* Add the initial region of memory to the heap */ mm_addregion(heap, heapstart, heapsize); + +#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO) +#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) + heap_impl->mm_procfs.name = name; + heap_impl->mm_procfs.mallinfo = (FAR void *)mm_mallinfo; + heap_impl->mm_procfs.user_data = heap; + procfs_register_meminfo(&heap_impl->mm_procfs); +#endif +#endif } diff --git a/mm/mm_heap/mm_sbrk.c b/mm/mm_heap/mm_sbrk.c index 7639943f4f..0655a9e032 100644 --- a/mm/mm_heap/mm_sbrk.c +++ b/mm/mm_heap/mm_sbrk.c @@ -130,7 +130,7 @@ FAR void *mm_sbrk(FAR struct mm_heap_s *heap, intptr_t incr, { /* No... then initialize it now */ - mm_initialize(heap, (FAR void *)allocbase, bytesize); + mm_initialize(heap, "Umem", (FAR void *)allocbase, bytesize); } else { diff --git a/mm/umm_heap/umm_initialize.c b/mm/umm_heap/umm_initialize.c index 14ea650b2f..13059d3ce1 100644 --- a/mm/umm_heap/umm_initialize.c +++ b/mm/umm_heap/umm_initialize.c @@ -26,7 +26,6 @@ #include -#include #include #include "umm_heap/umm_heap.h" @@ -82,17 +81,5 @@ void umm_initialize(FAR void *heap_start, size_t heap_size) { - mm_initialize(USR_HEAP, heap_start, heap_size); - -#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO) -#if (defined(CONFIG_BUILD_PROTECTED) && defined(__KERNEL__)) || \ - defined(CONFIG_BUILD_FLAT) - static struct procfs_meminfo_entry_s g_umm_procfs; - - g_umm_procfs.name = "Umem"; - g_umm_procfs.mallinfo = (void *)mm_mallinfo; - g_umm_procfs.user_data = USR_HEAP; - procfs_register_meminfo(&g_umm_procfs); -#endif -#endif + mm_initialize(USR_HEAP, "Umem", heap_start, heap_size); }