]> xenbits.xensource.com Git - ovmf.git/log
ovmf.git
2 years agoMdeModulePkg/Include/Ppi: Add FirmwareVolumeShadowPpi
Umang Patel [Fri, 13 Jan 2023 11:01:14 +0000 (03:01 -0800)]
MdeModulePkg/Include/Ppi: Add FirmwareVolumeShadowPpi

Add FirmwareVolumeShadow PPI to shadow an FV to memory.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Patel Umang <umang.patel@intel.com>
Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
2 years agoUefiCpuPkg/CpuPageTableLib: Reduce the number of random tests
Dun Tan [Wed, 22 Mar 2023 08:28:55 +0000 (16:28 +0800)]
UefiCpuPkg/CpuPageTableLib: Reduce the number of random tests

Reduce the number of random tests. In previous patch, non-1:1
mapping is enbaled and it may need more than an hour and a half
for the CI test, which may lead to CI timeout. Reduce the number
of random test count to pass the CI.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoUefiCpuPkg/CpuPageTableLib: Add RandomTest for PAE paging
Dun Tan [Wed, 22 Mar 2023 04:14:30 +0000 (12:14 +0800)]
UefiCpuPkg/CpuPageTableLib: Add RandomTest for PAE paging

Add RandomTest for PAE paging.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoUefiCpuPkg/CpuPageTableLib: Enable PAE paging
Dun Tan [Wed, 22 Mar 2023 07:20:20 +0000 (15:20 +0800)]
UefiCpuPkg/CpuPageTableLib: Enable PAE paging

Modify CpuPageTableLib code to enable PAE paging.
In PageTableMap() API:
When creating new PAE page table, after creating page table,
set all MustBeZero fields of 4 PDPTE to 0. The MustBeZero
fields are treated as RW and other attributes by the common
map logic. So they might be set to 1.
When updating exsiting PAE page table, the special steps are:
1.Prepare 4K-aligned 32bytes memory in stack for 4 temp PDPTE.
2.Copy original 4 PDPTE to the 4 temp PDPTE and set the RW,
  UserSupervisor to 1 and set Nx of 4 temp PDPTE to 0.
4.After updating the page table, set the MustBeZero fields of
  4 temp PDPTE to 0.
5.Copy the temp PDPTE to original PDPTE.

In PageTableParse() API, also create 4 temp PDPTE in stack.
Copy original 4 PDPTE to the 4 temp PDPTE. Then set the RW,
UserSupervisor to 1 and set Nx of 4 temp PDPTE to 0. Finally
use the address of temp PDPTE as the page table address.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoUefiCpuPkg: Combine branch for non-present and leaf ParentEntry
Dun Tan [Thu, 23 Mar 2023 07:16:20 +0000 (15:16 +0800)]
UefiCpuPkg: Combine branch for non-present and leaf ParentEntry

Combine 'if' condition branch for non-present and leaf Parent
Entry in PageTableLibMapInLevel. Most steps of these two condition
are the same. This commit doesn't change any functionality.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoUefiCpuPkg/CpuPageTableLib: Add check for page table creation
Dun Tan [Mon, 20 Mar 2023 04:24:17 +0000 (12:24 +0800)]
UefiCpuPkg/CpuPageTableLib: Add check for page table creation

Add code to compare ParentPagingEntry Attribute&Mask and input
Attribute&Mask to decide if new next level page table is needed
in non-present ParentPagingEntry condition. This can help avoid
unneccessary page table creation.

For example, there is a page table in which [0, 1G] is mapped(Lv4[0]
,Lv3[0,0], a non-leaf level4 entry and a leaf level3 entry).And we
only want to map [1G, 1G+2M] linear address still as non-present.
The expected behaviour should be nothing happens in the process.
However, previous code logic doesn't check if ParentPagingEntry
Attribute&Mask and input Attribute&Mask are the same in non-present
ParentPagingEntry condition. Then a new 4K memory is allocated for
Lv2 since 1G+2M is not 1G-aligned.
So when ParentPagingEntry is non-present, before allocate 4K memory
for next level paging, we also check if ParentPagingEntry Attribute&
Mask and input Attribute&Mask are the same.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoUefiCpuPkg: Modify UnitTest code since tested API is changed
Zhiguang Liu [Tue, 7 Mar 2023 06:21:54 +0000 (14:21 +0800)]
UefiCpuPkg: Modify UnitTest code since tested API is changed

Last commit changed the CpuPageTableLib API PageTableMap, unit
test code should also be modified.

Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
2 years agoUefiCpuPkg: Fix IA32 build failure in CpuPageTableLib.inf
Zhiguang Liu [Tue, 7 Mar 2023 05:55:43 +0000 (13:55 +0800)]
UefiCpuPkg: Fix IA32 build failure in CpuPageTableLib.inf

The definition of IA32_MAP_ATTRIBUTE has 64 bits, and one of the bit
field PageTableBaseAddress is from bit 12 to bit 52. This means if the
compiler treats the 64bits value as two UINT32 value, the field
PageTableBaseAddress spans two UINT32 value. That's why when building in
NOOPT mode in IA32, the below issue is noticed:
unresolved external symbol __allshl
This patch fix the build failure by seperate field PageTableBaseAddress
into two fields, make sure no field spans two UINT32 value.

Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
Signed-off-by: Ray Ni <ray.ni@intel.com>
2 years agoUefiCpuPkg/CpuPageTableLib: Modify RandomTest to check IsModified
Dun Tan [Tue, 7 Mar 2023 07:25:27 +0000 (15:25 +0800)]
UefiCpuPkg/CpuPageTableLib: Modify RandomTest to check IsModified

Modify RandomTest to check if parameter IsModified of
PageTableMap() correctlly indicates whether input page table
is modified or not.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
2 years agoUefiCpuPkg/CpuPageTableLib: Add OUTPUT IsModified parameter.
Dun Tan [Fri, 9 Dec 2022 02:36:37 +0000 (10:36 +0800)]
UefiCpuPkg/CpuPageTableLib: Add OUTPUT IsModified parameter.

Add OUTPUT IsModified parameter in PageTableMap() to indicate
if page table has been modified. With this parameter, caller
can know if need to call FlushTlb when the page table is in CR3.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoUefiCpuPkg/CpuPageTableLib: Enable non-1:1 mapping in random test
Dun Tan [Fri, 3 Mar 2023 07:30:46 +0000 (15:30 +0800)]
UefiCpuPkg/CpuPageTableLib: Enable non-1:1 mapping in random test

Enable non-1:1 mapping in random test. In previous test, non-1:1
test will fail due to the non-1:1 mapping issue in CpuPageTableLib
and invalid Input Mask when creating new page table or mapping
not-present range. Now these issue have been fixed.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoUefiCpuPkg/CpuPageTableLib:Modify RandomTest to check Mask/Attr
Dun Tan [Fri, 17 Mar 2023 07:06:48 +0000 (15:06 +0800)]
UefiCpuPkg/CpuPageTableLib:Modify RandomTest to check Mask/Attr

Modify RandomTest to check invalid input. When creating new page
table or updating exsiting page table:
1.If set [LinearAddress, LinearAddress+Length] to non-present, all
  other attributes should not be provided.
2.If [LinearAddress, LinearAddress+Length] contain non-present range,
  the Returnstatus of PageTableMap() should be InvalidParameter when:
2.1Some of attributes are not provided when mapping non-present range
   to present.
2.2Set any other attribute without setting the non-present range to
   Present.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
2 years agoUefiCpuPkg/CpuPageTableLib: Add LastMapEntry pointer
Dun Tan [Fri, 24 Mar 2023 04:12:44 +0000 (12:12 +0800)]
UefiCpuPkg/CpuPageTableLib: Add LastMapEntry pointer

