uart_bus_pci.c revision 287747
1139749Simp/*- 2158078Smarcel * Copyright (c) 2006 Marcel Moolenaar 3158078Smarcel * Copyright (c) 2001 M. Warner Losh 4158078Smarcel * All rights reserved. 5119815Smarcel * 6119815Smarcel * Redistribution and use in source and binary forms, with or without 7119815Smarcel * modification, are permitted provided that the following conditions 8119815Smarcel * are met: 9119815Smarcel * 1. Redistributions of source code must retain the above copyright 10119815Smarcel * notice, this list of conditions and the following disclaimer. 11119815Smarcel * 2. Redistributions in binary form must reproduce the above copyright 12119815Smarcel * notice, this list of conditions and the following disclaimer in the 13119815Smarcel * documentation and/or other materials provided with the distribution. 14119815Smarcel * 15119815Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16119815Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17119815Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18119815Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19119815Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20119815Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21119815Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22119815Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23119815Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24119815Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25119815Smarcel */ 26119815Smarcel 27119815Smarcel#include <sys/cdefs.h> 28119815Smarcel__FBSDID("$FreeBSD: head/sys/dev/uart/uart_bus_pci.c 287747 2015-09-13 12:08:25Z mav $"); 29119815Smarcel 30119815Smarcel#include <sys/param.h> 31119815Smarcel#include <sys/systm.h> 32119815Smarcel#include <sys/bus.h> 33119815Smarcel#include <sys/conf.h> 34119815Smarcel#include <sys/kernel.h> 35119815Smarcel#include <sys/module.h> 36119815Smarcel#include <machine/bus.h> 37119815Smarcel#include <sys/rman.h> 38119815Smarcel#include <machine/resource.h> 39119815Smarcel 40119815Smarcel#include <dev/pci/pcivar.h> 41119815Smarcel 42119815Smarcel#include <dev/uart/uart.h> 43119815Smarcel#include <dev/uart/uart_bus.h> 44119815Smarcel 45158058Smarcel#define DEFAULT_RCLK 1843200 46158058Smarcel 47119815Smarcelstatic int uart_pci_probe(device_t dev); 48119815Smarcel 49119815Smarcelstatic device_method_t uart_pci_methods[] = { 50119815Smarcel /* Device interface */ 51119815Smarcel DEVMETHOD(device_probe, uart_pci_probe), 52119815Smarcel DEVMETHOD(device_attach, uart_bus_attach), 53119815Smarcel DEVMETHOD(device_detach, uart_bus_detach), 54246243Savg DEVMETHOD(device_resume, uart_bus_resume), 55246300Smarius DEVMETHOD_END 56119815Smarcel}; 57119815Smarcel 58119815Smarcelstatic driver_t uart_pci_driver = { 59119815Smarcel uart_driver_name, 60119815Smarcel uart_pci_methods, 61119815Smarcel sizeof(struct uart_softc), 62119815Smarcel}; 63119815Smarcel 64119815Smarcelstruct pci_id { 65158058Smarcel uint16_t vendor; 66158058Smarcel uint16_t device; 67158058Smarcel uint16_t subven; 68158058Smarcel uint16_t subdev; 69119815Smarcel const char *desc; 70119815Smarcel int rid; 71158058Smarcel int rclk; 72284623Smarcel int regshft; 73119815Smarcel}; 74119815Smarcel 75246300Smariusstatic const struct pci_id pci_ns8250_ids[] = { 76158078Smarcel{ 0x1028, 0x0008, 0xffff, 0, "Dell Remote Access Card III", 0x14, 77158078Smarcel 128 * DEFAULT_RCLK }, 78158078Smarcel{ 0x1028, 0x0012, 0xffff, 0, "Dell RAC 4 Daughter Card Virtual UART", 0x14, 79158078Smarcel 128 * DEFAULT_RCLK }, 80158058Smarcel{ 0x1033, 0x0074, 0x1033, 0x8014, "NEC RCV56ACF 56k Voice Modem", 0x10 }, 81158058Smarcel{ 0x1033, 0x007d, 0x1033, 0x8012, "NEC RS232C", 0x10 }, 82158078Smarcel{ 0x103c, 0x1048, 0x103c, 0x1227, "HP Diva Serial [GSP] UART - Powerbar SP2", 83158078Smarcel 0x10 }, 84169646Smarcel{ 0x103c, 0x1048, 0x103c, 0x1301, "HP Diva RMP3", 0x14 }, 85158078Smarcel{ 0x103c, 0x1290, 0xffff, 0, "HP Auxiliary Diva Serial Port", 0x18 }, 86259838Smarcel{ 0x103c, 0x3301, 0xffff, 0, "HP iLO serial port", 0x10 }, 87158058Smarcel{ 0x11c1, 0x0480, 0xffff, 0, "Agere Systems Venus Modem (V90, 56KFlex)", 0x14 }, 88158058Smarcel{ 0x115d, 0x0103, 0xffff, 0, "Xircom Cardbus Ethernet + 56k Modem", 0x10 }, 89223874Sjhb{ 0x1282, 0x6585, 0xffff, 0, "Davicom 56PDV PCI Modem", 0x10 }, 90158058Smarcel{ 0x12b9, 0x1008, 0xffff, 0, "3Com 56K FaxModem Model 5610", 0x10 }, 91158058Smarcel{ 0x131f, 0x1000, 0xffff, 0, "Siig CyberSerial (1-port) 16550", 0x18 }, 92158058Smarcel{ 0x131f, 0x1001, 0xffff, 0, "Siig CyberSerial (1-port) 16650", 0x18 }, 93158058Smarcel{ 0x131f, 0x1002, 0xffff, 0, "Siig CyberSerial (1-port) 16850", 0x18 }, 94158058Smarcel{ 0x131f, 0x2000, 0xffff, 0, "Siig CyberSerial (1-port) 16550", 0x10 }, 95158058Smarcel{ 0x131f, 0x2001, 0xffff, 0, "Siig CyberSerial (1-port) 16650", 0x10 }, 96158058Smarcel{ 0x131f, 0x2002, 0xffff, 0, "Siig CyberSerial (1-port) 16850", 0x10 }, 97158058Smarcel{ 0x135c, 0x0190, 0xffff, 0, "Quatech SSCLP-100", 0x18 }, 98158058Smarcel{ 0x135c, 0x01c0, 0xffff, 0, "Quatech SSCLP-200/300", 0x18 }, 99158078Smarcel{ 0x135e, 0x7101, 0xffff, 0, "Sealevel Systems Single Port RS-232/422/485/530", 100158078Smarcel 0x18 }, 101158058Smarcel{ 0x1407, 0x0110, 0xffff, 0, "Lava Computer mfg DSerial-PCI Port A", 0x10 }, 102158058Smarcel{ 0x1407, 0x0111, 0xffff, 0, "Lava Computer mfg DSerial-PCI Port B", 0x10 }, 103188472Skaiw{ 0x1407, 0x0510, 0xffff, 0, "Lava SP Serial 550 PCI", 0x10 }, 104158078Smarcel{ 0x1409, 0x7168, 0x1409, 0x4025, "Timedia Technology Serial Port", 0x10, 105158078Smarcel 8 * DEFAULT_RCLK }, 106158078Smarcel{ 0x1409, 0x7168, 0x1409, 0x4027, "Timedia Technology Serial Port", 0x10, 107158078Smarcel 8 * DEFAULT_RCLK }, 108158078Smarcel{ 0x1409, 0x7168, 0x1409, 0x4028, "Timedia Technology Serial Port", 0x10, 109158078Smarcel 8 * DEFAULT_RCLK }, 110158078Smarcel{ 0x1409, 0x7168, 0x1409, 0x5025, "Timedia Technology Serial Port", 0x10, 111158078Smarcel 8 * DEFAULT_RCLK }, 112158078Smarcel{ 0x1409, 0x7168, 0x1409, 0x5027, "Timedia Technology Serial Port", 0x10, 113158078Smarcel 8 * DEFAULT_RCLK }, 114158078Smarcel{ 0x1415, 0x950b, 0xffff, 0, "Oxford Semiconductor OXCB950 Cardbus 16950 UART", 115158078Smarcel 0x10, 16384000 }, 116277043Sgrehan{ 0x1415, 0xc120, 0xffff, 0, "Oxford Semiconductor OXPCIe952 PCIe 16950 UART", 117277043Sgrehan 0x10 }, 118286668Smarcel{ 0x14e4, 0x160a, 0xffff, 0, "Broadcom TruManage UART", 0x10, 119286668Smarcel 128 * DEFAULT_RCLK, 2}, 120230327Seadler{ 0x14e4, 0x4344, 0xffff, 0, "Sony Ericsson GC89 PC Card", 0x10}, 121158078Smarcel{ 0x151f, 0x0000, 0xffff, 0, "TOPIC Semiconductor TP560 56k modem", 0x10 }, 122264257Smarius{ 0x1fd4, 0x1999, 0x1fd4, 0x0001, "Sunix SER5xxxx Serial Port", 0x10, 123264257Smarius 8 * DEFAULT_RCLK }, 124284623Smarcel{ 0x8086, 0x0f0a, 0xffff, 0, "Intel ValleyView LPIO1 HSUART#1", 0x10, 125284623Smarcel 24 * DEFAULT_RCLK, 2 }, 126284623Smarcel{ 0x8086, 0x0f0c, 0xffff, 0, "Intel ValleyView LPIO1 HSUART#2", 0x10, 127284623Smarcel 24 * DEFAULT_RCLK, 2 }, 128228947Skib{ 0x8086, 0x1c3d, 0xffff, 0, "Intel AMT - KT Controller", 0x10 }, 129249803Seadler{ 0x8086, 0x1d3d, 0xffff, 0, "Intel C600/X79 Series Chipset KT Controller", 0x10 }, 130287747Smav{ 0x8086, 0x1e3d, 0xffff, 0, "Intel Panther Point KT Controller", 0x10 }, 131266744Ssbruno{ 0x8086, 0x2a07, 0xffff, 0, "Intel AMT - PM965/GM965 KT Controller", 0x10 }, 132278292Sjhb{ 0x8086, 0x2a47, 0xffff, 0, "Mobile 4 Series Chipset KT Controller", 0x10 }, 133232967Skib{ 0x8086, 0x2e17, 0xffff, 0, "4 Series Chipset Serial KT Controller", 0x10 }, 134229971Skib{ 0x8086, 0x3b67, 0xffff, 0, "5 Series/3400 Series Chipset KT Controller", 135229971Skib 0x10 }, 136229379Skevlo{ 0x8086, 0x8811, 0xffff, 0, "Intel EG20T Serial Port 0", 0x10 }, 137229379Skevlo{ 0x8086, 0x8812, 0xffff, 0, "Intel EG20T Serial Port 1", 0x10 }, 138229379Skevlo{ 0x8086, 0x8813, 0xffff, 0, "Intel EG20T Serial Port 2", 0x10 }, 139229379Skevlo{ 0x8086, 0x8814, 0xffff, 0, "Intel EG20T Serial Port 3", 0x10 }, 140257808Ssbruno{ 0x8086, 0x8c3d, 0xffff, 0, "Intel Lynx Point KT Controller", 0x10 }, 141275101Smav{ 0x8086, 0x8cbd, 0xffff, 0, "Intel Wildcat Point KT Controller", 0x10 }, 142284702Ssbruno{ 0x8086, 0x9c3d, 0xffff, 0, "Intel Lynx Point-LP HECI KT", 0x10 }, 143200257Smav{ 0x9710, 0x9820, 0x1000, 1, "NetMos NM9820 Serial Port", 0x10 }, 144189407Sjhb{ 0x9710, 0x9835, 0x1000, 1, "NetMos NM9835 Serial Port", 0x10 }, 145200230Smarcel{ 0x9710, 0x9865, 0xa000, 0x1000, "NetMos NM9865 Serial Port", 0x10 }, 146223672Shselasky{ 0x9710, 0x9900, 0xa000, 0x1000, 147223672Shselasky "MosChip MCS9900 PCIe to Peripheral Controller", 0x10 }, 148204533Sdelphij{ 0x9710, 0x9901, 0xa000, 0x1000, 149204533Sdelphij "MosChip MCS9901 PCIe to Peripheral Controller", 0x10 }, 150232639Sremko{ 0x9710, 0x9904, 0xa000, 0x1000, 151232639Sremko "MosChip MCS9904 PCIe to Peripheral Controller", 0x10 }, 152276351Smarius{ 0x9710, 0x9922, 0xa000, 0x1000, 153276351Smarius "MosChip MCS9922 PCIe to Peripheral Controller", 0x10 }, 154158058Smarcel{ 0xdeaf, 0x9051, 0xffff, 0, "Middle Digital PC Weasel Serial Port", 0x10 }, 155158058Smarcel{ 0xffff, 0, 0xffff, 0, NULL, 0, 0} 156119815Smarcel}; 157119815Smarcel 158246300Smariusconst static struct pci_id * 159246300Smariusuart_pci_match(device_t dev, const struct pci_id *id) 160119815Smarcel{ 161158058Smarcel uint16_t device, subdev, subven, vendor; 162119815Smarcel 163158058Smarcel vendor = pci_get_vendor(dev); 164158058Smarcel device = pci_get_device(dev); 165158058Smarcel while (id->vendor != 0xffff && 166158058Smarcel (id->vendor != vendor || id->device != device)) 167119815Smarcel id++; 168158058Smarcel if (id->vendor == 0xffff) 169158058Smarcel return (NULL); 170158058Smarcel if (id->subven == 0xffff) 171158058Smarcel return (id); 172158058Smarcel subven = pci_get_subvendor(dev); 173158058Smarcel subdev = pci_get_subdevice(dev); 174158058Smarcel while (id->vendor == vendor && id->device == device && 175158058Smarcel (id->subven != subven || id->subdev != subdev)) 176158058Smarcel id++; 177158058Smarcel return ((id->vendor == vendor && id->device == device) ? id : NULL); 178119815Smarcel} 179119815Smarcel 180119815Smarcelstatic int 181119815Smarceluart_pci_probe(device_t dev) 182119815Smarcel{ 183119815Smarcel struct uart_softc *sc; 184246300Smarius const struct pci_id *id; 185253654Smarcel int result; 186119815Smarcel 187119815Smarcel sc = device_get_softc(dev); 188119815Smarcel 189158058Smarcel id = uart_pci_match(dev, pci_ns8250_ids); 190119815Smarcel if (id != NULL) { 191119815Smarcel sc->sc_class = &uart_ns8250_class; 192119815Smarcel goto match; 193119815Smarcel } 194119815Smarcel /* Add checks for non-ns8250 IDs here. */ 195119815Smarcel return (ENXIO); 196119815Smarcel 197119815Smarcel match: 198284623Smarcel result = uart_bus_probe(dev, id->regshft, id->rclk, id->rid, 0); 199253654Smarcel /* Bail out on error. */ 200253654Smarcel if (result > 0) 201253654Smarcel return (result); 202253654Smarcel /* Set/override the device description. */ 203119815Smarcel if (id->desc) 204119815Smarcel device_set_desc(dev, id->desc); 205253654Smarcel return (result); 206119815Smarcel} 207119815Smarcel 208246300SmariusDRIVER_MODULE(uart, pci, uart_pci_driver, uart_devclass, NULL, NULL); 209