Download raw body.
psp(4): Implement shutdown command and ioctl
Hi,
this diff ipmlements the shutdown command for psp(4). Will be used by
vmd(8) to reset psp(4) on daemon startup.
Take care,
HJ.
--------------------------------------------------------------------------
commit 672b3628dfba6d598054e0f1cd25e3d7c6847847
Author: Hans-Joerg Hoexer <hshoexer@genua.de>
Date: Tue Oct 22 13:17:57 2024 +0200
psp(4): Implement shutdown command and ioctl
Will be used by vmd(8) to reset psp(4) on startup.
diff --git a/sys/dev/ic/psp.c b/sys/dev/ic/psp.c
index 24ef5efc3e1..fe869cdea87 100644
--- a/sys/dev/ic/psp.c
+++ b/sys/dev/ic/psp.c
@@ -328,6 +328,35 @@ fail_0:
return (ENOMEM);
}
+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)
{
@@ -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..ccdc681fb4c 100644
--- a/sys/dev/ic/pspvar.h
+++ b/sys/dev/ic/pspvar.h
@@ -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
psp(4): Implement shutdown command and ioctl