Add LastMapEntry pointer to replace MapEntrys->Maps[MapsIndex]
in SingleMapEntryTest () of RandomTest.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
2 years agoUefiCpuPkg/CpuPageTableLib:Modify RandomBoolean() in RandomTest
Dun Tan [Fri, 17 Mar 2023 04:09:50 +0000 (12:09 +0800)]
UefiCpuPkg/CpuPageTableLib:Modify RandomBoolean() in RandomTest

Add an input parameter to control the probability of returning
true. Change RandomBoolean() in RandomTest from 50% chance
returning true to returning true with the percentage of input
Probability.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoUefiCpuPkg/CpuPageTableLib: Add manual test to check Mask and Attr
Dun Tan [Fri, 24 Feb 2023 07:25:09 +0000 (15:25 +0800)]
UefiCpuPkg/CpuPageTableLib: Add manual test to check Mask and Attr

Add manual test case to check input Mask and Attribute. The check
steps are:
1.Create Page table to cover [0, 2G]. All fields of MapMask should
  be set.
2.Update Page table to set [2G - 8K,2G] from present to non-present.
  All fields of MapMask except present should not be set.
3.Still set [2G - 8K, 2G] as not present, this case is permitted.
  But set [2G - 8K, 2G] as RW is not permitted.
4.Update Page table to set [2G - 8K, 2G] as present and RW. All
  fields of MapMask should be set.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoUefiCpuPkg/CpuPageTableLib:Add check for Mask and Attr
Dun Tan [Fri, 24 Feb 2023 07:05:08 +0000 (15:05 +0800)]
UefiCpuPkg/CpuPageTableLib:Add check for Mask and Attr

For different usage, check if the combination for Mask and
Attr is valid when creating or updating page table.

1.For non-present range
  1.1Mask.Present is 0 but some other attributes is provided.
     This case is invalid.
  1.2Mask.Present is 1 and Attr.Present is 0. In this case,all
     other attributes should not be provided.
  1.3Mask.Present is 1 and Attr.Present is 1. In this case,all
     attributes should be provided to intialize the attribute.

2.For present range
  2.1Mask.Present is 1 and Attr.Present is 0.In this case, all
     other attributes should not be provided.
All other usage for present range is permitted.
In the mentioned cases, 1.2 and 2.1 can be merged into 1 check.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoUefiCpuPkg/MpInitLib: Add code to initialize MapMask
Dun Tan [Fri, 17 Mar 2023 07:43:26 +0000 (15:43 +0800)]
UefiCpuPkg/MpInitLib: Add code to initialize MapMask

In function CreatePageTable(), add code to initialize MapMask to
MAX_UINT64. When creating new page table or map non-present range
to present, all attributes should be provided.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoUefiCpuPkg/CpuPageTableLib: Fix issue when splitting leaf entry
Dun Tan [Fri, 9 Dec 2022 02:34:43 +0000 (10:34 +0800)]
UefiCpuPkg/CpuPageTableLib: Fix issue when splitting leaf entry

When splitting leaf parent entry to smaller granularity, create
child page table before modifing parent entry. In previous code
logic, when splitting a leaf parent entry, parent entry will
point to a null 4k memory before child page table is created in
this 4k memory. When the page table to be modified is the page
table in CR3, if the executed CpuPageTableLib code is in the
range mapped by the modified leaf parent entry, then issue will
happen.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoUefiCpuPkg/CpuPageTableLib:Clear PageSize bit(Bit7) for non-leaf
Dun Tan [Mon, 20 Mar 2023 01:40:01 +0000 (09:40 +0800)]
UefiCpuPkg/CpuPageTableLib:Clear PageSize bit(Bit7) for non-leaf

Clear PageSize bit(Bit7) for non-leaf entry in PageTableLibSetPnle.
This function is used to set non-leaf entry attributes so it should
make sure that the PageSize bit of the entry should be 0.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoUefiCpuPkg/CpuPageTableLib: Fix the non-1:1 mapping issue
Dun Tan [Thu, 16 Mar 2023 02:34:40 +0000 (10:34 +0800)]
UefiCpuPkg/CpuPageTableLib: Fix the non-1:1 mapping issue

In previous code logic, when splitting a leaf parent entry to
smaller granularity child page table, if the parent entry
Attribute&Mask(without PageTableBaseAddress field) is equal to the
input attribute&mask(without PageTableBaseAddress field), the split
process won't happen. This may lead to failure in non-1:1 mapping.

For example, there is a page table in which [0, 1G] is mapped(Lv4[0]
,Lv3[0,0], a non-leaf level4 entry and a leaf level3 entry). And we
want to remap [0, 2M] linear address range to [1G, 1G + 2M] with the
same attibute. The expected behaviour should be: split Lv3[0,0]
entry into 512 level2 entries and remap the first level2 entry to
cover [0, 2M]. But the split won't happen in previous code since
PageTableBaseAddress of input Attribute is not checked.

So, when checking if a leaf parent entry needs to be splitted, we
should also check if PageTableBaseAddress calculated by parent entry
is equal to the value caculated by input attribute.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoUefiCpuPkg/CpuPageTableLib:Initialize some LocalVariable at beginning
Dun Tan [Thu, 16 Mar 2023 02:30:53 +0000 (10:30 +0800)]
UefiCpuPkg/CpuPageTableLib:Initialize some LocalVariable at beginning

Move some local variable initialization to the beginning of the
function. Also delete duplicated calculation for RegionLength.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoUefiCpuPkg/CpuPageTableLib: Add check for input Length
Dun Tan [Tue, 7 Mar 2023 03:51:32 +0000 (11:51 +0800)]
UefiCpuPkg/CpuPageTableLib: Add check for input Length

Add check for input Length in PageTableMap (). Return
RETURN_SUCCESS when input Length is 0.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoUefiCpuPkg/CpuPageTableLib: Remove unneeded 'if' condition
Dun Tan [Fri, 3 Mar 2023 07:39:41 +0000 (15:39 +0800)]
UefiCpuPkg/CpuPageTableLib: Remove unneeded 'if' condition

Remove unneeded 'if' condition in CpuPageTableLib code.
The deleted code is in the code branch for present non-leaf parent
entry. So the 'if' check for (ParentPagingEntry->Pnle.Bits.Present
== 0) is always FALSE.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoPcAtChipsetPkg: Add PCD for RTC default year
Michael D Kinney [Sun, 26 Mar 2023 02:41:38 +0000 (19:41 -0700)]
PcAtChipsetPkg: Add PCD for RTC default year

Add PcdRtcDefaultYear to specify the default year to use when
the RTC is in an invalid state. Make sure PcdRtcDefaultYear is
>= PcdMinimalValidYear and <= PcdMaximalValidYear.  Set the
default value for this PCD to PcdMinimalValidYear to preserve
the existing behavior. A platform DSC file can override this
default value setting.

Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
2 years agoUefiCpuPkg: Solve that stack top address is not mapped in pagetable
Xie, Yuanhao [Tue, 21 Mar 2023 07:29:59 +0000 (15:29 +0800)]
UefiCpuPkg: Solve that stack top address is not mapped in pagetable

For the case CPU logic index is 0, RSP points to the very top of all AP
stacks. That address is not mapped in page table.

Cc: Guo Dong <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Sean Rhodes <sean@starlabs.systems>
Cc: James Lu <james.lu@intel.com>
Cc: Gua Guo <gua.guo@intel.com>
Signed-off-by: Ted Kuo <ted.kuo@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
2 years agoUefiPayloadPkg: Add gUefiAcpiBoardInfoGuid support
Gua Guo [Fri, 24 Mar 2023 06:55:13 +0000 (14:55 +0800)]
UefiPayloadPkg: Add gUefiAcpiBoardInfoGuid support

