yeeloong_machdep.c revision 1.2 1 1.1 bouyer /* $OpenBSD: yeeloong_machdep.c,v 1.16 2011/04/15 20:40:06 deraadt Exp $ */
2 1.1 bouyer
3 1.1 bouyer /*
4 1.1 bouyer * Copyright (c) 2009, 2010 Miodrag Vallat.
5 1.1 bouyer *
6 1.1 bouyer * Permission to use, copy, modify, and distribute this software for any
7 1.1 bouyer * purpose with or without fee is hereby granted, provided that the above
8 1.1 bouyer * copyright notice and this permission notice appear in all copies.
9 1.1 bouyer *
10 1.1 bouyer * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 1.1 bouyer * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 1.1 bouyer * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 1.1 bouyer * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 1.1 bouyer * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 1.1 bouyer * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 1.1 bouyer * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 1.1 bouyer */
18 1.1 bouyer
19 1.1 bouyer /*
20 1.1 bouyer * Lemote {Fu,Lyn,Yee}loong specific code and configuration data.
21 1.1 bouyer * (this file really ought to be named lemote_machdep.c by now)
22 1.1 bouyer */
23 1.1 bouyer
24 1.1 bouyer #include <sys/param.h>
25 1.1 bouyer #include <sys/systm.h>
26 1.1 bouyer #include <sys/device.h>
27 1.1 bouyer #include <sys/types.h>
28 1.1 bouyer
29 1.1 bouyer #include <evbmips/loongson/autoconf.h>
30 1.1 bouyer #include <mips/pmon/pmon.h>
31 1.1 bouyer #include <evbmips/loongson/loongson_intr.h>
32 1.1 bouyer #include <evbmips/loongson/loongson_bus_defs.h>
33 1.1 bouyer #include <evbmips/loongson/loongson_isa.h>
34 1.1 bouyer
35 1.1 bouyer #include <dev/isa/isareg.h>
36 1.1 bouyer #include <dev/isa/isavar.h>
37 1.1 bouyer #include <dev/ic/i8259reg.h>
38 1.1 bouyer
39 1.1 bouyer #include <dev/pci/pcireg.h>
40 1.1 bouyer #include <dev/pci/pcivar.h>
41 1.1 bouyer #include <dev/pci/pcidevs.h>
42 1.1 bouyer
43 1.1 bouyer #include <mips/bonito/bonitoreg.h>
44 1.1 bouyer #include <mips/bonito/bonitovar.h>
45 1.1 bouyer
46 1.1 bouyer #include <evbmips/loongson/dev/kb3310var.h>
47 1.1 bouyer #include <evbmips/loongson/dev/glxreg.h>
48 1.1 bouyer #include <evbmips/loongson/dev/glxvar.h>
49 1.1 bouyer
50 1.1 bouyer #include "com.h"
51 1.1 bouyer #include "isa.h"
52 1.1 bouyer #include "ykbec.h"
53 1.1 bouyer
54 1.1 bouyer #if NCOM > 0
55 1.1 bouyer #include <sys/termios.h>
56 1.1 bouyer #include <dev/ic/comvar.h>
57 1.1 bouyer #endif
58 1.1 bouyer
59 1.1 bouyer #ifdef LOW_DEBUG
60 1.1 bouyer #define DPRINTF(x) printf x
61 1.1 bouyer #else
62 1.1 bouyer #define DPRINTF(x)
63 1.1 bouyer #endif
64 1.1 bouyer
65 1.1 bouyer void lemote_device_register(struct device *, void *);
66 1.1 bouyer void lemote_reset(void);
67 1.1 bouyer
68 1.1 bouyer void fuloong_powerdown(void);
69 1.1 bouyer void fuloong_setup(void);
70 1.1 bouyer
71 1.1 bouyer void yeeloong_powerdown(void);
72 1.1 bouyer
73 1.1 bouyer void lemote_pci_attach_hook(device_t, device_t,
74 1.1 bouyer struct pcibus_attach_args *);
75 1.1 bouyer int lemote_intr_map(int, int, int, pci_intr_handle_t *);
76 1.1 bouyer
77 1.1 bouyer void lemote_isa_attach_hook(struct device *, struct device *,
78 1.1 bouyer struct isabus_attach_args *);
79 1.1 bouyer void *lemote_isa_intr_establish(void *, int, int, int,
80 1.1 bouyer int (*)(void *), void *);
81 1.1 bouyer void lemote_isa_intr_disestablish(void *, void *);
82 1.1 bouyer const struct evcnt * lemote_isa_intr_evcnt(void *, int);
83 1.1 bouyer const char * lemote_isa_intr_string(void *, int);
84 1.1 bouyer
85 1.1 bouyer uint lemote_get_isa_imr(void);
86 1.1 bouyer uint lemote_get_isa_isr(void);
87 1.1 bouyer void lemote_isa_intr(int, vaddr_t, uint32_t);
88 1.1 bouyer
89 1.1 bouyer const struct bonito_config lemote_bonito = {
90 1.1 bouyer .bc_adbase = 11,
91 1.1 bouyer
92 1.1 bouyer .bc_gpioIE = LOONGSON_INTRMASK_GPIO,
93 1.1 bouyer .bc_intEdge = LOONGSON_INTRMASK_PCI_SYSERR |
94 1.1 bouyer LOONGSON_INTRMASK_PCI_PARERR,
95 1.1 bouyer .bc_intSteer = 0,
96 1.1 bouyer .bc_intPol = LOONGSON_INTRMASK_DRAM_PARERR |
97 1.1 bouyer LOONGSON_INTRMASK_PCI_SYSERR | LOONGSON_INTRMASK_PCI_PARERR |
98 1.1 bouyer LOONGSON_INTRMASK_INT0 | LOONGSON_INTRMASK_INT1,
99 1.1 bouyer
100 1.1 bouyer .bc_attach_hook = lemote_pci_attach_hook,
101 1.1 bouyer };
102 1.1 bouyer
103 1.1 bouyer const struct legacy_io_range fuloong_legacy_ranges[] = {
104 1.1 bouyer /* isa */
105 1.1 bouyer { IO_DMAPG + 4, IO_DMAPG + 4 },
106 1.1 bouyer /* mcclock */
107 1.1 bouyer { IO_RTC, IO_RTC + 1 },
108 1.1 bouyer /* pciide */
109 1.1 bouyer { 0x170, 0x170 + 7 },
110 1.1 bouyer { 0x1f0, 0x1f0 + 7 },
111 1.1 bouyer { 0x376, 0x376 },
112 1.1 bouyer { 0x3f6, 0x3f6 },
113 1.1 bouyer /* com */
114 1.1 bouyer { IO_COM1, IO_COM1 + 8 }, /* IR port */
115 1.1 bouyer { IO_COM2, IO_COM2 + 8 }, /* serial port */
116 1.1 bouyer
117 1.1 bouyer { 0 }
118 1.1 bouyer };
119 1.1 bouyer
120 1.1 bouyer const struct legacy_io_range lynloong_legacy_ranges[] = {
121 1.1 bouyer /* isa */
122 1.1 bouyer { IO_DMAPG + 4, IO_DMAPG + 4 },
123 1.1 bouyer /* mcclock */
124 1.1 bouyer { IO_RTC, IO_RTC + 1 },
125 1.1 bouyer /* pciide */
126 1.1 bouyer { 0x170, 0x170 + 7 },
127 1.1 bouyer { 0x1f0, 0x1f0 + 7 },
128 1.1 bouyer { 0x376, 0x376 },
129 1.1 bouyer { 0x3f6, 0x3f6 },
130 1.1 bouyer #if 0 /* no external connector */
131 1.1 bouyer /* com */
132 1.1 bouyer { IO_COM2, IO_COM2 + 8 },
133 1.1 bouyer #endif
134 1.1 bouyer
135 1.1 bouyer { 0 }
136 1.1 bouyer };
137 1.1 bouyer
138 1.1 bouyer const struct legacy_io_range yeeloong_legacy_ranges[] = {
139 1.1 bouyer /* isa */
140 1.1 bouyer { IO_DMAPG + 4, IO_DMAPG + 4 },
141 1.1 bouyer /* pckbc */
142 1.1 bouyer { IO_KBD, IO_KBD },
143 1.1 bouyer { IO_KBD + 4, IO_KBD + 4 },
144 1.1 bouyer /* mcclock */
145 1.1 bouyer { IO_RTC, IO_RTC + 1 },
146 1.1 bouyer /* pciide */
147 1.1 bouyer { 0x170, 0x170 + 7 },
148 1.1 bouyer { 0x1f0, 0x1f0 + 7 },
149 1.1 bouyer { 0x376, 0x376 },
150 1.1 bouyer { 0x3f6, 0x3f6 },
151 1.1 bouyer /* kb3110b embedded controller */
152 1.1 bouyer { 0x381, 0x383 },
153 1.1 bouyer
154 1.1 bouyer { 0 }
155 1.1 bouyer };
156 1.1 bouyer
157 1.1 bouyer struct mips_isa_chipset lemote_isa_chipset = {
158 1.1 bouyer .ic_v = NULL,
159 1.1 bouyer
160 1.1 bouyer .ic_attach_hook = lemote_isa_attach_hook,
161 1.1 bouyer .ic_intr_establish = lemote_isa_intr_establish,
162 1.1 bouyer .ic_intr_disestablish = lemote_isa_intr_disestablish,
163 1.1 bouyer .ic_intr_evcnt = lemote_isa_intr_evcnt,
164 1.1 bouyer .ic_intr_string = lemote_isa_intr_string,
165 1.1 bouyer };
166 1.1 bouyer
167 1.1 bouyer const struct platform fuloong_platform = {
168 1.1 bouyer .system_type = LOONGSON_FULOONG,
169 1.1 bouyer .vendor = "Lemote",
170 1.1 bouyer .product = "Fuloong",
171 1.1 bouyer
172 1.1 bouyer .bonito_config = &lemote_bonito,
173 1.1 bouyer .isa_chipset = &lemote_isa_chipset,
174 1.1 bouyer .legacy_io_ranges = fuloong_legacy_ranges,
175 1.1 bouyer .bonito_mips_intr = MIPS_INT_MASK_4,
176 1.1 bouyer .isa_mips_intr = MIPS_INT_MASK_0,
177 1.1 bouyer .isa_intr = lemote_isa_intr,
178 1.1 bouyer .p_pci_intr_map = lemote_intr_map,
179 1.1 bouyer .irq_map =loongson2f_irqmap,
180 1.1 bouyer
181 1.1 bouyer .setup = fuloong_setup,
182 1.1 bouyer .device_register = lemote_device_register,
183 1.1 bouyer
184 1.1 bouyer .powerdown = fuloong_powerdown,
185 1.1 bouyer .reset = lemote_reset
186 1.1 bouyer };
187 1.1 bouyer
188 1.1 bouyer const struct platform lynloong_platform = {
189 1.1 bouyer .system_type = LOONGSON_LYNLOONG,
190 1.1 bouyer .vendor = "Lemote",
191 1.1 bouyer .product = "Lynloong",
192 1.1 bouyer
193 1.1 bouyer .bonito_config = &lemote_bonito,
194 1.1 bouyer .isa_chipset = &lemote_isa_chipset,
195 1.1 bouyer .legacy_io_ranges = lynloong_legacy_ranges,
196 1.1 bouyer .bonito_mips_intr = MIPS_INT_MASK_4,
197 1.1 bouyer .isa_mips_intr = MIPS_INT_MASK_0,
198 1.1 bouyer .isa_intr = lemote_isa_intr,
199 1.1 bouyer .p_pci_intr_map = lemote_intr_map,
200 1.1 bouyer .irq_map =loongson2f_irqmap,
201 1.1 bouyer
202 1.1 bouyer .setup = fuloong_setup,
203 1.1 bouyer .device_register = lemote_device_register,
204 1.1 bouyer
205 1.1 bouyer .powerdown = fuloong_powerdown,
206 1.1 bouyer .reset = lemote_reset
207 1.1 bouyer };
208 1.1 bouyer
209 1.1 bouyer const struct platform yeeloong_platform = {
210 1.1 bouyer .system_type = LOONGSON_YEELOONG,
211 1.1 bouyer .vendor = "Lemote",
212 1.1 bouyer .product = "Yeeloong",
213 1.1 bouyer
214 1.1 bouyer .bonito_config = &lemote_bonito,
215 1.1 bouyer .isa_chipset = &lemote_isa_chipset,
216 1.1 bouyer .legacy_io_ranges = yeeloong_legacy_ranges,
217 1.1 bouyer .bonito_mips_intr = MIPS_INT_MASK_4,
218 1.1 bouyer .isa_mips_intr = MIPS_INT_MASK_0,
219 1.1 bouyer .isa_intr = lemote_isa_intr,
220 1.1 bouyer .p_pci_intr_map = lemote_intr_map,
221 1.1 bouyer .irq_map =loongson2f_irqmap,
222 1.1 bouyer
223 1.1 bouyer .setup = NULL,
224 1.1 bouyer .device_register = lemote_device_register,
225 1.1 bouyer
226 1.1 bouyer .powerdown = yeeloong_powerdown,
227 1.1 bouyer .reset = lemote_reset,
228 1.1 bouyer #if NYKBEC > 0
229 1.1 bouyer .suspend = ykbec_suspend,
230 1.1 bouyer .resume = ykbec_resume
231 1.1 bouyer #endif
232 1.1 bouyer };
233 1.1 bouyer
234 1.1 bouyer static int stray_intr[BONITO_NISA];
235 1.1 bouyer
236 1.1 bouyer /*
237 1.1 bouyer * PCI model specific routines
238 1.1 bouyer */
239 1.1 bouyer
240 1.1 bouyer void
241 1.1 bouyer lemote_pci_attach_hook(device_t parent, device_t self,
242 1.1 bouyer struct pcibus_attach_args *pba)
243 1.1 bouyer {
244 1.1 bouyer pci_chipset_tag_t pc = pba->pba_pc;
245 1.1 bouyer pcireg_t id;
246 1.1 bouyer pcitag_t tag;
247 1.1 bouyer int dev, i;
248 1.1 bouyer
249 1.1 bouyer if (pba->pba_bus != 0)
250 1.1 bouyer return;
251 1.1 bouyer
252 1.1 bouyer /*
253 1.1 bouyer * Check for an AMD CS5536 chip; if one is found, register
254 1.1 bouyer * the proper PCI configuration space hooks.
255 1.1 bouyer */
256 1.1 bouyer
257 1.1 bouyer for (dev = pci_bus_maxdevs(pc, 0); dev >= 0; dev--) {
258 1.1 bouyer tag = pci_make_tag(pc, 0, dev, 0);
259 1.1 bouyer id = pci_conf_read(pc, tag, PCI_ID_REG);
260 1.1 bouyer DPRINTF(("lemote_pci_attach_hook id 0x%x\n", id));
261 1.1 bouyer if (id == PCI_ID_CODE(PCI_VENDOR_AMD,
262 1.1 bouyer PCI_PRODUCT_AMD_CS5536_PCISB)) {
263 1.1 bouyer glx_init(pc, tag, dev);
264 1.1 bouyer break;
265 1.1 bouyer }
266 1.1 bouyer }
267 1.1 bouyer wrmsr(GCSC_PIC_SHDW, 0);
268 1.1 bouyer DPRINTF(("PMON setup picregs:"));
269 1.1 bouyer for (i = 0; i < 12; i++) {
270 1.1 bouyer if (i == 6)
271 1.1 bouyer DPRINTF((" | "));
272 1.1 bouyer DPRINTF((" 0x%x", (uint32_t)(rdmsr(GCSC_PIC_SHDW) & 0xff)));
273 1.1 bouyer }
274 1.1 bouyer DPRINTF(("\n"));
275 1.1 bouyer DPRINTF(("intsel 0x%x 0x%x\n", REGVAL8(BONITO_PCIIO_BASE + 0x4d0),
276 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + 0x4d1)));
277 1.1 bouyer /* setup legacy interrupt controller */
278 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + IO_ICU1 + PIC_OCW1) = 0xff;
279 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + IO_ICU1 + PIC_ICW1) =
280 1.1 bouyer ICW1_SELECT | ICW1_IC4;
281 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + IO_ICU1 + PIC_ICW2) = ICW2_VECTOR(0);
282 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + IO_ICU1 + PIC_ICW3) = ICW3_CASCADE(2);
283 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + IO_ICU1 + PIC_ICW4) = ICW4_8086;
284 1.1 bouyer delay(100);
285 1.1 bouyer /* mask all interrupts */
286 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + IO_ICU1 + PIC_OCW1) = 0xff;
287 1.1 bouyer
288 1.1 bouyer /* read ISR by default. */
289 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + IO_ICU1 + PIC_OCW3) =
290 1.1 bouyer OCW3_SELECT | OCW3_RR;
291 1.1 bouyer (void)REGVAL8(BONITO_PCIIO_BASE + IO_ICU1 + PIC_OCW3);
292 1.1 bouyer
293 1.1 bouyer /* reset; program device, four bytes */
294 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + IO_ICU2 + PIC_OCW1) = 0xff;
295 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + IO_ICU2 + PIC_ICW1) =
296 1.1 bouyer ICW1_SELECT | ICW1_IC4;
297 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + IO_ICU2 + PIC_ICW2) = ICW2_VECTOR(8);
298 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + IO_ICU2 + PIC_ICW3) = ICW3_SIC(2);
299 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + IO_ICU2 + PIC_ICW4) = ICW4_8086;
300 1.1 bouyer delay(100);
301 1.1 bouyer /* leave interrupts masked */
302 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + IO_ICU2 + PIC_OCW1) = 0xff;
303 1.1 bouyer /* read ISR by default. */
304 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + IO_ICU2 + PIC_OCW3) =
305 1.1 bouyer OCW3_SELECT | OCW3_RR;
306 1.1 bouyer (void)REGVAL8(BONITO_PCIIO_BASE + IO_ICU2 + PIC_OCW3);
307 1.1 bouyer }
308 1.1 bouyer
309 1.1 bouyer int
310 1.1 bouyer lemote_intr_map(int dev, int fn, int pin, pci_intr_handle_t *ihp)
311 1.1 bouyer {
312 1.1 bouyer switch (dev) {
313 1.1 bouyer /* onboard devices, only pin A is wired */
314 1.1 bouyer case 6:
315 1.1 bouyer case 7:
316 1.1 bouyer case 8:
317 1.1 bouyer case 9:
318 1.1 bouyer if (pin == PCI_INTERRUPT_PIN_A) {
319 1.1 bouyer *ihp = BONITO_DIRECT_IRQ(LOONGSON_INTR_PCIA +
320 1.1 bouyer (dev - 6));
321 1.1 bouyer return 0;
322 1.1 bouyer }
323 1.1 bouyer break;
324 1.1 bouyer /* PCI slot */
325 1.1 bouyer case 10:
326 1.1 bouyer *ihp = BONITO_DIRECT_IRQ(LOONGSON_INTR_PCIA +
327 1.1 bouyer (pin - PCI_INTERRUPT_PIN_A));
328 1.1 bouyer return 0;
329 1.1 bouyer /* Geode chip */
330 1.1 bouyer case 14:
331 1.1 bouyer switch (fn) {
332 1.1 bouyer case 1: /* Flash */
333 1.1 bouyer *ihp = BONITO_ISA_IRQ(6);
334 1.1 bouyer return 0;
335 1.1 bouyer case 3: /* AC97 */
336 1.1 bouyer *ihp = BONITO_ISA_IRQ(9);
337 1.1 bouyer return 0;
338 1.1 bouyer case 4: /* OHCI */
339 1.1 bouyer case 5: /* EHCI */
340 1.1 bouyer *ihp = BONITO_ISA_IRQ(11);
341 1.1 bouyer return 0;
342 1.1 bouyer }
343 1.1 bouyer break;
344 1.1 bouyer default:
345 1.1 bouyer break;
346 1.1 bouyer }
347 1.1 bouyer
348 1.1 bouyer return 1;
349 1.1 bouyer }
350 1.1 bouyer
351 1.1 bouyer /*
352 1.1 bouyer * ISA model specific routines
353 1.1 bouyer */
354 1.1 bouyer
355 1.1 bouyer void
356 1.1 bouyer lemote_isa_attach_hook(struct device *parent, struct device *self,
357 1.1 bouyer struct isabus_attach_args *iba)
358 1.1 bouyer {
359 1.1 bouyer loongson_set_isa_imr(loongson_isaimr);
360 1.1 bouyer }
361 1.1 bouyer
362 1.1 bouyer void *
363 1.1 bouyer lemote_isa_intr_establish(void *v, int irq, int type, int level,
364 1.1 bouyer int (*handler)(void *), void *arg)
365 1.1 bouyer {
366 1.1 bouyer void *ih;
367 1.1 bouyer uint imr;
368 1.1 bouyer
369 1.1 bouyer ih = evbmips_intr_establish(BONITO_ISA_IRQ(irq), handler, arg);
370 1.1 bouyer if (ih == NULL)
371 1.1 bouyer return NULL;
372 1.1 bouyer /* enable interrupt */
373 1.1 bouyer imr = lemote_get_isa_imr();
374 1.1 bouyer imr |= (1 << irq);
375 1.1 bouyer DPRINTF(("lemote_isa_intr_establish: enable irq %d 0x%x\n",
376 1.1 bouyer irq, imr));
377 1.1 bouyer loongson_set_isa_imr(imr);
378 1.1 bouyer return ih;
379 1.1 bouyer }
380 1.1 bouyer
381 1.1 bouyer void
382 1.1 bouyer lemote_isa_intr_disestablish(void *v, void *ih)
383 1.1 bouyer {
384 1.1 bouyer evbmips_intr_disestablish(ih);
385 1.1 bouyer }
386 1.1 bouyer
387 1.1 bouyer const struct evcnt *
388 1.1 bouyer lemote_isa_intr_evcnt(void *v, int irq)
389 1.1 bouyer {
390 1.1 bouyer
391 1.1 bouyer if (irq == 0 || irq >= BONITO_NISA || irq == 2)
392 1.1 bouyer panic("lemote_isa_intr_evcnt: bogus isa irq 0x%x", irq);
393 1.1 bouyer
394 1.1 bouyer return (&bonito_intrhead[BONITO_ISA_IRQ(irq)].intr_count);
395 1.1 bouyer }
396 1.1 bouyer
397 1.1 bouyer const char *
398 1.1 bouyer lemote_isa_intr_string(void *v, int irq)
399 1.1 bouyer {
400 1.1 bouyer if (irq == 0 || irq >= BONITO_NISA || irq == 2)
401 1.1 bouyer panic("lemote_isa_intr_string: bogus isa irq 0x%x", irq);
402 1.1 bouyer
403 1.1 bouyer return loongson_intr_string(&lemote_bonito, BONITO_ISA_IRQ(irq));
404 1.1 bouyer }
405 1.1 bouyer
406 1.1 bouyer /*
407 1.1 bouyer * Legacy (ISA) interrupt handling
408 1.1 bouyer */
409 1.1 bouyer
410 1.1 bouyer /*
411 1.1 bouyer * Process legacy interrupts.
412 1.1 bouyer *
413 1.1 bouyer * XXX On 2F, ISA interrupts only occur on LOONGSON_INTR_INT0, but since
414 1.1 bouyer * XXX the other LOONGSON_INTR_INT# are unmaskable, bad things will happen
415 1.1 bouyer * XXX if they ever are triggered...
416 1.1 bouyer */
417 1.1 bouyer void
418 1.1 bouyer lemote_isa_intr(int ipl, vaddr_t pc, uint32_t ipending)
419 1.1 bouyer {
420 1.1 bouyer #if NISA > 0
421 1.1 bouyer uint32_t isr, imr, mask;
422 1.1 bouyer int bit;
423 1.1 bouyer struct evbmips_intrhand *ih;
424 1.1 bouyer int rc;
425 1.1 bouyer //int i;
426 1.1 bouyer
427 1.1 bouyer imr = lemote_get_isa_imr();
428 1.1 bouyer isr = lemote_get_isa_isr() & imr;
429 1.1 bouyer
430 1.1 bouyer /*
431 1.1 bouyer * Now process allowed interrupts.
432 1.1 bouyer */
433 1.1 bouyer if (isr != 0) {
434 1.1 bouyer int bitno, ret;
435 1.1 bouyer
436 1.1 bouyer /* Service higher level interrupts first */
437 1.1 bouyer bit = BONITO_NISA - 1;
438 1.1 bouyer for (bitno = bit, mask = 1UL << bitno;
439 1.1 bouyer mask != 0;
440 1.1 bouyer bitno--, mask >>= 1) {
441 1.1 bouyer if ((isr & mask) == 0)
442 1.1 bouyer continue;
443 1.1 bouyer loongson_isa_specific_eoi(bitno);
444 1.1 bouyer rc = 0;
445 1.1 bouyer LIST_FOREACH(ih,
446 1.1 bouyer &bonito_intrhead[BONITO_ISA_IRQ(bitno)].intrhand_head,
447 1.1 bouyer ih_q) {
448 1.1 bouyer ret = (*ih->ih_func)(ih->ih_arg);
449 1.1 bouyer if (ret) {
450 1.1 bouyer rc = 1;
451 1.1 bouyer bonito_intrhead[BONITO_ISA_IRQ(bitno)].intr_count.ev_count++;
452 1.1 bouyer }
453 1.1 bouyer }
454 1.1 bouyer if (rc == 0) {
455 1.1 bouyer if (stray_intr[bitno]++ & 0x10000) {
456 1.1 bouyer printf("spurious isa interrupt %d\n",
457 1.1 bouyer bitno);
458 1.1 bouyer stray_intr[bitno] = 0;
459 1.1 bouyer }
460 1.1 bouyer }
461 1.1 bouyer
462 1.1 bouyer if ((isr ^= mask) == 0)
463 1.1 bouyer break;
464 1.1 bouyer }
465 1.1 bouyer
466 1.1 bouyer /*
467 1.1 bouyer * Reenable interrupts which have been serviced.
468 1.1 bouyer */
469 1.1 bouyer loongson_set_isa_imr(imr);
470 1.1 bouyer }
471 1.1 bouyer
472 1.1 bouyer #endif
473 1.1 bouyer return;
474 1.1 bouyer }
475 1.1 bouyer
476 1.1 bouyer uint
477 1.2 christos lemote_get_isa_imr(void)
478 1.1 bouyer {
479 1.1 bouyer uint imr1, imr2;
480 1.1 bouyer
481 1.1 bouyer imr1 = 0xff & ~REGVAL8(BONITO_PCIIO_BASE + IO_ICU1 + 1);
482 1.1 bouyer imr1 &= ~(1 << 2); /* hide cascade */
483 1.1 bouyer imr2 = 0xff & ~REGVAL8(BONITO_PCIIO_BASE + IO_ICU2 + 1);
484 1.1 bouyer
485 1.1 bouyer return (imr2 << 8) | imr1;
486 1.1 bouyer }
487 1.1 bouyer
488 1.1 bouyer uint
489 1.2 christos lemote_get_isa_isr(void)
490 1.1 bouyer {
491 1.1 bouyer uint isr1, isr2 = 0;
492 1.1 bouyer
493 1.1 bouyer isr1 = REGVAL8(BONITO_PCIIO_BASE + IO_ICU1);
494 1.1 bouyer isr1 &= ~(1<<2);
495 1.1 bouyer isr2 = REGVAL8(BONITO_PCIIO_BASE + IO_ICU2);
496 1.1 bouyer
497 1.1 bouyer return (isr1 | (isr2 << 8));
498 1.1 bouyer }
499 1.1 bouyer
500 1.1 bouyer /*
501 1.1 bouyer * Other model specific routines
502 1.1 bouyer */
503 1.1 bouyer
504 1.1 bouyer void
505 1.2 christos fuloong_powerdown(void)
506 1.1 bouyer {
507 1.1 bouyer vaddr_t gpiobase;
508 1.1 bouyer
509 1.1 bouyer gpiobase = BONITO_PCIIO_BASE + (rdmsr(GCSC_DIVIL_LBAR_GPIO) & 0xff00);
510 1.1 bouyer /* enable GPIO 13 */
511 1.1 bouyer REGVAL(gpiobase + GCSC_GPIOL_OUT_EN) = GCSC_GPIO_ATOMIC_VALUE(13, 1);
512 1.1 bouyer /* set GPIO13 value to zero */
513 1.1 bouyer REGVAL(gpiobase + GCSC_GPIOL_OUT_VAL) = GCSC_GPIO_ATOMIC_VALUE(13, 0);
514 1.1 bouyer }
515 1.1 bouyer
516 1.1 bouyer void
517 1.2 christos yeeloong_powerdown(void)
518 1.1 bouyer {
519 1.1 bouyer REGVAL(BONITO_GPIODATA) &= ~0x00000001;
520 1.1 bouyer REGVAL(BONITO_GPIOIE) &= ~0x00000001;
521 1.1 bouyer }
522 1.1 bouyer
523 1.1 bouyer void
524 1.2 christos lemote_reset(void)
525 1.1 bouyer {
526 1.1 bouyer wrmsr(GCSC_GLCP_SYS_RST, rdmsr(GCSC_GLCP_SYS_RST) | 1);
527 1.1 bouyer }
528 1.1 bouyer
529 1.1 bouyer void
530 1.1 bouyer fuloong_setup(void)
531 1.1 bouyer {
532 1.1 bouyer #if NCOM > 0
533 1.1 bouyer const char *envvar;
534 1.1 bouyer int serial;
535 1.1 bouyer
536 1.1 bouyer envvar = pmon_getenv("nokbd");
537 1.1 bouyer serial = envvar != NULL;
538 1.1 bouyer envvar = pmon_getenv("novga");
539 1.1 bouyer serial = serial && envvar != NULL;
540 1.1 bouyer
541 1.1 bouyer //serial = 1; /* XXXXXX */
542 1.1 bouyer if (serial) {
543 1.1 bouyer comconsiot = &bonito_iot;
544 1.1 bouyer comconsaddr = 0x2f8;
545 1.1 bouyer comconsrate = 115200; /* default PMON console speed */
546 1.1 bouyer }
547 1.1 bouyer #endif
548 1.1 bouyer }
549 1.1 bouyer
550 1.1 bouyer void
551 1.1 bouyer lemote_device_register(struct device *dev, void *aux)
552 1.1 bouyer {
553 1.1 bouyer const char *name = device_xname(dev);
554 1.1 bouyer
555 1.1 bouyer if (dev->dv_class != bootdev_class)
556 1.1 bouyer return;
557 1.1 bouyer
558 1.1 bouyer /*
559 1.1 bouyer * The device numbering must match. There's no way
560 1.1 bouyer * pmon tells us more info. Depending on the usb slot
561 1.1 bouyer * and hubs used you may be lucky. Also, assume umass/sd for usb
562 1.1 bouyer * attached devices.
563 1.1 bouyer */
564 1.1 bouyer switch (bootdev_class) {
565 1.1 bouyer case DV_DISK:
566 1.1 bouyer if (device_is_a(dev, "wd") && strcmp(name, bootdev) == 0) {
567 1.1 bouyer if (booted_device == NULL)
568 1.1 bouyer booted_device = dev;
569 1.1 bouyer } else {
570 1.1 bouyer /* XXX this really only works safely for usb0... */
571 1.1 bouyer if ((device_is_a(dev, "sd") ||
572 1.1 bouyer device_is_a(dev, "cd") == 0) &&
573 1.1 bouyer strncmp(bootdev, "usb", 3) == 0 &&
574 1.1 bouyer strcmp(name + 2, bootdev + 3) == 0) {
575 1.1 bouyer if (booted_device == NULL)
576 1.1 bouyer booted_device = dev;
577 1.1 bouyer }
578 1.1 bouyer }
579 1.1 bouyer break;
580 1.1 bouyer case DV_IFNET:
581 1.1 bouyer /*
582 1.1 bouyer * This relies on the onboard Ethernet interface being
583 1.1 bouyer * attached before any other (usb) interface.
584 1.1 bouyer */
585 1.1 bouyer if (booted_device == NULL)
586 1.1 bouyer booted_device = dev;
587 1.1 bouyer break;
588 1.1 bouyer default:
589 1.1 bouyer break;
590 1.1 bouyer }
591 1.1 bouyer }
592