X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=UefiCpuPkg%2FPiSmmCpuDxeSmm%2FSmmCpuMemoryManagement.c;h=2d7dba59bf30370241c06f22bb4e690a9533846d;hb=827330ccd1d0983fe4d059fee518bf42c70ef31e;hp=55c04c7aa79b6bdcdaeac55fa7bdf25f2f04f685;hpb=e63da9f033274843163908ccefa95c892d7944e5;p=mirror_edk2.git diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c index 55c04c7aa7..2d7dba59bf 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c @@ -1120,166 +1120,166 @@ IsSmmCommBufferForbiddenAddress ( } return FALSE; } - -/** - This function set given attributes of the memory region specified by - BaseAddress and Length. - - @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance. - @param BaseAddress The physical address that is the start address of - a memory region. - @param Length The size in bytes of the memory region. - @param Attributes The bit mask of attributes to set for the memory - region. - - @retval EFI_SUCCESS The attributes were set for the memory region. - @retval EFI_INVALID_PARAMETER Length is zero. - Attributes specified an illegal combination of - attributes that cannot be set together. - @retval EFI_UNSUPPORTED The processor does not support one or more - bytes of the memory resource range specified - by BaseAddress and Length. - The bit mask of attributes is not support for - the memory resource range specified by - BaseAddress and Length. - -**/ -EFI_STATUS -EFIAPI -EdkiiSmmSetMemoryAttributes ( - IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This, - IN EFI_PHYSICAL_ADDRESS BaseAddress, - IN UINT64 Length, - IN UINT64 Attributes - ) -{ - return SmmSetMemoryAttributes (BaseAddress, Length, Attributes); -} - -/** - This function clears given attributes of the memory region specified by - BaseAddress and Length. - - @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance. - @param BaseAddress The physical address that is the start address of - a memory region. - @param Length The size in bytes of the memory region. - @param Attributes The bit mask of attributes to set for the memory - region. - - @retval EFI_SUCCESS The attributes were set for the memory region. - @retval EFI_INVALID_PARAMETER Length is zero. - Attributes specified an illegal combination of - attributes that cannot be set together. - @retval EFI_UNSUPPORTED The processor does not support one or more - bytes of the memory resource range specified - by BaseAddress and Length. - The bit mask of attributes is not support for - the memory resource range specified by - BaseAddress and Length. - -**/ -EFI_STATUS -EFIAPI -EdkiiSmmClearMemoryAttributes ( - IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This, - IN EFI_PHYSICAL_ADDRESS BaseAddress, - IN UINT64 Length, - IN UINT64 Attributes - ) -{ - return SmmClearMemoryAttributes (BaseAddress, Length, Attributes); -} - -/** - This function retrieve the attributes of the memory region specified by - BaseAddress and Length. If different attributes are got from different part - of the memory region, EFI_NO_MAPPING will be returned. - - @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance. - @param BaseAddress The physical address that is the start address of - a memory region. - @param Length The size in bytes of the memory region. - @param Attributes Pointer to attributes returned. - - @retval EFI_SUCCESS The attributes got for the memory region. - @retval EFI_INVALID_PARAMETER Length is zero. - Attributes is NULL. - @retval EFI_NO_MAPPING Attributes are not consistent cross the memory - region. - @retval EFI_UNSUPPORTED The processor does not support one or more - bytes of the memory resource range specified - by BaseAddress and Length. - The bit mask of attributes is not support for - the memory resource range specified by - BaseAddress and Length. - -**/ -EFI_STATUS -EFIAPI -EdkiiSmmGetMemoryAttributes ( - IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This, - IN EFI_PHYSICAL_ADDRESS BaseAddress, - IN UINT64 Length, - OUT UINT64 *Attributes - ) -{ - EFI_PHYSICAL_ADDRESS Address; - UINT64 *PageEntry; - UINT64 MemAttr; - PAGE_ATTRIBUTE PageAttr; - INT64 Size; - - if (Length < SIZE_4KB || Attributes == NULL) { - return EFI_INVALID_PARAMETER; - } - - Size = (INT64)Length; - MemAttr = (UINT64)-1; - - do { - - PageEntry = GetPageTableEntry (BaseAddress, &PageAttr); - if (PageEntry == NULL || PageAttr == PageNone) { - return EFI_UNSUPPORTED; - } - - // - // If the memory range is cross page table boundary, make sure they - // share the same attribute. Return EFI_NO_MAPPING if not. - // - *Attributes = GetAttributesFromPageEntry (PageEntry); - if (MemAttr != (UINT64)-1 && *Attributes != MemAttr) { - return EFI_NO_MAPPING; - } - - switch (PageAttr) { - case Page4K: - Address = *PageEntry & ~mAddressEncMask & PAGING_4K_ADDRESS_MASK_64; - Size -= (SIZE_4KB - (BaseAddress - Address)); - BaseAddress += (SIZE_4KB - (BaseAddress - Address)); - break; - - case Page2M: - Address = *PageEntry & ~mAddressEncMask & PAGING_2M_ADDRESS_MASK_64; - Size -= SIZE_2MB - (BaseAddress - Address); - BaseAddress += SIZE_2MB - (BaseAddress - Address); - break; - - case Page1G: - Address = *PageEntry & ~mAddressEncMask & PAGING_1G_ADDRESS_MASK_64; - Size -= SIZE_1GB - (BaseAddress - Address); - BaseAddress += SIZE_1GB - (BaseAddress - Address); - break; - - default: - return EFI_UNSUPPORTED; - } - - MemAttr = *Attributes; - - } while (Size > 0); - - return EFI_SUCCESS; -} - + +/** + This function set given attributes of the memory region specified by + BaseAddress and Length. + + @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance. + @param BaseAddress The physical address that is the start address of + a memory region. + @param Length The size in bytes of the memory region. + @param Attributes The bit mask of attributes to set for the memory + region. + + @retval EFI_SUCCESS The attributes were set for the memory region. + @retval EFI_INVALID_PARAMETER Length is zero. + Attributes specified an illegal combination of + attributes that cannot be set together. + @retval EFI_UNSUPPORTED The processor does not support one or more + bytes of the memory resource range specified + by BaseAddress and Length. + The bit mask of attributes is not support for + the memory resource range specified by + BaseAddress and Length. + +**/ +EFI_STATUS +EFIAPI +EdkiiSmmSetMemoryAttributes ( + IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length, + IN UINT64 Attributes + ) +{ + return SmmSetMemoryAttributes (BaseAddress, Length, Attributes); +} + +/** + This function clears given attributes of the memory region specified by + BaseAddress and Length. + + @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance. + @param BaseAddress The physical address that is the start address of + a memory region. + @param Length The size in bytes of the memory region. + @param Attributes The bit mask of attributes to set for the memory + region. + + @retval EFI_SUCCESS The attributes were set for the memory region. + @retval EFI_INVALID_PARAMETER Length is zero. + Attributes specified an illegal combination of + attributes that cannot be set together. + @retval EFI_UNSUPPORTED The processor does not support one or more + bytes of the memory resource range specified + by BaseAddress and Length. + The bit mask of attributes is not support for + the memory resource range specified by + BaseAddress and Length. + +**/ +EFI_STATUS +EFIAPI +EdkiiSmmClearMemoryAttributes ( + IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length, + IN UINT64 Attributes + ) +{ + return SmmClearMemoryAttributes (BaseAddress, Length, Attributes); +} + +/** + This function retrieve the attributes of the memory region specified by + BaseAddress and Length. If different attributes are got from different part + of the memory region, EFI_NO_MAPPING will be returned. + + @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance. + @param BaseAddress The physical address that is the start address of + a memory region. + @param Length The size in bytes of the memory region. + @param Attributes Pointer to attributes returned. + + @retval EFI_SUCCESS The attributes got for the memory region. + @retval EFI_INVALID_PARAMETER Length is zero. + Attributes is NULL. + @retval EFI_NO_MAPPING Attributes are not consistent cross the memory + region. + @retval EFI_UNSUPPORTED The processor does not support one or more + bytes of the memory resource range specified + by BaseAddress and Length. + The bit mask of attributes is not support for + the memory resource range specified by + BaseAddress and Length. + +**/ +EFI_STATUS +EFIAPI +EdkiiSmmGetMemoryAttributes ( + IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length, + OUT UINT64 *Attributes + ) +{ + EFI_PHYSICAL_ADDRESS Address; + UINT64 *PageEntry; + UINT64 MemAttr; + PAGE_ATTRIBUTE PageAttr; + INT64 Size; + + if (Length < SIZE_4KB || Attributes == NULL) { + return EFI_INVALID_PARAMETER; + } + + Size = (INT64)Length; + MemAttr = (UINT64)-1; + + do { + + PageEntry = GetPageTableEntry (BaseAddress, &PageAttr); + if (PageEntry == NULL || PageAttr == PageNone) { + return EFI_UNSUPPORTED; + } + + // + // If the memory range is cross page table boundary, make sure they + // share the same attribute. Return EFI_NO_MAPPING if not. + // + *Attributes = GetAttributesFromPageEntry (PageEntry); + if (MemAttr != (UINT64)-1 && *Attributes != MemAttr) { + return EFI_NO_MAPPING; + } + + switch (PageAttr) { + case Page4K: + Address = *PageEntry & ~mAddressEncMask & PAGING_4K_ADDRESS_MASK_64; + Size -= (SIZE_4KB - (BaseAddress - Address)); + BaseAddress += (SIZE_4KB - (BaseAddress - Address)); + break; + + case Page2M: + Address = *PageEntry & ~mAddressEncMask & PAGING_2M_ADDRESS_MASK_64; + Size -= SIZE_2MB - (BaseAddress - Address); + BaseAddress += SIZE_2MB - (BaseAddress - Address); + break; + + case Page1G: + Address = *PageEntry & ~mAddressEncMask & PAGING_1G_ADDRESS_MASK_64; + Size -= SIZE_1GB - (BaseAddress - Address); + BaseAddress += SIZE_1GB - (BaseAddress - Address); + break; + + default: + return EFI_UNSUPPORTED; + } + + MemAttr = *Attributes; + + } while (Size > 0); + + return EFI_SUCCESS; +} +