ofw_isa.c revision 86232
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: head/sys/sparc64/isa/ofw_isa.c 86232 2001-11-09 20:21:21Z 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/bus.h>
40
41#include <ofw/openfirm.h>
42#include <ofw/ofw_pci.h>
43
44#include <machine/resource.h>
45#include <machine/ofw_bus.h>
46
47#include <sparc64/isa/ofw_isa.h>
48#include <sparc64/pci/ofw_pci.h>
49
50/*
51 * This applies only for an ISA/EBus with an own interrupt-map property.
52 */
53int
54ofw_isa_map_intr(struct isa_imap *imap, int nimap, struct isa_imap_msk *imapmsk,
55    int intr, struct isa_regs *regs, int nregs)
56{
57	char regm[8];
58
59	return (ofw_bus_route_intr(intr, regs, sizeof(*regs), 8, nregs,
60	    imap, nimap, imapmsk, regm));
61}
62
63/* XXX: this only supports PCI as parent bus right now. */
64int
65ofw_isa_map_iorange(struct isa_ranges *range, int nrange, u_long *start,
66    u_long *end)
67{
68	u_int64_t offs, cstart, cend;
69	int i;
70
71	for (i = 0; i < nrange; i++) {
72		cstart = ((u_int64_t)range[i].child_hi << 32) |
73		    range[i].child_lo;
74		cend = cstart + range[i].size;
75		if (*start < cstart || *start > cend)
76			continue;
77		if (*end < cstart || *end > cend) {
78			panic("ofw_isa_map_iorange: iorange crosses pci "
79			    "ranges (%#lx not in %#lx - %#lx)", *end, cstart,
80			    cend);
81		}
82		offs = (((u_int64_t)range[i].phys_mid << 32) |
83		    range[i].phys_lo);
84		*start = *start + offs - cstart;
85		*end  = *end + offs - cstart;
86		/* Isolate address space and find the right tag */
87		switch (ISA_RANGE_PS(&range[i])) {
88		case PCI_CS_IO:
89			return (SYS_RES_IOPORT);
90		case PCI_CS_MEM32:
91			return (SYS_RES_MEMORY);
92		default:
93			panic("ofw_isa_map_iorange: illegal space %x",
94			    ISA_RANGE_PS(&range[i]));
95			break;
96		}
97	}
98	panic("ofw_isa_map_iorange: could not map range %#lx - %#lx",
99	    *start, *end);
100}
101