cmd_ambapp.c 7.3 KB

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