Deleted Added
full compact
isa.c (90612) isa.c (93067)
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 90612 2002-02-13 15:43:42Z tmm $
29 * $FreeBSD: head/sys/sparc64/isa/isa.c 93067 2002-03-24 02:11:06Z tmm $
30 */
31
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>

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

46
47#include <pci/pcireg.h>
48#include <pci/pcivar.h>
49
50#include <ofw/ofw_pci.h>
51#include <ofw/openfirm.h>
52
53#include <machine/intr_machdep.h>
30 */
31
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>

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

46
47#include <pci/pcireg.h>
48#include <pci/pcivar.h>
49
50#include <ofw/ofw_pci.h>
51#include <ofw/openfirm.h>
52
53#include <machine/intr_machdep.h>
54#include <machine/ofw_bus.h>
54#include <machine/resource.h>
55
56#include <sparc64/pci/ofw_pci.h>
57#include <sparc64/isa/ofw_isa.h>
58
59#include "sparcbus_if.h"
60
61/* There can be only one ISA bus, so it is safe to use globals. */

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

66
67u_int64_t isa_io_base;
68u_int64_t isa_io_limit;
69u_int64_t isa_mem_base;
70u_int64_t isa_mem_limit;
71
72device_t isa_bus_device;
73
55#include <machine/resource.h>
56
57#include <sparc64/pci/ofw_pci.h>
58#include <sparc64/isa/ofw_isa.h>
59
60#include "sparcbus_if.h"
61
62/* There can be only one ISA bus, so it is safe to use globals. */

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

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
74static struct ofw_pci_register isab_reg;
75static struct ofw_pci_imap *isab_imap;
76static int isab_nimap;
77static struct ofw_pci_imap_msk isab_imap_msk;
78static phandle_t isab_node;
75static phandle_t isab_node;
76static u_int32_t isa_ino[8];
79
80/*
81 * XXX: This is really partly partly PCI-specific, but unfortunately is
82 * differently enough to have to duplicate it here...
83 */
84#define ISAB_RANGE_PHYS(r) \
85 (((u_int64_t)(r)->phys_mid << 32) | (u_int64_t)(r)->phys_lo)
86#define ISAB_RANGE_SPACE(r) (((r)->phys_hi >> 24) & 0x03)
87
88#define ISAR_SPACE_IO 0x01
89#define ISAR_SPACE_MEM 0x02
90
91#define INRANGE(x, start, end) ((x) >= (start) && (x) <= (end))
92
93static int isa_route_intr_res(device_t, u_long, u_long);
94
77
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
86#define ISAR_SPACE_IO 0x01
87#define ISAR_SPACE_MEM 0x02
88
89#define INRANGE(x, start, end) ((x) >= (start) && (x) <= (end))
90
91static int isa_route_intr_res(device_t, u_long, u_long);
92
95static int isa_ino[8];
96
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--) {
105 pending <<= 1;
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--) {
101 pending <<= 1;
106 if (isa_ino[i] != 255) {
102 if (isa_ino[i] != ORIR_NOTFOUND) {
107 pending |= (SPARCBUS_INTR_PENDING(isa_bus_device,
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;
103 pending |= (SPARCBUS_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;
115 u_int32_t ino;
119 struct isa_ranges *br;
120 int nbr, i;
121
122 /* The parent of the bus must be a PCI-ISA bridge. */
123 bridge = device_get_parent(dev);
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);
124 isab_node = ofw_pci_find_node(pci_get_bus(bridge), pci_get_slot(bridge),
125 pci_get_function(bridge));
126 if (OF_getprop(isab_node, "reg", &isab_reg, sizeof(isab_reg)) < 0)
127 panic("isa_init: cannot get bridge reg property");
121 isab_node = ofw_pci_node(bridge);
128 nbr = OF_getprop_alloc(isab_node, "ranges", sizeof(*br), (void **)&br);
129 if (nbr <= 0)
130 panic("isa_init: cannot get bridge range property");
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");
131 node = isab_node;
132 isab_nimap = ofw_pci_find_imap(node, &isab_imap, &isab_imap_msk);
133 if (isab_nimap == -1)
134 panic("isa_init: could not find interrupt-map");
135 for (i = 0; i < 8; i++) {
136 isa_ino[i] = ofw_pci_route_intr2(i, &isab_reg, isab_imap,
137 isab_nimap, &isab_imap_msk);
125 /*
126 * This is really a bad kluge; however, it is needed to provide
127 * isa_irq_pending().
128 */
129 for (i = 0; i < 8; i++)
130 isa_ino[i] = ORIR_NOTFOUND;
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");
136 isa_ino[ino] = ofw_bus_route_intr(node, ino);
138 }
139
137 }
138
140
141 for (nbr -= 1; nbr >= 0; nbr--) {
142 switch(ISAB_RANGE_SPACE(br + nbr)) {
143 case ISAR_SPACE_IO:
144 /* This is probably always 0. */
145 isa_io_base = ISAB_RANGE_PHYS(&br[nbr]);
146 isa_io_limit = br[nbr].size;
147 isa_io_hdl = SPARCBUS_GET_BUS_HANDLE(bridge, SBBT_IO,
148 isa_io_base, &isa_io_bt);

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

163isa_route_intr_res(device_t bus, u_long start, u_long end)
164{
165 int res;
166
167 if (start != end) {
168 panic("isa_route_intr_res: allocation of interrupt range not "
169 "supported (0x%lx - 0x%lx)", start, end);
170 }
139 for (nbr -= 1; nbr >= 0; nbr--) {
140 switch(ISAB_RANGE_SPACE(br + nbr)) {
141 case ISAR_SPACE_IO:
142 /* This is probably always 0. */
143 isa_io_base = ISAB_RANGE_PHYS(&br[nbr]);
144 isa_io_limit = br[nbr].size;
145 isa_io_hdl = SPARCBUS_GET_BUS_HANDLE(bridge, SBBT_IO,
146 isa_io_base, &isa_io_bt);

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

161isa_route_intr_res(device_t bus, u_long start, u_long end)
162{
163 int res;
164
165 if (start != end) {
166 panic("isa_route_intr_res: allocation of interrupt range not "
167 "supported (0x%lx - 0x%lx)", start, end);
168 }
171 res = ofw_pci_route_intr2(start, &isab_reg, isab_imap, isab_nimap,
172 &isab_imap_msk);
169 if (start > 7)
170 panic("isa_route_intr_res: start out of isa range");
171 res = isa_ino[start];
173 if (res == 255)
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)

--- 167 unchanged lines hidden ---
172 if (res == 255)
173 device_printf(bus, "could not map interrupt %d\n", res);
174 return (res);
175}
176
177struct resource *
178isa_alloc_resource(device_t bus, device_t child, int type, int *rid,
179 u_long start, u_long end, u_long count, u_int flags)

--- 167 unchanged lines hidden ---