sync with OpenBSD -current

This commit is contained in:
purplerain 2024-09-03 18:50:36 +00:00
parent 676afb990b
commit 39bad15604
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
65 changed files with 14096 additions and 1714 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: ccp_pci.c,v 1.11 2024/06/13 17:59:08 bluhm Exp $ */
/* $OpenBSD: ccp_pci.c,v 1.12 2024/09/03 00:23:05 jsg Exp $ */
/*
* Copyright (c) 2018 David Gwynne <dlg@openbsd.org>
@ -27,16 +27,15 @@
#include <dev/pci/pcivar.h>
#include <dev/ic/ccpvar.h>
#include <dev/ic/pspvar.h>
#define CCP_PCI_BAR 0x18
int ccp_pci_match(struct device *, void *, void *);
void ccp_pci_attach(struct device *, struct device *, void *);
#ifdef __amd64__
void psp_pci_attach(struct device *, struct device *, void *);
int psp_pci_intr(void *);
#endif
const struct cfattach ccp_pci_ca = {
sizeof(struct ccp_softc),
@ -79,14 +78,11 @@ ccp_pci_attach(struct device *parent, struct device *self, void *aux)
return;
}
#ifdef __amd64__
psp_pci_attach(parent, self, aux);
#endif
ccp_attach(sc);
}
#ifdef __amd64__
void
psp_pci_attach(struct device *parent, struct device *self, void *aux)
{
@ -140,4 +136,3 @@ psp_pci_intr(void *arg)
return (1);
}
#endif /* __amd64__ */

View file

