3 * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
25 * AMBA Plug&Play information list command
32 DECLARE_GLOBAL_DATA_PTR;
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)
36 * the first time. BSS is not garantueed to be zero since BSS
37 * hasn't been cleared the first times entering the CPU AMBA functions.
39 * The AMBA PnP routines call these functions if ambapp_???_print is set.
42 int ambapp_apb_print __attribute__ ((section(".data"))) = 0;
43 int ambapp_ahb_print __attribute__ ((section(".data"))) = 0;
50 static 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"},
87 static ambapp_device_name esa_devices[] = {
88 {ESA_LEON2, "ESA_LEON2"},
89 {ESA_MCTRL, "ESA_MCTRL"},
93 static ambapp_device_name opencores_devices[] = {
94 {OPENCORES_PCIBR, "OPENCORES_PCIBR"},
95 {OPENCORES_ETHMAC, "OPENCORES_ETHMAC"},
100 unsigned int vendor_id;
102 ambapp_device_name *devices;
103 } ambapp_vendor_devnames;
105 static 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},
112 static char *ambapp_get_devname(ambapp_device_name * devs, int id)
117 while (devs->device_id > 0) {
118 if (devs->device_id == id)
125 char *ambapp_device_id2str(int vendor, int id)
127 ambapp_vendor_devnames *ven = &vendors[0];
129 while (ven->vendor_id > 0) {
130 if (ven->vendor_id == vendor) {
131 return ambapp_get_devname(ven->devices, id);
138 char *ambapp_vendor_id2str(int vendor)
140 ambapp_vendor_devnames *ven = &vendors[0];
142 while (ven->vendor_id > 0) {
143 if (ven->vendor_id == vendor) {
151 static char *unknown = "unknown";
153 /* Print one APB device */
154 void ambapp_print_apb(apbctrl_pp_dev * apb, ambapp_ahbdev * apbmst, int index)
156 char *dev_str, *ven_str;
157 int irq, ver, vendor, deviceid;
158 unsigned int address, apbmst_base, mask;
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);
168 mask = amba_membar_mask(apb->bar) << 8;
169 mask = ((~mask) & 0x000fffff) + 1;
171 ven_str = ambapp_vendor_id2str(vendor);
176 dev_str = ambapp_device_id2str(vendor, deviceid);
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);
188 void ambapp_print_ahb(ahbctrl_pp_dev * ahb, int index)
190 char *dev_str, *ven_str;
191 int irq, ver, vendor, deviceid;
192 unsigned int addr, mask;
195 vendor = amba_vendor(ahb->conf);
196 deviceid = amba_device(ahb->conf);
197 irq = amba_irq(ahb->conf);
198 ver = amba_ver(ahb->conf);
200 ven_str = ambapp_vendor_id2str(vendor);
205 dev_str = ambapp_device_id2str(vendor, deviceid);
210 printf("0x%02x:0x%02x:0x%02x: %s %s\n",
211 index, vendor, deviceid, ven_str, dev_str);
213 for (j = 0; j < 4; j++) {
214 addr = amba_membar_start(ahb->bars[j]);
215 if (amba_membar_type(ahb->bars[j]) == 0)
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));
223 printf(" irq: %-2d (ver: %d)\n", irq, ver);
226 int do_ambapp_print(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
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... */
235 /* Print AHB Slaves */
236 puts("--------- AHB Slaves ---------\n");
237 ambapp_ahbslv_count(99, 99); /* Get vendor&device 99 = nonexistent... */
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... */
245 /* Reset, no futher printing */
246 ambapp_apb_print = 0;
247 ambapp_ahb_print = 0;
252 int ambapp_init_reloc(void)
254 ambapp_vendor_devnames *vend = vendors;
255 ambapp_device_name *dev;
257 while (vend->vendor_id && vend->name) {
258 vend->name = (char *)((unsigned int)vend->name + gd->reloc_off);
260 (ambapp_device_name *) ((unsigned int)vend->devices +
266 while (dev->device_id && dev->name) {
268 (char *)((unsigned int)dev->name + gd->reloc_off);;
275 U_BOOT_CMD(ambapp, 1, 1, do_ambapp_print,
276 "list AMBA Plug&Play information",
278 " - lists AMBA (AHB & APB) Plug&Play devices present on the system"