if system both exist gUefiAcpiBoardInfoGuid and rsdp,
we may need to use gUefiAcpiBoardInfoGuid as final
config to have backward support.

Cc: Guo Dong <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Sean Rhodes <sean@starlabs.systems>
Reviewed-by: James Lu <james.lu@intel.com>
Signed-off-by: Gua Guo <gua.guo@intel.com>
2 years agoMdePkg/Include: Add IPMI KCS definitions
Abner Chang [Fri, 3 Mar 2023 01:34:46 +0000 (09:34 +0800)]
MdePkg/Include: Add IPMI KCS definitions

BZ #4354
This change adds definitions for IPMI KCS.

Spec ref:
https://www.intel.com/content/www/us/en/products/docs/servers/ipmi/ipmi-second-gen-interface-spec-v2-rev1-1.html

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
Acked-by: Isaac Oram <isaac.w.oram@intel.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Tinh Nguyen <tinhnguyen@os.amperecomputing.com>
2 years agoMdePkg/Include: Add DMTF MCTP definitions
Abner Chang [Fri, 3 Mar 2023 03:22:54 +0000 (11:22 +0800)]
MdePkg/Include: Add DMTF MCTP definitions

BZ #4355
This change adds definitions for DMTF MCTP
base specification.

Spec ref:
https://www.dmtf.org/sites/default/files/standards/documents/DSP0236_1.3.1.pdf

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
Acked-by: Isaac Oram <isaac.w.oram@intel.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
2 years agoMdePkg/Include/Ppi: Remove Itanium leftover data structure
Paweł Poławski [Fri, 24 Mar 2023 14:36:59 +0000 (07:36 -0700)]
MdePkg/Include/Ppi: Remove Itanium leftover data structure

Itanium support has been removed from EDK2 around 2019.
ITANIUM_HANDOFF_STATUS data structure looks to be
some leftover from that process.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1560
GitHub: https://github.com/tianocore/edk2/commit/4e1daa60f5372c22a11503961061ffa569eaf873

There is also positive side effect of this data structure removal.
Due to HOB allocation type used in PEI stage there is a limit
how much data about virtual CPU can be hold. This limit result
in only 1024 vCPU can be used by VM.

With Itanium related data structure removed more allocated space
can be used for vCPU data and with current allocation limit
will change from 1024 to around 8k vCPUs.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Signed-off-by: Paweł Poławski <ppolawsk@redhat.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
2 years agoIntelFsp2Pkg: Fix NASM X64 build warnings.
Chasel Chiu [Fri, 17 Mar 2023 06:37:40 +0000 (23:37 -0700)]
IntelFsp2Pkg: Fix NASM X64 build warnings.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4377

Fix below warnings generated by NASM X64 build:
/X64/FspHelper.iii:26: warning: signed dword value exceeds bounds
/X64/FspHelper.iii:35: warning: signed dword value exceeds bounds
/X64/FspApiEntryT.iii:320: warning: dword data exceeds bounds

Also replaced "cmp reg, 0" with "test reg, reg" per optimization
suggestion.

Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Signed-off-by: Chasel Chiu <chasel.chiu@intel.com>
Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
2 years agoBaseTools: Replace duplicate __PcdSet prototype with __PcdGet
Rebecca Cran [Mon, 20 Feb 2023 06:22:59 +0000 (23:22 -0700)]
BaseTools: Replace duplicate __PcdSet prototype with __PcdGet

Replace the duplicate __PcdSet prototype in PcdValueCommon.h
with the prototype for __PcdGet.

Signed-off-by: Rebecca Cran <rebecca@bsdio.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
2 years agoBaseTools: Source/C/Common: Fix doc block locations and convert to Doxygen
Rebecca Cran [Mon, 20 Feb 2023 06:21:43 +0000 (23:21 -0700)]
BaseTools: Source/C/Common: Fix doc block locations and convert to Doxygen

Move the documentation blocks from between the parameter list and function
body to above the function.

Convert all the documentation blocks to Doxygen format.

Signed-off-by: Rebecca Cran <rebecca@bsdio.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
2 years agoOvmfPkg/PlatformBootManagerLib: use utf8 for the serial console.
Gerd Hoffmann [Fri, 17 Mar 2023 12:19:21 +0000 (13:19 +0100)]
OvmfPkg/PlatformBootManagerLib: use utf8 for the serial console.

Time to leave behind relics from the last century and arrive in the
modern world.  Drop PC-ANSI Terminal Type for the serial console, use
UTF-8 instead.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoUefiCpuPkg/PiSmmCpuDxeSmm: fix error handling
Gerd Hoffmann [Fri, 10 Mar 2023 12:48:49 +0000 (20:48 +0800)]
UefiCpuPkg/PiSmmCpuDxeSmm: fix error handling

ASSERT() is not proper handling of allocation failures, it gets compiled
out on RELEASE builds.  Print a message and enter dead loop instead.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
2 years agoUefiCpuPkg/PiSmmCpuDxeSmm: drop support for obsolete processors
Gerd Hoffmann [Fri, 10 Mar 2023 12:48:48 +0000 (20:48 +0800)]
UefiCpuPkg/PiSmmCpuDxeSmm: drop support for obsolete processors

It's highly unlikely the code ever runs on processors which are
almost 30 years old.  Drop the code handling them.

Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=4345
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
2 years agoSecurityPkg/DxeImageVerificationLib: Check result of GetEfiGlobalVariable2
Gerd Hoffmann [Fri, 3 Mar 2023 10:35:53 +0000 (18:35 +0800)]
SecurityPkg/DxeImageVerificationLib: Check result of GetEfiGlobalVariable2

Call gRT->GetVariable() directly to read the SecureBoot variable.  It is
one byte in size so we can easily place it on the stack instead of
having GetEfiGlobalVariable2() allocate it for us, which avoids a few
possible error cases.

Skip secure boot checks if (and only if):

 (a) the SecureBoot variable is not present (EFI_NOT_FOUND) according to
     the return value, or
 (b) the SecureBoot variable was read successfully and is set to
     SECURE_BOOT_MODE_DISABLE.

Previously the code skipped the secure boot checks on *any*
gRT->GetVariable() error (GetEfiGlobalVariable2 sets the variable
value to NULL in that case) and also on memory allocation failures.

Fixes: CVE-2019-14560
Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=2167
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Suggested-by: Marvin Häuser <mhaeuser@posteo.de>
Reviewed-by: Min Xu <min.m.xu@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2 years agoRedfishPkg: Update Readme.md
Abner Chang [Sat, 7 Jan 2023 15:23:37 +0000 (23:23 +0800)]
RedfishPkg: Update Readme.md

Update readme.md and add figures to delineate the
relationship of edk2 Redfish, USB NIC and IPMI.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Reviewed-by: Nickle Wang <nicklew@nvidia.com>
2 years agoRedfishPkg: Update Redfish DSC
Abner Chang [Tue, 27 Dec 2022 02:55:27 +0000 (10:55 +0800)]
RedfishPkg: Update Redfish DSC

Update Redfish DSC for
PlatformHostInterfaceBmcUsbNicLib.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Reviewed-by: Nickle Wang <nicklew@nvidia.com>
2 years agoRedfishPkg/Library: Redfish BMC USBNIC Host Interface
Abner Chang [Tue, 7 Mar 2023 04:08:59 +0000 (12:08 +0800)]
RedfishPkg/Library: Redfish BMC USBNIC Host Interface

