Deleted Added
full compact
isa.c (116448) isa.c (117119)
1/*-
2 * Copyright (c) 1998 Doug Rabson
3 * Copyright (c) 2001 Thomas Moestl <tmm@FreeBSD.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 12 unchanged lines hidden (view full) ---

21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * from: FreeBSD: src/sys/alpha/isa/isa.c,v 1.26 2001/07/11
28 *
1/*-
2 * Copyright (c) 1998 Doug Rabson
3 * Copyright (c) 2001 Thomas Moestl <tmm@FreeBSD.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 12 unchanged lines hidden (view full) ---

21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * from: FreeBSD: src/sys/alpha/isa/isa.c,v 1.26 2001/07/11
28 *
29 * $FreeBSD: head/sys/sparc64/isa/isa.c 116448 2003-06-16 19:06:36Z jmg $
29 * $FreeBSD: head/sys/sparc64/isa/isa.c 117119 2003-07-01 14:52:47Z tmm $
30 */
31
30 */
31
32#include "opt_ofw_pci.h"
33
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>
35#include <sys/module.h>
36#include <sys/bus.h>
37#include <machine/bus.h>
38#include <sys/malloc.h>
39#include <sys/proc.h>

--- 12 unchanged lines hidden (view full) ---

52
53#include <machine/intr_machdep.h>
54#include <machine/ofw_bus.h>
55#include <machine/resource.h>
56
57#include <sparc64/pci/ofw_pci.h>
58#include <sparc64/isa/ofw_isa.h>
59
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/kernel.h>
37#include <sys/module.h>
38#include <sys/bus.h>
39#include <machine/bus.h>
40#include <sys/malloc.h>
41#include <sys/proc.h>

--- 12 unchanged lines hidden (view full) ---

54
55#include <machine/intr_machdep.h>
56#include <machine/ofw_bus.h>
57#include <machine/resource.h>
58
59#include <sparc64/pci/ofw_pci.h>
60#include <sparc64/isa/ofw_isa.h>
61
60#include "sparcbus_if.h"
61
62/* There can be only one ISA bus, so it is safe to use globals. */
63bus_space_tag_t isa_io_bt = NULL;
64bus_space_handle_t isa_io_hdl;
65bus_space_tag_t isa_mem_bt = NULL;
66bus_space_handle_t isa_mem_hdl;
67
68u_int64_t isa_io_base;
69u_int64_t isa_io_limit;
70u_int64_t isa_mem_base;
71u_int64_t isa_mem_limit;
72
73device_t isa_bus_device;
74
75static phandle_t isab_node;
62/* There can be only one ISA bus, so it is safe to use globals. */
63bus_space_tag_t isa_io_bt = NULL;
64bus_space_handle_t isa_io_hdl;
65bus_space_tag_t isa_mem_bt = NULL;
66bus_space_handle_t isa_mem_hdl;
67
68u_int64_t isa_io_base;
69u_int64_t isa_io_limit;
70u_int64_t isa_mem_base;
71u_int64_t isa_mem_limit;
72
73device_t isa_bus_device;
74
75static phandle_t isab_node;
76static u_int32_t isa_ino[8];
76static ofw_pci_intr_t isa_ino[8];
77
77
78#ifdef OFW_NEWPCI
79struct ofw_bus_iinfo isa_iinfo;
80#endif
81
78/*
79 * XXX: This is really partly partly PCI-specific, but unfortunately is
80 * differently enough to have to duplicate it here...
81 */
82#define ISAB_RANGE_PHYS(r) \
83 (((u_int64_t)(r)->phys_mid << 32) | (u_int64_t)(r)->phys_lo)
84#define ISAB_RANGE_SPACE(r) (((r)->phys_hi >> 24) & 0x03)
85

--- 7 unchanged lines hidden (view full) ---

