From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web08.2661.1652352917194448306 for ; Thu, 12 May 2022 03:55:18 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=X0GxtIon; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: zhiguang.liu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652352917; x=1683888917; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ma063xzXiGbUTrgwwdIdVDGjy2ITxwn3nd2RyADrQZQ=; b=X0GxtIonbh8ok1lYQPCgcofrH/PoDnxLDHfyVfBtCEki+bZFLjY0TGEK YraIUuBwq6gDmtbYDhcWxufIxLswo1fOR3+OsVfUPa67F9EJw5xfWyqY6 xN+6ksqTl2u/ezT8D2uIYvyaQM/Ztv2W6UKwYyquN8DTZUJzgfBfYwXml s0ESqIQ/397wehmlwY3ebCbfIEJNY+XtAug0MHJ6yU/e3Biy/G7vriYJZ GxMLHqX02A1GOR96Owi5PEJk+vyFJ+8RT9VgrdeSC8xlbFa99x0FUAed0 ZmMnyQqVymtbVH2IoYz8EZ4Ak+8m/MRO65aXCG9n6YGnZOqxOCYtn+YME Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10344"; a="270094638" X-IronPort-AV: E=Sophos;i="5.91,219,1647327600"; d="scan'208";a="270094638" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2022 03:55:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,219,1647327600"; d="scan'208";a="566627450" Received: from shwdesfp01.ccr.corp.intel.com ([10.239.158.158]) by orsmga007.jf.intel.com with ESMTP; 12 May 2022 03:55:14 -0700 From: "Zhiguang Liu" To: devel@edk2.groups.io Cc: Guo Dong , Ray Ni , Maurice Ma , Benjamin You , Sean Rhodes Subject: [PATCH v2 1/3] UefiPayloadPkg: Simplify code logic Date: Thu, 12 May 2022 18:54:57 +0800 Message-Id: <395134d6b7eae24441d404aa3e10ab391afcd049.1652351830.git.zhiguang.liu@intel.com> X-Mailer: git-send-email 2.32.0.windows.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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. Cc: Guo Dong Cc: Ray Ni Cc: Maurice Ma Cc: Benjamin You Cc: Sean Rhodes Signed-off-by: Zhiguang Liu --- .../PlatformBootManagerLib/PlatformConsole.c | 93 +++++-------------- .../PlatformBootManagerLib/PlatformConsole.h | 5 +- 2 files changed, 25 insertions(+), 73 deletions(-) diff --git a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformConsole.= c b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformConsole.c index bfaf89e74c..75aafebccd 100644 --- a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformConsole.c +++ b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformConsole.c @@ -333,7 +333,6 @@ PreparePciSerialDevicePath ( =0D @param[in] Id - The protocol GUID for callback=0D @param[in] CallBackFunction - The callback function=0D - @param[in] Context - The context of the callback=0D =0D @retval EFI_STATUS - Callback function failed.=0D =0D @@ -341,9 +340,8 @@ PreparePciSerialDevicePath ( EFI_STATUS=0D EFIAPI=0D VisitAllInstancesOfProtocol (=0D - IN EFI_GUID *Id,=0D - IN PROTOCOL_INSTANCE_CALLBACK CallBackFunction,=0D - IN VOID *Context=0D + IN EFI_GUID *Id,=0D + IN SIMPLE_PROTOCOL_INSTANCE_CALLBACK CallBackFunction=0D )=0D {=0D EFI_STATUS Status;=0D @@ -376,8 +374,7 @@ VisitAllInstancesOfProtocol ( =0D Status =3D (*CallBackFunction)(=0D HandleBuffer[Index],=0D - Instance,=0D - Context=0D + Instance=0D );=0D }=0D =0D @@ -387,21 +384,21 @@ VisitAllInstancesOfProtocol ( }=0D =0D /**=0D - For every PCI instance execute a callback function.=0D + Do platform specific PCI Device check and add them to=0D + ConOut, ConIn, ErrOut.=0D =0D - @param[in] Handle - The PCI device handle=0D - @param[in] Instance - The instance of the PciIo protocol=0D - @param[in] Context - The context of the callback=0D + @param[in] Handle - Handle of PCI device instance=0D + @param[in] Instance - The instance of PCI device=0D =0D - @retval EFI_STATUS - Callback function failed.=0D + @retval EFI_SUCCESS - PCI Device check and Console variable update succe= ssfully.=0D + @retval EFI_STATUS - PCI Device check or Console variable update fail.=0D =0D **/=0D EFI_STATUS=0D EFIAPI=0D -VisitingAPciInstance (=0D +DetectAndPreparePlatformPciDevicePath (=0D IN EFI_HANDLE Handle,=0D - IN VOID *Instance,=0D - IN VOID *Context=0D + IN VOID *Instance=0D )=0D {=0D EFI_STATUS Status;=0D @@ -424,56 +421,6 @@ VisitingAPciInstance ( return Status;=0D }=0D =0D - return (*(VISIT_PCI_INSTANCE_CALLBACK)(UINTN)Context)(=0D - Handle,=0D - PciIo,=0D - &Pci=0D - );=0D -}=0D -=0D -/**=0D - For every PCI instance execute a callback function.=0D -=0D - @param[in] CallBackFunction - Callback function pointer=0D -=0D - @retval EFI_STATUS - Callback function failed.=0D -=0D -**/=0D -EFI_STATUS=0D -EFIAPI=0D -VisitAllPciInstances (=0D - IN VISIT_PCI_INSTANCE_CALLBACK CallBackFunction=0D - )=0D -{=0D - return VisitAllInstancesOfProtocol (=0D - &gEfiPciIoProtocolGuid,=0D - VisitingAPciInstance,=0D - (VOID *)(UINTN)CallBackFunction=0D - );=0D -}=0D -=0D -/**=0D - Do platform specific PCI Device check and add them to=0D - ConOut, ConIn, ErrOut.=0D -=0D - @param[in] Handle - Handle of PCI device instance=0D - @param[in] PciIo - PCI IO protocol instance=0D - @param[in] Pci - PCI Header register block=0D -=0D - @retval EFI_SUCCESS - PCI Device check and Console variable update succe= ssfully.=0D - @retval EFI_STATUS - PCI Device check or Console variable update fail.=0D -=0D -**/=0D -EFI_STATUS=0D -EFIAPI=0D -DetectAndPreparePlatformPciDevicePath (=0D - IN EFI_HANDLE Handle,=0D - IN EFI_PCI_IO_PROTOCOL *PciIo,=0D - IN PCI_TYPE00 *Pci=0D - )=0D -{=0D - EFI_STATUS Status;=0D -=0D Status =3D PciIo->Attributes (=0D PciIo,=0D EfiPciIoAttributeOperationEnable,=0D @@ -486,9 +433,9 @@ DetectAndPreparePlatformPciDevicePath ( //=0D // Here we decide whether it is LPC Bridge=0D //=0D - if ((IS_PCI_LPC (Pci)) ||=0D - ((IS_PCI_ISA_PDECODE (Pci)) &&=0D - (Pci->Hdr.VendorId =3D=3D 0x8086)=0D + if ((IS_PCI_LPC (&Pci)) ||=0D + ((IS_PCI_ISA_PDECODE (&Pci)) &&=0D + (Pci.Hdr.VendorId =3D=3D 0x8086)=0D )=0D )=0D {=0D @@ -504,7 +451,7 @@ DetectAndPreparePlatformPciDevicePath ( //=0D // Here we decide which Serial device to enable in PCI bus=0D //=0D - if (IS_PCI_16550SERIAL (Pci)) {=0D + if (IS_PCI_16550SERIAL (&Pci)) {=0D //=0D // Add them to ConOut, ConIn, ErrOut.=0D //=0D @@ -517,7 +464,7 @@ DetectAndPreparePlatformPciDevicePath ( //=0D // Enable all display devices=0D //=0D - if (IS_PCI_DISPLAY (Pci)) {=0D + if (IS_PCI_DISPLAY (&Pci)) {=0D //=0D // Add them to ConOut.=0D //=0D @@ -543,6 +490,8 @@ DetectAndPreparePlatformPciDevicePaths ( BOOLEAN DetectDisplayOnly=0D )=0D {=0D + EFI_STATUS Status;=0D +=0D mDetectDisplayOnly =3D DetectDisplayOnly;=0D =0D EfiBootManagerUpdateConsoleVariable (=0D @@ -551,7 +500,11 @@ DetectAndPreparePlatformPciDevicePaths ( NULL=0D );=0D =0D - return VisitAllPciInstances (DetectAndPreparePlatformPciDevicePath);=0D + Status =3D VisitAllInstancesOfProtocol (=0D + &gEfiPciIoProtocolGuid,=0D + DetectAndPreparePlatformPciDevicePath=0D + );=0D + return Status;=0D }=0D =0D /**=0D diff --git a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformConsole.= h b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformConsole.h index a13f4b8b59..3713c21c45 100644 --- a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformConsole.h +++ b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformConsole.h @@ -37,10 +37,9 @@ typedef struct { =0D typedef=0D EFI_STATUS=0D -(EFIAPI *PROTOCOL_INSTANCE_CALLBACK)(=0D +(EFIAPI *SIMPLE_PROTOCOL_INSTANCE_CALLBACK)(=0D IN EFI_HANDLE Handle,=0D - IN VOID *Instance,=0D - IN VOID *Context=0D + IN VOID *Instance=0D );=0D =0D /**=0D --=20 2.32.0.windows.2