BMC exposed USB NIC platform Redfish Host Interface
library implementation.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Reviewed-by: Nickle Wang <nicklew@nvidia.com>
2 years agoMdePkg: Update code to be more C11 compliant by using __func__
Rebecca Cran [Thu, 9 Feb 2023 14:29:22 +0000 (07:29 -0700)]
MdePkg: Update code to be more C11 compliant by using __func__

__FUNCTION__ is a pre-standard extension that gcc and Visual C++ among
others support, while __func__ was standardized in C99.

Since it's more standard, replace __FUNCTION__ with __func__ throughout
MdePkg.

Visual Studio versions before VS 2015 don't support __func__ and so
will fail to compile. A workaround is to define __func__ as
__FUNCTION__ :

 #define __func__ __FUNCTION__

Signed-off-by: Rebecca Cran <rebecca@quicinc.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
2 years agoMdePkg: Update Base.h to be compliant with C11
Rebecca Cran [Thu, 9 Feb 2023 14:24:16 +0000 (07:24 -0700)]
MdePkg: Update Base.h to be compliant with C11

With the introduction of the use of _Static_assert, edk2 requires a C11
compatible compiler. Update Include/Base.h to be compliant with C11.

As of C11, the maximum type of an enum is type `int`. Since the UEFI
Specification 2.3.1 Errata C allows either `int` or `unsigned int`, fix
the 32-bit enum check to use a signed int.

Since the UEFI 2.3 Specification only allowed signed int, update the
comment to reference 2.3.1 Errata C where the change was made to allow
unsigned int.

Signed-off-by: Rebecca Cran <rebecca@quicinc.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
2 years agoCryptoPkg/Library: add -Wno-unused-but-set-variable for openssl
Gang Chen [Tue, 3 Jan 2023 05:57:38 +0000 (13:57 +0800)]
CryptoPkg/Library: add -Wno-unused-but-set-variable for openssl

The GCC warning fix is not in 1.1.1x. Ignore the warning type
-Wno-unused-but-set-variable with GCC compiler in the build option.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Signed-off-by: Gang Chen <gang.c.chen@intel.com>
Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>
2 years agoMdeModulePkg/BmBoot: Skip removable media if it is not present
Matt DeVillier [Fri, 9 Dec 2022 20:45:38 +0000 (04:45 +0800)]
MdeModulePkg/BmBoot: Skip removable media if it is not present

Only enumerate devices that have media present.

Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhichao Gao <zhichao.gao@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Reviewed-by: Sean Rhodes <sean@starlabs.systems>
Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
2 years agoArmVirtPkg/ArmVirtQemu: Use PEI flavor of ArmMmuLib for all PEIMs
Ard Biesheuvel [Mon, 13 Feb 2023 11:31:06 +0000 (12:31 +0100)]
ArmVirtPkg/ArmVirtQemu: Use PEI flavor of ArmMmuLib for all PEIMs

The PEI flavor of the ArmMmuLib will install a HOB that exposes its
implementation of the special helper routine that is used to update live
entries, so that other instantiations of ArmMmuLib can invoke it. This
is needed to ensure that splitting page tables using break-before-make
(BBM) does not unmap the code that is performing the split.

However, the BASE variety of ArmMmuLib discovers the HOB and sets a
global pointer to refer to it, which is not possible in PEIMs, and so
all PEIMs must use the PEI variety of this library if one does.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
2 years agoArmPkg/ArmMmuLib: Introduce region types for RO/XP WB cached memory
Ard Biesheuvel [Fri, 10 Feb 2023 16:52:45 +0000 (17:52 +0100)]
ArmPkg/ArmMmuLib: Introduce region types for RO/XP WB cached memory

To prepare for the enablement of booting EFI with the SCTLR.WXN control
enabled, which makes all writeable memory regions non-executable by
default, introduce a memory type that we will use to describe the flash
region that carries the SEC and PEIM modules that execute in place. Even
if these are implicitly read-only due to the ROM nature, they need to be
mapped with read-only attributes in the page tables to be able to
execute from them.

Also add the XP counterpart which will be used for all normal DRAM right
at the outset.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
2 years agoArmPkg/Mmu: Remove handling of NONSECURE memory regions
Ard Biesheuvel [Mon, 13 Feb 2023 08:30:05 +0000 (09:30 +0100)]
ArmPkg/Mmu: Remove handling of NONSECURE memory regions

Non-secure memory is a distinction that only matters when executing code
in the secure world that reasons about the secure vs non-secure address
spaces. EDK2 was not designed for that, and the AArch64 version of the
MMU handling library already treats them as identical, so let's just
drop the ARM memory region types that mark memory as 'non-secure'
explicitly.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
2 years agoArmPkg/CpuDxe: Implement EFI memory attributes protocol
Ard Biesheuvel [Tue, 31 Jan 2023 22:26:25 +0000 (23:26 +0100)]
ArmPkg/CpuDxe: Implement EFI memory attributes protocol

Expose the protocol introduced in v2.10 that permits the caller to
manage mapping permissions in the page tables.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
2 years agoMdePkg: Add Memory Attribute Protocol definition
Ard Biesheuvel [Thu, 2 Feb 2023 09:29:07 +0000 (10:29 +0100)]
MdePkg: Add Memory Attribute Protocol definition

Add the Memory Attribute Protocol definition, which was adopted and
included in version 2.10 of the UEFI specification.

Link: https://bugzilla.tianocore.org/show_bug.cgi?id=3519
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
2 years agoArmPkg/CpuDxe: Expose unified region-to-EFI attribute conversion
Ard Biesheuvel [Tue, 31 Jan 2023 22:23:14 +0000 (23:23 +0100)]
ArmPkg/CpuDxe: Expose unified region-to-EFI attribute conversion

In preparation for introducing an implementation of the EFI memory
attributes protocol that is shared between ARM and AArch64, unify the
existing code that converts a page table descriptor into a
EFI_MEMORY_xx bitfield, so it can be called from the generic code.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
2 years agoArmPkg/ArmMmuLib: Avoid splitting block entries if possible
Ard Biesheuvel [Wed, 8 Feb 2023 17:19:36 +0000 (18:19 +0100)]
ArmPkg/ArmMmuLib: Avoid splitting block entries if possible

Currently, the ARM MMU page table logic will break down any block entry
that overlaps with the region being mapped, even if the block entry in
question is using the same attributes as the new region.

This means that creating a non-executable mapping inside a region that
is already mapped non-executable at a coarser granularity may trigger a
call to AllocatePages (), which may recurse back into the page table
code to update the attributes on the newly allocated page tables.

Let's avoid this, by preserving the block entry if it already covers the
region being mapped with the correct attributes.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
2 years agoArmVirtPkg: Enable stack guard
Ard Biesheuvel [Tue, 7 Feb 2023 17:27:15 +0000 (18:27 +0100)]
ArmVirtPkg: Enable stack guard

Enable the stack guard in ArmVirtPkg builds, so that stack overflows are
caught as they occur, rather than when they happen to hit a read-only
memory region.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
2 years agoArmPkg/ArmMmuLib: Implement EFI_MEMORY_RP using access flag
Ard Biesheuvel [Tue, 7 Feb 2023 15:09:56 +0000 (16:09 +0100)]
ArmPkg/ArmMmuLib: Implement EFI_MEMORY_RP using access flag

Implement support for read-protected memory by wiring it up to the
access flag in the page table descriptor. The resulting mapping is
implicitly non-writable and non-executable as well, but this is good
enough for implementing this attribute, as we never rely on write or
execute permissions without read permissions.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
2 years agoArmPkg/ArmMmuLib ARM: Clear individual permission bits
Ard Biesheuvel [Thu, 9 Feb 2023 09:23:03 +0000 (10:23 +0100)]
ArmPkg/ArmMmuLib ARM: Clear individual permission bits

