sio_pci.c revision 92401
1/* 2 * Copyright (c) 2001 M. Warner Losh. All rights reserved. 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, BUT 18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * 24 * $FreeBSD: head/sys/dev/sio/sio_pci.c 92401 2002-03-16 04:26:46Z imp $ 25 */ 26 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/lock.h> 33#include <sys/malloc.h> 34#include <sys/mutex.h> 35#include <sys/module.h> 36#include <sys/tty.h> 37#include <machine/bus_pio.h> 38#include <machine/bus.h> 39#include <sys/timepps.h> 40 41#include <dev/sio/siovar.h> 42 43#include <pci/pcivar.h> 44 45static int sio_pci_attach __P((device_t dev)); 46static void sio_pci_kludge_unit __P((device_t dev)); 47static int sio_pci_probe __P((device_t dev)); 48 49static device_method_t sio_pci_methods[] = { 50 /* Device interface */ 51 DEVMETHOD(device_probe, sio_pci_probe), 52 DEVMETHOD(device_attach, sio_pci_attach), 53 54 { 0, 0 } 55}; 56 57static driver_t sio_pci_driver = { 58 sio_driver_name, 59 sio_pci_methods, 60 0, 61}; 62 63struct pci_ids { 64 u_int32_t type; 65 const char *desc; 66 int rid; 67}; 68 69static struct pci_ids pci_ids[] = { 70 { 0x100812b9, "3COM PCI FaxModem", 0x10 }, 71 { 0x2000131f, "CyberSerial (1-port) 16550", 0x10 }, 72 { 0x01101407, "Koutech IOFLEX-2S PCI Dual Port Serial", 0x10 }, 73 { 0x01111407, "Koutech IOFLEX-2S PCI Dual Port Serial", 0x10 }, 74 { 0x048011c1, "Lucent kermit based PCI Modem", 0x14 }, 75 { 0x95211415, "Oxford Semiconductor PCI Dual Port Serial", 0x10 }, 76 { 0x0000151f, "SmartLink 5634PCV SurfRider", 0x10 }, 77 { 0x0103115d, "Xircom Cardbus modem", 0x10 }, 78 { 0x00000000, NULL, 0 } 79}; 80 81static int 82sio_pci_attach(dev) 83 device_t dev; 84{ 85 u_int32_t type; 86 struct pci_ids *id; 87 88 type = pci_get_devid(dev); 89 id = pci_ids; 90 while (id->type && id->type != type) 91 id++; 92 if (id->desc == NULL) 93 return (ENXIO); 94 sio_pci_kludge_unit(dev); 95 return (sioattach(dev, id->rid, 0UL)); 96} 97 98/* 99 * Don't cut and paste this to other drivers. It is a horrible kludge 100 * which will fail to work and also be unnecessary in future versions. 101 */ 102static void 103sio_pci_kludge_unit(dev) 104 device_t dev; 105{ 106 devclass_t dc; 107 int err; 108 int start; 109 int unit; 110 111 unit = 0; 112 start = 0; 113 while (resource_int_value("sio", unit, "port", &start) == 0 && 114 start > 0) 115 unit++; 116 if (device_get_unit(dev) < unit) { 117 dc = device_get_devclass(dev); 118 while (devclass_get_device(dc, unit)) 119 unit++; 120 device_printf(dev, "moving to sio%d\n", unit); 121 err = device_set_unit(dev, unit); /* EVIL DO NOT COPY */ 122 if (err) 123 device_printf(dev, "error moving device %d\n", err); 124 } 125} 126 127static int 128sio_pci_probe(dev) 129 device_t dev; 130{ 131 u_int32_t type; 132 struct pci_ids *id; 133 134 type = pci_get_devid(dev); 135 id = pci_ids; 136 while (id->type && id->type != type) 137 id++; 138 if (id->desc == NULL) 139 return (ENXIO); 140 device_set_desc(dev, id->desc); 141#ifdef PC98 142 SET_FLAG(dev, SET_IFTYPE(COM_IF_NS16550)); 143#endif 144 return (sioprobe(dev, id->rid, 0UL, 0)); 145} 146 147DRIVER_MODULE(sio, pci, sio_pci_driver, sio_devclass, 0, 0); 148DRIVER_MODULE(sio, cardbus, sio_pci_driver, sio_devclass, 0, 0); 149