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 #include <linux/kernel.h>
13 #include <linux/types.h>
14 #include <linux/pci.h>
15 #include <linux/sched.h>
16 #include <linux/init.h>
18 #include <asm/ptrace.h>
19 #include <asm/system.h>
21 #define __EXTERN_INLINE
23 #include <asm/core_t2.h>
24 #undef __EXTERN_INLINE
31 * NOTE: Herein lie back-to-back mb instructions. They are magic.
32 * One plausible explanation is that the i/o controller does not properly
33 * handle the system transaction. Another involves timing. Ho hum.
37 * BIOS32-style PCI interface:
40 #define DEBUG_CONFIG 0
43 # define DBG(args) printk args
50 * Given a bus, device, and function number, compute resulting
51 * configuration space address and setup the T2_HAXR2 register
52 * accordingly. It is therefore not safe to have concurrent
53 * invocations to configuration space access routines, but there
54 * really shouldn't be any need for this.
58 * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
59 * 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
60 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
61 * | | |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|
62 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64 * 31:11 Device select bit.
65 * 10:8 Function number
70 * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
71 * 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
72 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73 * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
74 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
77 * 23:16 bus number (8 bits = 128 possible buses)
78 * 15:11 Device number (5 bits)
79 * 10:8 function number
83 * The function number selects which function of a multi-function device
84 * (e.g., SCSI and Ethernet).
86 * The register selects a DWORD (32 bit) register offset. Hence it
87 * doesn't get shifted by 2 bits as we want to "drop" the bottom two
92 mk_conf_addr(struct pci_dev
*dev
, int where
, unsigned long *pci_addr
,
96 u8 bus
= dev
->bus
->number
;
97 u8 device_fn
= dev
->devfn
;
99 DBG(("mk_conf_addr(bus=%d, dfn=0x%x, where=0x%x,"
100 " addr=0x%lx, type1=0x%x)\n",
101 bus
, device_fn
, where
, pci_addr
, type1
));
104 int device
= device_fn
>> 3;
106 /* Type 0 configuration cycle. */
109 DBG(("mk_conf_addr: device (%d)>20, returning -1\n",
115 addr
= (0x0800L
<< device
) | ((device_fn
& 7) << 8) | (where
);
117 /* Type 1 configuration cycle. */
119 addr
= (bus
<< 16) | (device_fn
<< 8) | (where
);
122 DBG(("mk_conf_addr: returning pci_addr 0x%lx\n", addr
));
127 conf_read(unsigned long addr
, unsigned char type1
)
130 unsigned int value
, cpu
;
131 unsigned long t2_cfg
= 0;
133 cpu
= smp_processor_id();
135 __save_and_cli(flags
); /* avoid getting hit by machine check */
137 DBG(("conf_read(addr=0x%lx, type1=%d)\n", addr
, type1
));
142 /* Reset status register to avoid losing errors. */
143 stat0
= *(vulp
)T2_IOCSR
;
144 *(vulp
)T2_IOCSR
= stat0
;
146 DBG(("conf_read: T2 IOCSR was 0x%x\n", stat0
));
150 /* If Type1 access, must set T2 CFG. */
152 t2_cfg
= *(vulp
)T2_HAE_3
& ~0xc0000000UL
;
153 *(vulp
)T2_HAE_3
= 0x40000000UL
| t2_cfg
;
155 DBG(("conf_read: TYPE1 access\n"));
160 mcheck_expected(cpu
) = 1;
161 mcheck_taken(cpu
) = 0;
164 /* Access configuration space. */
169 if (mcheck_taken(cpu
)) {
170 mcheck_taken(cpu
) = 0;
174 mcheck_expected(cpu
) = 0;
177 /* If Type1 access, must reset T2 CFG so normal IO space ops work. */
179 *(vulp
)T2_HAE_3
= t2_cfg
;
182 DBG(("conf_read(): finished\n"));
184 __restore_flags(flags
);
189 conf_write(unsigned long addr
, unsigned int value
, unsigned char type1
)
193 unsigned long t2_cfg
= 0;
195 cpu
= smp_processor_id();
197 __save_and_cli(flags
); /* avoid getting hit by machine check */
202 /* Reset status register to avoid losing errors. */
203 stat0
= *(vulp
)T2_IOCSR
;
204 *(vulp
)T2_IOCSR
= stat0
;
206 DBG(("conf_write: T2 ERR was 0x%x\n", stat0
));
210 /* If Type1 access, must set T2 CFG. */
212 t2_cfg
= *(vulp
)T2_HAE_3
& ~0xc0000000UL
;
213 *(vulp
)T2_HAE_3
= t2_cfg
| 0x40000000UL
;
215 DBG(("conf_write: TYPE1 access\n"));
220 mcheck_expected(cpu
) = 1;
223 /* Access configuration space. */
228 mcheck_expected(cpu
) = 0;
231 /* If Type1 access, must reset T2 CFG so normal IO space ops work. */
233 *(vulp
)T2_HAE_3
= t2_cfg
;
236 DBG(("conf_write(): finished\n"));
237 __restore_flags(flags
);
241 t2_read_config_byte(struct pci_dev
*dev
, int where
, u8
*value
)
243 unsigned long addr
, pci_addr
;
246 if (mk_conf_addr(dev
, where
, &pci_addr
, &type1
))
247 return PCIBIOS_DEVICE_NOT_FOUND
;
249 addr
= (pci_addr
<< 5) + 0x00 + T2_CONF
;
250 *value
= conf_read(addr
, type1
) >> ((where
& 3) * 8);
251 return PCIBIOS_SUCCESSFUL
;
255 t2_read_config_word(struct pci_dev
*dev
, int where
, u16
*value
)
257 unsigned long addr
, pci_addr
;
260 if (mk_conf_addr(dev
, where
, &pci_addr
, &type1
))
261 return PCIBIOS_DEVICE_NOT_FOUND
;
263 addr
= (pci_addr
<< 5) + 0x08 + T2_CONF
;
264 *value
= conf_read(addr
, type1
) >> ((where
& 3) * 8);
265 return PCIBIOS_SUCCESSFUL
;
269 t2_read_config_dword(struct pci_dev
*dev
, int where
, u32
*value
)
271 unsigned long addr
, pci_addr
;
274 if (mk_conf_addr(dev
, where
, &pci_addr
, &type1
))
275 return PCIBIOS_DEVICE_NOT_FOUND
;
277 addr
= (pci_addr
<< 5) + 0x18 + T2_CONF
;
278 *value
= conf_read(addr
, type1
);
279 return PCIBIOS_SUCCESSFUL
;
283 t2_write_config(struct pci_dev
*dev
, int where
, u32 value
, long mask
)
285 unsigned long addr
, pci_addr
;
288 if (mk_conf_addr(dev
, where
, &pci_addr
, &type1
))
289 return PCIBIOS_DEVICE_NOT_FOUND
;
291 addr
= (pci_addr
<< 5) + mask
+ T2_CONF
;
292 conf_write(addr
, value
<< ((where
& 3) * 8), type1
);
293 return PCIBIOS_SUCCESSFUL
;
297 t2_write_config_byte(struct pci_dev
*dev
, int where
, u8 value
)
299 return t2_write_config(dev
, where
, value
, 0x00);
303 t2_write_config_word(struct pci_dev
*dev
, int where
, u16 value
)
305 return t2_write_config(dev
, where
, value
, 0x08);
309 t2_write_config_dword(struct pci_dev
*dev
, int where
, u32 value
)
311 return t2_write_config(dev
, where
, value
, 0x18);
314 struct pci_ops t2_pci_ops
=
316 read_byte
: t2_read_config_byte
,
317 read_word
: t2_read_config_word
,
318 read_dword
: t2_read_config_dword
,
319 write_byte
: t2_write_config_byte
,
320 write_word
: t2_write_config_word
,
321 write_dword
: t2_write_config_dword
325 t2_init_arch(unsigned long *mem_start
, unsigned long *mem_end
)
327 struct pci_controler
*hose
;
330 for (i
= 0; i
< NR_CPUS
; i
++) {
331 mcheck_expected(i
) = 0;
337 /* Set up error reporting. */
338 unsigned long t2_err
;
340 t2_err
= *(vulp
)T2_IOCSR
;
341 t2_err
|= (0x1 << 7); /* master abort */
342 *(vulp
)T2_IOCSR
= t2_err
;
347 printk("t2_init: HBASE was 0x%lx\n", *(vulp
)T2_HBASE
);
349 printk("t2_init: WBASE1=0x%lx WMASK1=0x%lx TBASE1=0x%lx\n",
353 printk("t2_init: WBASE2=0x%lx WMASK2=0x%lx TBASE2=0x%lx\n",
360 * Set up the PCI->physical memory translation windows.
361 * For now, window 2 is disabled. In the future, we may
362 * want to use it to do scatter/gather DMA.
364 * Window 1 goes at 1 GB and is 1 GB large.
367 /* WARNING!! must correspond to the DMA_WIN params!!! */
368 *(vulp
)T2_WBASE1
= 0x400807ffU
;
369 *(vulp
)T2_WMASK1
= 0x3ff00000U
;
370 *(vulp
)T2_TBASE1
= 0;
372 *(vulp
)T2_WBASE2
= 0x0;
373 *(vulp
)T2_HBASE
= 0x0;
376 *(vulp
)T2_HAE_1
= 0; mb();
377 *(vulp
)T2_HAE_2
= 0; mb();
378 *(vulp
)T2_HAE_3
= 0; mb();
380 *(vulp
)T2_HAE_4
= 0; mb(); /* do not touch this */
384 * Create our single hose.
387 hose
= alloc_pci_controler(mem_start
);
388 hose
->io_space
= &ioport_resource
;
389 hose
->mem_space
= &iomem_resource
;
390 hose
->config_space
= T2_CONF
;
394 #define SIC_SEIC (1UL << 33) /* System Event Clear */
397 t2_clear_errors(int cpu
)
399 struct sable_cpu_csr
*cpu_regs
;
401 cpu_regs
= (struct sable_cpu_csr
*)T2_CPU0_BASE
;
403 cpu_regs
= (struct sable_cpu_csr
*)T2_CPU1_BASE
;
405 cpu_regs
= (struct sable_cpu_csr
*)T2_CPU2_BASE
;
407 cpu_regs
= (struct sable_cpu_csr
*)T2_CPU3_BASE
;
409 cpu_regs
->sic
&= ~SIC_SEIC
;
411 /* Clear CPU errors. */
412 cpu_regs
->bcce
|= cpu_regs
->bcce
;
413 cpu_regs
->cbe
|= cpu_regs
->cbe
;
414 cpu_regs
->bcue
|= cpu_regs
->bcue
;
415 cpu_regs
->dter
|= cpu_regs
->dter
;
417 *(vulp
)T2_CERR1
|= *(vulp
)T2_CERR1
;
418 *(vulp
)T2_PERR1
|= *(vulp
)T2_PERR1
;
425 t2_machine_check(unsigned long vector
, unsigned long la_ptr
,
426 struct pt_regs
* regs
)
428 int cpu
= smp_processor_id();
430 /* Clear the error before any reporting. */
434 t2_clear_errors(cpu
);
435 wrmces(rdmces()|1); /* ??? */
438 process_mcheck_info(vector
, la_ptr
, regs
, "T2", mcheck_expected(cpu
));