Currently, the MMU code that is supposed to clear the RO or XP
attributes from a region just clears both unconditionally. This
approximates the desired behavior to some extent, but it does mean that
setting the RO bit first on a code region, and then clearing the XP bit
results both RO and XP being cleared, and we end up with writable code,
and avoiding that is the point of all these protections.

Once we introduce RP support, this will only get worse, so let's fix
this up, by reshuffling the attribute update code to take the entry mask
from the caller, and use the mask to preserve other attributes when
clearing RO or XP.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
2 years agoArmPkg/ArmMmuLib ARM: Isolate the access flag from AP mask
Ard Biesheuvel [Tue, 7 Feb 2023 16:32:19 +0000 (17:32 +0100)]
ArmPkg/ArmMmuLib ARM: Isolate the access flag from AP mask

Split the ARM permission fields in the short descriptors into an access
flag and AP[2:1] as per the recommendation in the ARM ARM. This makes
the access flag available separately, which allows us to implement
EFI_MEMORY_RP memory analogous to how it will be implemented for
AArch64.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
2 years agoArmPkg/CpuDxe ARM: Fix page-to-section attribute conversion
Ard Biesheuvel [Mon, 6 Feb 2023 18:29:09 +0000 (19:29 +0100)]
ArmPkg/CpuDxe ARM: Fix page-to-section attribute conversion

The section-to-page attribute conversion takes the shareability and
execute-never attributes into account, whereas the page-to-section
counterpart does not. The result is that GetMemoryRegionPage () -which
takes a section attribute argument (via *RegionAttributes) that is
ostensibly based on the first page in the range, but differs from the
actual page attributes when converted back- may return with a
RegionLength of zero. This is incorrect, and confuses code that scans a
region by calling GetMemoryRegion () in sequence.

So fix the conversion, and ASSERT () on a non-zero region length.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
2 years agoArmPkg/ArmMmuLib ARM: Split off XN page descriptor bit from type field
Ard Biesheuvel [Thu, 9 Feb 2023 09:01:45 +0000 (10:01 +0100)]
ArmPkg/ArmMmuLib ARM: Split off XN page descriptor bit from type field

With large page support out of the picture, we can treat bits 1 and 0 of
the page descriptor as individual valid and XN bits, instead of treating
XN as a page type. Doing so aligns the handling of the attribute with
the section descriptor layout, as well as the XN handling on AArch64,
and this is beneficial for maintainability.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
2 years agoArmPkg/ArmMmuLib ARM: Remove half baked large page support
Ard Biesheuvel [Thu, 9 Feb 2023 08:46:37 +0000 (09:46 +0100)]
ArmPkg/ArmMmuLib ARM: Remove half baked large page support

Large page support on 32-bit ARM is essentially a glorified contiguous
bit where 16 consecutive entries describing a contiguous range with the
same attributes are presented in a way that permits the TLB to cache its
translation with a single entry.

This was never wired up completely, and does not add a lot of value in
EFI, where the page granularity is 4k and we expect to be able to set RO
and XP permissions on individual pages.

Given that large page support complicates the handling of the XN bit at
the page level (which is in a different place depending on whether the
page is small or large), let's just rip it out.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
2 years agoMdePkg/BaseCacheMaintenanceLib: RISC-V: Fix InvalidateInstructionCacheRange
Tuan Phan [Fri, 10 Mar 2023 21:50:19 +0000 (13:50 -0800)]
MdePkg/BaseCacheMaintenanceLib: RISC-V: Fix InvalidateInstructionCacheRange

When the range instruction cache invalidating not supported, the whole
instruction cache should be invalidated instead.

Signed-off-by: Tuan Phan <tphan@ventanamicro.com>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
2 years agoOvmfPkg/PlatformCI: Add CI coverage for RiscVVirtQemu
Sunil V L [Wed, 15 Mar 2023 07:17:29 +0000 (12:47 +0530)]
OvmfPkg/PlatformCI: Add CI coverage for RiscVVirtQemu

Add support for building RiscVVirtQemu platform in CI.

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoUefiPayloadPkg: Correct MAX_LOGICAL_PROCESSORS value
MarsX Lin [Tue, 14 Mar 2023 09:08:59 +0000 (17:08 +0800)]
UefiPayloadPkg: Correct MAX_LOGICAL_PROCESSORS value

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4372

Correct MAX_LOGICAL_PROCESSORS value to 1024

Cc: Guo Dong <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Sean Rhodes <sean@starlabs.systems>
Reviewed-by: James Lu <james.lu@intel.com>
Reviewed-by: Gua Guo <gua.guo@intel.com>
Signed-off-by: MarsX Lin <marsx.lin@intel.com>
2 years agoUefiCpuPkg/PiSmmCpuDxeSmm: Fix S3 failure in SmmRestoreCpu
Wu, Jiaxin [Mon, 13 Mar 2023 07:03:57 +0000 (15:03 +0800)]
UefiCpuPkg/PiSmmCpuDxeSmm: Fix S3 failure in SmmRestoreCpu

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4368

This issue is caused by the commit:
ec07fd0e35d90dbcc36be300a9ceeac29c5de2ad

GetFirstGuidHob() should not be used after exit boot service.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Zeng Star <star.zeng@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
2 years agoShellPkg/Library: Fix 32-bit truncation of pointer values
Michael D Kinney [Sat, 11 Mar 2023 19:31:51 +0000 (11:31 -0800)]
ShellPkg/Library: Fix 32-bit truncation of pointer values

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4366

Update C and UNI files that are incorrectly using %x or %08x
instead of %p for pointer values.  On 64-bit systems, this is
truncating pointer values above 4GB.

In reviewing ShellPkg for this issue some unused UNI strings
with incorrect format specifiers were removed instead of being
fixed.

Cc: Ray Ni <ray.ni@intel.com>
Cc: Zhichao Gao <zhichao.gao@intel.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
2 years agoBaseTools: Extend fields for module_report.json
Guillermo Antonio Palomino Sosa [Mon, 27 Feb 2023 23:31:49 +0000 (17:31 -0600)]
BaseTools: Extend fields for module_report.json

Adding following fields to module_report.json:
* LibraryClass
* ModuleEntryPointList
* ConstructorList
* DestructorList

Signed-off-by: Guillermo Antonio Palomino Sosa <guillermo.a.palomino.sosa@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
2 years agoBaseTools: Generate compile information in build report
Palomino Sosa, Guillermo A [Tue, 7 Feb 2023 03:07:23 +0000 (11:07 +0800)]
BaseTools: Generate compile information in build report

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2850

Add "-Y REPORT_INFO" option to build command to generate compile
information as part of BuildReport.
This option generates files to be used by external tools as IDE's
to enhance functionality.
Files are created inside build folder:
<Build>/<BuildTarget>/<ToolChain>/CompileInfo

Files created:
* compile_commands.json - Compilation Database. To be used by IDE's
  to enable advance features
* cscope.files - List of files used in compilation. Used by Cscope to parse
  C code and provide browse functionality.
* module_report.json - Module data form buildReport in Json format.

Signed-off-by: Guillermo Antonio Palomino Sosa <guillermo.a.palomino.sosa@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
2 years agoDynamicTablesPkg: Add SMBIOS String table helper library
Sami Mujawar [Thu, 8 Sep 2022 17:35:50 +0000 (18:35 +0100)]
DynamicTablesPkg: Add SMBIOS String table helper library

The Section 6.1.3, SMBIOS specification version 3.6.0 describes the
handling of test strings in SMBIOS tables.

