PSP is optional to ccp(4). Thus if PSP attachment fails (e.g.
interrupt can not be set up), do not unmap IO space. It will still
be needed by ccp(4). Nonetheless, disestablish interrupt handler
if PSP attachment fails.
Another tweak: If PSP can not be initialized, there's no need to
actually flush caches (wbinvd) on all CPUs.
Cleanup dmesg output and make it more precise.
from hshoexer@; reported and tested by Hrvoje Popovski
-/* $OpenBSD: ccp.c,v 1.4 2024/06/12 12:54:54 bluhm Exp $ */
+/* $OpenBSD: ccp.c,v 1.5 2024/06/13 17:59:08 bluhm Exp $ */
/*
* Copyright (c) 2018 David Gwynne <dlg@openbsd.org>
timeout_set(&sc->sc_tick, ccp_rng, sc);
ccp_rng(sc);
- if (sc->sc_psp_attached)
+ if (sc->sc_psp_attached != 0)
printf(", RNG\n");
else
printf(": RNG\n");
if (psp_get_pstatus(&pst) || pst.state != 0)
goto fail_3;
- printf(", SEV");
-
/*
* create and map Trusted Memory Region (TMR); size 1 Mbyte,
* needs to be aligend to 1 Mbyte.
if (psp_init(&init))
goto fail_7;
+ printf(", SEV");
+
psp_get_pstatus(&pst);
if ((pst.state == 1) && (pst.cfges_build & 0x1))
printf(", SEV-ES");
bus_dmamap_destroy(sc->sc_dmat, sc->sc_cmd_map);
ccp_softc = NULL;
+ sc->sc_psp_attached = -1;
return (0);
}
/* Did PSP sent a response code? */
if (status & PSP_CMDRESP_RESPONSE) {
- if ((status & PSP_STATUS_MASK) != PSP_STATUS_SUCCESS) {
- printf("%s: command failed: 0x%x\n", __func__,
- (status & PSP_STATUS_MASK));
+ if ((status & PSP_STATUS_MASK) != PSP_STATUS_SUCCESS)
return (1);
- }
}
return (0);
init->tmr_length = uinit->tmr_length;
ret = ccp_docmd(sc, PSP_CMD_INIT, sc->sc_cmd_map->dm_segs[0].ds_addr);
-
- wbinvd_on_all_cpus();
-
if (ret != 0)
return (EIO);
+ wbinvd_on_all_cpus();
+
return (0);
}
-/* $OpenBSD: ccpvar.h,v 1.2 2024/06/12 12:54:54 bluhm Exp $ */
+/* $OpenBSD: ccpvar.h,v 1.3 2024/06/13 17:59:08 bluhm Exp $ */
/*
* Copyright (c) 2018 David Gwynne <dlg@openbsd.org>
struct timeout sc_tick;
- bus_size_t sc_size;
int sc_psp_attached;
#ifdef __amd64__
-/* $OpenBSD: ccp_pci.c,v 1.10 2024/06/12 12:54:54 bluhm Exp $ */
+/* $OpenBSD: ccp_pci.c,v 1.11 2024/06/13 17:59:08 bluhm Exp $ */
/*
* Copyright (c) 2018 David Gwynne <dlg@openbsd.org>
}
if (pci_mapreg_map(pa, CCP_PCI_BAR, memtype, 0,
- &sc->sc_iot, &sc->sc_ioh, NULL, &sc->sc_size, 0) != 0) {
+ &sc->sc_iot, &sc->sc_ioh, NULL, NULL, 0) != 0) {
printf(": cannot map registers\n");
return;
}
if (pci_intr_map_msix(pa, 0, &ih) != 0 &&
pci_intr_map_msi(pa, &ih) != 0 && pci_intr_map(pa, &ih) != 0) {
printf(": couldn't map interrupt\n");
- bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_size);
return;
}
if (sc->sc_ih != NULL)
printf(": %s", intrstr);
- if (psp_attach(sc)) {
- /* enable interrupts */
- bus_space_write_4(sc->sc_iot, sc->sc_ioh, PSP_REG_INTEN, -1);
+ if (!psp_attach(sc)) {
+ pci_intr_disestablish(pa->pa_pc, sc->sc_ih);
+ sc->sc_ih = NULL;
+ return;
}
+
+ /* enable interrupts */
+ bus_space_write_4(sc->sc_iot, sc->sc_ioh, PSP_REG_INTEN, -1);
}
int