@ -1,4 +1,4 @@
/* $OpenBSD: virtio_pci.c,v 1.40 2024/08/27 19:01:11 sf Exp $ */
/* $OpenBSD: virtio_pci.c,v 1.42 2024/09/02 08:26:26 sf Exp $ */
/* $NetBSD: virtio.c,v 1.3 2011/11/02 23:05:52 njoly Exp $ */
/*
@ -73,6 +73,7 @@ void virtio_pci_write_device_config_4(struct virtio_softc *, int, uint32_t);
void virtio_pci_write_device_config_8(struct virtio_softc *, int, uint64_t);
uint16_t virtio_pci_read_queue_size(struct virtio_softc *, uint16_t);
void virtio_pci_setup_queue(struct virtio_softc *, struct virtqueue *, uint64_t);
void virtio_pci_setup_intrs(struct virtio_softc *);
int virtio_pci_get_status(struct virtio_softc *);
void virtio_pci_set_status(struct virtio_softc *, int);
int virtio_pci_negotiate_features(struct virtio_softc *, const struct virtio_feature_name *);
@ -99,6 +100,11 @@ enum irq_type {
IRQ_MSIX_PER_VQ, /* vec 0: config irq, vec n: irq of vq[n-1] */
};
struct virtio_pci_intr {
char name[16];
void *ih;
};
struct virtio_pci_softc {
struct virtio_softc sc_sc;
pci_chipset_tag_t sc_pc;
@ -132,7 +138,8 @@ struct virtio_pci_softc {
bus_space_handle_t sc_isr_ioh;
bus_size_t sc_isr_iosize;
void *sc_ih[MAX_MSIX_VECS];
struct virtio_pci_intr *sc_intr;
int sc_nintr;
enum irq_type sc_irq_type;
};
@ -163,6 +170,7 @@ const struct virtio_ops virtio_pci_ops = {
virtio_pci_write_device_config_8,
virtio_pci_read_queue_size,
virtio_pci_setup_queue,
virtio_pci_setup_intrs,
virtio_pci_get_status,
virtio_pci_set_status,
virtio_pci_negotiate_features,
@ -265,23 +273,23 @@ virtio_pci_setup_queue(struct virtio_softc *vsc, struct virtqueue *vq,
bus_space_write_4(sc->sc_iot, sc->sc_ioh,
VIRTIO_CONFIG_QUEUE_ADDRESS, addr / VIRTIO_PAGE_SIZE);
}
}
/*
* This path is only executed if this function is called after
* the child's attach function has finished. In other cases,
* it's done in virtio_pci_setup_msix().
*/
if (sc->sc_irq_type != IRQ_NO_MSIX) {
int vec = 1;
if (sc->sc_irq_type == IRQ_MSIX_PER_VQ)
vec += vq->vq_index;
if (sc->sc_sc.sc_version_1) {
CWRITE(sc, queue_msix_vector, vec);
} else {
bus_space_write_2(sc->sc_iot, sc->sc_ioh,
VIRTIO_MSI_QUEUE_VECTOR, vec);
}
void
virtio_pci_setup_intrs(struct virtio_softc *vsc)
{
struct virtio_pci_softc *sc = (struct virtio_pci_softc *)vsc;
int i;
if (sc->sc_irq_type == IRQ_NO_MSIX)
return;
for (i = 0; i <= vsc->sc_nvqs; i++) {
unsigned vec = vsc->sc_vqs[i].vq_intr_vec;
virtio_pci_set_msix_queue_vector(sc, i, vec);
}
if (vsc->sc_config_change)
virtio_pci_set_msix_config_vector(sc, 0);
}
int
@ -585,7 +593,6 @@ virtio_pci_attach(struct device *parent, struct device *self, void *aux)
char const *intrstr;
pci_intr_handle_t ih;
struct virtio_pci_attach_args vpa = { { 0 }, pa };
int n;
revision = PCI_REVISION(pa->pa_class);
switch (revision) {
@ -617,9 +624,12 @@ virtio_pci_attach(struct device *parent, struct device *self, void *aux)
virtio_pci_dump_caps(sc);
#endif
n = MIN(MAX_MSIX_VECS, pci_intr_msix_count(pa));
n = MAX(n, 1);
vpa.vpa_va.va_nintr = n;
sc->sc_nintr = min(MAX_MSIX_VECS, pci_intr_msix_count(pa));
sc->sc_nintr = max(sc->sc_nintr, 1);
vpa.vpa_va.va_nintr = sc->sc_nintr;
sc->sc_intr = mallocarray(sc->sc_nintr, sizeof(*sc->sc_intr),
M_DEVBUF, M_WAITOK | M_ZERO);
vsc->sc_ops = &virtio_pci_ops;
if ((vsc->sc_dev.dv_cfdata->cf_flags & VIRTIO_CF_NO_VERSION_1) == 0 &&
@ -633,13 +643,13 @@ virtio_pci_attach(struct device *parent, struct device *self, void *aux)
}
if (ret != 0) {
printf(": Cannot attach (%d)\n", ret);
return;
goto fail_0;
}
sc->sc_devcfg_offset = VIRTIO_CONFIG_DEVICE_CONFIG_NOMSI;
sc->sc_irq_type = IRQ_NO_MSIX;
if (virtio_pci_adjust_config_region(sc) != 0)
return;
goto fail_0;
virtio_device_reset(vsc);
virtio_set_status(vsc, VIRTIO_CONFIG_DEVICE_STATUS_ACK);
@ -680,9 +690,10 @@ virtio_pci_attach(struct device *parent, struct device *self, void *aux)
*/
if (vsc->sc_ipl & IPL_MPSAFE)
ih_func = virtio_pci_legacy_intr_mpsafe;
sc->sc_ih[0] = pci_intr_establish(pc, ih, vsc->sc_ipl | IPL_MPSAFE,
ih_func, sc, vsc->sc_dev.dv_xname);
if (sc->sc_ih[0] == NULL) {
sc->sc_intr[0].ih = pci_intr_establish(pc, ih,
vsc->sc_ipl | IPL_MPSAFE, ih_func, sc,
vsc->sc_child->dv_xname);
if (sc->sc_intr[0].ih == NULL) {
printf("%s: couldn't establish interrupt", vsc->sc_dev.dv_xname);
if (intrstr != NULL)
printf(" at %s", intrstr);
@ -690,6 +701,7 @@ virtio_pci_attach(struct device *parent, struct device *self, void *aux)
goto fail_2;
}
}
virtio_pci_setup_intrs(vsc);
printf("%s: %s\n", vsc->sc_dev.dv_xname, intrstr);
return;
@ -699,6 +711,8 @@ fail_2:
fail_1:
/* no pci_mapreg_unmap() or pci_intr_unmap() */
virtio_set_status(vsc, VIRTIO_CONFIG_DEVICE_STATUS_FAILED);
fail_0:
free(sc->sc_intr, M_DEVBUF, sc->sc_nintr * sizeof(*sc->sc_intr));
}
int
@ -929,6 +943,8 @@ virtio_pci_msix_establish(struct virtio_pci_softc *sc,
struct virtio_softc *vsc = &sc->sc_sc;
pci_intr_handle_t ih;
KASSERT(idx < sc->sc_nintr);
if (pci_intr_map_msix(vpa->vpa_pa, idx, &ih) != 0) {
#if VIRTIO_DEBUG
printf("%s[%d]: pci_intr_map_msix failed\n",
@ -936,9 +952,11 @@ virtio_pci_msix_establish(struct virtio_pci_softc *sc,
#endif
return 1;
}
sc->sc_ih[idx] = pci_intr_establish(sc->sc_pc, ih, vsc->sc_ipl,
handler, ih_arg, vsc->sc_dev.dv_xname);
if (sc->sc_ih[idx] == NULL) {
snprintf(sc->sc_intr[idx].name, sizeof(sc->sc_intr[idx].name), "%s:%d",
vsc->sc_child->dv_xname, idx);
sc->sc_intr[idx].ih = pci_intr_establish(sc->sc_pc, ih, vsc->sc_ipl,
handler, ih_arg, sc->sc_intr[idx].name);
if (sc->sc_intr[idx].ih == NULL) {
printf("%s[%d]: couldn't establish msix interrupt\n",
vsc->sc_dev.dv_xname, idx);
return 1;
@ -985,10 +1003,10 @@ virtio_pci_free_irqs(struct virtio_pci_softc *sc)
}
}
for (i = 0; i < MAX_MSIX_VECS; i++) {
if (sc->sc_ih[i]) {
pci_intr_disestablish(sc->sc_pc, sc->sc_ih[i]);
sc->sc_ih[i] = NULL;
for (i = 0; i < sc->sc_nintr; i++) {
if (sc->sc_intr[i].ih) {
pci_intr_disestablish(sc->sc_pc, sc->sc_intr[i].ih);
sc->sc_intr[i].ih = NULL;
}
}
@ -1014,7 +1032,6 @@ virtio_pci_setup_msix(struct virtio_pci_softc *sc,
return 1;
sc->sc_devcfg_offset = VIRTIO_CONFIG_DEVICE_CONFIG_MSI;
virtio_pci_adjust_config_region(sc);
virtio_pci_set_msix_config_vector(sc, 0);
if (shared) {
if (virtio_pci_msix_establish(sc, vpa, 1,
@ -1023,14 +1040,14 @@ virtio_pci_setup_msix(struct virtio_pci_softc *sc,
}
for (i = 0; i < vsc->sc_nvqs; i++)
virtio_pci_set_msix_queue_vector(sc, i, 1);
vsc->sc_vqs[i].vq_intr_vec = 1;
} else {
for (i = 0; i < vsc->sc_nvqs; i++) {
if (virtio_pci_msix_establish(sc, vpa, i + 1,
virtio_pci_queue_intr, &vsc->sc_vqs[i])) {
goto fail;
}
virtio_pci_set_msix_queue_vector(sc, i, i + 1);
vsc->sc_vqs[i].vq_intr_vec = i + 1;
}
}