3 * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com.
5 * SPDX-License-Identifier: GPL-2.0+
9 * AMBA Plug&Play information list command
16 DECLARE_GLOBAL_DATA_PTR
;
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)
20 * the first time. BSS is not garantueed to be zero since BSS
21 * hasn't been cleared the first times entering the CPU AMBA functions.
23 * The AMBA PnP routines call these functions if ambapp_???_print is set.
26 int ambapp_apb_print
__attribute__ ((section(".data"))) = 0;
27 int ambapp_ahb_print
__attribute__ ((section(".data"))) = 0;
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"},
71 static ambapp_device_name esa_devices
[] = {
72 {ESA_LEON2
, "ESA_LEON2"},
73 {ESA_MCTRL
, "ESA_MCTRL"},
77 static ambapp_device_name opencores_devices
[] = {
78 {OPENCORES_PCIBR
, "OPENCORES_PCIBR"},
79 {OPENCORES_ETHMAC
, "OPENCORES_ETHMAC"},
84 unsigned int vendor_id
;
86 ambapp_device_name
*devices
;
87 } ambapp_vendor_devnames
;
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
},
96 static char *ambapp_get_devname(ambapp_device_name
* devs
, int id
)
101 while (devs
->device_id
> 0) {
102 if (devs
->device_id
== id
)
109 char *ambapp_device_id2str(int vendor
, int id
)
111 ambapp_vendor_devnames
*ven
= &vendors
[0];
113 while (ven
->vendor_id
> 0) {
114 if (ven
->vendor_id
== vendor
) {
115 return ambapp_get_devname(ven
->devices
, id
);
122 char *ambapp_vendor_id2str(int vendor
)
124 ambapp_vendor_devnames
*ven
= &vendors
[0];
126 while (ven
->vendor_id
> 0) {
127 if (ven
->vendor_id
== vendor
) {
135 static char *unknown
= "unknown";
137 /* Print one APB device */
138 void ambapp_print_apb(apbctrl_pp_dev
* apb
, ambapp_ahbdev
* apbmst
, int index
)
140 char *dev_str
, *ven_str
;
141 int irq
, ver
, vendor
, deviceid
;
142 unsigned int address
, apbmst_base
, mask
;
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);
152 mask
= amba_membar_mask(apb
->bar
) << 8;
153 mask
= ((~mask
) & 0x000fffff) + 1;
155 ven_str
= ambapp_vendor_id2str(vendor
);
160 dev_str
= ambapp_device_id2str(vendor
, deviceid
);
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
);
172 void ambapp_print_ahb(ahbctrl_pp_dev
* ahb
, int index
)
174 char *dev_str
, *ven_str
;
175 int irq
, ver
, vendor
, deviceid
;
176 unsigned int addr
, mask
;
179 vendor
= amba_vendor(ahb
->conf
);
180 deviceid
= amba_device(ahb
->conf
);
181 irq
= amba_irq(ahb
->conf
);
182 ver
= amba_ver(ahb
->conf
);
184 ven_str
= ambapp_vendor_id2str(vendor
);
189 dev_str
= ambapp_device_id2str(vendor
, deviceid
);
194 printf("0x%02x:0x%02x:0x%02x: %s %s\n",
195 index
, vendor
, deviceid
, ven_str
, dev_str
);
197 for (j
= 0; j
< 4; j
++) {
198 addr
= amba_membar_start(ahb
->bars
[j
]);
199 if (amba_membar_type(ahb
->bars
[j
]) == 0)
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));
207 printf(" irq: %-2d (ver: %d)\n", irq
, ver
);
210 int do_ambapp_print(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
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... */
219 /* Print AHB Slaves */
220 puts("--------- AHB Slaves ---------\n");
221 ambapp_ahbslv_count(99, 99); /* Get vendor&device 99 = nonexistent... */
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... */
229 /* Reset, no futher printing */
230 ambapp_apb_print
= 0;
231 ambapp_ahb_print
= 0;
236 int ambapp_init_reloc(void)
238 ambapp_vendor_devnames
*vend
= vendors
;
239 ambapp_device_name
*dev
;
241 while (vend
->vendor_id
&& vend
->name
) {
242 vend
->name
= (char *)((unsigned int)vend
->name
+ gd
->reloc_off
);
244 (ambapp_device_name
*) ((unsigned int)vend
->devices
+
250 while (dev
->device_id
&& dev
->name
) {
252 (char *)((unsigned int)dev
->name
+ gd
->reloc_off
);;
260 ambapp
, 1, 1, do_ambapp_print
,
261 "list AMBA Plug&Play information",
263 " - lists AMBA (AHB & APB) Plug&Play devices present on the system"