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 <[email protected]>
AuthorDate: Tue May 16 15:41:49 2023 +0800

    procfs:add risc-v cpuinfo
    
    Signed-off-by: liaoao <[email protected]>
---
 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 */

Reply via email to