Text strings are added at the end of the formatted portion of the SMBIOS
structure and are referenced by index in the SMBIOS structure.

Therefore, introduce a SmbiosStringTableLib to simplify the publishing
of the string set.

SmbiosStringTableLib introduces a concept of string table which records
the references to the SMBIOS strings as they are added and returns an
string reference which is then assigned to the string field in the
formatted portion of the SMBIOS structure. Once all strings are added,
the library provides an interface to get the required size for the string
set. This allows sufficient memory to be allocated for the SMBIOS table.
The library also provides an interface to publish the string set in
accordance with the SMBIOS specification.

Example:
EFI_STATUS
BuildSmbiosType17Table () {
  STRING_TABLE         StrTable;
  UINT8                DevLocatorRef;
  UINT8                BankLocatorRef;
  SMBIOS_TABLE_TYPE17  *SmbiosRecord;
  CHAR8                *StringSet;
  ...

  // Initialize string table for 7 strings
  StringTableInitialize (&StrTable, 7);

  StringTableAddString (&StrTable, "SIMM 3", &DevLocatorRef);
  StringTableAddString (&StrTable, "Bank 0", &BankLocatorRef);
  ...

  SmbiosRecord = AllocateZeroPool (
                   sizeof (SMBIOS_TABLE_TYPE17) +
                     StringTableGetStringSetSize (&StrTable)
                   );
  ...
  SmbiosRecord->DeviceLocator = DevLocatorRef;
  SmbiosRecord->BankLocator = BankLocatorRef;
  ...
  // get the string set area
  StringSet = (CHAR8*)(SmbiosRecord + 1);

  // publish the string set
  StringTablePublishStringSet (
    &StrTable,
    StringSet,
    StringTableGetStringSetSize (&StrTable)
    );

  // free string table
  StringTableFree (&StrTable);

  return EFI_SUCCESS;
}

Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
Reviewed-by: Pierre Gondois <pierre.gondois@arm.com>
Cc: Alexei Fedorov <Alexei.Fedorov@arm.com>
Cc: Pierre Gondois <pierre.gondois@arm.com>
Cc: Girish Mahadevan <gmahadevan@nvidia.com>
Cc: Jeff Brasen <jbrasen@nvidia.com>
Cc: Ashish Singhal <ashishsingha@nvidia.com>
Cc: Nick Ramirez <nramirez@nvidia.com>
Cc: William Watson <wwatson@nvidia.com>
Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
2 years agoUefiPayloadPkg: Remove UefiCpuLib from module INFs.
Yu Pu [Tue, 29 Mar 2022 03:49:14 +0000 (11:49 +0800)]
UefiPayloadPkg: Remove UefiCpuLib from module INFs.

Because UefiCpuPkg/UefiCpuLib is merged to MdePkg/CpuLib, remove the
dependency of UefiCpuLib.

Reviewed-by: Guo Dong <guo.dong@intel.com>
Reviewed-by: James Lu <james.lu@intel.com>
Reviewed-by: Gua Guo <gua.guo@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Benjamin You <benjamin.you@intel.com>
Cc: Sean Rhodes <sean@starlabs.systems>
Signed-off-by: Yu Pu <yu.pu@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
2 years agoUefiCpuPkg: Remove UefiCpuLib from module INFs.
Yu Pu [Tue, 29 Mar 2022 03:48:24 +0000 (11:48 +0800)]
UefiCpuPkg: Remove UefiCpuLib from module INFs.

Because UefiCpuPkg/UefiCpuLib is merged to MdePkg/CpuLib, remove the
dependency of UefiCpuLib.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Signed-off-by: Yu Pu <yu.pu@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
2 years agoSourceLevelDebugPkg: Remove UefiCpuLib from module INFs.
Yu Pu [Tue, 29 Mar 2022 03:47:53 +0000 (11:47 +0800)]
SourceLevelDebugPkg: Remove UefiCpuLib from module INFs.

Because UefiCpuPkg/UefiCpuLib is merged to MdePkg/CpuLib, remove the
dependency of UefiCpuLib.

Cc: Hao A Wu <hao.a.wu@intel.com>
Acked-by: Hao A Wu <hao.a.wu@intel.com>
Signed-off-by: Yu Pu <yu.pu@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
2 years agoPcAtChipsetPkg: Remove UefiCpuLib from module INFs.
Yu Pu [Tue, 29 Mar 2022 03:47:27 +0000 (11:47 +0800)]
PcAtChipsetPkg: Remove UefiCpuLib from module INFs.

Because UefiCpuPkg/UefiCpuLib is merged to MdePkg/CpuLib, remove the
dependency of UefiCpuLib.

Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Yu Pu <yu.pu@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
2 years agoOvmfPkg: Remove UefiCpuLib from module INFs.
Yu Pu [Tue, 29 Mar 2022 03:46:31 +0000 (11:46 +0800)]
OvmfPkg: Remove UefiCpuLib from module INFs.

Because UefiCpuPkg/UefiCpuLib is merged to MdePkg/CpuLib, remove the
dependency of UefiCpuLib.

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Yu Pu <yu.pu@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
2 years agoIntelFsp2Pkg: Remove UefiCpuLib from module INFs.
Yu Pu [Tue, 29 Mar 2022 03:45:12 +0000 (11:45 +0800)]
IntelFsp2Pkg: Remove UefiCpuLib from module INFs.

Because UefiCpuPkg/UefiCpuLib is merged to MdePkg/CpuLib, remove the
dependency of UefiCpuLib.

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Signed-off-by: Yu Pu <yu.pu@intel.com>
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>
2 years agoMdePkg: Move API and implementation from UefiCpuLib to CpuLib
Yu Pu [Tue, 29 Mar 2022 03:28:32 +0000 (11:28 +0800)]
MdePkg: Move API and implementation from UefiCpuLib to CpuLib

There are two libraries: MdePkg/CpuLib and UefiCpuPkg/UefiCpuLib. This
patch merges UefiCpuPkg/UefiCpuLib to MdePkg/CpuLib.

Change-Id: Ic26f4c2614ed6bd9840f817d50e47ac1de4bd013
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Signed-off-by: Yu Pu <yu.pu@intel.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
2 years agoOvmfPkg: Add CpuLib to module INFs that depend on UefiCpuLib.
Zhiguang Liu [Tue, 1 Nov 2022 01:33:15 +0000 (09:33 +0800)]
OvmfPkg: Add CpuLib to module INFs that depend on UefiCpuLib.

There are two libraries: MdePkg/CpuLib and UefiCpuPkg/UefiCpuLib and
UefiCpuPkg/UefiCpuLib will be merged to MdePkg/CpuLib. To avoid build
failure, add CpuLib dependency to all modules that depend on UefiCpuLib.

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
2 years agoUefiCpuPkg/MicrocodeMeasurementDxe: Fix exception
Darbin Reyes [Tue, 7 Mar 2023 23:04:03 +0000 (15:04 -0800)]
UefiCpuPkg/MicrocodeMeasurementDxe: Fix exception

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4360

An incorrect format specifier is being used in a DEBUG print,
specifically, a variable of type EFI_STATUS was being printed with
the %a format specifier (pointer to an ASCII string), thus the value of
the Status variable was being treated as the address of a string,
leading to a CPU exception, when encountered this bug manifests itself
as a hang near "Ready to Boot Event", with the last DEBUG print being
"INFO: Got MicrocodePatchHob with microcode patches starting address"
followed by a CPU Exception dump.

