1 /*- 2 * Copyright (c) 1991 The Regents of the University of California. 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 * 3. Neither the name of the University nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30 #include <sys/param.h> 31 #include <sys/systm.h> 32 #include <sys/tty.h> 33 #include <sys/proc.h> 34 #include <sys/module.h> 35 #include <sys/kernel.h> 36 #include <sys/bus.h> 37 #include <sys/rman.h> 38 #include <sys/timepps.h> 39 40 #include "sioreg.h" 41 #include "sio_private.h" 42 43 #include <bus/pccard/pccard_cis.h> 44 #include <bus/pccard/pccardreg.h> 45 #include <bus/pccard/pccardvar.h> 46 47 #include "pccarddevs.h" 48 49 static int sio_pccard_attach(device_t dev); 50 static int sio_pccard_match(device_t self); 51 static int sio_pccard_detach(device_t dev); 52 static int sio_pccard_probe(device_t dev); 53 54 static device_method_t sio_pccard_methods[] = { 55 /* Device interface */ 56 DEVMETHOD(device_probe, pccard_compat_probe), 57 DEVMETHOD(device_attach, pccard_compat_attach), 58 DEVMETHOD(device_detach, sio_pccard_detach), 59 60 /* Card interface */ 61 DEVMETHOD(card_compat_match, sio_pccard_match), 62 DEVMETHOD(card_compat_probe, sio_pccard_probe), 63 DEVMETHOD(card_compat_attach, sio_pccard_attach), 64 65 DEVMETHOD_END 66 }; 67 68 static driver_t sio_pccard_driver = { 69 "sio", 70 sio_pccard_methods, 71 sizeof(struct com_s), 72 }; 73 74 static int 75 sio_pccard_match(device_t dev) 76 { 77 u_int32_t fcn = PCCARD_FUNCTION_UNSPEC; 78 79 fcn = pccard_get_function(dev); 80 /* 81 * If a serial card, we are likely the right driver. However, 82 * some serial cards are better servered by other drivers, so 83 * allow other drivers to claim it, if they want. 84 */ 85 if (fcn == PCCARD_FUNCTION_SERIAL) 86 return (-100); 87 88 return(ENXIO); 89 } 90 91 static int 92 sio_pccard_probe(device_t dev) 93 { 94 /* Do not probe IRQ - pccard doesn't turn on the interrupt line */ 95 /* until bus_setup_intr */ 96 SET_FLAG(dev, COM_C_NOPROBE); 97 98 return (sioprobe(dev, 0, 0UL)); 99 } 100 101 static int 102 sio_pccard_attach(device_t dev) 103 { 104 return (sioattach(dev, 0, 0UL)); 105 } 106 107 /* 108 * sio_detach - unload the driver and clear the table. 109 * XXX TODO: 110 * This is usually called when the card is ejected, but 111 * can be caused by a modunload of a controller driver. 112 * The idea is to reset the driver's view of the device 113 * and ensure that any driver entry points such as 114 * read and write do not hang. 115 */ 116 static int 117 sio_pccard_detach(device_t dev) 118 { 119 struct com_s *com; 120 121 com = (struct com_s *) device_get_softc(dev); 122 if (com == NULL) { 123 device_printf(dev, "NULL com in siounload\n"); 124 return (0); 125 } 126 com->gone = 1; 127 if (com->irqres) { 128 bus_teardown_intr(dev, com->irqres, com->cookie); 129 bus_release_resource(dev, SYS_RES_IRQ, 0, com->irqres); 130 } 131 if (com->ioportres) 132 bus_release_resource(dev, SYS_RES_IOPORT, 0, com->ioportres); 133 if (com->tp && (com->tp->t_state & TS_ISOPEN)) { 134 device_printf(dev, "still open, forcing close\n"); 135 ttyclose(com->tp); 136 } else { 137 if (com->ibuf != NULL) 138 kfree(com->ibuf, M_DEVBUF); 139 } 140 device_printf(dev, "unloaded\n"); 141 return (0); 142 } 143 144 DRIVER_MODULE(sio, pccard, sio_pccard_driver, sio_devclass, NULL, NULL); 145