2 * linux/arch/alpha/kernel/core_mcpcia.c
4 * Based on code written by David A Rusling (david.rusling@reo.mts.dec.com).
6 * Code common to all MCbus-PCI Adaptor core logic chipsets
9 #include <linux/kernel.h>
10 #include <linux/types.h>
11 #include <linux/pci.h>
12 #include <linux/sched.h>
13 #include <linux/init.h>
14 #include <linux/delay.h>
16 #include <asm/ptrace.h>
17 #include <asm/system.h>
18 #include <asm/hwrpb.h>
20 #define __EXTERN_INLINE inline
22 #include <asm/core_mcpcia.h>
23 #undef __EXTERN_INLINE
29 * NOTE: Herein lie back-to-back mb instructions. They are magic.
30 * One plausible explanation is that the i/o controller does not properly
31 * handle the system transaction. Another involves timing. Ho hum.
35 * BIOS32-style PCI interface:
41 # define DBG_CFG(args) printk args
43 # define DBG_CFG(args)
46 #define MCPCIA_MAX_HOSES 4
48 /* Dodge has PCI0 and PCI1 at MID 4 and 5 respectively. Durango adds
49 PCI2 and PCI3 at MID 6 and 7 respectively. */
51 #define hose2mid(h) ((h) + 4)
55 * Given a bus, device, and function number, compute resulting
56 * configuration space address and setup the MCPCIA_HAXR2 register
57 * accordingly. It is therefore not safe to have concurrent
58 * invocations to configuration space access routines, but there
59 * really shouldn't be any need for this.
63 * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
64 * 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
65 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66 * | | |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|
67 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
69 * 31:11 Device select bit.
70 * 10:8 Function number
75 * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
76 * 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
77 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
78 * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
79 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
82 * 23:16 bus number (8 bits = 128 possible buses)
83 * 15:11 Device number (5 bits)
84 * 10:8 function number
88 * The function number selects which function of a multi-function device
89 * (e.g., SCSI and Ethernet).
91 * The register selects a DWORD (32 bit) register offset. Hence it
92 * doesn't get shifted by 2 bits as we want to "drop" the bottom two
97 conf_read(unsigned long addr
, unsigned char type1
,
98 struct pci_controler
*hose
)
101 unsigned long mid
= hose2mid(hose
->index
);
102 unsigned int stat0
, value
, temp
, cpu
;
104 cpu
= smp_processor_id();
106 __save_and_cli(flags
);
108 DBG_CFG(("conf_read(addr=0x%lx, type1=%d, hose=%d)\n",
111 /* Reset status register to avoid losing errors. */
112 stat0
= *(vuip
)MCPCIA_CAP_ERR(mid
);
113 *(vuip
)MCPCIA_CAP_ERR(mid
) = stat0
;
115 temp
= *(vuip
)MCPCIA_CAP_ERR(mid
);
116 DBG_CFG(("conf_read: MCPCIA_CAP_ERR(%d) was 0x%x\n", mid
, stat0
));
120 mcheck_expected(cpu
) = 1;
121 mcheck_taken(cpu
) = 0;
122 mcheck_extra(cpu
) = mid
;
125 /* Access configuration space. */
126 value
= *((vuip
)addr
);
130 if (mcheck_taken(cpu
)) {
131 mcheck_taken(cpu
) = 0;
135 mcheck_expected(cpu
) = 0;
138 DBG_CFG(("conf_read(): finished\n"));
140 __restore_flags(flags
);
145 conf_write(unsigned long addr
, unsigned int value
, unsigned char type1
,
146 struct pci_controler
*hose
)
149 unsigned long mid
= hose2mid(hose
->index
);
150 unsigned int stat0
, temp
, cpu
;
152 cpu
= smp_processor_id();
154 __save_and_cli(flags
); /* avoid getting hit by machine check */
156 /* Reset status register to avoid losing errors. */
157 stat0
= *(vuip
)MCPCIA_CAP_ERR(mid
);
158 *(vuip
)MCPCIA_CAP_ERR(mid
) = stat0
; mb();
159 temp
= *(vuip
)MCPCIA_CAP_ERR(mid
);
160 DBG_CFG(("conf_write: MCPCIA CAP_ERR(%d) was 0x%x\n", mid
, stat0
));
163 mcheck_expected(cpu
) = 1;
164 mcheck_extra(cpu
) = mid
;
167 /* Access configuration space. */
168 *((vuip
)addr
) = value
;
171 temp
= *(vuip
)MCPCIA_CAP_ERR(mid
); /* read to force the write */
172 mcheck_expected(cpu
) = 0;
175 DBG_CFG(("conf_write(): finished\n"));
176 __restore_flags(flags
);
180 mk_conf_addr(struct pci_dev
*dev
, int where
, struct pci_controler
*hose
,
181 unsigned long *pci_addr
, unsigned char *type1
)
183 u8 bus
= dev
->bus
->number
;
184 u8 devfn
= dev
->devfn
;
187 DBG_CFG(("mk_conf_addr(bus=%d,devfn=0x%x,hose=%d,where=0x%x,"
188 " pci_addr=0x%p, type1=0x%p)\n",
189 bus
, devfn
, hose
->index
, where
, pci_addr
, type1
));
191 /* Type 1 configuration cycle for *ALL* busses. */
194 if (dev
->bus
->number
== hose
->first_busno
)
196 addr
= (bus
<< 16) | (devfn
<< 8) | (where
);
197 addr
<<= 5; /* swizzle for SPARSE */
198 addr
|= hose
->config_space
;
201 DBG_CFG(("mk_conf_addr: returning pci_addr 0x%lx\n", addr
));
206 mcpcia_read_config_byte(struct pci_dev
*dev
, int where
, u8
*value
)
208 struct pci_controler
*hose
= dev
->sysdata
;
209 unsigned long addr
, w
;
212 if (mk_conf_addr(dev
, where
, hose
, &addr
, &type1
))
213 return PCIBIOS_DEVICE_NOT_FOUND
;
216 w
= conf_read(addr
, type1
, hose
);
217 *value
= __kernel_extbl(w
, where
& 3);
218 return PCIBIOS_SUCCESSFUL
;
222 mcpcia_read_config_word(struct pci_dev
*dev
, int where
, u16
*value
)
224 struct pci_controler
*hose
= dev
->sysdata
;
225 unsigned long addr
, w
;
228 if (mk_conf_addr(dev
, where
, hose
, &addr
, &type1
))
229 return PCIBIOS_DEVICE_NOT_FOUND
;
232 w
= conf_read(addr
, type1
, hose
);
233 *value
= __kernel_extwl(w
, where
& 3);
234 return PCIBIOS_SUCCESSFUL
;
238 mcpcia_read_config_dword(struct pci_dev
*dev
, int where
, u32
*value
)
240 struct pci_controler
*hose
= dev
->sysdata
;
244 if (mk_conf_addr(dev
, where
, hose
, &addr
, &type1
))
245 return PCIBIOS_DEVICE_NOT_FOUND
;
248 *value
= conf_read(addr
, type1
, hose
);
249 return PCIBIOS_SUCCESSFUL
;
253 mcpcia_write_config(struct pci_dev
*dev
, int where
, u32 value
, long mask
)
255 struct pci_controler
*hose
= dev
->sysdata
;
259 if (mk_conf_addr(dev
, where
, hose
, &addr
, &type1
))
260 return PCIBIOS_DEVICE_NOT_FOUND
;
263 value
= __kernel_insql(value
, where
& 3);
264 conf_write(addr
, value
, type1
, hose
);
265 return PCIBIOS_SUCCESSFUL
;
269 mcpcia_write_config_byte(struct pci_dev
*dev
, int where
, u8 value
)
271 return mcpcia_write_config(dev
, where
, value
, 0x00);
275 mcpcia_write_config_word(struct pci_dev
*dev
, int where
, u16 value
)
277 return mcpcia_write_config(dev
, where
, value
, 0x08);
281 mcpcia_write_config_dword(struct pci_dev
*dev
, int where
, u32 value
)
283 return mcpcia_write_config(dev
, where
, value
, 0x18);
286 struct pci_ops mcpcia_pci_ops
=
288 read_byte
: mcpcia_read_config_byte
,
289 read_word
: mcpcia_read_config_word
,
290 read_dword
: mcpcia_read_config_dword
,
291 write_byte
: mcpcia_write_config_byte
,
292 write_word
: mcpcia_write_config_word
,
293 write_dword
: mcpcia_write_config_dword
297 mcpcia_probe_hose(int h
)
299 int cpu
= smp_processor_id();
300 int mid
= hose2mid(h
);
301 unsigned int pci_rev
;
303 /* Gotta be REAL careful. If hose is absent, we get an mcheck. */
309 mcheck_expected(cpu
) = 2; /* indicates probing */
310 mcheck_taken(cpu
) = 0;
311 mcheck_extra(cpu
) = mid
;
314 /* Access the bus revision word. */
315 pci_rev
= *(vuip
)MCPCIA_REV(mid
);
319 if (mcheck_taken(cpu
)) {
320 mcheck_taken(cpu
) = 0;
321 pci_rev
= 0xffffffff;
324 mcheck_expected(cpu
) = 0;
327 return (pci_rev
>> 16) == PCI_CLASS_BRIDGE_HOST
;
331 mcpcia_new_hose(int h
)
333 struct pci_controler
*hose
;
334 struct resource
*io
, *mem
, *hae_mem
;
335 int mid
= hose2mid(h
);
337 hose
= alloc_pci_controler();
338 io
= alloc_resource();
339 mem
= alloc_resource();
340 hae_mem
= alloc_resource();
343 hose
->mem_space
= hae_mem
;
344 hose
->config_space
= MCPCIA_CONF(mid
);
347 io
->start
= MCPCIA_IO(mid
) - MCPCIA_IO_BIAS
;
348 io
->end
= io
->start
+ 0xffff;
349 io
->name
= pci_io_names
[h
];
350 io
->flags
= IORESOURCE_IO
;
352 mem
->start
= MCPCIA_DENSE(mid
) - MCPCIA_MEM_BIAS
;
353 mem
->end
= mem
->start
+ 0xffffffff;
354 mem
->name
= pci_mem_names
[h
];
355 mem
->flags
= IORESOURCE_MEM
;
357 hae_mem
->start
= mem
->start
;
358 hae_mem
->end
= mem
->start
+ MCPCIA_MEM_MASK
;
359 hae_mem
->name
= pci_hae0_name
;
360 hae_mem
->flags
= IORESOURCE_MEM
;
362 if (request_resource(&ioport_resource
, io
) < 0)
363 printk(KERN_ERR
"Failed to request IO on hose %d\n", h
);
364 if (request_resource(&iomem_resource
, mem
) < 0)
365 printk(KERN_ERR
"Failed to request MEM on hose %d\n", h
);
366 if (request_resource(mem
, hae_mem
) < 0)
367 printk(KERN_ERR
"Failed to request HAE_MEM on hose %d\n", h
);
371 mcpcia_pci_clr_err(int mid
)
373 *(vuip
)MCPCIA_CAP_ERR(mid
);
374 *(vuip
)MCPCIA_CAP_ERR(mid
) = 0xffffffff; /* Clear them all. */
376 *(vuip
)MCPCIA_CAP_ERR(mid
); /* Re-read for force write. */
380 mcpcia_startup_hose(struct pci_controler
*hose
)
382 int mid
= hose2mid(hose
->index
);
385 mcpcia_pci_clr_err(mid
);
388 * Set up error reporting.
390 tmp
= *(vuip
)MCPCIA_CAP_ERR(mid
);
391 tmp
|= 0x0006; /* master/target abort */
392 *(vuip
)MCPCIA_CAP_ERR(mid
) = tmp
;
394 tmp
= *(vuip
)MCPCIA_CAP_ERR(mid
);
397 * Set up the PCI->physical memory translation windows.
398 * For now, windows 1,2 and 3 are disabled. In the
399 * future, we may want to use them to do scatter/
402 * Window 0 goes at 2 GB and is 2 GB large.
405 *(vuip
)MCPCIA_W0_BASE(mid
) = 1U | (MCPCIA_DMA_WIN_BASE
& 0xfff00000U
);
406 *(vuip
)MCPCIA_W0_MASK(mid
) = (MCPCIA_DMA_WIN_SIZE
- 1) & 0xfff00000U
;
407 *(vuip
)MCPCIA_T0_BASE(mid
) = 0;
409 *(vuip
)MCPCIA_W1_BASE(mid
) = 0x0;
410 *(vuip
)MCPCIA_W2_BASE(mid
) = 0x0;
411 *(vuip
)MCPCIA_W3_BASE(mid
) = 0x0;
413 *(vuip
)MCPCIA_HBASE(mid
) = 0x0;
417 tmp
= *(vuip
)MCPCIA_INT_CTL(mid
);
418 printk("mcpcia_startup_hose: INT_CTL was 0x%x\n", tmp
);
419 *(vuip
)MCPCIA_INT_CTL(mid
) = 1U;
421 tmp
= *(vuip
)MCPCIA_INT_CTL(mid
);
424 *(vuip
)MCPCIA_HAE_MEM(mid
) = 0U;
426 *(vuip
)MCPCIA_HAE_MEM(mid
); /* read it back. */
427 *(vuip
)MCPCIA_HAE_IO(mid
) = 0;
429 *(vuip
)MCPCIA_HAE_IO(mid
); /* read it back. */
433 mcpcia_init_arch(void)
435 /* With multiple PCI busses, we play with I/O as physical addrs. */
436 ioport_resource
.end
= ~0UL;
437 iomem_resource
.end
= ~0UL;
439 /* Allocate hose 0. That's the one that all the ISA junk hangs
440 off of, from which we'll be registering stuff here in a bit.
441 Other hose detection is done in mcpcia_init_hoses, which is
442 called from init_IRQ. */
447 /* This is called from init_IRQ, since we cannot take interrupts
448 before then. Which means we cannot do this in init_arch. */
451 mcpcia_init_hoses(void)
453 struct pci_controler
*hose
;
454 int h
, hose_count
= 0;
456 /* First, find how many hoses we have. */
457 for (h
= 0; h
< MCPCIA_MAX_HOSES
; ++h
) {
458 if (mcpcia_probe_hose(h
)) {
465 printk("mcpcia_init_hoses: found %d hoses\n", hose_count
);
467 /* Now do init for each hose. */
468 for (hose
= hose_head
; hose
; hose
= hose
->next
)
469 mcpcia_startup_hose(hose
);
473 mcpcia_print_uncorrectable(struct el_MCPCIA_uncorrected_frame_mcheck
*logout
)
475 struct el_common_EV5_uncorrectable_mcheck
*frame
;
478 frame
= &logout
->procdata
;
480 /* Print PAL fields */
481 for (i
= 0; i
< 24; i
+= 2) {
482 printk(" paltmp[%d-%d] = %16lx %16lx\n",
483 i
, i
+1, frame
->paltemp
[i
], frame
->paltemp
[i
+1]);
485 for (i
= 0; i
< 8; i
+= 2) {
486 printk(" shadow[%d-%d] = %16lx %16lx\n",
487 i
, i
+1, frame
->shadow
[i
],
490 printk(" Addr of excepting instruction = %16lx\n",
492 printk(" Summary of arithmetic traps = %16lx\n",
494 printk(" Exception mask = %16lx\n",
496 printk(" Base address for PALcode = %16lx\n",
498 printk(" Interrupt Status Reg = %16lx\n",
500 printk(" CURRENT SETUP OF EV5 IBOX = %16lx\n",
502 printk(" I-CACHE Reg %s parity error = %16lx\n",
503 (frame
->ic_perr_stat
& 0x800L
) ?
505 frame
->ic_perr_stat
);
506 printk(" D-CACHE error Reg = %16lx\n",
507 frame
->dc_perr_stat
);
508 if (frame
->dc_perr_stat
& 0x2) {
509 switch (frame
->dc_perr_stat
& 0x03c) {
511 printk(" Data error in bank 1\n");
514 printk(" Data error in bank 0\n");
517 printk(" Tag error in bank 1\n");
520 printk(" Tag error in bank 0\n");
524 printk(" Effective VA = %16lx\n",
526 printk(" Reason for D-stream = %16lx\n",
528 printk(" EV5 SCache address = %16lx\n",
530 printk(" EV5 SCache TAG/Data parity = %16lx\n",
532 printk(" EV5 BC_TAG_ADDR = %16lx\n",
534 printk(" EV5 EI_ADDR: Phys addr of Xfer = %16lx\n",
536 printk(" Fill Syndrome = %16lx\n",
537 frame
->fill_syndrome
);
538 printk(" EI_STAT reg = %16lx\n",
540 printk(" LD_LOCK = %16lx\n",
545 mcpcia_machine_check(unsigned long vector
, unsigned long la_ptr
,
546 struct pt_regs
* regs
)
548 struct el_common
*mchk_header
;
549 struct el_MCPCIA_uncorrected_frame_mcheck
*mchk_logout
;
550 unsigned int cpu
= smp_processor_id();
553 mchk_header
= (struct el_common
*)la_ptr
;
554 mchk_logout
= (struct el_MCPCIA_uncorrected_frame_mcheck
*)la_ptr
;
555 expected
= mcheck_expected(cpu
);
564 /* FIXME: how do we figure out which hose the
566 struct pci_controler
*hose
;
567 for (hose
= hose_head
; hose
; hose
= hose
->next
)
568 mcpcia_pci_clr_err(hose2mid(hose
->index
));
572 mcpcia_pci_clr_err(mcheck_extra(cpu
));
575 /* Otherwise, we're being called from mcpcia_probe_hose
576 and there's no hose clear an error from. */
583 process_mcheck_info(vector
, la_ptr
, regs
, "MCPCIA", expected
!= 0);
584 if (!expected
&& vector
!= 0x620 && vector
!= 0x630)
585 mcpcia_print_uncorrectable(mchk_logout
);