Signed-off-by: Darbin Reyes <darbin.reyes@intel.com>
Reviewed-by: Jacob Narey <jacob.narey@intel.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
2 years agoCryptoPkg/OpensslLib: Upgrade OpenSSL to 1.1.1t
Sheng Wei [Tue, 28 Feb 2023 02:43:57 +0000 (10:43 +0800)]
CryptoPkg/OpensslLib: Upgrade OpenSSL to 1.1.1t

Upgrade openssl to 1.1.1t
Pick up bugfixes from the latest openssl release.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Xiaoyu Lu <xiaoyu1.lu@intel.com>
Cc: Guomin Jiang <guomin.jiang@intel.com>
Signed-off-by: Sheng Wei <w.sheng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2 years agoIntelFsp2Pkg: Fix GCC Compiler warning.
S, Ashraf Ali [Thu, 9 Mar 2023 16:05:57 +0000 (08:05 -0800)]
IntelFsp2Pkg: Fix GCC Compiler warning.

Function definition should match with declaration.
[-Wlto-type-mismatch]

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Signed-off-by: Ashraf Ali S <ashraf.ali.s@intel.com>
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>
Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
Reviewed-by: Sai Chaganty <rangasai.v.chaganty@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
2 years agoOvmfPkg/SmbiosPlatformDxe: tweak fallback release date
Gerd Hoffmann [Thu, 9 Mar 2023 09:02:07 +0000 (10:02 +0100)]
OvmfPkg/SmbiosPlatformDxe: tweak fallback release date

In case PcdFirmwareReleaseDateString is not set use a valid date
as fallback.  Using "unknown" makes Windows unhappy.

Fixes: 4cb94f20b002 ("OvmfPkg/SmbiosPlatformDxe: use PcdFirmware*")
Reported-by: ruifeng.gao@intel.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
2 years agoArmPkg/SemihostFs: replace SetMem with ZeroMem
Gerd Hoffmann [Wed, 15 Feb 2023 14:37:32 +0000 (15:37 +0100)]
ArmPkg/SemihostFs: replace SetMem with ZeroMem

SetMem arguments 2+3 are in the wrong order, resulting in
the call having no effect because Length is zero.

Fix this by using ZeroMem instead.

Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=4205
Reported-by: Jeremy Boone <jeremy.boone@nccgroup.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Rebecca Cran <rebecca@bsdio.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
2 years agoUefiCpuPkg: BaseRiscV64CpuExceptionHandlerLib: clean up
Andrei Warkentin [Sat, 18 Feb 2023 00:42:29 +0000 (18:42 -0600)]
UefiCpuPkg: BaseRiscV64CpuExceptionHandlerLib: clean up

RegisterCpuInterruptHandler did not allow setting
exception handlers for anything beyond the timer IRQ.
Beyond that, it didn't meet the spec around handling
of inputs.

RiscVSupervisorModeTrapHandler now will invoke
set handlers for both exceptions and interrupts.
Two arrays of handlers are maintained - one for exceptions
and one for interrupts.

For unhandled traps, RiscVSupervisorModeTrapHandler dumps
state using the now implemented DumpCpuContext.

For EFI_SYSTEM_CONTEXT_RISCV64, extend this with the trapped
PC address (SEPC), just like on AArch64 (ELR). This is
necessary for X86EmulatorPkg to work as it allows a trap
handler to return execution to a different place. Add
SSTATUS/STVAL as well, at least for debugging purposes. There
is no value in hiding this.

