weichangzheng | 74b4519 | 2022-03-02 15:09:05 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2021 |
| 4 | * lixinde <lixinde@phytium.com.cn> |
| 5 | * weichangzheng <weichangzheng@phytium.com.cn> |
| 6 | */ |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | #include <command.h> |
Simon Glass | 1cedca1 | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 10 | #include <event.h> |
weichangzheng | 74b4519 | 2022-03-02 15:09:05 +0800 | [diff] [blame] | 11 | #include <init.h> |
| 12 | #include <asm/armv8/mmu.h> |
| 13 | #include <asm/io.h> |
| 14 | #include <linux/arm-smccc.h> |
| 15 | #include <scsi.h> |
| 16 | #include <init.h> |
| 17 | #include <asm/u-boot.h> |
| 18 | #include "cpu.h" |
| 19 | |
| 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
| 22 | int dram_init(void) |
| 23 | { |
| 24 | debug("Phytium ddr init\n"); |
| 25 | ddr_init(); |
| 26 | |
| 27 | gd->mem_clk = 0; |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 28 | gd->ram_size = get_ram_size((void *)CFG_SYS_SDRAM_BASE, 0x7b000000); |
weichangzheng | 74b4519 | 2022-03-02 15:09:05 +0800 | [diff] [blame] | 29 | |
| 30 | sec_init(); |
| 31 | debug("PBF relocate done\n"); |
| 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | int board_init(void) |
| 37 | { |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | void reset_cpu(void) |
| 42 | { |
| 43 | struct arm_smccc_res res; |
| 44 | |
| 45 | debug("run in reset cpu\n"); |
| 46 | arm_smccc_smc(0x84000009, 0, 0, 0, 0, 0, 0, 0, &res); |
| 47 | if (res.a0 != 0) |
| 48 | panic("reset cpu error, %lx\n", res.a0); |
| 49 | } |
| 50 | |
| 51 | int mach_cpu_init(void) |
| 52 | { |
| 53 | check_reset(); |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | int board_early_init_f(void) |
| 58 | { |
| 59 | pcie_init(); |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | static struct mm_region pomelo_mem_map[] = { |
| 64 | { |
| 65 | .virt = 0x0UL, |
| 66 | .phys = 0x0UL, |
| 67 | .size = 0x80000000UL, |
| 68 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 69 | PTE_BLOCK_NON_SHARE | |
| 70 | PTE_BLOCK_PXN | |
| 71 | PTE_BLOCK_UXN |
| 72 | }, |
| 73 | { |
| 74 | .virt = 0x80000000UL, |
| 75 | .phys = 0x80000000UL, |
| 76 | .size = 0x7b000000UL, |
| 77 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 78 | PTE_BLOCK_NS | |
| 79 | PTE_BLOCK_INNER_SHARE |
| 80 | }, |
| 81 | { |
| 82 | 0, |
| 83 | } |
| 84 | }; |
| 85 | |
| 86 | struct mm_region *mem_map = pomelo_mem_map; |
| 87 | |
| 88 | int __asm_flush_l3_dcache(void) |
| 89 | { |
| 90 | int i, pstate; |
| 91 | |
| 92 | for (i = 0; i < HNF_COUNT; i++) |
| 93 | writeq(HNF_PSTATE_SFONLY, HNF_PSTATE_REQ + i * HNF_STRIDE); |
| 94 | for (i = 0; i < HNF_COUNT; i++) { |
| 95 | do { |
| 96 | pstate = readq(HNF_PSTATE_STAT + i * HNF_STRIDE); |
| 97 | } while ((pstate & 0xf) != (HNF_PSTATE_SFONLY << 2)); |
| 98 | } |
| 99 | |
| 100 | for (i = 0; i < HNF_COUNT; i++) |
| 101 | writeq(HNF_PSTATE_FULL, HNF_PSTATE_REQ + i * HNF_STRIDE); |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
Simon Glass | 1cedca1 | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 106 | static int last_stage_init(void) |
weichangzheng | 74b4519 | 2022-03-02 15:09:05 +0800 | [diff] [blame] | 107 | { |
| 108 | int ret; |
| 109 | |
| 110 | /* pci e */ |
| 111 | pci_init(); |
| 112 | /* scsi scan */ |
| 113 | ret = scsi_scan(true); |
| 114 | if (ret) { |
| 115 | printf("scsi scan failed\n"); |
| 116 | return CMD_RET_FAILURE; |
| 117 | } |
| 118 | return ret; |
| 119 | } |
Simon Glass | 1cedca1 | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 120 | EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, last_stage_init); |