Skip to content

Commit eefc3f6

Browse files
committed
c908x: Add fastmem setting support
Xuantie C908X supports fast memory configuration vector and scalar memory access instructions to access external SRAM. Configure the starting address and size through CSR_MFASTMBA. For specific settings, please refer to the datasheet. Dynamic configuration is achieved by parsing dts through opensbi. The dts reference configuration is as follows: ``` / { compatible = "xuantie,c908x"; model = "xuantie,c908x"; fastmem { mfastmba = <0x12 0x34567890>; }; }; ``` Signed-off-by: hanyu.cp <[email protected]>
1 parent 9294bed commit eefc3f6

File tree

8 files changed

+78
-0
lines changed

8 files changed

+78
-0
lines changed

docs/platform/thead-c9xx.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,17 @@ Here is the simplest boot flow for a fpga prototype:
2525

2626
For more details, refer:
2727
[zero stage boot](https://github.com/c-sky/zero_stage_boot)
28+
29+
DTS Example: (fastmem)
30+
-----------------------------
31+
32+
```
33+
/ {
34+
compatible = "xuantie,c908x";
35+
model = "xuantie,c908x";
36+
37+
fastmem {
38+
mfastmba = <0x12 0x34567890>;
39+
};
40+
};
41+
```

platform/generic/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ config PLATFORM_STARFIVE_JH7110
6262
config PLATFORM_THEAD
6363
bool "THEAD C9xx support"
6464
select THEAD_C9XX_ERRATA
65+
select THEAD_C9XX_EXTFUNC
6566
select THEAD_C9XX_PMU
6667
default n
6768

platform/generic/include/thead/c9xx_encoding.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#define THEAD_C9XX_CSR_MEXSTATUS 0x7e1
2121
#define THEAD_C9XX_CSR_MNMICAUSE 0x7e2
2222
#define THEAD_C9XX_CSR_MNMIPC 0x7e3
23+
#define THEAD_C9XX_CSR_MFASTMBA 0x7eb
24+
#define THEAD_C9XX_CSR_MFASTMBAH 0x7ec
2325
#define THEAD_C9XX_CSR_MHPMCR 0x7f0
2426
#define THEAD_C9XX_CSR_MHPMSR 0x7f1
2527
#define THEAD_C9XX_CSR_MHPMER 0x7f2
@@ -95,6 +97,7 @@
9597

9698
/* T-HEAD C9xx U mode CSR. */
9799
#define THEAD_C9XX_CSR_FXCR 0x800
100+
#define THEAD_C9XX_CSR_UTNMODE 0x8da
98101

99102
/* T-HEAD C9xx MMU extentions. */
100103
#define THEAD_C9XX_CSR_SMIR 0x9c0
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
#ifndef __RISCV_THEAD_C9XX_EXTFUNC_H____
3+
#define __RISCV_THEAD_C9XX_EXTFUNC_H____
4+
5+
/* Fast Memory Setting */
6+
#define THEAD_QUIRK_EXTFUNC_FASTMEM BIT(0)
7+
8+
void thead_c9xx_fastmem_init(void);
9+
10+
#endif // __RISCV_THEAD_C9XX_EXTFUNC_H____

platform/generic/thead/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ config THEAD_C9XX_PMU
77
config THEAD_C9XX_ERRATA
88
bool "T-HEAD c9xx errata support"
99
default n
10+
11+
config THEAD_C9XX_EXTFUNC
12+
bool "THEAD c9xx extfunc support"
13+
default n

platform/generic/thead/objects.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ platform-objs-$(CONFIG_THEAD_C9XX_PMU) += thead/thead_c9xx_pmu.o
99

1010
platform-objs-$(CONFIG_THEAD_C9XX_ERRATA) += thead/thead_c9xx_tlb_trap_handler.o
1111
platform-objs-$(CONFIG_THEAD_C9XX_ERRATA) += thead/thead_c9xx_errata_tlb_flush.o
12+
platform-objs-$(CONFIG_THEAD_C9XX_EXTFUNC) += thead/thead_c9xx_extfunc_fastmem.o
1213

1314
carray-platform_override_modules-$(CONFIG_PLATFORM_THEAD) += thead_generic
1415
platform-objs-$(CONFIG_PLATFORM_THEAD) += thead/thead-generic.o

platform/generic/thead/thead-generic.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <platform_override.h>
1010
#include <thead/c9xx_errata.h>
11+
#include <thead/c9xx_extfunc.h>
1112
#include <thead/c9xx_pmu.h>
1213
#include <sbi/sbi_const.h>
1314
#include <sbi/sbi_platform.h>
@@ -16,6 +17,7 @@
1617
#include <sbi_utils/fdt/fdt_helper.h>
1718

1819
struct thead_generic_quirks {
20+
u64 extfunc;
1921
u64 errata;
2022
};
2123

@@ -27,6 +29,9 @@ static int thead_generic_early_init(bool cold_boot,
2729
if (quirks->errata & THEAD_QUIRK_ERRATA_TLB_FLUSH)
2830
thead_register_tlb_flush_trap_handler();
2931

32+
if (quirks->extfunc & THEAD_QUIRK_EXTFUNC_FASTMEM)
33+
thead_c9xx_fastmem_init();
34+
3035
return 0;
3136
}
3237

@@ -45,8 +50,13 @@ static struct thead_generic_quirks thead_th1520_quirks = {
4550
.errata = THEAD_QUIRK_ERRATA_TLB_FLUSH | THEAD_QUIRK_ERRATA_THEAD_PMU,
4651
};
4752

53+
static struct thead_generic_quirks xuantie_c908x_quirks = {
54+
.extfunc = THEAD_QUIRK_EXTFUNC_FASTMEM,
55+
};
56+
4857
static const struct fdt_match thead_generic_match[] = {
4958
{ .compatible = "thead,th1520", .data = &thead_th1520_quirks },
59+
{ .compatible = "xuantie,c908x", .data = &xuantie_c908x_quirks },
5060
{ },
5161
};
5262

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* SPDX-License-Identifier: BSD-2-Clause
3+
*/
4+
5+
#include <libfdt.h>
6+
#include <libfdt_env.h>
7+
#include <sbi_utils/fdt/fdt_helper.h>
8+
#include <sbi/riscv_asm.h>
9+
#include <thead/c9xx_encoding.h>
10+
11+
void thead_c9xx_fastmem_init(void)
12+
{
13+
int offset, len;
14+
unsigned long mfastmbal, mfastmbah;
15+
const fdt32_t *val;
16+
17+
void *fdt = fdt_get_address();
18+
19+
/* Find node offset */
20+
offset = fdt_path_offset(fdt, "/fastmem");
21+
if (offset < 0)
22+
return;
23+
24+
val = fdt_getprop(fdt, offset, "mfastmba", &len);
25+
if (val && len == 8) {
26+
mfastmbah = fdt32_to_cpu(val[0]);
27+
mfastmbal = fdt32_to_cpu(val[1]);
28+
#if __riscv_xlen == 32
29+
csr_write(THEAD_C9XX_CSR_MFASTMBA, mfastmbal);
30+
csr_write(THEAD_C9XX_CSR_MFASTMBAH, mfastmbah);
31+
#else
32+
csr_write(THEAD_C9XX_CSR_MFASTMBA, mfastmbah << 32 | mfastmbal);
33+
#endif
34+
}
35+
}

0 commit comments

Comments
 (0)