You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/05/26 19:29:47 UTC
[nuttx] branch master updated (ac4183e589 -> 6424b5322f)
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
from ac4183e589 socket/send/recv: Copy user parameters to kernel memory (BUILD_KERNEL)
new 6ea3eb3ce2 procfs:add /proc/cpuinfo
new 108c47c07b procfs:add armv7-m cpuinfo
new 5c5d9420af procfs:add armv7-a cpuinfo
new 1abe90c7cd procfs:add armv7-r cpuinfo
new 8a5bf87c72 procfs:add risc-v cpuinfo
new db53c7abcf procfs:add armv8-m cpuinfo
new 6424b5322f procfs:add xtensa cpuinfo
The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
arch/Kconfig | 6 +
arch/arm/Kconfig | 4 +
arch/arm/src/armv7-a/Make.defs | 2 +-
arch/arm/src/armv7-a/arm_cpuinfo.c | 167 +++++++++++++++
arch/arm/src/armv7-m/Make.defs | 2 +-
arch/arm/src/armv7-m/arm_cpuinfo.c | 158 ++++++++++++++
arch/arm/src/armv7-r/Make.defs | 2 +-
arch/arm/src/armv7-r/arm_cpuinfo.c | 148 +++++++++++++
arch/arm/src/armv8-m/Make.defs | 2 +-
arch/arm/src/armv8-m/arm_cpuinfo.c | 144 +++++++++++++
arch/arm/src/common/hwcap.h | 70 +++++++
arch/risc-v/src/common/Make.defs | 2 +-
.../risc-v/src/common/riscv_cpuinfo.c | 83 ++++----
arch/xtensa/src/common/Make.defs | 17 +-
arch/xtensa/src/common/xtensa_cpuinfo.c | 232 +++++++++++++++++++++
fs/procfs/Kconfig | 5 +
fs/procfs/Make.defs | 8 +-
fs/procfs/fs_procfs.c | 5 +
.../{fs_procfsiobinfo.c => fs_procfscpuinfo.c} | 170 +++++----------
fs/procfs/fs_procfsutil.c | 72 +++++++
include/nuttx/arch.h | 19 ++
include/nuttx/fs/procfs.h | 21 ++
22 files changed, 1162 insertions(+), 177 deletions(-)
create mode 100644 arch/arm/src/armv7-a/arm_cpuinfo.c
create mode 100644 arch/arm/src/armv7-m/arm_cpuinfo.c
create mode 100644 arch/arm/src/armv7-r/arm_cpuinfo.c
create mode 100644 arch/arm/src/armv8-m/arm_cpuinfo.c
create mode 100644 arch/arm/src/common/hwcap.h
copy boards/arm/rp2040/raspberrypi-pico/include/rp2040_spisd.h => arch/risc-v/src/common/riscv_cpuinfo.c (53%)
create mode 100644 arch/xtensa/src/common/xtensa_cpuinfo.c
copy fs/procfs/{fs_procfsiobinfo.c => fs_procfscpuinfo.c} (52%)
[nuttx] 05/07: procfs:add risc-v cpuinfo
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 8a5bf87c72fc19ebe7d1831a04be96087c0fee87
Author: liaoao <li...@xiaomi.com>
AuthorDate: Tue May 16 15:41:49 2023 +0800
procfs:add risc-v cpuinfo
Signed-off-by: liaoao <li...@xiaomi.com>
---
arch/Kconfig | 1 +
arch/risc-v/src/common/Make.defs | 2 +-
arch/risc-v/src/common/riscv_cpuinfo.c | 82 ++++++++++++++++++++++++++++++++++
3 files changed, 84 insertions(+), 1 deletion(-)
diff --git a/arch/Kconfig b/arch/Kconfig
index b7f4ca5a2c..f610488d2f 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -78,6 +78,7 @@ config ARCH_RENESAS
config ARCH_RISCV
bool "RISC-V"
select ARCH_HAVE_BACKTRACE
+ select ARCH_HAVE_CPUINFO
select ARCH_HAVE_INTERRUPTSTACK
select ARCH_HAVE_STACKCHECK
select ARCH_HAVE_VFORK
diff --git a/arch/risc-v/src/common/Make.defs b/arch/risc-v/src/common/Make.defs
index b85fdcd100..6fa161de70 100644
--- a/arch/risc-v/src/common/Make.defs
+++ b/arch/risc-v/src/common/Make.defs
@@ -28,7 +28,7 @@ CMN_ASRCS += riscv_saveusercontext.S
# Specify C code within the common directory to be included
CMN_CSRCS += riscv_initialize.c riscv_swint.c riscv_mtimer.c
-CMN_CSRCS += riscv_allocateheap.c riscv_createstack.c
+CMN_CSRCS += riscv_allocateheap.c riscv_createstack.c riscv_cpuinfo.c
CMN_CSRCS += riscv_cpuidlestack.c riscv_doirq.c riscv_exit.c riscv_exception.c
CMN_CSRCS += riscv_getnewintctx.c riscv_getintstack.c riscv_initialstate.c
CMN_CSRCS += riscv_idle.c riscv_modifyreg32.c riscv_nputs.c riscv_releasestack.c
diff --git a/arch/risc-v/src/common/riscv_cpuinfo.c b/arch/risc-v/src/common/riscv_cpuinfo.c
new file mode 100644
index 0000000000..beb6d644eb
--- /dev/null
+++ b/arch/risc-v/src/common/riscv_cpuinfo.c
@@ -0,0 +1,82 @@
+/****************************************************************************
+ * arch/risc-v/src/common/riscv_cpuinfo.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/arch.h>
+#include <nuttx/config.h>
+#include <nuttx/fs/procfs.h>
+
+#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_CPUINFO)
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * name: up_show_cpuinfo
+ ****************************************************************************/
+
+ssize_t up_show_cpuinfo(FAR char *buf, size_t buf_size, off_t file_off)
+{
+ int i;
+
+ for (i = 0; i < CONFIG_SMP_NCPUS; i++)
+ {
+ procfs_sprintf(buf, buf_size, &file_off, "processor\t: %d\n", i);
+ procfs_sprintf(buf, buf_size, &file_off, "hart\t\t: %d\n", i);
+
+ /* ISA */
+
+ procfs_sprintf(buf, buf_size, &file_off, "isa\t\t: %si",
+ CONFIG_ARCH_FAMILY);
+#ifdef CONFIG_ARCH_RV_ISA_M
+ procfs_sprintf(buf, buf_size, &file_off, "%s", "m");
+#endif
+#ifdef CONFIG_ARCH_RV_ISA_A
+ procfs_sprintf(buf, buf_size, &file_off, "%s", "a");
+#endif
+#ifdef CONFIG_ARCH_FPU
+ procfs_sprintf(buf, buf_size, &file_off, "%s", "f");
+#endif
+#ifdef CONFIG_ARCH_DPFPU
+ procfs_sprintf(buf, buf_size, &file_off, "%s", "d");
+#endif
+#ifdef CONFIG_ARCH_RV_ISA_C
+ procfs_sprintf(buf, buf_size, &file_off, "%s", "c");
+#endif
+
+ /* MMU type */
+
+ procfs_sprintf(buf, buf_size, &file_off, "\nmmu\t\t: ");
+#ifdef ARCH_HAVE_MMU
+# ifdef ARCH_MMU_TYPE_SV39
+ procfs_sprintf(buf, buf_size, &file_off, "%s\n", "sv39");
+# endif
+#else
+ procfs_sprintf(buf, buf_size, &file_off, "%s\n", "none");
+#endif
+ }
+
+ return -file_off;
+}
+#endif /* CONFIG_FS_PROCFS && !CONFIG_FS_PROCFS_EXCLUDE_CPUINFO */
[nuttx] 02/07: procfs:add armv7-m cpuinfo
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 108c47c07b0829c4e08bd4a9b12a513411848661
Author: liaoao <li...@xiaomi.com>
AuthorDate: Sun Apr 23 11:57:19 2023 +0800
procfs:add armv7-m cpuinfo
Signed-off-by: liaoao <li...@xiaomi.com>
---
arch/arm/Kconfig | 1 +
arch/arm/src/armv7-m/Make.defs | 2 +-
arch/arm/src/armv7-m/arm_cpuinfo.c | 158 +++++++++++++++++++++++++++++++++++++
arch/arm/src/common/hwcap.h | 69 ++++++++++++++++
include/nuttx/fs/procfs.h | 2 +-
5 files changed, 230 insertions(+), 2 deletions(-)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 114ed5fd92..1c9d8a730b 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -718,6 +718,7 @@ config ARCH_CORTEXM0
config ARCH_ARMV7M
bool
default n
+ select ARCH_HAVE_CPUINFO
config ARCH_CORTEXM3
bool
diff --git a/arch/arm/src/armv7-m/Make.defs b/arch/arm/src/armv7-m/Make.defs
index 056a5d582f..2cdb688b89 100644
--- a/arch/arm/src/armv7-m/Make.defs
+++ b/arch/arm/src/armv7-m/Make.defs
@@ -24,7 +24,7 @@ include common/Make.defs
CMN_ASRCS += arm_exception.S arm_saveusercontext.S
-CMN_CSRCS += arm_busfault.c arm_cache.c arm_doirq.c
+CMN_CSRCS += arm_busfault.c arm_cache.c arm_cpuinfo.c arm_doirq.c
CMN_CSRCS += arm_hardfault.c arm_initialstate.c arm_itm.c
CMN_CSRCS += arm_memfault.c arm_perf.c
CMN_CSRCS += arm_schedulesigaction.c arm_sigdeliver.c
diff --git a/arch/arm/src/armv7-m/arm_cpuinfo.c b/arch/arm/src/armv7-m/arm_cpuinfo.c
new file mode 100644
index 0000000000..0b677e651e
--- /dev/null
+++ b/arch/arm/src/armv7-m/arm_cpuinfo.c
@@ -0,0 +1,158 @@
+/****************************************************************************
+ * arch/arm/src/armv7-m/arm_cpuinfo.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/procfs.h>
+#include <nuttx/arch.h>
+
+#include "arm_internal.h"
+#include "hwcap.h"
+#include "nvic.h"
+
+#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_CPUINFO)
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * name: hwcap_extract_field
+ ****************************************************************************/
+
+static int hwcap_extract_field(uint32_t features, int field)
+{
+ int feature;
+
+ feature = (features >> field) & 0xf;
+ if (feature > 7)
+ feature -= 16;
+
+ return feature;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * name: up_show_cpuinfo
+ ****************************************************************************/
+
+ssize_t up_show_cpuinfo(FAR char *buf, size_t buf_size, off_t file_off)
+{
+ int i;
+ uint32_t cpuid;
+
+ for (i = 0; i < CONFIG_SMP_NCPUS; i++)
+ {
+ procfs_sprintf(buf, buf_size, &file_off, "processor\t: %d\n", i);
+ procfs_sprintf(buf, buf_size, &file_off, "BogoMIPS\t: %u.%02u\n",
+ (CONFIG_BOARD_LOOPSPERMSEC / 1000),
+ (CONFIG_BOARD_LOOPSPERMSEC / 10) % 100);
+ procfs_sprintf(buf, buf_size, &file_off, "cpu MHz\t\t: %lu.%02lu\n",
+ up_perf_getfreq() / 1000000,
+ (up_perf_getfreq() / 10000) % 100);
+
+ /* CPU Features */
+
+ procfs_sprintf(buf, buf_size, &file_off, "Features\t:");
+ procfs_sprintf(buf, buf_size, &file_off, " %s %s",
+ HWCAP_HALF, HWCAP_FAST_MULT);
+
+ /* If the CPU supports LDREX/STREX and LDREXB/STREXB,
+ * avoid advertising SWP; it may not be atomic with
+ * multiprocessing cores.
+ */
+
+ if (hwcap_extract_field(getreg32(NVIC_ISAR3), 12) <= 1 &&
+ hwcap_extract_field(getreg32(NVIC_ISAR4), 20) < 3)
+ {
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_SWP);
+ }
+
+ if (hwcap_extract_field(getreg32(NVIC_ISAR0), 24) == 1)
+#ifdef CONFIG_ARM_THUMB
+ {
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_IDIVT);
+ }
+
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_THUMB);
+#else
+ {
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_IDIVA);
+ }
+#endif
+
+#if defined(CONFIG_ARCH_CORTEXM4) || defined(CONFIG_ARCH_CORTEXM7)
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_EDSP);
+#endif
+
+#ifdef CONFIG_SCHED_THREAD_LOCAL
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_TLS);
+#endif
+
+ /* LPAE implies atomic ldrd/strd instructions */
+
+ if (hwcap_extract_field(getreg32(NVIC_ISAR2), 0) == 1)
+ {
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_LPAE);
+ }
+
+ /* VFP Features */
+
+#if defined(CONFIG_ARCH_FPU)
+# ifdef CONFIG_ARCH_CORTEXM4
+ procfs_sprintf(buf, buf_size, &file_off, " %s %s %s",
+ HWCAP_VFPV4, HWCAP_FPSP, HWCAP_VFPV3D16);
+# elif defined(CONFIG_ARCH_CORTEXM7)
+ procfs_sprintf(buf, buf_size, &file_off, " %s %s %s",
+ HWCAP_FPV5, HWCAP_FPSP, HWCAP_VFPV3D16);
+# ifdef CONFIG_ARCH_DPFPU
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_FPDP);
+# endif
+# endif
+#endif
+
+ /* Cpuid info */
+
+ cpuid = getreg32(NVIC_CPUID_BASE);
+ procfs_sprintf(buf, buf_size, &file_off,
+ "\nmodel name\t: %s rev %" PRIx32 " (%s)\n"
+ "CPU architecture: %s\n",
+ "ARMv7-M", cpuid & 15, "v7ml", "7M");
+
+ procfs_sprintf(buf, buf_size, &file_off,
+ "CPU implementer\t: 0x%02" PRIx32 "\n"
+ "CPU variant\t: 0x%" PRIx32 "\n"
+ "CPU part\t: 0x%03" PRIx32 "\n"
+ "CPU revision\t: %" PRIu32"\n\n",
+ cpuid >> 24,
+ (cpuid >> 20) & 0xf,
+ (cpuid >> 4) & 0xfff,
+ cpuid & 0xf);
+ }
+
+ return -file_off;
+}
+#endif /* CONFIG_FS_PROCFS && !CONFIG_FS_PROCFS_EXCLUDE_CPUINFO */
diff --git a/arch/arm/src/common/hwcap.h b/arch/arm/src/common/hwcap.h
new file mode 100644
index 0000000000..eba334ae1e
--- /dev/null
+++ b/arch/arm/src/common/hwcap.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+ * arch/arm/src/common/hwcap.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_ARM_SRC_COMMON_HWCAP_H
+#define __ARCH_ARM_SRC_COMMON_HWCAP_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Hardware capabilities */
+
+#define HWCAP_SWP "swp" /* SWP instruction */
+#define HWCAP_HALF "half" /* Half word */
+#define HWCAP_THUMB "thumb" /* Thumb instruction set support */
+#define HWCAP_26BIT "26bit" /* Play it safe */
+#define HWCAP_FAST_MULT "fastmult" /* Long multiply such as umull and umlal */
+#define HWCAP_FPA "fpa"
+#define HWCAP_VFP "vfp"
+#define HWCAP_EDSP "edsp" /* Enhanced dsp instruction */
+#define HWCAP_JAVA "java"
+#define HWCAP_IWMMXT "iwmmxt"
+#define HWCAP_CRUNCH "crunch"
+#define HWCAP_THUMBEE "thumbee"
+#define HWCAP_NEON "neon" /* Advanced SIMD extension */
+#define HWCAP_VFPV3 "vfpv3" /* Floating-point extension version */
+#define HWCAP_VFPV3D16 "vfpv3d16" /* Also set for vfpv4-d16 */
+#define HWCAP_TLS "tls" /* Thread local storage */
+#define HWCAP_VFPV4 "vfpv4" /* Floating-point extension version */
+#define HWCAP_IDIVA "idiva" /* SDIV and UDIV instruction */
+#define HWCAP_IDIVT "idivt" /* SDIV and UDIV in thumb instruction set */
+#define HWCAP_VFPD32 "vfpd32" /* Set if VFP has 32 64-bit regs (not 16) */
+#define HWCAP_LPAE "lpae" /* LDRD/STRD instructions */
+#define HWCAP_EVTSTRM "evtstrm"
+#define HWCAP_FPHP "fphp" /* Half-precision instructions support */
+#define HWCAP_FPSP "fpsp" /* Single-precision instructions support */
+#define HWCAP_FPDP "fpdp" /* Double-precision instructions support */
+#define HWCAP_FPV5 "fpv5" /* Floating-point extension version */
+
+/* Hardware capabilities added form armv8 */
+
+#define HWCAP2_AES "aes"
+#define HWCAP2_PMULL "pmull"
+#define HWCAP2_SHA1 "sha1"
+#define HWCAP2_SHA2 "sha2"
+#define HWCAP2_CRC32 "crc32"
+
+#endif /* __ARCH_ARM_SRC_COMMON_HWCAP_H */
diff --git a/include/nuttx/fs/procfs.h b/include/nuttx/fs/procfs.h
index 04a64d69e9..f14dceeca9 100644
--- a/include/nuttx/fs/procfs.h
+++ b/include/nuttx/fs/procfs.h
@@ -241,7 +241,7 @@ int procfs_snprintf(FAR char *buf, size_t size,
****************************************************************************/
void procfs_sprintf(FAR char *buf, size_t size, FAR off_t *offset,
- FAR const IPTR char *format, ...);
+ FAR const IPTR char *format, ...) printf_like(4, 5);
/****************************************************************************
* Name: procfs_register
[nuttx] 04/07: procfs:add armv7-r cpuinfo
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 1abe90c7cd496f548814fdaa8c7c988516f25af2
Author: liaoao <li...@xiaomi.com>
AuthorDate: Sat May 6 17:51:36 2023 +0800
procfs:add armv7-r cpuinfo
Signed-off-by: liaoao <li...@xiaomi.com>
---
arch/arm/Kconfig | 1 +
arch/arm/src/armv7-r/Make.defs | 2 +-
arch/arm/src/armv7-r/arm_cpuinfo.c | 148 +++++++++++++++++++++++++++++++++++++
3 files changed, 150 insertions(+), 1 deletion(-)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 050bb98834..7090d9e5a6 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -821,6 +821,7 @@ config ARCH_CORTEXA9
config ARCH_ARMV7R
bool
default n
+ select ARCH_HAVE_CPUINFO
config ARCH_CORTEXR4
bool
diff --git a/arch/arm/src/armv7-r/Make.defs b/arch/arm/src/armv7-r/Make.defs
index c246414600..4d13b3b610 100644
--- a/arch/arm/src/armv7-r/Make.defs
+++ b/arch/arm/src/armv7-r/Make.defs
@@ -29,7 +29,7 @@ HEAD_ASRC += arm_vectortab.S
# Common assembly language files
-CMN_CSRCS += arm_cache.c arm_dataabort.c arm_doirq.c arm_gicv2.c
+CMN_CSRCS += arm_cache.c arm_cpuinfo.c arm_dataabort.c arm_doirq.c arm_gicv2.c
CMN_CSRCS += arm_initialstate.c arm_prefetchabort.c
CMN_CSRCS += arm_schedulesigaction.c arm_sigdeliver.c
CMN_CSRCS += arm_syscall.c arm_tcbinfo.c arm_undefinedinsn.c
diff --git a/arch/arm/src/armv7-r/arm_cpuinfo.c b/arch/arm/src/armv7-r/arm_cpuinfo.c
new file mode 100644
index 0000000000..522729b46f
--- /dev/null
+++ b/arch/arm/src/armv7-r/arm_cpuinfo.c
@@ -0,0 +1,148 @@
+/****************************************************************************
+ * arch/arm/src/armv7-r/arm_cpuinfo.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/arch.h>
+#include <nuttx/config.h>
+#include <nuttx/fs/procfs.h>
+
+#include "arm_internal.h"
+#include "hwcap.h"
+#include "cp15.h"
+
+#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_CPUINFO)
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * name: hwcap_extract_field
+ ****************************************************************************/
+
+static int hwcap_extract_field(uint32_t features, int field)
+{
+ int feature;
+
+ feature = (features >> field) & 0xf;
+ if (feature > 7)
+ {
+ feature -= 16;
+ }
+
+ return feature;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * name: up_show_cpuinfo
+ ****************************************************************************/
+
+ssize_t up_show_cpuinfo(FAR char *buf, size_t buf_size, off_t file_off)
+{
+ int i;
+ uint32_t cpuid;
+
+ for (i = 0; i < CONFIG_SMP_NCPUS; i++)
+ {
+ procfs_sprintf(buf, buf_size, &file_off, "processor\t: %d\n", i);
+ procfs_sprintf(buf, buf_size, &file_off, "BogoMIPS\t: %u.%02u\n",
+ (CONFIG_BOARD_LOOPSPERMSEC / 1000),
+ (CONFIG_BOARD_LOOPSPERMSEC / 10) % 100);
+ procfs_sprintf(buf, buf_size, &file_off, "cpu MHz\t\t: %lu.%02lu\n",
+ up_perf_getfreq() / 1000000,
+ (up_perf_getfreq() / 10000) % 100);
+
+ /* CPU Features */
+
+ procfs_sprintf(buf, buf_size, &file_off, "Features\t:");
+ procfs_sprintf(buf, buf_size, &file_off, " %s %s %s",
+ HWCAP_HALF, HWCAP_FAST_MULT, HWCAP_EDSP);
+
+ /* If the CPU supports LDREX/STREX and LDREXB/STREXB,
+ * avoid advertising SWP; it may not be atomic with
+ * multiprocessing cores.
+ */
+
+ if (hwcap_extract_field(CP15_GET(ID_ISAR3), 12) <= 1 &&
+ hwcap_extract_field(CP15_GET(ID_ISAR4), 20) < 3)
+ {
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_SWP);
+ }
+
+#ifdef CONFIG_ARM_THUMB
+ if (hwcap_extract_field(CP15_GET(ID_ISAR0), 24) >= 1)
+ {
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_IDIVT);
+ }
+
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_THUMB);
+#endif
+ if (hwcap_extract_field(CP15_GET(ID_ISAR0), 24) == 2)
+ {
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_IDIVA);
+ }
+
+#ifdef CONFIG_SCHED_THREAD_LOCAL
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_TLS);
+#endif
+
+ /* LPAE implies atomic ldrd/strd instructions */
+
+ if (hwcap_extract_field(CP15_GET(ID_ISAR2), 0) == 1)
+ {
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_LPAE);
+ }
+
+ /* VFP Features */
+
+#if defined(CONFIG_ARCH_FPU)
+ procfs_sprintf(buf, buf_size, &file_off, " %s %s %s %s",
+ HWCAP_VFPV3, HWCAP_FPSP, HWCAP_FPDP, HWCAP_VFPV3D16);
+#endif
+
+ /* Cpuid info */
+
+ cpuid = CP15_GET(MIDR);
+ procfs_sprintf(buf, buf_size, &file_off,
+ "\nmodel name\t: %s rev %" PRIx32 " (%s)\n"
+ "CPU architecture: %s\n",
+ "ARMv7 Processor", cpuid & 15, "v7", "7");
+
+ procfs_sprintf(buf, buf_size, &file_off,
+ "CPU implementer\t: 0x%02" PRIx32 "\n"
+ "CPU variant\t: 0x%" PRIx32 "\n"
+ "CPU part\t: 0x%03" PRIx32 "\n"
+ "CPU revision\t: %" PRIu32 "\n\n",
+ cpuid >> 24,
+ (cpuid >> 20) & 0xf,
+ (cpuid >> 4) & 0xfff,
+ cpuid & 0xf);
+ }
+
+ return -file_off;
+}
+#endif /* CONFIG_FS_PROCFS && !CONFIG_FS_PROCFS_EXCLUDE_CPUINFO */
[nuttx] 03/07: procfs:add armv7-a cpuinfo
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 5c5d9420af76070456dc767aa8dc411d2b13b9b8
Author: liaoao <li...@xiaomi.com>
AuthorDate: Sat May 6 15:46:36 2023 +0800
procfs:add armv7-a cpuinfo
Signed-off-by: liaoao <li...@xiaomi.com>
---
arch/arm/Kconfig | 1 +
arch/arm/src/armv7-a/Make.defs | 2 +-
arch/arm/src/armv7-a/arm_cpuinfo.c | 167 +++++++++++++++++++++++++++++++++++++
3 files changed, 169 insertions(+), 1 deletion(-)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 1c9d8a730b..050bb98834 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -772,6 +772,7 @@ config ARCH_CORTEXM7
config ARCH_ARMV7A
bool
default n
+ select ARCH_HAVE_CPUINFO
select ARM_HAVE_WFE_SEV
config ARCH_CORTEXA5
diff --git a/arch/arm/src/armv7-a/Make.defs b/arch/arm/src/armv7-a/Make.defs
index 618699ff0e..ddb629b693 100644
--- a/arch/arm/src/armv7-a/Make.defs
+++ b/arch/arm/src/armv7-a/Make.defs
@@ -41,7 +41,7 @@ CMN_ASRCS += arm_saveusercontext.S
# Common C source files
-CMN_CSRCS += arm_cache.c arm_dataabort.c
+CMN_CSRCS += arm_cache.c arm_cpuinfo.c arm_dataabort.c
CMN_CSRCS += arm_doirq.c arm_gicv2.c arm_gicv2_dump.c
CMN_CSRCS += arm_initialstate.c arm_mmu.c arm_prefetchabort.c
CMN_CSRCS += arm_schedulesigaction.c arm_sigdeliver.c
diff --git a/arch/arm/src/armv7-a/arm_cpuinfo.c b/arch/arm/src/armv7-a/arm_cpuinfo.c
new file mode 100644
index 0000000000..cc1b0e3508
--- /dev/null
+++ b/arch/arm/src/armv7-a/arm_cpuinfo.c
@@ -0,0 +1,167 @@
+/****************************************************************************
+ * arch/arm/src/armv7-a/arm_cpuinfo.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/arch.h>
+#include <nuttx/config.h>
+#include <nuttx/fs/procfs.h>
+
+#include "arm_internal.h"
+#include "hwcap.h"
+#include "cp15.h"
+
+#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_CPUINFO)
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * name: hwcap_extract_field
+ ****************************************************************************/
+
+static int hwcap_extract_field(uint32_t features, int field)
+{
+ int feature;
+
+ feature = (features >> field) & 0xf;
+ if (feature > 7)
+ {
+ feature -= 16;
+ }
+
+ return feature;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * name: up_show_cpuinfo
+ ****************************************************************************/
+
+ssize_t up_show_cpuinfo(FAR char *buf, size_t buf_size, off_t file_off)
+{
+ int i;
+ uint32_t cpuid;
+
+ for (i = 0; i < CONFIG_SMP_NCPUS; i++)
+ {
+ procfs_sprintf(buf, buf_size, &file_off, "processor\t: %d\n", i);
+ procfs_sprintf(buf, buf_size, &file_off, "BogoMIPS\t: %u.%02u\n",
+ (CONFIG_BOARD_LOOPSPERMSEC / 1000),
+ (CONFIG_BOARD_LOOPSPERMSEC / 10) % 100);
+ procfs_sprintf(buf, buf_size, &file_off, "cpu MHz\t\t: %lu.%02lu\n",
+ up_perf_getfreq() / 1000000,
+ (up_perf_getfreq() / 10000) % 100);
+
+ /* CPU Features */
+
+ procfs_sprintf(buf, buf_size, &file_off, "Features\t:");
+ procfs_sprintf(buf, buf_size, &file_off, " %s %s %s",
+ HWCAP_HALF, HWCAP_FAST_MULT, HWCAP_EDSP);
+
+ /* If the CPU supports LDREX/STREX and LDREXB/STREXB,
+ * avoid advertising SWP; it may not be atomic with
+ * multiprocessing cores.
+ */
+
+ if (hwcap_extract_field(CP15_GET(ID_ISAR3), 12) <= 1 &&
+ hwcap_extract_field(CP15_GET(ID_ISAR4), 20) < 3)
+ {
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_SWP);
+ }
+
+#ifdef CONFIG_ARM_THUMB
+ if (hwcap_extract_field(CP15_GET(ID_ISAR0), 24) >= 1)
+ {
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_IDIVT);
+ }
+
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_THUMB);
+#endif
+ if (hwcap_extract_field(CP15_GET(ID_ISAR0), 24) == 2)
+ {
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_IDIVA);
+ }
+
+#ifdef CONFIG_SCHED_THREAD_LOCAL
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_TLS);
+#endif
+
+ /* LPAE implies atomic ldrd/strd instructions */
+
+ if (hwcap_extract_field(CP15_GET(ID_ISAR2), 0) == 1)
+ {
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_LPAE);
+ }
+
+ /* VFP Features */
+
+#if defined(CONFIG_ARCH_FPU)
+# if defined(CONFIG_ARCH_CORTEXA8) || defined(CONFIG_ARCH_CORTEXA9)
+ procfs_sprintf(buf, buf_size, &file_off, " %s %s %s",
+ HWCAP_VFPV3, HWCAP_FPSP, HWCAP_FPDP);
+# else
+ procfs_sprintf(buf, buf_size, &file_off, " %s %s %s",
+ HWCAP_VFPV4, HWCAP_FPSP, HWCAP_FPDP);
+# endif
+
+# if defined(CONFIG_ARCH_CORTEXA5) || defined(CONFIG_ARCH_CORTEXA9)
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_FPHP);
+# endif
+
+# ifdef CONFIG_ARM_DPFPU32
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_VFPD32);
+# else
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_VFPV3D16);
+# endif
+
+# ifdef CONFIG_ARM_NEON
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_NEON);
+# endif
+#endif
+
+ /* Cpuid info */
+
+ cpuid = CP15_GET(MIDR);
+ procfs_sprintf(buf, buf_size, &file_off,
+ "\nmodel name\t: %s rev %" PRIx32 " (%s)\n"
+ "CPU architecture: %s\n",
+ "ARMv7 Processor", cpuid & 15, "v7", "7");
+
+ procfs_sprintf(buf, buf_size, &file_off,
+ "CPU implementer\t: 0x%02" PRIx32 "\n"
+ "CPU variant\t: 0x%" PRIx32 "\n"
+ "CPU part\t: 0x%03" PRIx32 "\n"
+ "CPU revision\t: %" PRIu32 "\n\n",
+ cpuid >> 24,
+ (cpuid >> 20) & 0xf,
+ (cpuid >> 4) & 0xfff,
+ cpuid & 0xf);
+ }
+
+ return -file_off;
+}
+#endif /* CONFIG_FS_PROCFS && !CONFIG_FS_PROCFS_EXCLUDE_CPUINFO */
[nuttx] 06/07: procfs:add armv8-m cpuinfo
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit db53c7abcf3f9b55076ed89b5b6702a3a56f4385
Author: liaoao <li...@xiaomi.com>
AuthorDate: Thu Apr 27 20:04:16 2023 +0800
procfs:add armv8-m cpuinfo
Signed-off-by: liaoao <li...@xiaomi.com>
---
arch/arm/Kconfig | 1 +
arch/arm/src/armv8-m/Make.defs | 2 +-
arch/arm/src/armv8-m/arm_cpuinfo.c | 144 +++++++++++++++++++++++++++++++++++++
arch/arm/src/common/hwcap.h | 1 +
4 files changed, 147 insertions(+), 1 deletion(-)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 7090d9e5a6..613c15199f 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -853,6 +853,7 @@ config ARCH_CORTEXR7
config ARCH_ARMV8M
bool
default n
+ select ARCH_HAVE_CPUINFO
config ARCH_CORTEXM23
bool
diff --git a/arch/arm/src/armv8-m/Make.defs b/arch/arm/src/armv8-m/Make.defs
index 72222e7adf..c3e05ffc11 100644
--- a/arch/arm/src/armv8-m/Make.defs
+++ b/arch/arm/src/armv8-m/Make.defs
@@ -24,7 +24,7 @@ include common/Make.defs
CMN_ASRCS += arm_exception.S arm_saveusercontext.S
-CMN_CSRCS += arm_busfault.c arm_cache.c arm_doirq.c
+CMN_CSRCS += arm_busfault.c arm_cache.c arm_cpuinfo.c arm_doirq.c
CMN_CSRCS += arm_hardfault.c arm_initialstate.c arm_itm.c
CMN_CSRCS += arm_memfault.c arm_perf.c arm_sau.c
CMN_CSRCS += arm_schedulesigaction.c arm_securefault.c arm_secure_irq.c
diff --git a/arch/arm/src/armv8-m/arm_cpuinfo.c b/arch/arm/src/armv8-m/arm_cpuinfo.c
new file mode 100644
index 0000000000..0022f5259d
--- /dev/null
+++ b/arch/arm/src/armv8-m/arm_cpuinfo.c
@@ -0,0 +1,144 @@
+/****************************************************************************
+ * arch/arm/src/armv8-m/arm_cpuinfo.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/procfs.h>
+#include <nuttx/arch.h>
+
+#include "arm_internal.h"
+#include "hwcap.h"
+#include "nvic.h"
+
+#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_CPUINFO)
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * name: hwcap_extract_field
+ ****************************************************************************/
+
+#if defined(CONFIG_ARCH_FPU)
+static int hwcap_extract_field(uint32_t features, int field)
+{
+ int feature;
+
+ feature = (features >> field) & 0xf;
+ if (feature > 7)
+ {
+ feature -= 16;
+ }
+
+ return feature;
+}
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * name: up_show_cpuinfo
+ ****************************************************************************/
+
+ssize_t up_show_cpuinfo(FAR char *buf, size_t buf_size, off_t file_off)
+{
+ int i;
+ uint32_t cpuid;
+
+ for (i = 0; i < CONFIG_SMP_NCPUS; i++)
+ {
+ procfs_sprintf(buf, buf_size, &file_off, "processor\t: %d\n", i);
+ procfs_sprintf(buf, buf_size, &file_off, "BogoMIPS\t: %u.%02u\n",
+ (CONFIG_BOARD_LOOPSPERMSEC / 1000),
+ (CONFIG_BOARD_LOOPSPERMSEC / 10) % 100);
+ procfs_sprintf(buf, buf_size, &file_off, "cpu MHz\t\t: %lu.%02lu\n",
+ up_perf_getfreq() / 1000000,
+ (up_perf_getfreq() / 10000) % 100);
+
+ /* Cpu features */
+
+ procfs_sprintf(buf, buf_size, &file_off, "Features\t:");
+ procfs_sprintf(buf, buf_size, &file_off, " %s %s %s",
+ HWCAP_HALF, HWCAP_FAST_MULT, HWCAP_LPAE);
+
+#ifdef CONFIG_ARM_THUMB
+ procfs_sprintf(buf, buf_size, &file_off, " %s %s",
+ HWCAP_IDIVT, HWCAP_THUMB);
+#else
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_IDIVA);
+#endif
+
+#ifdef CONFIG_ARM_DSP
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_EDSP);
+#endif
+
+#ifdef CONFIG_SCHED_THREAD_LOCAL
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_TLS);
+#endif
+
+ /* VFP features */
+
+#if defined(CONFIG_ARCH_FPU)
+# if defined(CONFIG_ARCH_CORTEXM33) || defined(CONFIG_ARCH_CORTEXM35P)
+ procfs_sprintf(buf, buf_size, &file_off, " %s %s %s",
+ HWCAP_FPV5, HWCAP_FPSP, HWCAP_VFPV3D16);
+# elif defined(CONFIG_ARCH_CORTEXM55) || defined(CONFIG_ARCH_CORTEXM85)
+ procfs_sprintf(buf, buf_size, &file_off, " %s %s %s %s",
+ HWCAP_FPV5, HWCAP_FPSP, HWCAP_FPDP, HWCAP_VFPV3D16);
+# endif
+
+# if defined(CONFIG_ARM_HAVE_MVE)
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_MVE);
+# endif
+
+ if (hwcap_extract_field(getreg32(NVIC_MVFR1), 20) == 1)
+ {
+ procfs_sprintf(buf, buf_size, &file_off, " %s", HWCAP_FPHP);
+ }
+#endif
+
+ /* Cpuid info */
+
+ cpuid = getreg32(NVIC_CPUID_BASE);
+ procfs_sprintf(buf, buf_size, &file_off,
+ "\nmodel name\t: %s rev %" PRIx32 " (%s)\n"
+ "CPU architecture: %s\n",
+ "ARMv8-M", cpuid & 15, "v8ml", "8M");
+
+ procfs_sprintf(buf, buf_size, &file_off,
+ "CPU implementer\t: 0x%02" PRIx32 "\n"
+ "CPU variant\t: 0x%" PRIx32 "\n"
+ "CPU part\t: 0x%03" PRIx32 "\n"
+ "CPU revision\t: %" PRIu32"\n\n",
+ cpuid >> 24,
+ (cpuid >> 20) & 0xf,
+ (cpuid >> 4) & 0xfff,
+ cpuid & 0xf);
+ }
+
+ return -file_off;
+}
+#endif /* CONFIG_FS_PROCFS && !CONFIG_FS_PROCFS_EXCLUDE_CPUINFO */
diff --git a/arch/arm/src/common/hwcap.h b/arch/arm/src/common/hwcap.h
index eba334ae1e..14a085df72 100644
--- a/arch/arm/src/common/hwcap.h
+++ b/arch/arm/src/common/hwcap.h
@@ -57,6 +57,7 @@
#define HWCAP_FPSP "fpsp" /* Single-precision instructions support */
#define HWCAP_FPDP "fpdp" /* Double-precision instructions support */
#define HWCAP_FPV5 "fpv5" /* Floating-point extension version */
+#define HWCAP_MVE "mve" /* M-profile vector extension */
/* Hardware capabilities added form armv8 */
[nuttx] 07/07: procfs:add xtensa cpuinfo
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 6424b5322f719a9ace418c87934f8c79067f21e6
Author: liaoao <li...@xiaomi.com>
AuthorDate: Wed Apr 26 21:33:36 2023 +0800
procfs:add xtensa cpuinfo
Signed-off-by: liaoao <li...@xiaomi.com>
---
arch/Kconfig | 1 +
arch/xtensa/src/common/Make.defs | 17 +--
arch/xtensa/src/common/xtensa_cpuinfo.c | 232 ++++++++++++++++++++++++++++++++
3 files changed, 242 insertions(+), 8 deletions(-)
diff --git a/arch/Kconfig b/arch/Kconfig
index f610488d2f..80acae798d 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -128,6 +128,7 @@ config ARCH_X86_64
config ARCH_XTENSA
bool "Xtensa"
select ARCH_HAVE_BACKTRACE
+ select ARCH_HAVE_CPUINFO
select ARCH_HAVE_INTERRUPTSTACK
select ARCH_HAVE_STACKCHECK
select ARCH_HAVE_CUSTOMOPT
diff --git a/arch/xtensa/src/common/Make.defs b/arch/xtensa/src/common/Make.defs
index 95644a9991..b02be8544a 100644
--- a/arch/xtensa/src/common/Make.defs
+++ b/arch/xtensa/src/common/Make.defs
@@ -27,14 +27,15 @@ HEAD_ASRC += xtensa_int_handlers.S xtensa_user_handler.S
CMN_ASRCS = xtensa_context.S xtensa_cpuint.S xtensa_panic.S
-CMN_CSRCS = xtensa_assert.c xtensa_cpenable.c xtensa_createstack.c
-CMN_CSRCS += xtensa_exit.c xtensa_getintstack.c xtensa_initialize.c
-CMN_CSRCS += xtensa_initialstate.c xtensa_irqdispatch.c xtensa_lowputs.c
-CMN_CSRCS += xtensa_modifyreg8.c xtensa_modifyreg16.c xtensa_modifyreg32.c
-CMN_CSRCS += xtensa_mdelay.c xtensa_nputs.c xtensa_releasestack.c
-CMN_CSRCS += xtensa_registerdump.c xtensa_sigdeliver.c xtensa_switchcontext.c
-CMN_CSRCS += xtensa_swint.c xtensa_stackframe.c xtensa_saveusercontext.c
-CMN_CSRCS += xtensa_schedsigaction.c xtensa_udelay.c xtensa_usestack.c
+CMN_CSRCS = xtensa_assert.c xtensa_cpenable.c xtensa_cpuinfo.c
+CMN_CSRCS += xtensa_createstack.c xtensa_exit.c xtensa_getintstack.c
+CMN_CSRCS += xtensa_initialize.c xtensa_initialstate.c xtensa_irqdispatch.c
+CMN_CSRCS += xtensa_lowputs.c xtensa_modifyreg8.c xtensa_modifyreg16.c
+CMN_CSRCS += xtensa_modifyreg32.c xtensa_mdelay.c xtensa_nputs.c xtensa_perf.c
+CMN_CSRCS += xtensa_releasestack.c xtensa_registerdump.c xtensa_sigdeliver.c
+CMN_CSRCS += xtensa_switchcontext.c xtensa_swint.c xtensa_stackframe.c
+CMN_CSRCS += xtensa_saveusercontext.c xtensa_schedsigaction.c xtensa_udelay.c
+CMN_CSRCS += xtensa_usestack.c
# Configuration-dependent common Xtensa files
diff --git a/arch/xtensa/src/common/xtensa_cpuinfo.c b/arch/xtensa/src/common/xtensa_cpuinfo.c
new file mode 100644
index 0000000000..147f0d32c0
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_cpuinfo.c
@@ -0,0 +1,232 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_cpuinfo.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/arch.h>
+#include <nuttx/config.h>
+#include <nuttx/fs/procfs.h>
+
+#include <arch/xtensa/xtensa_specregs.h>
+#include <sys/types.h>
+
+#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_CPUINFO)
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: xtensa_getconfig0
+ *
+ * Description:
+ * Get the value of the CONFIGID0 register.
+ *
+ ****************************************************************************/
+
+static inline uint32_t xtensa_getconfig0(void)
+{
+ uint32_t reg;
+
+ __asm__ __volatile__
+ (
+ "rsr %0, CONFIGID0" : "=r"(reg)
+ );
+
+ return reg;
+}
+
+/****************************************************************************
+ * Name: xtensa_getconfig1
+ *
+ * Description:
+ * Get the value of the CONFIGID1 register.
+ *
+ ****************************************************************************/
+
+static inline uint32_t xtensa_getconfig1(void)
+{
+ uint32_t reg;
+
+ __asm__ __volatile__
+ (
+ "rsr %0, CONFIGID1" : "=r"(reg)
+ );
+
+ return reg;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * name: up_show_cpuinfo
+ ****************************************************************************/
+
+ssize_t up_show_cpuinfo(FAR char *buf, size_t buf_size, off_t file_off)
+{
+ procfs_sprintf(buf, buf_size, &file_off,
+ "CPU count\t: %u\n"
+ "vendor_id\t: Tensilica\n"
+ "model\t\t: Xtensa " XCHAL_HW_VERSION_NAME "\n",
+ CONFIG_SMP_NCPUS);
+
+ procfs_sprintf(buf, buf_size, &file_off,
+ "core ID\t\t: " XCHAL_CORE_ID "\n"
+ "build ID\t: 0x%x\n"
+ "config ID\t: %08" PRIx32 ":%08" PRIx32 "\n",
+ XCHAL_BUILD_UNIQUE_ID,
+ xtensa_getconfig0(), xtensa_getconfig1());
+
+ procfs_sprintf(buf, buf_size, &file_off,
+ "byte order\t: %s\n"
+ "cpu MHz\t\t: %lu.%02lu\n"
+ "bogomips\t: %u.%02u\n",
+ XCHAL_HAVE_BE ? "big" : "little",
+ up_perf_getfreq() / 1000000,
+ (up_perf_getfreq() / 10000) % 100,
+ (CONFIG_BOARD_LOOPSPERMSEC / 1000),
+ (CONFIG_BOARD_LOOPSPERMSEC / 10) % 100);
+
+ /* Features */
+
+ procfs_sprintf(buf, buf_size, &file_off, "flags\t\t: "
+#if XCHAL_HAVE_NMI
+ "nmi "
+#endif
+#if XCHAL_HAVE_DEBUG
+ "debug "
+# if XCHAL_HAVE_OCD
+ "ocd "
+# endif
+#endif
+#if XCHAL_HAVE_DENSITY
+ "density "
+#endif
+#if XCHAL_HAVE_BOOLEANS
+ "boolean "
+#endif
+#if XCHAL_HAVE_LOOPS
+ "loop "
+#endif
+#if XCHAL_HAVE_NSA
+ "nsa "
+#endif
+#if XCHAL_HAVE_MINMAX
+ "minmax "
+#endif
+#if XCHAL_HAVE_SEXT
+ "sext "
+#endif
+#if XCHAL_HAVE_CLAMPS
+ "clamps "
+#endif
+#if XCHAL_HAVE_MAC16
+ "mac16 "
+#endif
+#if XCHAL_HAVE_MUL16
+ "mul16 "
+#endif
+#if XCHAL_HAVE_MUL32
+ "mul32 "
+#endif
+#if XCHAL_HAVE_MUL32_HIGH
+ "mul32h "
+#endif
+#if XCHAL_HAVE_FP
+ "fpu "
+#endif
+#if XCHAL_HAVE_S32C1I
+ "s32c1i "
+#endif
+#ifdef XCHAL_HAVE_EXCLUSIVE
+# if XCHAL_HAVE_EXCLUSIVE
+ "exclusive "
+# endif
+#endif
+ "\n");
+
+ /* Registers */
+
+ procfs_sprintf(buf, buf_size, &file_off,
+ "physical aregs\t: %d\n"
+ "misc regs\t: %d\n"
+ "ibreak\t\t: %d\n"
+ "dbreak\t\t: %d\n",
+ XCHAL_NUM_AREGS,
+ XCHAL_NUM_MISC_REGS,
+ XCHAL_NUM_IBREAK,
+ XCHAL_NUM_DBREAK);
+
+ /* Interrupt */
+
+ procfs_sprintf(buf, buf_size, &file_off,
+ "num ints\t: %d\n"
+ "ext ints\t: %d\n"
+ "int levels\t: %d\n"
+ "timers\t\t: %d\n"
+ "debug level\t: %d\n",
+ XCHAL_NUM_INTERRUPTS,
+ XCHAL_NUM_EXTINTERRUPTS,
+ XCHAL_NUM_INTLEVELS,
+ XCHAL_NUM_TIMERS,
+ XCHAL_DEBUGLEVEL);
+
+ /* Cache */
+
+#ifdef CONFIG_XTENSA_ICACHE
+ procfs_sprintf(buf, buf_size, &file_off,
+ "icache line size: %d\n"
+ "icache ways\t: %d\n"
+ "icache size\t: %d\n"
+ "icache flags\t: "
+#if XCHAL_ICACHE_LINE_LOCKABLE
+ "lock "
+#endif
+ "\n",
+ XCHAL_ICACHE_LINESIZE,
+ XCHAL_ICACHE_WAYS,
+ XCHAL_ICACHE_SIZE);
+#endif
+
+#ifdef CONFIG_XTENSA_DCACHE
+ procfs_sprintf(buf, buf_size, &file_off,
+ "dcache line size: %d\n"
+ "dcache ways\t: %d\n"
+ "dcache size\t: %d\n"
+ "dcache flags\t: "
+#if XCHAL_DCACHE_IS_WRITEBACK
+ "writeback "
+#endif
+#if XCHAL_DCACHE_LINE_LOCKABLE
+ "lock "
+#endif
+ "\n",
+ XCHAL_DCACHE_LINESIZE,
+ XCHAL_DCACHE_WAYS,
+ XCHAL_DCACHE_SIZE);
+#endif
+
+ return -file_off;
+}
+#endif /* CONFIG_FS_PROCFS && !CONFIG_FS_PROCFS_EXCLUDE_CPUINFO */
[nuttx] 01/07: procfs:add /proc/cpuinfo
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 6ea3eb3ce2949f0afd9cb28716d07acd5abbdc52
Author: liaoao <li...@xiaomi.com>
AuthorDate: Wed Mar 15 20:48:40 2023 +0800
procfs:add /proc/cpuinfo
Signed-off-by: liaoao <li...@xiaomi.com>
---
arch/Kconfig | 4 +
fs/procfs/Kconfig | 5 +
fs/procfs/Make.defs | 8 +-
fs/procfs/fs_procfs.c | 5 +
fs/procfs/fs_procfscpuinfo.c | 218 +++++++++++++++++++++++++++++++++++++++++++
fs/procfs/fs_procfsutil.c | 72 ++++++++++++++
include/nuttx/arch.h | 19 ++++
include/nuttx/fs/procfs.h | 21 +++++
8 files changed, 348 insertions(+), 4 deletions(-)
diff --git a/arch/Kconfig b/arch/Kconfig
index 572b613e57..b7f4ca5a2c 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -468,6 +468,10 @@ config ARCH_HAVE_BOOTLOADER
bool
default n
+config ARCH_HAVE_CPUINFO
+ bool
+ default n
+
config ARCH_FPU
bool "FPU support"
default y
diff --git a/fs/procfs/Kconfig b/fs/procfs/Kconfig
index a99acbf9e1..a07bc5ce44 100644
--- a/fs/procfs/Kconfig
+++ b/fs/procfs/Kconfig
@@ -38,6 +38,11 @@ config FS_PROCFS_EXCLUDE_BLOCKS
system. This procfs file provides the text output for the NSH 'df'
command.
+config FS_PROCFS_EXCLUDE_CPUINFO
+ bool "Exclude cpuinfo procfs"
+ depends on ARCH_HAVE_CPUINFO
+ default DEFAULT_SMALL
+
config FS_PROCFS_EXCLUDE_CPULOAD
bool "Exclude CPU load"
depends on SCHED_CPULOAD
diff --git a/fs/procfs/Make.defs b/fs/procfs/Make.defs
index eb30d4ed94..57dbf97d06 100644
--- a/fs/procfs/Make.defs
+++ b/fs/procfs/Make.defs
@@ -21,10 +21,10 @@
ifeq ($(CONFIG_FS_PROCFS),y)
# Files required for procfs file system support
-CSRCS += fs_procfs.c fs_procfscpuload.c fs_procfscritmon.c
-CSRCS += fs_procfsiobinfo.c fs_procfsmeminfo.c fs_procfsproc.c
-CSRCS += fs_procfstcbinfo.c fs_procfsuptime.c fs_procfsutil.c
-CSRCS += fs_procfsversion.c
+CSRCS += fs_procfs.c fs_procfscpuinfo.c fs_procfscpuload.c
+CSRCS += fs_procfscritmon.c fs_procfsiobinfo.c fs_procfsmeminfo.c
+CSRCS += fs_procfsproc.c fs_procfstcbinfo.c fs_procfsuptime.c
+CSRCS += fs_procfsutil.c fs_procfsversion.c
# Include procfs build support
diff --git a/fs/procfs/fs_procfs.c b/fs/procfs/fs_procfs.c
index be3461472e..5065108904 100644
--- a/fs/procfs/fs_procfs.c
+++ b/fs/procfs/fs_procfs.c
@@ -52,6 +52,7 @@
* External Definitions
****************************************************************************/
+extern const struct procfs_operations g_cpuinfo_operations;
extern const struct procfs_operations g_cpuload_operations;
extern const struct procfs_operations g_critmon_operations;
extern const struct procfs_operations g_iobinfo_operations;
@@ -95,6 +96,10 @@ static const struct procfs_entry_s g_procfs_entries[] =
{ "[0-9]*", &g_proc_operations, PROCFS_DIR_TYPE },
#endif
+#if defined(CONFIG_ARCH_HAVE_CPUINFO) && !defined(CONFIG_FS_PROCFS_EXCLUDE_CPUINFO)
+ { "cpuinfo", &g_cpuinfo_operations, PROCFS_FILE_TYPE },
+#endif
+
#if defined(CONFIG_SCHED_CPULOAD) && !defined(CONFIG_FS_PROCFS_EXCLUDE_CPULOAD)
{ "cpuload", &g_cpuload_operations, PROCFS_FILE_TYPE },
#endif
diff --git a/fs/procfs/fs_procfscpuinfo.c b/fs/procfs/fs_procfscpuinfo.c
new file mode 100644
index 0000000000..bf31d20210
--- /dev/null
+++ b/fs/procfs/fs_procfscpuinfo.c
@@ -0,0 +1,218 @@
+/****************************************************************************
+ * fs/procfs/fs_procfscpuinfo.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/fs/procfs.h>
+
+#if defined(CONFIG_ARCH_HAVE_CPUINFO) && !defined(CONFIG_FS_PROCFS_EXCLUDE_CPUINFO)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* This structure describes one open "file" */
+
+struct cpuinfo_file_s
+{
+ struct procfs_file_s base; /* Base open file structure */
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* File system methods */
+
+static int cpuinfo_open(FAR struct file *filep, FAR const char *relpath,
+ int oflags, mode_t mode);
+static int cpuinfo_close(FAR struct file *filep);
+static ssize_t cpuinfo_read(FAR struct file *filep, FAR char *buffer,
+ size_t buflen);
+static int cpuinfo_dup(FAR const struct file *oldp,
+ FAR struct file *newp);
+static int cpuinfo_stat(FAR const char *relpath, FAR struct stat *buf);
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/* See fs_mount.c -- this structure is explicitly externed there.
+ * We use the old-fashioned kind of initializers so that this will compile
+ * with any compiler.
+ */
+
+const struct procfs_operations g_cpuinfo_operations =
+{
+ cpuinfo_open, /* open */
+ cpuinfo_close, /* close */
+ cpuinfo_read, /* read */
+ NULL, /* write */
+ cpuinfo_dup, /* dup */
+ NULL, /* opendir */
+ NULL, /* closedir */
+ NULL, /* readdir */
+ NULL, /* rewinddir */
+ cpuinfo_stat /* stat */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: cpuinfo_open
+ ****************************************************************************/
+
+static int cpuinfo_open(FAR struct file *filep, FAR const char *relpath,
+ int oflags, mode_t mode)
+{
+ FAR struct cpuinfo_file_s *procfile;
+
+ finfo("Open '%s'\n", relpath);
+
+ /* Allocate a container to hold the file attributes */
+
+ procfile = kmm_zalloc(sizeof(struct cpuinfo_file_s));
+ if (procfile == NULL)
+ {
+ ferr("ERROR: Failed to allocate file attributes\n");
+ return -ENOMEM;
+ }
+
+ /* Save the attributes as the open-specific state in filep->f_priv */
+
+ filep->f_priv = procfile;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: cpuinfo_close
+ ****************************************************************************/
+
+static int cpuinfo_close(FAR struct file *filep)
+{
+ FAR struct cpuinfo_file_s *procfile;
+
+ /* Recover our private data from the struct file instance */
+
+ procfile = filep->f_priv;
+ DEBUGASSERT(procfile);
+
+ /* Release the file attributes structure */
+
+ kmm_free(procfile);
+ filep->f_priv = NULL;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: cpuinfo_read
+ ****************************************************************************/
+
+static ssize_t cpuinfo_read(FAR struct file *filep, FAR char *buffer,
+ size_t buflen)
+{
+ ssize_t copylen;
+ off_t offset;
+
+ finfo("buffer=%p buflen=%zu\n", buffer, buflen);
+
+ DEBUGASSERT(filep != NULL && buffer != NULL && buflen > 0);
+ offset = filep->f_pos;
+
+ copylen = up_show_cpuinfo(buffer, buflen, offset);
+ if (copylen > 0)
+ {
+ filep->f_pos += copylen;
+ }
+
+ return copylen;
+}
+
+/****************************************************************************
+ * Name: cpuinfo_dup
+ *
+ * Description:
+ * Duplicate open file data in the new file structure.
+ *
+ ****************************************************************************/
+
+static int cpuinfo_dup(FAR const struct file *oldp, FAR struct file *newp)
+{
+ FAR struct cpuinfo_file_s *oldattr;
+ FAR struct cpuinfo_file_s *newattr;
+
+ finfo("Dup %p->%p\n", oldp, newp);
+
+ /* Recover our private data from the old struct file instance */
+
+ oldattr = oldp->f_priv;
+ DEBUGASSERT(oldattr);
+
+ /* Allocate a new container to hold the task and attribute selection */
+
+ newattr = kmm_malloc(sizeof(struct cpuinfo_file_s));
+ if (newattr == NULL)
+ {
+ ferr("ERROR: Failed to allocate file attributes\n");
+ return -ENOMEM;
+ }
+
+ /* The copy the file attributes from the old attributes to the new */
+
+ memcpy(newattr, oldattr, sizeof(struct cpuinfo_file_s));
+
+ /* Save the new attributes in the new file structure */
+
+ newp->f_priv = newattr;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: cpuinfo_stat
+ *
+ * Description: Return information about a file or directory
+ *
+ ****************************************************************************/
+
+static int cpuinfo_stat(FAR const char *relpath, FAR struct stat *buf)
+{
+ /* "cpuinfo" is the name for a read-only file */
+
+ memset(buf, 0, sizeof(struct stat));
+ buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR;
+ return OK;
+}
+#endif /* !CONFIG_FS_PROCFS_EXCLUDE_CPUINFO */
diff --git a/fs/procfs/fs_procfsutil.c b/fs/procfs/fs_procfsutil.c
index f093f74f99..1b3415849a 100644
--- a/fs/procfs/fs_procfsutil.c
+++ b/fs/procfs/fs_procfsutil.c
@@ -33,6 +33,16 @@
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS)
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Determines the size of an intermediate buffer in procfs_sprintf that must
+ * be large enough to handle the longest line generated by this logic.
+ */
+
+#define LINEBUF_SIZE 128
+
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -138,4 +148,66 @@ int procfs_snprintf(FAR char *buf, size_t size,
return n < size - 1 ? n : size - 1;
}
+/****************************************************************************
+ * Name: procfs_sprintf
+ *
+ * Description:
+ * This function used to continous format string and copy it to buffer.
+ * Every single string length must be smaller then LINEBUF_SIZE.
+ *
+ * Input Parameters:
+ * buf - The address of the user's receive buffer.
+ * size - The size (in bytes) of the user's receive buffer.
+ * offset - On input, when *offset is larger the 0 , this is the
+ * number of bytes to skip before returning data; If bytes
+ * were skipped, this *offset will be decremented. when it
+ * decrements to a negative value, -*offset is the number of
+ * data copied to buffer.
+ *
+ ****************************************************************************/
+
+void procfs_sprintf(FAR char *buf, size_t size, FAR off_t *offset,
+ FAR const IPTR char *format, ...)
+{
+ char linebuf[LINEBUF_SIZE];
+ size_t linesize;
+ size_t copysize;
+ va_list ap;
+
+ va_start(ap, format);
+ linesize = vsnprintf(linebuf, LINEBUF_SIZE, format, ap);
+ va_end(ap);
+
+ linesize = MIN(linesize, LINEBUF_SIZE - 1);
+
+ if (*offset > 0)
+ {
+ if (linesize < *offset)
+ {
+ *offset -= linesize;
+ return;
+ }
+ else
+ {
+ copysize = MIN(linesize - *offset, size);
+ memcpy(buf, linebuf + *offset, copysize);
+ *offset = 0;
+ }
+ }
+ else
+ {
+ if (size + *offset > 0)
+ {
+ copysize = MIN(linesize, size + *offset);
+ memcpy(buf - *offset, linebuf, copysize);
+ }
+ else
+ {
+ copysize = 0;
+ }
+ }
+
+ *offset -= copysize;
+}
+
#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS */
diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h
index 52f5805191..462161c10b 100644
--- a/include/nuttx/arch.h
+++ b/include/nuttx/arch.h
@@ -2560,6 +2560,25 @@ unsigned long up_perf_gettime(void);
unsigned long up_perf_getfreq(void);
void up_perf_convert(unsigned long elapsed, FAR struct timespec *ts);
+/****************************************************************************
+ * Name: up_show_cpuinfo
+ *
+ * Description:
+ * This function will be called when reading /proc/cpufinfo.
+ * This function should be implemented by each arch to show its cpuinfo.
+ *
+ * Input Parameters:
+ * buf - The address of the user's receive buffer.
+ * buf_size - The size (in bytes) of the user's receive buffer.
+ * file_off - The /proc/cpuinfo file offset.
+ *
+ * Returned Value:
+ * The number of bytes actually transferred into the user's receive buffer.
+ *
+ ****************************************************************************/
+
+ssize_t up_show_cpuinfo(FAR char *buf, size_t buf_size, off_t file_off);
+
/****************************************************************************
* Name: up_saveusercontext
*
diff --git a/include/nuttx/fs/procfs.h b/include/nuttx/fs/procfs.h
index 5ff76262bf..04a64d69e9 100644
--- a/include/nuttx/fs/procfs.h
+++ b/include/nuttx/fs/procfs.h
@@ -222,6 +222,27 @@ size_t procfs_memcpy(FAR const char *src, size_t srclen,
int procfs_snprintf(FAR char *buf, size_t size,
FAR const IPTR char *format, ...) printf_like(3, 4);
+/****************************************************************************
+ * Name: procfs_sprintf
+ *
+ * Description:
+ * This function used to continous format string and copy it to buffer.
+ * Every single string length must be smaller then LINEBUF_SIZE.
+ *
+ * Input Parameters:
+ * buf - The address of the user's receive buffer.
+ * size - The size (in bytes) of the user's receive buffer.
+ * offset - On input, when *offset is larger the 0 , this is the
+ * number of bytes to skip before returning data; If bytes
+ * were skipped, this *offset will be decremented. when it
+ * decrements to a negative value, -*offset is the number of
+ * data copied to buffer.
+ *
+ ****************************************************************************/
+
+void procfs_sprintf(FAR char *buf, size_t size, FAR off_t *offset,
+ FAR const IPTR char *format, ...);
+
/****************************************************************************
* Name: procfs_register
*