siutils_priv.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * Include file private to the SOC Interconnect support files.
  3. *
  4. * Copyright (C) 1999-2014, Broadcom Corporation
  5. *
  6. * Unless you and Broadcom execute a separate written software license
  7. * agreement governing use of this software, this software is licensed to you
  8. * under the terms of the GNU General Public License version 2 (the "GPL"),
  9. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  10. * following added to such license:
  11. *
  12. * As a special exception, the copyright holders of this software give you
  13. * permission to link this software with independent modules, and to copy and
  14. * distribute the resulting executable under terms of your choice, provided that
  15. * you also meet, for each linked independent module, the terms and conditions of
  16. * the license of that module. An independent module is a module which is not
  17. * derived from this software. The special exception does not apply to any
  18. * modifications of the software.
  19. *
  20. * Notwithstanding the above, under no circumstances may you combine this
  21. * software in any way with any other Broadcom software provided under a license
  22. * other than the GPL, without Broadcom's express prior written consent.
  23. *
  24. * $Id: siutils_priv.h 431423 2013-10-23 16:07:35Z $
  25. */
  26. #ifndef _siutils_priv_h_
  27. #define _siutils_priv_h_
  28. #define SI_ERROR(args)
  29. #define SI_MSG(args)
  30. #ifdef BCMDBG_SI
  31. #define SI_VMSG(args) printf args
  32. #else
  33. #define SI_VMSG(args)
  34. #endif
  35. #define IS_SIM(chippkg) ((chippkg == HDLSIM_PKG_ID) || (chippkg == HWSIM_PKG_ID))
  36. typedef uint32 (*si_intrsoff_t)(void *intr_arg);
  37. typedef void (*si_intrsrestore_t)(void *intr_arg, uint32 arg);
  38. typedef bool (*si_intrsenabled_t)(void *intr_arg);
  39. typedef struct gpioh_item {
  40. void *arg;
  41. bool level;
  42. gpio_handler_t handler;
  43. uint32 event;
  44. struct gpioh_item *next;
  45. } gpioh_item_t;
  46. #define SI_GPIO_MAX 16
  47. typedef struct gci_gpio_item {
  48. void *arg;
  49. uint8 gci_gpio;
  50. uint8 status;
  51. gci_gpio_handler_t handler;
  52. struct gci_gpio_item *next;
  53. } gci_gpio_item_t;
  54. typedef struct si_cores_info {
  55. void *regs[SI_MAXCORES]; /* other regs va */
  56. uint coreid[SI_MAXCORES]; /* id of each core */
  57. uint32 coresba[SI_MAXCORES]; /* backplane address of each core */
  58. void *regs2[SI_MAXCORES]; /* va of each core second register set (usbh20) */
  59. uint32 coresba2[SI_MAXCORES]; /* address of each core second register set (usbh20) */
  60. uint32 coresba_size[SI_MAXCORES]; /* backplane address space size */
  61. uint32 coresba2_size[SI_MAXCORES]; /* second address space size */
  62. void *wrappers[SI_MAXCORES]; /* other cores wrapper va */
  63. uint32 wrapba[SI_MAXCORES]; /* address of controlling wrapper */
  64. uint32 cia[SI_MAXCORES]; /* erom cia entry for each core */
  65. uint32 cib[SI_MAXCORES]; /* erom cia entry for each core */
  66. } si_cores_info_t;
  67. /* misc si info needed by some of the routines */
  68. typedef struct si_info {
  69. struct si_pub pub; /* back plane public state (must be first field) */
  70. void *osh; /* osl os handle */
  71. void *sdh; /* bcmsdh handle */
  72. uint dev_coreid; /* the core provides driver functions */
  73. void *intr_arg; /* interrupt callback function arg */
  74. si_intrsoff_t intrsoff_fn; /* turns chip interrupts off */
  75. si_intrsrestore_t intrsrestore_fn; /* restore chip interrupts */
  76. si_intrsenabled_t intrsenabled_fn; /* check if interrupts are enabled */
  77. void *pch; /* PCI/E core handle */
  78. gpioh_item_t *gpioh_head; /* GPIO event handlers list */
  79. bool memseg; /* flag to toggle MEM_SEG register */
  80. char *vars;
  81. uint varsz;
  82. void *curmap; /* current regs va */
  83. uint curidx; /* current core index */
  84. uint numcores; /* # discovered cores */
  85. void *curwrap; /* current wrapper va */
  86. uint32 oob_router; /* oob router registers for axi */
  87. void *cores_info;
  88. gci_gpio_item_t *gci_gpio_head; /* gci gpio interrupts head */
  89. } si_info_t;
  90. #define SI_INFO(sih) ((si_info_t *)(uintptr)sih)
  91. #define GOODCOREADDR(x, b) (((x) >= (b)) && ((x) < ((b) + SI_MAXCORES * SI_CORE_SIZE)) && \
  92. ISALIGNED((x), SI_CORE_SIZE))
  93. #define GOODREGS(regs) ((regs) != NULL && ISALIGNED((uintptr)(regs), SI_CORE_SIZE))
  94. #define BADCOREADDR 0
  95. #define GOODIDX(idx) (((uint)idx) < SI_MAXCORES)
  96. #define NOREV -1 /* Invalid rev */
  97. #define PCI(si) ((BUSTYPE((si)->pub.bustype) == PCI_BUS) && \
  98. ((si)->pub.buscoretype == PCI_CORE_ID))
  99. #define PCIE_GEN1(si) ((BUSTYPE((si)->pub.bustype) == PCI_BUS) && \
  100. ((si)->pub.buscoretype == PCIE_CORE_ID))
  101. #define PCIE_GEN2(si) ((BUSTYPE((si)->pub.bustype) == PCI_BUS) && \
  102. ((si)->pub.buscoretype == PCIE2_CORE_ID))
  103. #define PCIE(si) (PCIE_GEN1(si) || PCIE_GEN2(si))
  104. #define PCMCIA(si) ((BUSTYPE((si)->pub.bustype) == PCMCIA_BUS) && ((si)->memseg == TRUE))
  105. /* Newer chips can access PCI/PCIE and CC core without requiring to change
  106. * PCI BAR0 WIN
  107. */
  108. #define SI_FAST(si) (PCIE(si) || (PCI(si) && ((si)->pub.buscorerev >= 13)))
  109. #define PCIEREGS(si) (((char *)((si)->curmap) + PCI_16KB0_PCIREGS_OFFSET))
  110. #define CCREGS_FAST(si) (((char *)((si)->curmap) + PCI_16KB0_CCREGS_OFFSET))
  111. /*
  112. * Macros to disable/restore function core(D11, ENET, ILINE20, etc) interrupts before/
  113. * after core switching to avoid invalid register accesss inside ISR.
  114. */
  115. #define INTR_OFF(si, intr_val) \
  116. if ((si)->intrsoff_fn && (cores_info)->coreid[(si)->curidx] == (si)->dev_coreid) { \
  117. intr_val = (*(si)->intrsoff_fn)((si)->intr_arg); }
  118. #define INTR_RESTORE(si, intr_val) \
  119. if ((si)->intrsrestore_fn && (cores_info)->coreid[(si)->curidx] == (si)->dev_coreid) { \
  120. (*(si)->intrsrestore_fn)((si)->intr_arg, intr_val); }
  121. /* dynamic clock control defines */
  122. #define LPOMINFREQ 25000 /* low power oscillator min */
  123. #define LPOMAXFREQ 43000 /* low power oscillator max */
  124. #define XTALMINFREQ 19800000 /* 20 MHz - 1% */
  125. #define XTALMAXFREQ 20200000 /* 20 MHz + 1% */
  126. #define PCIMINFREQ 25000000 /* 25 MHz */
  127. #define PCIMAXFREQ 34000000 /* 33 MHz + fudge */
  128. #define ILP_DIV_5MHZ 0 /* ILP = 5 MHz */
  129. #define ILP_DIV_1MHZ 4 /* ILP = 1 MHz */
  130. /* Force fast clock for 4360b0 */
  131. #define PCI_FORCEHT(si) \
  132. (((PCIE_GEN1(si)) && (si->pub.chip == BCM4311_CHIP_ID) && ((si->pub.chiprev <= 1))) || \
  133. ((PCI(si) || PCIE_GEN1(si)) && (si->pub.chip == BCM4321_CHIP_ID)) || \
  134. (PCIE_GEN1(si) && (si->pub.chip == BCM4716_CHIP_ID)) || \
  135. (PCIE_GEN1(si) && (si->pub.chip == BCM4748_CHIP_ID)))
  136. /* GPIO Based LED powersave defines */
  137. #define DEFAULT_GPIO_ONTIME 10 /* Default: 10% on */
  138. #define DEFAULT_GPIO_OFFTIME 90 /* Default: 10% on */
  139. #ifndef DEFAULT_GPIOTIMERVAL
  140. #define DEFAULT_GPIOTIMERVAL ((DEFAULT_GPIO_ONTIME << GPIO_ONTIME_SHIFT) | DEFAULT_GPIO_OFFTIME)
  141. #endif
  142. /* Silicon Backplane externs */
  143. extern void sb_scan(si_t *sih, void *regs, uint devid);
  144. extern uint sb_coreid(si_t *sih);
  145. extern uint sb_intflag(si_t *sih);
  146. extern uint sb_flag(si_t *sih);
  147. extern void sb_setint(si_t *sih, int siflag);
  148. extern uint sb_corevendor(si_t *sih);
  149. extern uint sb_corerev(si_t *sih);
  150. extern uint sb_corereg(si_t *sih, uint coreidx, uint regoff, uint mask, uint val);
  151. extern uint32 *sb_corereg_addr(si_t *sih, uint coreidx, uint regoff);
  152. extern bool sb_iscoreup(si_t *sih);
  153. extern void *sb_setcoreidx(si_t *sih, uint coreidx);
  154. extern uint32 sb_core_cflags(si_t *sih, uint32 mask, uint32 val);
  155. extern void sb_core_cflags_wo(si_t *sih, uint32 mask, uint32 val);
  156. extern uint32 sb_core_sflags(si_t *sih, uint32 mask, uint32 val);
  157. extern void sb_commit(si_t *sih);
  158. extern uint32 sb_base(uint32 admatch);
  159. extern uint32 sb_size(uint32 admatch);
  160. extern void sb_core_reset(si_t *sih, uint32 bits, uint32 resetbits);
  161. extern void sb_core_disable(si_t *sih, uint32 bits);
  162. extern uint32 sb_addrspace(si_t *sih, uint asidx);
  163. extern uint32 sb_addrspacesize(si_t *sih, uint asidx);
  164. extern int sb_numaddrspaces(si_t *sih);
  165. extern uint32 sb_set_initiator_to(si_t *sih, uint32 to, uint idx);
  166. extern bool sb_taclear(si_t *sih, bool details);
  167. /* Wake-on-wireless-LAN (WOWL) */
  168. extern bool sb_pci_pmecap(si_t *sih);
  169. struct osl_info;
  170. extern bool sb_pci_fastpmecap(struct osl_info *osh);
  171. extern bool sb_pci_pmeclr(si_t *sih);
  172. extern void sb_pci_pmeen(si_t *sih);
  173. extern uint sb_pcie_readreg(void *sih, uint addrtype, uint offset);
  174. /* AMBA Interconnect exported externs */
  175. extern si_t *ai_attach(uint pcidev, osl_t *osh, void *regs, uint bustype,
  176. void *sdh, char **vars, uint *varsz);
  177. extern si_t *ai_kattach(osl_t *osh);
  178. extern void ai_scan(si_t *sih, void *regs, uint devid);
  179. extern uint ai_flag(si_t *sih);
  180. extern uint ai_flag_alt(si_t *sih);
  181. extern void ai_setint(si_t *sih, int siflag);
  182. extern uint ai_coreidx(si_t *sih);
  183. extern uint ai_corevendor(si_t *sih);
  184. extern uint ai_corerev(si_t *sih);
  185. extern uint32 *ai_corereg_addr(si_t *sih, uint coreidx, uint regoff);
  186. extern bool ai_iscoreup(si_t *sih);
  187. extern void *ai_setcoreidx(si_t *sih, uint coreidx);
  188. extern uint32 ai_core_cflags(si_t *sih, uint32 mask, uint32 val);
  189. extern void ai_core_cflags_wo(si_t *sih, uint32 mask, uint32 val);
  190. extern uint32 ai_core_sflags(si_t *sih, uint32 mask, uint32 val);
  191. extern uint ai_corereg(si_t *sih, uint coreidx, uint regoff, uint mask, uint val);
  192. extern void ai_core_reset(si_t *sih, uint32 bits, uint32 resetbits);
  193. extern void ai_core_disable(si_t *sih, uint32 bits);
  194. extern int ai_numaddrspaces(si_t *sih);
  195. extern uint32 ai_addrspace(si_t *sih, uint asidx);
  196. extern uint32 ai_addrspacesize(si_t *sih, uint asidx);
  197. extern void ai_coreaddrspaceX(si_t *sih, uint asidx, uint32 *addr, uint32 *size);
  198. extern uint ai_wrap_reg(si_t *sih, uint32 offset, uint32 mask, uint32 val);
  199. #define ub_scan(a, b, c) do {} while (0)
  200. #define ub_flag(a) (0)
  201. #define ub_setint(a, b) do {} while (0)
  202. #define ub_coreidx(a) (0)
  203. #define ub_corevendor(a) (0)
  204. #define ub_corerev(a) (0)
  205. #define ub_iscoreup(a) (0)
  206. #define ub_setcoreidx(a, b) (0)
  207. #define ub_core_cflags(a, b, c) (0)
  208. #define ub_core_cflags_wo(a, b, c) do {} while (0)
  209. #define ub_core_sflags(a, b, c) (0)
  210. #define ub_corereg(a, b, c, d, e) (0)
  211. #define ub_core_reset(a, b, c) do {} while (0)
  212. #define ub_core_disable(a, b) do {} while (0)
  213. #define ub_numaddrspaces(a) (0)
  214. #define ub_addrspace(a, b) (0)
  215. #define ub_addrspacesize(a, b) (0)
  216. #define ub_view(a, b) do {} while (0)
  217. #define ub_dumpregs(a, b) do {} while (0)
  218. #endif /* _siutils_priv_h_ */