|
| 1 | +/** @file |
| 2 | +
|
| 3 | + Update the patched PCDs to their correct value |
| 4 | +
|
| 5 | + Copyright (c) 2020, Linaro Ltd. All rights reserved.<BR> |
| 6 | +
|
| 7 | + SPDX-License-Identifier: BSD-2-Clause-Patent |
| 8 | +
|
| 9 | +**/ |
| 10 | + |
| 11 | +/** |
| 12 | + * Patch the relevant PCDs of the RPMB driver with the correct address of the |
| 13 | + * allocated memory |
| 14 | + * |
| 15 | +**/ |
| 16 | +#include <Library/BaseLib.h> |
| 17 | +#include <Library/DebugLib.h> |
| 18 | +#include <Library/MmServicesTableLib.h> |
| 19 | +#include <Library/PcdLib.h> |
| 20 | + |
| 21 | +#include <Protocol/FirmwareVolumeBlock.h> |
| 22 | +#include <Protocol/SmmFirmwareVolumeBlock.h> |
| 23 | + |
| 24 | +#include "OpTeeRpmbFvb.h" |
| 25 | + |
| 26 | +/** |
| 27 | + Fixup the Pcd values for variable storage |
| 28 | +
|
| 29 | + Since the upper layers of EDK2 expect a memory mapped interface and we can't |
| 30 | + offer that from an RPMB, the driver allocates memory on init and passes that |
| 31 | + on the upper layers. Since the memory is dynamically allocated and we can't set the |
| 32 | + PCD is StMM context, we need to patch it correctly on each access |
| 33 | +
|
| 34 | + @retval EFI_SUCCESS Protocol was found and PCDs patched up |
| 35 | +
|
| 36 | + **/ |
| 37 | +EFI_STATUS |
| 38 | +EFIAPI |
| 39 | +FixPcdMemory ( |
| 40 | + VOID |
| 41 | + ) |
| 42 | +{ |
| 43 | + EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol; |
| 44 | + MEM_INSTANCE *Instance; |
| 45 | + EFI_STATUS Status; |
| 46 | + |
| 47 | + // |
| 48 | + // Locate SmmFirmwareVolumeBlockProtocol |
| 49 | + // |
| 50 | + Status = gMmst->MmLocateProtocol ( |
| 51 | + &gEfiSmmFirmwareVolumeBlockProtocolGuid, |
| 52 | + NULL, |
| 53 | + (VOID **) &FvbProtocol |
| 54 | + ); |
| 55 | + ASSERT_EFI_ERROR (Status); |
| 56 | + |
| 57 | + Instance = INSTANCE_FROM_FVB_THIS(FvbProtocol); |
| 58 | + // Patch PCDs with the the correct values |
| 59 | + PatchPcdSet32 (PcdFlashNvStorageVariableBase, Instance->MemBaseAddress); |
| 60 | + PatchPcdSet32 (PcdFlashNvStorageFtwWorkingBase, Instance->MemBaseAddress + |
| 61 | + PcdGet32 (PcdFlashNvStorageVariableSize)); |
| 62 | + PatchPcdSet32 (PcdFlashNvStorageFtwSpareBase, Instance->MemBaseAddress + |
| 63 | + PcdGet32 (PcdFlashNvStorageVariableSize) + |
| 64 | + PcdGet32 (PcdFlashNvStorageFtwWorkingSize)); |
| 65 | + |
| 66 | + DEBUG ((DEBUG_INFO, "%a: Fixup PcdFlashNvStorageVariableBase: 0x%lx\n", |
| 67 | + __FUNCTION__, PcdGet32 (PcdFlashNvStorageVariableBase))); |
| 68 | + DEBUG ((DEBUG_INFO, "%a: Fixup PcdFlashNvStorageFtwWorkingBase: 0x%lx\n", |
| 69 | + __FUNCTION__, PcdGet32 (PcdFlashNvStorageFtwWorkingBase))); |
| 70 | + DEBUG ((DEBUG_INFO, "%a: Fixup PcdFlashNvStorageFtwSpareBase: 0x%lx\n", |
| 71 | + __FUNCTION__, PcdGet32 (PcdFlashNvStorageFtwSpareBase))); |
| 72 | + |
| 73 | + return Status; |
| 74 | +} |
0 commit comments