blob: 0cb65b32e48919f2a38cebec329389be8db3dcf1 [file] [log] [blame]
Kumar Gala8975d7a2010-12-30 12:09:53 -06001/*
2 * Copyright 2011 Freescale Semiconductor, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 2 of the License, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
17 * MA 02111-1307 USA
18 */
19
20#include <common.h>
21#include <config.h>
22#include <asm/fsl_law.h>
23#include <asm/fsl_serdes.h>
Liu Gang4cc85322012-03-08 00:33:17 +000024#include <asm/fsl_srio.h>
25
26#define SRIO_PORT_ACCEPT_ALL 0x10000001
27#define SRIO_IB_ATMU_AR 0x80f55000
Liu Gangf420aa92012-03-08 00:33:21 +000028#define SRIO_OB_ATMU_AR_MAINT 0x80077000
29#define SRIO_OB_ATMU_AR_RW 0x80045000
30#define SRIO_LCSBA1CSR_OFFSET 0x5c
31#define SRIO_MAINT_WIN_SIZE 0x1000000 /* 16M */
32#define SRIO_RW_WIN_SIZE 0x100000 /* 1M */
33#define SRIO_LCSBA1CSR 0x60000000
Kumar Gala8975d7a2010-12-30 12:09:53 -060034
35#if defined(CONFIG_FSL_CORENET)
36 #define _DEVDISR_SRIO1 FSL_CORENET_DEVDISR_SRIO1
37 #define _DEVDISR_SRIO2 FSL_CORENET_DEVDISR_SRIO2
38 #define _DEVDISR_RMU FSL_CORENET_DEVDISR_RMU
39 #define CONFIG_SYS_MPC8xxx_GUTS_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
40#elif defined(CONFIG_MPC85xx)
41 #define _DEVDISR_SRIO1 MPC85xx_DEVDISR_SRIO
42 #define _DEVDISR_SRIO2 MPC85xx_DEVDISR_SRIO
43 #define _DEVDISR_RMU MPC85xx_DEVDISR_RMSG
44 #define CONFIG_SYS_MPC8xxx_GUTS_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
45#elif defined(CONFIG_MPC86xx)
46 #define _DEVDISR_SRIO1 MPC86xx_DEVDISR_SRIO
47 #define _DEVDISR_SRIO2 MPC86xx_DEVDISR_SRIO
48 #define _DEVDISR_RMU MPC86xx_DEVDISR_RMSG
49 #define CONFIG_SYS_MPC8xxx_GUTS_ADDR \
50 (&((immap_t *)CONFIG_SYS_IMMR)->im_gur)
51#else
52#error "No defines for DEVDISR_SRIO"
53#endif
54
55void srio_init(void)
56{
57 ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC8xxx_GUTS_ADDR;
58 int srio1_used = 0, srio2_used = 0;
59
60 if (is_serdes_configured(SRIO1)) {
61 set_next_law(CONFIG_SYS_SRIO1_MEM_PHYS,
62 law_size_bits(CONFIG_SYS_SRIO1_MEM_SIZE),
63 LAW_TRGT_IF_RIO_1);
64 srio1_used = 1;
65 printf("SRIO1: enabled\n");
66 } else {
67 printf("SRIO1: disabled\n");
68 }
69
70#ifdef CONFIG_SRIO2
71 if (is_serdes_configured(SRIO2)) {
72 set_next_law(CONFIG_SYS_SRIO2_MEM_PHYS,
73 law_size_bits(CONFIG_SYS_SRIO2_MEM_SIZE),
74 LAW_TRGT_IF_RIO_2);
75 srio2_used = 1;
76 printf("SRIO2: enabled\n");
77 } else {
78 printf("SRIO2: disabled\n");
79 }
80#endif
81
82#ifdef CONFIG_FSL_CORENET
83 /* On FSL_CORENET devices we can disable individual ports */
84 if (!srio1_used)
85 setbits_be32(&gur->devdisr, FSL_CORENET_DEVDISR_SRIO1);
86 if (!srio2_used)
87 setbits_be32(&gur->devdisr, FSL_CORENET_DEVDISR_SRIO2);
88#endif
89
90 /* neither port is used - disable everything */
91 if (!srio1_used && !srio2_used) {
92 setbits_be32(&gur->devdisr, _DEVDISR_SRIO1);
93 setbits_be32(&gur->devdisr, _DEVDISR_SRIO2);
94 setbits_be32(&gur->devdisr, _DEVDISR_RMU);
95 }
96}
Liu Gang4cc85322012-03-08 00:33:17 +000097
Liu Gangd7b17a92012-08-09 05:09:59 +000098#ifdef CONFIG_FSL_CORENET
99void srio_boot_master(int port)
Liu Gang4cc85322012-03-08 00:33:17 +0000100{
101 struct ccsr_rio *srio = (void *)CONFIG_SYS_FSL_SRIO_ADDR;
102
103 /* set port accept-all */
Liu Gangd7b17a92012-08-09 05:09:59 +0000104 out_be32((void *)&srio->impl.port[port - 1].ptaacr,
Liu Gang4cc85322012-03-08 00:33:17 +0000105 SRIO_PORT_ACCEPT_ALL);
106
Liu Gangd7b17a92012-08-09 05:09:59 +0000107 debug("SRIOBOOT - MASTER: Master port [ %d ] for srio boot.\n", port);
Liu Gang58f030c2012-03-08 00:33:19 +0000108 /* configure inbound window for slave's u-boot image */
109 debug("SRIOBOOT - MASTER: Inbound window for slave's image; "
Liu Gang4cc85322012-03-08 00:33:17 +0000110 "Local = 0x%llx, Srio = 0x%llx, Size = 0x%x\n",
Liu Gang99e0c292012-08-09 05:10:02 +0000111 (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS,
112 (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS1,
113 CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE);
Liu Gangd7b17a92012-08-09 05:09:59 +0000114 out_be32((void *)&srio->atmu.port[port - 1].inbw[0].riwtar,
Liu Gang99e0c292012-08-09 05:10:02 +0000115 CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS >> 12);
Liu Gangd7b17a92012-08-09 05:09:59 +0000116 out_be32((void *)&srio->atmu.port[port - 1].inbw[0].riwbar,
Liu Gang99e0c292012-08-09 05:10:02 +0000117 CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS1 >> 12);
Liu Gangd7b17a92012-08-09 05:09:59 +0000118 out_be32((void *)&srio->atmu.port[port - 1].inbw[0].riwar,
Liu Gang4cc85322012-03-08 00:33:17 +0000119 SRIO_IB_ATMU_AR
Liu Gang99e0c292012-08-09 05:10:02 +0000120 | atmu_size_mask(CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE));
Liu Gang4cc85322012-03-08 00:33:17 +0000121
Liu Gang58f030c2012-03-08 00:33:19 +0000122 /* configure inbound window for slave's u-boot image */
123 debug("SRIOBOOT - MASTER: Inbound window for slave's image; "
Liu Gang4cc85322012-03-08 00:33:17 +0000124 "Local = 0x%llx, Srio = 0x%llx, Size = 0x%x\n",
Liu Gang99e0c292012-08-09 05:10:02 +0000125 (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS,
126 (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS2,
127 CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE);
Liu Gangd7b17a92012-08-09 05:09:59 +0000128 out_be32((void *)&srio->atmu.port[port - 1].inbw[1].riwtar,
Liu Gang99e0c292012-08-09 05:10:02 +0000129 CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS >> 12);
Liu Gangd7b17a92012-08-09 05:09:59 +0000130 out_be32((void *)&srio->atmu.port[port - 1].inbw[1].riwbar,
Liu Gang99e0c292012-08-09 05:10:02 +0000131 CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS2 >> 12);
Liu Gangd7b17a92012-08-09 05:09:59 +0000132 out_be32((void *)&srio->atmu.port[port - 1].inbw[1].riwar,
Liu Gang4cc85322012-03-08 00:33:17 +0000133 SRIO_IB_ATMU_AR
Liu Gang99e0c292012-08-09 05:10:02 +0000134 | atmu_size_mask(CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE));
Liu Gang58f030c2012-03-08 00:33:19 +0000135
Liu Gangd7b17a92012-08-09 05:09:59 +0000136 /* configure inbound window for slave's ucode and ENV */
137 debug("SRIOBOOT - MASTER: Inbound window for slave's ucode and ENV; "
Liu Gang58f030c2012-03-08 00:33:19 +0000138 "Local = 0x%llx, Srio = 0x%llx, Size = 0x%x\n",
Liu Gang99e0c292012-08-09 05:10:02 +0000139 (u64)CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_PHYS,
140 (u64)CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_BUS,
141 CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_SIZE);
Liu Gangd7b17a92012-08-09 05:09:59 +0000142 out_be32((void *)&srio->atmu.port[port - 1].inbw[2].riwtar,
Liu Gang99e0c292012-08-09 05:10:02 +0000143 CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_PHYS >> 12);
Liu Gangd7b17a92012-08-09 05:09:59 +0000144 out_be32((void *)&srio->atmu.port[port - 1].inbw[2].riwbar,
Liu Gang99e0c292012-08-09 05:10:02 +0000145 CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_BUS >> 12);
Liu Gangd7b17a92012-08-09 05:09:59 +0000146 out_be32((void *)&srio->atmu.port[port - 1].inbw[2].riwar,
Liu Gang58f030c2012-03-08 00:33:19 +0000147 SRIO_IB_ATMU_AR
Liu Gang99e0c292012-08-09 05:10:02 +0000148 | atmu_size_mask(CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_SIZE));
Liu Gang4cc85322012-03-08 00:33:17 +0000149}
Liu Gangf420aa92012-03-08 00:33:21 +0000150
Liu Gangd7b17a92012-08-09 05:09:59 +0000151void srio_boot_master_release_slave(int port)
Liu Gangf420aa92012-03-08 00:33:21 +0000152{
153 struct ccsr_rio *srio = (void *)CONFIG_SYS_FSL_SRIO_ADDR;
154 u32 escsr;
155 debug("SRIOBOOT - MASTER: "
156 "Check the port status and release slave core ...\n");
157
Liu Gangd7b17a92012-08-09 05:09:59 +0000158 escsr = in_be32((void *)&srio->lp_serial.port[port - 1].pescsr);
Liu Gangf420aa92012-03-08 00:33:21 +0000159 if (escsr & 0x2) {
160 if (escsr & 0x10100) {
161 debug("SRIOBOOT - MASTER: Port [ %d ] is error.\n",
Liu Gangd7b17a92012-08-09 05:09:59 +0000162 port);
Liu Gangf420aa92012-03-08 00:33:21 +0000163 } else {
164 debug("SRIOBOOT - MASTER: "
Liu Gangd7b17a92012-08-09 05:09:59 +0000165 "Port [ %d ] is ready, now release slave's core ...\n",
166 port);
Liu Gangf420aa92012-03-08 00:33:21 +0000167 /*
168 * configure outbound window
169 * with maintenance attribute to set slave's LCSBA1CSR
170 */
Liu Gangd7b17a92012-08-09 05:09:59 +0000171 out_be32((void *)&srio->atmu.port[port - 1]
Liu Gangf420aa92012-03-08 00:33:21 +0000172 .outbw[1].rowtar, 0);
Liu Gangd7b17a92012-08-09 05:09:59 +0000173 out_be32((void *)&srio->atmu.port[port - 1]
Liu Gangf420aa92012-03-08 00:33:21 +0000174 .outbw[1].rowtear, 0);
Liu Gangd7b17a92012-08-09 05:09:59 +0000175 if (port - 1)
176 out_be32((void *)&srio->atmu.port[port - 1]
Liu Gangf420aa92012-03-08 00:33:21 +0000177 .outbw[1].rowbar,
178 CONFIG_SYS_SRIO2_MEM_PHYS >> 12);
179 else
Liu Gangd7b17a92012-08-09 05:09:59 +0000180 out_be32((void *)&srio->atmu.port[port - 1]
Liu Gangf420aa92012-03-08 00:33:21 +0000181 .outbw[1].rowbar,
182 CONFIG_SYS_SRIO1_MEM_PHYS >> 12);
Liu Gangd7b17a92012-08-09 05:09:59 +0000183 out_be32((void *)&srio->atmu.port[port - 1]
Liu Gangf420aa92012-03-08 00:33:21 +0000184 .outbw[1].rowar,
185 SRIO_OB_ATMU_AR_MAINT
186 | atmu_size_mask(SRIO_MAINT_WIN_SIZE));
187
188 /*
189 * configure outbound window
190 * with R/W attribute to set slave's BRR
191 */
Liu Gangd7b17a92012-08-09 05:09:59 +0000192 out_be32((void *)&srio->atmu.port[port - 1]
Liu Gangf420aa92012-03-08 00:33:21 +0000193 .outbw[2].rowtar,
194 SRIO_LCSBA1CSR >> 9);
Liu Gangd7b17a92012-08-09 05:09:59 +0000195 out_be32((void *)&srio->atmu.port[port - 1]
Liu Gangf420aa92012-03-08 00:33:21 +0000196 .outbw[2].rowtear, 0);
Liu Gangd7b17a92012-08-09 05:09:59 +0000197 if (port - 1)
198 out_be32((void *)&srio->atmu.port[port - 1]
Liu Gangf420aa92012-03-08 00:33:21 +0000199 .outbw[2].rowbar,
200 (CONFIG_SYS_SRIO2_MEM_PHYS
201 + SRIO_MAINT_WIN_SIZE) >> 12);
202 else
Liu Gangd7b17a92012-08-09 05:09:59 +0000203 out_be32((void *)&srio->atmu.port[port - 1]
Liu Gangf420aa92012-03-08 00:33:21 +0000204 .outbw[2].rowbar,
205 (CONFIG_SYS_SRIO1_MEM_PHYS
206 + SRIO_MAINT_WIN_SIZE) >> 12);
Liu Gangd7b17a92012-08-09 05:09:59 +0000207 out_be32((void *)&srio->atmu.port[port - 1]
Liu Gangf420aa92012-03-08 00:33:21 +0000208 .outbw[2].rowar,
209 SRIO_OB_ATMU_AR_RW
210 | atmu_size_mask(SRIO_RW_WIN_SIZE));
211
212 /*
213 * Set the LCSBA1CSR register in slave
214 * by the maint-outbound window
215 */
Liu Gangd7b17a92012-08-09 05:09:59 +0000216 if (port - 1) {
Liu Gangf420aa92012-03-08 00:33:21 +0000217 out_be32((void *)CONFIG_SYS_SRIO2_MEM_VIRT
218 + SRIO_LCSBA1CSR_OFFSET,
219 SRIO_LCSBA1CSR);
220 while (in_be32((void *)CONFIG_SYS_SRIO2_MEM_VIRT
221 + SRIO_LCSBA1CSR_OFFSET)
222 != SRIO_LCSBA1CSR)
223 ;
224 /*
225 * And then set the BRR register
226 * to release slave core
227 */
228 out_be32((void *)CONFIG_SYS_SRIO2_MEM_VIRT
229 + SRIO_MAINT_WIN_SIZE
Liu Gang99e0c292012-08-09 05:10:02 +0000230 + CONFIG_SRIO_PCIE_BOOT_BRR_OFFSET,
231 CONFIG_SRIO_PCIE_BOOT_RELEASE_MASK);
Liu Gangf420aa92012-03-08 00:33:21 +0000232 } else {
233 out_be32((void *)CONFIG_SYS_SRIO1_MEM_VIRT
234 + SRIO_LCSBA1CSR_OFFSET,
235 SRIO_LCSBA1CSR);
236 while (in_be32((void *)CONFIG_SYS_SRIO1_MEM_VIRT
237 + SRIO_LCSBA1CSR_OFFSET)
238 != SRIO_LCSBA1CSR)
239 ;
240 /*
241 * And then set the BRR register
242 * to release slave core
243 */
244 out_be32((void *)CONFIG_SYS_SRIO1_MEM_VIRT
245 + SRIO_MAINT_WIN_SIZE
Liu Gang99e0c292012-08-09 05:10:02 +0000246 + CONFIG_SRIO_PCIE_BOOT_BRR_OFFSET,
247 CONFIG_SRIO_PCIE_BOOT_RELEASE_MASK);
Liu Gangf420aa92012-03-08 00:33:21 +0000248 }
249 debug("SRIOBOOT - MASTER: "
250 "Release slave successfully! Now the slave should start up!\n");
251 }
252 } else
Liu Gangd7b17a92012-08-09 05:09:59 +0000253 debug("SRIOBOOT - MASTER: Port [ %d ] is not ready.\n", port);
Liu Gangf420aa92012-03-08 00:33:21 +0000254}
255#endif