summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2024-11-05 13:28:36 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2024-11-05 13:28:36 +0000
commit04d9a5d044fb10db615692bd66749542d96f5af3 (patch)
tree219f3f597fdaef302331977aa5b536745694cc2a /sys/dev
parent9927ba4f82263ed60af1be339ce510204432c3ad (diff)
Implement psp(4) shutdown command and ioctl(2) PSP_IOC_SHUTDOWN.
This will be used by vmd(8) to reset psp(4) on startup. from hshoexer@; OK mlarkin@
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/ic/psp.c34
-rw-r--r--sys/dev/ic/pspvar.h4
2 files changed, 36 insertions, 2 deletions
diff --git a/sys/dev/ic/psp.c b/sys/dev/ic/psp.c
index 24ef5efc3e1..0ec90293709 100644
--- a/sys/dev/ic/psp.c
+++ b/sys/dev/ic/psp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: psp.c,v 1.9 2024/10/30 18:33:26 bluhm Exp $ */
+/* $OpenBSD: psp.c,v 1.10 2024/11/05 13:28:35 bluhm Exp $ */
/*
* Copyright (c) 2023, 2024 Hans-Joerg Hoexer <hshoexer@genua.de>
@@ -329,6 +329,35 @@ fail_0:
}
int
+psp_shutdown(struct psp_softc *sc)
+{
+ int ret;
+
+ if (sc->sc_tmr_map == NULL)
+ return (EINVAL);
+
+ ret = ccp_docmd(sc, PSP_CMD_SHUTDOWN, 0x0);
+
+ if (ret != 0)
+ return (EIO);
+
+ /* wbinvd right after SHUTDOWN */
+ wbinvd_on_all_cpus();
+
+ /* release TMR */
+ bus_dmamap_unload(sc->sc_dmat, sc->sc_tmr_map);
+ bus_dmamem_unmap(sc->sc_dmat, sc->sc_tmr_kva, sc->sc_tmr_size);
+ bus_dmamem_free(sc->sc_dmat, &sc->sc_tmr_seg, 1);
+ bus_dmamap_destroy(sc->sc_dmat, sc->sc_tmr_map);
+ sc->sc_tmr_map = NULL;
+
+ /* reset flags */
+ sc->sc_flags = 0;
+
+ return (0);
+}
+
+int
psp_get_pstatus(struct psp_softc *sc, struct psp_platform_status *ustatus)
{
struct psp_platform_status *status;
@@ -748,6 +777,9 @@ pspioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
case PSP_IOC_INIT:
ret = psp_reinit(sc);
break;
+ case PSP_IOC_SHUTDOWN:
+ ret = psp_shutdown(sc);
+ break;
case PSP_IOC_GET_PSTATUS:
ret = psp_get_pstatus(sc, (struct psp_platform_status *)data);
break;
diff --git a/sys/dev/ic/pspvar.h b/sys/dev/ic/pspvar.h
index 9ec1e44f18c..fa36a3a90db 100644
--- a/sys/dev/ic/pspvar.h
+++ b/sys/dev/ic/pspvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pspvar.h,v 1.5 2024/10/30 17:51:12 bluhm Exp $ */
+/* $OpenBSD: pspvar.h,v 1.6 2024/11/05 13:28:35 bluhm Exp $ */
/*
* Copyright (c) 2023, 2024 Hans-Joerg Hoexer <hshoexer@genua.de>
@@ -76,6 +76,7 @@
/* Selection of PSP commands of the SEV API Version 0.24 */
#define PSP_CMD_INIT 0x1
+#define PSP_CMD_SHUTDOWN 0x2
#define PSP_CMD_PLATFORMSTATUS 0x4
#define PSP_CMD_DF_FLUSH 0xa
#define PSP_CMD_DOWNLOADFIRMWARE 0xb
@@ -256,6 +257,7 @@ struct psp_snp_platform_status {
#define PSP_IOC_DEACTIVATE _IOW('P', 10, struct psp_deactivate)
#define PSP_IOC_SNP_GET_PSTATUS _IOR('P', 11, struct psp_snp_platform_status)
#define PSP_IOC_INIT _IO('P', 12)
+#define PSP_IOC_SHUTDOWN _IO('P', 13)
#define PSP_IOC_GUEST_SHUTDOWN _IOW('P', 255, struct psp_guest_shutdown)
#ifdef _KERNEL