1 /*
2 * Copyright (c) 1999, 2000 Matthew R. Green
3 * Copyright (c) 2001, 2003 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:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * from: NetBSD: ebus.c,v 1.26 2001/09/10 16:27:53 eeh Exp
30 *
31 * $FreeBSD: releng/5.2/sys/sparc64/isa/ofw_isa.c 119338 2003-08-23 00:11:16Z imp $
32 */
33
34 /*
35 * Helper functions which can be used in both ISA and EBus code.
36 */
37
38 #include "opt_ofw_pci.h"
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/bus.h>
43
44 #include <dev/ofw/openfirm.h>
45 #include <dev/ofw/ofw_pci.h>
46
47 #include <machine/bus.h>
48 #include <machine/resource.h>
49 #include <machine/ofw_bus.h>
50
51 #include <sparc64/pci/ofw_pci.h>
52 #include <sparc64/isa/ofw_isa.h>
53
54 #include "pcib_if.h"
55
56 /* XXX: this only supports PCI as parent bus right now. */
57 int
58 ofw_isa_map_iorange(struct isa_ranges *range, int nrange, u_long *start,
59 u_long *end)
60 {
61 u_int64_t offs, cstart, cend;
62 int i;
63
64 for (i = 0; i < nrange; i++) {
65 cstart = ((u_int64_t)range[i].child_hi << 32) |
66 range[i].child_lo;
67 cend = cstart + range[i].size;
68 if (*start < cstart || *start > cend)
69 continue;
70 if (*end < cstart || *end > cend) {
71 panic("ofw_isa_map_iorange: iorange crosses pci "
72 "ranges (%#lx not in %#lx - %#lx)", *end, cstart,
73 cend);
74 }
75 offs = (((u_int64_t)range[i].phys_mid << 32) |
76 range[i].phys_lo);
77 *start = *start + offs - cstart;
78 *end = *end + offs - cstart;
79 /* Isolate address space and find the right tag */
80 switch (ISA_RANGE_PS(&range[i])) {
81 case PCI_CS_IO:
82 return (SYS_RES_IOPORT);
83 case PCI_CS_MEM32:
84 return (SYS_RES_MEMORY);
85 default:
86 panic("ofw_isa_map_iorange: illegal space %x",
87 ISA_RANGE_PS(&range[i]));
88 break;
89 }
90 }
91 panic("ofw_isa_map_iorange: could not map range %#lx - %#lx",
92 *start, *end);
93 }
94
95 #ifdef OFW_NEWPCI
96 ofw_pci_intr_t
97 ofw_isa_route_intr(device_t bridge, phandle_t node, struct ofw_bus_iinfo *ii,
98 ofw_isa_intr_t intr)
99 {
100 struct isa_regs reg;
101 u_int8_t maskbuf[sizeof(reg) + sizeof(intr)];
102 device_t pbridge;
103 ofw_isa_intr_t mintr;
104
105 pbridge = device_get_parent(device_get_parent(bridge));
106 /*
107 * If we get a match from using the map, the resulting INO is
108 * fully specified, so we may not continue to map.
109 */
110 if (!ofw_bus_lookup_imap(node, ii, ®, sizeof(reg),
111 &intr, sizeof(intr), &mintr, sizeof(mintr), maskbuf)) {
112 /* Try routing at the parent bridge. */
113 mintr = PCIB_ROUTE_INTERRUPT(pbridge, bridge, intr);
114 }
115 return (mintr);
116 }
117 #endif /* OFW_NEWPCI */
Cache object: 7c891cafd5e4b5e1ba4eec6a3e93187b
|