import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / arch / alpha / kernel / sys_ruffian.c
1 /*
2  *      linux/arch/alpha/kernel/sys_ruffian.c
3  *
4  *      Copyright (C) 1995 David A Rusling
5  *      Copyright (C) 1996 Jay A Estabrook
6  *      Copyright (C) 1998, 1999, 2000 Richard Henderson
7  *
8  * Code supporting the RUFFIAN.
9  */
10
11 #include <linux/kernel.h>
12 #include <linux/types.h>
13 #include <linux/mm.h>
14 #include <linux/sched.h>
15 #include <linux/pci.h>
16 #include <linux/ioport.h>
17 #include <linux/init.h>
18
19 #include <asm/ptrace.h>
20 #include <asm/system.h>
21 #include <asm/dma.h>
22 #include <asm/irq.h>
23 #include <asm/mmu_context.h>
24 #include <asm/io.h>
25 #include <asm/pgtable.h>
26 #include <asm/core_cia.h>
27
28 #include "proto.h"
29 #include "irq_impl.h"
30 #include "pci_impl.h"
31 #include "machvec_impl.h"
32
33
34 static void __init
35 ruffian_init_irq(void)
36 {
37         /* Invert 6&7 for i82371 */
38         *(vulp)PYXIS_INT_HILO  = 0x000000c0UL; mb();
39         *(vulp)PYXIS_INT_CNFG  = 0x00002064UL; mb();     /* all clear */
40
41         outb(0x11,0xA0);
42         outb(0x08,0xA1);
43         outb(0x02,0xA1);
44         outb(0x01,0xA1);
45         outb(0xFF,0xA1);
46         
47         outb(0x11,0x20);
48         outb(0x00,0x21);
49         outb(0x04,0x21);
50         outb(0x01,0x21);
51         outb(0xFF,0x21);
52         
53         /* Finish writing the 82C59A PIC Operation Control Words */
54         outb(0x20,0xA0);
55         outb(0x20,0x20);
56         
57         init_i8259a_irqs();
58
59         /* Not interested in the bogus interrupts (0,3,6),
60            NMI (1), HALT (2), flash (5), or 21142 (8).  */
61         init_pyxis_irqs(0x16f0000);
62
63         common_init_isa_dma();
64 }
65
66 static void __init
67 ruffian_init_rtc(void)
68 {
69         /* Ruffian does not have the RTC connected to the CPU timer
70            interrupt.  Instead, it uses the PIT connected to IRQ 0.  */
71
72         /* Setup interval timer.  */
73         outb(0x34, 0x43);               /* binary, mode 2, LSB/MSB, ch 0 */
74         outb(LATCH & 0xff, 0x40);       /* LSB */
75         outb(LATCH >> 8, 0x40);         /* MSB */
76
77         outb(0xb6, 0x43);               /* pit counter 2: speaker */
78         outb(0x31, 0x42);
79         outb(0x13, 0x42);
80
81         setup_irq(0, &timer_irqaction);
82 }
83
84 static void
85 ruffian_kill_arch (int mode)
86 {
87         cia_kill_arch(mode);
88 #if 0
89         /* This only causes re-entry to ARCSBIOS */
90         /* Perhaps this works for other PYXIS as well?  */
91         *(vuip) PYXIS_RESET = 0x0000dead;
92         mb();
93 #endif
94 }
95
96 /*
97  *  Interrupt routing:
98  *
99  *              Primary bus
100  *        IdSel         INTA    INTB    INTC    INTD
101  * 21052   13             -       -       -       -
102  * SIO     14            23       -       -       -
103  * 21143   15            44       -       -       -
104  * Slot 0  17            43      42      41      40
105  *
106  *              Secondary bus
107  *        IdSel         INTA    INTB    INTC    INTD
108  * Slot 0   8 (18)       19      18      17      16
109  * Slot 1   9 (19)       31      30      29      28
110  * Slot 2  10 (20)       27      26      25      24
111  * Slot 3  11 (21)       39      38      37      36
112  * Slot 4  12 (22)       35      34      33      32
113  * 53c875  13 (23)       20       -       -       -
114  *
115  */
116
117 static int __init
118 ruffian_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
119 {
120         static char irq_tab[11][5] __initdata = {
121               /*INT  INTA INTB INTC INTD */
122                 {-1,  -1,  -1,  -1,  -1},  /* IdSel 13,  21052       */
123                 {-1,  -1,  -1,  -1,  -1},  /* IdSel 14,  SIO         */
124                 {44,  44,  44,  44,  44},  /* IdSel 15,  21143       */
125                 {-1,  -1,  -1,  -1,  -1},  /* IdSel 16,  none        */
126                 {43,  43,  42,  41,  40},  /* IdSel 17,  64-bit slot */
127                 /* the next 6 are actually on PCI bus 1, across the bridge */
128                 {19,  19,  18,  17,  16},  /* IdSel  8,  slot 0      */
129                 {31,  31,  30,  29,  28},  /* IdSel  9,  slot 1      */
130                 {27,  27,  26,  25,  24},  /* IdSel 10,  slot 2      */
131                 {39,  39,  38,  37,  36},  /* IdSel 11,  slot 3      */
132                 {35,  35,  34,  33,  32},  /* IdSel 12,  slot 4      */
133                 {20,  20,  20,  20,  20},  /* IdSel 13,  53c875      */
134         };
135         const long min_idsel = 13, max_idsel = 23, irqs_per_slot = 5;
136         return COMMON_TABLE_LOOKUP;
137 }
138
139 static u8 __init
140 ruffian_swizzle(struct pci_dev *dev, u8 *pinp)
141 {
142         int slot, pin = *pinp;
143
144         if (dev->bus->number == 0) {
145                 slot = PCI_SLOT(dev->devfn);
146         }               
147         /* Check for the built-in bridge.  */
148         else if (PCI_SLOT(dev->bus->self->devfn) == 13) {
149                 slot = PCI_SLOT(dev->devfn) + 10;
150         }
151         else 
152         {
153                 /* Must be a card-based bridge.  */
154                 do {
155                         if (PCI_SLOT(dev->bus->self->devfn) == 13) {
156                                 slot = PCI_SLOT(dev->devfn) + 10;
157                                 break;
158                         }
159                         pin = bridge_swizzle(pin, PCI_SLOT(dev->devfn));
160
161                         /* Move up the chain of bridges.  */
162                         dev = dev->bus->self;
163                         /* Slot of the next bridge.  */
164                         slot = PCI_SLOT(dev->devfn);
165                 } while (dev->bus->self);
166         }
167         *pinp = pin;
168         return slot;
169 }
170
171 #ifdef BUILDING_FOR_MILO
172 /*
173  * The DeskStation Ruffian motherboard firmware does not place
174  * the memory size in the PALimpure area.  Therefore, we use
175  * the Bank Configuration Registers in PYXIS to obtain the size.
176  */
177 static unsigned long __init
178 ruffian_get_bank_size(unsigned long offset)
179 {
180         unsigned long bank_addr, bank, ret = 0;
181   
182         /* Valid offsets are: 0x800, 0x840 and 0x880
183            since Ruffian only uses three banks.  */
184         bank_addr = (unsigned long)PYXIS_MCR + offset;
185         bank = *(vulp)bank_addr;
186     
187         /* Check BANK_ENABLE */
188         if (bank & 0x01) {
189                 static unsigned long size[] __initdata = {
190                         0x40000000UL, /* 0x00,   1G */ 
191                         0x20000000UL, /* 0x02, 512M */
192                         0x10000000UL, /* 0x04, 256M */
193                         0x08000000UL, /* 0x06, 128M */
194                         0x04000000UL, /* 0x08,  64M */
195                         0x02000000UL, /* 0x0a,  32M */
196                         0x01000000UL, /* 0x0c,  16M */
197                         0x00800000UL, /* 0x0e,   8M */
198                         0x80000000UL, /* 0x10,   2G */
199                 };
200
201                 bank = (bank & 0x1e) >> 1;
202                 if (bank < sizeof(size)/sizeof(*size))
203                         ret = size[bank];
204         }
205
206         return ret;
207 }
208 #endif /* BUILDING_FOR_MILO */
209
210 /*
211  * The System Vector
212  */
213
214 struct alpha_machine_vector ruffian_mv __initmv = {
215         vector_name:            "Ruffian",
216         DO_EV5_MMU,
217         DO_DEFAULT_RTC,
218         DO_PYXIS_IO,
219         DO_CIA_BUS,
220         machine_check:          cia_machine_check,
221         max_dma_address:        ALPHA_RUFFIAN_MAX_DMA_ADDRESS,
222         min_io_address:         DEFAULT_IO_BASE,
223         min_mem_address:        DEFAULT_MEM_BASE,
224         pci_dac_offset:         PYXIS_DAC_OFFSET,
225
226         nr_irqs:                48,
227         device_interrupt:       pyxis_device_interrupt,
228
229         init_arch:              pyxis_init_arch,
230         init_irq:               ruffian_init_irq,
231         init_rtc:               ruffian_init_rtc,
232         init_pci:               cia_init_pci,
233         kill_arch:              ruffian_kill_arch,
234         pci_map_irq:            ruffian_map_irq,
235         pci_swizzle:            ruffian_swizzle,
236 };
237 ALIAS_MV(ruffian)