blob: 4839e332f0aff01bf2f85ac381eb167a2bf3f4e4 [file] [log] [blame]
York Sun40f8dec2014-09-08 12:20:00 -07001/*
Mingkai Hu9f3183d2015-10-26 19:47:50 +08002 * Copyright 2014-2015 Freescale Semiconductor, Inc.
York Sun40f8dec2014-09-08 12:20:00 -07003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <libfdt.h>
9#include <fdt_support.h>
Mingkai Hu9f3183d2015-10-26 19:47:50 +080010#include <phy.h>
11#ifdef CONFIG_FSL_LSCH3
12#include <asm/arch/fdt.h>
13#endif
Yangbo Lu8b064602015-03-20 19:28:31 -070014#ifdef CONFIG_FSL_ESDHC
15#include <fsl_esdhc.h>
16#endif
Mingkai Hu9f3183d2015-10-26 19:47:50 +080017#ifdef CONFIG_MP
18#include <asm/arch/mp.h>
19#endif
York Sun40f8dec2014-09-08 12:20:00 -070020
21#ifdef CONFIG_MP
22void ft_fixup_cpu(void *blob)
23{
24 int off;
25 __maybe_unused u64 spin_tbl_addr = (u64)get_spin_tbl_addr();
26 fdt32_t *reg;
27 int addr_cells;
Arnab Basu60385d92015-01-06 13:18:41 -080028 u64 val, core_id;
York Sun40f8dec2014-09-08 12:20:00 -070029 size_t *boot_code_size = &(__secondary_boot_code_size);
30
31 off = fdt_path_offset(blob, "/cpus");
32 if (off < 0) {
33 puts("couldn't find /cpus node\n");
34 return;
35 }
36 of_bus_default_count_cells(blob, off, &addr_cells, NULL);
37
38 off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
39 while (off != -FDT_ERR_NOTFOUND) {
40 reg = (fdt32_t *)fdt_getprop(blob, off, "reg", 0);
41 if (reg) {
Alison Wang6a00a9c2015-09-01 10:47:27 +080042 core_id = of_read_number(reg, addr_cells);
Arnab Basu60385d92015-01-06 13:18:41 -080043 if (core_id == 0 || (is_core_online(core_id))) {
44 val = spin_tbl_addr;
45 val += id_to_core(core_id) *
46 SPIN_TABLE_ELEM_SIZE;
47 val = cpu_to_fdt64(val);
48 fdt_setprop_string(blob, off, "enable-method",
49 "spin-table");
50 fdt_setprop(blob, off, "cpu-release-addr",
51 &val, sizeof(val));
52 } else {
53 debug("skipping offline core\n");
54 }
York Sun40f8dec2014-09-08 12:20:00 -070055 } else {
56 puts("Warning: found cpu node without reg property\n");
57 }
58 off = fdt_node_offset_by_prop_value(blob, off, "device_type",
59 "cpu", 4);
60 }
61
62 fdt_add_mem_rsv(blob, (uintptr_t)&secondary_boot_code,
63 *boot_code_size);
64}
65#endif
66
Stuart Yoder70e52d22015-07-02 11:29:04 +053067/*
68 * the burden is on the the caller to not request a count
69 * exceeding the bounds of the stream_ids[] array
70 */
71void alloc_stream_ids(int start_id, int count, u32 *stream_ids, int max_cnt)
72{
73 int i;
74
75 if (count > max_cnt) {
76 printf("\n%s: ERROR: max per-device stream ID count exceed\n",
77 __func__);
78 return;
79 }
80
81 for (i = 0; i < count; i++)
82 stream_ids[i] = start_id++;
83}
84
85/*
86 * This function updates the mmu-masters property on the SMMU
87 * node as per the SMMU binding-- phandle and list of stream IDs
88 * for each MMU master.
89 */
90void append_mmu_masters(void *blob, const char *smmu_path,
91 const char *master_name, u32 *stream_ids, int count)
92{
93 u32 phandle;
94 int smmu_nodeoffset;
95 int master_nodeoffset;
96 int i;
97
98 /* get phandle of mmu master device */
99 master_nodeoffset = fdt_path_offset(blob, master_name);
100 if (master_nodeoffset < 0) {
101 printf("\n%s: ERROR: master not found\n", __func__);
102 return;
103 }
104 phandle = fdt_get_phandle(blob, master_nodeoffset);
105 if (!phandle) { /* if master has no phandle, create one */
106 phandle = fdt_create_phandle(blob, master_nodeoffset);
107 if (!phandle) {
108 printf("\n%s: ERROR: unable to create phandle\n",
109 __func__);
110 return;
111 }
112 }
113
114 /* append it to mmu-masters */
115 smmu_nodeoffset = fdt_path_offset(blob, smmu_path);
116 if (fdt_appendprop_u32(blob, smmu_nodeoffset, "mmu-masters",
117 phandle) < 0) {
118 printf("\n%s: ERROR: unable to update SMMU node\n", __func__);
119 return;
120 }
121
122 /* for each stream ID, append to mmu-masters */
123 for (i = 0; i < count; i++) {
124 fdt_appendprop_u32(blob, smmu_nodeoffset, "mmu-masters",
125 stream_ids[i]);
126 }
127
128 /* fix up #stream-id-cells with stream ID count */
129 if (fdt_setprop_u32(blob, master_nodeoffset, "#stream-id-cells",
130 count) < 0)
131 printf("\n%s: ERROR: unable to update #stream-id-cells\n",
132 __func__);
133}
134
135
136/*
137 * The info below summarizes how streamID partitioning works
138 * for ls2085a and how it is conveyed to the OS via the device tree.
139 *
140 * -non-PCI legacy, platform devices (USB, SD/MMC, SATA, DMA)
141 * -all legacy devices get a unique ICID assigned and programmed in
142 * their AMQR registers by u-boot
143 * -u-boot updates the hardware device tree with streamID properties
144 * for each platform/legacy device (smmu-masters property)
145 *
146 * -PCIe
147 * -for each PCI controller that is active (as per RCW settings),
148 * u-boot will allocate a range of ICID and convey that to Linux via
149 * the device tree (smmu-masters property)
150 *
151 * -DPAA2
152 * -u-boot will allocate a range of ICIDs to be used by the Management
153 * Complex for containers and will set these values in the MC DPC image.
154 * -the MC is responsible for allocating and setting up ICIDs
155 * for all DPAA2 devices.
156 *
157 */
Mingkai Hu9f3183d2015-10-26 19:47:50 +0800158#ifdef CONFIG_FSL_LSCH3
Stuart Yoder70e52d22015-07-02 11:29:04 +0530159static void fdt_fixup_smmu(void *blob)
160{
161 int nodeoffset;
162
163 nodeoffset = fdt_path_offset(blob, "/iommu@5000000");
164 if (nodeoffset < 0) {
165 printf("\n%s: WARNING: no SMMU node found\n", __func__);
166 return;
167 }
168
169 /* fixup for all PCI controllers */
170#ifdef CONFIG_PCI
171 fdt_fixup_smmu_pcie(blob);
172#endif
173}
Mingkai Hu9f3183d2015-10-26 19:47:50 +0800174#endif
Stuart Yoder70e52d22015-07-02 11:29:04 +0530175
York Sun40f8dec2014-09-08 12:20:00 -0700176void ft_cpu_setup(void *blob, bd_t *bd)
177{
178#ifdef CONFIG_MP
179 ft_fixup_cpu(blob);
180#endif
Bhupesh Sharma912cc402015-01-06 13:18:44 -0800181
182#ifdef CONFIG_SYS_NS16550
Scott Wood1e528352015-03-20 19:28:14 -0700183 do_fixup_by_compat_u32(blob, "fsl,ns16550",
Bhupesh Sharma912cc402015-01-06 13:18:44 -0800184 "clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
185#endif
Yangbo Lu8b064602015-03-20 19:28:31 -0700186
Prabhakar Kushwaha5be3b442015-05-28 14:53:59 +0530187#ifdef CONFIG_PCI
188 ft_pci_setup(blob, bd);
189#endif
190
Mingkai Hu9f3183d2015-10-26 19:47:50 +0800191#ifdef CONFIG_FSL_ESDHC
Yangbo Lu8b064602015-03-20 19:28:31 -0700192 fdt_fixup_esdhc(blob, bd);
193#endif
Stuart Yoder70e52d22015-07-02 11:29:04 +0530194
Mingkai Hu9f3183d2015-10-26 19:47:50 +0800195#ifdef CONFIG_FSL_LSCH3
Stuart Yoder70e52d22015-07-02 11:29:04 +0530196 fdt_fixup_smmu(blob);
Mingkai Hu9f3183d2015-10-26 19:47:50 +0800197#endif
York Sun40f8dec2014-09-08 12:20:00 -0700198}