1098ca2bdSWarner Losh /*- 2718cf2ccSPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3718cf2ccSPedro F. Giffuni * 4f86e6000SWarner Losh * Copyright (c) 2006 Marcel Moolenaar All rights reserved. 5f86e6000SWarner Losh * Copyright (c) 2001 M. Warner Losh <imp@FreeBSD.org> 627d5dc18SMarcel Moolenaar * 727d5dc18SMarcel Moolenaar * Redistribution and use in source and binary forms, with or without 827d5dc18SMarcel Moolenaar * modification, are permitted provided that the following conditions 927d5dc18SMarcel Moolenaar * are met: 1027d5dc18SMarcel Moolenaar * 1. Redistributions of source code must retain the above copyright 1127d5dc18SMarcel Moolenaar * notice, this list of conditions and the following disclaimer. 1227d5dc18SMarcel Moolenaar * 2. Redistributions in binary form must reproduce the above copyright 1327d5dc18SMarcel Moolenaar * notice, this list of conditions and the following disclaimer in the 1427d5dc18SMarcel Moolenaar * documentation and/or other materials provided with the distribution. 1527d5dc18SMarcel Moolenaar * 1627d5dc18SMarcel Moolenaar * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1727d5dc18SMarcel Moolenaar * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1827d5dc18SMarcel Moolenaar * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1927d5dc18SMarcel Moolenaar * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2027d5dc18SMarcel Moolenaar * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2127d5dc18SMarcel Moolenaar * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2227d5dc18SMarcel Moolenaar * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2327d5dc18SMarcel Moolenaar * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2427d5dc18SMarcel Moolenaar * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2527d5dc18SMarcel Moolenaar * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2627d5dc18SMarcel Moolenaar */ 2727d5dc18SMarcel Moolenaar 2827d5dc18SMarcel Moolenaar #include <sys/cdefs.h> 2927d5dc18SMarcel Moolenaar __FBSDID("$FreeBSD$"); 3027d5dc18SMarcel Moolenaar 3127d5dc18SMarcel Moolenaar #include <sys/param.h> 3227d5dc18SMarcel Moolenaar #include <sys/systm.h> 3327d5dc18SMarcel Moolenaar #include <sys/bus.h> 3427d5dc18SMarcel Moolenaar #include <sys/conf.h> 3527d5dc18SMarcel Moolenaar #include <sys/kernel.h> 3627d5dc18SMarcel Moolenaar #include <sys/module.h> 3727d5dc18SMarcel Moolenaar #include <machine/bus.h> 3827d5dc18SMarcel Moolenaar #include <sys/rman.h> 3927d5dc18SMarcel Moolenaar #include <machine/resource.h> 4027d5dc18SMarcel Moolenaar 4127d5dc18SMarcel Moolenaar #include <dev/pci/pcivar.h> 429eb5fd35SWarner Losh #include <dev/pci/pcireg.h> 4327d5dc18SMarcel Moolenaar 4427d5dc18SMarcel Moolenaar #include <dev/uart/uart.h> 4527d5dc18SMarcel Moolenaar #include <dev/uart/uart_bus.h> 46ad93649dSColin Percival #include <dev/uart/uart_cpu.h> 4727d5dc18SMarcel Moolenaar 4824f9da03SMarcel Moolenaar #define DEFAULT_RCLK 1843200 4924f9da03SMarcel Moolenaar 5027d5dc18SMarcel Moolenaar static int uart_pci_probe(device_t dev); 51fb1d9b7fSBruce M Simpson static int uart_pci_attach(device_t dev); 52fb1d9b7fSBruce M Simpson static int uart_pci_detach(device_t dev); 5327d5dc18SMarcel Moolenaar 5427d5dc18SMarcel Moolenaar static device_method_t uart_pci_methods[] = { 5527d5dc18SMarcel Moolenaar /* Device interface */ 5627d5dc18SMarcel Moolenaar DEVMETHOD(device_probe, uart_pci_probe), 57fb1d9b7fSBruce M Simpson DEVMETHOD(device_attach, uart_pci_attach), 58fb1d9b7fSBruce M Simpson DEVMETHOD(device_detach, uart_pci_detach), 595b23b1b9SAndriy Gapon DEVMETHOD(device_resume, uart_bus_resume), 60dec28016SMarius Strobl DEVMETHOD_END 6127d5dc18SMarcel Moolenaar }; 6227d5dc18SMarcel Moolenaar 6327d5dc18SMarcel Moolenaar static driver_t uart_pci_driver = { 6427d5dc18SMarcel Moolenaar uart_driver_name, 6527d5dc18SMarcel Moolenaar uart_pci_methods, 6627d5dc18SMarcel Moolenaar sizeof(struct uart_softc), 6727d5dc18SMarcel Moolenaar }; 6827d5dc18SMarcel Moolenaar 6927d5dc18SMarcel Moolenaar struct pci_id { 7024f9da03SMarcel Moolenaar uint16_t vendor; 7124f9da03SMarcel Moolenaar uint16_t device; 7224f9da03SMarcel Moolenaar uint16_t subven; 7324f9da03SMarcel Moolenaar uint16_t subdev; 7427d5dc18SMarcel Moolenaar const char *desc; 7527d5dc18SMarcel Moolenaar int rid; 7624f9da03SMarcel Moolenaar int rclk; 779308005eSMarcel Moolenaar int regshft; 7827d5dc18SMarcel Moolenaar }; 7927d5dc18SMarcel Moolenaar 80ad93649dSColin Percival struct pci_unique_id { 81ad93649dSColin Percival uint16_t vendor; 82ad93649dSColin Percival uint16_t device; 83ad93649dSColin Percival }; 84ad93649dSColin Percival 85bf400807SWarner Losh #define PCI_NO_MSI 0x40000000 86bf400807SWarner Losh #define PCI_RID_MASK 0x0000ffff 87bf400807SWarner Losh 88dec28016SMarius Strobl static const struct pci_id pci_ns8250_ids[] = { 89ab2b8832SMarcel Moolenaar { 0x1028, 0x0008, 0xffff, 0, "Dell Remote Access Card III", 0x14, 90ab2b8832SMarcel Moolenaar 128 * DEFAULT_RCLK }, 91ab2b8832SMarcel Moolenaar { 0x1028, 0x0012, 0xffff, 0, "Dell RAC 4 Daughter Card Virtual UART", 0x14, 92ab2b8832SMarcel Moolenaar 128 * DEFAULT_RCLK }, 9324f9da03SMarcel Moolenaar { 0x1033, 0x0074, 0x1033, 0x8014, "NEC RCV56ACF 56k Voice Modem", 0x10 }, 9424f9da03SMarcel Moolenaar { 0x1033, 0x007d, 0x1033, 0x8012, "NEC RS232C", 0x10 }, 95ab2b8832SMarcel Moolenaar { 0x103c, 0x1048, 0x103c, 0x1227, "HP Diva Serial [GSP] UART - Powerbar SP2", 96ab2b8832SMarcel Moolenaar 0x10 }, 977db977fbSMarcel Moolenaar { 0x103c, 0x1048, 0x103c, 0x1301, "HP Diva RMP3", 0x14 }, 98ab2b8832SMarcel Moolenaar { 0x103c, 0x1290, 0xffff, 0, "HP Auxiliary Diva Serial Port", 0x18 }, 99b1a64a96SMarcel Moolenaar { 0x103c, 0x3301, 0xffff, 0, "HP iLO serial port", 0x10 }, 10024f9da03SMarcel Moolenaar { 0x11c1, 0x0480, 0xffff, 0, "Agere Systems Venus Modem (V90, 56KFlex)", 0x14 }, 10124f9da03SMarcel Moolenaar { 0x115d, 0x0103, 0xffff, 0, "Xircom Cardbus Ethernet + 56k Modem", 0x10 }, 102059178b6SEd Maste { 0x125b, 0x9100, 0xa000, 0x1000, 103059178b6SEd Maste "ASIX AX99100 PCIe 1/2/3/4-port RS-232/422/485", 0x10 }, 1042f8c04adSJohn Baldwin { 0x1282, 0x6585, 0xffff, 0, "Davicom 56PDV PCI Modem", 0x10 }, 10524f9da03SMarcel Moolenaar { 0x12b9, 0x1008, 0xffff, 0, "3Com 56K FaxModem Model 5610", 0x10 }, 10624f9da03SMarcel Moolenaar { 0x131f, 0x1000, 0xffff, 0, "Siig CyberSerial (1-port) 16550", 0x18 }, 10724f9da03SMarcel Moolenaar { 0x131f, 0x1001, 0xffff, 0, "Siig CyberSerial (1-port) 16650", 0x18 }, 10824f9da03SMarcel Moolenaar { 0x131f, 0x1002, 0xffff, 0, "Siig CyberSerial (1-port) 16850", 0x18 }, 10924f9da03SMarcel Moolenaar { 0x131f, 0x2000, 0xffff, 0, "Siig CyberSerial (1-port) 16550", 0x10 }, 11024f9da03SMarcel Moolenaar { 0x131f, 0x2001, 0xffff, 0, "Siig CyberSerial (1-port) 16650", 0x10 }, 11124f9da03SMarcel Moolenaar { 0x131f, 0x2002, 0xffff, 0, "Siig CyberSerial (1-port) 16850", 0x10 }, 11224f9da03SMarcel Moolenaar { 0x135c, 0x0190, 0xffff, 0, "Quatech SSCLP-100", 0x18 }, 11324f9da03SMarcel Moolenaar { 0x135c, 0x01c0, 0xffff, 0, "Quatech SSCLP-200/300", 0x18 }, 114ab2b8832SMarcel Moolenaar { 0x135e, 0x7101, 0xffff, 0, "Sealevel Systems Single Port RS-232/422/485/530", 115ab2b8832SMarcel Moolenaar 0x18 }, 11624f9da03SMarcel Moolenaar { 0x1407, 0x0110, 0xffff, 0, "Lava Computer mfg DSerial-PCI Port A", 0x10 }, 11724f9da03SMarcel Moolenaar { 0x1407, 0x0111, 0xffff, 0, "Lava Computer mfg DSerial-PCI Port B", 0x10 }, 11864fc5491SKai Wang { 0x1407, 0x0510, 0xffff, 0, "Lava SP Serial 550 PCI", 0x10 }, 119ab2b8832SMarcel Moolenaar { 0x1409, 0x7168, 0x1409, 0x4025, "Timedia Technology Serial Port", 0x10, 120ab2b8832SMarcel Moolenaar 8 * DEFAULT_RCLK }, 121ab2b8832SMarcel Moolenaar { 0x1409, 0x7168, 0x1409, 0x4027, "Timedia Technology Serial Port", 0x10, 122ab2b8832SMarcel Moolenaar 8 * DEFAULT_RCLK }, 123ab2b8832SMarcel Moolenaar { 0x1409, 0x7168, 0x1409, 0x4028, "Timedia Technology Serial Port", 0x10, 124ab2b8832SMarcel Moolenaar 8 * DEFAULT_RCLK }, 125ab2b8832SMarcel Moolenaar { 0x1409, 0x7168, 0x1409, 0x5025, "Timedia Technology Serial Port", 0x10, 126ab2b8832SMarcel Moolenaar 8 * DEFAULT_RCLK }, 127ab2b8832SMarcel Moolenaar { 0x1409, 0x7168, 0x1409, 0x5027, "Timedia Technology Serial Port", 0x10, 128ab2b8832SMarcel Moolenaar 8 * DEFAULT_RCLK }, 129ab2b8832SMarcel Moolenaar { 0x1415, 0x950b, 0xffff, 0, "Oxford Semiconductor OXCB950 Cardbus 16950 UART", 130ab2b8832SMarcel Moolenaar 0x10, 16384000 }, 1317e47312cSPeter Grehan { 0x1415, 0xc120, 0xffff, 0, "Oxford Semiconductor OXPCIe952 PCIe 16950 UART", 1327e47312cSPeter Grehan 0x10 }, 1337bd6f3d0SMarcel Moolenaar { 0x14e4, 0x160a, 0xffff, 0, "Broadcom TruManage UART", 0x10, 1347bd6f3d0SMarcel Moolenaar 128 * DEFAULT_RCLK, 2}, 135383227f1SEitan Adler { 0x14e4, 0x4344, 0xffff, 0, "Sony Ericsson GC89 PC Card", 0x10}, 136ab2b8832SMarcel Moolenaar { 0x151f, 0x0000, 0xffff, 0, "TOPIC Semiconductor TP560 56k modem", 0x10 }, 1371bfa40d2SColin Percival { 0x1d0f, 0x8250, 0x0000, 0, "Amazon PCI serial device", 0x10 }, 138189bd7a9SColin Percival { 0x1d0f, 0x8250, 0x1d0f, 0, "Amazon PCI serial device", 0x10 }, 13950c0e894SMarius Strobl { 0x1fd4, 0x1999, 0x1fd4, 0x0001, "Sunix SER5xxxx Serial Port", 0x10, 14050c0e894SMarius Strobl 8 * DEFAULT_RCLK }, 1419308005eSMarcel Moolenaar { 0x8086, 0x0f0a, 0xffff, 0, "Intel ValleyView LPIO1 HSUART#1", 0x10, 1429308005eSMarcel Moolenaar 24 * DEFAULT_RCLK, 2 }, 1439308005eSMarcel Moolenaar { 0x8086, 0x0f0c, 0xffff, 0, "Intel ValleyView LPIO1 HSUART#2", 0x10, 1449308005eSMarcel Moolenaar 24 * DEFAULT_RCLK, 2 }, 145ef7161e7SEd Maste { 0x8086, 0x108f, 0xffff, 0, "Intel AMT - SOL", 0x10 }, 146f37cc713SJustin Hibbits { 0x8086, 0x19d8, 0xffff, 0, "Intel Denverton UART", 0x10 }, 14784f94128SKonstantin Belousov { 0x8086, 0x1c3d, 0xffff, 0, "Intel AMT - KT Controller", 0x10 }, 1485b8b6b26SJose Luis Duran { 0x8086, 0x1d3d, 0xffff, 0, "Intel C600/X79 Series Chipset KT Controller", 1495b8b6b26SJose Luis Duran 0x10 }, 1500a5c75e5SAlexander Motin { 0x8086, 0x1e3d, 0xffff, 0, "Intel Panther Point KT Controller", 0x10 }, 151cb3c7e7fSSean Bruno { 0x8086, 0x228a, 0xffff, 0, "Intel Cherryview SIO HSUART#1", 0x10, 152cb3c7e7fSSean Bruno 24 * DEFAULT_RCLK, 2 }, 153cb3c7e7fSSean Bruno { 0x8086, 0x228c, 0xffff, 0, "Intel Cherryview SIO HSUART#2", 0x10, 154cb3c7e7fSSean Bruno 24 * DEFAULT_RCLK, 2 }, 155aa475e14SSean Bruno { 0x8086, 0x2a07, 0xffff, 0, "Intel AMT - PM965/GM965 KT Controller", 0x10 }, 156a1d18b66SJohn Baldwin { 0x8086, 0x2a47, 0xffff, 0, "Mobile 4 Series Chipset KT Controller", 0x10 }, 15777b5f5c8SKonstantin Belousov { 0x8086, 0x2e17, 0xffff, 0, "4 Series Chipset Serial KT Controller", 0x10 }, 158eaf00819SKonstantin Belousov { 0x8086, 0x31bc, 0xffff, 0, "Intel Gemini Lake SIO/LPSS UART 0", 0x10, 159eaf00819SKonstantin Belousov 24 * DEFAULT_RCLK, 2 }, 160eaf00819SKonstantin Belousov { 0x8086, 0x31be, 0xffff, 0, "Intel Gemini Lake SIO/LPSS UART 1", 0x10, 161eaf00819SKonstantin Belousov 24 * DEFAULT_RCLK, 2 }, 162eaf00819SKonstantin Belousov { 0x8086, 0x31c0, 0xffff, 0, "Intel Gemini Lake SIO/LPSS UART 2", 0x10, 163eaf00819SKonstantin Belousov 24 * DEFAULT_RCLK, 2 }, 164eaf00819SKonstantin Belousov { 0x8086, 0x31ee, 0xffff, 0, "Intel Gemini Lake SIO/LPSS UART 3", 0x10, 165eaf00819SKonstantin Belousov 24 * DEFAULT_RCLK, 2 }, 166f5793e6fSKonstantin Belousov { 0x8086, 0x3b67, 0xffff, 0, "5 Series/3400 Series Chipset KT Controller", 167f5793e6fSKonstantin Belousov 0x10 }, 1688f156243SJose Luis Duran { 0x8086, 0x5abc, 0xffff, 0, "Intel Apollo Lake SIO/LPSS UART 0", 0x10, 1698f156243SJose Luis Duran 24 * DEFAULT_RCLK, 2 }, 1708f156243SJose Luis Duran { 0x8086, 0x5abe, 0xffff, 0, "Intel Apollo Lake SIO/LPSS UART 1", 0x10, 1718f156243SJose Luis Duran 24 * DEFAULT_RCLK, 2 }, 1728f156243SJose Luis Duran { 0x8086, 0x5ac0, 0xffff, 0, "Intel Apollo Lake SIO/LPSS UART 2", 0x10, 1738f156243SJose Luis Duran 24 * DEFAULT_RCLK, 2 }, 1748f156243SJose Luis Duran { 0x8086, 0x5aee, 0xffff, 0, "Intel Apollo Lake SIO/LPSS UART 3", 0x10, 1758f156243SJose Luis Duran 24 * DEFAULT_RCLK, 2 }, 1761a74905fSKevin Lo { 0x8086, 0x8811, 0xffff, 0, "Intel EG20T Serial Port 0", 0x10 }, 1771a74905fSKevin Lo { 0x8086, 0x8812, 0xffff, 0, "Intel EG20T Serial Port 1", 0x10 }, 1781a74905fSKevin Lo { 0x8086, 0x8813, 0xffff, 0, "Intel EG20T Serial Port 2", 0x10 }, 1791a74905fSKevin Lo { 0x8086, 0x8814, 0xffff, 0, "Intel EG20T Serial Port 3", 0x10 }, 180f478527dSSean Bruno { 0x8086, 0x8c3d, 0xffff, 0, "Intel Lynx Point KT Controller", 0x10 }, 181e67f3becSAlexander Motin { 0x8086, 0x8cbd, 0xffff, 0, "Intel Wildcat Point KT Controller", 0x10 }, 1824abd2509SSean Bruno { 0x8086, 0x9c3d, 0xffff, 0, "Intel Lynx Point-LP HECI KT", 0x10 }, 183fb640be4SSean Bruno { 0x8086, 0xa13d, 0xffff, 0, 184bf400807SWarner Losh "100 Series/C230 Series Chipset Family KT Redirection", 185bf400807SWarner Losh 0x10 | PCI_NO_MSI }, 1867b4386c6SAlexander Motin { 0x9710, 0x9820, 0x1000, 1, "NetMos NM9820 Serial Port", 0x10 }, 187843994aeSJohn Baldwin { 0x9710, 0x9835, 0x1000, 1, "NetMos NM9835 Serial Port", 0x10 }, 1881d864e0dSMarcel Moolenaar { 0x9710, 0x9865, 0xa000, 0x1000, "NetMos NM9865 Serial Port", 0x10 }, 18924f4fe9aSHans Petter Selasky { 0x9710, 0x9900, 0xa000, 0x1000, 19024f4fe9aSHans Petter Selasky "MosChip MCS9900 PCIe to Peripheral Controller", 0x10 }, 191506b3c39SXin LI { 0x9710, 0x9901, 0xa000, 0x1000, 192506b3c39SXin LI "MosChip MCS9901 PCIe to Peripheral Controller", 0x10 }, 193c8e72d0cSRemko Lodder { 0x9710, 0x9904, 0xa000, 0x1000, 194c8e72d0cSRemko Lodder "MosChip MCS9904 PCIe to Peripheral Controller", 0x10 }, 19539367742SMarius Strobl { 0x9710, 0x9922, 0xa000, 0x1000, 19639367742SMarius Strobl "MosChip MCS9922 PCIe to Peripheral Controller", 0x10 }, 19724f9da03SMarcel Moolenaar { 0xdeaf, 0x9051, 0xffff, 0, "Middle Digital PC Weasel Serial Port", 0x10 }, 19824f9da03SMarcel Moolenaar { 0xffff, 0, 0xffff, 0, NULL, 0, 0} 19927d5dc18SMarcel Moolenaar }; 20027d5dc18SMarcel Moolenaar 201dec28016SMarius Strobl const static struct pci_id * 202dec28016SMarius Strobl uart_pci_match(device_t dev, const struct pci_id *id) 20327d5dc18SMarcel Moolenaar { 20424f9da03SMarcel Moolenaar uint16_t device, subdev, subven, vendor; 20527d5dc18SMarcel Moolenaar 20624f9da03SMarcel Moolenaar vendor = pci_get_vendor(dev); 20724f9da03SMarcel Moolenaar device = pci_get_device(dev); 20824f9da03SMarcel Moolenaar while (id->vendor != 0xffff && 20924f9da03SMarcel Moolenaar (id->vendor != vendor || id->device != device)) 21027d5dc18SMarcel Moolenaar id++; 21124f9da03SMarcel Moolenaar if (id->vendor == 0xffff) 21224f9da03SMarcel Moolenaar return (NULL); 21324f9da03SMarcel Moolenaar if (id->subven == 0xffff) 21424f9da03SMarcel Moolenaar return (id); 21524f9da03SMarcel Moolenaar subven = pci_get_subvendor(dev); 21624f9da03SMarcel Moolenaar subdev = pci_get_subdevice(dev); 21724f9da03SMarcel Moolenaar while (id->vendor == vendor && id->device == device && 21824f9da03SMarcel Moolenaar (id->subven != subven || id->subdev != subdev)) 21924f9da03SMarcel Moolenaar id++; 22024f9da03SMarcel Moolenaar return ((id->vendor == vendor && id->device == device) ? id : NULL); 22127d5dc18SMarcel Moolenaar } 22227d5dc18SMarcel Moolenaar 223ad93649dSColin Percival extern SLIST_HEAD(uart_devinfo_list, uart_devinfo) uart_sysdevs; 224ad93649dSColin Percival 225ad93649dSColin Percival /* PCI vendor/device pairs of devices guaranteed to be unique on a system. */ 226ad93649dSColin Percival static const struct pci_unique_id pci_unique_devices[] = { 227ad93649dSColin Percival { 0x1d0f, 0x8250 } /* Amazon PCI serial device */ 228ad93649dSColin Percival }; 229ad93649dSColin Percival 230ad93649dSColin Percival /* Match a UART to a console if it's a PCI device known to be unique. */ 231ad93649dSColin Percival static void 232ad93649dSColin Percival uart_pci_unique_console_match(device_t dev) 233ad93649dSColin Percival { 234ad93649dSColin Percival struct uart_softc *sc; 235ad93649dSColin Percival struct uart_devinfo * sysdev; 236ad93649dSColin Percival const struct pci_unique_id * id; 237ad93649dSColin Percival uint16_t vendor, device; 238ad93649dSColin Percival 239ad93649dSColin Percival sc = device_get_softc(dev); 240ad93649dSColin Percival vendor = pci_get_vendor(dev); 241ad93649dSColin Percival device = pci_get_device(dev); 242ad93649dSColin Percival 243ad93649dSColin Percival /* Is this a device known to exist only once in a system? */ 244ad93649dSColin Percival for (id = pci_unique_devices; ; id++) { 245ad93649dSColin Percival if (id == &pci_unique_devices[nitems(pci_unique_devices)]) 246ad93649dSColin Percival return; 247ad93649dSColin Percival if (id->vendor == vendor && id->device == device) 248ad93649dSColin Percival break; 249ad93649dSColin Percival } 250ad93649dSColin Percival 251ad93649dSColin Percival /* If it matches a console, it must be the same device. */ 252ad93649dSColin Percival SLIST_FOREACH(sysdev, &uart_sysdevs, next) { 253ad93649dSColin Percival if (sysdev->pci_info.vendor == vendor && 254ad93649dSColin Percival sysdev->pci_info.device == device) { 255ad93649dSColin Percival sc->sc_sysdev = sysdev; 256ad93649dSColin Percival sysdev->bas.rclk = sc->sc_bas.rclk; 257ad93649dSColin Percival } 258ad93649dSColin Percival } 259ad93649dSColin Percival } 260ad93649dSColin Percival 26127d5dc18SMarcel Moolenaar static int 26227d5dc18SMarcel Moolenaar uart_pci_probe(device_t dev) 26327d5dc18SMarcel Moolenaar { 26427d5dc18SMarcel Moolenaar struct uart_softc *sc; 265dec28016SMarius Strobl const struct pci_id *id; 2669eb5fd35SWarner Losh struct pci_id cid = { 2679eb5fd35SWarner Losh .regshft = 0, 2689eb5fd35SWarner Losh .rclk = 0, 2699eb5fd35SWarner Losh .rid = 0x10 | PCI_NO_MSI, 2709eb5fd35SWarner Losh .desc = "Generic SimpleComm PCI device", 2719eb5fd35SWarner Losh }; 272a177309fSMarcel Moolenaar int result; 27327d5dc18SMarcel Moolenaar 27427d5dc18SMarcel Moolenaar sc = device_get_softc(dev); 27527d5dc18SMarcel Moolenaar 27624f9da03SMarcel Moolenaar id = uart_pci_match(dev, pci_ns8250_ids); 27727d5dc18SMarcel Moolenaar if (id != NULL) { 27827d5dc18SMarcel Moolenaar sc->sc_class = &uart_ns8250_class; 27927d5dc18SMarcel Moolenaar goto match; 28027d5dc18SMarcel Moolenaar } 2819eb5fd35SWarner Losh if (pci_get_class(dev) == PCIC_SIMPLECOMM && 2829eb5fd35SWarner Losh pci_get_subclass(dev) == PCIS_SIMPLECOMM_UART && 2839eb5fd35SWarner Losh pci_get_progif(dev) < PCIP_SIMPLECOMM_UART_16550A) { 2849eb5fd35SWarner Losh /* XXX rclk what to do */ 2859eb5fd35SWarner Losh id = &cid; 2869eb5fd35SWarner Losh sc->sc_class = &uart_ns8250_class; 2879eb5fd35SWarner Losh goto match; 2889eb5fd35SWarner Losh } 28927d5dc18SMarcel Moolenaar /* Add checks for non-ns8250 IDs here. */ 29027d5dc18SMarcel Moolenaar return (ENXIO); 29127d5dc18SMarcel Moolenaar 29227d5dc18SMarcel Moolenaar match: 293bf400807SWarner Losh result = uart_bus_probe(dev, id->regshft, 0, id->rclk, 294bf400807SWarner Losh id->rid & PCI_RID_MASK, 0, 0); 295a177309fSMarcel Moolenaar /* Bail out on error. */ 296a177309fSMarcel Moolenaar if (result > 0) 297a177309fSMarcel Moolenaar return (result); 298ad93649dSColin Percival /* 299ad93649dSColin Percival * If we haven't already matched this to a console, check if it's a 300ad93649dSColin Percival * PCI device which is known to only exist once in any given system 301ad93649dSColin Percival * and we can match it that way. 302ad93649dSColin Percival */ 303ad93649dSColin Percival if (sc->sc_sysdev == NULL) 304ad93649dSColin Percival uart_pci_unique_console_match(dev); 305a177309fSMarcel Moolenaar /* Set/override the device description. */ 30627d5dc18SMarcel Moolenaar if (id->desc) 30727d5dc18SMarcel Moolenaar device_set_desc(dev, id->desc); 308a177309fSMarcel Moolenaar return (result); 30927d5dc18SMarcel Moolenaar } 31027d5dc18SMarcel Moolenaar 311fb1d9b7fSBruce M Simpson static int 312fb1d9b7fSBruce M Simpson uart_pci_attach(device_t dev) 313fb1d9b7fSBruce M Simpson { 314fb1d9b7fSBruce M Simpson struct uart_softc *sc; 315bf400807SWarner Losh const struct pci_id *id; 316fb1d9b7fSBruce M Simpson int count; 317fb1d9b7fSBruce M Simpson 318fb1d9b7fSBruce M Simpson sc = device_get_softc(dev); 319fb1d9b7fSBruce M Simpson 320fb1d9b7fSBruce M Simpson /* 321955b6109SWarner Losh * Use MSI in preference to legacy IRQ if available. However, experience 322955b6109SWarner Losh * suggests this is only reliable when one MSI vector is advertised. 323fb1d9b7fSBruce M Simpson */ 324bf400807SWarner Losh id = uart_pci_match(dev, pci_ns8250_ids); 325bf400807SWarner Losh if ((id == NULL || (id->rid & PCI_NO_MSI) == 0) && 326bf400807SWarner Losh pci_msi_count(dev) == 1) { 327fb1d9b7fSBruce M Simpson count = 1; 328fb1d9b7fSBruce M Simpson if (pci_alloc_msi(dev, &count) == 0) { 329fb1d9b7fSBruce M Simpson sc->sc_irid = 1; 330fb1d9b7fSBruce M Simpson device_printf(dev, "Using %d MSI message\n", count); 331fb1d9b7fSBruce M Simpson } 332fb1d9b7fSBruce M Simpson } 333fb1d9b7fSBruce M Simpson 334fb1d9b7fSBruce M Simpson return (uart_bus_attach(dev)); 335fb1d9b7fSBruce M Simpson } 336fb1d9b7fSBruce M Simpson 337fb1d9b7fSBruce M Simpson static int 338fb1d9b7fSBruce M Simpson uart_pci_detach(device_t dev) 339fb1d9b7fSBruce M Simpson { 340fb1d9b7fSBruce M Simpson struct uart_softc *sc; 341fb1d9b7fSBruce M Simpson 342fb1d9b7fSBruce M Simpson sc = device_get_softc(dev); 343fb1d9b7fSBruce M Simpson 344fb1d9b7fSBruce M Simpson if (sc->sc_irid != 0) 345fb1d9b7fSBruce M Simpson pci_release_msi(dev); 346fb1d9b7fSBruce M Simpson 347fb1d9b7fSBruce M Simpson return (uart_bus_detach(dev)); 348fb1d9b7fSBruce M Simpson } 349fb1d9b7fSBruce M Simpson 350*c90ea831SJohn Baldwin DRIVER_MODULE(uart, pci, uart_pci_driver, NULL, NULL); 351