isa_machdep.c revision 1.2 1 1.1 bouyer /* $OpenBSD: isa_machdep.c,v 1.1 2010/05/08 21:59:56 miod 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 * Legacy device support.
21 1.1 bouyer */
22 1.1 bouyer
23 1.1 bouyer #include <sys/param.h>
24 1.1 bouyer #include <sys/systm.h>
25 1.1 bouyer #include <sys/device.h>
26 1.1 bouyer
27 1.2 macallan #include <mips/cpuregs.h>
28 1.1 bouyer #include <evbmips/loongson/autoconf.h>
29 1.1 bouyer #include <machine/intr.h>
30 1.1 bouyer
31 1.1 bouyer #include <dev/ic/i8259reg.h>
32 1.1 bouyer
33 1.1 bouyer #include <dev/pci/pcivar.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
38 1.1 bouyer #include <mips/bonito/bonitoreg.h>
39 1.1 bouyer #include <mips/bonito/bonitovar.h>
40 1.1 bouyer
41 1.1 bouyer #include <evbmips/loongson/loongson_isa.h>
42 1.1 bouyer
43 1.1 bouyer uint loongson_isaimr;
44 1.1 bouyer
45 1.1 bouyer void
46 1.1 bouyer loongson_set_isa_imr(uint newimr)
47 1.1 bouyer {
48 1.1 bouyer uint imr1, imr2;
49 1.1 bouyer
50 1.1 bouyer imr1 = 0xff & ~newimr;
51 1.1 bouyer imr1 &= ~(1 << 2); /* enable cascade */
52 1.1 bouyer imr2 = 0xff & ~(newimr >> 8);
53 1.1 bouyer
54 1.1 bouyer /*
55 1.1 bouyer * For some reason, trying to write the same value to the PIC
56 1.1 bouyer * registers causes an immediate system freeze (at least on the
57 1.1 bouyer * 2F and CS5536 based Lemote Yeeloong), so we only do this if
58 1.1 bouyer * the value changes.
59 1.1 bouyer * Note that interrupts have been disabled by the caller.
60 1.1 bouyer */
61 1.1 bouyer //if ((newimr ^ loongson_isaimr) & 0xff00)
62 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + IO_ICU2 + 1) = imr2;
63 1.1 bouyer //if ((newimr ^ loongson_isaimr) & 0x00ff)
64 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + IO_ICU1 + 1) = imr1;
65 1.1 bouyer __asm__ __volatile__ ("sync" ::: "memory");
66 1.1 bouyer loongson_isaimr = newimr;
67 1.1 bouyer }
68 1.1 bouyer
69 1.1 bouyer void
70 1.1 bouyer loongson_isa_specific_eoi(int bit)
71 1.1 bouyer {
72 1.1 bouyer KASSERT((bit < 16) && (bit >= 0));
73 1.1 bouyer loongson_isaimr &= ~(1 << bit);
74 1.1 bouyer if (bit & 8) {
75 1.1 bouyer (void)REGVAL8(BONITO_PCIIO_BASE + IO_ICU2 + 1);
76 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + IO_ICU2 + 1) =
77 1.1 bouyer (0xff & ~(loongson_isaimr >> 8));
78 1.1 bouyer __asm__ __volatile__ ("sync" ::: "memory");
79 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + IO_ICU2 + PIC_OCW2) =
80 1.1 bouyer OCW2_SELECT | OCW2_EOI | OCW2_SL | OCW2_ILS(bit & 7);
81 1.1 bouyer bit = 2;
82 1.1 bouyer __asm__ __volatile__ ("sync" ::: "memory");
83 1.1 bouyer }
84 1.1 bouyer (void)REGVAL8(BONITO_PCIIO_BASE + IO_ICU1 + 1);
85 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + IO_ICU1 + 1) =
86 1.1 bouyer (0xff & ~(loongson_isaimr));
87 1.1 bouyer __asm__ __volatile__ ("sync" ::: "memory");
88 1.1 bouyer REGVAL8(BONITO_PCIIO_BASE + IO_ICU1 + PIC_OCW2) =
89 1.1 bouyer OCW2_SELECT | OCW2_EOI | OCW2_SL | OCW2_ILS(bit);
90 1.1 bouyer __asm__ __volatile__ ("sync" ::: "memory");
91 1.1 bouyer }
92