Skip to content

Commit e2a918d

Browse files
enjoy-digitaltrabucayre
authored andcommitted
add initial litex/vexriscv platform.
1 parent ea6533a commit e2a918d

File tree

4 files changed

+240
-0
lines changed

4 files changed

+240
-0
lines changed

platform/litex/vexriscv/config.mk

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# SPDX-License-Identifier: BSD-2-Clause
3+
#
4+
# Copyright (c) 2020 Florent Kermarrec <[email protected]>
5+
# Copyright (c) 2020 Dolu1990 <[email protected]>
6+
#
7+
8+
# Compiler flags
9+
platform-cppflags-y =
10+
platform-cflags-y =
11+
platform-asflags-y =
12+
platform-ldflags-y =
13+
14+
# Command for platform specific "make run"
15+
platform-runcmd = echo LiteX/VexRiscv SMP
16+
17+
PLATFORM_RISCV_XLEN = 32
18+
PLATFORM_RISCV_ABI = ilp32
19+
PLATFORM_RISCV_ISA = rv32ima
20+
PLATFORM_RISCV_CODE_MODEL = medany
21+
22+
# Blobs to build
23+
FW_TEXT_START=0x40F00000
24+
FW_DYNAMIC=y
25+
FW_JUMP=y
26+
FW_JUMP_ADDR=0x40000000
27+
FW_JUMP_FDT_ADDR=0x40EF0000
28+
FW_PAYLOAD=y
29+
FW_PAYLOAD_OFFSET=0x40000000
30+
FW_PAYLOAD_FDT_ADDR=0x40EF0000

platform/litex/vexriscv/litex.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* SPDX-License-Identifier: BSD-2-Clause
3+
*
4+
* Copyright (c) 2020 Florent Kermarrec <[email protected]>
5+
* Copyright (c) 2020 Dolu1990 <[email protected]>
6+
*
7+
*/
8+
9+
#include <stdint.h>
10+
11+
#define UART_EV_TX 0x1
12+
#define UART_EV_RX 0x2
13+
14+
#define MMPTR(a) (*((volatile uint32_t *)(a)))
15+
16+
static inline void csr_write_simple(unsigned long v, unsigned long a)
17+
{
18+
MMPTR(a) = v;
19+
}
20+
21+
static inline unsigned long csr_read_simple(unsigned long a)
22+
{
23+
return MMPTR(a);
24+
}
25+
26+
#define CSR_BASE 0xf0000000L
27+
28+
static inline uint8_t uart_rxtx_read(void) {
29+
return csr_read_simple(CSR_BASE + 0x1000L);
30+
}
31+
static inline void uart_rxtx_write(uint8_t v) {
32+
csr_write_simple(v, CSR_BASE + 0x1000L);
33+
}
34+
35+
static inline uint8_t uart_txfull_read(void) {
36+
return csr_read_simple(CSR_BASE + 0x1004L);
37+
}
38+
39+
static inline uint8_t uart_rxempty_read(void) {
40+
return csr_read_simple(CSR_BASE + 0x1008L);
41+
}
42+
43+
static inline void uart_ev_pending_write(uint8_t v) {
44+
csr_write_simple(v, CSR_BASE + 0x1010L);
45+
}
46+
47+
static inline uint8_t uart_txempty_read(void) {
48+
return csr_read_simple(CSR_BASE + 0x1018L);
49+
}
50+
static inline uint8_t uart_rxfull_read(void) {
51+
return csr_read_simple(CSR_BASE + 0x101cL);
52+
}
53+
54+
55+
void vex_putc(char c){
56+
while (uart_txfull_read());
57+
uart_rxtx_write(c);
58+
uart_ev_pending_write(UART_EV_TX);
59+
}
60+
61+
int vex_getc(void){
62+
char c;
63+
if (uart_rxempty_read()) return -1;
64+
c = uart_rxtx_read();
65+
uart_ev_pending_write(UART_EV_RX);
66+
return c;
67+
}

platform/litex/vexriscv/objects.mk

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# SPDX-License-Identifier: BSD-2-Clause
3+
#
4+
# Copyright (c) 2020 Dolu1990 <[email protected]>
5+
#
6+
7+
platform-objs-y += platform.o
8+
platform-objs-y += litex.o