93intrmask_t
94isa_irq_pending(void)
95{
96 intrmask_t pending;
97 int i;
98
99 /* XXX: Is this correct? */
100 for (i = 7, pending = 0; i >= 0; i--) {
82/*
83 * XXX: This is really partly partly PCI-specific, but unfortunately is
84 * differently enough to have to duplicate it here...
85 */
86#define ISAB_RANGE_PHYS(r) \
87 (((u_int64_t)(r)->phys_mid << 32) | (u_int64_t)(r)->phys_lo)
88#define ISAB_RANGE_SPACE(r) (((r)->phys_hi >> 24) & 0x03)
89

--- 7 unchanged lines hidden (view full) ---

97intrmask_t
98isa_irq_pending(void)
99{
100 intrmask_t pending;
101 int i;
102
103 /* XXX: Is this correct? */
104 for (i = 7, pending = 0; i >= 0; i--) {
101 pending <<= 1;
102 if (isa_ino[i] != ORIR_NOTFOUND) {
103 pending |= (SPARCBUS_INTR_PENDING(isa_bus_device,
105 pending <<= 1;
106 if (isa_ino[i] != PCI_INVALID_IRQ) {
107 pending |= (OFW_PCI_INTR_PENDING(isa_bus_device,
104 isa_ino[i]) == 0) ? 0 : 1;
105 }
106 }
107 return (pending);
108}
109
110void
111isa_init(device_t dev)
112{
113 device_t bridge;
114 phandle_t node;
108 isa_ino[i]) == 0) ? 0 : 1;
109 }
110 }
111 return (pending);
112}
113
114void
115isa_init(device_t dev)
116{
117 device_t bridge;
118 phandle_t node;
115 u_int32_t ino;
119 ofw_isa_intr_t ino;
120#ifndef OFW_NEWPCI
121 ofw_pci_intr_t rino;
122#endif
116 struct isa_ranges *br;
117 int nbr, i;
118
119 /* The parent of the bus must be a PCI-ISA bridge. */
120 bridge = device_get_parent(dev);
123 struct isa_ranges *br;
124 int nbr, i;
125
126 /* The parent of the bus must be a PCI-ISA bridge. */
127 bridge = device_get_parent(dev);
128#ifdef OFW_NEWPCI
129 isab_node = ofw_pci_get_node(bridge);
130#else
121 isab_node = ofw_pci_node(bridge);
131 isab_node = ofw_pci_node(bridge);
132#endif
122 nbr = OF_getprop_alloc(isab_node, "ranges", sizeof(*br), (void **)&br);
123 if (nbr <= 0)
124 panic("isa_init: cannot get bridge range property");
133 nbr = OF_getprop_alloc(isab_node, "ranges", sizeof(*br), (void **)&br);
134 if (nbr <= 0)
135 panic("isa_init: cannot get bridge range property");
136
137#ifdef OFW_NEWPCI
138 ofw_bus_setup_iinfo(isab_node, &isa_iinfo, sizeof(ofw_isa_intr_t));
139#endif
140
125 /*
141 /*
126 * This is really a bad kluge; however, it is needed to provide
127 * isa_irq_pending().
142 * This is really a bad kludge; however, it is needed to provide
143 * isa_irq_pending(), which is unfortunately still used by some
144 * drivers.
128 */
129 for (i = 0; i < 8; i++)
145 */
146 for (i = 0; i < 8; i++)
130 isa_ino[i] = ORIR_NOTFOUND;
147 isa_ino[i] = PCI_INVALID_IRQ;
131 for (node = OF_child(isab_node); node != 0; node = OF_peer(node)) {
132 if (OF_getprop(node, "interrupts", &ino, sizeof(ino)) == -1)
133 continue;
134 if (ino > 7)
135 panic("isa_init: XXX: ino too large");
148 for (node = OF_child(isab_node); node != 0; node = OF_peer(node)) {
149 if (OF_getprop(node, "interrupts", &ino, sizeof(ino)) == -1)
150 continue;
151 if (ino > 7)
152 panic("isa_init: XXX: ino too large");
136 isa_ino[ino] = ofw_bus_route_intr(node, ino,
137 ofw_pci_orb_callback, dev);
153#ifdef OFW_NEWPCI
154 isa_ino[ino] = ofw_isa_route_intr(bridge, node, &isa_iinfo,
155 ino);
156#else
157 rino = ofw_bus_route_intr(node, ino, ofw_pci_orb_callback, dev);
158 isa_ino[ino] = rino == ORIR_NOTFOUND ? PCI_INVALID_IRQ : rino;
159#endif
138 }
139
140 for (nbr -= 1; nbr >= 0; nbr--) {
141 switch(ISAB_RANGE_SPACE(br + nbr)) {
142 case ISAR_SPACE_IO:
143 /* This is probably always 0. */
144 isa_io_base = ISAB_RANGE_PHYS(&br[nbr]);
145 isa_io_limit = br[nbr].size;
160 }
161
162 for (nbr -= 1; nbr >= 0; nbr--) {
163 switch(ISAB_RANGE_SPACE(br + nbr)) {
164 case ISAR_SPACE_IO:
165 /* This is probably always 0. */
166 isa_io_base = ISAB_RANGE_PHYS(&br[nbr]);
167 isa_io_limit = br[nbr].size;
146 isa_io_hdl = SPARCBUS_GET_BUS_HANDLE(bridge, SBBT_IO,
147 isa_io_base, &isa_io_bt);
168 isa_io_hdl = OFW_PCI_GET_BUS_HANDLE(bridge,
169 SYS_RES_IOPORT, isa_io_base, &isa_io_bt);
148 break;
149 case ISAR_SPACE_MEM:
150 /* This is probably always 0. */
151 isa_mem_base = ISAB_RANGE_PHYS(&br[nbr]);
152 isa_mem_limit = br[nbr].size;
170 break;
171 case ISAR_SPACE_MEM:
172 /* This is probably always 0. */
173 isa_mem_base = ISAB_RANGE_PHYS(&br[nbr]);
174 isa_mem_limit = br[nbr].size;
153 isa_mem_hdl = SPARCBUS_GET_BUS_HANDLE(bridge, SBBT_MEM,
154 isa_mem_base, &isa_mem_bt);
175 isa_mem_hdl = OFW_PCI_GET_BUS_HANDLE(bridge,
176 SYS_RES_MEMORY, isa_mem_base, &isa_mem_bt);
155 break;
156 }
157 }
158 free(br, M_OFWPROP);
159}
160
161static int
162isa_route_intr_res(device_t bus, u_long start, u_long end)
163{
164 int res;
165
166 if (start != end) {
167 panic("isa_route_intr_res: allocation of interrupt range not "
168 "supported (0x%lx - 0x%lx)", start, end);
169 }
170 if (start > 7)
171 panic("isa_route_intr_res: start out of isa range");
172 res = isa_ino[start];
177 break;
178 }
179 }
180 free(br, M_OFWPROP);
181}
182
183static int
184isa_route_intr_res(device_t bus, u_long start, u_long end)
185{
186 int res;
187
188 if (start != end) {
189 panic("isa_route_intr_res: allocation of interrupt range not "
190 "supported (0x%lx - 0x%lx)", start, end);
191 }
192 if (start > 7)
193 panic("isa_route_intr_res: start out of isa range");
194 res = isa_ino[start];
173 if (res == ORIR_NOTFOUND)
195 if (res == PCI_INVALID_IRQ)
174 device_printf(bus, "could not map interrupt %d\n", res);
175 return (res);
176}
177
178struct resource *
179isa_alloc_resource(device_t bus, device_t child, int type, int *rid,
180 u_long start, u_long end, u_long count, u_int flags)
181{

--- 57 unchanged lines hidden (view full) ---

239 limit = base + isa_io_limit;
240 break;
241 case SYS_RES_IRQ:
242 if (isdefault && passthrough)
243 panic("isa_alloc_resource: cannot pass through default "
244 "irq allocation");
245 if (!isdefault) {
246 start = end = isa_route_intr_res(bus, start, end);
196 device_printf(bus, "could not map interrupt %d\n", res);
197 return (res);
198}
199
200struct resource *
201isa_alloc_resource(device_t bus, device_t child, int type, int *rid,
202 u_long start, u_long end, u_long count, u_int flags)
203{

--- 57 unchanged lines hidden (view full) ---

261 limit = base + isa_io_limit;
262 break;
263 case SYS_RES_IRQ:
264 if (isdefault && passthrough)
265 panic("isa_alloc_resource: cannot pass through default "
266 "irq allocation");
267 if (!isdefault) {
268 start = end = isa_route_intr_res(bus, start, end);
247 if (start == 255)
269 if (start == PCI_INVALID_IRQ)
248 return (NULL);
249 }
250 break;
251 default:
252 panic("isa_alloc_resource: unsupported resource type %d", type);
253 }
254 if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) {
255 start = ulmin(start + base, limit);
256 end = ulmin(end + base, limit);
257 }
270 return (NULL);
271 }
272 break;
273 default:
274 panic("isa_alloc_resource: unsupported resource type %d", type);
275 }
276 if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) {
277 start = ulmin(start + base, limit);
278 end = ulmin(end + base, limit);
279 }
258
280
259 /*
260 * This inlines a modified resource_list_alloc(); this is needed
261 * because the resources need to have offsets added to them, which
262 * cannot be done beforehand without patching the resource list entries
263 * (which is ugly).
264 */
265 if (passthrough) {
266 return (BUS_ALLOC_RESOURCE(device_get_parent(bus), child,

--- 17 unchanged lines hidden (view full) ---

284 start += base;
285 end += base;
286 if (!INRANGE(start, base, limit) ||
287 !INRANGE(end, base, limit))
288 return (NULL);
289 break;
290 case SYS_RES_IRQ:
291 start = end = isa_route_intr_res(bus, start, end);
281 /*
282 * This inlines a modified resource_list_alloc(); this is needed
283 * because the resources need to have offsets added to them, which
284 * cannot be done beforehand without patching the resource list entries
285 * (which is ugly).
286 */
287 if (passthrough) {
288 return (BUS_ALLOC_RESOURCE(device_get_parent(bus), child,

--- 17 unchanged lines hidden (view full) ---

306 start += base;
307 end += base;
308 if (!INRANGE(start, base, limit) ||
309 !INRANGE(end, base, limit))
310 return (NULL);
311 break;
312 case SYS_RES_IRQ:
313 start = end = isa_route_intr_res(bus, start, end);
292 if (start == 255)
314 if (start == PCI_INVALID_IRQ)
293 return (NULL);
294 break;
295 }
296 }
297
298 rle->res = BUS_ALLOC_RESOURCE(device_get_parent(bus), child,
299 type, rid, start, end, count, flags);
300

--- 44 unchanged lines hidden ---
315 return (NULL);
316 break;
317 }
318 }
319
320 rle->res = BUS_ALLOC_RESOURCE(device_get_parent(bus), child,
321 type, rid, start, end, count, flags);
322

--- 44 unchanged lines hidden ---