ofw_isa.c revision 91966
186232Stmm/*
286232Stmm * Copyright (c) 1999, 2000 Matthew R. Green
386232Stmm * Copyright (c) 2001 Thomas Moestl <tmm@FreeBSD.org>
486232Stmm * All rights reserved.
586232Stmm *
686232Stmm * Redistribution and use in source and binary forms, with or without
786232Stmm * modification, are permitted provided that the following conditions
886232Stmm * are met:
986232Stmm * 1. Redistributions of source code must retain the above copyright
1086232Stmm *    notice, this list of conditions and the following disclaimer.
1186232Stmm * 2. Redistributions in binary form must reproduce the above copyright
1286232Stmm *    notice, this list of conditions and the following disclaimer in the
1386232Stmm *    documentation and/or other materials provided with the distribution.
1486232Stmm * 3. The name of the author may not be used to endorse or promote products
1586232Stmm *    derived from this software without specific prior written permission.
1686232Stmm *
1786232Stmm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1886232Stmm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1986232Stmm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2086232Stmm * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2186232Stmm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2286232Stmm * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2386232Stmm * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2486232Stmm * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2586232Stmm * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2686232Stmm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2786232Stmm * SUCH DAMAGE.
2886232Stmm *
2986232Stmm *	from: NetBSD: ebus.c,v 1.26 2001/09/10 16:27:53 eeh Exp
3086232Stmm *
3186232Stmm * $FreeBSD: head/sys/sparc64/isa/ofw_isa.c 91966 2002-03-09 22:00:30Z tmm $
3286232Stmm */
3386232Stmm
3486232Stmm/*
3586232Stmm * Helper functions which can be used in both ISA and EBus code.
3686232Stmm */
3786232Stmm
3886232Stmm#include <sys/param.h>
3991966Stmm#include <sys/systm.h>
4086232Stmm#include <sys/bus.h>
4186232Stmm
4286232Stmm#include <ofw/openfirm.h>
4386232Stmm#include <ofw/ofw_pci.h>
4486232Stmm
4586232Stmm#include <machine/resource.h>
4686232Stmm#include <machine/ofw_bus.h>
4786232Stmm
4886232Stmm#include <sparc64/isa/ofw_isa.h>
4986232Stmm#include <sparc64/pci/ofw_pci.h>
5086232Stmm
5186232Stmm/*
5286232Stmm * This applies only for an ISA/EBus with an own interrupt-map property.
5386232Stmm */
5486232Stmmint
5586232Stmmofw_isa_map_intr(struct isa_imap *imap, int nimap, struct isa_imap_msk *imapmsk,
5686232Stmm    int intr, struct isa_regs *regs, int nregs)
5786232Stmm{
5886232Stmm	char regm[8];
5986232Stmm
6086232Stmm	return (ofw_bus_route_intr(intr, regs, sizeof(*regs), 8, nregs,
6186232Stmm	    imap, nimap, imapmsk, regm));
6286232Stmm}
6386232Stmm
6486232Stmm/* XXX: this only supports PCI as parent bus right now. */
6586232Stmmint
6686232Stmmofw_isa_map_iorange(struct isa_ranges *range, int nrange, u_long *start,
6786232Stmm    u_long *end)
6886232Stmm{
6986232Stmm	u_int64_t offs, cstart, cend;
7086232Stmm	int i;
7186232Stmm
7286232Stmm	for (i = 0; i < nrange; i++) {
7386232Stmm		cstart = ((u_int64_t)range[i].child_hi << 32) |
7486232Stmm		    range[i].child_lo;
7586232Stmm		cend = cstart + range[i].size;
7686232Stmm		if (*start < cstart || *start > cend)
7786232Stmm			continue;
7886232Stmm		if (*end < cstart || *end > cend) {
7986232Stmm			panic("ofw_isa_map_iorange: iorange crosses pci "
8086232Stmm			    "ranges (%#lx not in %#lx - %#lx)", *end, cstart,
8186232Stmm			    cend);
8286232Stmm		}
8386232Stmm		offs = (((u_int64_t)range[i].phys_mid << 32) |
8486232Stmm		    range[i].phys_lo);
8586232Stmm		*start = *start + offs - cstart;
8686232Stmm		*end  = *end + offs - cstart;
8786232Stmm		/* Isolate address space and find the right tag */
8886232Stmm		switch (ISA_RANGE_PS(&range[i])) {
8986232Stmm		case PCI_CS_IO:
9086232Stmm			return (SYS_RES_IOPORT);
9186232Stmm		case PCI_CS_MEM32:
9286232Stmm			return (SYS_RES_MEMORY);
9386232Stmm		default:
9486232Stmm			panic("ofw_isa_map_iorange: illegal space %x",
9586232Stmm			    ISA_RANGE_PS(&range[i]));
9686232Stmm			break;
9786232Stmm		}
9886232Stmm	}
9986232Stmm	panic("ofw_isa_map_iorange: could not map range %#lx - %#lx",
10086232Stmm	    *start, *end);
10186232Stmm}
102