2 * linux/arch/alpha/kernel/core_lca.c
4 * Written by David Mosberger (davidm@cs.arizona.edu) with some code
5 * taken from Dave Rusling's (david.rusling@reo.mts.dec.com) 32-bit
8 * Code common to all LCA core logic chips.
11 #include <linux/kernel.h>
12 #include <linux/types.h>
13 #include <linux/pci.h>
14 #include <linux/init.h>
15 #include <linux/tty.h>
17 #include <asm/ptrace.h>
18 #include <asm/system.h>
21 #define __EXTERN_INLINE inline
23 #include <asm/core_lca.h>
24 #undef __EXTERN_INLINE
31 * BIOS32-style PCI interface:
35 * Machine check reasons. Defined according to PALcode sources
36 * (osf.h and platform.h).
38 #define MCHK_K_TPERR 0x0080
39 #define MCHK_K_TCPERR 0x0082
40 #define MCHK_K_HERR 0x0084
41 #define MCHK_K_ECC_C 0x0086
42 #define MCHK_K_ECC_NC 0x0088
43 #define MCHK_K_UNKNOWN 0x008A
44 #define MCHK_K_CACKSOFT 0x008C
45 #define MCHK_K_BUGCHECK 0x008E
46 #define MCHK_K_OS_BUGCHECK 0x0090
47 #define MCHK_K_DCPERR 0x0092
48 #define MCHK_K_ICPERR 0x0094
52 * Platform-specific machine-check reasons:
54 #define MCHK_K_SIO_SERR 0x204 /* all platforms so far */
55 #define MCHK_K_SIO_IOCHK 0x206 /* all platforms so far */
56 #define MCHK_K_DCSR 0x208 /* all but Noname */
60 * Given a bus, device, and function number, compute resulting
61 * configuration space address and setup the LCA_IOC_CONF register
62 * accordingly. It is therefore not safe to have concurrent
63 * invocations to configuration space access routines, but there
64 * really shouldn't be any need for this.
68 * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
69 * 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
70 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71 * | | | | | | | | | | | | | | | | | | | | | | | |F|F|F|R|R|R|R|R|R|0|0|
72 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74 * 31:11 Device select bit.
75 * 10:8 Function number
80 * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
81 * 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
82 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
83 * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
84 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
87 * 23:16 bus number (8 bits = 128 possible buses)
88 * 15:11 Device number (5 bits)
89 * 10:8 function number
93 * The function number selects which function of a multi-function device
94 * (e.g., SCSI and Ethernet).
96 * The register selects a DWORD (32 bit) register offset. Hence it
97 * doesn't get shifted by 2 bits as we want to "drop" the bottom two
102 mk_conf_addr(struct pci_dev *dev, int where, unsigned long *pci_addr)
105 u8 bus = dev->bus->number;
106 u8 device_fn = dev->devfn;
109 int device = device_fn >> 3;
110 int func = device_fn & 0x7;
112 /* Type 0 configuration cycle. */
118 *(vulp)LCA_IOC_CONF = 0;
119 addr = (1 << (11 + device)) | (func << 8) | where;
121 /* Type 1 configuration cycle. */
122 *(vulp)LCA_IOC_CONF = 1;
123 addr = (bus << 16) | (device_fn << 8) | where;
130 conf_read(unsigned long addr)
132 unsigned long flags, code, stat0;
135 __save_and_cli(flags);
137 /* Reset status register to avoid loosing errors. */
138 stat0 = *(vulp)LCA_IOC_STAT0;
139 *(vulp)LCA_IOC_STAT0 = stat0;
142 /* Access configuration space. */
146 stat0 = *(vulp)LCA_IOC_STAT0;
147 if (stat0 & LCA_IOC_STAT0_ERR) {
148 code = ((stat0 >> LCA_IOC_STAT0_CODE_SHIFT)
149 & LCA_IOC_STAT0_CODE_MASK);
151 printk("lca.c:conf_read: got stat0=%lx\n", stat0);
154 /* Reset error status. */
155 *(vulp)LCA_IOC_STAT0 = stat0;
158 /* Reset machine check. */
163 __restore_flags(flags);
168 conf_write(unsigned long addr, unsigned int value)
170 unsigned long flags, code, stat0;
172 __save_and_cli(flags); /* avoid getting hit by machine check */
174 /* Reset status register to avoid loosing errors. */
175 stat0 = *(vulp)LCA_IOC_STAT0;
176 *(vulp)LCA_IOC_STAT0 = stat0;
179 /* Access configuration space. */
183 stat0 = *(vulp)LCA_IOC_STAT0;
184 if (stat0 & LCA_IOC_STAT0_ERR) {
185 code = ((stat0 >> LCA_IOC_STAT0_CODE_SHIFT)
186 & LCA_IOC_STAT0_CODE_MASK);
188 printk("lca.c:conf_write: got stat0=%lx\n", stat0);
191 /* Reset error status. */
192 *(vulp)LCA_IOC_STAT0 = stat0;
195 /* Reset machine check. */
198 __restore_flags(flags);
202 lca_read_config_byte(struct pci_dev *dev, int where, u8 *value)
204 unsigned long addr, pci_addr;
206 if (mk_conf_addr(dev, where, &pci_addr))
207 return PCIBIOS_DEVICE_NOT_FOUND;
209 addr = (pci_addr << 5) + 0x00 + LCA_CONF;
210 *value = conf_read(addr) >> ((where & 3) * 8);
211 return PCIBIOS_SUCCESSFUL;
215 lca_read_config_word(struct pci_dev *dev, int where, u16 *value)
217 unsigned long addr, pci_addr;
219 if (mk_conf_addr(dev, where, &pci_addr))
220 return PCIBIOS_DEVICE_NOT_FOUND;
222 addr = (pci_addr << 5) + 0x08 + LCA_CONF;
223 *value = conf_read(addr) >> ((where & 3) * 8);
224 return PCIBIOS_SUCCESSFUL;
228 lca_read_config_dword(struct pci_dev *dev, int where, u32 *value)
230 unsigned long addr, pci_addr;
232 if (mk_conf_addr(dev, where, &pci_addr))
233 return PCIBIOS_DEVICE_NOT_FOUND;
235 addr = (pci_addr << 5) + 0x18 + LCA_CONF;
236 *value = conf_read(addr);
237 return PCIBIOS_SUCCESSFUL;
241 lca_write_config(struct pci_dev *dev, int where, u32 value, long mask)
243 unsigned long addr, pci_addr;
245 if (mk_conf_addr(dev, where, &pci_addr))
246 return PCIBIOS_DEVICE_NOT_FOUND;
248 addr = (pci_addr << 5) + mask + LCA_CONF;
249 conf_write(addr, value << ((where & 3) * 8));
250 return PCIBIOS_SUCCESSFUL;
254 lca_write_config_byte(struct pci_dev *dev, int where, u8 value)
256 return lca_write_config(dev, where, value, 0x00);
260 lca_write_config_word(struct pci_dev *dev, int where, u16 value)
262 return lca_write_config(dev, where, value, 0x08);
266 lca_write_config_dword(struct pci_dev *dev, int where, u32 value)
268 return lca_write_config(dev, where, value, 0x18);
271 struct pci_ops lca_pci_ops =
273 read_byte: lca_read_config_byte,
274 read_word: lca_read_config_word,
275 read_dword: lca_read_config_dword,
276 write_byte: lca_write_config_byte,
277 write_word: lca_write_config_word,
278 write_dword: lca_write_config_dword
282 lca_pci_tbi(struct pci_controller *hose, dma_addr_t start, dma_addr_t end)
285 *(vip)LCA_IOC_TBIA = 0;
292 struct pci_controller *hose;
295 * Create our single hose.
298 pci_isa_hose = hose = alloc_pci_controller();
299 hose->io_space = &ioport_resource;
300 hose->mem_space = &iomem_resource;
303 hose->sparse_mem_base = LCA_SPARSE_MEM - IDENT_ADDR;
304 hose->dense_mem_base = LCA_DENSE_MEM - IDENT_ADDR;
305 hose->sparse_io_base = LCA_IO - IDENT_ADDR;
306 hose->dense_io_base = 0;
309 * Set up the PCI to main memory translation windows.
311 * Window 0 is direct access 1GB at 1GB
312 * Window 1 is scatter-gather 8MB at 8MB (for isa)
314 hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000, 0);
316 __direct_map_base = 0x40000000;
317 __direct_map_size = 0x40000000;
319 *(vulp)LCA_IOC_W_BASE0 = __direct_map_base | (2UL << 32);
320 *(vulp)LCA_IOC_W_MASK0 = (__direct_map_size - 1) & 0xfff00000;
321 *(vulp)LCA_IOC_T_BASE0 = 0;
323 *(vulp)LCA_IOC_W_BASE1 = hose->sg_isa->dma_base | (3UL << 32);
324 *(vulp)LCA_IOC_W_MASK1 = (hose->sg_isa->size - 1) & 0xfff00000;
325 *(vulp)LCA_IOC_T_BASE1 = virt_to_phys(hose->sg_isa->ptes);
327 *(vulp)LCA_IOC_TB_ENA = 0x80;
329 lca_pci_tbi(hose, 0, -1);
332 * Disable PCI parity for now. The NCR53c810 chip has
333 * troubles meeting the PCI spec which results in
334 * data parity errors.
336 *(vulp)LCA_IOC_PAR_DIS = 1UL<<5;
340 * Constants used during machine-check handling. I suppose these
341 * could be moved into lca.h but I don't see much reason why anybody
342 * else would want to use them.
345 #define ESR_EAV (1UL<< 0) /* error address valid */
346 #define ESR_CEE (1UL<< 1) /* correctable error */
347 #define ESR_UEE (1UL<< 2) /* uncorrectable error */
348 #define ESR_WRE (1UL<< 3) /* write-error */
349 #define ESR_SOR (1UL<< 4) /* error source */
350 #define ESR_CTE (1UL<< 7) /* cache-tag error */
351 #define ESR_MSE (1UL<< 9) /* multiple soft errors */
352 #define ESR_MHE (1UL<<10) /* multiple hard errors */
353 #define ESR_NXM (1UL<<12) /* non-existent memory */
355 #define IOC_ERR ( 1<<4) /* ioc logs an error */
356 #define IOC_CMD_SHIFT 0
357 #define IOC_CMD (0xf<<IOC_CMD_SHIFT)
358 #define IOC_CODE_SHIFT 8
359 #define IOC_CODE (0xf<<IOC_CODE_SHIFT)
360 #define IOC_LOST ( 1<<5)
361 #define IOC_P_NBR ((__u32) ~((1<<13) - 1))
364 mem_error(unsigned long esr, unsigned long ear)
366 printk(" %s %s error to %s occurred at address %x\n",
367 ((esr & ESR_CEE) ? "Correctable" :
368 (esr & ESR_UEE) ? "Uncorrectable" : "A"),
369 (esr & ESR_WRE) ? "write" : "read",
370 (esr & ESR_SOR) ? "memory" : "b-cache",
371 (unsigned) (ear & 0x1ffffff8));
373 printk(" A b-cache tag parity error was detected.\n");
376 printk(" Several other correctable errors occurred.\n");
379 printk(" Several other uncorrectable errors occurred.\n");
382 printk(" Attempted to access non-existent memory.\n");
387 ioc_error(__u32 stat0, __u32 stat1)
389 static const char * const pci_cmd[] = {
390 "Interrupt Acknowledge", "Special", "I/O Read", "I/O Write",
391 "Rsvd 1", "Rsvd 2", "Memory Read", "Memory Write", "Rsvd3",
392 "Rsvd4", "Configuration Read", "Configuration Write",
393 "Memory Read Multiple", "Dual Address", "Memory Read Line",
394 "Memory Write and Invalidate"
396 static const char * const err_name[] = {
397 "exceeded retry limit", "no device", "bad data parity",
398 "target abort", "bad address parity", "page table read error",
399 "invalid page", "data error"
401 unsigned code = (stat0 & IOC_CODE) >> IOC_CODE_SHIFT;
402 unsigned cmd = (stat0 & IOC_CMD) >> IOC_CMD_SHIFT;
404 printk(" %s initiated PCI %s cycle to address %x"
405 " failed due to %s.\n",
406 code > 3 ? "PCI" : "CPU", pci_cmd[cmd], stat1, err_name[code]);
408 if (code == 5 || code == 6) {
409 printk(" (Error occurred at PCI memory address %x.)\n",
410 (stat0 & ~IOC_P_NBR));
412 if (stat0 & IOC_LOST) {
413 printk(" Other PCI errors occurred simultaneously.\n");
418 lca_machine_check(unsigned long vector, unsigned long la_ptr,
419 struct pt_regs *regs)
424 el.c = (struct el_common *) la_ptr;
426 wrmces(rdmces()); /* reset machine check pending flag */
428 printk(KERN_CRIT "LCA machine check: vector=%#lx pc=%#lx code=%#x\n",
429 vector, regs->pc, (unsigned int) el.c->code);
432 * The first quadword after the common header always seems to
433 * be the machine check reason---don't know why this isn't
434 * part of the common header instead. In the case of a long
435 * logout frame, the upper 32 bits is the machine check
436 * revision level, which we ignore for now.
438 switch ((unsigned int) el.c->code) {
439 case MCHK_K_TPERR: reason = "tag parity error"; break;
440 case MCHK_K_TCPERR: reason = "tag control parity error"; break;
441 case MCHK_K_HERR: reason = "access to non-existent memory"; break;
442 case MCHK_K_ECC_C: reason = "correctable ECC error"; break;
443 case MCHK_K_ECC_NC: reason = "non-correctable ECC error"; break;
444 case MCHK_K_CACKSOFT: reason = "MCHK_K_CACKSOFT"; break;
445 case MCHK_K_BUGCHECK: reason = "illegal exception in PAL mode"; break;
446 case MCHK_K_OS_BUGCHECK: reason = "callsys in kernel mode"; break;
447 case MCHK_K_DCPERR: reason = "d-cache parity error"; break;
448 case MCHK_K_ICPERR: reason = "i-cache parity error"; break;
449 case MCHK_K_SIO_SERR: reason = "SIO SERR occurred on PCI bus"; break;
450 case MCHK_K_SIO_IOCHK: reason = "SIO IOCHK occurred on ISA bus"; break;
451 case MCHK_K_DCSR: reason = "MCHK_K_DCSR"; break;
453 default: reason = "unknown"; break;
456 switch (el.c->size) {
457 case sizeof(struct el_lca_mcheck_short):
459 " Reason: %s (short frame%s, dc_stat=%#lx):\n",
460 reason, el.c->retry ? ", retryable" : "",
462 if (el.s->esr & ESR_EAV) {
463 mem_error(el.s->esr, el.s->ear);
465 if (el.s->ioc_stat0 & IOC_ERR) {
466 ioc_error(el.s->ioc_stat0, el.s->ioc_stat1);
470 case sizeof(struct el_lca_mcheck_long):
471 printk(KERN_CRIT " Reason: %s (long frame%s):\n",
472 reason, el.c->retry ? ", retryable" : "");
474 " reason: %#lx exc_addr: %#lx dc_stat: %#lx\n",
475 el.l->pt[0], el.l->exc_addr, el.l->dc_stat);
476 printk(KERN_CRIT " car: %#lx\n", el.l->car);
477 if (el.l->esr & ESR_EAV) {
478 mem_error(el.l->esr, el.l->ear);
480 if (el.l->ioc_stat0 & IOC_ERR) {
481 ioc_error(el.l->ioc_stat0, el.l->ioc_stat1);
486 printk(KERN_CRIT " Unknown errorlog size %d\n", el.c->size);
489 /* Dump the logout area to give all info. */
492 unsigned long * ptr = (unsigned long *) la_ptr;
494 for (i = 0; i < el.c->size / sizeof(long); i += 2) {
495 printk(KERN_CRIT " +%8lx %016lx %016lx\n",
496 i*sizeof(long), ptr[i], ptr[i+1]);
503 * The following routines are needed to support the SPEED changing
504 * necessary to successfully manage the thermal problem on the AlphaBook1.
508 lca_clock_print(void)
512 pmr_reg = LCA_READ_PMR;
514 printk("Status of clock control:\n");
515 printk("\tPrimary clock divisor\t0x%lx\n", LCA_GET_PRIMARY(pmr_reg));
516 printk("\tOverride clock divisor\t0x%lx\n", LCA_GET_OVERRIDE(pmr_reg));
517 printk("\tInterrupt override is %s\n",
518 (pmr_reg & LCA_PMR_INTO) ? "on" : "off");
519 printk("\tDMA override is %s\n",
520 (pmr_reg & LCA_PMR_DMAO) ? "on" : "off");
529 pmr_reg = LCA_READ_PMR;
530 return(LCA_GET_PRIMARY(pmr_reg));
535 lca_clock_fiddle(int divisor)
539 pmr_reg = LCA_READ_PMR;
540 LCA_SET_PRIMARY_CLOCK(pmr_reg, divisor);
541 /* lca_norm_clock = divisor; */
542 LCA_WRITE_PMR(pmr_reg);