ambapp.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 2009, 2015
  7. * Daniel Hellstrom, Cobham Gaisler, daniel@gaisler.com.
  8. *
  9. * SPDX-License-Identifier: GPL-2.0+
  10. */
  11. #ifndef __AMBAPP_H__
  12. #define __AMBAPP_H__
  13. #include <ambapp_ids.h>
  14. #ifndef __ASSEMBLER__
  15. /* Structures used to access Plug&Play information directly */
  16. struct ambapp_pnp_ahb {
  17. const unsigned int id; /* VENDOR, DEVICE, VER, IRQ, */
  18. const unsigned int custom[3];
  19. const unsigned int mbar[4]; /* MASK, ADDRESS, TYPE,
  20. * CACHABLE/PREFETCHABLE */
  21. };
  22. struct ambapp_pnp_apb {
  23. const unsigned int id; /* VENDOR, DEVICE, VER, IRQ, */
  24. const unsigned int iobar; /* MASK, ADDRESS, TYPE,
  25. * CACHABLE/PREFETCHABLE */
  26. };
  27. /* AMBA Plug&Play AHB Masters & Slaves information locations
  28. * Max devices is 64 supported by HW, however often only 16
  29. * are used.
  30. */
  31. struct ambapp_pnp_info {
  32. struct ambapp_pnp_ahb masters[64];
  33. struct ambapp_pnp_ahb slaves[63];
  34. const unsigned int unused[4];
  35. const unsigned int systemid[4];
  36. };
  37. /* Describes a AMBA PnP bus */
  38. struct ambapp_bus {
  39. int buses; /* Number of buses */
  40. unsigned int ioareas[6]; /* PnP I/O AREAs of AHB buses */
  41. unsigned int freq; /* Frequency of bus0 [Hz] */
  42. };
  43. /* Processor Local AMBA bus */
  44. extern struct ambapp_bus ambapp_plb;
  45. /* Get Bus frequency of a certain AMBA bus */
  46. extern unsigned int ambapp_bus_freq(
  47. struct ambapp_bus *abus,
  48. int ahb_bus_index
  49. );
  50. /* AMBA PnP information of a APB Device */
  51. typedef struct {
  52. unsigned int vendor;
  53. unsigned int device;
  54. unsigned char irq;
  55. unsigned char ver;
  56. unsigned int address;
  57. unsigned int mask;
  58. int ahb_bus_index;
  59. } ambapp_apbdev;
  60. /* AMBA PnP information of a AHB Device */
  61. typedef struct {
  62. unsigned int vendor;
  63. unsigned int device;
  64. unsigned char irq;
  65. unsigned char ver;
  66. unsigned int userdef[3];
  67. unsigned int address[4];
  68. unsigned int mask[4];
  69. int type[4];
  70. int ahb_bus_index;
  71. } ambapp_ahbdev;
  72. /* Scan AMBA Bus for AHB Bridges */
  73. extern void ambapp_bus_init(
  74. unsigned int ioarea,
  75. unsigned int freq,
  76. struct ambapp_bus *abus);
  77. /* Find APB Slave device by index using breath first search.
  78. *
  79. * When vendor and device are both set to zero, any device
  80. * with a non-zero device ID will match the search. It may be
  81. * useful when processing all devices on a AMBA bus.
  82. */
  83. extern int ambapp_apb_find(
  84. struct ambapp_bus *abus,
  85. int vendor,
  86. int device,
  87. int index,
  88. ambapp_apbdev *dev
  89. );
  90. /* Find AHB Master device by index using breath first search.
  91. *
  92. * When vendor and device are both set to zero, any device
  93. * with a non-zero device ID will match the search. It may be
  94. * useful when processing all devices on a AMBA bus.
  95. */
  96. extern int ambapp_ahbmst_find(
  97. struct ambapp_bus *abus,
  98. int vendor,
  99. int device,
  100. int index,
  101. ambapp_ahbdev *dev
  102. );
  103. /* Find AHB Slave device by index using breath first search.
  104. *
  105. * When vendor and device are both set to zero, any device
  106. * with a non-zero device ID will match the search. It may be
  107. * useful when processing all devices on a AMBA bus.
  108. */
  109. extern int ambapp_ahbslv_find(
  110. struct ambapp_bus *abus,
  111. int vendor,
  112. int device,
  113. int index,
  114. ambapp_ahbdev *dev
  115. );
  116. /* Return number of APB Slave devices of a certain ID (VENDOR:DEVICE)
  117. * zero is returned if no devices was found.
  118. */
  119. extern int ambapp_apb_count(struct ambapp_bus *abus, int vendor, int device);
  120. /* Return number of AHB Master devices of a certain ID (VENDOR:DEVICE)
  121. * zero is returned if no devices was found.
  122. */
  123. extern int ambapp_ahbmst_count(struct ambapp_bus *abus, int vendor, int device);
  124. /* Return number of AHB Slave devices of a certain ID (VENDOR:DEVICE)
  125. * zero is returned if no devices was found.
  126. */
  127. extern int ambapp_ahbslv_count(struct ambapp_bus *abus, int vendor, int device);
  128. #ifdef CONFIG_CMD_AMBAPP
  129. /* AMBA Plug&Play relocation & initialization */
  130. int ambapp_init_reloc(void);
  131. /* AMBA Plug&Play Name of Vendors and devices */
  132. /* Return name of device */
  133. char *ambapp_device_id2str(int vendor, int id);
  134. /* Return name of vendor */
  135. char *ambapp_vendor_id2str(int vendor);
  136. /* Return description of a device */
  137. char *ambapp_device_id2desc(int vendor, int id);
  138. #endif
  139. #endif /* defined(__ASSEMBLER__) */
  140. #define AMBA_DEFAULT_IOAREA 0xfff00000
  141. #define AMBA_CONF_AREA 0xff000
  142. #define AMBA_AHB_SLAVE_CONF_AREA 0x800
  143. #define DEV_NONE 0
  144. #define DEV_AHB_MST 1
  145. #define DEV_AHB_SLV 2
  146. #define DEV_APB_SLV 3
  147. #define AMBA_TYPE_APBIO 0x1
  148. #define AMBA_TYPE_MEM 0x2
  149. #define AMBA_TYPE_AHBIO 0x3
  150. /* ID layout for APB and AHB devices */
  151. #define AMBA_PNP_ID(vendor, device) (((vendor)<<24) | ((device)<<12))
  152. /* APB Slave PnP layout definitions */
  153. #define AMBA_APB_ID_OFS (0*4)
  154. #define AMBA_APB_IOBAR_OFS (1*4)
  155. #define AMBA_APB_CONF_LENGH (2*4)
  156. /* AHB Master/Slave layout PnP definitions */
  157. #define AMBA_AHB_ID_OFS (0*4)
  158. #define AMBA_AHB_CUSTOM0_OFS (1*4)
  159. #define AMBA_AHB_CUSTOM1_OFS (2*4)
  160. #define AMBA_AHB_CUSTOM2_OFS (3*4)
  161. #define AMBA_AHB_MBAR0_OFS (4*4)
  162. #define AMBA_AHB_MBAR1_OFS (5*4)
  163. #define AMBA_AHB_MBAR2_OFS (6*4)
  164. #define AMBA_AHB_MBAR3_OFS (7*4)
  165. #define AMBA_AHB_CONF_LENGH (8*4)
  166. /* Macros for extracting information from AMBA PnP information
  167. * registers.
  168. */
  169. #define amba_vendor(x) (((x) >> 24) & 0xff)
  170. #define amba_device(x) (((x) >> 12) & 0xfff)
  171. #define amba_irq(conf) ((conf) & 0x1f)
  172. #define amba_ver(conf) (((conf)>>5) & 0x1f)
  173. #define amba_iobar_start(base, iobar) \
  174. ((base) | ((((iobar) & 0xfff00000)>>12) & (((iobar) & 0xfff0)<<4)))
  175. #define amba_membar_start(mbar) \
  176. (((mbar) & 0xfff00000) & (((mbar) & 0xfff0) << 16))
  177. #define amba_membar_type(mbar) ((mbar) & 0xf)
  178. #define amba_membar_mask(mbar) (((mbar) >> 4) & 0xfff)
  179. #define amba_ahbio_adr(addr, base_ioarea) \
  180. ((unsigned int)(base_ioarea) | ((addr) >> 12))
  181. #define amba_apb_mask(iobar) ((~(amba_membar_mask(iobar)<<8) & 0x000fffff) + 1)
  182. #endif