1191450Smarcel/*- 2191450Smarcel * Copyright (c) 2009 Marcel Moolenaar 3191450Smarcel * 4191450Smarcel * Redistribution and use in source and binary forms, with or without 5191450Smarcel * modification, are permitted provided that the following conditions 6191450Smarcel * are met: 7191450Smarcel * 1. Redistributions of source code must retain the above copyright 8191450Smarcel * notice, this list of conditions and the following disclaimer. 9191450Smarcel * 2. Redistributions in binary form must reproduce the above copyright 10191450Smarcel * notice, this list of conditions and the following disclaimer in the 11191450Smarcel * documentation and/or other materials provided with the distribution. 12191450Smarcel * 13191450Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14191450Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15191450Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16191450Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17191450Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 18191450Smarcel * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19191450Smarcel * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 20191450Smarcel * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 21191450Smarcel * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22191450Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23191450Smarcel * SUCH DAMAGE. 24191450Smarcel */ 25191450Smarcel 26191450Smarcel#include <sys/cdefs.h> 27191450Smarcel__FBSDID("$FreeBSD$"); 28191450Smarcel 29191450Smarcel#include <sys/param.h> 30191450Smarcel#include <sys/bus.h> 31191450Smarcel#include <sys/malloc.h> 32191450Smarcel#include <machine/bus.h> 33191450Smarcel#include <sys/rman.h> 34191450Smarcel 35209298Snwhitehorn#include <machine/intr_machdep.h> 36191450Smarcel#include <machine/resource.h> 37191450Smarcel 38191450Smarcel#include <isa/isareg.h> 39191450Smarcel#include <isa/isavar.h> 40191450Smarcel#include <isa/isa_common.h> 41191450Smarcel 42191450Smarcelvoid 43191450Smarcelisa_init(device_t dev) 44191450Smarcel{ 45191450Smarcel} 46191450Smarcel 47191450Smarcelstruct resource * 48191450Smarcelisa_alloc_resource(device_t bus, device_t child, int type, int *rid, 49191450Smarcel u_long start, u_long end, u_long count, u_int flags) 50191450Smarcel{ 51191450Smarcel struct isa_device* idev = DEVTOISA(child); 52191450Smarcel struct resource_list *rl = &idev->id_resources; 53191450Smarcel int isdefault, passthrough, rids; 54191450Smarcel 55191450Smarcel isdefault = (start == 0UL && end == ~0UL) ? 1 : 0; 56191450Smarcel passthrough = (device_get_parent(child) != bus) ? 1 : 0; 57191450Smarcel 58191450Smarcel if (!passthrough && !isdefault && 59191450Smarcel resource_list_find(rl, type, *rid) == NULL) { 60191450Smarcel switch (type) { 61191450Smarcel case SYS_RES_IOPORT: rids = ISA_PNP_NPORT; break; 62218075Smarcel case SYS_RES_IRQ: rids = ISA_PNP_NIRQ; break; 63191450Smarcel case SYS_RES_MEMORY: rids = ISA_PNP_NMEM; break; 64191450Smarcel default: rids = 0; break; 65191450Smarcel } 66191450Smarcel if (*rid < 0 || *rid >= rids) 67191450Smarcel return (NULL); 68191450Smarcel 69191450Smarcel resource_list_add(rl, type, *rid, start, end, count); 70191450Smarcel } 71191450Smarcel 72191450Smarcel return (resource_list_alloc(rl, bus, child, type, rid, start, end, 73191450Smarcel count, flags)); 74191450Smarcel} 75191450Smarcel 76191450Smarcelint 77191450Smarcelisa_release_resource(device_t bus, device_t child, int type, int rid, 78191450Smarcel struct resource *r) 79191450Smarcel{ 80191450Smarcel struct isa_device* idev = DEVTOISA(child); 81191450Smarcel struct resource_list *rl = &idev->id_resources; 82191450Smarcel 83191450Smarcel return (resource_list_release(rl, bus, child, type, rid, r)); 84191450Smarcel} 85