blob: 960e491c7687adacfa0a5aa4699639e92afd0551 [file] [log] [blame]
weichangzheng74b45192022-03-02 15:09:05 +08001// 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 Glass1cedca12023-08-21 21:17:01 -060010#include <event.h>
weichangzheng74b45192022-03-02 15:09:05 +080011#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
20DECLARE_GLOBAL_DATA_PTR;
21
22int dram_init(void)
23{
24 debug("Phytium ddr init\n");
25 ddr_init();
26
27 gd->mem_clk = 0;
Tom Rinibb4dd962022-11-16 13:10:37 -050028 gd->ram_size = get_ram_size((void *)CFG_SYS_SDRAM_BASE, 0x7b000000);
weichangzheng74b45192022-03-02 15:09:05 +080029
30 sec_init();
31 debug("PBF relocate done\n");
32
33 return 0;
34}
35
36int board_init(void)
37{
38 return 0;
39}
40
41void 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
51int mach_cpu_init(void)
52{
53 check_reset();
54 return 0;
55}
56
57int board_early_init_f(void)
58{
59 pcie_init();
60 return 0;
61}
62
63static 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
86struct mm_region *mem_map = pomelo_mem_map;
87
88int __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 Glass1cedca12023-08-21 21:17:01 -0600106static int last_stage_init(void)
weichangzheng74b45192022-03-02 15:09:05 +0800107{
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 Glass1cedca12023-08-21 21:17:01 -0600120EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, last_stage_init);