|
11 | 11 | #include <sbi/sbi_const.h> |
12 | 12 | #include <sbi/sbi_hart.h> |
13 | 13 | #include <sbi/sbi_platform.h> |
| 14 | +#include <sbi_utils/fdt/fdt_helper.h> |
| 15 | +#include <sbi_utils/fdt/fdt_fixup.h> |
| 16 | +#include <sbi_utils/ipi/aclint_mswi.h> |
14 | 17 | #include <sbi_utils/irqchip/plic.h> |
15 | | -#include <sbi_utils/serial/uart8250.h> |
16 | | -#include <sbi_utils/sys/clint.h> |
| 18 | +#include <sbi_utils/serial/litex-uart.h> |
| 19 | +#include <sbi_utils/timer/aclint_mtimer.h> |
| 20 | + |
| 21 | +#define VEX_DEFAULT_HART_COUNT 8 |
| 22 | +#define VEX_DEFAULT_PLATFORM_FEATURES SBI_PLATFORM_HAS_MFAULTS_DELEGATION |
| 23 | +#define VEX_DEFAULT_UART_ADDR 0xf0001000 |
| 24 | +#define VEX_DEFAULT_PLIC_ADDR 0xf0c00000 |
| 25 | +#define VEX_DEFAULT_PLIC_NUM_SOURCES 4 |
| 26 | +#define VEX_DEFAULT_CLINT_ADDR 0xF0010000 |
| 27 | +#define VEX_DEFAULT_ACLINT_MTIMER_FREQ 100000000 |
| 28 | +#define VEX_DEFAULT_ACLINT_MSWI_ADDR \ |
| 29 | + (VEX_DEFAULT_CLINT_ADDR + CLINT_MSWI_OFFSET) |
| 30 | +#define VEX_DEFAULT_ACLINT_MTIMER_ADDR \ |
| 31 | + (VEX_DEFAULT_CLINT_ADDR + CLINT_MTIMER_OFFSET) |
| 32 | +#define VEX_DEFAULT_HART_STACK_SIZE 8192 |
17 | 33 |
|
| 34 | +/* clang-format on */ |
18 | 35 |
|
19 | | -/* clang-format off */ |
20 | | - |
21 | | -#define VEX_HART_COUNT 8 |
22 | | -#define VEX_PLATFORM_FEATURES (SBI_PLATFORM_HAS_TIMER_VALUE | SBI_PLATFORM_HAS_MFAULTS_DELEGATION) |
23 | | -#define VEX_CLINT_ADDR 0xF0010000 |
24 | | -#define VEX_HART_STACK_SIZE 8192 |
| 36 | +static struct plic_data plic = { |
| 37 | + .addr = VEX_DEFAULT_PLIC_ADDR, |
| 38 | + .num_src = VEX_DEFAULT_PLIC_NUM_SOURCES, |
| 39 | +}; |
25 | 40 |
|
26 | | -/* clang-format on */ |
| 41 | +static struct aclint_mswi_data mswi = { |
| 42 | + .addr = VEX_DEFAULT_ACLINT_MSWI_ADDR, |
| 43 | + .size = ACLINT_MSWI_SIZE, |
| 44 | + .first_hartid = 0, |
| 45 | + .hart_count = VEX_DEFAULT_HART_COUNT, |
| 46 | +}; |
27 | 47 |
|
28 | | -static struct clint_data clint = {VEX_CLINT_ADDR, 0, VEX_HART_COUNT, true}; |
| 48 | +static struct aclint_mtimer_data mtimer = { |
| 49 | + .mtime_freq = VEX_DEFAULT_ACLINT_MTIMER_FREQ, |
| 50 | + .mtime_addr = VEX_DEFAULT_ACLINT_MTIMER_ADDR + |
| 51 | + ACLINT_DEFAULT_MTIME_OFFSET, |
| 52 | + .mtime_size = ACLINT_DEFAULT_MTIME_SIZE, |
| 53 | + .mtimecmp_addr = VEX_DEFAULT_ACLINT_MTIMER_ADDR + |
| 54 | + ACLINT_DEFAULT_MTIMECMP_OFFSET, |
| 55 | + .mtimecmp_size = ACLINT_DEFAULT_MTIMECMP_SIZE, |
| 56 | + .first_hartid = 0, |
| 57 | + .hart_count = VEX_DEFAULT_HART_COUNT, |
| 58 | + .has_64bit_mmio = true, |
| 59 | +}; |
29 | 60 |
|
30 | | -static int vex_final_init(bool cold_boot) |
| 61 | +/* |
| 62 | + * VexRiscv platform early initialization. |
| 63 | + */ |
| 64 | +static int vex_early_init(bool cold_boot) |
31 | 65 | { |
32 | 66 | return 0; |
33 | 67 | } |
34 | 68 |
|
35 | | -static u32 vex_pmp_region_count(u32 hartid) |
| 69 | +/* |
| 70 | + * VexRiscv platform final initialization. |
| 71 | + */ |
| 72 | +static int vex_final_init(bool cold_boot) |
36 | 73 | { |
37 | | - return 0; |
38 | | -} |
| 74 | + void *fdt; |
39 | 75 |
|
40 | | -static int vex_pmp_region_info(u32 hartid, u32 index, ulong *prot, ulong *addr, |
41 | | - ulong *log2size) |
42 | | -{ |
43 | | - int ret = 0; |
| 76 | + if (!cold_boot) |
| 77 | + return 0; |
44 | 78 |
|
45 | | - switch (index) { |
46 | | - default: |
47 | | - ret = -1; |
48 | | - break; |
49 | | - }; |
| 79 | + fdt = fdt_get_address(); |
| 80 | + fdt_fixups(fdt); |
50 | 81 |
|
51 | | - return ret; |
| 82 | + return 0; |
52 | 83 | } |
53 | 84 |
|
54 | | - |
55 | | -extern void vex_putc(char ch); |
56 | | -extern int vex_getc(void); |
57 | | - |
| 85 | +/* |
| 86 | + * Initialize the vexRiscv console. |
| 87 | + */ |
58 | 88 | static int vex_console_init(void) |
59 | 89 | { |
60 | | - return 0; |
| 90 | + return litex_uart_init(VEX_DEFAULT_UART_ADDR); |
61 | 91 | } |
62 | 92 |
|
| 93 | +/* |
| 94 | + * Initialize the vexRiscv interrupt controller for current HART. |
| 95 | + */ |
63 | 96 | static int vex_irqchip_init(bool cold_boot) |
64 | 97 | { |
65 | | - return 0; |
| 98 | + int rc; |
| 99 | + u32 hartid = current_hartid(); |
| 100 | + |
| 101 | + if (cold_boot) { |
| 102 | + rc = plic_cold_irqchip_init(&plic); |
| 103 | + if (rc) |
| 104 | + return rc; |
| 105 | + } |
| 106 | + |
| 107 | + return plic_warm_irqchip_init(&plic, hartid * 2, hartid * 2 + 1); |
| 108 | + |
66 | 109 | } |
67 | 110 |
|
| 111 | +/* |
| 112 | + * Initialize IPI for current HART. |
| 113 | + */ |
68 | 114 | static int vex_ipi_init(bool cold_boot) |
69 | 115 | { |
70 | 116 | int rc; |
71 | 117 |
|
72 | 118 | if (cold_boot) { |
73 | | - rc = clint_cold_ipi_init(&clint); |
| 119 | + rc = aclint_mswi_cold_init(&mswi); |
74 | 120 | if (rc) |
75 | 121 | return rc; |
76 | 122 | } |
77 | 123 |
|
78 | | - return clint_warm_ipi_init(); |
| 124 | + return aclint_mswi_warm_init(); |
79 | 125 | } |
80 | 126 |
|
| 127 | +/* |
| 128 | + * Initialize vexRiscv timer for current HART. |
| 129 | + */ |
81 | 130 | static int vex_timer_init(bool cold_boot) |
82 | 131 | { |
83 | 132 | int rc; |
84 | 133 | if (cold_boot) { |
85 | | - rc = clint_cold_timer_init(&clint, NULL); /* Timer has no reference */ |
| 134 | + rc = aclint_mtimer_cold_init(&mtimer, NULL); /* Timer has no reference */ |
86 | 135 | if (rc) |
87 | 136 | return rc; |
88 | 137 | } |
89 | 138 |
|
90 | | - return clint_warm_timer_init(); |
91 | | -} |
92 | | - |
93 | | -static int vex_system_reset(u32 type) |
94 | | -{ |
95 | | - /* Tell the "finisher" that the simulation |
96 | | - * was successful so that QEMU exits |
97 | | - */ |
98 | | - |
99 | | - return 0; |
| 139 | + return aclint_mtimer_warm_init(); |
100 | 140 | } |
101 | 141 |
|
| 142 | +/* |
| 143 | + * Platform descriptor. |
| 144 | + */ |
102 | 145 | const struct sbi_platform_operations platform_ops = { |
103 | | - .pmp_region_count = vex_pmp_region_count, |
104 | | - .pmp_region_info = vex_pmp_region_info, |
105 | | - .final_init = vex_final_init, |
106 | | - .console_putc = vex_putc, |
107 | | - .console_getc = vex_getc, |
108 | | - .console_init = vex_console_init, |
109 | | - .irqchip_init = vex_irqchip_init, |
110 | | - .ipi_send = clint_ipi_send, |
111 | | - .ipi_clear = clint_ipi_clear, |
112 | | - .ipi_init = vex_ipi_init, |
113 | | - .timer_value = clint_timer_value, |
114 | | - .timer_event_stop = clint_timer_event_stop, |
115 | | - .timer_event_start = clint_timer_event_start, |
116 | | - .timer_init = vex_timer_init, |
117 | | - .system_reset = vex_system_reset |
| 146 | + .early_init = vex_early_init, |
| 147 | + .final_init = vex_final_init, |
| 148 | + .console_init = vex_console_init, |
| 149 | + .irqchip_init = vex_irqchip_init, |
| 150 | + .ipi_init = vex_ipi_init, |
| 151 | + .timer_init = vex_timer_init |
118 | 152 | }; |
119 | 153 |
|
120 | 154 | const struct sbi_platform platform = { |
121 | | - .opensbi_version = OPENSBI_VERSION, |
122 | | - .platform_version = SBI_PLATFORM_VERSION(0x0, 0x01), |
123 | | - .name = "LiteX / VexRiscv-SMP", |
124 | | - .features = VEX_PLATFORM_FEATURES, |
125 | | - .hart_count = VEX_HART_COUNT, |
126 | | - .hart_stack_size = VEX_HART_STACK_SIZE, |
127 | | - .platform_ops_addr = (unsigned long)&platform_ops |
| 155 | + .opensbi_version = OPENSBI_VERSION, |
| 156 | + .platform_version = SBI_PLATFORM_VERSION(0x0, 0x01), |
| 157 | + .name = "LiteX / VexRiscv-SMP", |
| 158 | + .features = VEX_DEFAULT_PLATFORM_FEATURES, |
| 159 | + .hart_count = VEX_DEFAULT_HART_COUNT, |
| 160 | + .hart_stack_size = VEX_DEFAULT_HART_STACK_SIZE, |
| 161 | + .heap_size = |
| 162 | + SBI_PLATFORM_DEFAULT_HEAP_SIZE(VEX_DEFAULT_HART_COUNT), |
| 163 | + .platform_ops_addr = (unsigned long)&platform_ops |
128 | 164 | }; |
129 | | - |
130 | | - |
|
0 commit comments