platform/litex/vexriscv/platform.c

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
* SPDX-License-Identifier: BSD-2-Clause
3+
*
4+
* Copyright (c) 2020 Dolu1990 <[email protected]>
5+
*
6+
*/
7+
8+
#include <sbi/riscv_asm.h>
9+
#include <sbi/riscv_encoding.h>
10+
#include <sbi/riscv_io.h>
11+
#include <sbi/sbi_const.h>
12+
#include <sbi/sbi_hart.h>
13+
#include <sbi/sbi_platform.h>
14+
#include <sbi_utils/irqchip/plic.h>
15+
#include <sbi_utils/serial/uart8250.h>
16+
#include <sbi_utils/sys/clint.h>
17+
18+
19+
/* clang-format off */
20+
21+
#define VEX_HART_COUNT 4
22+
#define VEX_PLATFORM_FEATURES \
23+
(SBI_PLATFORM_HAS_TIMER_VALUE | SBI_PLATFORM_HAS_MFAULTS_DELEGATION)
24+
25+
#define VEX_CLINT_ADDR 0xF0010000
26+
27+
#define VEX_HART_STACK_SIZE 8192
28+
29+
30+
31+
/* clang-format on */
32+
33+
static struct clint_data clint = {VEX_CLINT_ADDR, 0, VEX_HART_COUNT, true};
34+
35+
static int vex_final_init(bool cold_boot)
36+
{
37+
return 0;
38+
}
39+
40+
static u32 vex_pmp_region_count(u32 hartid)
41+
{
42+
return 0;
43+
}
44+
45+
static int vex_pmp_region_info(u32 hartid, u32 index, ulong *prot, ulong *addr,
46+
ulong *log2size)
47+
{
48+
int ret = 0;
49+
50+
switch (index) {
51+
default:
52+
ret = -1;
53+
break;
54+
};
55+
56+
return ret;
57+
}
58+
59+
60+
extern void vex_putc(char ch);
61+
extern int vex_getc(void);
62+
63+
static int vex_console_init(void)
64+
{
65+
return 0;
66+
}
67+
68+
static int vex_irqchip_init(bool cold_boot)
69+
{
70+
return 0;
71+
}
72+
73+
static int vex_ipi_init(bool cold_boot)
74+
{
75+
int rc;
76+
77+
if (cold_boot) {
78+
rc = clint_cold_ipi_init(&clint);
79+
if (rc)
80+
return rc;
81+
}
82+
83+
return clint_warm_ipi_init();
84+
}
85+
86+
static int vex_timer_init(bool cold_boot)
87+
{
88+
int rc;
89+
if (cold_boot) {
90+
rc = clint_cold_timer_init(&clint, NULL); /* Timer has no reference */
91+
if (rc)
92+
return rc;
93+
}
94+
95+
return clint_warm_timer_init();
96+
}
97+
98+
static int vex_system_reset(u32 type)
99+
{
100+
/* Tell the "finisher" that the simulation
101+
* was successful so that QEMU exits
102+
*/
103+
104+
return 0;
105+
}
106+
107+
const struct sbi_platform_operations platform_ops = {
108+
.pmp_region_count = vex_pmp_region_count,
109+
.pmp_region_info = vex_pmp_region_info,
110+
.final_init = vex_final_init,
111+
.console_putc = vex_putc,
112+
.console_getc = vex_getc,
113+
.console_init = vex_console_init,
114+
.irqchip_init = vex_irqchip_init,
115+
.ipi_send = clint_ipi_send,
116+
.ipi_clear = clint_ipi_clear,
117+
.ipi_init = vex_ipi_init,
118+
.timer_value = clint_timer_value,
119+
.timer_event_stop = clint_timer_event_stop,
120+
.timer_event_start = clint_timer_event_start,
121+
.timer_init = vex_timer_init,
122+
.system_reset = vex_system_reset
123+
};
124+
125+
const struct sbi_platform platform = {
126+
.opensbi_version = OPENSBI_VERSION,
127+
.platform_version = SBI_PLATFORM_VERSION(0x0, 0x01),
128+
.name = "LiteX/VexRiscv SMP",
129+
.features = VEX_PLATFORM_FEATURES,
130+
.hart_count = VEX_HART_COUNT,
131+
.hart_stack_size = VEX_HART_STACK_SIZE,
132+
.platform_ops_addr = (unsigned long)&platform_ops
133+
};
134+
135+

0 commit comments

Comments
 (0)