summaryrefslogtreecommitdiff
path: root/sys/dev/ic
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2024-10-24 18:53:00 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2024-10-24 18:53:00 +0000
commit74efed2a7ff980788efff6b3b5993762e7a78215 (patch)
tree122826ea8c34527a24858772effc3bbcdd14dd91 /sys/dev/ic
parent9cd2590ca23be81c1d41f53830d293a19657ac78 (diff)
Attach psp(4) version 1.
Some AMD CPUs come with an older platform security processor. It is detectet by PCI Id and has different register offsets. Move the dynamic register offsets into psp_softc. The PCI attach code is now in a separate psp_pci.c file and detects the version of the psp along with the ccp. The attach code is more verbose to display where problems might occur. Now the ccp_wait() has 2 seconds timeout, both for polling and interrupt. Also prevent a useless bus_space_read_4(). OK hshoexer@
Diffstat (limited to 'sys/dev/ic')
-rw-r--r--sys/dev/ic/psp.c71
-rw-r--r--sys/dev/ic/pspvar.h17
2 files changed, 67 insertions, 21 deletions
diff --git a/sys/dev/ic/psp.c b/sys/dev/ic/psp.c
index 95babb7d3db..e3eda5c96a8 100644
--- a/sys/dev/ic/psp.c
+++ b/sys/dev/ic/psp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: psp.c,v 1.5 2024/10/04 16:58:26 bluhm Exp $ */
+/* $OpenBSD: psp.c,v 1.6 2024/10/24 18:52:59 bluhm Exp $ */
/*
* Copyright (c) 2023, 2024 Hans-Joerg Hoexer <hshoexer@genua.de>
@@ -37,7 +37,12 @@ struct psp_softc {
bus_space_handle_t sc_ioh;
bus_dma_tag_t sc_dmat;
- uint32_t sc_capabilities;
+
+ bus_size_t sc_reg_inten;
+ bus_size_t sc_reg_intsts;
+ bus_size_t sc_reg_cmdresp;
+ bus_size_t sc_reg_addrlo;
+ bus_size_t sc_reg_addrhi;
bus_dmamap_t sc_cmd_map;
bus_dma_segment_t sc_cmd_seg;
@@ -74,8 +79,8 @@ psp_sev_intr(void *arg)
struct psp_softc *sc = (struct psp_softc *)csc->sc_psp;
uint32_t status;
- status = bus_space_read_4(sc->sc_iot, sc->sc_ioh, PSP_REG_INTSTS);
- bus_space_write_4(sc->sc_iot, sc->sc_ioh, PSP_REG_INTSTS, status);
+ status = bus_space_read_4(sc->sc_iot, sc->sc_ioh, sc->sc_reg_intsts);
+ bus_space_write_4(sc->sc_iot, sc->sc_ioh, sc->sc_reg_intsts, status);
if (!(status & PSP_CMDRESP_COMPLETE))
return (0);
@@ -101,10 +106,25 @@ psp_attach(struct device *parent, struct device *self, void *aux)
size_t size;
int nsegs;
+ printf(":");
sc->sc_iot = arg->iot;
sc->sc_ioh = arg->ioh;
sc->sc_dmat = arg->dmat;
- sc->sc_capabilities = arg->capabilities;
+ if (arg->version == 1) {
+ sc->sc_reg_inten = PSPV1_REG_INTEN;
+ sc->sc_reg_intsts = PSPV1_REG_INTSTS;
+ sc->sc_reg_cmdresp = PSPV1_REG_CMDRESP;
+ sc->sc_reg_addrlo = PSPV1_REG_ADDRLO;
+ sc->sc_reg_addrhi = PSPV1_REG_ADDRHI;
+ } else {
+ sc->sc_reg_inten = PSP_REG_INTEN;
+ sc->sc_reg_intsts = PSP_REG_INTSTS;
+ sc->sc_reg_cmdresp = PSP_REG_CMDRESP;
+ sc->sc_reg_addrlo = PSP_REG_ADDRLO;
+ sc->sc_reg_addrhi = PSP_REG_ADDRHI;
+ }
+ if (arg->version)
+ printf(" vers %d,", arg->version);
rw_init(&sc->sc_lock, "psp_lock");
@@ -127,8 +147,16 @@ psp_attach(struct device *parent, struct device *self, void *aux)
size, NULL, BUS_DMA_WAITOK) != 0)
goto fail_2;
- if (psp_get_pstatus(sc, &pst) || pst.state != 0)
+ if (psp_get_pstatus(sc, &pst)) {
+ printf(" platform status");
goto fail_3;
+ }
+ if (pst.state != PSP_PSTATE_UNINIT) {
+ printf(" uninitialized state");
+ goto fail_3;
+ }
+ printf(" api %u.%u, build %u,",
+ pst.api_major, pst.api_minor, pst.cfges_build >> 24);
/*
* create and map Trusted Memory Region (TMR); size 1 Mbyte,
@@ -156,15 +184,20 @@ psp_attach(struct device *parent, struct device *self, void *aux)
init.enable_es = 1;
init.tmr_length = PSP_TMR_SIZE;
init.tmr_paddr = sc->sc_tmr_map->dm_segs[0].ds_addr;
- if (psp_init(sc, &init))
+ if (psp_init(sc, &init)) {
+ printf(" init");
goto fail_7;
+ }
- printf(": SEV");
+ printf(" SEV");
psp_get_pstatus(sc, &pst);
- if ((pst.state == 1) && (pst.cfges_build & 0x1))
+ if ((pst.state == PSP_PSTATE_INIT) && (pst.cfges_build & 0x1))
printf(", SEV-ES");
+ /* enable interrupts */
+ bus_space_write_4(sc->sc_iot, sc->sc_ioh, sc->sc_reg_inten, -1);
+
printf("\n");
return;
@@ -186,7 +219,7 @@ fail_1:
fail_0:
bus_dmamap_destroy(sc->sc_dmat, sc->sc_cmd_map);
- printf("\n");
+ printf(" failed\n");
return;
}
@@ -199,9 +232,9 @@ ccp_wait(struct psp_softc *sc, uint32_t *status, int poll)
if (poll) {
count = 0;
- while (count++ < 100) {
+ while (count++ < 400) {
cmdword = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
- PSP_REG_CMDRESP);
+ sc->sc_reg_cmdresp);
if (cmdword & PSP_CMDRESP_RESPONSE)
goto done;
delay(5000);
@@ -214,12 +247,10 @@ ccp_wait(struct psp_softc *sc, uint32_t *status, int poll)
if (tsleep_nsec(sc, PWAIT, "psp", SEC_TO_NSEC(2)) == EWOULDBLOCK)
return (1);
+ cmdword = bus_space_read_4(sc->sc_iot, sc->sc_ioh, sc->sc_reg_cmdresp);
done:
- if (status) {
- *status = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
- PSP_REG_CMDRESP);
- }
-
+ if (status != NULL)
+ *status = cmdword;
return (0);
}
@@ -234,9 +265,9 @@ ccp_docmd(struct psp_softc *sc, int cmd, uint64_t paddr)
if (!cold)
cmdword |= PSP_CMDRESP_IOC;
- bus_space_write_4(sc->sc_iot, sc->sc_ioh, PSP_REG_ADDRLO, plo);
- bus_space_write_4(sc->sc_iot, sc->sc_ioh, PSP_REG_ADDRHI, phi);
- bus_space_write_4(sc->sc_iot, sc->sc_ioh, PSP_REG_CMDRESP, cmdword);
+ bus_space_write_4(sc->sc_iot, sc->sc_ioh, sc->sc_reg_addrlo, plo);
+ bus_space_write_4(sc->sc_iot, sc->sc_ioh, sc->sc_reg_addrhi, phi);
+ bus_space_write_4(sc->sc_iot, sc->sc_ioh, sc->sc_reg_cmdresp, cmdword);
if (ccp_wait(sc, &status, cold))
return (1);
diff --git a/sys/dev/ic/pspvar.h b/sys/dev/ic/pspvar.h
index a1d7c83849e..c3bad155aca 100644
--- a/sys/dev/ic/pspvar.h
+++ b/sys/dev/ic/pspvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pspvar.h,v 1.2 2024/09/04 07:45:08 jsg Exp $ */
+/* $OpenBSD: pspvar.h,v 1.3 2024/10/24 18:52:59 bluhm Exp $ */
/*
* Copyright (c) 2023, 2024 Hans-Joerg Hoexer <hshoexer@genua.de>
@@ -19,6 +19,13 @@
#include <sys/ioctl.h>
/* AMD 17h */
+#define PSPV1_REG_INTEN 0x10610
+#define PSPV1_REG_INTSTS 0x10614
+#define PSPV1_REG_CMDRESP 0x10580
+#define PSPV1_REG_ADDRLO 0x105e0
+#define PSPV1_REG_ADDRHI 0x105e4
+#define PSPV1_REG_CAPABILITIES 0x105fc
+
#define PSP_REG_INTEN 0x10690
#define PSP_REG_INTSTS 0x10694
#define PSP_REG_CMDRESP 0x10980
@@ -252,10 +259,18 @@ struct psp_attach_args {
bus_dma_tag_t dmat;
uint32_t capabilities;
+ int version;
};
int pspsubmatch(struct device *, void *, void *);
int pspprint(void *aux, const char *pnp);
int psp_sev_intr(void *);
+struct ccp_softc;
+struct pci_attach_args;
+
+int psp_pci_match(struct ccp_softc *, struct pci_attach_args *);
+void psp_pci_intr_map(struct ccp_softc *, struct pci_attach_args *);
+void psp_pci_attach(struct ccp_softc *, struct pci_attach_args *);
+
#endif /* _KERNEL */