isa.c revision 52174
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 *
2650477Speter * $FreeBSD: head/sys/i386/isa/isa.c 52174 1999-10-12 21:35:51Z dfr $
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>
6045720Speter#include <sys/bus.h>
612056Swollman#include <sys/malloc.h>
6245720Speter#include <machine/bus.h>
634Srgrimes
6445720Speter#include <machine/resource.h>
6526157Sse
6645720Speter#include <isa/isavar.h>
6747398Sdfr#include <isa/isa_common.h>
6829613Sjmg
6947398Sdfrvoid
7047398Sdfrisa_init(void)
7131457Sjmg{
7247398Sdfr    isa_wrap_old_drivers();
733258Sdg}
748876Srgrimes
7547178Sdfr/*
7645720Speter * This implementation simply passes the request up to the parent
7745720Speter * bus, which in our case is the special i386 nexus, substituting any
7845720Speter * configured values if the caller defaulted.  We can get away with
7945720Speter * this because there is no special mapping for ISA resources on an Intel
8045720Speter * platform.  When porting this code to another architecture, it may be
8145720Speter * necessary to interpose a mapping layer here.
8215147Ssmpatel */
8347398Sdfrstruct resource *
8445720Speterisa_alloc_resource(device_t bus, device_t child, int type, int *rid,
8545720Speter		   u_long start, u_long end, u_long count, u_int flags)
8615147Ssmpatel{
8745720Speter	/*
8847398Sdfr	 * Consider adding a resource definition. We allow rid 0-1 for
8947616Sdfr	 * irq and drq, 0-3 for memory and 0-7 for ports which is
9047616Sdfr	 * sufficient for isapnp.
9145720Speter	 */
9247398Sdfr	int passthrough = (device_get_parent(child) != bus);
9347398Sdfr	int isdefault = (start == 0UL && end == ~0UL);
9452174Sdfr	struct isa_device* idev = DEVTOISA(child);
9552174Sdfr	struct resource_list *rl = &idev->id_resources;
9647398Sdfr	struct resource_list_entry *rle;
9747398Sdfr
9847398Sdfr	if (!passthrough && !isdefault) {
9947398Sdfr		rle = resource_list_find(rl, type, *rid);
10047398Sdfr		if (!rle) {
10147398Sdfr			if (*rid < 0)
10247398Sdfr				return 0;
10352174Sdfr			switch (type) {
10452174Sdfr			case SYS_RES_IRQ:
10552174Sdfr				if (*rid >= ISA_NIRQ)
10652174Sdfr					return 0;
10752174Sdfr				break;
10852174Sdfr			case SYS_RES_DRQ:
10952174Sdfr				if (*rid >= ISA_NDRQ)
11052174Sdfr					return 0;
11152174Sdfr				break;
11252174Sdfr			case SYS_RES_MEMORY:
11352174Sdfr				if (*rid >= ISA_NMEM)
11452174Sdfr					return 0;
11552174Sdfr				break;
11652174Sdfr			case SYS_RES_IOPORT:
11752174Sdfr				if (*rid >= ISA_NPORT)
11852174Sdfr					return 0;
11952174Sdfr				break;
12052174Sdfr			default:
12147398Sdfr				return 0;
12252174Sdfr			}
12347398Sdfr			resource_list_add(rl, type, *rid, start, end, count);
12445720Speter		}
12545720Speter	}
12647398Sdfr
12752174Sdfr	return resource_list_alloc(rl, bus, child, type, rid,
12847398Sdfr				   start, end, count, flags);
12945720Speter}
13015147Ssmpatel
13147398Sdfrint
13245720Speterisa_release_resource(device_t bus, device_t child, int type, int rid,
13345720Speter		     struct resource *r)
13445720Speter{
13552174Sdfr	struct isa_device* idev = DEVTOISA(child);
13652174Sdfr	struct resource_list *rl = &idev->id_resources;
13752174Sdfr	return resource_list_release(rl, bus, child, type, rid, r);
1384Srgrimes}
1394Srgrimes
1404Srgrimes/*
14145720Speter * We can't use the bus_generic_* versions of these methods because those
14245720Speter * methods always pass the bus param as the requesting device, and we need
14345720Speter * to pass the child (the i386 nexus knows about this and is prepared to
14445720Speter * deal).
1454Srgrimes */
14647398Sdfrint
14746743Sdfrisa_setup_intr(device_t bus, device_t child, struct resource *r, int flags,
14845720Speter	       void (*ihand)(void *), void *arg, void **cookiep)
14931457Sjmg{
15046743Sdfr	return (BUS_SETUP_INTR(device_get_parent(bus), child, r, flags,
15146743Sdfr			       ihand, arg, cookiep));
1524Srgrimes}
1534Srgrimes
15447398Sdfrint
15545720Speterisa_teardown_intr(device_t bus, device_t child, struct resource *r,
15645720Speter		  void *cookie)
15727639Smsmith{
15845720Speter	return (BUS_TEARDOWN_INTR(device_get_parent(bus), child, r, cookie));
15927639Smsmith}
160