xref: /netbsd/sys/arch/i386/pci/sis85c503.c (revision bf9ec67e)
1 /*	$NetBSD: sis85c503.c,v 1.3 2001/11/15 07:03:35 lukem Exp $	*/
2 
3 /*-
4  * Copyright (c) 1999 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9  * NASA Ames Research Center.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *	This product includes software developed by the NetBSD
22  *	Foundation, Inc. and its contributors.
23  * 4. Neither the name of The NetBSD Foundation nor the names of its
24  *    contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39 
40 /*
41  * Copyright (c) 1999, by UCHIYAMA Yasushi
42  * All rights reserved.
43  *
44  * Redistribution and use in source and binary forms, with or without
45  * modification, are permitted provided that the following conditions
46  * are met:
47  * 1. Redistributions of source code must retain the above copyright
48  *    notice, this list of conditions and the following disclaimer.
49  * 2. The name of the developer may NOT be used to endorse or promote products
50  *    derived from this software without specific prior written permission.
51  *
52  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
53  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
56  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62  * SUCH DAMAGE.
63  */
64 
65 /*
66  * Support for the SiS 85c503 PCI-ISA bridge interrupt controller.
67  */
68 
69 #include <sys/cdefs.h>
70 __KERNEL_RCSID(0, "$NetBSD: sis85c503.c,v 1.3 2001/11/15 07:03:35 lukem Exp $");
71 
72 #include <sys/param.h>
73 #include <sys/systm.h>
74 #include <sys/device.h>
75 
76 #include <machine/intr.h>
77 #include <machine/bus.h>
78 
79 #include <dev/pci/pcivar.h>
80 #include <dev/pci/pcireg.h>
81 #include <dev/pci/pcidevs.h>
82 
83 #include <i386/pci/pci_intr_fixup.h>
84 #include <i386/pci/sis85c503reg.h>
85 #include <i386/pci/piixvar.h>
86 
87 int	sis85c503_getclink __P((pciintr_icu_handle_t, int, int *));
88 int	sis85c503_get_intr __P((pciintr_icu_handle_t, int, int *));
89 int	sis85c503_set_intr __P((pciintr_icu_handle_t, int, int));
90 
91 const struct pciintr_icu sis85c503_pci_icu = {
92 	sis85c503_getclink,
93 	sis85c503_get_intr,
94 	sis85c503_set_intr,
95 	piix_get_trigger,
96 	piix_set_trigger,
97 };
98 
99 int
100 sis85c503_init(pc, iot, tag, ptagp, phandp)
101 	pci_chipset_tag_t pc;
102 	bus_space_tag_t iot;
103 	pcitag_t tag;
104 	pciintr_icu_tag_t *ptagp;
105 	pciintr_icu_handle_t *phandp;
106 {
107 
108 	if (piix_init(pc, iot, tag, ptagp, phandp) == 0) {
109 		*ptagp = &sis85c503_pci_icu;
110 		return (0);
111 	}
112 
113 	return (1);
114 }
115 
116 int
117 sis85c503_getclink(v, link, clinkp)
118 	pciintr_icu_handle_t v;
119 	int link, *clinkp;
120 {
121 
122 	/* Pattern 1: simple. */
123 	if (link >= 1 && link <= 4) {
124 		*clinkp = SIS85C503_CFG_PIRQ_REGSTART + link - 1;
125 		return (0);
126 	}
127 
128 	/* Pattern 2: configuration register offset */
129 	if (link >= SIS85C503_CFG_PIRQ_REGSTART &&
130 	    link <= SIS85C503_CFG_PIRQ_REGEND) {
131 		*clinkp = link;
132 		return (0);
133 	}
134 
135 	return (1);
136 }
137 
138 int
139 sis85c503_get_intr(v, clink, irqp)
140 	pciintr_icu_handle_t v;
141 	int clink, *irqp;
142 {
143 	struct piix_handle *ph = v;
144 	pcireg_t reg;
145 
146 	if (SIS85C503_LEGAL_LINK(clink) == 0)
147 		return (1);
148 
149 	reg = pci_conf_read(ph->ph_pc, ph->ph_tag,
150 	    SIS85C503_CFG_PIRQ_REGOFS(clink));
151 	reg = SIS85C503_CFG_PIRQ_REG(reg, clink);
152 
153 	if (reg & SIS85C503_CFG_PIRQ_ROUTE_DISABLE)
154 		*irqp = I386_PCI_INTERRUPT_LINE_NO_CONNECTION;
155 	else
156 		*irqp = reg & SIS85C503_CFG_PIRQ_INTR_MASK;
157 
158 	return (0);
159 }
160 
161 int
162 sis85c503_set_intr(v, clink, irq)
163 	pciintr_icu_handle_t v;
164 	int clink, irq;
165 {
166 	struct piix_handle *ph = v;
167 	int shift;
168 	pcireg_t reg;
169 
170 	if (SIS85C503_LEGAL_LINK(clink) == 0 || SIS85C503_LEGAL_IRQ(irq) == 0)
171 		return (1);
172 
173 	reg = pci_conf_read(ph->ph_pc, ph->ph_tag,
174 	    SIS85C503_CFG_PIRQ_REGOFS(clink));
175 	shift = SIS85C503_CFG_PIRQ_SHIFT(clink);
176 	reg &= ~((SIS85C503_CFG_PIRQ_ROUTE_DISABLE |
177 	    SIS85C503_CFG_PIRQ_INTR_MASK) << shift);
178 	reg |= (irq << shift);
179 	pci_conf_write(ph->ph_pc, ph->ph_tag, SIS85C503_CFG_PIRQ_REGOFS(clink),
180 	    reg);
181 
182 	return (0);
183 }
184