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+
2430struct 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
3345const 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
4052void 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)
79101void 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}
83115MSH_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 )
86147rt_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
94158void 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
0 commit comments