Skip to content

Commit edaa0d9

Browse files
HelloByeAllmysterywolf
authored andcommitted
更新rk3568 bsp 支持PSCI、amp模式
1 parent 780806f commit edaa0d9

File tree

8 files changed

+103
-27
lines changed

8 files changed

+103
-27
lines changed

bsp/rockchip/rk3568/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ config SOC_RK3568
2525
select RT_USING_CACHE
2626
select RT_USING_COMPONENTS_INIT
2727
select RT_USING_USER_MAIN
28+
select ARCH_ARM_BOOTWITH_FLUSH_CACHE
2829
default y
2930

3031
source "$BSP_DIR/driver/Kconfig"

bsp/rockchip/rk3568/driver/Kconfig

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ menu "Hardware Drivers Config"
5151
bool
5252
default y
5353

54-
config BSP_USING_GICV3
55-
bool
56-
default y
54+
config BSP_USING_GICV3
55+
bool
56+
default y
5757

58+
select ARCH_ARM_CORTEX_A55
5859
endmenu

bsp/rockchip/rk3568/driver/board.c

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,29 @@
1717
#include <gtimer.h>
1818
#include <cpuport.h>
1919
#include <interrupt.h>
20+
#include <ioremap.h>
21+
#include <psci_api.h>
2022

2123
#include <board.h>
2224
#include <drv_uart.h>
2325

26+
#include "mm_page.h"
27+
28+
#define PLATFORM_MEM_TALBE(va, size) va, ((unsigned long)va + size - 1)
29+
2430
struct mem_desc platform_mem_desc[] =
2531
{
26-
{0x200000, 0x80000000, 0x200000, NORMAL_MEM},
27-
{UART0_MMIO_BASE, UART0_MMIO_BASE + 0x10000, UART0_MMIO_BASE, DEVICE_MEM},
28-
{UART1_MMIO_BASE, UART1_MMIO_BASE + 0x90000, UART1_MMIO_BASE, DEVICE_MEM},
29-
{GIC_PL600_DISTRIBUTOR_PPTR, GIC_PL600_DISTRIBUTOR_PPTR + 0x10000, GIC_PL600_DISTRIBUTOR_PPTR, DEVICE_MEM},
30-
{GIC_PL600_REDISTRIBUTOR_PPTR, GIC_PL600_REDISTRIBUTOR_PPTR + 0xc0000, GIC_PL600_REDISTRIBUTOR_PPTR, DEVICE_MEM},
32+
{PLATFORM_MEM_TALBE(0x20000000, 0x10000000), 0x20000000, NORMAL_MEM},
33+
{PLATFORM_MEM_TALBE(GRF_PMU_BASE, 0x10000), GRF_PMU_BASE, DEVICE_MEM},
34+
{PLATFORM_MEM_TALBE(GRF_SYS_BASE, 0x10000), GRF_SYS_BASE, DEVICE_MEM},
35+
{PLATFORM_MEM_TALBE(CRU_BASE, 0x10000), CRU_BASE, DEVICE_MEM},
36+
{PLATFORM_MEM_TALBE(UART0_MMIO_BASE, 0x10000), UART0_MMIO_BASE, DEVICE_MEM},
37+
{PLATFORM_MEM_TALBE(UART1_MMIO_BASE, 0x90000), UART1_MMIO_BASE, DEVICE_MEM},
38+
{PLATFORM_MEM_TALBE(GIC_PL600_DISTRIBUTOR_PPTR, 0x10000), GIC_PL600_DISTRIBUTOR_PPTR, DEVICE_MEM},
39+
{PLATFORM_MEM_TALBE(GIC_PL600_REDISTRIBUTOR_PPTR, 0xc0000), GIC_PL600_REDISTRIBUTOR_PPTR, DEVICE_MEM},
40+
#ifdef PKG_USING_RT_OPENAMP
41+
{PLATFORM_MEM_TALBE(AMP_SHARE_MEMORY_ADDRESS, AMP_SHARE_MEMORY_SIZE), AMP_SHARE_MEMORY_ADDRESS, NORMAL_MEM},
42+
#endif /* PKG_USING_RT_OPENAMP */
3143
};
3244

