]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiPayloadPkg: Simplify code logic
authorLiu, Zhiguang <Zhiguang.Liu@intel.com>
Thu, 12 May 2022 10:54:57 +0000 (18:54 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 13 May 2022 01:47:11 +0000 (01:47 +0000)
A little overdesign about VisitAllPciInstances function, since there are
two call back functions. Simplify the code logic by combining the two call
back functions, and unused parameters.
Change the PROTOCOL_INSTANCE_CALLBACK to SIMPLE_PROTOCOL_INSTANCE_CALLBACK
because the former is also defined in OvmfPkg. Rename it to avoid confusion.

Reviewed-by: Guo Dong <guo.dong@intel.com>
Reviewed-by: 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: Zhiguang Liu <zhiguang.liu@intel.com>
UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformConsole.c
UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformConsole.h

index bfaf89e74c3c01446796cf2ca22db0238a34a229..75aafebccd03f0f297b88a44d92f8bff0650d302 100644 (file)
@@ -333,7 +333,6 @@ PreparePciSerialDevicePath (
 \r
   @param[in]  Id                 - The protocol GUID for callback\r
   @param[in]  CallBackFunction   - The callback function\r
-  @param[in]  Context    - The context of the callback\r
 \r
   @retval EFI_STATUS - Callback function failed.\r
 \r
@@ -341,9 +340,8 @@ PreparePciSerialDevicePath (
 EFI_STATUS\r
 EFIAPI\r
 VisitAllInstancesOfProtocol (\r
-  IN EFI_GUID                    *Id,\r
-  IN PROTOCOL_INSTANCE_CALLBACK  CallBackFunction,\r
-  IN VOID                        *Context\r
+  IN EFI_GUID                           *Id,\r
+  IN SIMPLE_PROTOCOL_INSTANCE_CALLBACK  CallBackFunction\r
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -376,8 +374,7 @@ VisitAllInstancesOfProtocol (
 \r
     Status = (*CallBackFunction)(\r
   HandleBuffer[Index],\r
-  Instance,\r
-  Context\r
+  Instance\r
   );\r
   }\r
 \r
@@ -387,21 +384,21 @@ VisitAllInstancesOfProtocol (
 }\r
 \r
 /**\r
-  For every PCI instance execute a callback function.\r
+  Do platform specific PCI Device check and add them to\r
+  ConOut, ConIn, ErrOut.\r
 \r
-  @param[in]  Handle     - The PCI device handle\r
-  @param[in]  Instance   - The instance of the PciIo protocol\r
-  @param[in]  Context    - The context of the callback\r
+  @param[in]  Handle    - Handle of PCI device instance\r
+  @param[in]  Instance  - The instance of PCI device\r
 \r
-  @retval EFI_STATUS - Callback function failed.\r
+  @retval EFI_SUCCESS - PCI Device check and Console variable update successfully.\r
+  @retval EFI_STATUS - PCI Device check or Console variable update fail.\r
 \r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-VisitingAPciInstance (\r
+DetectAndPreparePlatformPciDevicePath (\r
   IN EFI_HANDLE  Handle,\r
-  IN VOID        *Instance,\r
-  IN VOID        *Context\r
+  IN VOID        *Instance\r
   )\r
 {\r
   EFI_STATUS           Status;\r
@@ -424,56 +421,6 @@ VisitingAPciInstance (
     return Status;\r
   }\r
 \r
-  return (*(VISIT_PCI_INSTANCE_CALLBACK)(UINTN)Context)(\r
-  Handle,\r
-  PciIo,\r
-  &Pci\r
-  );\r
-}\r
-\r
-/**\r
-  For every PCI instance execute a callback function.\r
-\r
-  @param[in]  CallBackFunction - Callback function pointer\r
-\r
-  @retval EFI_STATUS - Callback function failed.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-VisitAllPciInstances (\r
-  IN VISIT_PCI_INSTANCE_CALLBACK  CallBackFunction\r
-  )\r
-{\r
-  return VisitAllInstancesOfProtocol (\r
-           &gEfiPciIoProtocolGuid,\r
-           VisitingAPciInstance,\r
-           (VOID *)(UINTN)CallBackFunction\r
-           );\r
-}\r
-\r
-/**\r
-  Do platform specific PCI Device check and add them to\r
-  ConOut, ConIn, ErrOut.\r
-\r
-  @param[in]  Handle - Handle of PCI device instance\r
-  @param[in]  PciIo - PCI IO protocol instance\r
-  @param[in]  Pci - PCI Header register block\r
-\r
-  @retval EFI_SUCCESS - PCI Device check and Console variable update successfully.\r
-  @retval EFI_STATUS - PCI Device check or Console variable update fail.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-DetectAndPreparePlatformPciDevicePath (\r
-  IN EFI_HANDLE           Handle,\r
-  IN EFI_PCI_IO_PROTOCOL  *PciIo,\r
-  IN PCI_TYPE00           *Pci\r
-  )\r
-{\r
-  EFI_STATUS  Status;\r
-\r
   Status = PciIo->Attributes (\r
                     PciIo,\r
                     EfiPciIoAttributeOperationEnable,\r
@@ -486,9 +433,9 @@ DetectAndPreparePlatformPciDevicePath (
     //\r
     // Here we decide whether it is LPC Bridge\r
     //\r
-    if ((IS_PCI_LPC (Pci)) ||\r
-        ((IS_PCI_ISA_PDECODE (Pci)) &&\r
-         (Pci->Hdr.VendorId == 0x8086)\r
+    if ((IS_PCI_LPC (&Pci)) ||\r
+        ((IS_PCI_ISA_PDECODE (&Pci)) &&\r
+         (Pci.Hdr.VendorId == 0x8086)\r
         )\r
         )\r
     {\r
@@ -504,7 +451,7 @@ DetectAndPreparePlatformPciDevicePath (
     //\r
     // Here we decide which Serial device to enable in PCI bus\r
     //\r
-    if (IS_PCI_16550SERIAL (Pci)) {\r
+    if (IS_PCI_16550SERIAL (&Pci)) {\r
       //\r
       // Add them to ConOut, ConIn, ErrOut.\r
       //\r
@@ -517,7 +464,7 @@ DetectAndPreparePlatformPciDevicePath (
   //\r
   // Enable all display devices\r
   //\r
-  if (IS_PCI_DISPLAY (Pci)) {\r
+  if (IS_PCI_DISPLAY (&Pci)) {\r
     //\r
     // Add them to ConOut.\r
     //\r
@@ -543,6 +490,8 @@ DetectAndPreparePlatformPciDevicePaths (
   BOOLEAN  DetectDisplayOnly\r
   )\r
 {\r
+  EFI_STATUS  Status;\r
+\r
   mDetectDisplayOnly = DetectDisplayOnly;\r
 \r
   EfiBootManagerUpdateConsoleVariable (\r
@@ -551,7 +500,11 @@ DetectAndPreparePlatformPciDevicePaths (
     NULL\r
     );\r
 \r
-  return VisitAllPciInstances (DetectAndPreparePlatformPciDevicePath);\r
+  Status = VisitAllInstancesOfProtocol (\r
+             &gEfiPciIoProtocolGuid,\r
+             DetectAndPreparePlatformPciDevicePath\r
+             );\r
+  return Status;\r
 }\r
 \r
 /**\r
index a13f4b8b5953cfb5ccd16b45b155f96c499b0d5a..3713c21c45137a6a21a8b053ef9dd1244273dc4e 100644 (file)
@@ -37,10 +37,9 @@ typedef struct {
 \r
 typedef\r
 EFI_STATUS\r
-(EFIAPI *PROTOCOL_INSTANCE_CALLBACK)(\r
+(EFIAPI *SIMPLE_PROTOCOL_INSTANCE_CALLBACK)(\r
   IN EFI_HANDLE            Handle,\r
-  IN VOID                 *Instance,\r
-  IN VOID                 *Context\r
+  IN VOID                 *Instance\r
   );\r
 \r
 /**\r