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.
4 * Copyright (C) 1997, 1999 David S. Miller (davem@redhat.com)
7 #include <linux/kernel.h>
8 #include <linux/types.h>
9 #include <linux/string.h>
10 #include <linux/timer.h>
11 #include <linux/sched.h>
12 #include <linux/delay.h>
13 #include <linux/init.h>
14 #include <linux/bootmem.h>
18 #include <asm/starfire.h>
20 struct linux_central *central_bus = NULL;
21 struct linux_fhc *fhc_list = NULL;
23 #define IS_CENTRAL_FHC(__fhc) ((__fhc) == central_bus->child)
25 static inline unsigned long long_align(unsigned long addr)
27 return ((addr + (sizeof(unsigned long) - 1)) &
28 ~(sizeof(unsigned long) - 1));
31 static void central_ranges_init(int cnode, struct linux_central *central)
35 central->num_central_ranges = 0;
36 success = prom_getproperty(central->prom_node, "ranges",
37 (char *) central->central_ranges,
38 sizeof (central->central_ranges));
40 central->num_central_ranges = (success/sizeof(struct linux_prom_ranges));
43 static void fhc_ranges_init(int fnode, struct linux_fhc *fhc)
47 fhc->num_fhc_ranges = 0;
48 success = prom_getproperty(fhc->prom_node, "ranges",
49 (char *) fhc->fhc_ranges,
50 sizeof (fhc->fhc_ranges));
52 fhc->num_fhc_ranges = (success/sizeof(struct linux_prom_ranges));
55 /* Range application routines are exported to various drivers,
56 * so do not __init this.
58 static void adjust_regs(struct linux_prom_registers *regp, int nregs,
59 struct linux_prom_ranges *rangep, int nranges)
63 for (regc = 0; regc < nregs; regc++) {
64 for (rngc = 0; rngc < nranges; rngc++)
65 if (regp[regc].which_io == rangep[rngc].ot_child_space)
67 if (rngc == nranges) /* oops */
68 prom_printf("adjust_regs: Could not find range with matching bus type...\n");
69 regp[regc].which_io = rangep[rngc].ot_parent_space;
70 regp[regc].phys_addr -= rangep[rngc].ot_child_base;
71 regp[regc].phys_addr += rangep[rngc].ot_parent_base;
75 /* Apply probed fhc ranges to registers passed, if no ranges return. */
76 void apply_fhc_ranges(struct linux_fhc *fhc,
77 struct linux_prom_registers *regs,
80 if (fhc->num_fhc_ranges)
81 adjust_regs(regs, nregs, fhc->fhc_ranges,
85 /* Apply probed central ranges to registers passed, if no ranges return. */
86 void apply_central_ranges(struct linux_central *central,
87 struct linux_prom_registers *regs, int nregs)
89 if (central->num_central_ranges)
90 adjust_regs(regs, nregs, central->central_ranges,
91 central->num_central_ranges);
94 void * __init central_alloc_bootmem(unsigned long size)
98 ret = __alloc_bootmem(size, SMP_CACHE_BYTES, 0UL);
100 memset(ret, 0, size);
105 static void probe_other_fhcs(void)
107 struct linux_prom64_registers fpregs[6];
111 node = prom_getchild(prom_root_node);
112 node = prom_searchsiblings(node, "fhc");
114 prom_printf("FHC: Cannot find any toplevel firehose controllers.\n");
118 struct linux_fhc *fhc;
122 fhc = (struct linux_fhc *)
123 central_alloc_bootmem(sizeof(struct linux_fhc));
125 prom_printf("probe_other_fhcs: Cannot alloc fhc.\n");
129 /* Link it into the FHC chain. */
130 fhc->next = fhc_list;
133 /* Toplevel FHCs have no parent. */
136 fhc->prom_node = node;
137 prom_getstring(node, "name", namebuf, sizeof(namebuf));
138 strcpy(fhc->prom_name, namebuf);
139 fhc_ranges_init(node, fhc);
141 /* Non-central FHC's have 64-bit OBP format registers. */
142 if (prom_getproperty(node, "reg",
143 (char *)&fpregs[0], sizeof(fpregs)) == -1) {
144 prom_printf("FHC: Fatal error, cannot get fhc regs.\n");
148 /* Only central FHC needs special ranges applied. */
149 fhc->fhc_regs.pregs = fpregs[0].phys_addr;
150 fhc->fhc_regs.ireg = fpregs[1].phys_addr;
151 fhc->fhc_regs.ffregs = fpregs[2].phys_addr;
152 fhc->fhc_regs.sregs = fpregs[3].phys_addr;
153 fhc->fhc_regs.uregs = fpregs[4].phys_addr;
154 fhc->fhc_regs.tregs = fpregs[5].phys_addr;
156 board = prom_getintdefault(node, "board#", -1);
159 tmp = upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_JCTRL);
160 if ((tmp & FHC_JTAG_CTRL_MENAB) != 0)
161 fhc->jtag_master = 1;
163 fhc->jtag_master = 0;
165 tmp = upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_ID);
166 printk("FHC(board %d): Version[%x] PartID[%x] Manuf[%x] %s\n",
168 (tmp & FHC_ID_VERS) >> 28,
169 (tmp & FHC_ID_PARTID) >> 12,
170 (tmp & FHC_ID_MANUF) >> 1,
171 (fhc->jtag_master ? "(JTAG Master)" : ""));
173 /* This bit must be set in all non-central FHC's in
174 * the system. When it is clear, this identifies
177 tmp = upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_CTRL);
178 tmp |= FHC_CONTROL_IXIST;
179 upa_writel(tmp, fhc->fhc_regs.pregs + FHC_PREGS_CTRL);
181 /* Look for the next FHC. */
182 node = prom_getsibling(node);
185 node = prom_searchsiblings(node, "fhc");
191 static void probe_clock_board(struct linux_central *central,
192 struct linux_fhc *fhc,
193 int cnode, int fnode)
195 struct linux_prom_registers cregs[3];
196 int clknode, nslots, tmp, nregs;
198 clknode = prom_searchsiblings(prom_getchild(fnode), "clock-board");
199 if (clknode == 0 || clknode == -1) {
200 prom_printf("Critical error, central lacks clock-board.\n");
203 nregs = prom_getproperty(clknode, "reg", (char *)&cregs[0], sizeof(cregs));
205 prom_printf("CENTRAL: Fatal error, cannot map clock-board regs.\n");
208 nregs /= sizeof(struct linux_prom_registers);
209 apply_fhc_ranges(fhc, &cregs[0], nregs);
210 apply_central_ranges(central, &cregs[0], nregs);
211 central->cfreg = ((((unsigned long)cregs[0].which_io) << 32UL) |
212 ((unsigned long)cregs[0].phys_addr));
213 central->clkregs = ((((unsigned long)cregs[1].which_io) << 32UL) |
214 ((unsigned long)cregs[1].phys_addr));
217 central->clkver = 0UL;
219 central->clkver = ((((unsigned long)cregs[2].which_io) << 32UL) |
220 ((unsigned long)cregs[2].phys_addr));
222 tmp = upa_readb(central->clkregs + CLOCK_STAT1);
232 if (central->clkver != 0UL &&
233 upa_readb(central->clkver) != 0) {
234 if ((upa_readb(central->clkver) & 0x80) != 0)
244 central->slots = nslots;
245 printk("CENTRAL: Detected %d slot Enterprise system. cfreg[%02x] cver[%02x]\n",
246 central->slots, upa_readb(central->cfreg),
247 (central->clkver ? upa_readb(central->clkver) : 0x00));
250 static void init_all_fhc_hw(void)
252 struct linux_fhc *fhc;
254 for (fhc = fhc_list; fhc != NULL; fhc = fhc->next) {
257 /* Clear all of the interrupt mapping registers
258 * just in case OBP left them in a foul state.
260 #define ZAP(ICLR, IMAP) \
262 upa_writel(0, (ICLR)); \
264 imap_tmp = upa_readl(IMAP); \
265 imap_tmp &= ~(0x80000000); \
266 upa_writel(imap_tmp, (IMAP)); \
270 ZAP(fhc->fhc_regs.ffregs + FHC_FFREGS_ICLR,
271 fhc->fhc_regs.ffregs + FHC_FFREGS_IMAP);
272 ZAP(fhc->fhc_regs.sregs + FHC_SREGS_ICLR,
273 fhc->fhc_regs.sregs + FHC_SREGS_IMAP);
274 ZAP(fhc->fhc_regs.uregs + FHC_UREGS_ICLR,
275 fhc->fhc_regs.uregs + FHC_UREGS_IMAP);
276 ZAP(fhc->fhc_regs.tregs + FHC_TREGS_ICLR,
277 fhc->fhc_regs.tregs + FHC_TREGS_IMAP);
281 /* Setup FHC control register. */
282 tmp = upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_CTRL);
284 /* All non-central boards have this bit set. */
285 if (! IS_CENTRAL_FHC(fhc))
286 tmp |= FHC_CONTROL_IXIST;
288 /* For all FHCs, clear the firmware synchronization
289 * line and both low power mode enables.
291 tmp &= ~(FHC_CONTROL_AOFF | FHC_CONTROL_BOFF | FHC_CONTROL_SLINE);
293 upa_writel(tmp, fhc->fhc_regs.pregs + FHC_PREGS_CTRL);
294 upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_CTRL);
299 void central_probe(void)
301 struct linux_prom_registers fpregs[6];
302 struct linux_fhc *fhc;
304 int cnode, fnode, err;
306 cnode = prom_finddevice("/central");
307 if (cnode == 0 || cnode == -1) {
308 if (this_is_starfire)
309 starfire_cpu_setup();
313 /* Ok we got one, grab some memory for software state. */
314 central_bus = (struct linux_central *)
315 central_alloc_bootmem(sizeof(struct linux_central));
316 if (central_bus == NULL) {
317 prom_printf("central_probe: Cannot alloc central_bus.\n");
321 fhc = (struct linux_fhc *)
322 central_alloc_bootmem(sizeof(struct linux_fhc));
324 prom_printf("central_probe: Cannot alloc central fhc.\n");
328 /* First init central. */
329 central_bus->child = fhc;
330 central_bus->prom_node = cnode;
332 prom_getstring(cnode, "name", namebuf, sizeof(namebuf));
333 strcpy(central_bus->prom_name, namebuf);
335 central_ranges_init(cnode, central_bus);
337 /* And then central's FHC. */
338 fhc->next = fhc_list;
341 fhc->parent = central_bus;
342 fnode = prom_searchsiblings(prom_getchild(cnode), "fhc");
343 if (fnode == 0 || fnode == -1) {
344 prom_printf("Critical error, central board lacks fhc.\n");
347 fhc->prom_node = fnode;
348 prom_getstring(fnode, "name", namebuf, sizeof(namebuf));
349 strcpy(fhc->prom_name, namebuf);
351 fhc_ranges_init(fnode, fhc);
353 /* Now, map in FHC register set. */
354 if (prom_getproperty(fnode, "reg", (char *)&fpregs[0], sizeof(fpregs)) == -1) {
355 prom_printf("CENTRAL: Fatal error, cannot get fhc regs.\n");
358 apply_central_ranges(central_bus, &fpregs[0], 6);
360 fhc->fhc_regs.pregs = ((((unsigned long)fpregs[0].which_io)<<32UL) |
361 ((unsigned long)fpregs[0].phys_addr));
362 fhc->fhc_regs.ireg = ((((unsigned long)fpregs[1].which_io)<<32UL) |
363 ((unsigned long)fpregs[1].phys_addr));
364 fhc->fhc_regs.ffregs = ((((unsigned long)fpregs[2].which_io)<<32UL) |
365 ((unsigned long)fpregs[2].phys_addr));
366 fhc->fhc_regs.sregs = ((((unsigned long)fpregs[3].which_io)<<32UL) |
367 ((unsigned long)fpregs[3].phys_addr));
368 fhc->fhc_regs.uregs = ((((unsigned long)fpregs[4].which_io)<<32UL) |
369 ((unsigned long)fpregs[4].phys_addr));
370 fhc->fhc_regs.tregs = ((((unsigned long)fpregs[5].which_io)<<32UL) |
371 ((unsigned long)fpregs[5].phys_addr));
373 /* Obtain board number from board status register, Central's
374 * FHC lacks "board#" property.
376 err = upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_BSR);
377 fhc->board = (((err >> 16) & 0x01) |
378 ((err >> 12) & 0x0e));
380 fhc->jtag_master = 0;
382 /* Attach the clock board registers for CENTRAL. */
383 probe_clock_board(central_bus, fhc, cnode, fnode);
385 err = upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_ID);
386 printk("FHC(board %d): Version[%x] PartID[%x] Manuf[%x] (CENTRAL)\n",
388 ((err & FHC_ID_VERS) >> 28),
389 ((err & FHC_ID_PARTID) >> 12),
390 ((err & FHC_ID_MANUF) >> 1));
397 static __inline__ void fhc_ledblink(struct linux_fhc *fhc, int on)
401 tmp = upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_CTRL);
403 /* NOTE: reverse logic on this bit */
405 tmp &= ~(FHC_CONTROL_RLED);
407 tmp |= FHC_CONTROL_RLED;
408 tmp &= ~(FHC_CONTROL_AOFF | FHC_CONTROL_BOFF | FHC_CONTROL_SLINE);
410 upa_writel(tmp, fhc->fhc_regs.pregs + FHC_PREGS_CTRL);
411 upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_CTRL);
414 static __inline__ void central_ledblink(struct linux_central *central, int on)
418 tmp = upa_readb(central->clkregs + CLOCK_CTRL);
420 /* NOTE: reverse logic on this bit */
422 tmp &= ~(CLOCK_CTRL_RLED);
424 tmp |= CLOCK_CTRL_RLED;
426 upa_writeb(tmp, central->clkregs + CLOCK_CTRL);
427 upa_readb(central->clkregs + CLOCK_CTRL);
430 static struct timer_list sftimer;
431 static int led_state;
433 static void sunfire_timer(unsigned long __ignored)
435 struct linux_fhc *fhc;
437 central_ledblink(central_bus, led_state);
438 for (fhc = fhc_list; fhc != NULL; fhc = fhc->next)
439 if (! IS_CENTRAL_FHC(fhc))
440 fhc_ledblink(fhc, led_state);
441 led_state = ! led_state;
442 sftimer.expires = jiffies + (HZ >> 1);
446 /* After PCI/SBUS busses have been probed, this is called to perform
447 * final initialization of all FireHose Controllers in the system.
449 void firetruck_init(void)
451 struct linux_central *central = central_bus;
454 /* No central bus, nothing to do. */
458 /* OBP leaves it on, turn it off so clock board timer LED
459 * is in sync with FHC ones.
461 ctrl = upa_readb(central->clkregs + CLOCK_CTRL);
462 ctrl &= ~(CLOCK_CTRL_RLED);
463 upa_writeb(ctrl, central->clkregs + CLOCK_CTRL);
466 init_timer(&sftimer);
468 sftimer.function = &sunfire_timer;
469 sftimer.expires = jiffies + (HZ >> 1);