2 * linux/arch/alpha/kernel/core_apecs.c
4 * Rewritten for Apecs from the lca.c from:
6 * Written by David Mosberger (davidm@cs.arizona.edu) with some code
7 * taken from Dave Rusling's (david.rusling@reo.mts.dec.com) 32-bit
10 * Code common to all APECS core logic chips.
13 #include <linux/kernel.h>
14 #include <linux/types.h>
15 #include <linux/pci.h>
16 #include <linux/init.h>
18 #include <asm/system.h>
19 #include <asm/ptrace.h>
22 #define __EXTERN_INLINE inline
24 #include <asm/core_apecs.h>
25 #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 DBGC(args) printk args
48 #define vuip volatile unsigned int *
51 * Given a bus, device, and function number, compute resulting
52 * configuration space address and setup the APECS_HAXR2 register
53 * accordingly. It is therefore not safe to have concurrent
54 * invocations to configuration space access routines, but there
55 * really shouldn't be any need for this.
59 * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
60 * 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
61 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62 * | | | | | | | | | | | | | | | | | | | | | | | |F|F|F|R|R|R|R|R|R|0|0|
63 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
65 * 31:11 Device select bit.
66 * 10:8 Function number
71 * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
72 * 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
73 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74 * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
75 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
78 * 23:16 bus number (8 bits = 128 possible buses)
79 * 15:11 Device number (5 bits)
80 * 10:8 function number
84 * The function number selects which function of a multi-function device
85 * (e.g., SCSI and Ethernet).
87 * The register selects a DWORD (32 bit) register offset. Hence it
88 * doesn't get shifted by 2 bits as we want to "drop" the bottom two
93 mk_conf_addr(struct pci_dev *dev, int where, unsigned long *pci_addr,
97 u8 bus = dev->bus->number;
98 u8 device_fn = dev->devfn;
100 DBGC(("mk_conf_addr(bus=%d ,device_fn=0x%x, where=0x%x,"
101 " pci_addr=0x%p, type1=0x%p)\n",
102 bus, device_fn, where, pci_addr, type1));
105 int device = device_fn >> 3;
107 /* type 0 configuration cycle: */
110 DBGC(("mk_conf_addr: device (%d) > 20, returning -1\n",
116 addr = (device_fn << 8) | (where);
118 /* type 1 configuration cycle: */
120 addr = (bus << 16) | (device_fn << 8) | (where);
123 DBGC(("mk_conf_addr: returning pci_addr 0x%lx\n", addr));
128 conf_read(unsigned long addr, unsigned char type1)
131 unsigned int stat0, value;
132 unsigned int haxr2 = 0;
134 __save_and_cli(flags); /* avoid getting hit by machine check */
136 DBGC(("conf_read(addr=0x%lx, type1=%d)\n", addr, type1));
138 /* Reset status register to avoid losing errors. */
139 stat0 = *(vuip)APECS_IOC_DCSR;
140 *(vuip)APECS_IOC_DCSR = stat0;
142 DBGC(("conf_read: APECS DCSR was 0x%x\n", stat0));
144 /* If Type1 access, must set HAE #2. */
146 haxr2 = *(vuip)APECS_IOC_HAXR2;
148 *(vuip)APECS_IOC_HAXR2 = haxr2 | 1;
149 DBGC(("conf_read: TYPE1 access\n"));
153 mcheck_expected(0) = 1;
157 /* Access configuration space. */
159 /* Some SRMs step on these registers during a machine check. */
160 asm volatile("ldl %0,%1; mb; mb" : "=r"(value) : "m"(*(vuip)addr)
161 : "$9", "$10", "$11", "$12", "$13", "$14", "memory");
163 if (mcheck_taken(0)) {
168 mcheck_expected(0) = 0;
173 * david.rusling@reo.mts.dec.com. This code is needed for the
174 * EB64+ as it does not generate a machine check (why I don't
175 * know). When we build kernels for one particular platform
176 * then we can make this conditional on the type.
180 /* Now look for any errors. */
181 stat0 = *(vuip)APECS_IOC_DCSR;
182 DBGC(("conf_read: APECS DCSR after read 0x%x\n", stat0));
184 /* Is any error bit set? */
185 if (stat0 & 0xffe0U) {
186 /* If not NDEV, print status. */
187 if (!(stat0 & 0x0800)) {
188 printk("apecs.c:conf_read: got stat0=%x\n", stat0);
191 /* Reset error status. */
192 *(vuip)APECS_IOC_DCSR = stat0;
194 wrmces(0x7); /* reset machine check */
199 /* If Type1 access, must reset HAE #2 so normal IO space ops work. */
201 *(vuip)APECS_IOC_HAXR2 = haxr2 & ~1;
204 __restore_flags(flags);
210 conf_write(unsigned long addr, unsigned int value, unsigned char type1)
214 unsigned int haxr2 = 0;
216 __save_and_cli(flags); /* avoid getting hit by machine check */
218 /* Reset status register to avoid losing errors. */
219 stat0 = *(vuip)APECS_IOC_DCSR;
220 *(vuip)APECS_IOC_DCSR = stat0;
223 /* If Type1 access, must set HAE #2. */
225 haxr2 = *(vuip)APECS_IOC_HAXR2;
227 *(vuip)APECS_IOC_HAXR2 = haxr2 | 1;
231 mcheck_expected(0) = 1;
234 /* Access configuration space. */
238 mcheck_expected(0) = 0;
243 * david.rusling@reo.mts.dec.com. This code is needed for the
244 * EB64+ as it does not generate a machine check (why I don't
245 * know). When we build kernels for one particular platform
246 * then we can make this conditional on the type.
250 /* Now look for any errors. */
251 stat0 = *(vuip)APECS_IOC_DCSR;
253 /* Is any error bit set? */
254 if (stat0 & 0xffe0U) {
255 /* If not NDEV, print status. */
256 if (!(stat0 & 0x0800)) {
257 printk("apecs.c:conf_write: got stat0=%x\n", stat0);
260 /* Reset error status. */
261 *(vuip)APECS_IOC_DCSR = stat0;
263 wrmces(0x7); /* reset machine check */
267 /* If Type1 access, must reset HAE #2 so normal IO space ops work. */
269 *(vuip)APECS_IOC_HAXR2 = haxr2 & ~1;
272 __restore_flags(flags);
276 apecs_read_config_byte(struct pci_dev *dev, int where, u8 *value)
278 unsigned long addr, pci_addr;
281 if (mk_conf_addr(dev, where, &pci_addr, &type1))
282 return PCIBIOS_DEVICE_NOT_FOUND;
284 addr = (pci_addr << 5) + 0x00 + APECS_CONF;
285 *value = conf_read(addr, type1) >> ((where & 3) * 8);
286 return PCIBIOS_SUCCESSFUL;
290 apecs_read_config_word(struct pci_dev *dev, int where, u16 *value)
292 unsigned long addr, pci_addr;
295 if (mk_conf_addr(dev, where, &pci_addr, &type1))
296 return PCIBIOS_DEVICE_NOT_FOUND;
298 addr = (pci_addr << 5) + 0x08 + APECS_CONF;
299 *value = conf_read(addr, type1) >> ((where & 3) * 8);
300 return PCIBIOS_SUCCESSFUL;
304 apecs_read_config_dword(struct pci_dev *dev, int where, u32 *value)
306 unsigned long addr, pci_addr;
309 if (mk_conf_addr(dev, where, &pci_addr, &type1))
310 return PCIBIOS_DEVICE_NOT_FOUND;
312 addr = (pci_addr << 5) + 0x18 + APECS_CONF;
313 *value = conf_read(addr, type1);
314 return PCIBIOS_SUCCESSFUL;
318 apecs_write_config(struct pci_dev *dev, int where, u32 value, long mask)
320 unsigned long addr, pci_addr;
323 if (mk_conf_addr(dev, where, &pci_addr, &type1))
324 return PCIBIOS_DEVICE_NOT_FOUND;
326 addr = (pci_addr << 5) + mask + APECS_CONF;
327 conf_write(addr, value << ((where & 3) * 8), type1);
328 return PCIBIOS_SUCCESSFUL;
332 apecs_write_config_byte(struct pci_dev *dev, int where, u8 value)
334 return apecs_write_config(dev, where, value, 0x00);
338 apecs_write_config_word(struct pci_dev *dev, int where, u16 value)
340 return apecs_write_config(dev, where, value, 0x08);
344 apecs_write_config_dword(struct pci_dev *dev, int where, u32 value)
346 return apecs_write_config(dev, where, value, 0x18);
349 struct pci_ops apecs_pci_ops =
351 read_byte: apecs_read_config_byte,
352 read_word: apecs_read_config_word,
353 read_dword: apecs_read_config_dword,
354 write_byte: apecs_write_config_byte,
355 write_word: apecs_write_config_word,
356 write_dword: apecs_write_config_dword
360 apecs_pci_tbi(struct pci_controller *hose, dma_addr_t start, dma_addr_t end)
363 *(vip)APECS_IOC_TBIA = 0;
368 apecs_init_arch(void)
370 struct pci_controller *hose;
373 * Create our single hose.
376 pci_isa_hose = hose = alloc_pci_controller();
377 hose->io_space = &ioport_resource;
378 hose->mem_space = &iomem_resource;
381 hose->sparse_mem_base = APECS_SPARSE_MEM - IDENT_ADDR;
382 hose->dense_mem_base = APECS_DENSE_MEM - IDENT_ADDR;
383 hose->sparse_io_base = APECS_IO - IDENT_ADDR;
384 hose->dense_io_base = 0;
387 * Set up the PCI to main memory translation windows.
389 * Window 1 is direct access 1GB at 1GB
390 * Window 2 is scatter-gather 8MB at 8MB (for isa)
392 hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000, 0);
394 __direct_map_base = 0x40000000;
395 __direct_map_size = 0x40000000;
397 *(vuip)APECS_IOC_PB1R = __direct_map_base | 0x00080000;
398 *(vuip)APECS_IOC_PM1R = (__direct_map_size - 1) & 0xfff00000U;
399 *(vuip)APECS_IOC_TB1R = 0;
401 *(vuip)APECS_IOC_PB2R = hose->sg_isa->dma_base | 0x000c0000;
402 *(vuip)APECS_IOC_PM2R = (hose->sg_isa->size - 1) & 0xfff00000;
403 *(vuip)APECS_IOC_TB2R = virt_to_phys(hose->sg_isa->ptes) >> 1;
405 apecs_pci_tbi(hose, 0, -1);
408 * Finally, clear the HAXR2 register, which gets used
409 * for PCI Config Space accesses. That is the way
410 * we want to use it, and we do not want to depend on
411 * what ARC or SRM might have left behind...
413 *(vuip)APECS_IOC_HAXR2 = 0;
418 apecs_pci_clr_err(void)
422 jd = *(vuip)APECS_IOC_DCSR;
424 *(vuip)APECS_IOC_SEAR;
425 *(vuip)APECS_IOC_DCSR = jd | 0xffe1L;
427 *(vuip)APECS_IOC_DCSR;
429 *(vuip)APECS_IOC_TBIA = (unsigned int)APECS_IOC_TBIA;
431 *(vuip)APECS_IOC_TBIA;
435 apecs_machine_check(unsigned long vector, unsigned long la_ptr,
436 struct pt_regs * regs)
438 struct el_common *mchk_header;
439 struct el_apecs_procdata *mchk_procdata;
440 struct el_apecs_sysdata_mcheck *mchk_sysdata;
442 mchk_header = (struct el_common *)la_ptr;
444 mchk_procdata = (struct el_apecs_procdata *)
445 (la_ptr + mchk_header->proc_offset
446 - sizeof(mchk_procdata->paltemp));
448 mchk_sysdata = (struct el_apecs_sysdata_mcheck *)
449 (la_ptr + mchk_header->sys_offset);
452 /* Clear the error before any reporting. */
457 wrmces(0x7); /* reset machine check pending flag */
460 process_mcheck_info(vector, la_ptr, regs, "APECS",
462 && (mchk_sysdata->epic_dcsr & 0x0c00UL)));