From: Stefan Fritsch Subject: virtio_pci: Match all pci revisions for virtio 1.x To: tech@openbsd.org Date: Thu, 29 Aug 2024 16:50:10 +0200 Hi, we more compliant to the virtio 1.x standard, which says "Drivers match any PCI Revision ID value". ok? Cheers, Stefan diff --git a/sys/dev/pci/virtio_pci.c b/sys/dev/pci/virtio_pci.c index 5280b237ef5..1a5628be504 100644 --- a/sys/dev/pci/virtio_pci.c +++ b/sys/dev/pci/virtio_pci.c @@ -359,8 +359,7 @@ virtio_pci_match(struct device *parent, void *match, void *aux) return 1; /* virtio 1.0 */ if (PCI_PRODUCT(pa->pa_id) >= 0x1040 && - PCI_PRODUCT(pa->pa_id) <= 0x107f && - PCI_REVISION(pa->pa_class) == 1) + PCI_PRODUCT(pa->pa_id) <= 0x107f) return 1; return 0; } @@ -592,23 +591,22 @@ virtio_pci_attach(struct device *parent, struct device *self, void *aux) struct pci_attach_args *pa = (struct pci_attach_args *)aux; pci_chipset_tag_t pc = pa->pa_pc; pcitag_t tag = pa->pa_tag; - int revision, ret = ENODEV; + int revision, product, ret = ENODEV; pcireg_t id; char const *intrstr; pci_intr_handle_t ih; struct virtio_pci_attach_args vpa = { { 0 }, pa }; revision = PCI_REVISION(pa->pa_class); - switch (revision) { - case 0: + product = PCI_PRODUCT(pa->pa_id); + if (revision == 0) { /* subsystem ID shows what I am */ id = PCI_PRODUCT(pci_conf_read(pc, tag, PCI_SUBSYS_ID_REG)); - break; - case 1: - id = PCI_PRODUCT(pa->pa_id) - 0x1040; - break; - default: - printf("unknown revision 0x%02x; giving up\n", revision); + } else if (product >= 0x1040 && product <= 0x107f) { + id = product - 0x1040; + } else { + printf("unknown device prod 0x%04x rev 0x%02x; giving up\n", + product, revision); return; } @@ -637,7 +635,7 @@ virtio_pci_attach(struct device *parent, struct device *self, void *aux) vsc->sc_ops = &virtio_pci_ops; if ((vsc->sc_dev.dv_cfdata->cf_flags & VIRTIO_CF_NO_VERSION_1) == 0 && - (revision == 1 || + (revision >= 1 || (vsc->sc_dev.dv_cfdata->cf_flags & VIRTIO_CF_PREFER_VERSION_1))) { ret = virtio_pci_attach_10(sc, pa); }