From 8eadc5ec180d138c03464eee5b23b29a4079a186 Mon Sep 17 00:00:00 2001 From: jsg Date: Wed, 4 Sep 2024 07:45:08 +0000 Subject: [PATCH] make psp attach to ccp as a different driver 'fine with me' hshoexer, ok bluhm@ --- sys/arch/amd64/amd64/conf.c | 6 +- sys/arch/amd64/conf/GENERIC | 3 +- sys/arch/amd64/conf/files.amd64 | 4 +- sys/arch/amd64/include/conf.h | 4 +- sys/conf/files | 9 +- sys/dev/ic/ccp.c | 7 +- sys/dev/ic/ccpvar.h | 25 +--- sys/dev/ic/psp.c | 211 +++++++++++++++++++++----------- sys/dev/ic/pspvar.h | 16 ++- sys/dev/pci/ccp_pci.c | 64 +++++----- sys/kern/kern_pledge.c | 6 +- 11 files changed, 203 insertions(+), 152 deletions(-) diff --git a/sys/arch/amd64/amd64/conf.c b/sys/arch/amd64/amd64/conf.c index ddcb29aac0e..20aea88e6b5 100644 --- a/sys/arch/amd64/amd64/conf.c +++ b/sys/arch/amd64/amd64/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.81 2024/06/12 12:54:54 bluhm Exp $ */ +/* $OpenBSD: conf.c,v 1.82 2024/09/04 07:45:08 jsg Exp $ */ /* * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved. @@ -152,8 +152,6 @@ cdev_decl(nvram); #include "drm.h" #include "viocon.h" cdev_decl(viocon); -#include "ccp.h" -cdev_decl(psp); #include "wsdisplay.h" #include "wskbd.h" @@ -292,7 +290,7 @@ struct cdevsw cdevsw[] = cdev_fido_init(NFIDO,fido), /* 98: FIDO/U2F security keys */ cdev_pppx_init(NPPPX,pppac), /* 99: PPP Access Concentrator */ cdev_ujoy_init(NUJOY,ujoy), /* 100: USB joystick/gamecontroller */ - cdev_psp_init(NCCP,psp), /* 101: PSP */ + cdev_psp_init(NPSP,psp), /* 101: PSP */ }; int nchrdev = nitems(cdevsw); diff --git a/sys/arch/amd64/conf/GENERIC b/sys/arch/amd64/conf/GENERIC index 80e71a9febf..b78703c62c1 100644 --- a/sys/arch/amd64/conf/GENERIC +++ b/sys/arch/amd64/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.525 2024/08/14 14:40:45 patrick Exp $ +# $OpenBSD: GENERIC,v 1.526 2024/09/04 07:45:08 jsg Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -120,6 +120,7 @@ ksmn* at pci? # AMD K17 temperature sensor amas* at pci? disable # AMD memory configuration pchtemp* at pci? # Intel C610 temperature sensor ccp* at pci? # AMD Cryptographic Co-processor +psp* at ccp? # AMD Platform Security Processor # National Semiconductor LM7[89] and compatible hardware monitors lm0 at isa? port 0x290 diff --git a/sys/arch/amd64/conf/files.amd64 b/sys/arch/amd64/conf/files.amd64 index 0325062efb6..01967be09a0 100644 --- a/sys/arch/amd64/conf/files.amd64 +++ b/sys/arch/amd64/conf/files.amd64 @@ -1,4 +1,4 @@ -# $OpenBSD: files.amd64,v 1.110 2024/09/03 00:23:05 jsg Exp $ +# $OpenBSD: files.amd64,v 1.111 2024/09/04 07:45:08 jsg Exp $ maxpartitions 16 maxusers 2 16 128 @@ -65,8 +65,6 @@ file arch/amd64/amd64/powernow-k8.c !small_kernel file arch/amd64/amd64/est.c !small_kernel file arch/amd64/amd64/k1x-pstate.c !small_kernel -file dev/ic/psp.c ccp - include "dev/rasops/files.rasops" include "dev/wsfont/files.wsfont" diff --git a/sys/arch/amd64/include/conf.h b/sys/arch/amd64/include/conf.h index 730a5b2c249..312187c0c9f 100644 --- a/sys/arch/amd64/include/conf.h +++ b/sys/arch/amd64/include/conf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.h,v 1.10 2024/09/01 17:13:46 bluhm Exp $ */ +/* $OpenBSD: conf.h,v 1.11 2024/09/04 07:45:08 jsg Exp $ */ /* $NetBSD: conf.h,v 1.2 1996/05/05 19:28:34 christos Exp $ */ /* @@ -55,5 +55,5 @@ cdev_decl(pctr); #include "vmm.h" cdev_decl(vmm); -#include "ccp.h" +#include "psp.h" cdev_decl(psp); diff --git a/sys/conf/files b/sys/conf/files index f6efcb0d736..accdb2d9836 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,4 +1,4 @@ -# $OpenBSD: files,v 1.736 2024/08/31 04:17:14 dlg Exp $ +# $OpenBSD: files,v 1.737 2024/09/04 07:45:08 jsg Exp $ # $NetBSD: files,v 1.87 1996/05/19 17:17:50 jonathan Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 @@ -470,9 +470,14 @@ device xhci: usbus file dev/usb/xhci.c xhci needs-flag # AMD Cryptographic Co-processor -device ccp +device ccp {} file dev/ic/ccp.c ccp needs-flag +# AMD Platform Security Processor +device psp +attach psp at ccp +file dev/ic/psp.c psp needs-flag + # SDHC SD/MMC controller define sdhc device sdhc: sdmmcbus diff --git a/sys/dev/ic/ccp.c b/sys/dev/ic/ccp.c index 024291c86cc..af5980c2428 100644 --- a/sys/dev/ic/ccp.c +++ b/sys/dev/ic/ccp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ccp.c,v 1.10 2024/09/03 00:23:05 jsg Exp $ */ +/* $OpenBSD: ccp.c,v 1.11 2024/09/04 07:45:08 jsg Exp $ */ /* * Copyright (c) 2018 David Gwynne @@ -41,10 +41,7 @@ ccp_attach(struct ccp_softc *sc) timeout_set(&sc->sc_tick, ccp_rng, sc); ccp_rng(sc); - if (sc->sc_psp_attached != 0) - printf(", RNG\n"); - else - printf(": RNG\n"); + printf("\n"); } static void diff --git a/sys/dev/ic/ccpvar.h b/sys/dev/ic/ccpvar.h index 59fb2e9e613..61be13088db 100644 --- a/sys/dev/ic/ccpvar.h +++ b/sys/dev/ic/ccpvar.h @@ -1,8 +1,7 @@ -/* $OpenBSD: ccpvar.h,v 1.5 2024/09/03 00:23:05 jsg Exp $ */ +/* $OpenBSD: ccpvar.h,v 1.6 2024/09/04 07:45:08 jsg Exp $ */ /* * Copyright (c) 2018 David Gwynne - * Copyright (c) 2023, 2024 Hans-Joerg Hoexer * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -18,7 +17,6 @@ */ #include -#include struct ccp_softc { struct device sc_dev; @@ -26,25 +24,8 @@ struct ccp_softc { bus_space_handle_t sc_ioh; struct timeout sc_tick; - - int sc_psp_attached; - - bus_dma_tag_t sc_dmat; - uint32_t sc_capabilities; - int (*sc_sev_intr)(struct ccp_softc *, uint32_t); - void * sc_ih; - - bus_dmamap_t sc_cmd_map; - bus_dma_segment_t sc_cmd_seg; - size_t sc_cmd_size; - caddr_t sc_cmd_kva; - - bus_dmamap_t sc_tmr_map; - bus_dma_segment_t sc_tmr_seg; - size_t sc_tmr_size; - caddr_t sc_tmr_kva; - - struct rwlock sc_lock; + struct device *sc_psp; + void *sc_irqh; }; void ccp_attach(struct ccp_softc *); diff --git a/sys/dev/ic/psp.c b/sys/dev/ic/psp.c index d6a80998e09..63fcb5a8a1d 100644 --- a/sys/dev/ic/psp.c +++ b/sys/dev/ic/psp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: psp.c,v 1.1 2024/09/03 00:23:05 jsg Exp $ */ +/* $OpenBSD: psp.c,v 1.2 2024/09/04 07:45:08 jsg Exp $ */ /* * Copyright (c) 2023, 2024 Hans-Joerg Hoexer @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -31,14 +32,54 @@ #include #include -struct ccp_softc *ccp_softc; +struct psp_softc { + struct device sc_dev; + bus_space_tag_t sc_iot; + bus_space_handle_t sc_ioh; -int psp_get_pstatus(struct psp_platform_status *); -int psp_init(struct psp_init *); + struct timeout sc_tick; + + bus_dma_tag_t sc_dmat; + uint32_t sc_capabilities; + + bus_dmamap_t sc_cmd_map; + bus_dma_segment_t sc_cmd_seg; + size_t sc_cmd_size; + caddr_t sc_cmd_kva; + + bus_dmamap_t sc_tmr_map; + bus_dma_segment_t sc_tmr_seg; + size_t sc_tmr_size; + caddr_t sc_tmr_kva; + + struct rwlock sc_lock; +}; + +int psp_get_pstatus(struct psp_softc *, struct psp_platform_status *); +int psp_init(struct psp_softc *, struct psp_init *); +int psp_match(struct device *, void *, void *); +void psp_attach(struct device *, struct device *, void *); + +struct cfdriver psp_cd = { + NULL, "psp", DV_DULL +}; + +const struct cfattach psp_ca = { + sizeof(struct psp_softc), + psp_match, + psp_attach +}; int -psp_sev_intr(struct ccp_softc *sc, uint32_t status) +psp_sev_intr(void *arg) { + struct ccp_softc *csc = 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); + if (!(status & PSP_CMDRESP_COMPLETE)) return (0); @@ -48,24 +89,34 @@ psp_sev_intr(struct ccp_softc *sc, uint32_t status) } int -psp_attach(struct ccp_softc *sc) +psp_match(struct device *parent, void *match, void *aux) +{ + return (1); +} + +void +psp_attach(struct device *parent, struct device *self, void *aux) { + struct psp_softc *sc = (struct psp_softc *)self; + struct psp_attach_args *arg = aux; struct psp_platform_status pst; struct psp_init init; size_t size; int nsegs; - if (!(sc->sc_capabilities & PSP_CAP_SEV)) - return (0); + sc->sc_iot = arg->iot; + sc->sc_ioh = arg->ioh; + 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; if (bus_dmamap_create(sc->sc_dmat, size, 1, size, 0, BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW | BUS_DMA_64BIT, &sc->sc_cmd_map) != 0) - return (0); + return; if (bus_dmamem_alloc(sc->sc_dmat, size, 0, 0, &sc->sc_cmd_seg, 1, &nsegs, BUS_DMA_WAITOK | BUS_DMA_ZERO) != 0) @@ -79,10 +130,7 @@ psp_attach(struct ccp_softc *sc) size, NULL, BUS_DMA_WAITOK) != 0) goto fail_2; - sc->sc_sev_intr = psp_sev_intr; - ccp_softc = sc; - - if (psp_get_pstatus(&pst) || pst.state != 0) + if (psp_get_pstatus(sc, &pst) || pst.state != 0) goto fail_3; /* @@ -111,18 +159,18 @@ psp_attach(struct ccp_softc *sc) 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(&init)) + if (psp_init(sc, &init)) goto fail_7; - printf(", SEV"); + printf(": SEV"); - psp_get_pstatus(&pst); + psp_get_pstatus(sc, &pst); if ((pst.state == 1) && (pst.cfges_build & 0x1)) printf(", SEV-ES"); - sc->sc_psp_attached = 1; + printf("\n"); - return (1); + return; fail_7: bus_dmamap_unload(sc->sc_dmat, sc->sc_tmr_map); @@ -141,14 +189,13 @@ fail_1: fail_0: bus_dmamap_destroy(sc->sc_dmat, sc->sc_cmd_map); - ccp_softc = NULL; - sc->sc_psp_attached = -1; + printf("\n"); - return (0); + return; } static int -ccp_wait(struct ccp_softc *sc, uint32_t *status, int poll) +ccp_wait(struct psp_softc *sc, uint32_t *status, int poll) { uint32_t cmdword; int count; @@ -180,7 +227,7 @@ done: } static int -ccp_docmd(struct ccp_softc *sc, int cmd, uint64_t paddr) +ccp_docmd(struct psp_softc *sc, int cmd, uint64_t paddr) { uint32_t plo, phi, cmdword, status; @@ -207,9 +254,8 @@ ccp_docmd(struct ccp_softc *sc, int cmd, uint64_t paddr) } int -psp_init(struct psp_init *uinit) +psp_init(struct psp_softc *sc, struct psp_init *uinit) { - struct ccp_softc *sc = ccp_softc; struct psp_init *init; int ret; @@ -230,9 +276,8 @@ psp_init(struct psp_init *uinit) } int -psp_get_pstatus(struct psp_platform_status *ustatus) +psp_get_pstatus(struct psp_softc *sc, struct psp_platform_status *ustatus) { - struct ccp_softc *sc = ccp_softc; struct psp_platform_status *status; int ret; @@ -251,9 +296,8 @@ psp_get_pstatus(struct psp_platform_status *ustatus) } int -psp_df_flush(void) +psp_df_flush(struct psp_softc *sc) { - struct ccp_softc *sc = ccp_softc; int ret; wbinvd_on_all_cpus(); @@ -267,9 +311,8 @@ psp_df_flush(void) } int -psp_decommission(struct psp_decommission *udecom) +psp_decommission(struct psp_softc *sc, struct psp_decommission *udecom) { - struct ccp_softc *sc = ccp_softc; struct psp_decommission *decom; int ret; @@ -288,9 +331,8 @@ psp_decommission(struct psp_decommission *udecom) } int -psp_get_gstatus(struct psp_guest_status *ustatus) +psp_get_gstatus(struct psp_softc *sc, struct psp_guest_status *ustatus) { - struct ccp_softc *sc = ccp_softc; struct psp_guest_status *status; int ret; @@ -313,9 +355,8 @@ psp_get_gstatus(struct psp_guest_status *ustatus) } int -psp_launch_start(struct psp_launch_start *ustart) +psp_launch_start(struct psp_softc *sc, struct psp_launch_start *ustart) { - struct ccp_softc *sc = ccp_softc; struct psp_launch_start *start; int ret; @@ -339,9 +380,8 @@ psp_launch_start(struct psp_launch_start *ustart) } int -psp_launch_update_data(struct psp_launch_update_data *ulud, struct proc *p) +psp_launch_update_data(struct psp_softc *sc, struct psp_launch_update_data *ulud, struct proc *p) { - struct ccp_softc *sc = ccp_softc; struct psp_launch_update_data *ludata; pmap_t pmap; vaddr_t v, next, end; @@ -397,10 +437,9 @@ psp_launch_update_data(struct psp_launch_update_data *ulud, struct proc *p) } int -psp_launch_measure(struct psp_launch_measure *ulm) +psp_launch_measure(struct psp_softc *sc, struct psp_launch_measure *ulm) { struct psp_launch_measure *lm; - struct ccp_softc *sc = ccp_softc; int ret; uint64_t paddr; @@ -427,9 +466,8 @@ psp_launch_measure(struct psp_launch_measure *ulm) } int -psp_launch_finish(struct psp_launch_finish *ulf) +psp_launch_finish(struct psp_softc *sc, struct psp_launch_finish *ulf) { - struct ccp_softc *sc = ccp_softc; struct psp_launch_finish *lf; int ret; @@ -448,9 +486,8 @@ psp_launch_finish(struct psp_launch_finish *ulf) } int -psp_attestation(struct psp_attestation *uat) +psp_attestation(struct psp_softc *sc, struct psp_attestation *uat) { - struct ccp_softc *sc = ccp_softc; struct psp_attestation *at; int ret; uint64_t paddr; @@ -479,9 +516,8 @@ psp_attestation(struct psp_attestation *uat) } int -psp_activate(struct psp_activate *uact) +psp_activate(struct psp_softc *sc, struct psp_activate *uact) { - struct ccp_softc *sc = ccp_softc; struct psp_activate *act; int ret; @@ -501,9 +537,8 @@ psp_activate(struct psp_activate *uact) } int -psp_deactivate(struct psp_deactivate *udeact) +psp_deactivate(struct psp_softc *sc, struct psp_deactivate *udeact) { - struct ccp_softc *sc = ccp_softc; struct psp_deactivate *deact; int ret; @@ -522,7 +557,7 @@ psp_deactivate(struct psp_deactivate *udeact) } int -psp_guest_shutdown(struct psp_guest_shutdown *ugshutdown) +psp_guest_shutdown(struct psp_softc *sc, struct psp_guest_shutdown *ugshutdown) { struct psp_deactivate deact; struct psp_decommission decom; @@ -530,24 +565,23 @@ psp_guest_shutdown(struct psp_guest_shutdown *ugshutdown) bzero(&deact, sizeof(deact)); deact.handle = ugshutdown->handle; - if ((ret = psp_deactivate(&deact)) != 0) + if ((ret = psp_deactivate(sc, &deact)) != 0) return (ret); - if ((ret = psp_df_flush()) != 0) + if ((ret = psp_df_flush(sc)) != 0) return (ret); bzero(&decom, sizeof(decom)); decom.handle = ugshutdown->handle; - if ((ret = psp_decommission(&decom)) != 0) + if ((ret = psp_decommission(sc, &decom)) != 0) return (ret); return (0); } int -psp_snp_get_pstatus(struct psp_snp_platform_status *ustatus) +psp_snp_get_pstatus(struct psp_softc *sc, struct psp_snp_platform_status *ustatus) { - struct ccp_softc *sc = ccp_softc; struct psp_snp_platform_status *status; int ret; @@ -568,8 +602,11 @@ psp_snp_get_pstatus(struct psp_snp_platform_status *ustatus) int pspopen(dev_t dev, int flag, int mode, struct proc *p) { - if (ccp_softc == NULL) - return (ENODEV); + struct psp_softc *sc; + + sc = (struct psp_softc *)device_lookup(&psp_cd, minor(dev)); + if (sc == NULL) + return (ENXIO); return (0); } @@ -577,64 +614,75 @@ pspopen(dev_t dev, int flag, int mode, struct proc *p) int pspclose(dev_t dev, int flag, int mode, struct proc *p) { + struct psp_softc *sc; + + sc = (struct psp_softc *)device_lookup(&psp_cd, minor(dev)); + if (sc == NULL) + return (ENXIO); + return (0); } int pspioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) { - int ret; + struct psp_softc *sc; + int ret; + + sc = (struct psp_softc *)device_lookup(&psp_cd, minor(dev)); + if (sc == NULL) + return (ENXIO); - rw_enter_write(&ccp_softc->sc_lock); + rw_enter_write(&sc->sc_lock); switch (cmd) { case PSP_IOC_GET_PSTATUS: - ret = psp_get_pstatus((struct psp_platform_status *)data); + ret = psp_get_pstatus(sc, (struct psp_platform_status *)data); break; case PSP_IOC_DF_FLUSH: - ret = psp_df_flush(); + ret = psp_df_flush(sc); break; case PSP_IOC_DECOMMISSION: - ret = psp_decommission((struct psp_decommission *)data); + ret = psp_decommission(sc, (struct psp_decommission *)data); break; case PSP_IOC_GET_GSTATUS: - ret = psp_get_gstatus((struct psp_guest_status *)data); + ret = psp_get_gstatus(sc, (struct psp_guest_status *)data); break; case PSP_IOC_LAUNCH_START: - ret = psp_launch_start((struct psp_launch_start *)data); + ret = psp_launch_start(sc, (struct psp_launch_start *)data); break; case PSP_IOC_LAUNCH_UPDATE_DATA: - ret = psp_launch_update_data( + ret = psp_launch_update_data(sc, (struct psp_launch_update_data *)data, p); break; case PSP_IOC_LAUNCH_MEASURE: - ret = psp_launch_measure((struct psp_launch_measure *)data); + ret = psp_launch_measure(sc, (struct psp_launch_measure *)data); break; case PSP_IOC_LAUNCH_FINISH: - ret = psp_launch_finish((struct psp_launch_finish *)data); + ret = psp_launch_finish(sc, (struct psp_launch_finish *)data); break; case PSP_IOC_ATTESTATION: - ret = psp_attestation((struct psp_attestation *)data); + ret = psp_attestation(sc, (struct psp_attestation *)data); break; case PSP_IOC_ACTIVATE: - ret = psp_activate((struct psp_activate *)data); + ret = psp_activate(sc, (struct psp_activate *)data); break; case PSP_IOC_DEACTIVATE: - ret = psp_deactivate((struct psp_deactivate *)data); + ret = psp_deactivate(sc, (struct psp_deactivate *)data); break; case PSP_IOC_GUEST_SHUTDOWN: - ret = psp_guest_shutdown((struct psp_guest_shutdown *)data); + ret = psp_guest_shutdown(sc, (struct psp_guest_shutdown *)data); break; case PSP_IOC_SNP_GET_PSTATUS: - ret = - psp_snp_get_pstatus((struct psp_snp_platform_status *)data); + ret = psp_snp_get_pstatus(sc, + (struct psp_snp_platform_status *)data); break; default: ret = ENOTTY; break; } - rw_exit_write(&ccp_softc->sc_lock); + rw_exit_write(&sc->sc_lock); return (ret); } @@ -657,3 +705,20 @@ pledge_ioctl_psp(struct proc *p, long com) return (pledge_fail(p, EPERM, PLEDGE_VMM)); } } + +int +pspprint(void *aux, const char *pnp) +{ + return QUIET; +} + +int +pspsubmatch(struct device *parent, void *match, void *aux) +{ + struct psp_attach_args *arg = aux; + struct cfdata *cf = match; + + if (!(arg->capabilities & PSP_CAP_SEV)) + return (0); + return ((*cf->cf_attach->ca_match)(parent, cf, aux)); +} diff --git a/sys/dev/ic/pspvar.h b/sys/dev/ic/pspvar.h index 84f715d83e0..a1d7c83849e 100644 --- a/sys/dev/ic/pspvar.h +++ b/sys/dev/ic/pspvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pspvar.h,v 1.1 2024/09/03 00:23:05 jsg Exp $ */ +/* $OpenBSD: pspvar.h,v 1.2 2024/09/04 07:45:08 jsg Exp $ */ /* * Copyright (c) 2023, 2024 Hans-Joerg Hoexer @@ -246,10 +246,16 @@ struct psp_snp_platform_status { #ifdef _KERNEL -int psp_attach(struct ccp_softc *); +struct psp_attach_args { + bus_space_tag_t iot; + bus_space_handle_t ioh; -int pspclose(dev_t, int, int, struct proc *); -int pspopen(dev_t, int, int, struct proc *); -int pspioctl(dev_t, u_long, caddr_t, int, struct proc *); + bus_dma_tag_t dmat; + uint32_t capabilities; +}; + +int pspsubmatch(struct device *, void *, void *); +int pspprint(void *aux, const char *pnp); +int psp_sev_intr(void *); #endif /* _KERNEL */ diff --git a/sys/dev/pci/ccp_pci.c b/sys/dev/pci/ccp_pci.c index 1285603eb9e..8e1168689f4 100644 --- a/sys/dev/pci/ccp_pci.c +++ b/sys/dev/pci/ccp_pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ccp_pci.c,v 1.12 2024/09/03 00:23:05 jsg Exp $ */ +/* $OpenBSD: ccp_pci.c,v 1.13 2024/09/04 07:45:08 jsg Exp $ */ /* * Copyright (c) 2018 David Gwynne @@ -29,13 +29,15 @@ #include #include +#include "psp.h" + #define CCP_PCI_BAR 0x18 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 *); -int psp_pci_intr(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), @@ -78,24 +80,20 @@ 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) { - struct ccp_softc *sc = (struct ccp_softc *)self; - struct pci_attach_args *pa = aux; +#if NPSP > 0 pci_intr_handle_t ih; const char *intrstr = NULL; - sc->sc_dmat = pa->pa_dmat; - - sc->sc_capabilities = bus_space_read_4(sc->sc_iot, sc->sc_ioh, - PSP_REG_CAPABILITIES); - /* clear and disable interrupts */ bus_space_write_4(sc->sc_iot, sc->sc_ioh, PSP_REG_INTEN, 0); bus_space_write_4(sc->sc_iot, sc->sc_ioh, PSP_REG_INTSTS, -1); @@ -107,32 +105,34 @@ psp_pci_attach(struct device *parent, struct device *self, void *aux) } intrstr = pci_intr_string(pa->pa_pc, ih); - sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, psp_pci_intr, + sc->sc_irqh = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, psp_sev_intr, sc, sc->sc_dev.dv_xname); - if (sc->sc_ih != NULL) + if (sc->sc_irqh != NULL) printf(": %s", intrstr); +#endif +} - if (!psp_attach(sc)) { - pci_intr_disestablish(pa->pa_pc, sc->sc_ih); - sc->sc_ih = NULL; +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; + arg.ioh = sc->sc_ioh; + arg.dmat = pa->pa_dmat; + arg.capabilities = bus_space_read_4(sc->sc_iot, sc->sc_ioh, + PSP_REG_CAPABILITIES); + + sc->sc_psp = config_found_sm(self, &arg, pspprint, pspsubmatch); + if (sc->sc_psp == NULL) { + pci_intr_disestablish(pa->pa_pc, sc->sc_irqh); return; } /* enable interrupts */ bus_space_write_4(sc->sc_iot, sc->sc_ioh, PSP_REG_INTEN, -1); -} - -int -psp_pci_intr(void *arg) -{ - struct ccp_softc *sc = arg; - 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); - - if (sc->sc_sev_intr) - return (sc->sc_sev_intr(sc, status)); - - return (1); +#endif } diff --git a/sys/kern/kern_pledge.c b/sys/kern/kern_pledge.c index e1483fdbd39..c51c93a1f15 100644 --- a/sys/kern/kern_pledge.c +++ b/sys/kern/kern_pledge.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_pledge.c,v 1.318 2024/09/02 11:08:41 jsg Exp $ */ +/* $OpenBSD: kern_pledge.c,v 1.319 2024/09/04 07:45:08 jsg Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott @@ -73,7 +73,7 @@ #if defined(__amd64__) #include "vmm.h" -#include "ccp.h" +#include "psp.h" #include #endif @@ -1348,7 +1348,7 @@ pledge_ioctl(struct proc *p, long com, struct file *fp) } #endif -#if NCCP > 0 +#if NPSP > 0 if ((pledge & PLEDGE_VMM)) { if ((fp->f_type == DTYPE_VNODE) && (vp->v_type == VCHR) && -- 2.20.1