1 /*
2 * Copyright (c) 1999, 2000 Matthew R. Green
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:
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.1/sys/sparc64/isa/ofw_isa.c 93067 2002-03-24 02:11:06Z tmm $
32 */
33
34 /*
35 * Helper functions which can be used in both ISA and EBus code.
36 */
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/bus.h>
41
42 #include <ofw/openfirm.h>
43 #include <ofw/ofw_pci.h>
44
45 #include <machine/resource.h>
46 #include <machine/ofw_bus.h>
47
48 #include <sparc64/isa/ofw_isa.h>
49 #include <sparc64/pci/ofw_pci.h>
50
51 /* XXX: this only supports PCI as parent bus right now. */
52 int
53 ofw_isa_map_iorange(struct isa_ranges *range, int nrange, u_long *start,
54 u_long *end)
55 {
56 u_int64_t offs, cstart, cend;
57 int i;
58
59 for (i = 0; i < nrange; i++) {
60 cstart = ((u_int64_t)range[i].child_hi << 32) |
61 range[i].child_lo;
62 cend = cstart + range[i].size;
63 if (*start < cstart || *start > cend)
64 continue;
65 if (*end < cstart || *end > cend) {
66 panic("ofw_isa_map_iorange: iorange crosses pci "
67 "ranges (%#lx not in %#lx - %#lx)", *end, cstart,
68 cend);
69 }
70 offs = (((u_int64_t)range[i].phys_mid << 32) |
71 range[i].phys_lo);
72 *start = *start + offs - cstart;
73 *end = *end + offs - cstart;
74 /* Isolate address space and find the right tag */
75 switch (ISA_RANGE_PS(&range[i])) {
76 case PCI_CS_IO:
77 return (SYS_RES_IOPORT);
78 case PCI_CS_MEM32:
79 return (SYS_RES_MEMORY);
80 default:
81 panic("ofw_isa_map_iorange: illegal space %x",
82 ISA_RANGE_PS(&range[i]));
83 break;
84 }
85 }
86 panic("ofw_isa_map_iorange: could not map range %#lx - %#lx",
87 *start, *end);
88 }
Cache object: 69dc688a23143eb3150d3473201a2f16
|