Index: share/man/man9/PCI_SUBVID =================================================================== --- /dev/null +++ share/man/man9/PCI_SUBVID @@ -0,0 +1,78 @@ +.\" Copyright (c) 2018 Lakhan Shiva Kamireddy +.\" Sponsored by: Google, Inc. (GSoC 2018) +.\" Mentors: Warner Losh, Chuck Tuffli +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd August 11, 2018 +.Dt PCI_SUBVID 9 +.Os +.Sh NAME +.Nm PCI_SUBVID +.Nd stores PnP information of the device to the device table +using the subvendor id provided & +sets match flag on subvendor id +.\" +.Sh SYNOPSIS +.In dev/pci/pcivar.h +.Fo PCI_SUBVID +.Fa "uint16_t sv" +.Fc +.\" +.Sh DESCRIPTION +The +.Fn PCI_SUBVID +macro adds the PnP information of the device to the device table +of type pci_device_table which has device-identifying data for use by +.Xr devmatch 8 . +.Pp +The macro takes a +.Fa subvendor id +parameter that is of the type +.It uint16_t element. +.\" +.Sh EXAMPLES +.Bd -literal -offset indent -compact +#include +#include +struct pci_device_table my_ids[] = { + { PCI_VID(0x1234), PCI_SUBVID(0x0001), PCI_DESCR("Foo bar") }, + { PCI_VID(0x9abc), PCI_VID(0x9abc), PCI_DESCR("Baz fizz") }, +}; +.Ed +.\" +.Sh SEE ALSO +.Xr PCI_VID 9 , +.Xr devmatch 8 +.Sh HISTORY +The macro +.Nm +appeared in +.Fx 12.0 . +.Sh AUTHORS +The PNP framework and +.Xr devmatch 8 +utility were written by +.An Warner Losh Aq Mt imp@FreeBSD.org . Index: sys/dev/pci/pcivar.h =================================================================== --- sys/dev/pci/pcivar.h +++ sys/dev/pci/pcivar.h @@ -301,6 +301,8 @@ .match_flag_subdevice = 1, .subdevice = (sd) #define PCI_DEVID(did) \ PCI_DEV((uint16_t)did, (uint16_t)(did >> 16)) +#define PCI_SUBVID(sv) \ + .match_flag_subvendor = 1, .subvendor = (sv) #define PCI_CLASS(x) \ .match_flag_class = 1, .class_id = (x) #define PCI_SUBCLASS(x) \ Index: sys/dev/pcn/if_pcn.c =================================================================== --- sys/dev/pcn/if_pcn.c +++ sys/dev/pcn/if_pcn.c @@ -193,6 +193,8 @@ static devclass_t pcn_devclass; DRIVER_MODULE(pcn, pci, pcn_driver, pcn_devclass, 0, 0); +MODULE_PNP_INFO("U16:vendor; U16:device", pci, pcn, pcn_devs, + sizeof(pcn_devs[0]), nitems(pcn_devs) - 1); DRIVER_MODULE(miibus, pcn, miibus_driver, miibus_devclass, 0, 0); #define PCN_CSR_SETBIT(sc, reg, x) \ Index: sys/dev/pst/pst-pci.c =================================================================== --- sys/dev/pst/pst-pci.c +++ sys/dev/pst/pst-pci.c @@ -51,22 +51,25 @@ #include "dev/pst/pst-iop.h" +struct pci_device_table iop_devs[] = { + /* tested with actual hardware kindly donated by Promise */ + {PCI_DEVID(0x19628086), PCI_SUBVID(0x105a), + PCI_DESCR("Promise SuperTrak SX6000 ATA RAID controller")}, + /* support the older SuperTrak 100 as well */ + {PCI_DEVID(0x19608086), PCI_SUBVID(0x105a), + PCI_DESCR("Promise SuperTrak 100 ATA RAID controller")} +}; + static int iop_pci_probe(device_t dev) { - /* tested with actual hardware kindly donated by Promise */ - if (pci_get_devid(dev) == 0x19628086 && pci_get_subvendor(dev) == 0x105a) { - device_set_desc(dev, "Promise SuperTrak SX6000 ATA RAID controller"); - return BUS_PROBE_DEFAULT; - } - - /* support the older SuperTrak 100 as well */ - if (pci_get_devid(dev) == 0x19608086 && pci_get_subvendor(dev) == 0x105a) { - device_set_desc(dev, "Promise SuperTrak 100 ATA RAID controller"); - return BUS_PROBE_DEFAULT; - } - - return ENXIO; + const struct pci_device_table *iopd; + + iopd = PCI_MATCH(dev, iop_devs); + if (iopd == NULL) + return (ENXIO); + device_set_desc(dev, iopd->descr); + return (BUS_PROBE_DEFAULT); } static int @@ -133,3 +136,4 @@ static devclass_t pst_pci_devclass; DRIVER_MODULE(pstpci, pci, pst_pci_driver, pst_pci_devclass, 0, 0); +PCI_PNP_INFO(iop_devs); Index: sys/dev/ral/if_ral_pci.c =================================================================== --- sys/dev/ral/if_ral_pci.c +++ sys/dev/ral/if_ral_pci.c @@ -178,6 +178,8 @@ static devclass_t ral_devclass; DRIVER_MODULE(ral, pci, ral_pci_driver, ral_devclass, NULL, NULL); +MODULE_PNP_INFO("U16:vendor; U16:device; D:#", pci, ral, ral_pci_ids, + sizeof(ral_pci_ids[0]), nitems(ral_pci_ids) - 1); static int ral_pci_probe(device_t dev) Index: sys/dev/re/if_re.c =================================================================== --- sys/dev/re/if_re.c +++ sys/dev/re/if_re.c @@ -352,6 +352,8 @@ static devclass_t re_devclass; DRIVER_MODULE(re, pci, re_driver, re_devclass, 0, 0); +MODULE_PNP_INFO("U16:vendor; U16:device", pci, re, re_devs, + sizeof(re_devs[0]), nitems(re_devs) - 1); DRIVER_MODULE(miibus, re, miibus_driver, miibus_devclass, 0, 0); #define EE_SET(x) \ Index: sys/dev/rl/if_rl.c =================================================================== --- sys/dev/rl/if_rl.c +++ sys/dev/rl/if_rl.c @@ -259,6 +259,8 @@ static devclass_t rl_devclass; DRIVER_MODULE(rl, pci, rl_driver, rl_devclass, 0, 0); +MODULE_PNP_INFO("U16:vendor; U16:device", pci, rl, rl_devs, + sizeof(rl_devs[0]), nitems(rl_devs) - 1); DRIVER_MODULE(rl, cardbus, rl_driver, rl_devclass, 0, 0); DRIVER_MODULE(miibus, rl, miibus_driver, miibus_devclass, 0, 0); Index: sys/dev/sge/if_sge.c =================================================================== --- sys/dev/sge/if_sge.c +++ sys/dev/sge/if_sge.c @@ -101,10 +101,11 @@ /* * Various supported device vendors/types and their names. */ -static struct sge_type sge_devs[] = { - { SIS_VENDORID, SIS_DEVICEID_190, "SiS190 Fast Ethernet" }, - { SIS_VENDORID, SIS_DEVICEID_191, "SiS191 Fast/Gigabit Ethernet" }, - { 0, 0, NULL } +struct pci_device_table sge_devs[] = { + {PCI_DEV(SIS_VENDORID, SIS_DEVICEID_190), + PCI_DESCR("SiS190 Fast Ethernet")}, + {PCI_DEV(SIS_VENDORID, SIS_DEVICEID_191), + PCI_DESCR("SiS191 Fast/Gigabit Ethernet")} }; static int sge_probe(device_t); @@ -176,6 +177,7 @@ static devclass_t sge_devclass; DRIVER_MODULE(sge, pci, sge_driver, sge_devclass, 0, 0); +PCI_PNP_INFO(sge_devs); DRIVER_MODULE(miibus, sge, miibus_driver, miibus_devclass, 0, 0); /* @@ -531,19 +533,13 @@ static int sge_probe(device_t dev) { - struct sge_type *t; - - t = sge_devs; - while (t->sge_name != NULL) { - if ((pci_get_vendor(dev) == t->sge_vid) && - (pci_get_device(dev) == t->sge_did)) { - device_set_desc(dev, t->sge_name); - return (BUS_PROBE_DEFAULT); - } - t++; - } + const struct pci_device_table *sged; - return (ENXIO); + sged = PCI_MATCH(dev, sge_devs); + if (sged == NULL) + return (ENXIO); + device_set_desc(dev, sged->descr); + return (BUS_PROBE_DEFAULT); } /* Index: sys/dev/sis/if_sis.c =================================================================== --- sys/dev/sis/if_sis.c +++ sys/dev/sis/if_sis.c @@ -129,11 +129,13 @@ /* * Various supported device vendors/types and their names. */ -static const struct sis_type sis_devs[] = { - { SIS_VENDORID, SIS_DEVICEID_900, "SiS 900 10/100BaseTX" }, - { SIS_VENDORID, SIS_DEVICEID_7016, "SiS 7016 10/100BaseTX" }, - { NS_VENDORID, NS_DEVICEID_DP83815, "NatSemi DP8381[56] 10/100BaseTX" }, - { 0, 0, NULL } +struct pci_device_table sis_devs[] = { + {PCI_DEV(SIS_VENDORID, SIS_DEVICEID_900), + PCI_DESCR("SiS 900 10/100BaseTX")}, + {PCI_DEV(SIS_VENDORID, SIS_DEVICEID_7016), + PCI_DESCR("SiS 7016 10/100BaseTX")}, + {PCI_DEV(NS_VENDORID, NS_DEVICEID_DP83815), + PCI_DESCR("NatSemi DP8381[56] 10/100BaseTX")} }; static int sis_detach(device_t); @@ -866,20 +868,13 @@ static int sis_probe(device_t dev) { - const struct sis_type *t; + const struct pci_device_table *sisd; - t = sis_devs; - - while (t->sis_name != NULL) { - if ((pci_get_vendor(dev) == t->sis_vid) && - (pci_get_device(dev) == t->sis_did)) { - device_set_desc(dev, t->sis_name); - return (BUS_PROBE_DEFAULT); - } - t++; - } - - return (ENXIO); + sisd = PCI_MATCH(dev, sis_devs); + if (sisd == NULL) + return (ENXIO); + device_set_desc(dev, sisd->descr); + return (BUS_PROBE_DEFAULT); } /* @@ -2408,4 +2403,5 @@ static devclass_t sis_devclass; DRIVER_MODULE(sis, pci, sis_driver, sis_devclass, 0, 0); +PCI_PNP_INFO(sis_devs); DRIVER_MODULE(miibus, sis, miibus_driver, miibus_devclass, 0, 0); Index: sys/dev/ste/if_ste.c =================================================================== --- sys/dev/ste/if_ste.c +++ sys/dev/ste/if_ste.c @@ -88,11 +88,13 @@ /* * Various supported device vendors/types and their names. */ -static const struct ste_type ste_devs[] = { - { ST_VENDORID, ST_DEVICEID_ST201_1, "Sundance ST201 10/100BaseTX" }, - { ST_VENDORID, ST_DEVICEID_ST201_2, "Sundance ST201 10/100BaseTX" }, - { DL_VENDORID, DL_DEVICEID_DL10050, "D-Link DL10050 10/100BaseTX" }, - { 0, 0, NULL } +struct pci_device_table ste_devs[] = { + {PCI_DEV(ST_VENDORID, ST_DEVICEID_ST201_1), + PCI_DESCR("Sundance ST201 10/100BaseTX")}, + {PCI_DEV(ST_VENDORID, ST_DEVICEID_ST201_2), + PCI_DESCR("Sundance ST201 10/100BaseTX")}, + {PCI_DEV(DL_VENDORID, DL_DEVICEID_DL10050), + PCI_DESCR("D-Link DL10050 10/100BaseTX")} }; static int ste_attach(device_t); @@ -181,6 +183,7 @@ static devclass_t ste_devclass; DRIVER_MODULE(ste, pci, ste_driver, ste_devclass, 0, 0); +PCI_PNP_INFO(ste_devs); DRIVER_MODULE(miibus, ste, miibus_driver, miibus_devclass, 0, 0); #define STE_SETBIT4(sc, reg, x) \ @@ -881,20 +884,13 @@ static int ste_probe(device_t dev) { - const struct ste_type *t; + const struct pci_device_table *sted; - t = ste_devs; - - while (t->ste_name != NULL) { - if ((pci_get_vendor(dev) == t->ste_vid) && - (pci_get_device(dev) == t->ste_did)) { - device_set_desc(dev, t->ste_name); - return (BUS_PROBE_DEFAULT); - } - t++; - } - - return (ENXIO); + sted = PCI_MATCH(dev, ste_devs); + if (sted == NULL) + return (ENXIO); + device_set_desc(dev, sted->descr); + return (BUS_PROBE_DEFAULT); } /*