166458Sdfr/*-
266458Sdfr * Copyright (c) 1998 Doug Rabson
366458Sdfr * All rights reserved.
466458Sdfr *
566458Sdfr * Redistribution and use in source and binary forms, with or without
666458Sdfr * modification, are permitted provided that the following conditions
766458Sdfr * are met:
866458Sdfr * 1. Redistributions of source code must retain the above copyright
966458Sdfr *    notice, this list of conditions and the following disclaimer.
1066458Sdfr * 2. Redistributions in binary form must reproduce the above copyright
1166458Sdfr *    notice, this list of conditions and the following disclaimer in the
1266458Sdfr *    documentation and/or other materials provided with the distribution.
1366458Sdfr *
1466458Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1566458Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1666458Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1766458Sdfr * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1866458Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1966458Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2066458Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2166458Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2266458Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2366458Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2466458Sdfr * SUCH DAMAGE.
2566458Sdfr *
2666458Sdfr * $FreeBSD$
2766458Sdfr */
2866458Sdfr
2966458Sdfr/*
3066458Sdfr * Modifications for Intel architecture by Garrett A. Wollman.
3166458Sdfr * Copyright 1998 Massachusetts Institute of Technology
3266458Sdfr *
3366458Sdfr * Permission to use, copy, modify, and distribute this software and
3466458Sdfr * its documentation for any purpose and without fee is hereby
3566458Sdfr * granted, provided that both the above copyright notice and this
3666458Sdfr * permission notice appear in all copies, that both the above
3766458Sdfr * copyright notice and this permission notice appear in all
3866458Sdfr * supporting documentation, and that the name of M.I.T. not be used
3966458Sdfr * in advertising or publicity pertaining to distribution of the
4066458Sdfr * software without specific, written prior permission.  M.I.T. makes
4166458Sdfr * no representations about the suitability of this software for any
4266458Sdfr * purpose.  It is provided "as is" without express or implied
4366458Sdfr * warranty.
4466458Sdfr *
4566458Sdfr * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
4666458Sdfr * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
4766458Sdfr * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
4866458Sdfr * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
4966458Sdfr * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
5066458Sdfr * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
5166458Sdfr * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
5266458Sdfr * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
5366458Sdfr * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5466458Sdfr * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
5566458Sdfr * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5666458Sdfr * SUCH DAMAGE.
5766458Sdfr */
5866458Sdfr
5966458Sdfr#include <sys/param.h>
6066458Sdfr#include <sys/bus.h>
6166458Sdfr#include <sys/malloc.h>
6266458Sdfr#include <machine/bus.h>
6366458Sdfr#include <sys/rman.h>
6466458Sdfr
6566458Sdfr#include <machine/resource.h>
6666458Sdfr
6766458Sdfr#include <isa/isareg.h>
6866458Sdfr#include <isa/isavar.h>
6966458Sdfr#include <isa/isa_common.h>
7066458Sdfr
7166458Sdfrvoid
7288376Stmmisa_init(device_t dev)
7366458Sdfr{
7466458Sdfr}
7566458Sdfr
7666458Sdfr/*
7766458Sdfr * This implementation simply passes the request up to the parent
7866458Sdfr * bus, which in our case is the special i386 nexus, substituting any
7966458Sdfr * configured values if the caller defaulted.  We can get away with
8066458Sdfr * this because there is no special mapping for ISA resources on an Intel
8166458Sdfr * platform.  When porting this code to another architecture, it may be
8266458Sdfr * necessary to interpose a mapping layer here.
8366458Sdfr */
8466458Sdfrstruct resource *
8566458Sdfrisa_alloc_resource(device_t bus, device_t child, int type, int *rid,
8666458Sdfr		   u_long start, u_long end, u_long count, u_int flags)
8766458Sdfr{
8866458Sdfr	/*
89127146Sjmg	 * Consider adding a resource definition.
9066458Sdfr	 */
9166458Sdfr	int passthrough = (device_get_parent(child) != bus);
9266458Sdfr	int isdefault = (start == 0UL && end == ~0UL);
9366458Sdfr	struct isa_device* idev = DEVTOISA(child);
9466458Sdfr	struct resource_list *rl = &idev->id_resources;
9566458Sdfr	struct resource_list_entry *rle;
9666458Sdfr
9766458Sdfr	if (!passthrough && !isdefault) {
9866458Sdfr		rle = resource_list_find(rl, type, *rid);
9966458Sdfr		if (!rle) {
10066458Sdfr			if (*rid < 0)
10166458Sdfr				return 0;
10266458Sdfr			switch (type) {
10366458Sdfr			case SYS_RES_IRQ:
10466458Sdfr				if (*rid >= ISA_NIRQ)
10566458Sdfr					return 0;
10666458Sdfr				break;
10766458Sdfr			case SYS_RES_DRQ:
10866458Sdfr				if (*rid >= ISA_NDRQ)
10966458Sdfr					return 0;
11066458Sdfr				break;
11166458Sdfr			case SYS_RES_MEMORY:
11266458Sdfr				if (*rid >= ISA_NMEM)
11366458Sdfr					return 0;
11466458Sdfr				break;
11566458Sdfr			case SYS_RES_IOPORT:
11666458Sdfr				if (*rid >= ISA_NPORT)
11766458Sdfr					return 0;
11866458Sdfr				break;
11966458Sdfr			default:
12066458Sdfr				return 0;
12166458Sdfr			}
12266458Sdfr			resource_list_add(rl, type, *rid, start, end, count);
12366458Sdfr		}
12466458Sdfr	}
12566458Sdfr
12666458Sdfr	return resource_list_alloc(rl, bus, child, type, rid,
12766458Sdfr				   start, end, count, flags);
12866458Sdfr}
12966458Sdfr
13066458Sdfrint
13166458Sdfrisa_release_resource(device_t bus, device_t child, int type, int rid,
13266458Sdfr		     struct resource *r)
13366458Sdfr{
13466458Sdfr	struct isa_device* idev = DEVTOISA(child);
13566458Sdfr	struct resource_list *rl = &idev->id_resources;
13666458Sdfr	return resource_list_release(rl, bus, child, type, rid, r);
13766458Sdfr}
138