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