Daniel Hellstrom | 2a2fa79 | 2008-03-26 23:00:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Daniel Hellstrom | 2a2fa79 | 2008-03-26 23:00:38 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * AMBA Plug&Play information list command |
| 10 | * |
| 11 | */ |
| 12 | #include <common.h> |
| 13 | #include <command.h> |
| 14 | #include <ambapp.h> |
| 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
| 18 | /* We put these variables into .data section so that they are zero |
| 19 | * when entering the AMBA Plug & Play routines (in cpu/cpu/ambapp.c) |
Wolfgang Denk | 1aeed8d | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 20 | * the first time. BSS is not garantueed to be zero since BSS |
Daniel Hellstrom | 2a2fa79 | 2008-03-26 23:00:38 +0100 | [diff] [blame] | 21 | * hasn't been cleared the first times entering the CPU AMBA functions. |
| 22 | * |
| 23 | * The AMBA PnP routines call these functions if ambapp_???_print is set. |
Wolfgang Denk | 1aeed8d | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 24 | * |
Daniel Hellstrom | 2a2fa79 | 2008-03-26 23:00:38 +0100 | [diff] [blame] | 25 | */ |
| 26 | int ambapp_apb_print __attribute__ ((section(".data"))) = 0; |
| 27 | int ambapp_ahb_print __attribute__ ((section(".data"))) = 0; |
| 28 | |
| 29 | typedef struct { |
| 30 | int device_id; |
| 31 | char *name; |
| 32 | } ambapp_device_name; |
| 33 | |
| 34 | static ambapp_device_name gaisler_devices[] = { |
| 35 | {GAISLER_LEON3, "GAISLER_LEON3"}, |
| 36 | {GAISLER_LEON3DSU, "GAISLER_LEON3DSU"}, |
| 37 | {GAISLER_ETHAHB, "GAISLER_ETHAHB"}, |
| 38 | {GAISLER_ETHMAC, "GAISLER_ETHMAC"}, |
| 39 | {GAISLER_APBMST, "GAISLER_APBMST"}, |
| 40 | {GAISLER_AHBUART, "GAISLER_AHBUART"}, |
| 41 | {GAISLER_SRCTRL, "GAISLER_SRCTRL"}, |
| 42 | {GAISLER_SDCTRL, "GAISLER_SDCTRL"}, |
| 43 | {GAISLER_APBUART, "GAISLER_APBUART"}, |
| 44 | {GAISLER_IRQMP, "GAISLER_IRQMP"}, |
| 45 | {GAISLER_AHBRAM, "GAISLER_AHBRAM"}, |
| 46 | {GAISLER_GPTIMER, "GAISLER_GPTIMER"}, |
| 47 | {GAISLER_PCITRG, "GAISLER_PCITRG"}, |
| 48 | {GAISLER_PCISBRG, "GAISLER_PCISBRG"}, |
| 49 | {GAISLER_PCIFBRG, "GAISLER_PCIFBRG"}, |
| 50 | {GAISLER_PCITRACE, "GAISLER_PCITRACE"}, |
| 51 | {GAISLER_AHBTRACE, "GAISLER_AHBTRACE"}, |
| 52 | {GAISLER_ETHDSU, "GAISLER_ETHDSU"}, |
| 53 | {GAISLER_PIOPORT, "GAISLER_PIOPORT"}, |
| 54 | {GAISLER_AHBJTAG, "GAISLER_AHBJTAG"}, |
| 55 | {GAISLER_ATACTRL, "GAISLER_ATACTRL"}, |
| 56 | {GAISLER_VGA, "GAISLER_VGA"}, |
| 57 | {GAISLER_KBD, "GAISLER_KBD"}, |
| 58 | {GAISLER_L2TIME, "GAISLER_L2TIME"}, |
| 59 | {GAISLER_L2C, "GAISLER_L2C"}, |
| 60 | {GAISLER_PLUGPLAY, "GAISLER_PLUGPLAY"}, |
| 61 | {GAISLER_SPW, "GAISLER_SPW"}, |
| 62 | {GAISLER_SPW2, "GAISLER_SPW2"}, |
| 63 | {GAISLER_EHCI, "GAISLER_EHCI"}, |
| 64 | {GAISLER_UHCI, "GAISLER_UHCI"}, |
| 65 | {GAISLER_AHBSTAT, "GAISLER_AHBSTAT"}, |
| 66 | {GAISLER_DDR2SPA, "GAISLER_DDR2SPA"}, |
| 67 | {GAISLER_DDRSPA, "GAISLER_DDRSPA"}, |
| 68 | {0, NULL} |
| 69 | }; |
| 70 | |
| 71 | static ambapp_device_name esa_devices[] = { |
| 72 | {ESA_LEON2, "ESA_LEON2"}, |
| 73 | {ESA_MCTRL, "ESA_MCTRL"}, |
| 74 | {0, NULL} |
| 75 | }; |
| 76 | |
| 77 | static ambapp_device_name opencores_devices[] = { |
| 78 | {OPENCORES_PCIBR, "OPENCORES_PCIBR"}, |
| 79 | {OPENCORES_ETHMAC, "OPENCORES_ETHMAC"}, |
| 80 | {0, NULL} |
| 81 | }; |
| 82 | |
| 83 | typedef struct { |
| 84 | unsigned int vendor_id; |
| 85 | char *name; |
| 86 | ambapp_device_name *devices; |
| 87 | } ambapp_vendor_devnames; |
| 88 | |
| 89 | static ambapp_vendor_devnames vendors[] = { |
| 90 | {VENDOR_GAISLER, "VENDOR_GAISLER", gaisler_devices}, |
| 91 | {VENDOR_ESA, "VENDOR_ESA", esa_devices}, |
| 92 | {VENDOR_OPENCORES, "VENDOR_OPENCORES", opencores_devices}, |
| 93 | {0, NULL, 0} |
| 94 | }; |
| 95 | |
| 96 | static char *ambapp_get_devname(ambapp_device_name * devs, int id) |
| 97 | { |
| 98 | if (!devs) |
| 99 | return NULL; |
| 100 | |
| 101 | while (devs->device_id > 0) { |
| 102 | if (devs->device_id == id) |
| 103 | return devs->name; |
| 104 | devs++; |
| 105 | } |
| 106 | return NULL; |
| 107 | } |
| 108 | |
| 109 | char *ambapp_device_id2str(int vendor, int id) |
| 110 | { |
| 111 | ambapp_vendor_devnames *ven = &vendors[0]; |
| 112 | |
| 113 | while (ven->vendor_id > 0) { |
| 114 | if (ven->vendor_id == vendor) { |
| 115 | return ambapp_get_devname(ven->devices, id); |
| 116 | } |
| 117 | ven++; |
| 118 | } |
| 119 | return NULL; |
| 120 | } |
| 121 | |
| 122 | char *ambapp_vendor_id2str(int vendor) |
| 123 | { |
| 124 | ambapp_vendor_devnames *ven = &vendors[0]; |
| 125 | |
| 126 | while (ven->vendor_id > 0) { |
| 127 | if (ven->vendor_id == vendor) { |
| 128 | return ven->name; |
| 129 | } |
| 130 | ven++; |
| 131 | } |
| 132 | return NULL; |
| 133 | } |
| 134 | |
| 135 | static char *unknown = "unknown"; |
| 136 | |
| 137 | /* Print one APB device */ |
| 138 | void ambapp_print_apb(apbctrl_pp_dev * apb, ambapp_ahbdev * apbmst, int index) |
| 139 | { |
| 140 | char *dev_str, *ven_str; |
| 141 | int irq, ver, vendor, deviceid; |
| 142 | unsigned int address, apbmst_base, mask; |
| 143 | |
| 144 | vendor = amba_vendor(apb->conf); |
| 145 | deviceid = amba_device(apb->conf); |
| 146 | irq = amba_irq(apb->conf); |
| 147 | ver = amba_ver(apb->conf); |
| 148 | apbmst_base = apbmst->address[0] & LEON3_IO_AREA; |
| 149 | address = (apbmst_base | (((apb->bar & 0xfff00000) >> 12))) & |
| 150 | (((apb->bar & 0x0000fff0) << 4) | 0xfff00000); |
| 151 | |
| 152 | mask = amba_membar_mask(apb->bar) << 8; |
| 153 | mask = ((~mask) & 0x000fffff) + 1; |
| 154 | |
| 155 | ven_str = ambapp_vendor_id2str(vendor); |
| 156 | if (!ven_str) { |
| 157 | ven_str = unknown; |
| 158 | dev_str = unknown; |
| 159 | } else { |
| 160 | dev_str = ambapp_device_id2str(vendor, deviceid); |
| 161 | if (!dev_str) |
| 162 | dev_str = unknown; |
| 163 | } |
| 164 | |
| 165 | printf("0x%02x:0x%02x:0x%02x: %s %s\n" |
| 166 | " apb: 0x%08x - 0x%08x\n" |
| 167 | " irq: %-2d (ver: %-2d)\n", |
| 168 | index, vendor, deviceid, ven_str, dev_str, address, |
| 169 | address + mask, irq, ver); |
| 170 | } |
| 171 | |
| 172 | void ambapp_print_ahb(ahbctrl_pp_dev * ahb, int index) |
| 173 | { |
| 174 | char *dev_str, *ven_str; |
| 175 | int irq, ver, vendor, deviceid; |
| 176 | unsigned int addr, mask; |
| 177 | int j; |
| 178 | |
| 179 | vendor = amba_vendor(ahb->conf); |
| 180 | deviceid = amba_device(ahb->conf); |
| 181 | irq = amba_irq(ahb->conf); |
| 182 | ver = amba_ver(ahb->conf); |
| 183 | |
| 184 | ven_str = ambapp_vendor_id2str(vendor); |
| 185 | if (!ven_str) { |
| 186 | ven_str = unknown; |
| 187 | dev_str = unknown; |
| 188 | } else { |
| 189 | dev_str = ambapp_device_id2str(vendor, deviceid); |
| 190 | if (!dev_str) |
| 191 | dev_str = unknown; |
| 192 | } |
| 193 | |
| 194 | printf("0x%02x:0x%02x:0x%02x: %s %s\n", |
| 195 | index, vendor, deviceid, ven_str, dev_str); |
| 196 | |
| 197 | for (j = 0; j < 4; j++) { |
| 198 | addr = amba_membar_start(ahb->bars[j]); |
| 199 | if (amba_membar_type(ahb->bars[j]) == 0) |
| 200 | continue; |
| 201 | if (amba_membar_type(ahb->bars[j]) == AMBA_TYPE_AHBIO) |
| 202 | addr = AMBA_TYPE_AHBIO_ADDR(addr); |
| 203 | mask = amba_membar_mask(ahb->bars[j]) << 20; |
| 204 | printf(" mem: 0x%08x - 0x%08x\n", addr, addr + ((~mask) + 1)); |
| 205 | } |
| 206 | |
| 207 | printf(" irq: %-2d (ver: %d)\n", irq, ver); |
| 208 | } |
| 209 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 210 | int do_ambapp_print(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
Daniel Hellstrom | 2a2fa79 | 2008-03-26 23:00:38 +0100 | [diff] [blame] | 211 | { |
| 212 | |
| 213 | /* Print AHB Masters */ |
| 214 | puts("--------- AHB Masters ---------\n"); |
| 215 | ambapp_apb_print = 0; |
| 216 | ambapp_ahb_print = 1; |
| 217 | ambapp_ahbmst_count(99, 99); /* Get vendor&device 99 = nonexistent... */ |
| 218 | |
| 219 | /* Print AHB Slaves */ |
| 220 | puts("--------- AHB Slaves ---------\n"); |
| 221 | ambapp_ahbslv_count(99, 99); /* Get vendor&device 99 = nonexistent... */ |
| 222 | |
| 223 | /* Print APB Slaves */ |
| 224 | puts("--------- APB Slaves ---------\n"); |
| 225 | ambapp_apb_print = 1; |
| 226 | ambapp_ahb_print = 0; |
| 227 | ambapp_apb_count(99, 99); /* Get vendor&device 99 = nonexistent... */ |
| 228 | |
| 229 | /* Reset, no futher printing */ |
| 230 | ambapp_apb_print = 0; |
| 231 | ambapp_ahb_print = 0; |
| 232 | puts("\n"); |
| 233 | return 0; |
| 234 | } |
| 235 | |
| 236 | int ambapp_init_reloc(void) |
| 237 | { |
| 238 | ambapp_vendor_devnames *vend = vendors; |
| 239 | ambapp_device_name *dev; |
| 240 | |
| 241 | while (vend->vendor_id && vend->name) { |
| 242 | vend->name = (char *)((unsigned int)vend->name + gd->reloc_off); |
| 243 | vend->devices = |
| 244 | (ambapp_device_name *) ((unsigned int)vend->devices + |
| 245 | gd->reloc_off);; |
| 246 | dev = vend->devices; |
| 247 | vend++; |
| 248 | if (!dev) |
| 249 | continue; |
| 250 | while (dev->device_id && dev->name) { |
| 251 | dev->name = |
| 252 | (char *)((unsigned int)dev->name + gd->reloc_off);; |
| 253 | dev++; |
| 254 | } |
| 255 | } |
| 256 | return 0; |
| 257 | } |
| 258 | |
Frans Meulenbroeks | 388a29d | 2010-07-31 15:01:53 +0200 | [diff] [blame] | 259 | U_BOOT_CMD( |
| 260 | ambapp, 1, 1, do_ambapp_print, |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 261 | "list AMBA Plug&Play information", |
| 262 | "ambapp\n" |
| 263 | " - lists AMBA (AHB & APB) Plug&Play devices present on the system" |
| 264 | ); |