ambapp.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /* Interface for accessing Gaisler AMBA Plug&Play Bus.
  2. * The AHB bus can be interfaced with a simpler bus -
  3. * the APB bus, also freely available in GRLIB at
  4. * www.gaisler.com.
  5. *
  6. * (C) Copyright 2007
  7. * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com.
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. *
  27. */
  28. #ifndef __AMBAPP_H__
  29. #define __AMBAPP_H__
  30. /* Default location of Plug&Play info
  31. * normally 0xfffff000 for AHB masters
  32. * and 0xfffff800 for AHB slaves.
  33. * Normally no need to change this.
  34. */
  35. #define LEON3_IO_AREA 0xfff00000
  36. #define LEON3_CONF_AREA 0xff000
  37. #define LEON3_AHB_SLAVE_CONF_AREA (1 << 11)
  38. /* Max devices this software will support */
  39. #define LEON3_AHB_MASTERS 16
  40. #define LEON3_AHB_SLAVES 16
  41. /*#define LEON3_APB_MASTERS 1*/ /* Number of APB buses that has Plug&Play */
  42. #define LEON3_APB_SLAVES 16 /* Total number of APB slaves per APB bus */
  43. /* Vendor codes */
  44. #define VENDOR_GAISLER 1
  45. #define VENDOR_PENDER 2
  46. #define VENDOR_ESA 4
  47. #define VENDOR_ASTRIUM 6
  48. #define VENDOR_OPENCHIP 7
  49. #define VENDOR_OPENCORES 8
  50. #define VENDOR_CONTRIB 9
  51. #define VENDOR_EONIC 11
  52. #define VENDOR_RADIONOR 15
  53. #define VENDOR_GLEICHMANN 16
  54. #define VENDOR_MENTA 17
  55. #define VENDOR_SUN 19
  56. #define VENDOR_EMBEDDIT 234
  57. #define VENDOR_CAL 202
  58. /* Gaisler Research device id's */
  59. #define GAISLER_LEON3 0x003
  60. #define GAISLER_LEON3DSU 0x004
  61. #define GAISLER_ETHAHB 0x005
  62. #define GAISLER_APBMST 0x006
  63. #define GAISLER_AHBUART 0x007
  64. #define GAISLER_SRCTRL 0x008
  65. #define GAISLER_SDCTRL 0x009
  66. #define GAISLER_APBUART 0x00C
  67. #define GAISLER_IRQMP 0x00D
  68. #define GAISLER_AHBRAM 0x00E
  69. #define GAISLER_GPTIMER 0x011
  70. #define GAISLER_PCITRG 0x012
  71. #define GAISLER_PCISBRG 0x013
  72. #define GAISLER_PCIFBRG 0x014
  73. #define GAISLER_PCITRACE 0x015
  74. #define GAISLER_PCIDMA 0x016
  75. #define GAISLER_AHBTRACE 0x017
  76. #define GAISLER_ETHDSU 0x018
  77. #define GAISLER_PIOPORT 0x01A
  78. #define GAISLER_AHBJTAG 0x01c
  79. #define GAISLER_SPW 0x01f
  80. #define GAISLER_ATACTRL 0x024
  81. #define GAISLER_VGA 0x061
  82. #define GAISLER_KBD 0X060
  83. #define GAISLER_ETHMAC 0x01D
  84. #define GAISLER_DDRSPA 0x025
  85. #define GAISLER_EHCI 0x026
  86. #define GAISLER_UHCI 0x027
  87. #define GAISLER_SPW2 0x029
  88. #define GAISLER_DDR2SPA 0x02E
  89. #define GAISLER_AHBSTAT 0x052
  90. #define GAISLER_FTMCTRL 0x054
  91. #define GAISLER_L2TIME 0xffd /* internal device: leon2 timer */
  92. #define GAISLER_L2C 0xffe /* internal device: leon2compat */
  93. #define GAISLER_PLUGPLAY 0xfff /* internal device: plug & play configarea */
  94. /* European Space Agency device id's */
  95. #define ESA_LEON2 0x2
  96. #define ESA_MCTRL 0xF
  97. /* Opencores device id's */
  98. #define OPENCORES_PCIBR 0x4
  99. #define OPENCORES_ETHMAC 0x5
  100. /* Vendor codes */
  101. /*
  102. *
  103. * Macros for manipulating Configuration registers
  104. *
  105. */
  106. #define amba_vendor(x) (((x) >> 24) & 0xff)
  107. #define amba_device(x) (((x) >> 12) & 0xfff)
  108. #define amba_membar_start(mbar) \
  109. (((mbar) & 0xfff00000) & (((mbar) & 0xfff0) << 16))
  110. #define amba_iobar_start(base, iobar) \
  111. ((base) | ((((iobar) & 0xfff00000)>>12) & (((iobar) & 0xfff0)<<4)) )
  112. #define amba_irq(conf) ((conf) & 0xf)
  113. #define amba_ver(conf) (((conf)>>5) & 0x1f)
  114. #define amba_membar_type(mbar) ((mbar) & 0xf)
  115. #define amba_membar_mask(mbar) (((mbar)>>4) & 0xfff)
  116. #define AMBA_TYPE_APBIO 0x1
  117. #define AMBA_TYPE_MEM 0x2
  118. #define AMBA_TYPE_AHBIO 0x3
  119. #define AMBA_TYPE_AHBIO_ADDR(addr) (LEON3_IO_AREA | ((addr) >> 12))
  120. #ifndef __ASSEMBLER__
  121. #ifdef CONFIG_CMD_AMBAPP
  122. /* AMBA Plug&Play relocation & initialization */
  123. int ambapp_init_reloc(void);
  124. /* AMBA Plug&Play Name of Vendors and devices */
  125. /* Return name of device */
  126. char *ambapp_device_id2str(int vendor, int id);
  127. /* Return name of vendor */
  128. char *ambapp_vendor_id2str(int vendor);
  129. #endif
  130. /*
  131. * Types and structure used for AMBA Plug & Play bus scanning
  132. */
  133. /* AMBA Plug&Play AHB information layout */
  134. typedef struct {
  135. unsigned int conf;
  136. unsigned int userdef[3];
  137. unsigned int bars[4];
  138. } ahbctrl_pp_dev;
  139. /* Prototypes for scanning AMBA Plug&Play bus for AMBA
  140. * i) AHB Masters
  141. * ii) AHB Slaves
  142. * iii) APB Slaves (APB MST is a AHB Slave)
  143. */
  144. typedef struct {
  145. unsigned char irq;
  146. unsigned char ver;
  147. unsigned int address;
  148. } ambapp_apbdev;
  149. typedef struct {
  150. unsigned char irq;
  151. unsigned char ver;
  152. unsigned int userdef[3];
  153. unsigned int address[4];
  154. } ambapp_ahbdev;
  155. /* AMBA Plug&Play AHB Masters & Slaves information locations
  156. * Max devices is 64 supported by HW, however often only 8
  157. * are used.
  158. */
  159. typedef struct {
  160. ahbctrl_pp_dev masters[64];
  161. ahbctrl_pp_dev slaves[64];
  162. } ahbctrl_info;
  163. /* AMBA Plug&Play AHB information layout */
  164. typedef struct {
  165. unsigned int conf;
  166. unsigned int bar;
  167. } apbctrl_pp_dev;
  168. /* All functions return the number of found devices
  169. * 0 = no devices found
  170. */
  171. /****************************** APB SLAVES ******************************/
  172. int ambapp_apb_count(unsigned int vendor, unsigned int driver);
  173. int ambapp_apb_first(unsigned int vendor,
  174. unsigned int driver, ambapp_apbdev * dev);
  175. int ambapp_apb_next(unsigned int vendor,
  176. unsigned int driver, ambapp_apbdev * dev, int index);
  177. int ambapp_apbs_first(unsigned int vendor,
  178. unsigned int driver, ambapp_apbdev * dev, int max_cnt);
  179. /****************************** AHB MASTERS ******************************/
  180. int ambapp_ahbmst_count(unsigned int vendor, unsigned int driver);
  181. int ambapp_ahbmst_first(unsigned int vendor,
  182. unsigned int driver, ambapp_ahbdev * dev);
  183. int ambapp_ahbmst_next(unsigned int vendor,
  184. unsigned int driver, ambapp_ahbdev * dev, int index);
  185. int ambapp_ahbmsts_first(unsigned int vendor,
  186. unsigned int driver, ambapp_ahbdev * dev, int max_cnt);
  187. /****************************** AHB SLAVES ******************************/
  188. int ambapp_ahbslv_count(unsigned int vendor, unsigned int driver);
  189. int ambapp_ahbslv_first(unsigned int vendor,
  190. unsigned int driver, ambapp_ahbdev * dev);
  191. int ambapp_ahbslv_next(unsigned int vendor,
  192. unsigned int driver, ambapp_ahbdev * dev, int index);
  193. int ambapp_ahbslvs_first(unsigned int vendor,
  194. unsigned int driver, ambapp_ahbdev * dev, int max_cnt);
  195. /*************************** AHB/APB only regs functions *************************
  196. * During start up, no memory is available we can use the simplified functions
  197. * to get to the memory controller.
  198. *
  199. * Functions uses no stack/memory, only registers.
  200. */
  201. unsigned int ambapp_apb_next_nomem(register unsigned int vendor, /* Plug&Play Vendor ID */
  202. register unsigned int driver, /* Plug&Play Device ID */
  203. register int index);
  204. ahbctrl_pp_dev *ambapp_ahb_next_nomem(register unsigned int vendor, /* Plug&Play Vendor ID */
  205. register unsigned int driver, /* Plug&Play Device ID */
  206. register unsigned int opts, /* scan for AHB 1=slave, 0=masters */
  207. register int index);
  208. unsigned int ambapp_ahb_get_info(ahbctrl_pp_dev * ahb, int info);
  209. /*************************** AMBA Plug&Play device register MAPS *****************/
  210. /*
  211. * The following defines the bits in the LEON UART Status Registers.
  212. */
  213. #define LEON_REG_UART_STATUS_DR 0x00000001 /* Data Ready */
  214. #define LEON_REG_UART_STATUS_TSE 0x00000002 /* TX Send Register Empty */
  215. #define LEON_REG_UART_STATUS_THE 0x00000004 /* TX Hold Register Empty */
  216. #define LEON_REG_UART_STATUS_BR 0x00000008 /* Break Error */
  217. #define LEON_REG_UART_STATUS_OE 0x00000010 /* RX Overrun Error */
  218. #define LEON_REG_UART_STATUS_PE 0x00000020 /* RX Parity Error */
  219. #define LEON_REG_UART_STATUS_FE 0x00000040 /* RX Framing Error */
  220. #define LEON_REG_UART_STATUS_ERR 0x00000078 /* Error Mask */
  221. /*
  222. * The following defines the bits in the LEON UART Ctrl Registers.
  223. */
  224. #define LEON_REG_UART_CTRL_RE 0x00000001 /* Receiver enable */
  225. #define LEON_REG_UART_CTRL_TE 0x00000002 /* Transmitter enable */
  226. #define LEON_REG_UART_CTRL_RI 0x00000004 /* Receiver interrupt enable */
  227. #define LEON_REG_UART_CTRL_TI 0x00000008 /* Transmitter interrupt enable */
  228. #define LEON_REG_UART_CTRL_PS 0x00000010 /* Parity select */
  229. #define LEON_REG_UART_CTRL_PE 0x00000020 /* Parity enable */
  230. #define LEON_REG_UART_CTRL_FL 0x00000040 /* Flow control enable */
  231. #define LEON_REG_UART_CTRL_LB 0x00000080 /* Loop Back enable */
  232. #define LEON_REG_UART_CTRL_DBG (1<<11) /* Debug Bit used by GRMON */
  233. #define LEON3_GPTIMER_EN 1
  234. #define LEON3_GPTIMER_RL 2
  235. #define LEON3_GPTIMER_LD 4
  236. #define LEON3_GPTIMER_IRQEN 8
  237. /*
  238. * The following defines the bits in the LEON PS/2 Status Registers.
  239. */
  240. #define LEON_REG_PS2_STATUS_DR 0x00000001 /* Data Ready */
  241. #define LEON_REG_PS2_STATUS_PE 0x00000002 /* Parity error */
  242. #define LEON_REG_PS2_STATUS_FE 0x00000004 /* Framing error */
  243. #define LEON_REG_PS2_STATUS_KI 0x00000008 /* Keyboard inhibit */
  244. /*
  245. * The following defines the bits in the LEON PS/2 Ctrl Registers.
  246. */
  247. #define LEON_REG_PS2_CTRL_RE 0x00000001 /* Receiver enable */
  248. #define LEON_REG_PS2_CTRL_TE 0x00000002 /* Transmitter enable */
  249. #define LEON_REG_PS2_CTRL_RI 0x00000004 /* Keyboard receive interrupt */
  250. #define LEON_REG_PS2_CTRL_TI 0x00000008 /* Keyboard transmit interrupt */
  251. typedef struct {
  252. volatile unsigned int ilevel;
  253. volatile unsigned int ipend;
  254. volatile unsigned int iforce;
  255. volatile unsigned int iclear;
  256. volatile unsigned int mstatus;
  257. volatile unsigned int notused[11];
  258. volatile unsigned int cpu_mask[16];
  259. volatile unsigned int cpu_force[16];
  260. } ambapp_dev_irqmp;
  261. typedef struct {
  262. volatile unsigned int data;
  263. volatile unsigned int status;
  264. volatile unsigned int ctrl;
  265. volatile unsigned int scaler;
  266. } ambapp_dev_apbuart;
  267. typedef struct {
  268. volatile unsigned int val;
  269. volatile unsigned int rld;
  270. volatile unsigned int ctrl;
  271. volatile unsigned int unused;
  272. } ambapp_dev_gptimer_element;
  273. #define LEON3_GPTIMER_CTRL_EN 0x1 /* Timer enable */
  274. #define LEON3_GPTIMER_CTRL_RS 0x2 /* Timer reStart */
  275. #define LEON3_GPTIMER_CTRL_LD 0x4 /* Timer reLoad */
  276. #define LEON3_GPTIMER_CTRL_IE 0x8 /* interrupt enable */
  277. #define LEON3_GPTIMER_CTRL_IP 0x10 /* interrupt flag/pending */
  278. #define LEON3_GPTIMER_CTRL_CH 0x20 /* Chain with previous timer */
  279. typedef struct {
  280. volatile unsigned int scalar;
  281. volatile unsigned int scalar_reload;
  282. volatile unsigned int config;
  283. volatile unsigned int unused;
  284. volatile ambapp_dev_gptimer_element e[8];
  285. } ambapp_dev_gptimer;
  286. typedef struct {
  287. volatile unsigned int iodata;
  288. volatile unsigned int ioout;
  289. volatile unsigned int iodir;
  290. volatile unsigned int irqmask;
  291. volatile unsigned int irqpol;
  292. volatile unsigned int irqedge;
  293. } ambapp_dev_ioport;
  294. typedef struct {
  295. volatile unsigned int write;
  296. volatile unsigned int dummy;
  297. volatile unsigned int txcolor;
  298. volatile unsigned int bgcolor;
  299. } ambapp_dev_textvga;
  300. typedef struct {
  301. volatile unsigned int data;
  302. volatile unsigned int status;
  303. volatile unsigned int ctrl;
  304. } ambapp_dev_apbps2;
  305. typedef struct {
  306. unsigned int mcfg1, mcfg2, mcfg3;
  307. } ambapp_dev_mctrl;
  308. typedef struct {
  309. unsigned int sdcfg;
  310. } ambapp_dev_sdctrl;
  311. typedef struct {
  312. unsigned int cfg1;
  313. unsigned int cfg2;
  314. unsigned int cfg3;
  315. } ambapp_dev_ddr2spa;
  316. typedef struct {
  317. unsigned int ctrl;
  318. unsigned int cfg;
  319. } ambapp_dev_ddrspa;
  320. #endif
  321. #endif