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