import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / arch / alpha / kernel / sys_nautilus.c
1 /*
2  *      linux/arch/alpha/kernel/sys_nautilus.c
3  *
4  *      Copyright (C) 1995 David A Rusling
5  *      Copyright (C) 1998 Richard Henderson
6  *      Copyright (C) 1999 Alpha Processor, Inc.,
7  *              (David Daniel, Stig Telfer, Soohoon Lee)
8  *
9  * Code supporting NAUTILUS systems.
10  *
11  *
12  * NAUTILUS has the following I/O features:
13  *
14  * a) Driven by AMD 751 aka IRONGATE (northbridge):
15  *     4 PCI slots
16  *     1 AGP slot
17  *
18  * b) Driven by ALI M1543C (southbridge)
19  *     2 ISA slots
20  *     2 IDE connectors
21  *     1 dual drive capable FDD controller
22  *     2 serial ports
23  *     1 ECP/EPP/SP parallel port
24  *     2 USB ports
25  */
26
27 #include <linux/kernel.h>
28 #include <linux/types.h>
29 #include <linux/mm.h>
30 #include <linux/sched.h>
31 #include <linux/pci.h>
32 #include <linux/init.h>
33 #include <linux/reboot.h>
34 #include <linux/bootmem.h>
35
36 #include <asm/ptrace.h>
37 #include <asm/system.h>
38 #include <asm/dma.h>
39 #include <asm/irq.h>
40 #include <asm/bitops.h>
41 #include <asm/mmu_context.h>
42 #include <asm/io.h>
43 #include <asm/pci.h>
44 #include <asm/pgtable.h>
45 #include <asm/core_irongate.h>
46 #include <asm/hwrpb.h>
47
48 #include "proto.h"
49 #include "err_impl.h"
50 #include "irq_impl.h"
51 #include "pci_impl.h"
52 #include "machvec_impl.h"
53
54
55 static void __init
56 nautilus_init_irq(void)
57 {
58         if (alpha_using_srm) {
59                 alpha_mv.device_interrupt = srm_device_interrupt;
60         }
61
62         init_i8259a_irqs();
63         common_init_isa_dma();
64 }
65
66 static int __init
67 nautilus_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
68 {
69         /* Preserve the IRQ set up by the console.  */
70
71         u8 irq;
72         pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
73         return irq;
74 }
75
76 void
77 nautilus_kill_arch(int mode)
78 {
79         u32 pmuport;
80         int off;
81
82         switch (mode) {
83         case LINUX_REBOOT_CMD_RESTART:
84                 if (! alpha_using_srm) {
85                         u8 t8;
86                         pcibios_read_config_byte(0, 0x38, 0x43, &t8);
87                         pcibios_write_config_byte(0, 0x38, 0x43, t8 | 0x80);
88                         outb(1, 0x92);
89                         outb(0, 0x92);
90                         /* NOTREACHED */
91                 }
92                 break;
93
94         case LINUX_REBOOT_CMD_POWER_OFF:
95                 /* Assume M1543C */
96                 off = 0x2000;           /* SLP_TYPE = 0, SLP_EN = 1 */
97                 pcibios_read_config_dword(0, 0x88, 0x10, &pmuport);
98                 if (!pmuport) {
99                         /* M1535D/D+ */
100                         off = 0x3400;   /* SLP_TYPE = 5, SLP_EN = 1 */
101                         pcibios_read_config_dword(0, 0x88, 0xe0, &pmuport);
102                 }
103                 pmuport &= 0xfffe;
104                 outw(0xffff, pmuport);  /* Clear pending events. */
105                 outw(off, pmuport + 4);
106                 /* NOTREACHED */
107                 break;
108         }
109 }
110
111 /* Perform analysis of a machine check that arrived from the system (NMI) */
112
113 static void
114 naut_sys_machine_check(unsigned long vector, unsigned long la_ptr,
115                        struct pt_regs *regs)
116 {
117         printk("PC %lx RA %lx\n", regs->pc, regs->r26);
118         irongate_pci_clr_err();
119 }
120
121 /* Machine checks can come from two sources - those on the CPU and those
122    in the system.  They are analysed separately but all starts here.  */
123
124 void
125 nautilus_machine_check(unsigned long vector, unsigned long la_ptr,
126                        struct pt_regs *regs)
127 {
128         char *mchk_class;
129
130         /* Now for some analysis.  Machine checks fall into two classes --
131            those picked up by the system, and those picked up by the CPU.
132            Add to that the two levels of severity - correctable or not.  */
133
134         if (vector == SCB_Q_SYSMCHK
135             && ((IRONGATE0->dramms & 0x300) == 0x300)) {
136                 unsigned long nmi_ctl;
137
138                 /* Clear ALI NMI */
139                 nmi_ctl = inb(0x61);
140                 nmi_ctl |= 0x0c;
141                 outb(nmi_ctl, 0x61);
142                 nmi_ctl &= ~0x0c;
143                 outb(nmi_ctl, 0x61);
144
145                 /* Write again clears error bits.  */
146                 IRONGATE0->stat_cmd = IRONGATE0->stat_cmd & ~0x100;
147                 mb();
148                 IRONGATE0->stat_cmd;
149
150                 /* Write again clears error bits.  */
151                 IRONGATE0->dramms = IRONGATE0->dramms;
152                 mb();
153                 IRONGATE0->dramms;
154
155                 draina();
156                 wrmces(0x7);
157                 mb();
158                 return;
159         }
160
161         if (vector == SCB_Q_SYSERR)
162                 mchk_class = "Correctable";
163         else if (vector == SCB_Q_SYSMCHK)
164                 mchk_class = "Fatal";
165         else {
166                 ev6_machine_check(vector, la_ptr, regs);
167                 return;
168         }
169
170         printk(KERN_CRIT "NAUTILUS Machine check 0x%lx "
171                          "[%s System Machine Check (NMI)]\n",
172                vector, mchk_class);
173
174         naut_sys_machine_check(vector, la_ptr, regs);
175
176         /* Tell the PALcode to clear the machine check */
177         draina();
178         wrmces(0x7);
179         mb();
180 }
181
182
183 extern void free_reserved_mem(void *, void *);
184 extern void pbus_size_bridges(struct pci_bus *);
185 extern void pbus_assign_resources(struct pci_bus *);
186
187 static struct resource irongate_mem = {
188         .name   = "Irongate PCI MEM",
189         .flags  = IORESOURCE_MEM,
190 };
191
192 void __init
193 nautilus_init_pci(void)
194 {
195         struct pci_controller *hose = hose_head;
196         struct pci_bus *bus;
197         struct pci_dev *dev;
198         unsigned long bus_align, bus_size, pci_mem;
199         unsigned long memtop = max_low_pfn << PAGE_SHIFT;
200
201         /* Scan our single hose.  */
202         bus = pci_scan_bus(0, alpha_mv.pci_ops, hose);
203         hose->bus = bus;
204         hose->last_busno = bus->subordinate;
205
206         bus->self = pci_find_slot(0, 0);
207         bus->resource[1] = &irongate_mem;
208
209         pbus_size_bridges(bus);
210
211         /* IO port range. */
212         bus->resource[0]->start = 0;
213         bus->resource[0]->end = 0xffff;
214
215         /* Set up PCI memory range - limit is hardwired to 0xffffffff,
216            base must be at aligned to 16Mb. */
217         bus_align = bus->resource[1]->start;
218         bus_size = bus->resource[1]->end + 1 - bus_align;
219         if (bus_align < 0x1000000UL)
220                 bus_align = 0x1000000UL;
221
222         pci_mem = (0x100000000UL - bus_size) & -bus_align;
223
224         bus->resource[1]->start = pci_mem;
225         bus->resource[1]->end = 0xffffffffUL;
226         if (request_resource(&iomem_resource, bus->resource[1]) < 0)
227                 printk(KERN_ERR "Failed to request MEM on hose 0\n");
228
229         if (pci_mem < memtop)
230                 memtop = pci_mem;
231         if (memtop > alpha_mv.min_mem_address) {
232                 free_reserved_mem(__va(alpha_mv.min_mem_address),
233                                   __va(memtop));
234                 printk("nautilus_init_pci: %ldk freed\n",
235                         (memtop - alpha_mv.min_mem_address) >> 10);
236         }
237
238         if ((IRONGATE0->dev_vendor >> 16) > 0x7006)     /* Albacore? */
239                 IRONGATE0->pci_mem = pci_mem;
240
241         pbus_assign_resources(bus);
242
243         pci_for_each_dev(dev) {
244                 pdev_enable_device(dev);
245         }
246         pci_fixup_irqs(alpha_mv.pci_swizzle, alpha_mv.pci_map_irq);
247 }
248
249 /*
250  * The System Vectors
251  */
252
253 struct alpha_machine_vector nautilus_mv __initmv = {
254         vector_name:            "Nautilus",
255         DO_EV6_MMU,
256         DO_DEFAULT_RTC,
257         DO_IRONGATE_IO,
258         DO_IRONGATE_BUS,
259         machine_check:          nautilus_machine_check,
260         max_dma_address:        ALPHA_NAUTILUS_MAX_DMA_ADDRESS,
261         min_io_address:         DEFAULT_IO_BASE,
262         min_mem_address:        IRONGATE_DEFAULT_MEM_BASE,
263
264         nr_irqs:                16,
265         device_interrupt:       isa_device_interrupt,
266
267         init_arch:              irongate_init_arch,
268         init_irq:               nautilus_init_irq,
269         init_rtc:               common_init_rtc,
270         init_pci:               nautilus_init_pci,
271         kill_arch:              nautilus_kill_arch,
272         pci_map_irq:            nautilus_map_irq,
273         pci_swizzle:            common_swizzle,
274 };
275 ALIAS_MV(nautilus)