blob: fa7d7e280fb8acd386f376a6a61e4b13a69bf6a6 [file] [log] [blame]
Daniel Hellstromfeb0c262008-03-26 23:00:38 +01001/*
2 * (C) Copyright 2007
3 * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24/*
25 * AMBA Plug&Play information list command
26 *
27 */
28#include <common.h>
29#include <command.h>
30#include <ambapp.h>
31
32DECLARE_GLOBAL_DATA_PTR;
33
34/* We put these variables into .data section so that they are zero
35 * when entering the AMBA Plug & Play routines (in cpu/cpu/ambapp.c)
Wolfgang Denk35f734f2008-04-13 09:59:26 -070036 * the first time. BSS is not garantueed to be zero since BSS
Daniel Hellstromfeb0c262008-03-26 23:00:38 +010037 * hasn't been cleared the first times entering the CPU AMBA functions.
38 *
39 * The AMBA PnP routines call these functions if ambapp_???_print is set.
Wolfgang Denk35f734f2008-04-13 09:59:26 -070040 *
Daniel Hellstromfeb0c262008-03-26 23:00:38 +010041 */
42int ambapp_apb_print __attribute__ ((section(".data"))) = 0;
43int ambapp_ahb_print __attribute__ ((section(".data"))) = 0;
44
45typedef struct {
46 int device_id;
47 char *name;
48} ambapp_device_name;
49
50static ambapp_device_name gaisler_devices[] = {
51 {GAISLER_LEON3, "GAISLER_LEON3"},
52 {GAISLER_LEON3DSU, "GAISLER_LEON3DSU"},
53 {GAISLER_ETHAHB, "GAISLER_ETHAHB"},
54 {GAISLER_ETHMAC, "GAISLER_ETHMAC"},
55 {GAISLER_APBMST, "GAISLER_APBMST"},
56 {GAISLER_AHBUART, "GAISLER_AHBUART"},
57 {GAISLER_SRCTRL, "GAISLER_SRCTRL"},
58 {GAISLER_SDCTRL, "GAISLER_SDCTRL"},
59 {GAISLER_APBUART, "GAISLER_APBUART"},
60 {GAISLER_IRQMP, "GAISLER_IRQMP"},
61 {GAISLER_AHBRAM, "GAISLER_AHBRAM"},
62 {GAISLER_GPTIMER, "GAISLER_GPTIMER"},
63 {GAISLER_PCITRG, "GAISLER_PCITRG"},
64 {GAISLER_PCISBRG, "GAISLER_PCISBRG"},
65 {GAISLER_PCIFBRG, "GAISLER_PCIFBRG"},
66 {GAISLER_PCITRACE, "GAISLER_PCITRACE"},
67 {GAISLER_AHBTRACE, "GAISLER_AHBTRACE"},
68 {GAISLER_ETHDSU, "GAISLER_ETHDSU"},
69 {GAISLER_PIOPORT, "GAISLER_PIOPORT"},
70 {GAISLER_AHBJTAG, "GAISLER_AHBJTAG"},
71 {GAISLER_ATACTRL, "GAISLER_ATACTRL"},
72 {GAISLER_VGA, "GAISLER_VGA"},
73 {GAISLER_KBD, "GAISLER_KBD"},
74 {GAISLER_L2TIME, "GAISLER_L2TIME"},
75 {GAISLER_L2C, "GAISLER_L2C"},
76 {GAISLER_PLUGPLAY, "GAISLER_PLUGPLAY"},
77 {GAISLER_SPW, "GAISLER_SPW"},
78 {GAISLER_SPW2, "GAISLER_SPW2"},
79 {GAISLER_EHCI, "GAISLER_EHCI"},
80 {GAISLER_UHCI, "GAISLER_UHCI"},
81 {GAISLER_AHBSTAT, "GAISLER_AHBSTAT"},
82 {GAISLER_DDR2SPA, "GAISLER_DDR2SPA"},
83 {GAISLER_DDRSPA, "GAISLER_DDRSPA"},
84 {0, NULL}
85};
86
87static ambapp_device_name esa_devices[] = {
88 {ESA_LEON2, "ESA_LEON2"},
89 {ESA_MCTRL, "ESA_MCTRL"},
90 {0, NULL}
91};
92
93static ambapp_device_name opencores_devices[] = {
94 {OPENCORES_PCIBR, "OPENCORES_PCIBR"},
95 {OPENCORES_ETHMAC, "OPENCORES_ETHMAC"},
96 {0, NULL}
97};
98
99typedef struct {
100 unsigned int vendor_id;
101 char *name;
102 ambapp_device_name *devices;
103} ambapp_vendor_devnames;
104
105static ambapp_vendor_devnames vendors[] = {
106 {VENDOR_GAISLER, "VENDOR_GAISLER", gaisler_devices},
107 {VENDOR_ESA, "VENDOR_ESA", esa_devices},
108 {VENDOR_OPENCORES, "VENDOR_OPENCORES", opencores_devices},
109 {0, NULL, 0}
110};
111
112static char *ambapp_get_devname(ambapp_device_name * devs, int id)
113{
114 if (!devs)
115 return NULL;
116
117 while (devs->device_id > 0) {
118 if (devs->device_id == id)
119 return devs->name;
120 devs++;
121 }
122 return NULL;
123}
124
125char *ambapp_device_id2str(int vendor, int id)
126{
127 ambapp_vendor_devnames *ven = &vendors[0];
128
129 while (ven->vendor_id > 0) {
130 if (ven->vendor_id == vendor) {
131 return ambapp_get_devname(ven->devices, id);
132 }
133 ven++;
134 }
135 return NULL;
136}
137
138char *ambapp_vendor_id2str(int vendor)
139{
140 ambapp_vendor_devnames *ven = &vendors[0];
141
142 while (ven->vendor_id > 0) {
143 if (ven->vendor_id == vendor) {
144 return ven->name;
145 }
146 ven++;
147 }
148 return NULL;
149}
150
151static char *unknown = "unknown";
152
153/* Print one APB device */
154void ambapp_print_apb(apbctrl_pp_dev * apb, ambapp_ahbdev * apbmst, int index)
155{
156 char *dev_str, *ven_str;
157 int irq, ver, vendor, deviceid;
158 unsigned int address, apbmst_base, mask;
159
160 vendor = amba_vendor(apb->conf);
161 deviceid = amba_device(apb->conf);
162 irq = amba_irq(apb->conf);
163 ver = amba_ver(apb->conf);
164 apbmst_base = apbmst->address[0] & LEON3_IO_AREA;
165 address = (apbmst_base | (((apb->bar & 0xfff00000) >> 12))) &
166 (((apb->bar & 0x0000fff0) << 4) | 0xfff00000);
167
168 mask = amba_membar_mask(apb->bar) << 8;
169 mask = ((~mask) & 0x000fffff) + 1;
170
171 ven_str = ambapp_vendor_id2str(vendor);
172 if (!ven_str) {
173 ven_str = unknown;
174 dev_str = unknown;
175 } else {
176 dev_str = ambapp_device_id2str(vendor, deviceid);
177 if (!dev_str)
178 dev_str = unknown;
179 }
180
181 printf("0x%02x:0x%02x:0x%02x: %s %s\n"
182 " apb: 0x%08x - 0x%08x\n"
183 " irq: %-2d (ver: %-2d)\n",
184 index, vendor, deviceid, ven_str, dev_str, address,
185 address + mask, irq, ver);
186}
187
188void ambapp_print_ahb(ahbctrl_pp_dev * ahb, int index)
189{
190 char *dev_str, *ven_str;
191 int irq, ver, vendor, deviceid;
192 unsigned int addr, mask;
193 int j;
194
195 vendor = amba_vendor(ahb->conf);
196 deviceid = amba_device(ahb->conf);
197 irq = amba_irq(ahb->conf);
198 ver = amba_ver(ahb->conf);
199
200 ven_str = ambapp_vendor_id2str(vendor);
201 if (!ven_str) {
202 ven_str = unknown;
203 dev_str = unknown;
204 } else {
205 dev_str = ambapp_device_id2str(vendor, deviceid);
206 if (!dev_str)
207 dev_str = unknown;
208 }
209
210 printf("0x%02x:0x%02x:0x%02x: %s %s\n",
211 index, vendor, deviceid, ven_str, dev_str);
212
213 for (j = 0; j < 4; j++) {
214 addr = amba_membar_start(ahb->bars[j]);
215 if (amba_membar_type(ahb->bars[j]) == 0)
216 continue;
217 if (amba_membar_type(ahb->bars[j]) == AMBA_TYPE_AHBIO)
218 addr = AMBA_TYPE_AHBIO_ADDR(addr);
219 mask = amba_membar_mask(ahb->bars[j]) << 20;
220 printf(" mem: 0x%08x - 0x%08x\n", addr, addr + ((~mask) + 1));
221 }
222
223 printf(" irq: %-2d (ver: %d)\n", irq, ver);
224}
225
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200226int do_ambapp_print(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
Daniel Hellstromfeb0c262008-03-26 23:00:38 +0100227{
228
229 /* Print AHB Masters */
230 puts("--------- AHB Masters ---------\n");
231 ambapp_apb_print = 0;
232 ambapp_ahb_print = 1;
233 ambapp_ahbmst_count(99, 99); /* Get vendor&device 99 = nonexistent... */
234
235 /* Print AHB Slaves */
236 puts("--------- AHB Slaves ---------\n");
237 ambapp_ahbslv_count(99, 99); /* Get vendor&device 99 = nonexistent... */
238
239 /* Print APB Slaves */
240 puts("--------- APB Slaves ---------\n");
241 ambapp_apb_print = 1;
242 ambapp_ahb_print = 0;
243 ambapp_apb_count(99, 99); /* Get vendor&device 99 = nonexistent... */
244
245 /* Reset, no futher printing */
246 ambapp_apb_print = 0;
247 ambapp_ahb_print = 0;
248 puts("\n");
249 return 0;
250}
251
252int ambapp_init_reloc(void)
253{
254 ambapp_vendor_devnames *vend = vendors;
255 ambapp_device_name *dev;
256
257 while (vend->vendor_id && vend->name) {
258 vend->name = (char *)((unsigned int)vend->name + gd->reloc_off);
259 vend->devices =
260 (ambapp_device_name *) ((unsigned int)vend->devices +
261 gd->reloc_off);;
262 dev = vend->devices;
263 vend++;
264 if (!dev)
265 continue;
266 while (dev->device_id && dev->name) {
267 dev->name =
268 (char *)((unsigned int)dev->name + gd->reloc_off);;
269 dev++;
270 }
271 }
272 return 0;
273}
274
Frans Meulenbroeks7675a092010-07-31 15:01:53 +0200275U_BOOT_CMD(
276 ambapp, 1, 1, do_ambapp_print,
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200277 "list AMBA Plug&Play information",
278 "ambapp\n"
279 " - lists AMBA (AHB & APB) Plug&Play devices present on the system"
280);