1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2009 Marcel Moolenaar 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28 #include <sys/cdefs.h> 29 __FBSDID("$FreeBSD$"); 30 31 #include <sys/param.h> 32 #include <sys/bus.h> 33 #include <sys/malloc.h> 34 #include <machine/bus.h> 35 #include <sys/rman.h> 36 37 #include <machine/intr_machdep.h> 38 #include <machine/resource.h> 39 40 #include <isa/isareg.h> 41 #include <isa/isavar.h> 42 #include <isa/isa_common.h> 43 44 void 45 isa_init(device_t dev) 46 { 47 } 48 49 struct resource * 50 isa_alloc_resource(device_t bus, device_t child, int type, int *rid, 51 u_long start, u_long end, u_long count, u_int flags) 52 { 53 struct isa_device* idev = DEVTOISA(child); 54 struct resource_list *rl = &idev->id_resources; 55 int isdefault, passthrough, rids; 56 57 isdefault = RMAN_IS_DEFAULT_RANGE(start, end) ? 1 : 0; 58 passthrough = (device_get_parent(child) != bus) ? 1 : 0; 59 60 if (!passthrough && !isdefault && 61 resource_list_find(rl, type, *rid) == NULL) { 62 switch (type) { 63 case SYS_RES_IOPORT: rids = ISA_PNP_NPORT; break; 64 case SYS_RES_IRQ: rids = ISA_PNP_NIRQ; break; 65 case SYS_RES_MEMORY: rids = ISA_PNP_NMEM; break; 66 default: rids = 0; break; 67 } 68 if (*rid < 0 || *rid >= rids) 69 return (NULL); 70 71 resource_list_add(rl, type, *rid, start, end, count); 72 } 73 74 return (resource_list_alloc(rl, bus, child, type, rid, start, end, 75 count, flags)); 76 } 77 78 int 79 isa_release_resource(device_t bus, device_t child, int type, int rid, 80 struct resource *r) 81 { 82 struct isa_device* idev = DEVTOISA(child); 83 struct resource_list *rl = &idev->id_resources; 84 85 return (resource_list_release(rl, bus, child, type, rid, r)); 86 } 87