efi_loader: Expose ascending efi memory map
[platform/kernel/u-boot.git] / cmd / ambapp.c
1 /*
2  * (C) Copyright 2007
3  * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com.
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
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 typedef struct {
19         int device_id;
20         char *name;
21         char *desc;
22 } ambapp_device_name;
23
24 typedef struct {
25         unsigned int vendor_id;
26         char *name;
27         char *desc;
28         ambapp_device_name *devices;
29 } ambapp_vendor_devnames;
30
31 /** Vendor GAISLER devices */
32 static ambapp_device_name GAISLER_devices[] = {
33         {GAISLER_LEON2DSU, "LEON2DSU", "Leon2 Debug Support Unit"},
34         {GAISLER_LEON3, "LEON3", "Leon3 SPARC V8 Processor"},
35         {GAISLER_LEON3DSU, "LEON3DSU", "Leon3 Debug Support Unit"},
36         {GAISLER_ETHAHB, "ETHAHB", "OC ethernet AHB interface"},
37         {GAISLER_APBMST, "APBMST", "AHB/APB Bridge"},
38         {GAISLER_AHBUART, "AHBUART", "AHB Debug UART"},
39         {GAISLER_SRCTRL, "SRCTRL", "Simple SRAM Controller"},
40         {GAISLER_SDCTRL, "SDCTRL", "PC133 SDRAM Controller"},
41         {GAISLER_SSRCTRL, "SSRCTRL", "Synchronous SRAM Controller"},
42         {GAISLER_APBUART, "APBUART", "Generic UART"},
43         {GAISLER_IRQMP, "IRQMP", "Multi-processor Interrupt Ctrl."},
44         {GAISLER_AHBRAM, "AHBRAM", "Single-port AHB SRAM module"},
45         {GAISLER_AHBDPRAM, "AHBDPRAM", "Dual-port AHB SRAM module"},
46         {GAISLER_GPTIMER, "GPTIMER", "Modular Timer Unit"},
47         {GAISLER_PCITRG, "PCITRG", "Simple 32-bit PCI Target"},
48         {GAISLER_PCISBRG, "PCISBRG", "Simple 32-bit PCI Bridge"},
49         {GAISLER_PCIFBRG, "PCIFBRG", "Fast 32-bit PCI Bridge"},
50         {GAISLER_PCITRACE, "PCITRACE", "32-bit PCI Trace Buffer"},
51         {GAISLER_DMACTRL, "DMACTRL", "AMBA DMA controller"},
52         {GAISLER_AHBTRACE, "AHBTRACE", "AMBA Trace Buffer"},
53         {GAISLER_DSUCTRL, "DSUCTRL", "DSU/ETH controller"},
54         {GAISLER_CANAHB, "CANAHB", "OC CAN AHB interface"},
55         {GAISLER_GPIO, "GPIO", "General Purpose I/O port"},
56         {GAISLER_AHBROM, "AHBROM", "Generic AHB ROM"},
57         {GAISLER_AHBJTAG, "AHBJTAG", "JTAG Debug Link"},
58         {GAISLER_ETHMAC, "ETHMAC", "GR Ethernet MAC"},
59         {GAISLER_SWNODE, "SWNODE", "SpaceWire Node Interface"},
60         {GAISLER_SPW, "SPW", "SpaceWire Serial Link"},
61         {GAISLER_AHB2AHB, "AHB2AHB", "AHB-to-AHB Bridge"},
62         {GAISLER_USBDC, "USBDC", "GR USB 2.0 Device Controller"},
63         {GAISLER_USB_DCL, "USB_DCL", "USB Debug Communication Link"},
64         {GAISLER_DDRMP, "DDRMP", "Multi-port DDR controller"},
65         {GAISLER_ATACTRL, "ATACTRL", "ATA controller"},
66         {GAISLER_DDRSP, "DDRSP", "Single-port DDR266 controller"},
67         {GAISLER_EHCI, "EHCI", "USB Enhanced Host Controller"},
68         {GAISLER_UHCI, "UHCI", "USB Universal Host Controller"},
69         {GAISLER_I2CMST, "I2CMST", "AMBA Wrapper for OC I2C-master"},
70         {GAISLER_SPW2, "SPW2", "GRSPW2 SpaceWire Serial Link"},
71         {GAISLER_AHBDMA, "AHBDMA", ""},
72         {GAISLER_NUHOSP3, "NUHOSP3", "Nuhorizons Spartan3 IO I/F"},
73         {GAISLER_CLKGATE, "CLKGATE", "Clock gating unit"},
74         {GAISLER_SPICTRL, "SPICTRL", "SPI Controller"},
75         {GAISLER_DDR2SP, "DDR2SP", "Single-port DDR2 controller"},
76         {GAISLER_SLINK, "SLINK", "SLINK Master"},
77         {GAISLER_GRTM, "GRTM", "CCSDS Telemetry Encoder"},
78         {GAISLER_GRTC, "GRTC", "CCSDS Telecommand Decoder"},
79         {GAISLER_GRPW, "GRPW", "PacketWire to AMBA AHB I/F"},
80         {GAISLER_GRCTM, "GRCTM", "CCSDS Time Manager"},
81         {GAISLER_GRHCAN, "GRHCAN", "ESA HurriCANe CAN with DMA"},
82         {GAISLER_GRFIFO, "GRFIFO", "FIFO Controller"},
83         {GAISLER_GRADCDAC, "GRADCDAC", "ADC / DAC Interface"},
84         {GAISLER_GRPULSE, "GRPULSE", "General Purpose I/O with Pulses"},
85         {GAISLER_GRTIMER, "GRTIMER", "Timer Unit with Latches"},
86         {GAISLER_AHB2PP, "AHB2PP", "AMBA AHB to Packet Parallel I/F"},
87         {GAISLER_GRVERSION, "GRVERSION", "Version and Revision Register"},
88         {GAISLER_APB2PW, "APB2PW", "PacketWire Transmit Interface"},
89         {GAISLER_PW2APB, "PW2APB", "PacketWire Receive Interface"},
90         {GAISLER_GRCAN, "GRCAN", "CAN Controller with DMA"},
91         {GAISLER_I2CSLV, "I2CSLV", "I2C Slave"},
92         {GAISLER_U16550, "U16550", "Simple 16550 UART"},
93         {GAISLER_AHBMST_EM, "AHBMST_EM", "AMBA Master Emulator"},
94         {GAISLER_AHBSLV_EM, "AHBSLV_EM", "AMBA Slave Emulator"},
95         {GAISLER_GRTESTMOD, "GRTESTMOD", "Test report module"},
96         {GAISLER_ASCS, "ASCS", "ASCS Master"},
97         {GAISLER_IPMVBCTRL, "IPMVBCTRL", "IPM-bus/MVBC memory controller"},
98         {GAISLER_SPIMCTRL, "SPIMCTRL", "SPI Memory Controller"},
99         {GAISLER_L4STAT, "L4STAT", "Leon4 Statistics Module"},
100         {GAISLER_LEON4, "LEON4", "Leon4 SPARC V8 Processor"},
101         {GAISLER_LEON4DSU, "LEON4DSU", "Leon4 Debug Support Unit"},
102         {GAISLER_PWM, "PWM", "PWM generator"},
103         {GAISLER_L2CACHE, "L2CACHE", "L2-Cache Controller"},
104         {GAISLER_SDCTRL64, "SDCTRL64", "64-bit PC133 SDRAM Controller"},
105         {GAISLER_GR1553B, "GR1553B", "MIL-STD-1553B Interface"},
106         {GAISLER_1553TST, "1553TST", "MIL-STD-1553B Test Device"},
107         {GAISLER_GRIOMMU, "GRIOMMU", "I/O Memory Management Unit"},
108         {GAISLER_FTAHBRAM, "FTAHBRAM", "Generic FT AHB SRAM module"},
109         {GAISLER_FTSRCTRL, "FTSRCTRL", "Simple FT SRAM Controller"},
110         {GAISLER_AHBSTAT, "AHBSTAT", "AHB Status Register"},
111         {GAISLER_LEON3FT, "LEON3FT", "Leon3-FT SPARC V8 Processor"},
112         {GAISLER_FTMCTRL, "FTMCTRL", "Memory controller with EDAC"},
113         {GAISLER_FTSDCTRL, "FTSDCTRL", "FT PC133 SDRAM Controller"},
114         {GAISLER_FTSRCTRL8, "FTSRCTRL8", "FT 8-bit SRAM/16-bit IO Ctrl"},
115         {GAISLER_MEMSCRUB, "MEMSCRUB", "AHB Memory Scrubber"},
116         {GAISLER_FTSDCTRL64, "FTSDCTRL64", "64-bit FT SDRAM Controller"},
117         {GAISLER_APBPS2, "APBPS2", "PS2 interface"},
118         {GAISLER_VGACTRL, "VGACTRL", "VGA controller"},
119         {GAISLER_LOGAN, "LOGAN", "On chip Logic Analyzer"},
120         {GAISLER_SVGACTRL, "SVGACTRL", "SVGA frame buffer"},
121         {GAISLER_T1AHB, "T1AHB", "Niagara T1 PCX/AHB bridge"},
122         {GAISLER_MP7WRAP, "MP7WRAP", "CoreMP7 wrapper"},
123         {GAISLER_GRSYSMON, "GRSYSMON", "AMBA wrapper for System Monitor"},
124         {GAISLER_GRACECTRL, "GRACECTRL", "System ACE I/F Controller"},
125         {GAISLER_ATAHBSLV, "ATAHBSLV", "AMBA Test Framework AHB Slave"},
126         {GAISLER_ATAHBMST, "ATAHBMST", "AMBA Test Framework AHB Master"},
127         {GAISLER_ATAPBSLV, "ATAPBSLV", "AMBA Test Framework APB Slave"},
128         {GAISLER_B1553BC, "B1553BC", "AMBA Wrapper for Core1553BBC"},
129         {GAISLER_B1553RT, "B1553RT", "AMBA Wrapper for Core1553BRT"},
130         {GAISLER_B1553BRM, "B1553BRM", "AMBA Wrapper for Core1553BRM"},
131         {GAISLER_AES, "AES", "Advanced Encryption Standard"},
132         {GAISLER_ECC, "ECC", "Elliptic Curve Cryptography"},
133         {GAISLER_PCIF, "PCIF", "AMBA Wrapper for CorePCIF"},
134         {GAISLER_CLKMOD, "CLKMOD", "CPU Clock Switching Ctrl module"},
135         {GAISLER_HAPSTRAK, "HAPSTRAK", "HAPS HapsTrak I/O Port"},
136         {GAISLER_TEST_1X2, "TEST_1X2", "HAPS TEST_1x2 interface"},
137         {GAISLER_WILD2AHB, "WILD2AHB", "WildCard CardBus interface"},
138         {GAISLER_BIO1, "BIO1", "Basic I/O board BIO1"},
139         {GAISLER_AESDMA, "AESDMA", "AES 256 DMA"},
140         {GAISLER_SATCAN, "SATCAN", "SatCAN controller"},
141         {GAISLER_CANMUX, "CANMUX", "CAN Bus multiplexer"},
142         {GAISLER_GRTMRX, "GRTMRX", "CCSDS Telemetry Receiver"},
143         {GAISLER_GRTCTX, "GRTCTX", "CCSDS Telecommand Transmitter"},
144         {GAISLER_GRTMDESC, "GRTMDESC", "CCSDS Telemetry Descriptor"},
145         {GAISLER_GRTMVC, "GRTMVC", "CCSDS Telemetry VC Generator"},
146         {GAISLER_GEFFE, "GEFFE", "Geffe Generator"},
147         {GAISLER_GPREG, "GPREG", "General Purpose Register"},
148         {GAISLER_GRTMPAHB, "GRTMPAHB", "CCSDS Telemetry VC AHB Input"},
149         {GAISLER_SPWCUC, "SPWCUC", "CCSDS CUC / SpaceWire I/F"},
150         {GAISLER_SPW2_DMA, "SPW2_DMA", "GRSPW Router DMA interface"},
151         {GAISLER_SPWROUTER, "SPWROUTER", "GRSPW Router"},
152         {0, NULL, NULL}
153 };
154
155
156 /** Vendor PENDER devices */
157 static ambapp_device_name PENDER_devices[] = {
158         {0, NULL, NULL}
159 };
160
161
162 /** Vendor ESA devices */
163 static ambapp_device_name ESA_devices[] = {
164         {ESA_LEON2, "LEON2", "Leon2 SPARC V8 Processor"},
165         {ESA_LEON2APB, "LEON2APB", "Leon2 Peripheral Bus"},
166         {ESA_IRQ, "IRQ", "Leon2 Interrupt Controller"},
167         {ESA_TIMER, "TIMER", "Leon2 Timer"},
168         {ESA_UART, "UART", "Leon2 UART"},
169         {ESA_CFG, "CFG", "Leon2 Configuration Register"},
170         {ESA_IO, "IO", "Leon2 Input/Output"},
171         {ESA_MCTRL, "MCTRL", "Leon2 Memory Controller"},
172         {ESA_PCIARB, "PCIARB", "PCI Arbiter"},
173         {ESA_HURRICANE, "HURRICANE", "HurriCANe/HurryAMBA CAN Ctrl"},
174         {ESA_SPW_RMAP, "SPW_RMAP", "UoD/Saab SpaceWire/RMAP link"},
175         {ESA_AHBUART, "AHBUART", "Leon2 AHB Debug UART"},
176         {ESA_SPWA, "SPWA", "ESA/ASTRIUM SpaceWire link"},
177         {ESA_BOSCHCAN, "BOSCHCAN", "SSC/BOSCH CAN Ctrl"},
178         {ESA_IRQ2, "IRQ2", "Leon2 Secondary Irq Controller"},
179         {ESA_AHBSTAT, "AHBSTAT", "Leon2 AHB Status Register"},
180         {ESA_WPROT, "WPROT", "Leon2 Write Protection"},
181         {ESA_WPROT2, "WPROT2", "Leon2 Extended Write Protection"},
182         {ESA_PDEC3AMBA, "PDEC3AMBA", "ESA CCSDS PDEC3AMBA TC Decoder"},
183         {ESA_PTME3AMBA, "PTME3AMBA", "ESA CCSDS PTME3AMBA TM Encoder"},
184         {0, NULL, NULL}
185 };
186
187
188 /** Vendor ASTRIUM devices */
189 static ambapp_device_name ASTRIUM_devices[] = {
190         {0, NULL, NULL}
191 };
192
193
194 /** Vendor OPENCHIP devices */
195 static ambapp_device_name OPENCHIP_devices[] = {
196         {OPENCHIP_APBGPIO, "APBGPIO", "APB General Purpose IO"},
197         {OPENCHIP_APBI2C, "APBI2C", "APB I2C Interface"},
198         {OPENCHIP_APBSPI, "APBSPI", "APB SPI Interface"},
199         {OPENCHIP_APBCHARLCD, "APBCHARLCD", "APB Character LCD"},
200         {OPENCHIP_APBPWM, "APBPWM", "APB PWM"},
201         {OPENCHIP_APBPS2, "APBPS2", "APB PS/2 Interface"},
202         {OPENCHIP_APBMMCSD, "APBMMCSD", "APB MMC/SD Card Interface"},
203         {OPENCHIP_APBNAND, "APBNAND", "APB NAND(SmartMedia) Interface"},
204         {OPENCHIP_APBLPC, "APBLPC", "APB LPC Interface"},
205         {OPENCHIP_APBCF, "APBCF", "APB CompactFlash (IDE)"},
206         {OPENCHIP_APBSYSACE, "APBSYSACE", "APB SystemACE Interface"},
207         {OPENCHIP_APB1WIRE, "APB1WIRE", "APB 1-Wire Interface"},
208         {OPENCHIP_APBJTAG, "APBJTAG", "APB JTAG TAP Master"},
209         {OPENCHIP_APBSUI, "APBSUI", "APB Simple User Interface"},
210         {0, NULL, NULL}
211 };
212
213
214 /** Vendor OPENCORES devices */
215 static ambapp_device_name OPENCORES_devices[] = {
216         {OPENCORES_PCIBR, "PCIBR", "PCI Bridge"},
217         {OPENCORES_ETHMAC, "ETHMAC", "Ethernet MAC"},
218         {0, NULL}
219 };
220
221
222 /** Vendor CONTRIB devices */
223 static ambapp_device_name CONTRIB_devices[] = {
224         {CONTRIB_CORE1, "CORE1", "Contributed core 1"},
225         {CONTRIB_CORE2, "CORE2", "Contributed core 2"},
226         {0, NULL, NULL}
227 };
228
229
230 /** Vendor EONIC devices */
231 static ambapp_device_name EONIC_devices[] = {
232         {0, NULL, NULL}
233 };
234
235
236 /** Vendor RADIONOR devices */
237 static ambapp_device_name RADIONOR_devices[] = {
238         {0, NULL, NULL}
239 };
240
241
242 /** Vendor GLEICHMANN devices */
243 static ambapp_device_name GLEICHMANN_devices[] = {
244         {GLEICHMANN_CUSTOM, "CUSTOM", "Custom device"},
245         {GLEICHMANN_GEOLCD01, "GEOLCD01", "GEOLCD01 graphics system"},
246         {GLEICHMANN_DAC, "DAC", "Sigma delta DAC"},
247         {GLEICHMANN_HPI, "HPI", "AHB-to-HPI bridge"},
248         {GLEICHMANN_SPI, "SPI", "SPI master"},
249         {GLEICHMANN_HIFC, "HIFC", "Human interface controller"},
250         {GLEICHMANN_ADCDAC, "ADCDAC", "Sigma delta ADC/DAC"},
251         {GLEICHMANN_SPIOC, "SPIOC", ""},
252         {GLEICHMANN_AC97, "AC97", ""},
253         {0, NULL, NULL}
254 };
255
256
257 /** Vendor MENTA devices */
258 static ambapp_device_name MENTA_devices[] = {
259         {0, NULL, NULL}
260 };
261
262
263 /** Vendor SUN devices */
264 static ambapp_device_name SUN_devices[] = {
265         {SUN_T1, "T1", "Niagara T1 SPARC V9 Processor"},
266         {SUN_S1, "S1", "Niagara S1 SPARC V9 Processor"},
267         {0, NULL, NULL}
268 };
269
270
271 /** Vendor MOVIDIA devices */
272 static ambapp_device_name MOVIDIA_devices[] = {
273         {0, NULL, NULL}
274 };
275
276
277 /** Vendor ORBITA devices */
278 static ambapp_device_name ORBITA_devices[] = {
279         {ORBITA_1553B, "1553B", "MIL-STD-1553B Controller"},
280         {ORBITA_429, "429", "429 Interface"},
281         {ORBITA_SPI, "SPI", "SPI Interface"},
282         {ORBITA_I2C, "I2C", "I2C Interface"},
283         {ORBITA_SMARTCARD, "SMARTCARD", "Smart Card Reader"},
284         {ORBITA_SDCARD, "SDCARD", "SD Card Reader"},
285         {ORBITA_UART16550, "UART16550", "16550 UART"},
286         {ORBITA_CRYPTO, "CRYPTO", "Crypto Engine"},
287         {ORBITA_SYSIF, "SYSIF", "System Interface"},
288         {ORBITA_PIO, "PIO", "Programmable IO module"},
289         {ORBITA_RTC, "RTC", "Real-Time Clock"},
290         {ORBITA_COLORLCD, "COLORLCD", "Color LCD Controller"},
291         {ORBITA_PCI, "PCI", "PCI Module"},
292         {ORBITA_DSP, "DSP", "DPS Co-Processor"},
293         {ORBITA_USBHOST, "USBHOST", "USB Host"},
294         {ORBITA_USBDEV, "USBDEV", "USB Device"},
295         {0, NULL, NULL}
296 };
297
298
299 /** Vendor SYNOPSYS devices */
300 static ambapp_device_name SYNOPSYS_devices[] = {
301         {0, NULL, NULL}
302 };
303
304
305 /** Vendor NASA devices */
306 static ambapp_device_name NASA_devices[] = {
307         {NASA_EP32, "EP32", "EP32 Forth processor"},
308         {0, NULL, NULL}
309 };
310
311
312 /** Vendor CAL devices */
313 static ambapp_device_name CAL_devices[] = {
314         {CAL_DDRCTRL, "DDRCTRL", ""},
315         {0, NULL, NULL}
316 };
317
318
319 /** Vendor EMBEDDIT devices */
320 static ambapp_device_name EMBEDDIT_devices[] = {
321         {0, NULL, NULL}
322 };
323
324
325 /** Vendor CETON devices */
326 static ambapp_device_name CETON_devices[] = {
327         {0, NULL, NULL}
328 };
329
330
331 /** Vendor S3 devices */
332 static ambapp_device_name S3_devices[] = {
333         {0, NULL, NULL}
334 };
335
336
337 /** Vendor ACTEL devices */
338 static ambapp_device_name ACTEL_devices[] = {
339         {ACTEL_COREMP7, "COREMP7", "CoreMP7 Processor"},
340         {0, NULL, NULL}
341 };
342
343
344 /** Vendor APPLECORE devices */
345 static ambapp_device_name APPLECORE_devices[] = {
346         {APPLECORE_UTLEON3, "UTLEON3", "AppleCore uT-LEON3 Processor"},
347         {APPLECORE_UTLEON3DSU, "UTLEON3DSU", "AppleCore uT-LEON3 DSU"},
348         {0, NULL, NULL}
349 };
350
351
352 /** Vendors and their devices */
353 static ambapp_vendor_devnames vendors[] = {
354         {VENDOR_GAISLER, "GAISLER", "Gaisler Research", GAISLER_devices},
355         {VENDOR_PENDER, "PENDER", "", PENDER_devices},
356         {VENDOR_ESA, "ESA", "European Space Agency", ESA_devices},
357         {VENDOR_ASTRIUM, "ASTRIUM", "", ASTRIUM_devices},
358         {VENDOR_OPENCHIP, "OPENCHIP", "OpenChip", OPENCHIP_devices},
359         {VENDOR_OPENCORES, "OPENCORES", "OpenCores", OPENCORES_devices},
360         {VENDOR_CONTRIB, "CONTRIB", "Various contributions", CONTRIB_devices},
361         {VENDOR_EONIC, "EONIC", "Eonic BV", EONIC_devices},
362         {VENDOR_RADIONOR, "RADIONOR", "Radionor Communications", RADIONOR_devices},
363         {VENDOR_GLEICHMANN, "GLEICHMANN", "Gleichmann Electronics", GLEICHMANN_devices},
364         {VENDOR_MENTA, "MENTA", "Menta", MENTA_devices},
365         {VENDOR_SUN, "SUN", "Sun Microsystems", SUN_devices},
366         {VENDOR_MOVIDIA, "MOVIDIA", "", MOVIDIA_devices},
367         {VENDOR_ORBITA, "ORBITA", "Orbita", ORBITA_devices},
368         {VENDOR_SYNOPSYS, "SYNOPSYS", "Synopsys Inc.", SYNOPSYS_devices},
369         {VENDOR_NASA, "NASA", "NASA", NASA_devices},
370         {VENDOR_S3, "S3", "S3 Group", S3_devices},
371         {VENDOR_CAL, "CAL", "", CAL_devices},
372         {VENDOR_EMBEDDIT, "EMBEDDIT", "Embedd.it", EMBEDDIT_devices},
373         {VENDOR_CETON, "CETON", "Ceton Corporation", CETON_devices},
374         {VENDOR_ACTEL, "ACTEL", "Actel Corporation", ACTEL_devices},
375         {VENDOR_APPLECORE, "APPLECORE", "AppleCore", APPLECORE_devices},
376         {0, NULL, NULL, NULL}
377 };
378
379 static ambapp_device_name *ambapp_get_dev(ambapp_device_name *devs, int id)
380 {
381         if (!devs)
382                 return NULL;
383
384         while (devs->device_id > 0) {
385                 if (devs->device_id == id)
386                         return devs;
387                 devs++;
388         }
389         return NULL;
390 }
391
392 char *ambapp_device_id2str(int vendor, int id)
393 {
394         ambapp_vendor_devnames *ven = &vendors[0];
395         ambapp_device_name *dev;
396
397         while (ven->vendor_id > 0) {
398                 if (ven->vendor_id == vendor) {
399                         dev = ambapp_get_dev(ven->devices, id);
400                         if (!dev)
401                                 return NULL;
402                         return dev->name;
403                 }
404                 ven++;
405         }
406         return NULL;
407 }
408
409 char *ambapp_device_id2desc(int vendor, int id)
410 {
411         ambapp_vendor_devnames *ven = &vendors[0];
412         ambapp_device_name *dev;
413
414         while (ven->vendor_id > 0) {
415                 if (ven->vendor_id == vendor) {
416                         dev = ambapp_get_dev(ven->devices, id);
417                         if (!dev)
418                                 return NULL;
419                         return dev->desc;
420                 }
421                 ven++;
422         }
423         return NULL;
424 }
425
426 char *ambapp_vendor_id2str(int vendor)
427 {
428         ambapp_vendor_devnames *ven = &vendors[0];
429
430         while (ven->vendor_id > 0) {
431                 if (ven->vendor_id == vendor) {
432                         return ven->name;
433                 }
434                 ven++;
435         }
436         return NULL;
437 }
438
439 static char *unknown = "unknown";
440
441 char *ambapp_type_names[4] = {
442         /* 0 */ "UNUSED",
443         /* 1 */ "apb",
444         /* 2 */ "ahbmem",
445         /* 3 */ "ahbio"
446 };
447
448 /* Print one APB device */
449 void ambapp_print_apb(ambapp_apbdev *dev, int index)
450 {
451         char *dev_str, *ven_str;
452         unsigned int freq;
453
454         ven_str = ambapp_vendor_id2str(dev->vendor);
455         if (!ven_str) {
456                 ven_str = unknown;
457                 dev_str = unknown;
458         } else {
459                 dev_str = ambapp_device_id2str(dev->vendor, dev->device);
460                 if (!dev_str)
461                         dev_str = unknown;
462         }
463
464         /* Get Frequency of Core */
465         freq = ambapp_bus_freq(&ambapp_plb, dev->ahb_bus_index);
466
467         printf("0x%02x:0x%02x:0x%02x: %s  %s  (%dkHz)\n"
468                "   apb: 0x%08x - 0x%08x\n"
469                "   irq: %-2d (ver: %-2d)\n",
470                index, dev->vendor, dev->device, ven_str, dev_str, freq / 1000,
471                dev->address, dev->address + (dev->mask-1),
472                dev->irq, dev->ver);
473 }
474
475 void ambapp_print_ahb(ambapp_ahbdev *dev, int index)
476 {
477         char *dev_str, *ven_str, *type_str;
478         int i;
479         unsigned int freq;
480
481         ven_str = ambapp_vendor_id2str(dev->vendor);
482         if (!ven_str) {
483                 ven_str = unknown;
484                 dev_str = unknown;
485         } else {
486                 dev_str = ambapp_device_id2str(dev->vendor, dev->device);
487                 if (!dev_str)
488                         dev_str = unknown;
489         }
490
491         /* Get Frequency of Core */
492         freq = ambapp_bus_freq(&ambapp_plb, dev->ahb_bus_index);
493
494         printf("0x%02x:0x%02x:0x%02x: %s  %s  (%dkHz)\n",
495                index, dev->vendor, dev->device, ven_str, dev_str, freq / 1000);
496
497         for (i = 0; i < 4; i++) {
498                 if (dev->type[i] == 0)
499                         continue;
500                 type_str = ambapp_type_names[dev->type[i]];
501                 printf("   %-7s: 0x%08x - 0x%08x\n", type_str, dev->address[i],
502                         dev->address[i] + (dev->mask[i]-1));
503         }
504
505         printf("   irq: %-2d (ver: %d)\n", dev->irq, dev->ver);
506 }
507
508 int do_ambapp_print(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
509 {
510         int index;
511         ambapp_apbdev apbdev;
512         ambapp_ahbdev ahbdev;
513
514         /* Print AHB Masters */
515         puts("\n--------- AHB Masters ---------\n");
516         index = 0;
517         while (ambapp_ahbmst_find(&ambapp_plb, 0, 0, index, &ahbdev) == 1) {
518                 /* Found a AHB Master Device */
519                 ambapp_print_ahb(&ahbdev, index);
520                 index++;
521         }
522
523         /* Print AHB Slaves */
524         puts("\n--------- AHB Slaves  ---------\n");
525         index = 0;
526         while (ambapp_ahbslv_find(&ambapp_plb, 0, 0, index, &ahbdev) == 1) {
527                 /* Found a AHB Slave Device */
528                 ambapp_print_ahb(&ahbdev, index);
529                 index++;
530         }
531
532         /* Print APB Slaves */
533         puts("\n--------- APB Slaves  ---------\n");
534         index = 0;
535         while (ambapp_apb_find(&ambapp_plb, 0, 0, index, &apbdev) == 1) {
536                 /* Found a APB Slave Device */
537                 ambapp_print_apb(&apbdev, index);
538                 index++;
539         }
540
541         puts("\n");
542         return 0;
543 }
544
545 int ambapp_init_reloc(void)
546 {
547         ambapp_vendor_devnames *vend = vendors;
548         ambapp_device_name *dev;
549
550         while (vend->vendor_id && vend->name) {
551                 vend->name = (char *)((unsigned int)vend->name + gd->reloc_off);
552                 vend->desc = (char *)((unsigned int)vend->desc + gd->reloc_off);
553                 vend->devices = (ambapp_device_name *)
554                         ((unsigned int)vend->devices + gd->reloc_off);
555                 dev = vend->devices;
556                 vend++;
557                 if (!dev)
558                         continue;
559                 while (dev->device_id && dev->name) {
560                         dev->name =
561                             (char *)((unsigned int)dev->name + gd->reloc_off);
562                         dev->desc =
563                             (char *)((unsigned int)dev->desc + gd->reloc_off);
564                         dev++;
565                 }
566         }
567         return 0;
568 }
569
570 U_BOOT_CMD(
571         ambapp, 1, 1, do_ambapp_print,
572         "list AMBA Plug&Play information",
573         "ambapp\n"
574         "    - lists AMBA (AHB & APB) Plug&Play devices present on the system"
575 );