VirtualBox

Changeset 90908 in vbox


Ignore:
Timestamp:
Aug 26, 2021 10:27:04 AM (3 years ago)
Author:
vboxsync
Message:

Devices/ACPI: Preliminary TPM support (disabled), bugref:10075

Location:
trunk/src/VBox/Devices
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Makefile.kmk

    r90530 r90908  
    907907        $(VBoxDD_0_OUTDIR)/vboxssdt_cpuhotplug.aml \
    908908        $(VBoxDD_0_OUTDIR)/vboxssdt_cpuhotplug.aml.tmp \
    909         $(VBoxDD_0_OUTDIR)/vboxssdt_cpuhotplug.aml.pre
     909        $(VBoxDD_0_OUTDIR)/vboxssdt_cpuhotplug.aml.pre \
     910        $(if $(VBOX_WITH_TPM),$(VBoxDD_0_OUTDIR)/vboxssdt_tpm.hex,) \
     911        $(if $(VBOX_WITH_TPM),$(VBoxDD_0_OUTDIR)/vboxssdt_tpm.aml,) \
     912        $(if $(VBOX_WITH_TPM),$(VBoxDD_0_OUTDIR)/vboxssdt_tpm.aml.tmp,)
    910913  PC/ACPI/VBoxAcpi.cpp_DEPS = \
    911914        $(VBoxDD_0_OUTDIR)/vboxaml.hex \
    912915        $(VBoxDD_0_OUTDIR)/vboxssdt_standard.hex \
    913         $(VBoxDD_0_OUTDIR)/vboxssdt_cpuhotplug.hex
     916        $(VBoxDD_0_OUTDIR)/vboxssdt_cpuhotplug.hex \
     917        $(if $(VBOX_WITH_TPM),$(VBoxDD_0_OUTDIR)/vboxssdt_tpm.hex,)
    914918
    915919  $$(VBoxDD_0_OUTDIR)/vboxaml.hex: $(PATH_SUB_CURRENT)/PC/vbox.dsl | $$(dir $$@)
     
    949953
    950954  vboxssdt_cpuhotplug.hex:: $$(VBoxDD_0_OUTDIR)/vboxssdt_cpuhotplug.hex
     955
     956  if defined(VBOX_WITH_TPM)
     957   $$(VBoxDD_0_OUTDIR)/vboxssdt_tpm.hex: $(PATH_SUB_CURRENT)/PC/vbox-tpm.dsl | $$(dir $$@)
     958        $(call MSG_TOOL,iasl,VBoxDD,$<,$@)
     959        $(QUIET)$(RM) -f $@ $@.tmp
     960        $(QUIET)$(VBOX_IASLCMD) -tc -vs -p $@ $<
     961        $(QUIET)$(MV) -f $@ $@.tmp
     962        $(QUIET)$(SED) -e "s/AmlCode\|vboxssdt_tpm_aml_code/AmlCodeSsdtTpm/g" \
     963                --output $@ $@.tmp
     964        $(QUIET)$(RM) -f $@.tmp
     965
     966   vboxssdt_tpm.hex:: $$(VBoxDD_0_OUTDIR)/vboxssdt_tpm.hex
     967  endif # !VBOX_WITH_TPM
    951968
    952969 endif # !VBOX_WITH_DYNAMIC_DSDT
     
    13381355 endif
    13391356
     1357 if defined(VBOX_WITH_TPM)
     1358  VBoxDDR0_DEFS         += VBOX_WITH_TPM
     1359  VBoxDDR0_SOURCES      += \
     1360        Security/DevTpm.cpp
     1361 endif
     1362
    13401363 ifdef VBOX_WITH_HGSMI
    13411364  VBoxDDR0_DEFS         += VBOX_WITH_HGSMI
  • trunk/src/VBox/Devices/PC/ACPI/VBoxAcpi.cpp

    r85992 r90908  
    4545# include <vboxssdt_standard.hex>
    4646# include <vboxssdt_cpuhotplug.hex>
     47# ifdef VBOX_WITH_TPM
     48#  include <vboxssdt_tpm.hex>
     49# endif
    4750#endif
    4851
     
    443446}
    444447
     448#ifdef VBOX_WITH_TPM
     449/** No docs, lazy coder. */
     450int acpiPrepareTpmSsdt(PPDMDEVINS pDevIns, void **ppvPtr, size_t *pcbSsdt)
     451{
     452    uint8_t *pabAmlCodeSsdt = NULL;
     453    size_t   cbAmlCodeSsdt = 0;
     454    int rc = acpiAmlLoadExternal(pDevIns, "SsdtTpmFilePath", "SSDT", &pabAmlCodeSsdt, &cbAmlCodeSsdt);
     455    if (rc == VERR_CFGM_VALUE_NOT_FOUND)
     456    {
     457        rc = VINF_SUCCESS;
     458        cbAmlCodeSsdt  = sizeof(AmlCodeSsdtTpm);
     459        pabAmlCodeSsdt = (uint8_t *)RTMemDup(AmlCodeSsdtTpm, sizeof(AmlCodeSsdtTpm));
     460        if (!pabAmlCodeSsdt)
     461            rc = VERR_NO_MEMORY;
     462    }
     463    else if (RT_FAILURE(rc))
     464        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to read \"SsdtFilePath\""));
     465
     466    if (RT_SUCCESS(rc))
     467    {
     468        *ppvPtr = pabAmlCodeSsdt;
     469        *pcbSsdt = cbAmlCodeSsdt;
     470    }
     471    return rc;
     472}
     473
     474/** No docs, lazy coder. */
     475int acpiCleanupTpmSsdt(PPDMDEVINS pDevIns, void *pvPtr)
     476{
     477    RT_NOREF1(pDevIns);
     478    if (pvPtr)
     479        RTMemFree(pvPtr);
     480    return VINF_SUCCESS;
     481}
     482#endif
     483
  • trunk/src/VBox/Devices/PC/DevACPI.cpp

    r90447 r90908  
    296296*   Structures and Typedefs                                                                                                      *
    297297*********************************************************************************************************************************/
     298/**
     299 * The TPM mode configured.
     300 */
     301typedef enum ACPITPMMODE
     302{
     303    ACPITPMMODE_INVALID = 0,
     304    ACPITPMMODE_DISABLED,
     305    ACPITPMMODE_TIS_1_2,
     306    ACPITPMMODE_CRB_2_0,
     307    ACPITPMMODE_FIFO_2_0,
     308    ACPITPMMODE_32BIT_HACK = 0x7fffffff
     309} ACPITPMMODE;
     310
     311
    298312/**
    299313 * The shared ACPI device state.
     
    439453    uint8_t             uParallel1Irq;
    440454    /** @} */
     455
     456#ifdef VBOX_WITH_TPM
     457    /** @name TPM config bits
     458     * @{ */
     459    /** The ACPI TPM mode configured. */
     460    ACPITPMMODE         enmTpmMode;
     461    /** The MMIO register area base address. */
     462    RTGCPHYS            GCPhysTpmMmio;
     463    /** @} */
     464#endif
    441465
    442466    /** Number of custom ACPI tables */
     
    900924
    901925
     926#ifdef VBOX_WITH_TPM
     927/**
     928 * TPM: The ACPI table for a TPM 2.0 device
     929  * (from: https://trustedcomputinggroup.org/wp-content/uploads/TCG_ACPIGeneralSpec_v1p3_r8_pub.pdf).
     930 */
     931typedef struct ACPITBLTPM20
     932{
     933    /** The common ACPI table header. */
     934    ACPITBLHEADER       Hdr;
     935    /** The platform class. */
     936    uint16_t            u16PlatCls;
     937    /** Reserved. */
     938    uint16_t            u16Rsvd0;
     939    /** Address of the CRB control area or FIFO base address. */
     940    uint64_t            u64BaseAddrCrbOrFifo;
     941    /** The start method selector. */
     942    uint32_t            u32StartMethod;
     943    /** Following are start method specific parameters and optional LAML and LASA fields we don't implement right now. */
     944    /** @todo */
     945} ACPITBLTPM20;
     946AssertCompileSize(ACPITBLTPM20, 52);
     947
     948/** Revision of the TPM2.0 ACPI table. */
     949#define ACPI_TPM20_REVISION                 4
     950/** The default MMIO base address of the TPM. */
     951#define ACPI_TPM_MMIO_BASE_DEFAULT          0xfed40000
     952
     953
     954/** @name Possible values for the ACPITBLTPM20::u16PlatCls member.
     955 * @{ */
     956/** Client platform. */
     957#define ACPITBL_TPM20_PLAT_CLS_CLIENT       UINT16_C(0)
     958/** Server platform. */
     959#define ACPITBL_TPM20_PLAT_CLS_SERVER       UINT16_C(1)
     960/** @} */
     961
     962
     963/** @name Possible values for the ACPITBLTPM20::u32StartMethod member.
     964 * @{ */
     965/** MMIO interface (TIS1.2+Cancel). */
     966#define ACPITBL_TPM20_START_METHOD_TIS12    UINT16_C(6)
     967/** CRB interface. */
     968#define ACPITBL_TPM20_START_METHOD_CRB      UINT16_C(7)
     969/** @} */
     970#endif
     971
     972
    902973#pragma pack()
    903974
     
    28122883    acpiR3PhysCopy(pDevIns, addr, pvSrc, uSsdtLen);
    28132884}
     2885
     2886#ifdef VBOX_WITH_TPM
     2887/**
     2888 * Plant the Secondary System Description Table (SSDT).
     2889 */
     2890static void acpiR3SetupTpmSsdt(PPDMDEVINS pDevIns, RTGCPHYS32 addr, void const *pvSrc, size_t uSsdtLen)
     2891{
     2892    acpiR3PhysCopy(pDevIns, addr, pvSrc, uSsdtLen);
     2893}
     2894#endif
    28142895
    28152896/**
     
    34153496
    34163497
     3498#ifdef VBOX_WITH_TPM
     3499/**
     3500 * Plant the TPM 2.0 ACPI descriptor.
     3501 */
     3502static void acpiR3SetupTpm(PPDMDEVINS pDevIns, PACPISTATE pThis, RTGCPHYS32 addr)
     3503{
     3504    ACPITBLTPM20 Tpm2Tbl;
     3505    RT_ZERO(Tpm2Tbl);
     3506
     3507    acpiR3PrepareHeader(pThis, &Tpm2Tbl.Hdr, "TPM2", sizeof(ACPITBLTPM20), ACPI_TPM20_REVISION);
     3508
     3509    switch (pThis->enmTpmMode)
     3510    {
     3511        case ACPITPMMODE_CRB_2_0:
     3512            Tpm2Tbl.u32StartMethod       = ACPITBL_TPM20_START_METHOD_CRB;
     3513            Tpm2Tbl.u64BaseAddrCrbOrFifo = pThis->GCPhysTpmMmio;
     3514            break;
     3515        case ACPITPMMODE_TIS_1_2:
     3516        case ACPITPMMODE_FIFO_2_0:
     3517            Tpm2Tbl.u32StartMethod = ACPITBL_TPM20_START_METHOD_TIS12;
     3518            break;
     3519        case ACPITPMMODE_DISABLED: /* Should never be called with the TPM disabled. */
     3520        default:
     3521            AssertFailed();
     3522    }
     3523
     3524    Tpm2Tbl.u16PlatCls = ACPITBL_TPM20_PLAT_CLS_CLIENT;
     3525
     3526    /* Finally, compute checksum. */
     3527    Tpm2Tbl.Hdr.u8Checksum = acpiR3Checksum(&Tpm2Tbl, sizeof(Tpm2Tbl));
     3528
     3529    /* Plant the ACPI table. */
     3530    acpiR3PhysCopy(pDevIns, addr, (const uint8_t *)&Tpm2Tbl, sizeof(Tpm2Tbl));
     3531}
     3532#endif
     3533
     3534
    34173535/**
    34183536 * Used by acpiR3PlantTables to plant a MMCONFIG PCI config space access (MCFG)
     
    35173635    RTGCPHYS32 GCPhysIommu = 0;
    35183636#endif
     3637#ifdef VBOX_WITH_TPM
     3638    RTGCPHYS32 GCPhysTpm  = 0;
     3639    RTGCPHYS32 GCPhysSsdtTpm  = 0;
     3640#endif
    35193641    RTGCPHYS32 GCPhysApic = 0;
    35203642    RTGCPHYS32 GCPhysSsdt = 0;
     
    35233645    uint32_t   addend = 0;
    35243646#if defined(VBOX_WITH_IOMMU_AMD) || defined(VBOX_WITH_IOMMU_INTEL)
     3647# ifdef VBOX_WITH_TPM
     3648    RTGCPHYS32 aGCPhysRsdt[10 + MAX_CUST_TABLES];
     3649    RTGCPHYS32 aGCPhysXsdt[10 + MAX_CUST_TABLES];
     3650# else
    35253651    RTGCPHYS32 aGCPhysRsdt[8 + MAX_CUST_TABLES];
    35263652    RTGCPHYS32 aGCPhysXsdt[8 + MAX_CUST_TABLES];
     3653# endif
    35273654#else
     3655# ifdef VBOX_WITH_TPM
     3656    RTGCPHYS32 aGCPhysRsdt[9 + MAX_CUST_TABLES];
     3657    RTGCPHYS32 aGCPhysXsdt[9 + MAX_CUST_TABLES];
     3658# else
    35283659    RTGCPHYS32 aGCPhysRsdt[7 + MAX_CUST_TABLES];
    35293660    RTGCPHYS32 aGCPhysXsdt[7 + MAX_CUST_TABLES];
     3661# endif
    35303662#endif
    35313663    uint32_t   cAddr;
     
    35353667    uint32_t   iIommu = 0;
    35363668#endif
     3669#ifdef VBOX_WITH_TPM
     3670    uint32_t   iTpm   = 0;
     3671    uint32_t   iSsdtTpm   = 0;
     3672#endif
    35373673    uint32_t   iSsdt  = 0;
    35383674    uint32_t   iMcfg  = 0;
     
    35563692    if (pThis->fUseIommuIntel)
    35573693        iIommu = cAddr++;      /* IOMMU (Intel) */
     3694#endif
     3695
     3696#ifdef VBOX_WITH_TPM
     3697    if (pThis->enmTpmMode != ACPITPMMODE_DISABLED)
     3698    {
     3699        iTpm     = cAddr++;   /* TPM device */
     3700        iSsdtTpm = cAddr++;
     3701    }
    35583702#endif
    35593703
     
    36443788        GCPhysIommu = GCPhysCur;
    36453789        GCPhysCur = RT_ALIGN_32(GCPhysCur + sizeof(ACPITBLVTD), 16);
     3790    }
     3791#endif
     3792#ifdef VBOX_WITH_TPM
     3793    void  *pvSsdtTpmCode = NULL;
     3794    size_t cbSsdtTpm = 0;
     3795
     3796    if (pThis->enmTpmMode != ACPITPMMODE_DISABLED)
     3797    {
     3798        GCPhysTpm = GCPhysCur;
     3799        GCPhysCur = RT_ALIGN_32(GCPhysCur + sizeof(ACPITBLTPM20), 16); /** @todo TPM1.2 */
     3800
     3801        rc = acpiPrepareTpmSsdt(pDevIns, &pvSsdtTpmCode, &cbSsdtTpm);
     3802        if (RT_FAILURE(rc))
     3803            return rc;
     3804
     3805        GCPhysSsdtTpm = GCPhysCur;
     3806        GCPhysCur = RT_ALIGN_32(GCPhysCur + cbSsdtTpm, 16);
    36463807    }
    36473808#endif
     
    37353896    }
    37363897#endif
     3898#ifdef VBOX_WITH_TPM
     3899    if (pThis->enmTpmMode != ACPITPMMODE_DISABLED)
     3900    {
     3901        acpiR3SetupTpm(pDevIns, pThis, GCPhysTpm + addend);
     3902        aGCPhysRsdt[iTpm] = GCPhysTpm + addend;
     3903        aGCPhysXsdt[iTpm] = GCPhysTpm + addend;
     3904
     3905        acpiR3SetupTpmSsdt(pDevIns, GCPhysSsdtTpm + addend, pvSsdtTpmCode, cbSsdtTpm);
     3906        acpiCleanupTpmSsdt(pDevIns, pvSsdtTpmCode);
     3907        aGCPhysRsdt[iSsdtTpm] = GCPhysSsdtTpm + addend;
     3908        aGCPhysXsdt[iSsdtTpm] = GCPhysSsdtTpm + addend;
     3909    }
     3910#endif
     3911
    37373912    if (pThis->fUseMcfg)
    37383913    {
     
    40954270                                  "|IommuPciAddress"
    40964271                                  "|SbIoApicPciAddress"
     4272                                  "|TpmMode"
     4273                                  "|TpmMmioAddress"
     4274                                  "|SsdtTpmFilePath"
    40974275                                  , "");
    40984276
     
    43174495        && pThis->fUseIommuIntel)
    43184496        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Cannot enable Intel and AMD IOMMU simultaneously!"));
     4497
     4498#ifdef VBOX_WITH_TPM
     4499    char szTpmMode[64]; RT_ZERO(szTpmMode);
     4500
     4501    rc = pHlp->pfnCFGMQueryStringDef(pCfg, "TpmMode", &szTpmMode[0], RT_ELEMENTS(szTpmMode) - 1, "disabled");
     4502    if (RT_FAILURE(rc))
     4503        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to read \"TpmMode\""));
     4504
     4505    if (!RTStrICmp(szTpmMode, "disabled"))
     4506        pThis->enmTpmMode = ACPITPMMODE_DISABLED;
     4507    else if (!RTStrICmp(szTpmMode, "tis1.2"))
     4508        pThis->enmTpmMode = ACPITPMMODE_TIS_1_2;
     4509    else if (!RTStrICmp(szTpmMode, "crb2.0"))
     4510        pThis->enmTpmMode = ACPITPMMODE_CRB_2_0;
     4511    else if (!RTStrICmp(szTpmMode, "fifo2.0"))
     4512        pThis->enmTpmMode = ACPITPMMODE_FIFO_2_0;
     4513    else
     4514        return PDMDEV_SET_ERROR(pDevIns, VERR_INVALID_PARAMETER, N_("Configuration error: Value of \"TpmMode\" is not known"));
     4515
     4516    rc = pHlp->pfnCFGMQueryU64Def(pCfg, "TpmMmioAddress", (uint64_t *)&pThis->GCPhysTpmMmio, ACPI_TPM_MMIO_BASE_DEFAULT);
     4517    if (RT_FAILURE(rc))
     4518        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to read \"TpmMmioAddress\""));
     4519#endif
    43194520
    43204521    /* Try to attach the other CPUs */
  • trunk/src/VBox/Devices/build/VBoxDD.h

    r90530 r90908  
    214214int acpiCleanupSsdt(PPDMDEVINS pDevIns, void *pvPtr);
    215215
     216#ifdef VBOX_WITH_TPM
     217int acpiPrepareTpmSsdt(PPDMDEVINS pDevIns, void **ppvPtr, size_t *pcbSsdt);
     218int acpiCleanupTpmSsdt(PPDMDEVINS pDevIns, void *pvPtr);
     219#endif
     220
    216221RT_C_DECLS_END
    217222
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette