central.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. /* central.c: Central FHC driver for Sunfire/Starfire/Wildfire.
  2. *
  3. * Copyright (C) 1997, 1999 David S. Miller (davem@davemloft.net)
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/types.h>
  7. #include <linux/string.h>
  8. #include <linux/timer.h>
  9. #include <linux/sched.h>
  10. #include <linux/delay.h>
  11. #include <linux/init.h>
  12. #include <linux/bootmem.h>
  13. #include <asm/page.h>
  14. #include <asm/fhc.h>
  15. #include <asm/starfire.h>
  16. static struct linux_central *central_bus = NULL;
  17. static struct linux_fhc *fhc_list = NULL;
  18. #define IS_CENTRAL_FHC(__fhc) ((__fhc) == central_bus->child)
  19. static void central_probe_failure(int line)
  20. {
  21. prom_printf("CENTRAL: Critical device probe failure at central.c:%d\n",
  22. line);
  23. prom_halt();
  24. }
  25. static void central_ranges_init(struct linux_central *central)
  26. {
  27. struct device_node *dp = central->prom_node;
  28. const void *pval;
  29. int len;
  30. central->num_central_ranges = 0;
  31. pval = of_get_property(dp, "ranges", &len);
  32. if (pval) {
  33. memcpy(central->central_ranges, pval, len);
  34. central->num_central_ranges =
  35. (len / sizeof(struct linux_prom_ranges));
  36. }
  37. }
  38. static void fhc_ranges_init(struct linux_fhc *fhc)
  39. {
  40. struct device_node *dp = fhc->prom_node;
  41. const void *pval;
  42. int len;
  43. fhc->num_fhc_ranges = 0;
  44. pval = of_get_property(dp, "ranges", &len);
  45. if (pval) {
  46. memcpy(fhc->fhc_ranges, pval, len);
  47. fhc->num_fhc_ranges =
  48. (len / sizeof(struct linux_prom_ranges));
  49. }
  50. }
  51. /* Range application routines are exported to various drivers,
  52. * so do not __init this.
  53. */
  54. static void adjust_regs(struct linux_prom_registers *regp, int nregs,
  55. struct linux_prom_ranges *rangep, int nranges)
  56. {
  57. int regc, rngc;
  58. for (regc = 0; regc < nregs; regc++) {
  59. for (rngc = 0; rngc < nranges; rngc++)
  60. if (regp[regc].which_io == rangep[rngc].ot_child_space)
  61. break; /* Fount it */
  62. if (rngc == nranges) /* oops */
  63. central_probe_failure(__LINE__);
  64. regp[regc].which_io = rangep[rngc].ot_parent_space;
  65. regp[regc].phys_addr -= rangep[rngc].ot_child_base;
  66. regp[regc].phys_addr += rangep[rngc].ot_parent_base;
  67. }
  68. }
  69. /* Apply probed fhc ranges to registers passed, if no ranges return. */
  70. static void apply_fhc_ranges(struct linux_fhc *fhc,
  71. struct linux_prom_registers *regs,
  72. int nregs)
  73. {
  74. if (fhc->num_fhc_ranges)
  75. adjust_regs(regs, nregs, fhc->fhc_ranges,
  76. fhc->num_fhc_ranges);
  77. }
  78. /* Apply probed central ranges to registers passed, if no ranges return. */
  79. static void apply_central_ranges(struct linux_central *central,
  80. struct linux_prom_registers *regs, int nregs)
  81. {
  82. if (central->num_central_ranges)
  83. adjust_regs(regs, nregs, central->central_ranges,
  84. central->num_central_ranges);
  85. }
  86. static void * __init central_alloc_bootmem(unsigned long size)
  87. {
  88. void *ret;
  89. ret = __alloc_bootmem(size, SMP_CACHE_BYTES, 0UL);
  90. if (ret != NULL)
  91. memset(ret, 0, size);
  92. return ret;
  93. }
  94. static unsigned long prom_reg_to_paddr(struct linux_prom_registers *r)
  95. {
  96. unsigned long ret = ((unsigned long) r->which_io) << 32;
  97. return ret | (unsigned long) r->phys_addr;
  98. }
  99. static void __init probe_other_fhcs(void)
  100. {
  101. struct device_node *dp;
  102. const struct linux_prom64_registers *fpregs;
  103. for_each_node_by_name(dp, "fhc") {
  104. struct linux_fhc *fhc;
  105. int board;
  106. u32 tmp;
  107. if (dp->parent &&
  108. dp->parent->parent != NULL)
  109. continue;
  110. fhc = (struct linux_fhc *)
  111. central_alloc_bootmem(sizeof(struct linux_fhc));
  112. if (fhc == NULL)
  113. central_probe_failure(__LINE__);
  114. /* Link it into the FHC chain. */
  115. fhc->next = fhc_list;
  116. fhc_list = fhc;
  117. /* Toplevel FHCs have no parent. */
  118. fhc->parent = NULL;
  119. fhc->prom_node = dp;
  120. fhc_ranges_init(fhc);
  121. /* Non-central FHC's have 64-bit OBP format registers. */
  122. fpregs = of_get_property(dp, "reg", NULL);
  123. if (!fpregs)
  124. central_probe_failure(__LINE__);
  125. /* Only central FHC needs special ranges applied. */
  126. fhc->fhc_regs.pregs = fpregs[0].phys_addr;
  127. fhc->fhc_regs.ireg = fpregs[1].phys_addr;
  128. fhc->fhc_regs.ffregs = fpregs[2].phys_addr;
  129. fhc->fhc_regs.sregs = fpregs[3].phys_addr;
  130. fhc->fhc_regs.uregs = fpregs[4].phys_addr;
  131. fhc->fhc_regs.tregs = fpregs[5].phys_addr;
  132. board = of_getintprop_default(dp, "board#", -1);
  133. fhc->board = board;
  134. tmp = upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_JCTRL);
  135. if ((tmp & FHC_JTAG_CTRL_MENAB) != 0)
  136. fhc->jtag_master = 1;
  137. else
  138. fhc->jtag_master = 0;
  139. tmp = upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_ID);
  140. printk("FHC(board %d): Version[%x] PartID[%x] Manuf[%x] %s\n",
  141. board,
  142. (tmp & FHC_ID_VERS) >> 28,
  143. (tmp & FHC_ID_PARTID) >> 12,
  144. (tmp & FHC_ID_MANUF) >> 1,
  145. (fhc->jtag_master ? "(JTAG Master)" : ""));
  146. /* This bit must be set in all non-central FHC's in
  147. * the system. When it is clear, this identifies
  148. * the central board.
  149. */
  150. tmp = upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_CTRL);
  151. tmp |= FHC_CONTROL_IXIST;
  152. upa_writel(tmp, fhc->fhc_regs.pregs + FHC_PREGS_CTRL);
  153. }
  154. }
  155. static void probe_clock_board(struct linux_central *central,
  156. struct linux_fhc *fhc,
  157. struct device_node *fp)
  158. {
  159. struct device_node *dp;
  160. struct linux_prom_registers cregs[3];
  161. const struct linux_prom_registers *pr;
  162. int nslots, tmp, nregs;
  163. dp = fp->child;
  164. while (dp) {
  165. if (!strcmp(dp->name, "clock-board"))
  166. break;
  167. dp = dp->sibling;
  168. }
  169. if (!dp)
  170. central_probe_failure(__LINE__);
  171. pr = of_get_property(dp, "reg", &nregs);
  172. if (!pr)
  173. central_probe_failure(__LINE__);
  174. memcpy(cregs, pr, nregs);
  175. nregs /= sizeof(struct linux_prom_registers);
  176. apply_fhc_ranges(fhc, &cregs[0], nregs);
  177. apply_central_ranges(central, &cregs[0], nregs);
  178. central->cfreg = prom_reg_to_paddr(&cregs[0]);
  179. central->clkregs = prom_reg_to_paddr(&cregs[1]);
  180. if (nregs == 2)
  181. central->clkver = 0UL;
  182. else
  183. central->clkver = prom_reg_to_paddr(&cregs[2]);
  184. tmp = upa_readb(central->clkregs + CLOCK_STAT1);
  185. tmp &= 0xc0;
  186. switch(tmp) {
  187. case 0x40:
  188. nslots = 16;
  189. break;
  190. case 0xc0:
  191. nslots = 8;
  192. break;
  193. case 0x80:
  194. if (central->clkver != 0UL &&
  195. upa_readb(central->clkver) != 0) {
  196. if ((upa_readb(central->clkver) & 0x80) != 0)
  197. nslots = 4;
  198. else
  199. nslots = 5;
  200. break;
  201. }
  202. default:
  203. nslots = 4;
  204. break;
  205. };
  206. central->slots = nslots;
  207. printk("CENTRAL: Detected %d slot Enterprise system. cfreg[%02x] cver[%02x]\n",
  208. central->slots, upa_readb(central->cfreg),
  209. (central->clkver ? upa_readb(central->clkver) : 0x00));
  210. }
  211. static void ZAP(unsigned long iclr, unsigned long imap)
  212. {
  213. u32 imap_tmp;
  214. upa_writel(0, iclr);
  215. upa_readl(iclr);
  216. imap_tmp = upa_readl(imap);
  217. imap_tmp &= ~(0x80000000);
  218. upa_writel(imap_tmp, imap);
  219. upa_readl(imap);
  220. }
  221. static void init_all_fhc_hw(void)
  222. {
  223. struct linux_fhc *fhc;
  224. for (fhc = fhc_list; fhc != NULL; fhc = fhc->next) {
  225. u32 tmp;
  226. /* Clear all of the interrupt mapping registers
  227. * just in case OBP left them in a foul state.
  228. */
  229. ZAP(fhc->fhc_regs.ffregs + FHC_FFREGS_ICLR,
  230. fhc->fhc_regs.ffregs + FHC_FFREGS_IMAP);
  231. ZAP(fhc->fhc_regs.sregs + FHC_SREGS_ICLR,
  232. fhc->fhc_regs.sregs + FHC_SREGS_IMAP);
  233. ZAP(fhc->fhc_regs.uregs + FHC_UREGS_ICLR,
  234. fhc->fhc_regs.uregs + FHC_UREGS_IMAP);
  235. ZAP(fhc->fhc_regs.tregs + FHC_TREGS_ICLR,
  236. fhc->fhc_regs.tregs + FHC_TREGS_IMAP);
  237. /* Setup FHC control register. */
  238. tmp = upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_CTRL);
  239. /* All non-central boards have this bit set. */
  240. if (! IS_CENTRAL_FHC(fhc))
  241. tmp |= FHC_CONTROL_IXIST;
  242. /* For all FHCs, clear the firmware synchronization
  243. * line and both low power mode enables.
  244. */
  245. tmp &= ~(FHC_CONTROL_AOFF | FHC_CONTROL_BOFF |
  246. FHC_CONTROL_SLINE);
  247. upa_writel(tmp, fhc->fhc_regs.pregs + FHC_PREGS_CTRL);
  248. upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_CTRL);
  249. }
  250. }
  251. void __init central_probe(void)
  252. {
  253. struct linux_prom_registers fpregs[6];
  254. const struct linux_prom_registers *pr;
  255. struct linux_fhc *fhc;
  256. struct device_node *dp, *fp;
  257. int err;
  258. dp = of_find_node_by_name(NULL, "central");
  259. if (!dp) {
  260. if (this_is_starfire)
  261. starfire_cpu_setup();
  262. return;
  263. }
  264. /* Ok we got one, grab some memory for software state. */
  265. central_bus = (struct linux_central *)
  266. central_alloc_bootmem(sizeof(struct linux_central));
  267. if (central_bus == NULL)
  268. central_probe_failure(__LINE__);
  269. fhc = (struct linux_fhc *)
  270. central_alloc_bootmem(sizeof(struct linux_fhc));
  271. if (fhc == NULL)
  272. central_probe_failure(__LINE__);
  273. /* First init central. */
  274. central_bus->child = fhc;
  275. central_bus->prom_node = dp;
  276. central_ranges_init(central_bus);
  277. /* And then central's FHC. */
  278. fhc->next = fhc_list;
  279. fhc_list = fhc;
  280. fhc->parent = central_bus;
  281. fp = dp->child;
  282. while (fp) {
  283. if (!strcmp(fp->name, "fhc"))
  284. break;
  285. fp = fp->sibling;
  286. }
  287. if (!fp)
  288. central_probe_failure(__LINE__);
  289. fhc->prom_node = fp;
  290. fhc_ranges_init(fhc);
  291. /* Now, map in FHC register set. */
  292. pr = of_get_property(fp, "reg", NULL);
  293. if (!pr)
  294. central_probe_failure(__LINE__);
  295. memcpy(fpregs, pr, sizeof(fpregs));
  296. apply_central_ranges(central_bus, &fpregs[0], 6);
  297. fhc->fhc_regs.pregs = prom_reg_to_paddr(&fpregs[0]);
  298. fhc->fhc_regs.ireg = prom_reg_to_paddr(&fpregs[1]);
  299. fhc->fhc_regs.ffregs = prom_reg_to_paddr(&fpregs[2]);
  300. fhc->fhc_regs.sregs = prom_reg_to_paddr(&fpregs[3]);
  301. fhc->fhc_regs.uregs = prom_reg_to_paddr(&fpregs[4]);
  302. fhc->fhc_regs.tregs = prom_reg_to_paddr(&fpregs[5]);
  303. /* Obtain board number from board status register, Central's
  304. * FHC lacks "board#" property.
  305. */
  306. err = upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_BSR);
  307. fhc->board = (((err >> 16) & 0x01) |
  308. ((err >> 12) & 0x0e));
  309. fhc->jtag_master = 0;
  310. /* Attach the clock board registers for CENTRAL. */
  311. probe_clock_board(central_bus, fhc, fp);
  312. err = upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_ID);
  313. printk("FHC(board %d): Version[%x] PartID[%x] Manuf[%x] (CENTRAL)\n",
  314. fhc->board,
  315. ((err & FHC_ID_VERS) >> 28),
  316. ((err & FHC_ID_PARTID) >> 12),
  317. ((err & FHC_ID_MANUF) >> 1));
  318. probe_other_fhcs();
  319. init_all_fhc_hw();
  320. }
  321. static inline void fhc_ledblink(struct linux_fhc *fhc, int on)
  322. {
  323. u32 tmp;
  324. tmp = upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_CTRL);
  325. /* NOTE: reverse logic on this bit */
  326. if (on)
  327. tmp &= ~(FHC_CONTROL_RLED);
  328. else
  329. tmp |= FHC_CONTROL_RLED;
  330. tmp &= ~(FHC_CONTROL_AOFF | FHC_CONTROL_BOFF | FHC_CONTROL_SLINE);
  331. upa_writel(tmp, fhc->fhc_regs.pregs + FHC_PREGS_CTRL);
  332. upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_CTRL);
  333. }
  334. static inline void central_ledblink(struct linux_central *central, int on)
  335. {
  336. u8 tmp;
  337. tmp = upa_readb(central->clkregs + CLOCK_CTRL);
  338. /* NOTE: reverse logic on this bit */
  339. if (on)
  340. tmp &= ~(CLOCK_CTRL_RLED);
  341. else
  342. tmp |= CLOCK_CTRL_RLED;
  343. upa_writeb(tmp, central->clkregs + CLOCK_CTRL);
  344. upa_readb(central->clkregs + CLOCK_CTRL);
  345. }
  346. static struct timer_list sftimer;
  347. static int led_state;
  348. static void sunfire_timer(unsigned long __ignored)
  349. {
  350. struct linux_fhc *fhc;
  351. central_ledblink(central_bus, led_state);
  352. for (fhc = fhc_list; fhc != NULL; fhc = fhc->next)
  353. if (! IS_CENTRAL_FHC(fhc))
  354. fhc_ledblink(fhc, led_state);
  355. led_state = ! led_state;
  356. sftimer.expires = jiffies + (HZ >> 1);
  357. add_timer(&sftimer);
  358. }
  359. /* After PCI/SBUS busses have been probed, this is called to perform
  360. * final initialization of all FireHose Controllers in the system.
  361. */
  362. void firetruck_init(void)
  363. {
  364. struct linux_central *central = central_bus;
  365. u8 ctrl;
  366. /* No central bus, nothing to do. */
  367. if (central == NULL)
  368. return;
  369. /* OBP leaves it on, turn it off so clock board timer LED
  370. * is in sync with FHC ones.
  371. */
  372. ctrl = upa_readb(central->clkregs + CLOCK_CTRL);
  373. ctrl &= ~(CLOCK_CTRL_RLED);
  374. upa_writeb(ctrl, central->clkregs + CLOCK_CTRL);
  375. led_state = 0;
  376. init_timer(&sftimer);
  377. sftimer.data = 0;
  378. sftimer.function = &sunfire_timer;
  379. sftimer.expires = jiffies + (HZ >> 1);
  380. add_timer(&sftimer);
  381. }