2 * linux/arch/alpha/kernel/core_t2.c
4 * Written by Jay A Estabrook (jestabro@amt.tay1.dec.com).
7 * based on CIA code by David A Rusling (david.rusling@reo.mts.dec.com)
9 * Code common to all T2 core logic chips.
12 #define __EXTERN_INLINE
14 #include <asm/core_t2.h>
15 #undef __EXTERN_INLINE
17 #include <linux/types.h>
18 #include <linux/pci.h>
19 #include <linux/sched.h>
20 #include <linux/init.h>
22 #include <asm/ptrace.h>
23 #include <asm/delay.h>
28 /* For dumping initial DMA window settings. */
29 #define DEBUG_PRINT_INITIAL_SETTINGS 0
31 /* For dumping final DMA window settings. */
32 #define DEBUG_PRINT_FINAL_SETTINGS 0
35 * By default, we direct-map starting at 2GB, in order to allow the
36 * maximum size direct-map window (2GB) to match the maximum amount of
37 * memory (2GB) that can be present on SABLEs. But that limits the
38 * floppy to DMA only via the scatter/gather window set up for 8MB
39 * ISA DMA, since the maximum ISA DMA address is 2GB-1.
41 * For now, this seems a reasonable trade-off: even though most SABLEs
42 * have less than 1GB of memory, floppy usage/performance will not
43 * really be affected by forcing it to go via scatter/gather...
45 #define T2_DIRECTMAP_2G 1
48 # define T2_DIRECTMAP_START 0x80000000UL
49 # define T2_DIRECTMAP_LENGTH 0x80000000UL
51 # define T2_DIRECTMAP_START 0x40000000UL
52 # define T2_DIRECTMAP_LENGTH 0x40000000UL
55 /* The ISA scatter/gather window settings. */
56 #define T2_ISA_SG_START 0x00800000UL
57 #define T2_ISA_SG_LENGTH 0x00800000UL
60 * NOTE: Herein lie back-to-back mb instructions. They are magic.
61 * One plausible explanation is that the i/o controller does not properly
62 * handle the system transaction. Another involves timing. Ho hum.
66 * BIOS32-style PCI interface:
69 #define DEBUG_CONFIG 0
72 # define DBG(args) printk args
77 static volatile unsigned int t2_mcheck_any_expected
;
78 static volatile unsigned int t2_mcheck_last_taken
;
80 /* Place to save the DMA Window registers as set up by SRM
81 for restoration during shutdown. */
94 } t2_saved_config
__attribute((common
));
97 * Given a bus, device, and function number, compute resulting
98 * configuration space address and setup the T2_HAXR2 register
99 * accordingly. It is therefore not safe to have concurrent
100 * invocations to configuration space access routines, but there
101 * really shouldn't be any need for this.
105 * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
106 * 3 2|1 0 9 8|7 6 5 4|3 2 1 0|9 8 7 6|5 4 3 2|1 0 9 8|7 6 5 4|3 2 1 0
107 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
108 * | | |D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|0|
109 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
111 * 31:11 Device select bit.
112 * 10:8 Function number
113 * 7:2 Register number
117 * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
118 * 3 2|1 0 9 8|7 6 5 4|3 2 1 0|9 8 7 6|5 4 3 2|1 0 9 8|7 6 5 4|3 2 1 0
119 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
120 * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
121 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
124 * 23:16 bus number (8 bits = 128 possible buses)
125 * 15:11 Device number (5 bits)
126 * 10:8 function number
127 * 7:2 register number
130 * The function number selects which function of a multi-function device
131 * (e.g., SCSI and Ethernet).
133 * The register selects a DWORD (32 bit) register offset. Hence it
134 * doesn't get shifted by 2 bits as we want to "drop" the bottom two
139 mk_conf_addr(struct pci_bus
*pbus
, unsigned int device_fn
, int where
,
140 unsigned long *pci_addr
, unsigned char *type1
)
143 u8 bus
= pbus
->number
;
145 DBG(("mk_conf_addr(bus=%d, dfn=0x%x, where=0x%x,"
146 " addr=0x%lx, type1=0x%x)\n",
147 bus
, device_fn
, where
, pci_addr
, type1
));
150 int device
= device_fn
>> 3;
152 /* Type 0 configuration cycle. */
155 DBG(("mk_conf_addr: device (%d)>20, returning -1\n",
161 addr
= (0x0800L
<< device
) | ((device_fn
& 7) << 8) | (where
);
163 /* Type 1 configuration cycle. */
165 addr
= (bus
<< 16) | (device_fn
<< 8) | (where
);
168 DBG(("mk_conf_addr: returning pci_addr 0x%lx\n", addr
));
173 * NOTE: both conf_read() and conf_write() may set HAE_3 when needing
174 * to do type1 access. This is protected by the use of spinlock IRQ
175 * primitives in the wrapper functions pci_{read,write}_config_*()
176 * defined in drivers/pci/pci.c.
179 conf_read(unsigned long addr
, unsigned char type1
)
181 unsigned int value
, cpu
, taken
;
182 unsigned long t2_cfg
= 0;
184 cpu
= smp_processor_id();
186 DBG(("conf_read(addr=0x%lx, type1=%d)\n", addr
, type1
));
188 /* If Type1 access, must set T2 CFG. */
190 t2_cfg
= *(vulp
)T2_HAE_3
& ~0xc0000000UL
;
191 *(vulp
)T2_HAE_3
= 0x40000000UL
| t2_cfg
;
197 mcheck_expected(cpu
) = 1;
198 mcheck_taken(cpu
) = 0;
199 t2_mcheck_any_expected
|= (1 << cpu
);
202 /* Access configuration space. */
207 /* Wait for possible mcheck. Also, this lets other CPUs clear
208 their mchecks as well, as they can reliably tell when
209 another CPU is in the midst of handling a real mcheck via
210 the "taken" function. */
213 if ((taken
= mcheck_taken(cpu
))) {
214 mcheck_taken(cpu
) = 0;
215 t2_mcheck_last_taken
|= (1 << cpu
);
219 mcheck_expected(cpu
) = 0;
220 t2_mcheck_any_expected
= 0;
223 /* If Type1 access, must reset T2 CFG so normal IO space ops work. */
225 *(vulp
)T2_HAE_3
= t2_cfg
;
233 conf_write(unsigned long addr
, unsigned int value
, unsigned char type1
)
235 unsigned int cpu
, taken
;
236 unsigned long t2_cfg
= 0;
238 cpu
= smp_processor_id();
240 /* If Type1 access, must set T2 CFG. */
242 t2_cfg
= *(vulp
)T2_HAE_3
& ~0xc0000000UL
;
243 *(vulp
)T2_HAE_3
= t2_cfg
| 0x40000000UL
;
249 mcheck_expected(cpu
) = 1;
250 mcheck_taken(cpu
) = 0;
251 t2_mcheck_any_expected
|= (1 << cpu
);
254 /* Access configuration space. */
259 /* Wait for possible mcheck. Also, this lets other CPUs clear
260 their mchecks as well, as they can reliably tell when
261 this CPU is in the midst of handling a real mcheck via
262 the "taken" function. */
265 if ((taken
= mcheck_taken(cpu
))) {
266 mcheck_taken(cpu
) = 0;
267 t2_mcheck_last_taken
|= (1 << cpu
);
270 mcheck_expected(cpu
) = 0;
271 t2_mcheck_any_expected
= 0;
274 /* If Type1 access, must reset T2 CFG so normal IO space ops work. */
276 *(vulp
)T2_HAE_3
= t2_cfg
;
282 t2_read_config(struct pci_bus
*bus
, unsigned int devfn
, int where
,
283 int size
, u32
*value
)
285 unsigned long addr
, pci_addr
;
290 if (mk_conf_addr(bus
, devfn
, where
, &pci_addr
, &type1
))
291 return PCIBIOS_DEVICE_NOT_FOUND
;
293 mask
= (size
- 1) * 8;
294 shift
= (where
& 3) * 8;
295 addr
= (pci_addr
<< 5) + mask
+ T2_CONF
;
296 *value
= conf_read(addr
, type1
) >> (shift
);
297 return PCIBIOS_SUCCESSFUL
;
301 t2_write_config(struct pci_bus
*bus
, unsigned int devfn
, int where
, int size
,
304 unsigned long addr
, pci_addr
;
308 if (mk_conf_addr(bus
, devfn
, where
, &pci_addr
, &type1
))
309 return PCIBIOS_DEVICE_NOT_FOUND
;
311 mask
= (size
- 1) * 8;
312 addr
= (pci_addr
<< 5) + mask
+ T2_CONF
;
313 conf_write(addr
, value
<< ((where
& 3) * 8), type1
);
314 return PCIBIOS_SUCCESSFUL
;
317 struct pci_ops t2_pci_ops
=
319 .read
= t2_read_config
,
320 .write
= t2_write_config
,
324 t2_direct_map_window1(unsigned long base
, unsigned long length
)
328 __direct_map_base
= base
;
329 __direct_map_size
= length
;
331 temp
= (base
& 0xfff00000UL
) | ((base
+ length
- 1) >> 20);
332 *(vulp
)T2_WBASE1
= temp
| 0x80000UL
; /* OR in ENABLE bit */
333 temp
= (length
- 1) & 0xfff00000UL
;
334 *(vulp
)T2_WMASK1
= temp
;
335 *(vulp
)T2_TBASE1
= 0;
337 #if DEBUG_PRINT_FINAL_SETTINGS
338 printk("%s: setting WBASE1=0x%lx WMASK1=0x%lx TBASE1=0x%lx\n",
339 __func__
, *(vulp
)T2_WBASE1
, *(vulp
)T2_WMASK1
, *(vulp
)T2_TBASE1
);
344 t2_sg_map_window2(struct pci_controller
*hose
,
346 unsigned long length
)
350 /* Note we can only do 1 SG window, as the other is for direct, so
351 do an ISA SG area, especially for the floppy. */
352 hose
->sg_isa
= iommu_arena_new(hose
, base
, length
, 0);
355 temp
= (base
& 0xfff00000UL
) | ((base
+ length
- 1) >> 20);
356 *(vulp
)T2_WBASE2
= temp
| 0xc0000UL
; /* OR in ENABLE/SG bits */
357 temp
= (length
- 1) & 0xfff00000UL
;
358 *(vulp
)T2_WMASK2
= temp
;
359 *(vulp
)T2_TBASE2
= virt_to_phys(hose
->sg_isa
->ptes
) >> 1;
362 t2_pci_tbi(hose
, 0, -1); /* flush TLB all */
364 #if DEBUG_PRINT_FINAL_SETTINGS
365 printk("%s: setting WBASE2=0x%lx WMASK2=0x%lx TBASE2=0x%lx\n",
366 __func__
, *(vulp
)T2_WBASE2
, *(vulp
)T2_WMASK2
, *(vulp
)T2_TBASE2
);
371 t2_save_configuration(void)
373 #if DEBUG_PRINT_INITIAL_SETTINGS
374 printk("%s: HAE_1 was 0x%lx\n", __func__
, srm_hae
); /* HW is 0 */
375 printk("%s: HAE_2 was 0x%lx\n", __func__
, *(vulp
)T2_HAE_2
);
376 printk("%s: HAE_3 was 0x%lx\n", __func__
, *(vulp
)T2_HAE_3
);
377 printk("%s: HAE_4 was 0x%lx\n", __func__
, *(vulp
)T2_HAE_4
);
378 printk("%s: HBASE was 0x%lx\n", __func__
, *(vulp
)T2_HBASE
);
380 printk("%s: WBASE1=0x%lx WMASK1=0x%lx TBASE1=0x%lx\n", __func__
,
381 *(vulp
)T2_WBASE1
, *(vulp
)T2_WMASK1
, *(vulp
)T2_TBASE1
);
382 printk("%s: WBASE2=0x%lx WMASK2=0x%lx TBASE2=0x%lx\n", __func__
,
383 *(vulp
)T2_WBASE2
, *(vulp
)T2_WMASK2
, *(vulp
)T2_TBASE2
);
387 * Save the DMA Window registers.
389 t2_saved_config
.window
[0].wbase
= *(vulp
)T2_WBASE1
;
390 t2_saved_config
.window
[0].wmask
= *(vulp
)T2_WMASK1
;
391 t2_saved_config
.window
[0].tbase
= *(vulp
)T2_TBASE1
;
392 t2_saved_config
.window
[1].wbase
= *(vulp
)T2_WBASE2
;
393 t2_saved_config
.window
[1].wmask
= *(vulp
)T2_WMASK2
;
394 t2_saved_config
.window
[1].tbase
= *(vulp
)T2_TBASE2
;
396 t2_saved_config
.hae_1
= srm_hae
; /* HW is already set to 0 */
397 t2_saved_config
.hae_2
= *(vulp
)T2_HAE_2
;
398 t2_saved_config
.hae_3
= *(vulp
)T2_HAE_3
;
399 t2_saved_config
.hae_4
= *(vulp
)T2_HAE_4
;
400 t2_saved_config
.hbase
= *(vulp
)T2_HBASE
;
406 struct pci_controller
*hose
;
407 struct resource
*hae_mem
;
411 for (i
= 0; i
< NR_CPUS
; i
++) {
412 mcheck_expected(i
) = 0;
415 t2_mcheck_any_expected
= 0;
416 t2_mcheck_last_taken
= 0;
418 /* Enable scatter/gather TLB use. */
419 temp
= *(vulp
)T2_IOCSR
;
420 if (!(temp
& (0x1UL
<< 26))) {
421 printk("t2_init_arch: enabling SG TLB, IOCSR was 0x%lx\n",
423 *(vulp
)T2_IOCSR
= temp
| (0x1UL
<< 26);
425 *(vulp
)T2_IOCSR
; /* read it back to make sure */
428 t2_save_configuration();
431 * Create our single hose.
433 pci_isa_hose
= hose
= alloc_pci_controller();
434 hose
->io_space
= &ioport_resource
;
435 hae_mem
= alloc_resource();
437 hae_mem
->end
= T2_MEM_R1_MASK
;
438 hae_mem
->name
= pci_hae0_name
;
439 if (request_resource(&iomem_resource
, hae_mem
) < 0)
440 printk(KERN_ERR
"Failed to request HAE_MEM\n");
441 hose
->mem_space
= hae_mem
;
444 hose
->sparse_mem_base
= T2_SPARSE_MEM
- IDENT_ADDR
;
445 hose
->dense_mem_base
= T2_DENSE_MEM
- IDENT_ADDR
;
446 hose
->sparse_io_base
= T2_IO
- IDENT_ADDR
;
447 hose
->dense_io_base
= 0;
450 * Set up the PCI->physical memory translation windows.
452 * Window 1 is direct mapped.
453 * Window 2 is scatter/gather (for ISA).
456 t2_direct_map_window1(T2_DIRECTMAP_START
, T2_DIRECTMAP_LENGTH
);
458 /* Always make an ISA DMA window. */
459 t2_sg_map_window2(hose
, T2_ISA_SG_START
, T2_ISA_SG_LENGTH
);
461 *(vulp
)T2_HBASE
= 0x0; /* Disable HOLES. */
464 *(vulp
)T2_HAE_1
= 0; mb(); /* Sparse MEM HAE */
465 *(vulp
)T2_HAE_2
= 0; mb(); /* Sparse I/O HAE */
466 *(vulp
)T2_HAE_3
= 0; mb(); /* Config Space HAE */
469 * We also now zero out HAE_4, the dense memory HAE, so that
470 * we need not account for its "offset" when accessing dense
471 * memory resources which we allocated in our normal way. This
472 * HAE would need to stay untouched were we to keep the SRM
475 * Thus we can now run standard X servers on SABLE/LYNX. :-)
477 *(vulp
)T2_HAE_4
= 0; mb();
481 t2_kill_arch(int mode
)
484 * Restore the DMA Window registers.
486 *(vulp
)T2_WBASE1
= t2_saved_config
.window
[0].wbase
;
487 *(vulp
)T2_WMASK1
= t2_saved_config
.window
[0].wmask
;
488 *(vulp
)T2_TBASE1
= t2_saved_config
.window
[0].tbase
;
489 *(vulp
)T2_WBASE2
= t2_saved_config
.window
[1].wbase
;
490 *(vulp
)T2_WMASK2
= t2_saved_config
.window
[1].wmask
;
491 *(vulp
)T2_TBASE2
= t2_saved_config
.window
[1].tbase
;
494 *(vulp
)T2_HAE_1
= srm_hae
;
495 *(vulp
)T2_HAE_2
= t2_saved_config
.hae_2
;
496 *(vulp
)T2_HAE_3
= t2_saved_config
.hae_3
;
497 *(vulp
)T2_HAE_4
= t2_saved_config
.hae_4
;
498 *(vulp
)T2_HBASE
= t2_saved_config
.hbase
;
500 *(vulp
)T2_HBASE
; /* READ it back to ensure WRITE occurred. */
504 t2_pci_tbi(struct pci_controller
*hose
, dma_addr_t start
, dma_addr_t end
)
506 unsigned long t2_iocsr
;
508 t2_iocsr
= *(vulp
)T2_IOCSR
;
510 /* set the TLB Clear bit */
511 *(vulp
)T2_IOCSR
= t2_iocsr
| (0x1UL
<< 28);
513 *(vulp
)T2_IOCSR
; /* read it back to make sure */
515 /* clear the TLB Clear bit */
516 *(vulp
)T2_IOCSR
= t2_iocsr
& ~(0x1UL
<< 28);
518 *(vulp
)T2_IOCSR
; /* read it back to make sure */
521 #define SIC_SEIC (1UL << 33) /* System Event Clear */
524 t2_clear_errors(int cpu
)
526 struct sable_cpu_csr
*cpu_regs
;
528 cpu_regs
= (struct sable_cpu_csr
*)T2_CPUn_BASE(cpu
);
530 cpu_regs
->sic
&= ~SIC_SEIC
;
532 /* Clear CPU errors. */
533 cpu_regs
->bcce
|= cpu_regs
->bcce
;
534 cpu_regs
->cbe
|= cpu_regs
->cbe
;
535 cpu_regs
->bcue
|= cpu_regs
->bcue
;
536 cpu_regs
->dter
|= cpu_regs
->dter
;
538 *(vulp
)T2_CERR1
|= *(vulp
)T2_CERR1
;
539 *(vulp
)T2_PERR1
|= *(vulp
)T2_PERR1
;
546 * SABLE seems to have a "broadcast" style machine check, in that all
547 * CPUs receive it. And, the issuing CPU, in the case of PCI Config
548 * space read/write faults, will also receive a second mcheck, upon
549 * lowering IPL during completion processing in pci_read_config_byte()
552 * Hence all the taken/expected/any_expected/last_taken stuff...
555 t2_machine_check(unsigned long vector
, unsigned long la_ptr
)
557 int cpu
= smp_processor_id();
558 #ifdef CONFIG_VERBOSE_MCHECK
559 struct el_common
*mchk_header
= (struct el_common
*)la_ptr
;
562 /* Clear the error before any reporting. */
566 t2_clear_errors(cpu
);
568 /* This should not actually be done until the logout frame is
569 examined, but, since we don't do that, go on and do this... */
573 /* Now, do testing for the anomalous conditions. */
574 if (!mcheck_expected(cpu
) && t2_mcheck_any_expected
) {
576 * FUNKY: Received mcheck on a CPU and not
577 * expecting it, but another CPU is expecting one.
579 * Just dismiss it for now on this CPU...
581 #ifdef CONFIG_VERBOSE_MCHECK
582 if (alpha_verbose_mcheck
> 1) {
583 printk("t2_machine_check(cpu%d): any_expected 0x%x -"
584 " (assumed) spurious -"
585 " code 0x%x\n", cpu
, t2_mcheck_any_expected
,
586 (unsigned int)mchk_header
->code
);
592 if (!mcheck_expected(cpu
) && !t2_mcheck_any_expected
) {
593 if (t2_mcheck_last_taken
& (1 << cpu
)) {
594 #ifdef CONFIG_VERBOSE_MCHECK
595 if (alpha_verbose_mcheck
> 1) {
596 printk("t2_machine_check(cpu%d): last_taken 0x%x - "
597 "unexpected mcheck - code 0x%x\n",
598 cpu
, t2_mcheck_last_taken
,
599 (unsigned int)mchk_header
->code
);
602 t2_mcheck_last_taken
= 0;
606 t2_mcheck_last_taken
= 0;
611 #ifdef CONFIG_VERBOSE_MCHECK
612 if (alpha_verbose_mcheck
> 1) {
613 printk("%s t2_mcheck(cpu%d): last_taken 0x%x - "
614 "any_expected 0x%x - code 0x%x\n",
615 (mcheck_expected(cpu
) ? "EX" : "UN"), cpu
,
616 t2_mcheck_last_taken
, t2_mcheck_any_expected
,
617 (unsigned int)mchk_header
->code
);
621 process_mcheck_info(vector
, la_ptr
, "T2", mcheck_expected(cpu
));