risc-v/k230: add big core support
Previously NuttX runs on little core of K230, this patch allows NuttX to run on the big core as well. Within folder `arch/risc-v/src/k230`: - Changes: - CMakeLists.txt add k230_hart.c to sources list - Make.defs add k230_hart.c to sources list - chip.h add inclusion to k230_hart.h etc - k230_irq.c move sbi_late_init() to k230_hart.c - k230_start.c add support to run on big core - hardware/: - k230_memorymap.h add T-Head C908 specific CSR - Additions: - k230_hart.c sbi_late_init w/ hart initialization - k230_hart.h header file Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
This commit is contained in:
parent
9d761b8ca4
commit
0f169f50c4
@ -26,6 +26,7 @@ list(
|
||||
k230_start.c
|
||||
k230_irq_dispatch.c
|
||||
k230_irq.c
|
||||
k230_hart.c
|
||||
k230_timerisr.c
|
||||
k230_allocateheap.c)
|
||||
|
||||
|
@ -24,7 +24,7 @@ CHIP_ASRCS += k230_head.S
|
||||
|
||||
# Specify our C code within this directory to be included
|
||||
CHIP_CSRCS = k230_start.c k230_irq_dispatch.c k230_irq.c
|
||||
CHIP_CSRCS += k230_timerisr.c k230_allocateheap.c
|
||||
CHIP_CSRCS += k230_timerisr.c k230_allocateheap.c k230_hart.c
|
||||
|
||||
ifeq ($(CONFIG_BUILD_KERNEL),y)
|
||||
CHIP_CSRCS += k230_mm_init.c
|
||||
|
@ -30,9 +30,11 @@
|
||||
#include <arch/k230/chip.h>
|
||||
|
||||
#include "k230_memorymap.h"
|
||||
#include "k230_hart.h"
|
||||
|
||||
#include "hardware/k230_memorymap.h"
|
||||
#include "hardware/k230_plic.h"
|
||||
#include "hardware/k230_clint.h"
|
||||
|
||||
#include "riscv_internal.h"
|
||||
#include "riscv_percpu.h"
|
||||
|
@ -25,9 +25,21 @@
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Register Base Address ****************************************************/
|
||||
/* PLIC/CLINT Base Address **************************************************/
|
||||
|
||||
#define K230_PLIC_BASE 0xF00000000
|
||||
#define K230_CLINT_BASE (K230_PLIC_BASE + 0x04000000)
|
||||
|
||||
/* T-Head c908 specific CSR */
|
||||
|
||||
#define CSR_MCOR 0x7c2
|
||||
#define CSR_MHCR 0x7c1
|
||||
#define CSR_MCCR2 0x7c3
|
||||
#define CSR_MHINT 0x7c5
|
||||
#define CSR_MXSTATUS 0x7c0
|
||||
#define CSR_MRMR 0x7c6
|
||||
#define CSR_MRVBR 0x7c7
|
||||
#define CSR_MSMPR 0x7f3
|
||||
#define CSR_PLIC_BASE 0xfc1
|
||||
|
||||
#endif /* __ARCH_RISCV_SRC_K230_HARDWARE_K230_MEMORYMAP_H */
|
||||
|
91
arch/risc-v/src/k230/k230_hart.c
Normal file
91
arch/risc-v/src/k230/k230_hart.c
Normal file
@ -0,0 +1,91 @@
|
||||
/****************************************************************************
|
||||
* arch/risc-v/src/k230/k230_hart.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 <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
#include "riscv_internal.h"
|
||||
#include "chip.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#if !defined(CONFIG_BUILD_KERNEL) || defined(CONFIG_NUTTSBI)
|
||||
|
||||
/****************************************************************************
|
||||
* Name: hart_has_vec_ext()
|
||||
* Description: returns Non-zero if CPU has vector extension
|
||||
****************************************************************************/
|
||||
|
||||
int hart_has_vec_ext(void)
|
||||
{
|
||||
#define MISA_VECTOR_BIT ('V'-'A')
|
||||
#define MISA_VECOTR_MASK ( 1 << MISA_VECTOR_BIT )
|
||||
|
||||
return (READ_CSR(CSR_MISA) & MISA_VECOTR_MASK);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: k230_hart_init()
|
||||
* Description: K230 M-mode HART initialization
|
||||
****************************************************************************/
|
||||
|
||||
void k230_hart_init(void)
|
||||
{
|
||||
if (hart_has_vec_ext())
|
||||
{
|
||||
WRITE_CSR(CSR_MHCR, 0x11ff);
|
||||
WRITE_CSR(CSR_MCOR, 0x70013);
|
||||
WRITE_CSR(CSR_MSMPR, 0x1);
|
||||
WRITE_CSR(CSR_MCCR2, 0xe0410009);
|
||||
WRITE_CSR(CSR_MHINT, 0x16e30c);
|
||||
}
|
||||
|
||||
/* turn off MAEE to have standard PTE format */
|
||||
|
||||
WRITE_CSR(CSR_MXSTATUS, 0x438000);
|
||||
}
|
||||
#endif /* !defined(CONFIG_BUILD_KERNEL) || defined(CONFIG_NUTTSBI) */
|
||||
|
||||
#ifdef CONFIG_NUTTSBI
|
||||
/****************************************************************************
|
||||
* Name: sbi_late_initialize runs in M-mode
|
||||
****************************************************************************/
|
||||
|
||||
void sbi_late_initialize(void)
|
||||
{
|
||||
/* delegate K230 plic enable to S-mode */
|
||||
|
||||
*((volatile uint32_t *)K230_PLIC_CTRL) = 1;
|
||||
k230_hart_init();
|
||||
}
|
||||
#endif
|
40
arch/risc-v/src/k230/k230_hart.h
Normal file
40
arch/risc-v/src/k230/k230_hart.h
Normal file
@ -0,0 +1,40 @@
|
||||
/****************************************************************************
|
||||
* arch/risc-v/src/k230/k230_hart.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_RISCV_SRC_K230_K230_HART_H
|
||||
#define __ARCH_RISCV_SRC_K230_K230_HART_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
#if !defined(CONFIG_BUILD_KERNEL) || defined(CONFIG_NUTTSBI)
|
||||
|
||||
int hart_has_vec_ext(void); /* checks for vector extension */
|
||||
void k230_hart_init(void); /* M-mode initialization */
|
||||
|
||||
#endif /* !defined(CONFIG_BUILD_KERNEL) || defined(CONFIG_NUTTSBI) */
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __ARCH_RISCV_SRC_K230_K230_HART_H */
|
@ -41,19 +41,6 @@
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NUTTSBI
|
||||
/****************************************************************************
|
||||
* Name: sbi_late_initialize runs in M-mode
|
||||
****************************************************************************/
|
||||
|
||||
void sbi_late_initialize(void)
|
||||
{
|
||||
/* delegate K230 plic enable to S-mode */
|
||||
|
||||
*((volatile uint32_t *)K230_PLIC_CTRL) = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_irqinitialize
|
||||
****************************************************************************/
|
||||
|
@ -129,6 +129,10 @@ void k230_start(int mhartid, const char *dtb)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef CONFIG_BUILD_KERNEL
|
||||
k230_hart_init();
|
||||
#endif
|
||||
|
||||
/* Disable MMU */
|
||||
|
||||
WRITE_CSR(satp, 0x0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user