3345
const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc) / sizeof(platform_mem_desc[0]);
@@ -39,20 +51,30 @@ void idle_wfi(void)
3951

4052
void rt_hw_board_init(void)
4153
{
42-
extern void *MMUTable;
43-
rt_hw_mmu_map_init(&rt_kernel_space, (void*)0x80000000, 0x10000000, MMUTable, 0);
54+
extern unsigned long MMUTable[512];
55+
rt_region_t init_page_region;
56+
57+
rt_hw_mmu_map_init(&rt_kernel_space, (void *) 0x20000000, 0xE0000000 - 1, MMUTable, 0);
58+
59+
init_page_region.start = RT_HW_PAGE_START;
60+
init_page_region.end = RT_HW_PAGE_END;
61+
rt_page_init(init_page_region);
62+
4463
rt_hw_mmu_setup(&rt_kernel_space, platform_mem_desc, platform_mem_desc_size);
4564

4665
/* initialize hardware interrupt */
4766
rt_hw_interrupt_init();
67+
4868
/* initialize uart */
4969
rt_hw_uart_init();
70+
5071
/* initialize timer for os tick */
5172
rt_hw_gtimer_init();
5273

5374
rt_thread_idle_sethook(idle_wfi);
5475

5576
// TODO porting to FDT-driven PSCI: arm_psci_init(PSCI_METHOD_SMC, RT_NULL, RT_NULL);
77+
psci_init();
5678

5779
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
5880
/* set console device */
@@ -79,26 +101,68 @@ void rt_hw_board_init(void)
79101
void reboot(void)
80102
{
81103
// TODO poring to FDT to use new PSCI: arm_psci_system_reboot();
104+
if (psci_ops.system_reset)
105+
{
106+
psci_ops.system_reset();
107+
}
108+
else
109+
{
110+
void *cur_base = rt_ioremap((void *) CRU_BASE, 0x100);
111+
HWREG32(cur_base + 0x00D4) = 0xfdb9;
112+
HWREG32(cur_base + 0x00D8) = 0xeca8;
113+
}
82114
}
83115
MSH_CMD_EXPORT(reboot, reboot...);
84116

85-
#ifdef RT_USING_SMP
117+
static void print_cpu_id(int argc, char *argv[])
118+
{
119+
rt_kprintf("rt_hw_cpu_id:%d\n", rt_hw_cpu_id());
120+
}
121+
MSH_CMD_EXPORT_ALIAS(print_cpu_id, cpuid, print_cpu_id);
122+
123+
#ifdef RT_USING_AMP
124+
void start_cpu(int argc, char *argv[])
125+
{
126+
rt_uint32_t status;
127+
if (psci_ops.cpu_on)
128+
{
129+
status = psci_ops.cpu_on(0x3, (rt_uint64_t) 0x7A000000);
130+
rt_kprintf("arm_psci_cpu_on 0x%X\n", status);
131+
}
132+
}
133+
MSH_CMD_EXPORT(start_cpu, start_cpu);
134+
135+
#ifdef RT_AMP_SLAVE
136+
void rt_hw_cpu_shutdown()
137+
{
138+
if (psci_ops.cpu_off)
139+
{
140+
psci_ops.cpu_off(0);
141+
}
142+
}
143+
#endif /* RT_AMP_SLAVE */
144+
#endif /* RT_USING_AMP */
145+
146+
#if defined(RT_USING_SMP) || defined(RT_USING_AMP)
86147
rt_uint64_t rt_cpu_mpidr_early[] =
87148
{
88-
[0] = 0x81000000,
89-
[1] = 0x81000100,
90-
[2] = 0x81000200,
91-
[3] = 0x81000300,
149+
[0] = 0x80000000,
150+
[1] = 0x80000100,
151+
[2] = 0x80000200,
152+
[3] = 0x80000300,
153+
[RT_CPUS_NR] = 0
92154
};
155+
#endif
93156

157+
#ifdef RT_USING_SMP
94158
void rt_hw_secondary_cpu_up(void)
95159
{
96160
int i;
97161
extern void secondary_cpu_start(void);
98162

99163
for (i = 1; i < RT_CPUS_NR; ++i)
100164
{
101-
arm_psci_cpu_on(rt_cpu_mpidr_early[i], (rt_uint64_t)secondary_cpu_start);
165+
arm_psci_cpu_on(rt_cpu_mpidr_early[i], (rt_uint64_t) secondary_cpu_start);
102166
}
103167
}
104168

bsp/rockchip/rk3568/driver/board.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
extern unsigned char __bss_start;
1717
extern unsigned char __bss_end;
1818

19-
#define RT_HW_HEAP_BEGIN (void *)&__bss_end
20-
#define RT_HW_HEAP_END (void *)(RT_HW_HEAP_BEGIN + 64 * 1024 * 1024)
19+
#define RT_HW_PAGE_START RT_ALIGN((unsigned long)&__bss_end, 0x1000)
20+
#define RT_HW_PAGE_END (RT_HW_PAGE_START + 0x100000)
2121

22-
#ifndef RT_USING_SMART
23-
#define PV_OFFSET 0
24-
#define KERNEL_VADDR_START 0
25-
#endif
22+
#define RT_HW_HEAP_BEGIN (void *)(RT_HW_PAGE_END)
23+
#define RT_HW_HEAP_END (void *)(RT_HW_HEAP_BEGIN + 64 * 1024 * 1024)
2624

2725
void rt_hw_board_init(void);
2826

bsp/rockchip/rk3568/driver/drv_uart.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,12 @@ static void rt_hw_uart_isr(int irqno, void *param)
302302

303303
int rt_hw_uart_init(void)
304304
{
305-
struct hw_uart_device *uart;
305+
rt_uint32_t value;
306+
struct hw_uart_device* uart;
306307
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
308+
RT_UNUSED(value);
307309

308-
config.baud_rate = 1500000;
310+
config.baud_rate = 115200;
309311

310312
#define BSP_INSTALL_UART_DEVICE(no) \
311313
uart = &_uart##no##_device; \
@@ -331,6 +333,12 @@ int rt_hw_uart_init(void)
331333
#endif
332334

333335
#ifdef RT_USING_UART4
336+
HWREG32(CRU_BASE + 0x370) = 0xFFFF0000 | (0x600) |(HWREG32(CRU_BASE + 0x370) & 0xF0FF);
337+
value = HWREG32(0xFDC60000 + 0x48);
338+
value &= ~((7 << 8) | (7 << 4));
339+
value |= 0xFFFF0000 | (4 << 8) | (4 << 4);
340+
HWREG32(0xFDC60000 + 0x48) = value;
341+
HWREG32(0xFDC60000 + 0x30C) = 0xFFFF0000 | (1 << 14) | HWREG32(0xFDC60000 + 0x30C);
334342
BSP_INSTALL_UART_DEVICE(4);
335343
#endif
336344

bsp/rockchip/rk3568/driver/rk3568.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313

1414
#include <rtthread.h>
1515

16-
/* UART */
16+
#define GRF_PMU_BASE 0xFDC20000
17+
#define GRF_SYS_BASE 0xFDC60000
18+
#define CRU_BASE 0xFDD20000
19+
20+
/* UART */
1721
#define UART_MMIO_BASE 0xfe650000
1822
#define UART0_MMIO_BASE 0xfdd50000
1923
#define UART1_MMIO_BASE (UART_MMIO_BASE + 0)

bsp/rockchip/rk3568/link.lds

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ OUTPUT_ARCH(aarch64)
1313

1414
SECTIONS
1515
{
16-
. = 0x208000;
16+
. = 0x20000000;
1717
. = ALIGN(4096);
1818
.text :
1919
{

bsp/rockchip/rk3568/rtconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,5 +238,5 @@
238238
#define RT_USING_UART2
239239
#define BSP_USING_GIC
240240
#define BSP_USING_GICV3
241-
241+
#define ARCH_ARM_BOOTWITH_FLUSH_CACHE
242242
#endif

0 commit comments

Comments
 (0)