central.c 12 KB

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