procfs:add risc-v cpuinfo

Signed-off-by: liaoao <liaoao@xiaomi.com>
This commit is contained in:
liaoao 2023-05-16 15:41:49 +08:00 committed by Xiang Xiao
parent 1abe90c7cd
commit 8a5bf87c72
3 changed files with 84 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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 */