1 /*- 2 * Copyright (c) 2015 Marcel Moolenaar 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #include <sys/cdefs.h> 27 #include <sys/param.h> 28 #include <sys/systm.h> 29 #include <sys/bus.h> 30 #include <sys/conf.h> 31 #include <sys/kernel.h> 32 #include <sys/module.h> 33 #include <machine/bus.h> 34 #include <sys/rman.h> 35 #include <machine/resource.h> 36 #include <sys/sbuf.h> 37 38 #include <isa/isavar.h> 39 #include <isa/pnpvar.h> 40 41 #include <dev/proto/proto.h> 42 43 static int proto_isa_probe(device_t dev); 44 static int proto_isa_attach(device_t dev); 45 46 static device_method_t proto_isa_methods[] = { 47 /* Device interface */ 48 DEVMETHOD(device_probe, proto_isa_probe), 49 DEVMETHOD(device_attach, proto_isa_attach), 50 DEVMETHOD(device_detach, proto_detach), 51 DEVMETHOD_END 52 }; 53 54 static driver_t proto_isa_driver = { 55 proto_driver_name, 56 proto_isa_methods, 57 sizeof(struct proto_softc), 58 }; 59 60 static char proto_isa_prefix[] = "isa"; 61 static char **proto_isa_devnames; 62 63 static int 64 proto_isa_probe(device_t dev) 65 { 66 struct sbuf *sb; 67 struct resource *res; 68 int rid, type; 69 70 rid = 0; 71 type = SYS_RES_IOPORT; 72 res = bus_alloc_resource_any(dev, type, &rid, RF_ACTIVE); 73 if (res == NULL) { 74 type = SYS_RES_MEMORY; 75 res = bus_alloc_resource_any(dev, type, &rid, RF_ACTIVE); 76 } 77 if (res == NULL) 78 return (ENODEV); 79 80 sb = sbuf_new_auto(); 81 sbuf_printf(sb, "%s:%#jx", proto_isa_prefix, rman_get_start(res)); 82 sbuf_finish(sb); 83 device_set_desc_copy(dev, sbuf_data(sb)); 84 sbuf_delete(sb); 85 bus_release_resource(dev, type, rid, res); 86 return (proto_probe(dev, proto_isa_prefix, &proto_isa_devnames)); 87 } 88 89 static int 90 proto_isa_alloc(device_t dev, int type, int nrids) 91 { 92 struct resource *res; 93 struct proto_softc *sc; 94 int count, rid; 95 96 sc = device_get_softc(dev); 97 count = 0; 98 for (rid = 0; rid < nrids; rid++) { 99 res = bus_alloc_resource_any(dev, type, &rid, RF_ACTIVE); 100 if (res == NULL) 101 break; 102 proto_add_resource(sc, type, rid, res); 103 count++; 104 } 105 if (type == SYS_RES_DRQ && count > 0) 106 proto_add_resource(sc, PROTO_RES_BUSDMA, 0, NULL); 107 return (count); 108 } 109 110 static int 111 proto_isa_attach(device_t dev) 112 { 113 114 proto_isa_alloc(dev, SYS_RES_IRQ, ISA_NIRQ); 115 proto_isa_alloc(dev, SYS_RES_DRQ, ISA_NDRQ); 116 proto_isa_alloc(dev, SYS_RES_IOPORT, ISA_NPORT); 117 proto_isa_alloc(dev, SYS_RES_MEMORY, ISA_NMEM); 118 return (proto_attach(dev)); 119 } 120 121 DRIVER_MODULE(proto, acpi, proto_isa_driver, NULL, NULL); 122 DRIVER_MODULE(proto, isa, proto_isa_driver, NULL, NULL); 123