Fix nested exception handling. Handler code should not
be saving SIE (the value is saved in SSTATUS.SPIE) or
directly restored (that's done by SRET). Save and
restore the entire SSTATUS and STVAL, too.

Cc: Daniel Schaefer <git@danielschaefer.me>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
Signed-off-by: Andrei Warkentin <andrei.warkentin@intel.com>
2 years agoUefiCpuPkg: CpuTimerDxeRiscV64: fix tick duration accounting
Andrei Warkentin [Sat, 18 Feb 2023 00:44:51 +0000 (18:44 -0600)]
UefiCpuPkg: CpuTimerDxeRiscV64: fix tick duration accounting

The TimerDxe implementation doesn't account for the physical
time passed due to timer handler execution or (perhaps even
more importantly) time spent with interrupts masked.

Other implementations (e.g. like the Arm one) do. If the
timer tick is always incremented at a fixed rate, then
you can slow down UEFI's perception of time by running
long sections of code in a critical section.

Cc: Daniel Schaefer <git@danielschaefer.me>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
Signed-off-by: Andrei Warkentin <andrei.warkentin@intel.com>
2 years agoMdeModulePkg: Dxe: add RISCV64 to mMachineTypeInfo
Andrei Warkentin [Sat, 18 Feb 2023 00:57:22 +0000 (18:57 -0600)]
MdeModulePkg: Dxe: add RISCV64 to mMachineTypeInfo

This fixes messages like:
"Image type AARCH64 can't be loaded on <Unknown> UEFI system"

Cc: Daniel Schaefer <git@danielschaefer.me>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
Signed-off-by: Andrei Warkentin <andrei.warkentin@intel.com>
2 years agoMdePkg: BaseCpuLib: Fix RISCV CpuSleep symbol name.
Andrei Warkentin [Sat, 18 Feb 2023 00:44:15 +0000 (18:44 -0600)]
MdePkg: BaseCpuLib: Fix RISCV CpuSleep symbol name.

CpuSleep, not _CpuSleep.

Cc: Daniel Schaefer <git@danielschaefer.me>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
Signed-off-by: Andrei Warkentin <andrei.warkentin@intel.com>
2 years agoMdePkg: BaseLib: don't log in RISCV InternalSwitchStack
Andrei Warkentin [Sat, 18 Feb 2023 00:43:08 +0000 (18:43 -0600)]
MdePkg: BaseLib: don't log in RISCV InternalSwitchStack

InternalSwitchStack may be called with a TPL high
enough for a DebugLib implementation to assert.

Other arch implementations don't log either.

Cc: Daniel Schaefer <git@danielschaefer.me>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
Signed-off-by: Andrei Warkentin <andrei.warkentin@intel.com>
2 years agoMdePkg: BasePeCoffLib: Allow AArch64 and x64 images in ImageFormatSupported
Andrei Warkentin [Sat, 18 Feb 2023 00:33:55 +0000 (18:33 -0600)]
MdePkg: BasePeCoffLib: Allow AArch64 and x64 images in ImageFormatSupported

ARM64 and X64 may allow such foreign images to be used when
driver implementing EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL is
present.

Cc: Sunil V L <sunilvl@ventanamicro.com>
Cc: Daniel Schaefer <git@danielschaefer.me>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Signed-off-by: Andrei Warkentin <andrei.warkentin@intel.com>
2 years agoOvmfPkg: RiscVVirt: add SATA support
Andrei Warkentin [Sat, 18 Feb 2023 00:31:58 +0000 (18:31 -0600)]
OvmfPkg: RiscVVirt: add SATA support

Tested with a PCIe pass-thru'd AHCI controller.

Cc: Sunil V L <sunilvl@ventanamicro.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Signed-off-by: Andrei Warkentin <andrei.warkentin@intel.com>
2 years agoSecurityPkg/RngDxe: Conditionally install EFI_RNG_PROTOCOL
Pierre Gondois [Thu, 24 Nov 2022 16:17:55 +0000 (17:17 +0100)]
SecurityPkg/RngDxe: Conditionally install EFI_RNG_PROTOCOL

On Arm platforms, the number of available RNG algorithms is
dynamically detected and can be 0 in the absence of FEAT_RNG
and firmware TRNG.
In this case, the EFI_RNG_PROTOCOL should not be installed to
prevent from installing an empty protocol.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
[ardb: return EFI_REQUEST_UNLOAD_IMAGE instead of an error]
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
2 years agoSecurityPkg/RngDxe: Correctly update mAvailableAlgoArrayCount
Pierre Gondois [Thu, 24 Nov 2022 16:17:54 +0000 (17:17 +0100)]
SecurityPkg/RngDxe: Correctly update mAvailableAlgoArrayCount

mAvailableAlgoArrayCount holds the count of available RNG algorithms.
In a following patch, its value will be used to prevent the
EFI_RNG_PROTOCOL to be installed if no RNG algorithm is available.

Correctly set/reset the value for all implementations.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
2 years agoUefiCpuPkg: Calculate DisplayFamily correctly
Liu, Zhiguang [Tue, 7 Mar 2023 06:31:36 +0000 (14:31 +0800)]
UefiCpuPkg: Calculate DisplayFamily correctly

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4348

Per SDM:
DisplayFamily = Extended_Family_ID + Family_ID.
DisplayModelID = (Extended_Model_ID << 4) + Family_ID.
Correct the related code.

Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Cc: Mike Maslenkin <mike.maslenkin@gmail.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
2 years agoCryptoPkg/BaseCryptLib: avoid using SHA512()
Gerd Hoffmann [Mon, 13 Feb 2023 19:19:58 +0000 (03:19 +0800)]
CryptoPkg/BaseCryptLib: avoid using SHA512()

In openssl 3.0 SHA512() goes through the provider logic,
requiring a huge amount of openssl code.  The individual
functions do not, so use them instead.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2 years agoCryptoPkg/BaseCryptLib: avoid using SHA384()
Gerd Hoffmann [Mon, 13 Feb 2023 19:19:57 +0000 (03:19 +0800)]
CryptoPkg/BaseCryptLib: avoid using SHA384()

In openssl 3.0 SHA384() goes through the provider logic,
requiring a huge amount of openssl code.  The individual
functions do not, so use them instead.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2 years agoCryptoPkg/BaseCryptLib: avoid using SHA256()
Gerd Hoffmann [Mon, 13 Feb 2023 19:19:56 +0000 (03:19 +0800)]
CryptoPkg/BaseCryptLib: avoid using SHA256()

In openssl 3.0 SHA256() goes through the provider logic,
requiring a huge amount of openssl code.  The individual
functions do not, so use them instead.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2 years agoCryptoPkg/BaseCryptLib: avoid using SHA1()
Gerd Hoffmann [Mon, 13 Feb 2023 19:19:55 +0000 (03:19 +0800)]
CryptoPkg/BaseCryptLib: avoid using SHA1()

In openssl 3.0 SHA1() goes through the provider logic,
requiring a huge amount of openssl code.  The individual
functions do not, so use them instead.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2 years agoUefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
Xie, Yuanhao [Wed, 1 Mar 2023 06:09:54 +0000 (14:09 +0800)]
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm

Cc: Guo Dong <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Sean Rhodes <sean@starlabs.systems>
Cc: James Lu <james.lu@intel.com>
Cc: Gua Guo <gua.guo@intel.com>
Signed-off-by: Yuanhao Xie <yuanhao.xie@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
2 years agoUefiCpuPkg: Rename AsmRelocateApLoopStart.
Yuanhao Xie [Wed, 1 Mar 2023 06:09:53 +0000 (14:09 +0800)]
UefiCpuPkg: Rename AsmRelocateApLoopStart.

Rename AsmRelocateApLoopStart to AsmRelocateApLoopStartAmdSev

Cc: Guo Dong <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Sean Rhodes <sean@starlabs.systems>
Cc: James Lu <james.lu@intel.com>
Cc: Gua Guo <gua.guo@intel.com>
Signed-off-by: Yuanhao Xie <yuanhao.xie@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
2 years agoUefiCpuPkg: Put APs in 64 bit mode before handoff to OS.
Xie, Yuanhao [Wed, 1 Mar 2023 06:09:52 +0000 (14:09 +0800)]
UefiCpuPkg: Put APs in 64 bit mode before handoff to OS.

Add the 'AsmRelocateApLoopStartGeneric' for X64 processors except 64-bit
 AMD processors with SEV-ES.

Remove the unused arguments of AsmRelocateApLoopStartGeneric, updated
the stack offset.

Create PageTable for the allocated reserved memory.

Only keep 4GB limitation of memory allocation for the case APs still
need to be transferred to 32-bit mode before OS.

Cc: Guo Dong <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Sean Rhodes <sean@starlabs.systems>
Cc: James Lu <james.lu@intel.com>
Cc: Gua Guo <gua.guo@intel.com>
Signed-off-by: Yuanhao Xie <yuanhao.xie@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
2 years agoUefiPayloadPkg: Add CpuPageTableLib required by MpInitLib.
Xie, Yuanhao [Wed, 1 Mar 2023 06:09:51 +0000 (14:09 +0800)]
UefiPayloadPkg: Add CpuPageTableLib required by MpInitLib.

Add CpuPageTableLib required by MpInitLib in UefiPayloadPkg.

Cc: Guo Dong <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Sean Rhodes <sean@starlabs.systems>
Cc: James Lu <james.lu@intel.com>
Cc: Gua Guo <gua.guo@intel.com>
Signed-off-by: Yuanhao Xie <yuanhao.xie@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
2 years agoOvmfPkg: Add CpuPageTableLib required by MpInitLib.
Yuanhao Xie [Wed, 1 Mar 2023 06:09:50 +0000 (14:09 +0800)]
OvmfPkg: Add CpuPageTableLib required by MpInitLib.

Add CpuPageTableLib required by MpInitLib in OvmfPkg.

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Yuanhao Xie <yuanhao.xie@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
2 years agoUefiCpuPkg: Allocate contiguous memory for stacks and APs loop.
Xie, Yuanhao [Wed, 1 Mar 2023 06:09:49 +0000 (14:09 +0800)]
UefiCpuPkg: Allocate contiguous memory for stacks and APs loop.

Cc: Guo Dong <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Sean Rhodes <sean@starlabs.systems>
Cc: James Lu <james.lu@intel.com>
Cc: Gua Guo <gua.guo@intel.com>
Signed-off-by: Yuanhao Xie <yuanhao.xie@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
2 years agoUefiCpuPkg: Split the path in RelocateApLoop into two.
Xie, Yuanhao [Wed, 1 Mar 2023 06:09:48 +0000 (14:09 +0800)]
UefiCpuPkg: Split the path in RelocateApLoop into two.

Add the union RELOCATE_AP_LOOP_ENTRY, split the path in RelocateApLoop
 into two:
 1. 64-bit AMD processors with SEV-ES
 2. Intel processors (32-bit or 64-bit), 32-bit AMD processors, or
 64-bit AMD processors without SEV-ES.

Cc: Guo Dong <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Sean Rhodes <sean@starlabs.systems>
Cc: James Lu <james.lu@intel.com>
Cc: Gua Guo <gua.guo@intel.com>
Signed-off-by: Yuanhao Xie <yuanhao.xie@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
2 years agoUefiCpuPkg: Check AP_SAFE_STACK_SIZE during build time.
Xie, Yuanhao [Wed, 1 Mar 2023 06:09:47 +0000 (14:09 +0800)]
UefiCpuPkg: Check AP_SAFE_STACK_SIZE during build time.

Check if AP_SAFE_STACK_SIZE is aligned with CPU_STACK_ALIGNMENT
during build time.

No functional or structural changes.

Cc: Guo Dong <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Sean Rhodes <sean@starlabs.systems>
Cc: James Lu <james.lu@intel.com>
Cc: Gua Guo <gua.guo@intel.com>
Signed-off-by: Yuanhao Xie <yuanhao.xie@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>