From: Jonathan Gray Subject: Re: [EXT] make psp attach to ccp To: Hans-Jörg Höxer Cc: tech@openbsd.org, bluhm@openbsd.org Date: Wed, 4 Sep 2024 00:01:54 +1000 On Tue, Sep 03, 2024 at 02:34:39PM +0200, Hans-Jörg Höxer wrote: > Hi, > > > On Tue, Sep 03, 2024 at 09:51:18PM +1000, Jonathan Gray wrote: > > > > does calling psp_pci_attach() after ccp_attach() give the right output? > > no, now on both machines the intrstr is messed up: > > vendor "AMD", unknown product 0x145a (class instrumentation unknown subclass 0x00, rev 0x00) at pci4 dev 0 function 0 not configured > ccp0 at pci4 dev 0 function 2 "AMD 17h Crypto" rev 0x00 > : msixxhci0 at pci4 dev 0 function 3 "AMD 17h xHCI" rev 0x00: msix, xHCI 1.0 > usb0 at xhci0: USB revision 3.0 > > and > > vendor "AMD", unknown product 0x1485 (class instrumentation unknown subclass 0x00, rev 0x00) at pci19 dev 0 function 0 not configured > ccp0 at pci19 dev 0 function 1 "AMD 17h Crypto" rev 0x00 > : msixpsp0 at ccp0: SEV, SEV-ES > vendor "AMD", unknown product 0x1498 (class crypto subclass miscellaneous, rev 0x00) at pci19 dev 0 function 2 not configured needs to be split into two parts to cover all the cases revert the previous diff and try this diff --git sys/dev/ic/ccpvar.h sys/dev/ic/ccpvar.h index 65222f6bd95..a059eaa605a 100644 --- sys/dev/ic/ccpvar.h +++ sys/dev/ic/ccpvar.h @@ -25,6 +25,7 @@ struct ccp_softc { struct timeout sc_tick; struct device *sc_psp; + void *sc_irqh; }; void ccp_attach(struct ccp_softc *); diff --git sys/dev/ic/psp.c sys/dev/ic/psp.c index e2430e17413..205aeeff545 100644 --- sys/dev/ic/psp.c +++ sys/dev/ic/psp.c @@ -109,7 +109,7 @@ psp_attach(struct device *parent, struct device *self, void *aux) sc->sc_dmat = arg->dmat; sc->sc_capabilities = arg->capabilities; - rw_init(&sc->sc_lock, "ccp_lock"); + rw_init(&sc->sc_lock, "psp_lock"); /* create and map SEV command buffer */ sc->sc_cmd_size = size = PAGE_SIZE; @@ -189,6 +189,8 @@ fail_1: fail_0: bus_dmamap_destroy(sc->sc_dmat, sc->sc_cmd_map); + printf("\n"); + return; } diff --git sys/dev/pci/ccp_pci.c sys/dev/pci/ccp_pci.c index a81f455f203..b7b761f03fb 100644 --- sys/dev/pci/ccp_pci.c +++ sys/dev/pci/ccp_pci.c @@ -36,7 +36,8 @@ int ccp_pci_match(struct device *, void *, void *); void ccp_pci_attach(struct device *, struct device *, void *); -void psp_pci_attach(struct device *, struct device *, void *); +void ccp_pci_intr_map(struct ccp_softc *, struct pci_attach_args *); +void ccp_pci_psp_attach(struct ccp_softc *, struct pci_attach_args *); const struct cfattach ccp_pci_ca = { sizeof(struct ccp_softc), @@ -79,21 +80,19 @@ ccp_pci_attach(struct device *parent, struct device *self, void *aux) return; } - psp_pci_attach(parent, self, aux); + ccp_pci_intr_map(sc, pa); ccp_attach(sc); + + ccp_pci_psp_attach(sc, pa); } void -psp_pci_attach(struct device *parent, struct device *self, void *aux) +ccp_pci_intr_map(struct ccp_softc *sc, struct pci_attach_args *pa) { #if NPSP > 0 - struct ccp_softc *sc = (struct ccp_softc *)self; - struct pci_attach_args *pa = aux; pci_intr_handle_t ih; const char *intrstr = NULL; - struct psp_attach_args arg; - void *irqh; /* clear and disable interrupts */ bus_space_write_4(sc->sc_iot, sc->sc_ioh, PSP_REG_INTEN, 0); @@ -106,10 +105,19 @@ psp_pci_attach(struct device *parent, struct device *self, void *aux) } intrstr = pci_intr_string(pa->pa_pc, ih); - irqh = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, psp_sev_intr, + sc->sc_irqh = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, psp_sev_intr, sc, sc->sc_dev.dv_xname); - if (irqh != NULL) + if (sc->sc_irqh != NULL) printf(": %s", intrstr); +#endif +} + +void +ccp_pci_psp_attach(struct ccp_softc *sc, struct pci_attach_args *pa) +{ +#if NPSP > 0 + struct psp_attach_args arg; + struct device *self = (struct device *)sc; memset(&arg, 0, sizeof(arg)); arg.iot = sc->sc_iot; @@ -120,7 +128,7 @@ psp_pci_attach(struct device *parent, struct device *self, void *aux) sc->sc_psp = config_found_sm(self, &arg, pspprint, pspsubmatch); if (sc->sc_psp == NULL) { - pci_intr_disestablish(pa->pa_pc, irqh); + pci_intr_disestablish(pa->pa_pc, sc->sc_irqh); return; }