central.c 12 KB

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