cmd_ambapp.c 6.6 KB

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