prom_irqtrans.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  1. #include <linux/kernel.h>
  2. #include <linux/string.h>
  3. #include <linux/init.h>
  4. #include <linux/of.h>
  5. #include <linux/of_platform.h>
  6. #include <asm/oplib.h>
  7. #include <asm/prom.h>
  8. #include <asm/irq.h>
  9. #include <asm/upa.h>
  10. #include "prom.h"
  11. #ifdef CONFIG_PCI
  12. /* PSYCHO interrupt mapping support. */
  13. #define PSYCHO_IMAP_A_SLOT0 0x0c00UL
  14. #define PSYCHO_IMAP_B_SLOT0 0x0c20UL
  15. static unsigned long psycho_pcislot_imap_offset(unsigned long ino)
  16. {
  17. unsigned int bus = (ino & 0x10) >> 4;
  18. unsigned int slot = (ino & 0x0c) >> 2;
  19. if (bus == 0)
  20. return PSYCHO_IMAP_A_SLOT0 + (slot * 8);
  21. else
  22. return PSYCHO_IMAP_B_SLOT0 + (slot * 8);
  23. }
  24. #define PSYCHO_OBIO_IMAP_BASE 0x1000UL
  25. #define PSYCHO_ONBOARD_IRQ_BASE 0x20
  26. #define psycho_onboard_imap_offset(__ino) \
  27. (PSYCHO_OBIO_IMAP_BASE + (((__ino) & 0x1f) << 3))
  28. #define PSYCHO_ICLR_A_SLOT0 0x1400UL
  29. #define PSYCHO_ICLR_SCSI 0x1800UL
  30. #define psycho_iclr_offset(ino) \
  31. ((ino & 0x20) ? (PSYCHO_ICLR_SCSI + (((ino) & 0x1f) << 3)) : \
  32. (PSYCHO_ICLR_A_SLOT0 + (((ino) & 0x1f)<<3)))
  33. static unsigned int psycho_irq_build(struct device_node *dp,
  34. unsigned int ino,
  35. void *_data)
  36. {
  37. unsigned long controller_regs = (unsigned long) _data;
  38. unsigned long imap, iclr;
  39. unsigned long imap_off, iclr_off;
  40. int inofixup = 0;
  41. ino &= 0x3f;
  42. if (ino < PSYCHO_ONBOARD_IRQ_BASE) {
  43. /* PCI slot */
  44. imap_off = psycho_pcislot_imap_offset(ino);
  45. } else {
  46. /* Onboard device */
  47. imap_off = psycho_onboard_imap_offset(ino);
  48. }
  49. /* Now build the IRQ bucket. */
  50. imap = controller_regs + imap_off;
  51. iclr_off = psycho_iclr_offset(ino);
  52. iclr = controller_regs + iclr_off;
  53. if ((ino & 0x20) == 0)
  54. inofixup = ino & 0x03;
  55. return build_irq(inofixup, iclr, imap);
  56. }
  57. static void __init psycho_irq_trans_init(struct device_node *dp)
  58. {
  59. const struct linux_prom64_registers *regs;
  60. dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
  61. dp->irq_trans->irq_build = psycho_irq_build;
  62. regs = of_get_property(dp, "reg", NULL);
  63. dp->irq_trans->data = (void *) regs[2].phys_addr;
  64. }
  65. #define sabre_read(__reg) \
  66. ({ u64 __ret; \
  67. __asm__ __volatile__("ldxa [%1] %2, %0" \
  68. : "=r" (__ret) \
  69. : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
  70. : "memory"); \
  71. __ret; \
  72. })
  73. struct sabre_irq_data {
  74. unsigned long controller_regs;
  75. unsigned int pci_first_busno;
  76. };
  77. #define SABRE_CONFIGSPACE 0x001000000UL
  78. #define SABRE_WRSYNC 0x1c20UL
  79. #define SABRE_CONFIG_BASE(CONFIG_SPACE) \
  80. (CONFIG_SPACE | (1UL << 24))
  81. #define SABRE_CONFIG_ENCODE(BUS, DEVFN, REG) \
  82. (((unsigned long)(BUS) << 16) | \
  83. ((unsigned long)(DEVFN) << 8) | \
  84. ((unsigned long)(REG)))
  85. /* When a device lives behind a bridge deeper in the PCI bus topology
  86. * than APB, a special sequence must run to make sure all pending DMA
  87. * transfers at the time of IRQ delivery are visible in the coherency
  88. * domain by the cpu. This sequence is to perform a read on the far
  89. * side of the non-APB bridge, then perform a read of Sabre's DMA
  90. * write-sync register.
  91. */
  92. static void sabre_wsync_handler(unsigned int ino, void *_arg1, void *_arg2)
  93. {
  94. unsigned int phys_hi = (unsigned int) (unsigned long) _arg1;
  95. struct sabre_irq_data *irq_data = _arg2;
  96. unsigned long controller_regs = irq_data->controller_regs;
  97. unsigned long sync_reg = controller_regs + SABRE_WRSYNC;
  98. unsigned long config_space = controller_regs + SABRE_CONFIGSPACE;
  99. unsigned int bus, devfn;
  100. u16 _unused;
  101. config_space = SABRE_CONFIG_BASE(config_space);
  102. bus = (phys_hi >> 16) & 0xff;
  103. devfn = (phys_hi >> 8) & 0xff;
  104. config_space |= SABRE_CONFIG_ENCODE(bus, devfn, 0x00);
  105. __asm__ __volatile__("membar #Sync\n\t"
  106. "lduha [%1] %2, %0\n\t"
  107. "membar #Sync"
  108. : "=r" (_unused)
  109. : "r" ((u16 *) config_space),
  110. "i" (ASI_PHYS_BYPASS_EC_E_L)
  111. : "memory");
  112. sabre_read(sync_reg);
  113. }
  114. #define SABRE_IMAP_A_SLOT0 0x0c00UL
  115. #define SABRE_IMAP_B_SLOT0 0x0c20UL
  116. #define SABRE_ICLR_A_SLOT0 0x1400UL
  117. #define SABRE_ICLR_B_SLOT0 0x1480UL
  118. #define SABRE_ICLR_SCSI 0x1800UL
  119. #define SABRE_ICLR_ETH 0x1808UL
  120. #define SABRE_ICLR_BPP 0x1810UL
  121. #define SABRE_ICLR_AU_REC 0x1818UL
  122. #define SABRE_ICLR_AU_PLAY 0x1820UL
  123. #define SABRE_ICLR_PFAIL 0x1828UL
  124. #define SABRE_ICLR_KMS 0x1830UL
  125. #define SABRE_ICLR_FLPY 0x1838UL
  126. #define SABRE_ICLR_SHW 0x1840UL
  127. #define SABRE_ICLR_KBD 0x1848UL
  128. #define SABRE_ICLR_MS 0x1850UL
  129. #define SABRE_ICLR_SER 0x1858UL
  130. #define SABRE_ICLR_UE 0x1870UL
  131. #define SABRE_ICLR_CE 0x1878UL
  132. #define SABRE_ICLR_PCIERR 0x1880UL
  133. static unsigned long sabre_pcislot_imap_offset(unsigned long ino)
  134. {
  135. unsigned int bus = (ino & 0x10) >> 4;
  136. unsigned int slot = (ino & 0x0c) >> 2;
  137. if (bus == 0)
  138. return SABRE_IMAP_A_SLOT0 + (slot * 8);
  139. else
  140. return SABRE_IMAP_B_SLOT0 + (slot * 8);
  141. }
  142. #define SABRE_OBIO_IMAP_BASE 0x1000UL
  143. #define SABRE_ONBOARD_IRQ_BASE 0x20
  144. #define sabre_onboard_imap_offset(__ino) \
  145. (SABRE_OBIO_IMAP_BASE + (((__ino) & 0x1f) << 3))
  146. #define sabre_iclr_offset(ino) \
  147. ((ino & 0x20) ? (SABRE_ICLR_SCSI + (((ino) & 0x1f) << 3)) : \
  148. (SABRE_ICLR_A_SLOT0 + (((ino) & 0x1f)<<3)))
  149. static int sabre_device_needs_wsync(struct device_node *dp)
  150. {
  151. struct device_node *parent = dp->parent;
  152. const char *parent_model, *parent_compat;
  153. /* This traversal up towards the root is meant to
  154. * handle two cases:
  155. *
  156. * 1) non-PCI bus sitting under PCI, such as 'ebus'
  157. * 2) the PCI controller interrupts themselves, which
  158. * will use the sabre_irq_build but do not need
  159. * the DMA synchronization handling
  160. */
  161. while (parent) {
  162. if (!strcmp(parent->type, "pci"))
  163. break;
  164. parent = parent->parent;
  165. }
  166. if (!parent)
  167. return 0;
  168. parent_model = of_get_property(parent,
  169. "model", NULL);
  170. if (parent_model &&
  171. (!strcmp(parent_model, "SUNW,sabre") ||
  172. !strcmp(parent_model, "SUNW,simba")))
  173. return 0;
  174. parent_compat = of_get_property(parent,
  175. "compatible", NULL);
  176. if (parent_compat &&
  177. (!strcmp(parent_compat, "pci108e,a000") ||
  178. !strcmp(parent_compat, "pci108e,a001")))
  179. return 0;
  180. return 1;
  181. }
  182. static unsigned int sabre_irq_build(struct device_node *dp,
  183. unsigned int ino,
  184. void *_data)
  185. {
  186. struct sabre_irq_data *irq_data = _data;
  187. unsigned long controller_regs = irq_data->controller_regs;
  188. const struct linux_prom_pci_registers *regs;
  189. unsigned long imap, iclr;
  190. unsigned long imap_off, iclr_off;
  191. int inofixup = 0;
  192. int irq;
  193. ino &= 0x3f;
  194. if (ino < SABRE_ONBOARD_IRQ_BASE) {
  195. /* PCI slot */
  196. imap_off = sabre_pcislot_imap_offset(ino);
  197. } else {
  198. /* onboard device */
  199. imap_off = sabre_onboard_imap_offset(ino);
  200. }
  201. /* Now build the IRQ bucket. */
  202. imap = controller_regs + imap_off;
  203. iclr_off = sabre_iclr_offset(ino);
  204. iclr = controller_regs + iclr_off;
  205. if ((ino & 0x20) == 0)
  206. inofixup = ino & 0x03;
  207. irq = build_irq(inofixup, iclr, imap);
  208. /* If the parent device is a PCI<->PCI bridge other than
  209. * APB, we have to install a pre-handler to ensure that
  210. * all pending DMA is drained before the interrupt handler
  211. * is run.
  212. */
  213. regs = of_get_property(dp, "reg", NULL);
  214. if (regs && sabre_device_needs_wsync(dp)) {
  215. irq_install_pre_handler(irq,
  216. sabre_wsync_handler,
  217. (void *) (long) regs->phys_hi,
  218. (void *) irq_data);
  219. }
  220. return irq;
  221. }
  222. static void __init sabre_irq_trans_init(struct device_node *dp)
  223. {
  224. const struct linux_prom64_registers *regs;
  225. struct sabre_irq_data *irq_data;
  226. const u32 *busrange;
  227. dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
  228. dp->irq_trans->irq_build = sabre_irq_build;
  229. irq_data = prom_early_alloc(sizeof(struct sabre_irq_data));
  230. regs = of_get_property(dp, "reg", NULL);
  231. irq_data->controller_regs = regs[0].phys_addr;
  232. busrange = of_get_property(dp, "bus-range", NULL);
  233. irq_data->pci_first_busno = busrange[0];
  234. dp->irq_trans->data = irq_data;
  235. }
  236. /* SCHIZO interrupt mapping support. Unlike Psycho, for this controller the
  237. * imap/iclr registers are per-PBM.
  238. */
  239. #define SCHIZO_IMAP_BASE 0x1000UL
  240. #define SCHIZO_ICLR_BASE 0x1400UL
  241. static unsigned long schizo_imap_offset(unsigned long ino)
  242. {
  243. return SCHIZO_IMAP_BASE + (ino * 8UL);
  244. }
  245. static unsigned long schizo_iclr_offset(unsigned long ino)
  246. {
  247. return SCHIZO_ICLR_BASE + (ino * 8UL);
  248. }
  249. static unsigned long schizo_ino_to_iclr(unsigned long pbm_regs,
  250. unsigned int ino)
  251. {
  252. return pbm_regs + schizo_iclr_offset(ino);
  253. }
  254. static unsigned long schizo_ino_to_imap(unsigned long pbm_regs,
  255. unsigned int ino)
  256. {
  257. return pbm_regs + schizo_imap_offset(ino);
  258. }
  259. #define schizo_read(__reg) \
  260. ({ u64 __ret; \
  261. __asm__ __volatile__("ldxa [%1] %2, %0" \
  262. : "=r" (__ret) \
  263. : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
  264. : "memory"); \
  265. __ret; \
  266. })
  267. #define schizo_write(__reg, __val) \
  268. __asm__ __volatile__("stxa %0, [%1] %2" \
  269. : /* no outputs */ \
  270. : "r" (__val), "r" (__reg), \
  271. "i" (ASI_PHYS_BYPASS_EC_E) \
  272. : "memory")
  273. static void tomatillo_wsync_handler(unsigned int ino, void *_arg1, void *_arg2)
  274. {
  275. unsigned long sync_reg = (unsigned long) _arg2;
  276. u64 mask = 1UL << (ino & IMAP_INO);
  277. u64 val;
  278. int limit;
  279. schizo_write(sync_reg, mask);
  280. limit = 100000;
  281. val = 0;
  282. while (--limit) {
  283. val = schizo_read(sync_reg);
  284. if (!(val & mask))
  285. break;
  286. }
  287. if (limit <= 0) {
  288. printk("tomatillo_wsync_handler: DMA won't sync [%llx:%llx]\n",
  289. val, mask);
  290. }
  291. if (_arg1) {
  292. static unsigned char cacheline[64]
  293. __attribute__ ((aligned (64)));
  294. __asm__ __volatile__("rd %%fprs, %0\n\t"
  295. "or %0, %4, %1\n\t"
  296. "wr %1, 0x0, %%fprs\n\t"
  297. "stda %%f0, [%5] %6\n\t"
  298. "wr %0, 0x0, %%fprs\n\t"
  299. "membar #Sync"
  300. : "=&r" (mask), "=&r" (val)
  301. : "0" (mask), "1" (val),
  302. "i" (FPRS_FEF), "r" (&cacheline[0]),
  303. "i" (ASI_BLK_COMMIT_P));
  304. }
  305. }
  306. struct schizo_irq_data {
  307. unsigned long pbm_regs;
  308. unsigned long sync_reg;
  309. u32 portid;
  310. int chip_version;
  311. };
  312. static unsigned int schizo_irq_build(struct device_node *dp,
  313. unsigned int ino,
  314. void *_data)
  315. {
  316. struct schizo_irq_data *irq_data = _data;
  317. unsigned long pbm_regs = irq_data->pbm_regs;
  318. unsigned long imap, iclr;
  319. int ign_fixup;
  320. int irq;
  321. int is_tomatillo;
  322. ino &= 0x3f;
  323. /* Now build the IRQ bucket. */
  324. imap = schizo_ino_to_imap(pbm_regs, ino);
  325. iclr = schizo_ino_to_iclr(pbm_regs, ino);
  326. /* On Schizo, no inofixup occurs. This is because each
  327. * INO has it's own IMAP register. On Psycho and Sabre
  328. * there is only one IMAP register for each PCI slot even
  329. * though four different INOs can be generated by each
  330. * PCI slot.
  331. *
  332. * But, for JBUS variants (essentially, Tomatillo), we have
  333. * to fixup the lowest bit of the interrupt group number.
  334. */
  335. ign_fixup = 0;
  336. is_tomatillo = (irq_data->sync_reg != 0UL);
  337. if (is_tomatillo) {
  338. if (irq_data->portid & 1)
  339. ign_fixup = (1 << 6);
  340. }
  341. irq = build_irq(ign_fixup, iclr, imap);
  342. if (is_tomatillo) {
  343. irq_install_pre_handler(irq,
  344. tomatillo_wsync_handler,
  345. ((irq_data->chip_version <= 4) ?
  346. (void *) 1 : (void *) 0),
  347. (void *) irq_data->sync_reg);
  348. }
  349. return irq;
  350. }
  351. static void __init __schizo_irq_trans_init(struct device_node *dp,
  352. int is_tomatillo)
  353. {
  354. const struct linux_prom64_registers *regs;
  355. struct schizo_irq_data *irq_data;
  356. dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
  357. dp->irq_trans->irq_build = schizo_irq_build;
  358. irq_data = prom_early_alloc(sizeof(struct schizo_irq_data));
  359. regs = of_get_property(dp, "reg", NULL);
  360. dp->irq_trans->data = irq_data;
  361. irq_data->pbm_regs = regs[0].phys_addr;
  362. if (is_tomatillo)
  363. irq_data->sync_reg = regs[3].phys_addr + 0x1a18UL;
  364. else
  365. irq_data->sync_reg = 0UL;
  366. irq_data->portid = of_getintprop_default(dp, "portid", 0);
  367. irq_data->chip_version = of_getintprop_default(dp, "version#", 0);
  368. }
  369. static void __init schizo_irq_trans_init(struct device_node *dp)
  370. {
  371. __schizo_irq_trans_init(dp, 0);
  372. }
  373. static void __init tomatillo_irq_trans_init(struct device_node *dp)
  374. {
  375. __schizo_irq_trans_init(dp, 1);
  376. }
  377. static unsigned int pci_sun4v_irq_build(struct device_node *dp,
  378. unsigned int devino,
  379. void *_data)
  380. {
  381. u32 devhandle = (u32) (unsigned long) _data;
  382. return sun4v_build_irq(devhandle, devino);
  383. }
  384. static void __init pci_sun4v_irq_trans_init(struct device_node *dp)
  385. {
  386. const struct linux_prom64_registers *regs;
  387. dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
  388. dp->irq_trans->irq_build = pci_sun4v_irq_build;
  389. regs = of_get_property(dp, "reg", NULL);
  390. dp->irq_trans->data = (void *) (unsigned long)
  391. ((regs->phys_addr >> 32UL) & 0x0fffffff);
  392. }
  393. struct fire_irq_data {
  394. unsigned long pbm_regs;
  395. u32 portid;
  396. };
  397. #define FIRE_IMAP_BASE 0x001000
  398. #define FIRE_ICLR_BASE 0x001400
  399. static unsigned long fire_imap_offset(unsigned long ino)
  400. {
  401. return FIRE_IMAP_BASE + (ino * 8UL);
  402. }
  403. static unsigned long fire_iclr_offset(unsigned long ino)
  404. {
  405. return FIRE_ICLR_BASE + (ino * 8UL);
  406. }
  407. static unsigned long fire_ino_to_iclr(unsigned long pbm_regs,
  408. unsigned int ino)
  409. {
  410. return pbm_regs + fire_iclr_offset(ino);
  411. }
  412. static unsigned long fire_ino_to_imap(unsigned long pbm_regs,
  413. unsigned int ino)
  414. {
  415. return pbm_regs + fire_imap_offset(ino);
  416. }
  417. static unsigned int fire_irq_build(struct device_node *dp,
  418. unsigned int ino,
  419. void *_data)
  420. {
  421. struct fire_irq_data *irq_data = _data;
  422. unsigned long pbm_regs = irq_data->pbm_regs;
  423. unsigned long imap, iclr;
  424. unsigned long int_ctrlr;
  425. ino &= 0x3f;
  426. /* Now build the IRQ bucket. */
  427. imap = fire_ino_to_imap(pbm_regs, ino);
  428. iclr = fire_ino_to_iclr(pbm_regs, ino);
  429. /* Set the interrupt controller number. */
  430. int_ctrlr = 1 << 6;
  431. upa_writeq(int_ctrlr, imap);
  432. /* The interrupt map registers do not have an INO field
  433. * like other chips do. They return zero in the INO
  434. * field, and the interrupt controller number is controlled
  435. * in bits 6 to 9. So in order for build_irq() to get
  436. * the INO right we pass it in as part of the fixup
  437. * which will get added to the map register zero value
  438. * read by build_irq().
  439. */
  440. ino |= (irq_data->portid << 6);
  441. ino -= int_ctrlr;
  442. return build_irq(ino, iclr, imap);
  443. }
  444. static void __init fire_irq_trans_init(struct device_node *dp)
  445. {
  446. const struct linux_prom64_registers *regs;
  447. struct fire_irq_data *irq_data;
  448. dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
  449. dp->irq_trans->irq_build = fire_irq_build;
  450. irq_data = prom_early_alloc(sizeof(struct fire_irq_data));
  451. regs = of_get_property(dp, "reg", NULL);
  452. dp->irq_trans->data = irq_data;
  453. irq_data->pbm_regs = regs[0].phys_addr;
  454. irq_data->portid = of_getintprop_default(dp, "portid", 0);
  455. }
  456. #endif /* CONFIG_PCI */
  457. #ifdef CONFIG_SBUS
  458. /* INO number to IMAP register offset for SYSIO external IRQ's.
  459. * This should conform to both Sunfire/Wildfire server and Fusion
  460. * desktop designs.
  461. */
  462. #define SYSIO_IMAP_SLOT0 0x2c00UL
  463. #define SYSIO_IMAP_SLOT1 0x2c08UL
  464. #define SYSIO_IMAP_SLOT2 0x2c10UL
  465. #define SYSIO_IMAP_SLOT3 0x2c18UL
  466. #define SYSIO_IMAP_SCSI 0x3000UL
  467. #define SYSIO_IMAP_ETH 0x3008UL
  468. #define SYSIO_IMAP_BPP 0x3010UL
  469. #define SYSIO_IMAP_AUDIO 0x3018UL
  470. #define SYSIO_IMAP_PFAIL 0x3020UL
  471. #define SYSIO_IMAP_KMS 0x3028UL
  472. #define SYSIO_IMAP_FLPY 0x3030UL
  473. #define SYSIO_IMAP_SHW 0x3038UL
  474. #define SYSIO_IMAP_KBD 0x3040UL
  475. #define SYSIO_IMAP_MS 0x3048UL
  476. #define SYSIO_IMAP_SER 0x3050UL
  477. #define SYSIO_IMAP_TIM0 0x3060UL
  478. #define SYSIO_IMAP_TIM1 0x3068UL
  479. #define SYSIO_IMAP_UE 0x3070UL
  480. #define SYSIO_IMAP_CE 0x3078UL
  481. #define SYSIO_IMAP_SBERR 0x3080UL
  482. #define SYSIO_IMAP_PMGMT 0x3088UL
  483. #define SYSIO_IMAP_GFX 0x3090UL
  484. #define SYSIO_IMAP_EUPA 0x3098UL
  485. #define bogon ((unsigned long) -1)
  486. static unsigned long sysio_irq_offsets[] = {
  487. /* SBUS Slot 0 --> 3, level 1 --> 7 */
  488. SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0,
  489. SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0,
  490. SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1,
  491. SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1,
  492. SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2,
  493. SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2,
  494. SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3,
  495. SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3,
  496. /* Onboard devices (not relevant/used on SunFire). */
  497. SYSIO_IMAP_SCSI,
  498. SYSIO_IMAP_ETH,
  499. SYSIO_IMAP_BPP,
  500. bogon,
  501. SYSIO_IMAP_AUDIO,
  502. SYSIO_IMAP_PFAIL,
  503. bogon,
  504. bogon,
  505. SYSIO_IMAP_KMS,
  506. SYSIO_IMAP_FLPY,
  507. SYSIO_IMAP_SHW,
  508. SYSIO_IMAP_KBD,
  509. SYSIO_IMAP_MS,
  510. SYSIO_IMAP_SER,
  511. bogon,
  512. bogon,
  513. SYSIO_IMAP_TIM0,
  514. SYSIO_IMAP_TIM1,
  515. bogon,
  516. bogon,
  517. SYSIO_IMAP_UE,
  518. SYSIO_IMAP_CE,
  519. SYSIO_IMAP_SBERR,
  520. SYSIO_IMAP_PMGMT,
  521. SYSIO_IMAP_GFX,
  522. SYSIO_IMAP_EUPA,
  523. };
  524. #undef bogon
  525. #define NUM_SYSIO_OFFSETS ARRAY_SIZE(sysio_irq_offsets)
  526. /* Convert Interrupt Mapping register pointer to associated
  527. * Interrupt Clear register pointer, SYSIO specific version.
  528. */
  529. #define SYSIO_ICLR_UNUSED0 0x3400UL
  530. #define SYSIO_ICLR_SLOT0 0x3408UL
  531. #define SYSIO_ICLR_SLOT1 0x3448UL
  532. #define SYSIO_ICLR_SLOT2 0x3488UL
  533. #define SYSIO_ICLR_SLOT3 0x34c8UL
  534. static unsigned long sysio_imap_to_iclr(unsigned long imap)
  535. {
  536. unsigned long diff = SYSIO_ICLR_UNUSED0 - SYSIO_IMAP_SLOT0;
  537. return imap + diff;
  538. }
  539. static unsigned int sbus_of_build_irq(struct device_node *dp,
  540. unsigned int ino,
  541. void *_data)
  542. {
  543. unsigned long reg_base = (unsigned long) _data;
  544. const struct linux_prom_registers *regs;
  545. unsigned long imap, iclr;
  546. int sbus_slot = 0;
  547. int sbus_level = 0;
  548. ino &= 0x3f;
  549. regs = of_get_property(dp, "reg", NULL);
  550. if (regs)
  551. sbus_slot = regs->which_io;
  552. if (ino < 0x20)
  553. ino += (sbus_slot * 8);
  554. imap = sysio_irq_offsets[ino];
  555. if (imap == ((unsigned long)-1)) {
  556. prom_printf("get_irq_translations: Bad SYSIO INO[%x]\n",
  557. ino);
  558. prom_halt();
  559. }
  560. imap += reg_base;
  561. /* SYSIO inconsistency. For external SLOTS, we have to select
  562. * the right ICLR register based upon the lower SBUS irq level
  563. * bits.
  564. */
  565. if (ino >= 0x20) {
  566. iclr = sysio_imap_to_iclr(imap);
  567. } else {
  568. sbus_level = ino & 0x7;
  569. switch(sbus_slot) {
  570. case 0:
  571. iclr = reg_base + SYSIO_ICLR_SLOT0;
  572. break;
  573. case 1:
  574. iclr = reg_base + SYSIO_ICLR_SLOT1;
  575. break;
  576. case 2:
  577. iclr = reg_base + SYSIO_ICLR_SLOT2;
  578. break;
  579. default:
  580. case 3:
  581. iclr = reg_base + SYSIO_ICLR_SLOT3;
  582. break;
  583. }
  584. iclr += ((unsigned long)sbus_level - 1UL) * 8UL;
  585. }
  586. return build_irq(sbus_level, iclr, imap);
  587. }
  588. static void __init sbus_irq_trans_init(struct device_node *dp)
  589. {
  590. const struct linux_prom64_registers *regs;
  591. dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
  592. dp->irq_trans->irq_build = sbus_of_build_irq;
  593. regs = of_get_property(dp, "reg", NULL);
  594. dp->irq_trans->data = (void *) (unsigned long) regs->phys_addr;
  595. }
  596. #endif /* CONFIG_SBUS */
  597. static unsigned int central_build_irq(struct device_node *dp,
  598. unsigned int ino,
  599. void *_data)
  600. {
  601. struct device_node *central_dp = _data;
  602. struct platform_device *central_op = of_find_device_by_node(central_dp);
  603. struct resource *res;
  604. unsigned long imap, iclr;
  605. u32 tmp;
  606. if (!strcmp(dp->name, "eeprom")) {
  607. res = &central_op->resource[5];
  608. } else if (!strcmp(dp->name, "zs")) {
  609. res = &central_op->resource[4];
  610. } else if (!strcmp(dp->name, "clock-board")) {
  611. res = &central_op->resource[3];
  612. } else {
  613. return ino;
  614. }
  615. imap = res->start + 0x00UL;
  616. iclr = res->start + 0x10UL;
  617. /* Set the INO state to idle, and disable. */
  618. upa_writel(0, iclr);
  619. upa_readl(iclr);
  620. tmp = upa_readl(imap);
  621. tmp &= ~0x80000000;
  622. upa_writel(tmp, imap);
  623. return build_irq(0, iclr, imap);
  624. }
  625. static void __init central_irq_trans_init(struct device_node *dp)
  626. {
  627. dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
  628. dp->irq_trans->irq_build = central_build_irq;
  629. dp->irq_trans->data = dp;
  630. }
  631. struct irq_trans {
  632. const char *name;
  633. void (*init)(struct device_node *);
  634. };
  635. #ifdef CONFIG_PCI
  636. static struct irq_trans __initdata pci_irq_trans_table[] = {
  637. { "SUNW,sabre", sabre_irq_trans_init },
  638. { "pci108e,a000", sabre_irq_trans_init },
  639. { "pci108e,a001", sabre_irq_trans_init },
  640. { "SUNW,psycho", psycho_irq_trans_init },
  641. { "pci108e,8000", psycho_irq_trans_init },
  642. { "SUNW,schizo", schizo_irq_trans_init },
  643. { "pci108e,8001", schizo_irq_trans_init },
  644. { "SUNW,schizo+", schizo_irq_trans_init },
  645. { "pci108e,8002", schizo_irq_trans_init },
  646. { "SUNW,tomatillo", tomatillo_irq_trans_init },
  647. { "pci108e,a801", tomatillo_irq_trans_init },
  648. { "SUNW,sun4v-pci", pci_sun4v_irq_trans_init },
  649. { "pciex108e,80f0", fire_irq_trans_init },
  650. };
  651. #endif
  652. static unsigned int sun4v_vdev_irq_build(struct device_node *dp,
  653. unsigned int devino,
  654. void *_data)
  655. {
  656. u32 devhandle = (u32) (unsigned long) _data;
  657. return sun4v_build_irq(devhandle, devino);
  658. }
  659. static void __init sun4v_vdev_irq_trans_init(struct device_node *dp)
  660. {
  661. const struct linux_prom64_registers *regs;
  662. dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
  663. dp->irq_trans->irq_build = sun4v_vdev_irq_build;
  664. regs = of_get_property(dp, "reg", NULL);
  665. dp->irq_trans->data = (void *) (unsigned long)
  666. ((regs->phys_addr >> 32UL) & 0x0fffffff);
  667. }
  668. void __init irq_trans_init(struct device_node *dp)
  669. {
  670. #ifdef CONFIG_PCI
  671. const char *model;
  672. int i;
  673. #endif
  674. #ifdef CONFIG_PCI
  675. model = of_get_property(dp, "model", NULL);
  676. if (!model)
  677. model = of_get_property(dp, "compatible", NULL);
  678. if (model) {
  679. for (i = 0; i < ARRAY_SIZE(pci_irq_trans_table); i++) {
  680. struct irq_trans *t = &pci_irq_trans_table[i];
  681. if (!strcmp(model, t->name)) {
  682. t->init(dp);
  683. return;
  684. }
  685. }
  686. }
  687. #endif
  688. #ifdef CONFIG_SBUS
  689. if (!strcmp(dp->name, "sbus") ||
  690. !strcmp(dp->name, "sbi")) {
  691. sbus_irq_trans_init(dp);
  692. return;
  693. }
  694. #endif
  695. if (!strcmp(dp->name, "fhc") &&
  696. !strcmp(dp->parent->name, "central")) {
  697. central_irq_trans_init(dp);
  698. return;
  699. }
  700. if (!strcmp(dp->name, "virtual-devices") ||
  701. !strcmp(dp->name, "niu")) {
  702. sun4v_vdev_irq_trans_init(dp);
  703. return;
  704. }
  705. }