isa.c revision 47398
14Srgrimes/*-
245720Speter * Copyright (c) 1998 Doug Rabson
34Srgrimes * All rights reserved.
44Srgrimes *
54Srgrimes * Redistribution and use in source and binary forms, with or without
64Srgrimes * modification, are permitted provided that the following conditions
74Srgrimes * are met:
84Srgrimes * 1. Redistributions of source code must retain the above copyright
94Srgrimes *    notice, this list of conditions and the following disclaimer.
104Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
114Srgrimes *    notice, this list of conditions and the following disclaimer in the
124Srgrimes *    documentation and/or other materials provided with the distribution.
134Srgrimes *
1445720Speter * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
154Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
164Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1745720Speter * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
184Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
194Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
204Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
214Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
224Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
234Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
244Srgrimes * SUCH DAMAGE.
254Srgrimes *
2647398Sdfr *	$Id: isa.c,v 1.126 1999/05/14 11:22:28 dfr Exp $
274Srgrimes */
284Srgrimes
294Srgrimes/*
3045720Speter * Modifications for Intel architecture by Garrett A. Wollman.
3145720Speter * Copyright 1998 Massachusetts Institute of Technology
324Srgrimes *
3345720Speter * Permission to use, copy, modify, and distribute this software and
3445720Speter * its documentation for any purpose and without fee is hereby
3545720Speter * granted, provided that both the above copyright notice and this
3645720Speter * permission notice appear in all copies, that both the above
3745720Speter * copyright notice and this permission notice appear in all
3845720Speter * supporting documentation, and that the name of M.I.T. not be used
3945720Speter * in advertising or publicity pertaining to distribution of the
4045720Speter * software without specific, written prior permission.  M.I.T. makes
4145720Speter * no representations about the suitability of this software for any
4245720Speter * purpose.  It is provided "as is" without express or implied
4345720Speter * warranty.
4445720Speter *
4545720Speter * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
4645720Speter * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
4745720Speter * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
4845720Speter * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
4945720Speter * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
5045720Speter * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
5145720Speter * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
5245720Speter * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
5345720Speter * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5445720Speter * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
5545720Speter * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5645720Speter * SUCH DAMAGE.
574Srgrimes */
584Srgrimes
592056Swollman#include <sys/param.h>
6013644Sbde#include <sys/systm.h>
6145720Speter#include <sys/kernel.h>
6245720Speter#include <sys/bus.h>
632056Swollman#include <sys/malloc.h>
6445720Speter#include <sys/module.h>
6545720Speter#include <machine/bus.h>
6645720Speter#include <sys/rman.h>
674Srgrimes
6845720Speter#include <machine/resource.h>
6926157Sse
7045720Speter#include <isa/isavar.h>
7147398Sdfr#include <isa/isa_common.h>
7229613Sjmg
7347398Sdfrvoid
7447398Sdfrisa_init(void)
7531457Sjmg{
7647398Sdfr    isa_wrap_old_drivers();
773258Sdg}
788876Srgrimes
7947178Sdfr/*
8045720Speter * This implementation simply passes the request up to the parent
8145720Speter * bus, which in our case is the special i386 nexus, substituting any
8245720Speter * configured values if the caller defaulted.  We can get away with
8345720Speter * this because there is no special mapping for ISA resources on an Intel
8445720Speter * platform.  When porting this code to another architecture, it may be
8545720Speter * necessary to interpose a mapping layer here.
8615147Ssmpatel */
8747398Sdfrstruct resource *
8845720Speterisa_alloc_resource(device_t bus, device_t child, int type, int *rid,
8945720Speter		   u_long start, u_long end, u_long count, u_int flags)
9015147Ssmpatel{
9145720Speter	/*
9247398Sdfr	 * Consider adding a resource definition. We allow rid 0-1 for
9347398Sdfr	 * irq, drq and memory and rid 0-7 for ports which is sufficient for
9447398Sdfr	 * isapnp.
9545720Speter	 */
9647398Sdfr	int passthrough = (device_get_parent(child) != bus);
9747398Sdfr	int isdefault = (start == 0UL && end == ~0UL);
9847398Sdfr	struct resource_list *rl;
9947398Sdfr	struct resource_list_entry *rle;
10047398Sdfr
10147398Sdfr	if (!passthrough && !isdefault) {
10247398Sdfr		rl = device_get_ivars(child);
10347398Sdfr		rle = resource_list_find(rl, type, *rid);
10447398Sdfr		if (!rle) {
10547398Sdfr			if (*rid < 0)
10647398Sdfr				return 0;
10747398Sdfr			if (type != SYS_RES_IOPORT && *rid > 1)
10847398Sdfr				return 0;
10947398Sdfr			if (type == SYS_RES_IOPORT && *rid > 7)
11047398Sdfr				return 0;
11147398Sdfr			resource_list_add(rl, type, *rid, start, end, count);
11245720Speter		}
11345720Speter	}
11447398Sdfr
11547398Sdfr	return resource_list_alloc(bus, child, type, rid,
11647398Sdfr				   start, end, count, flags);
11745720Speter}
11815147Ssmpatel
11947398Sdfrint
12045720Speterisa_release_resource(device_t bus, device_t child, int type, int rid,
12145720Speter		     struct resource *r)
12245720Speter{
12347398Sdfr	return resource_list_release(bus, child, type, rid, r);
1244Srgrimes}
1254Srgrimes
1264Srgrimes/*
12745720Speter * We can't use the bus_generic_* versions of these methods because those
12845720Speter * methods always pass the bus param as the requesting device, and we need
12945720Speter * to pass the child (the i386 nexus knows about this and is prepared to
13045720Speter * deal).
1314Srgrimes */
13247398Sdfrint
13346743Sdfrisa_setup_intr(device_t bus, device_t child, struct resource *r, int flags,
13445720Speter	       void (*ihand)(void *), void *arg, void **cookiep)
13531457Sjmg{
13646743Sdfr	return (BUS_SETUP_INTR(device_get_parent(bus), child, r, flags,
13746743Sdfr			       ihand, arg, cookiep));
1384Srgrimes}
1394Srgrimes
14047398Sdfrint
14145720Speterisa_teardown_intr(device_t bus, device_t child, struct resource *r,
14245720Speter		  void *cookie)
14327639Smsmith{
14445720Speter	return (BUS_TEARDOWN_INTR(device_get_parent(bus), child, r, cookie));
14527639Smsmith}
146