From nobody Tue Feb 10 01:31:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+111093+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111093+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1699660775; cv=none; d=zohomail.com; s=zohoarc; b=PGxnT8HAO7eZFjSWKK7zm5osSYMCQ0ITd32iMYL4S5fzcr1KKDZcY4azJbX8//RgYiPt0vRQcBWzzZV0ZBLqz8COj1L6TPnpS9NWKPF/UkblfI+GQneYuzMuGXX77KY+NkfbOpDUFzhCTbsBjKiYtS0Or6VvJRgBqSvjPtAKt7k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699660775; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=h79X2eRqzFoKGNe3QAyBr0jn1lnfk/wWU6pMzaCYnZs=; b=YjzQVYYRzUWkpinE23xikbpMq3n0fqe0KgAbHTDcESQzjpOfpKyPLR8hrNOFeovznocM9z3B1ENYLNU2ZONhc2gSKu7ZCVAj6xiDJ36NwvqTZPJnhi+yopiMONbXuGxtM3Xu1SsYRLl+aAzYz1JBuvACGtx1C1gIJc+T7GxZC3s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111093+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1699660775973423.09779091720884; Fri, 10 Nov 2023 15:59:35 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=h79X2eRqzFoKGNe3QAyBr0jn1lnfk/wWU6pMzaCYnZs=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1699660775; v=1; b=NzLbM/D7SmxUED2wmjaKktUtgbQKiLaoSFmMrg3K3JEFQixZjBE+nteEVzMCpvMbUxelYRpH js2MRApknFeN5mEWe4Q/aTXkmDUeuK9uMqEVhWj88SRDEIwpbS7DY7+pnoGMyBtoeyNqR2gcxDN xNicH8bekdWEEJHiY6wd38pA= X-Received: by 127.0.0.2 with SMTP id Ds2jYY1788612x2PXSTrhKnt; Fri, 10 Nov 2023 15:59:35 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web11.42843.1699660774803137059 for ; Fri, 10 Nov 2023 15:59:35 -0800 X-Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-479-oGHwhZYWO0-hvIgZlv8olw-1; Fri, 10 Nov 2023 18:59:30 -0500 X-MC-Unique: oGHwhZYWO0-hvIgZlv8olw-1 X-Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7BC5C80B633; Fri, 10 Nov 2023 23:59:30 +0000 (UTC) X-Received: from lacos-laptop-9.usersys.redhat.com (unknown [10.39.192.173]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0ED1C15983; Fri, 10 Nov 2023 23:59:29 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Gerd Hoffmann , Jiewen Yao Subject: [edk2-devel] [PATCH 22/37] OvmfPkg: remove CsmSupportLib Date: Sat, 11 Nov 2023 00:58:05 +0100 Message-Id: <20231110235820.644381-23-lersek@redhat.com> In-Reply-To: <20231110235820.644381-1-lersek@redhat.com> References: <20231110235820.644381-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: Vy0UhpCctnxIWzGmqv9OEe6ax1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1699660777695100033 Content-Type: text/plain; charset="utf-8"; x-default="true" CsmSupportLib is not used by any platform at this point, remove it. This patch removes mentions of the following CSM resources from the source code [*]: - GUIDs (protocols or otherwise): - SYSTEM_ROM_FILE_GUID (1547B4F3-3E8A-4FEF-81C8-328ED647AB1A) - gEfiFirmwareVolumeProtocolGuid (by cutting the link) - gEfiLegacyBiosPlatformProtocolGuid - gEfiLegacyBiosProtocolGuid - gEfiLegacyInterruptProtocolGuid - headers: - FrameworkDxe.h - Protocol/FirmwareVolume.h - Protocol/LegacyBiosPlatform.h - Protocol/LegacyInterrupt.h which extends the list of resources scheduled for removal to: - GUIDs (protocols or otherwise): - SYSTEM_ROM_FILE_GUID (1547B4F3-3E8A-4FEF-81C8-328ED647AB1A) - gEfiFirmwareVolumeProtocolGuid - gEfiLegacy8259ProtocolGuid - gEfiLegacyBiosPlatformProtocolGuid - gEfiLegacyBiosProtocolGuid - gEfiLegacyInterruptProtocolGuid - headers: - FrameworkDxe.h - Protocol/FirmwareVolume.h - Protocol/Legacy8259.h - Protocol/LegacyBios.h - Protocol/LegacyBiosPlatform.h - Protocol/LegacyInterrupt.h [*] Note that gEfiLegacyRegion2ProtocolGuid, while a CSM-related protocol, cannot be scheduled for removal, because the protocol GUID is defined in "MdePkg.dec", and it's not only "OvmfPkg/Csm/CsmSupportLib" that produces it in all of edk2, but also "MdeModulePkg/Universal/LegacyRegion2Dxe" (not used by OVMF). For the same reason, the "Protocol/LegacyRegion2.h" header (from MdePkg) cannot be scheduled for removal. Cc: Ard Biesheuvel Cc: Gerd Hoffmann Cc: Jiewen Yao Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4588 Signed-off-by: Laszlo Ersek --- OvmfPkg/Csm/CsmSupportLib/CsmSupportLib.inf | 55 - OvmfPkg/Csm/CsmSupportLib/CsmSupportLib.h | 48 - OvmfPkg/Csm/CsmSupportLib/LegacyInterrupt.h | 115 --- OvmfPkg/Csm/CsmSupportLib/LegacyPlatform.h | 97 -- OvmfPkg/Csm/CsmSupportLib/LegacyRegion.h | 202 ---- OvmfPkg/Csm/CsmSupportLib/CsmSupportLib.c | 31 - OvmfPkg/Csm/CsmSupportLib/LegacyInterrupt.c | 212 ---- OvmfPkg/Csm/CsmSupportLib/LegacyPlatform.c | 1086 -------------------- OvmfPkg/Csm/CsmSupportLib/LegacyRegion.c | 506 --------- 9 files changed, 2352 deletions(-) diff --git a/OvmfPkg/Csm/CsmSupportLib/CsmSupportLib.inf b/OvmfPkg/Csm/CsmS= upportLib/CsmSupportLib.inf deleted file mode 100644 index 45f201f07b5f..000000000000 --- a/OvmfPkg/Csm/CsmSupportLib/CsmSupportLib.inf +++ /dev/null @@ -1,55 +0,0 @@ -## @file -# Platform CSM Support Library -# -# Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: BSD-2-Clause-Patent -# -## - -[Defines] - INF_VERSION =3D 0x00010005 - BASE_NAME =3D CsmSupportLib - FILE_GUID =3D 04e03541-4663-417d-93f6-976378247d61 - MODULE_TYPE =3D BASE - VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D CsmSupportLib - - CONSTRUCTOR =3D CsmSupportLibConstructor - -# -# The following information is for reference only and not required by the = build tools. -# -# VALID_ARCHITECTURES =3D IA32 X64 EBC -# - -[Sources] - CsmSupportLib.c - CsmSupportLib.h - LegacyInterrupt.c - LegacyInterrupt.h - LegacyPlatform.c - LegacyPlatform.h - LegacyRegion.c - LegacyRegion.h - -[Packages] - MdePkg/MdePkg.dec - OvmfPkg/OvmfPkg.dec - -[Pcd] - gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId - -[Protocols] - gEfiDevicePathProtocolGuid # PROTOCOL ALWAYS_CONSUMED - gEfiDiskInfoProtocolGuid # PROTOCOL ALWAYS_CONSUMED - gEfiLegacyBiosPlatformProtocolGuid # PROTOCOL ALWAYS_CONSUMED - gEfiLegacyBiosProtocolGuid # PROTOCOL ALWAYS_CONSUMED - gEfiLegacyInterruptProtocolGuid # PROTOCOL ALWAYS_PRODUCED - gEfiLegacyRegion2ProtocolGuid # PROTOCOL ALWAYS_PRODUCED - gEfiPciIoProtocolGuid # PROTOCOL ALWAYS_CONSUMED - -[LibraryClasses] - BaseLib - PciLib - IoLib - diff --git a/OvmfPkg/Csm/CsmSupportLib/CsmSupportLib.h b/OvmfPkg/Csm/CsmSup= portLib/CsmSupportLib.h deleted file mode 100644 index a6ee93f16739..000000000000 --- a/OvmfPkg/Csm/CsmSupportLib/CsmSupportLib.h +++ /dev/null @@ -1,48 +0,0 @@ -/** @file - Platform CSM Support Library - - Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.
- - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#ifndef _CSM_SUPPORT_LIB_H_ -#define _CSM_SUPPORT_LIB_H_ - -#include - -/** - Initialize Legacy Region support - - @retval EFI_SUCCESS Successfully initialized - -**/ -EFI_STATUS -LegacyRegionInit ( - VOID - ); - -/** - Initialize Legacy Interrupt support - - @retval EFI_SUCCESS Successfully initialized - -**/ -EFI_STATUS -LegacyInterruptInstall ( - VOID - ); - -/** - Initialize Legacy Platform support - - @retval EFI_SUCCESS Successfully initialized - -**/ -EFI_STATUS -LegacyBiosPlatformInstall ( - VOID - ); - -#endif diff --git a/OvmfPkg/Csm/CsmSupportLib/LegacyInterrupt.h b/OvmfPkg/Csm/CsmS= upportLib/LegacyInterrupt.h deleted file mode 100644 index 132365b9cc0e..000000000000 --- a/OvmfPkg/Csm/CsmSupportLib/LegacyInterrupt.h +++ /dev/null @@ -1,115 +0,0 @@ -/** @file - Legacy Region Support - - Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
- - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#ifndef _LEGACY_INTERRUPT_H_ -#define _LEGACY_INTERRUPT_H_ - -#include - -#include - -#include -#include -#include -#include -#include - -#define LEGACY_INT_BUS 0 -#define LEGACY_INT_DEV_PIIX4 0x01 -#define LEGACY_INT_DEV_Q35 0x1f -#define LEGACY_INT_FUNC 0 - -#define PIRQN 0x00 // PIRQ Null -#define PIRQA 0x60 -#define PIRQB 0x61 -#define PIRQC 0x62 -#define PIRQD 0x63 -#define PIRQE 0x68 -#define PIRQF 0x69 -#define PIRQG 0x6A -#define PIRQH 0x6B - -#define MAX_PIRQ_NUMBER 8 - -/** - Return the number of PIRQs supported by this chipset. - - @param[in] This Pointer to LegacyInterrupt Protocol - @param[out] NumberPirqs The pointer to return the max IRQ number suppor= ted - - @retval EFI_SUCCESS Max PIRQs successfully returned - -**/ -EFI_STATUS -EFIAPI -GetNumberPirqs ( - IN EFI_LEGACY_INTERRUPT_PROTOCOL *This, - OUT UINT8 *NumberPirqs - ); - -/** - Return PCI location of this device. - $PIR table requires this info. - - @param[in] This - Protocol instance pointer. - @param[out] Bus - PCI Bus - @param[out] Device - PCI Device - @param[out] Function - PCI Function - - @retval EFI_SUCCESS Bus/Device/Function returned - -**/ -EFI_STATUS -EFIAPI -GetLocation ( - IN EFI_LEGACY_INTERRUPT_PROTOCOL *This, - OUT UINT8 *Bus, - OUT UINT8 *Device, - OUT UINT8 *Function - ); - -/** - Read the given PIRQ register - - @param[in] This Protocol instance pointer - @param[in] PirqNumber The Pirq register 0 =3D A, 1 =3D B etc - @param[out] PirqData Value read - - @retval EFI_SUCCESS Decoding change affected. - @retval EFI_INVALID_PARAMETER Invalid PIRQ number - -**/ -EFI_STATUS -EFIAPI -ReadPirq ( - IN EFI_LEGACY_INTERRUPT_PROTOCOL *This, - IN UINT8 PirqNumber, - OUT UINT8 *PirqData - ); - -/** - Write the given PIRQ register - - @param[in] This Protocol instance pointer - @param[in] PirqNumber The Pirq register 0 =3D A, 1 =3D B etc - @param[out] PirqData Value to write - - @retval EFI_SUCCESS Decoding change affected. - @retval EFI_INVALID_PARAMETER Invalid PIRQ number - -**/ -EFI_STATUS -EFIAPI -WritePirq ( - IN EFI_LEGACY_INTERRUPT_PROTOCOL *This, - IN UINT8 PirqNumber, - IN UINT8 PirqData - ); - -#endif diff --git a/OvmfPkg/Csm/CsmSupportLib/LegacyPlatform.h b/OvmfPkg/Csm/CsmSu= pportLib/LegacyPlatform.h deleted file mode 100644 index 7dddd5200f43..000000000000 --- a/OvmfPkg/Csm/CsmSupportLib/LegacyPlatform.h +++ /dev/null @@ -1,97 +0,0 @@ -/** @file - Legacy BIOS Platform support - - Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
- - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#ifndef LEGACY_BIOS_PLATFORM_H_ -#define LEGACY_BIOS_PLATFORM_H_ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -// -// PIRQ information constants. -// -#define MAX_IRQ_ROUTING_ENTRIES 6 -#define MAX_IRQ_PRIORITY_ENTRIES 7 - -#define V_INTEL_VENDOR_ID 0x8086 -#define V_PIIX4_IDE_DEVICE_ID 0x7010 - -// -// Type declarations -// -typedef struct { - UINT8 SetupValue; - UINT16 DeviceType; - UINT8 Class; - UINT8 SubClass; -} EFI_SETUP_BBS_MAP; - -typedef struct { - UINT8 Class; - UINT8 SubClass; -} PCI_CLASS_RECORD; - -typedef struct { - EFI_LEGACY_PIRQ_TABLE_HEADER PirqTable; - EFI_LEGACY_IRQ_ROUTING_ENTRY IrqRoutingEntry[MAX_IRQ_ROUTING_ENTRIES]; -} EFI_LEGACY_PIRQ_TABLE; - -typedef struct { - EFI_HANDLE Handle; - UINT16 Vid; - UINT16 Did; - UINT16 SvId; - UINT16 SysId; -} DEVICE_STRUCTURE; - -typedef struct { - EFI_GUID FileName; - UINTN Valid; -} SYSTEM_ROM_TABLE; - -typedef struct { - UINT32 Signature; - EFI_HANDLE Handle; - EFI_LEGACY_BIOS_PLATFORM_PROTOCOL LegacyBiosPlatform; - EFI_HANDLE ImageHandle; - EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo; -} LEGACY_BIOS_PLATFORM_INSTANCE; - -#define LEGACY_BIOS_PLATFORM_INSTANCE_SIGNATURE SIGNATURE_32('P','B','I',= 'O') - -#define LEGACY_BIOS_PLATFORM_INSTANCE_FROM_THIS(this) \ - CR (this, \ - LEGACY_BIOS_PLATFORM_INSTANCE, \ - LegacyBiosPlatform, \ - LEGACY_BIOS_PLATFORM_INSTANCE_SIGNATURE \ - ) - -#endif diff --git a/OvmfPkg/Csm/CsmSupportLib/LegacyRegion.h b/OvmfPkg/Csm/CsmSupp= ortLib/LegacyRegion.h deleted file mode 100644 index 8ffe42a6a5e2..000000000000 --- a/OvmfPkg/Csm/CsmSupportLib/LegacyRegion.h +++ /dev/null @@ -1,202 +0,0 @@ -/** @file - Legacy Region Support - - Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.
- - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#ifndef _LEGACY_REGION_DXE_H_ -#define _LEGACY_REGION_DXE_H_ - -#include - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -#define PAM_BASE_ADDRESS 0xc0000 -#define PAM_LIMIT_ADDRESS BASE_1MB - -// -// Describes Legacy Region blocks and status. -// -typedef struct { - UINT32 Start; - UINT32 Length; - BOOLEAN ReadEnabled; - BOOLEAN WriteEnabled; -} LEGACY_MEMORY_SECTION_INFO; - -// -// Provides a map of the PAM registers and bits used to set Read/Write acc= ess. -// -typedef struct { - UINTN PAMRegPciLibAddress; - UINT8 ReadEnableData; - UINT8 WriteEnableData; -} PAM_REGISTER_VALUE; - -/** - Modify the hardware to allow (decode) or disallow (not decode) memory re= ads in a region. - - If the On parameter evaluates to TRUE, this function enables memory read= s in the address range - Start to (Start + Length - 1). - If the On parameter evaluates to FALSE, this function disables memory re= ads in the address range - Start to (Start + Length - 1). - - @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL i= nstance. - @param Start[in] The beginning of the physical address of t= he region whose attributes - should be modified. - @param Length[in] The number of bytes of memory whose attrib= utes should be modified. - The actual number of bytes modified may be= greater than the number - specified. - @param Granularity[out] The number of bytes in the last region aff= ected. This may be less - than the total number of bytes affected if= the starting address - was not aligned to a region's starting add= ress or if the length - was greater than the number of bytes in th= e first region. - @param On[in] Decode / Non-Decode flag. - - @retval EFI_SUCCESS The region's attributes were successfully = modified. - @retval EFI_INVALID_PARAMETER If Start or Length describe an address not= in the Legacy Region. - -**/ -EFI_STATUS -EFIAPI -LegacyRegion2Decode ( - IN EFI_LEGACY_REGION2_PROTOCOL *This, - IN UINT32 Start, - IN UINT32 Length, - OUT UINT32 *Granularity, - IN BOOLEAN *On - ); - -/** - Modify the hardware to disallow memory writes in a region. - - This function changes the attributes of a memory range to not allow writ= es. - - @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL i= nstance. - @param Start[in] The beginning of the physical address of t= he region whose - attributes should be modified. - @param Length[in] The number of bytes of memory whose attrib= utes should be modified. - The actual number of bytes modified may be= greater than the number - specified. - @param Granularity[out] The number of bytes in the last region aff= ected. This may be less - than the total number of bytes affected if= the starting address was - not aligned to a region's starting address= or if the length was - greater than the number of bytes in the fi= rst region. - - @retval EFI_SUCCESS The region's attributes were successfully = modified. - @retval EFI_INVALID_PARAMETER If Start or Length describe an address not= in the Legacy Region. - -**/ -EFI_STATUS -EFIAPI -LegacyRegion2Lock ( - IN EFI_LEGACY_REGION2_PROTOCOL *This, - IN UINT32 Start, - IN UINT32 Length, - OUT UINT32 *Granularity - ); - -/** - Modify the hardware to disallow memory attribute changes in a region. - - This function makes the attributes of a region read only. Once a region = is boot-locked with this - function, the read and write attributes of that region cannot be changed= until a power cycle has - reset the boot-lock attribute. Calls to Decode(), Lock() and Unlock() wi= ll have no effect. - - @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL i= nstance. - @param Start[in] The beginning of the physical address of t= he region whose - attributes should be modified. - @param Length[in] The number of bytes of memory whose attrib= utes should be modified. - The actual number of bytes modified may be= greater than the number - specified. - @param Granularity[out] The number of bytes in the last region aff= ected. This may be less - than the total number of bytes affected if= the starting address was - not aligned to a region's starting address= or if the length was - greater than the number of bytes in the fi= rst region. - - @retval EFI_SUCCESS The region's attributes were successfully = modified. - @retval EFI_INVALID_PARAMETER If Start or Length describe an address not= in the Legacy Region. - @retval EFI_UNSUPPORTED The chipset does not support locking the c= onfiguration registers in - a way that will not affect memory regions = outside the legacy memory - region. - -**/ -EFI_STATUS -EFIAPI -LegacyRegion2BootLock ( - IN EFI_LEGACY_REGION2_PROTOCOL *This, - IN UINT32 Start, - IN UINT32 Length, - OUT UINT32 *Granularity - ); - -/** - Modify the hardware to allow memory writes in a region. - - This function changes the attributes of a memory range to allow writes. - - @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL i= nstance. - @param Start[in] The beginning of the physical address of t= he region whose - attributes should be modified. - @param Length[in] The number of bytes of memory whose attrib= utes should be modified. - The actual number of bytes modified may be= greater than the number - specified. - @param Granularity[out] The number of bytes in the last region aff= ected. This may be less - than the total number of bytes affected if= the starting address was - not aligned to a region's starting address= or if the length was - greater than the number of bytes in the fi= rst region. - - @retval EFI_SUCCESS The region's attributes were successfully = modified. - @retval EFI_INVALID_PARAMETER If Start or Length describe an address not= in the Legacy Region. - -**/ -EFI_STATUS -EFIAPI -LegacyRegion2Unlock ( - IN EFI_LEGACY_REGION2_PROTOCOL *This, - IN UINT32 Start, - IN UINT32 Length, - OUT UINT32 *Granularity - ); - -/** - Get region information for the attributes of the Legacy Region. - - This function is used to discover the granularity of the attributes for = the memory in the legacy - region. Each attribute may have a different granularity and the granular= ity may not be the same - for all memory ranges in the legacy region. - - @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL i= nstance. - @param DescriptorCount[out] The number of region descriptor entries re= turned in the Descriptor - buffer. - @param Descriptor[out] A pointer to a pointer used to return a bu= ffer where the legacy - region information is deposited. This buff= er will contain a list of - DescriptorCount number of region descripto= rs. This function will - provide the memory for the buffer. - - @retval EFI_SUCCESS The region's attributes were successfully = modified. - @retval EFI_INVALID_PARAMETER If Start or Length describe an address not= in the Legacy Region. - -**/ -EFI_STATUS -EFIAPI -LegacyRegionGetInfo ( - IN EFI_LEGACY_REGION2_PROTOCOL *This, - OUT UINT32 *DescriptorCount, - OUT EFI_LEGACY_REGION_DESCRIPTOR **Descriptor - ); - -#endif diff --git a/OvmfPkg/Csm/CsmSupportLib/CsmSupportLib.c b/OvmfPkg/Csm/CsmSup= portLib/CsmSupportLib.c deleted file mode 100644 index 3ffd6e92b282..000000000000 --- a/OvmfPkg/Csm/CsmSupportLib/CsmSupportLib.c +++ /dev/null @@ -1,31 +0,0 @@ -/** @file - Platform CSM Support Library - - Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.
- - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "CsmSupportLib.h" - -/** - The constructor function for the platform CSM support library - - @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS. - -**/ -RETURN_STATUS -EFIAPI -CsmSupportLibConstructor ( - VOID - ) -{ - LegacyRegionInit (); - - LegacyInterruptInstall (); - - LegacyBiosPlatformInstall (); - - return EFI_SUCCESS; -} diff --git a/OvmfPkg/Csm/CsmSupportLib/LegacyInterrupt.c b/OvmfPkg/Csm/CsmS= upportLib/LegacyInterrupt.c deleted file mode 100644 index 410e4e457d9c..000000000000 --- a/OvmfPkg/Csm/CsmSupportLib/LegacyInterrupt.c +++ /dev/null @@ -1,212 +0,0 @@ -/** @file - Legacy Interrupt Support - - Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
- - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "LegacyInterrupt.h" - -// -// Handle for the Legacy Interrupt Protocol instance produced by this driv= er -// -STATIC EFI_HANDLE mLegacyInterruptHandle =3D NULL; - -// -// Legacy Interrupt Device number (0x01 on piix4, 0x1f on q35/mch) -// -STATIC UINT8 mLegacyInterruptDevice; - -// -// The Legacy Interrupt Protocol instance produced by this driver -// -STATIC EFI_LEGACY_INTERRUPT_PROTOCOL mLegacyInterrupt =3D { - GetNumberPirqs, - GetLocation, - ReadPirq, - WritePirq -}; - -STATIC UINT8 PirqReg[MAX_PIRQ_NUMBER] =3D { PIRQA, PIRQB, PIRQC, PIRQD, P= IRQE, PIRQF, PIRQG, PIRQH }; - -/** - Return the number of PIRQs supported by this chipset. - - @param[in] This Pointer to LegacyInterrupt Protocol - @param[out] NumberPirqs The pointer to return the max IRQ number suppor= ted - - @retval EFI_SUCCESS Max PIRQs successfully returned - -**/ -EFI_STATUS -EFIAPI -GetNumberPirqs ( - IN EFI_LEGACY_INTERRUPT_PROTOCOL *This, - OUT UINT8 *NumberPirqs - ) -{ - *NumberPirqs =3D MAX_PIRQ_NUMBER; - - return EFI_SUCCESS; -} - -/** - Return PCI location of this device. - $PIR table requires this info. - - @param[in] This - Protocol instance pointer. - @param[out] Bus - PCI Bus - @param[out] Device - PCI Device - @param[out] Function - PCI Function - - @retval EFI_SUCCESS Bus/Device/Function returned - -**/ -EFI_STATUS -EFIAPI -GetLocation ( - IN EFI_LEGACY_INTERRUPT_PROTOCOL *This, - OUT UINT8 *Bus, - OUT UINT8 *Device, - OUT UINT8 *Function - ) -{ - *Bus =3D LEGACY_INT_BUS; - *Device =3D mLegacyInterruptDevice; - *Function =3D LEGACY_INT_FUNC; - - return EFI_SUCCESS; -} - -/** - Builds the PCI configuration address for the register specified by PirqN= umber - - @param[in] PirqNumber - The PIRQ number to build the PCI configuration = address for - - @return The PCI Configuration address for the PIRQ -**/ -UINTN -GetAddress ( - UINT8 PirqNumber - ) -{ - return PCI_LIB_ADDRESS ( - LEGACY_INT_BUS, - mLegacyInterruptDevice, - LEGACY_INT_FUNC, - PirqReg[PirqNumber] - ); -} - -/** - Read the given PIRQ register - - @param[in] This Protocol instance pointer - @param[in] PirqNumber The Pirq register 0 =3D A, 1 =3D B etc - @param[out] PirqData Value read - - @retval EFI_SUCCESS Decoding change affected. - @retval EFI_INVALID_PARAMETER Invalid PIRQ number - -**/ -EFI_STATUS -EFIAPI -ReadPirq ( - IN EFI_LEGACY_INTERRUPT_PROTOCOL *This, - IN UINT8 PirqNumber, - OUT UINT8 *PirqData - ) -{ - if (PirqNumber >=3D MAX_PIRQ_NUMBER) { - return EFI_INVALID_PARAMETER; - } - - *PirqData =3D PciRead8 (GetAddress (PirqNumber)); - *PirqData =3D (UINT8)(*PirqData & 0x7f); - - return EFI_SUCCESS; -} - -/** - Write the given PIRQ register - - @param[in] This Protocol instance pointer - @param[in] PirqNumber The Pirq register 0 =3D A, 1 =3D B etc - @param[out] PirqData Value to write - - @retval EFI_SUCCESS Decoding change affected. - @retval EFI_INVALID_PARAMETER Invalid PIRQ number - -**/ -EFI_STATUS -EFIAPI -WritePirq ( - IN EFI_LEGACY_INTERRUPT_PROTOCOL *This, - IN UINT8 PirqNumber, - IN UINT8 PirqData - ) -{ - if (PirqNumber >=3D MAX_PIRQ_NUMBER) { - return EFI_INVALID_PARAMETER; - } - - PciWrite8 (GetAddress (PirqNumber), PirqData); - return EFI_SUCCESS; -} - -/** - Initialize Legacy Interrupt support - - @retval EFI_SUCCESS Successfully initialized - -**/ -EFI_STATUS -LegacyInterruptInstall ( - VOID - ) -{ - UINT16 HostBridgeDevId; - EFI_STATUS Status; - - // - // Make sure the Legacy Interrupt Protocol is not already installed in t= he system - // - ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiLegacyInterruptProtocolGui= d); - - // - // Query Host Bridge DID to determine platform type, then set device num= ber - // - HostBridgeDevId =3D PcdGet16 (PcdOvmfHostBridgePciDevId); - switch (HostBridgeDevId) { - case INTEL_82441_DEVICE_ID: - mLegacyInterruptDevice =3D LEGACY_INT_DEV_PIIX4; - break; - case INTEL_Q35_MCH_DEVICE_ID: - mLegacyInterruptDevice =3D LEGACY_INT_DEV_Q35; - break; - default: - DEBUG (( - DEBUG_ERROR, - "%a: Unknown Host Bridge Device ID: 0x%04x\n", - __func__, - HostBridgeDevId - )); - ASSERT (FALSE); - return EFI_UNSUPPORTED; - } - - // - // Make a new handle and install the protocol - // - Status =3D gBS->InstallMultipleProtocolInterfaces ( - &mLegacyInterruptHandle, - &gEfiLegacyInterruptProtocolGuid, - &mLegacyInterrupt, - NULL - ); - ASSERT_EFI_ERROR (Status); - - return Status; -} diff --git a/OvmfPkg/Csm/CsmSupportLib/LegacyPlatform.c b/OvmfPkg/Csm/CsmSu= pportLib/LegacyPlatform.c deleted file mode 100644 index 491897adbdf2..000000000000 --- a/OvmfPkg/Csm/CsmSupportLib/LegacyPlatform.c +++ /dev/null @@ -1,1086 +0,0 @@ -/** @file - Legacy BIOS Platform support - - Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
- - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "LegacyPlatform.h" - -EFI_SETUP_BBS_MAP mSetupBbsMap[] =3D { - { 1, 2, 1, 1 }, // ATA HardDrive - { 2, 3, 1, 1 }, // ATAPI CDROM - { 3, 0x80, 2, 0 }, // PXE - { 4, 1, 0, 6 }, // USB Floppy - { 4, 2, 0, 6 }, // USB HDD - { 4, 3, 0, 6 }, // USB CD - { 4, 1, 0, 0 }, // USB ZIP Bugbug since Class/SubClass code is u= ninitialized - { 4, 2, 0, 0 } // USB ZIP Bugbug since Class/SubClass code is u= ninitialized -}; - -// -// Global variables for System ROMs -// -#define SYSTEM_ROM_FILE_GUID \ -{ 0x1547B4F3, 0x3E8A, 0x4FEF, { 0x81, 0xC8, 0x32, 0x8E, 0xD6, 0x47, 0xAB, = 0x1A } } - -#define NULL_ROM_FILE_GUID \ -{ 0x00000000, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, = 0x00 } } - -SYSTEM_ROM_TABLE mSystemRomTable[] =3D { - { SYSTEM_ROM_FILE_GUID, 1 }, - { NULL_ROM_FILE_GUID, 0 } -}; - -EFI_HANDLE mVgaHandles[0x20]; -EFI_HANDLE mDiskHandles[0x20]; -EFI_HANDLE mIsaHandles[0x20]; - -EFI_LEGACY_IRQ_PRIORITY_TABLE_ENTRY IrqPriorityTable[MAX_IRQ_PRIORITY_ENT= RIES] =3D { - { 0x0B, 0 }, - { 0x09, 0 }, - { 0x0A, 0 }, - { 0x05, 0 }, - { 0x07, 0 }, - { 0x00, 0 }, - { 0x00, 0 } -}; - -// -// PIRQ Table -// - Slot numbering will be used to update the bus number and determine br= idge -// to check to get bus number. The Slot number - 1 is an index into a d= ecode -// table to get the bridge information. -// -EFI_LEGACY_PIRQ_TABLE PirqTableHead =3D { - { - EFI_LEGACY_PIRQ_TABLE_SIGNATURE, // UINT32 Signature - 0x00, // UINT8 MinorVersion - 0x01, // UINT8 MajorVersion - 0x0000, // UINT16 TableSize - 0x00, // UINT8 Bus - 0x08, // UINT8 DevFun - 0x0000, // UINT16 PciOnlyIrq - 0x8086, // UINT16 CompatibleVid - 0x122e, // UINT16 CompatibleDid - 0x00000000, // UINT32 Miniport - { // UINT8 Reserved[11] - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00 - }, - 0x00, // UINT8 Checksum - }, - { - // -- Pin 1 -- -- Pin 2 -- -- Pin 3 -- -- Pin 4 -- - // Bus Dev Reg Map Reg Map Reg Map Reg Map - // - { 0x00, 0x08, { - { 0x60, 0xDEB8 }, { 0x61, 0xDEB8 }, { 0x62, 0xDEB8 }, { 0x63, = 0xDEB8 } - }, 0x00, 0x00 }, - { 0x00, 0x10, { - { 0x61, 0xDEB8 }, { 0x62, 0xDEB8 }, { 0x63, 0xDEB8 }, { 0x60, = 0xDEB8 } - }, 0x01, 0x00 }, - { 0x00, 0x18, { - { 0x62, 0xDEB8 }, { 0x63, 0xDEB8 }, { 0x60, 0xDEB8 }, { 0x61, = 0xDEB8 } - }, 0x02, 0x00 }, - { 0x00, 0x20, { - { 0x63, 0xDEB8 }, { 0x60, 0xDEB8 }, { 0x61, 0xDEB8 }, { 0x62, = 0xDEB8 } - }, 0x03, 0x00 }, - { 0x00, 0x28, { - { 0x60, 0xDEB8 }, { 0x61, 0xDEB8 }, { 0x62, 0xDEB8 }, { 0x63, = 0xDEB8 } - }, 0x04, 0x00 }, - { 0x00, 0x30, { - { 0x61, 0xDEB8 }, { 0x62, 0xDEB8 }, { 0x63, 0xDEB8 }, { 0x60, = 0xDEB8 } - }, 0x05, 0x00 }, - } -}; - -LEGACY_BIOS_PLATFORM_INSTANCE mPrivateData; -EFI_HANDLE mImageHandle =3D NULL; - -/** - Return the handles and assorted information for the specified PCI Class = code - - @param[in] PciClasses Array of PCI_CLASS_RECORD to find terminate= d with ClassCode 0xff - @param[in,out] DeviceTable Table to place handles etc in. - @param[in,out] DeviceIndex Number of devices found - @param[in] DeviceFlags FALSE if a valid legacy ROM is required, TR= UE otherwise. - - @retval EFI_SUCCESS One or more devices found - @retval EFI_NOT_FOUND No device found - -**/ -EFI_STATUS -FindAllDeviceTypes ( - IN PCI_CLASS_RECORD *PciClasses, - IN OUT DEVICE_STRUCTURE *DeviceTable, - IN OUT UINT16 *DeviceIndex, - IN BOOLEAN DeviceFlags - ) -{ - UINTN HandleCount; - EFI_HANDLE *HandleBuffer; - UINTN Index; - UINTN StartIndex; - PCI_TYPE00 PciConfigHeader; - EFI_PCI_IO_PROTOCOL *PciIo; - EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; - UINTN Flags; - EFI_STATUS Status; - UINTN Index2; - - // - // Get legacy BIOS protocol as it is required to deal with Option ROMs. - // - StartIndex =3D *DeviceIndex; - Status =3D gBS->LocateProtocol ( - &gEfiLegacyBiosProtocolGuid, - NULL, - (VOID **)&LegacyBios - ); - ASSERT_EFI_ERROR (Status); - - // - // Get all PCI handles and check them to generate a list of matching dev= ices. - // - gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiPciIoProtocolGuid, - NULL, - &HandleCount, - &HandleBuffer - ); - for (Index =3D 0; Index < HandleCount; Index++) { - gBS->HandleProtocol ( - HandleBuffer[Index], - &gEfiPciIoProtocolGuid, - (VOID **)&PciIo - ); - PciIo->Pci.Read ( - PciIo, - EfiPciIoWidthUint32, - 0, - sizeof (PciConfigHeader) / sizeof (UINT32), - &PciConfigHeader - ); - for (Index2 =3D 0; PciClasses[Index2].Class !=3D 0xff; Index2++) { - if ((PciConfigHeader.Hdr.ClassCode[2] =3D=3D PciClasses[Index2].Clas= s) && - (PciConfigHeader.Hdr.ClassCode[1] =3D=3D PciClasses[Index2].SubC= lass)) - { - LegacyBios->CheckPciRom ( - LegacyBios, - HandleBuffer[Index], - NULL, - NULL, - &Flags - ); - - // - // Verify that results of OPROM check match request. - // The two valid requests are: - // DeviceFlags =3D 0 require a valid legacy ROM - // DeviceFlags =3D 1 require either no ROM or a valid legacy ROM - // - if ( - ((DeviceFlags !=3D 0) && (Flags =3D=3D NO_ROM)) || - ((Flags & (ROM_FOUND | VALID_LEGACY_ROM)) =3D=3D (ROM_FOUND | = VALID_LEGACY_ROM)) - ) - { - DeviceTable->Handle =3D HandleBuffer[Index]; - DeviceTable->Vid =3D PciConfigHeader.Hdr.VendorId; - DeviceTable->Did =3D PciConfigHeader.Hdr.DeviceId; - DeviceTable->SvId =3D PciConfigHeader.Device.SubsystemVendorID; - DeviceTable->SysId =3D PciConfigHeader.Device.SubsystemID; - ++*DeviceIndex; - DeviceTable++; - } - } - } - } - - // - // Free any allocated buffers - // - gBS->FreePool (HandleBuffer); - - if (*DeviceIndex !=3D StartIndex) { - return EFI_SUCCESS; - } else { - return EFI_NOT_FOUND; - } -} - -/** - Load and initialize the Legacy BIOS SMM handler. - - @param This The protocol instance pointer. - @param EfiToLegacy16BootTable A pointer to Legacy16 boot table. - - @retval EFI_SUCCESS SMM code loaded. - @retval EFI_DEVICE_ERROR SMM code failed to load - -**/ -EFI_STATUS -EFIAPI -SmmInit ( - IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This, - IN VOID *EfiToLegacy16BootTable - ) -{ - return EFI_SUCCESS; -} - -/** - Finds the device path that should be used as the primary display adapter. - - @param VgaHandle - The handle of the video device - -**/ -VOID -GetSelectedVgaDeviceInfo ( - OUT EFI_HANDLE *VgaHandle - ) -{ - EFI_STATUS Status; - UINTN HandleCount; - EFI_HANDLE *HandleBuffer; - UINTN Index; - EFI_PCI_IO_PROTOCOL *PciIo; - PCI_TYPE00 Pci; - UINT8 MinBus; - UINT8 MaxBus; - UINTN Segment; - UINTN Bus; - UINTN Device; - UINTN Function; - UINTN SelectedAddress; - UINTN CurrentAddress; - - // - // Initialize return to 'not found' state - // - *VgaHandle =3D NULL; - - // - // Initialize variable states. This is important for selecting the VGA - // device if multiple devices exist behind a single bridge. - // - HandleCount =3D 0; - HandleBuffer =3D NULL; - SelectedAddress =3D PCI_LIB_ADDRESS (0xff, 0x1f, 0x7, 0); - - // - // The bus range to search for a VGA device in. - // - MinBus =3D MaxBus =3D 0; - - // - // Start to check all the pci io to find all possible VGA device - // - HandleCount =3D 0; - HandleBuffer =3D NULL; - Status =3D gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiPciIoProtocolGuid, - NULL, - &HandleCount, - &HandleBuffer - ); - if (EFI_ERROR (Status)) { - return; - } - - for (Index =3D 0; Index < HandleCount; Index++) { - Status =3D gBS->HandleProtocol (HandleBuffer[Index], &gEfiPciIoProtoco= lGuid, (VOID **)&PciIo); - if (!EFI_ERROR (Status)) { - // - // Determine if this is in the correct bus range. - // - Status =3D PciIo->GetLocation (PciIo, &Segment, &Bus, &Device, &Func= tion); - if (EFI_ERROR (Status) || ((Bus < MinBus) || (Bus > MaxBus))) { - continue; - } - - // - // Read device information. - // - Status =3D PciIo->Pci.Read ( - PciIo, - EfiPciIoWidthUint32, - 0, - sizeof (Pci) / sizeof (UINT32), - &Pci - ); - if (EFI_ERROR (Status)) { - continue; - } - - // - // Make sure the device is a VGA device. - // - if (!IS_PCI_VGA (&Pci)) { - continue; - } - - DEBUG (( - DEBUG_INFO, - "PCI VGA: 0x%04x:0x%04x\n", - Pci.Hdr.VendorId, - Pci.Hdr.DeviceId - )); - - // - // Currently we use the lowest numbered bus/device/function if multi= ple - // devices are found in the target bus range. - // - CurrentAddress =3D PCI_LIB_ADDRESS (Bus, Device, Function, 0); - if (CurrentAddress < SelectedAddress) { - SelectedAddress =3D CurrentAddress; - *VgaHandle =3D HandleBuffer[Index]; - } - } - } - - FreePool (HandleBuffer); -} - -/** - Returns a buffer of handles for the requested subfunction. - - @param This The protocol instance pointer. - @param Mode Specifies what handle to return. See EFI_G= ET_PLATFORM_HANDLE_MODE enum. - @param Type Mode specific. See EFI_GET_PLATFORM_HANDLE= _MODE enum. - @param HandleBuffer Mode specific. See EFI_GET_PLATFORM_HANDLE= _MODE enum. - @param HandleCount Mode specific. See EFI_GET_PLATFORM_HANDLE= _MODE enum. - @param AdditionalData Mode specific. See EFI_GET_PLATFORM_HANDLE= _MODE enum. - - @retval EFI_SUCCESS Handle is valid. - @retval EFI_UNSUPPORTED Mode is not supported on the platform. - @retval EFI_NOT_FOUND Handle is not known. - -**/ -EFI_STATUS -EFIAPI -GetPlatformHandle ( - IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This, - IN EFI_GET_PLATFORM_HANDLE_MODE Mode, - IN UINT16 Type, - OUT EFI_HANDLE **HandleBuffer, - OUT UINTN *HandleCount, - OUT VOID **AdditionalData OPTIONAL - ) -{ - DEVICE_STRUCTURE LocalDevice[0x40]; - UINT32 LocalIndex; - UINT32 Index; - DEVICE_STRUCTURE TempDevice; - EFI_STATUS Status; - EFI_PCI_IO_PROTOCOL *PciIo; - UINTN Segment; - UINTN Bus; - UINTN Device; - UINTN Function; - HDD_INFO *HddInfo; - PCI_TYPE00 PciConfigHeader; - UINT32 HddIndex; - EFI_HANDLE IdeHandle; - EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; - PCI_CLASS_RECORD ClassLists[10]; - UINTN PriorityIndex; - - static BOOLEAN bConnected =3D FALSE; - - LocalIndex =3D 0x00; - HddInfo =3D NULL; - HddIndex =3D 0; - - Status =3D gBS->LocateProtocol ( - &gEfiLegacyBiosProtocolGuid, - NULL, - (VOID **)&LegacyBios - ); - - // - // Process mode specific operations - // - switch (Mode) { - case EfiGetPlatformVgaHandle: - // - // Get the handle for the currently selected VGA device. - // - GetSelectedVgaDeviceInfo (&mVgaHandles[0]); - *HandleBuffer =3D &mVgaHandles[0]; - *HandleCount =3D (mVgaHandles[0] !=3D NULL) ? 1 : 0; - return EFI_SUCCESS; - case EfiGetPlatformIdeHandle: - IdeHandle =3D NULL; - if (AdditionalData !=3D NULL) { - HddInfo =3D (HDD_INFO *)*AdditionalData; - } - - // - // Locate all found block io devices - // - ClassLists[0].Class =3D PCI_CLASS_MASS_STORAGE; - ClassLists[0].SubClass =3D PCI_CLASS_MASS_STORAGE_SCSI; - ClassLists[1].Class =3D PCI_CLASS_MASS_STORAGE; - ClassLists[1].SubClass =3D PCI_CLASS_MASS_STORAGE_IDE; - ClassLists[2].Class =3D PCI_CLASS_MASS_STORAGE; - ClassLists[2].SubClass =3D PCI_CLASS_MASS_STORAGE_RAID; - ClassLists[3].Class =3D PCI_CLASS_MASS_STORAGE; - ClassLists[3].SubClass =3D PCI_CLASS_MASS_STORAGE_SATADPA; - ClassLists[4].Class =3D 0xff; - FindAllDeviceTypes (ClassLists, LocalDevice, (UINT16 *)&LocalIndex, = TRUE); - if (LocalIndex =3D=3D 0) { - return EFI_NOT_FOUND; - } - - // - // Make sure all IDE controllers are connected. This is necessary - // in NO_CONFIG_CHANGE boot path to ensure IDE controller is correct= ly - // initialized and all IDE drives are enumerated - // - if (!bConnected) { - for (Index =3D 0; Index < LocalIndex; Index++) { - gBS->ConnectController (LocalDevice[Index].Handle, NULL, NULL, T= RUE); - } - } - - // - // Locate onboard controllers. - // - for (Index =3D 0; Index < LocalIndex; Index++) { - if (LocalDevice[Index].Vid =3D=3D V_INTEL_VENDOR_ID) { - if (LocalDevice[Index].Did =3D=3D V_PIIX4_IDE_DEVICE_ID) { - IdeHandle =3D LocalDevice[Index].Handle; - } - } - } - - // - // Set the IDE contorller as primary devices. - // - PriorityIndex =3D 0; - for (Index =3D 0; Index < LocalIndex; Index++) { - if ((LocalDevice[Index].Handle =3D=3D IdeHandle) && (PriorityIndex= =3D=3D 0)) { - TempDevice =3D LocalDevice[PriorityIndex]; - LocalDevice[PriorityIndex] =3D LocalDevice[Index]; - LocalDevice[Index] =3D TempDevice; - PriorityIndex++; - break; - } - } - - // - // Copy over handles and update return values. - // - for (Index =3D 0; Index < LocalIndex; Index++) { - mDiskHandles[Index] =3D LocalDevice[Index].Handle; - } - - *HandleBuffer =3D &mDiskHandles[0]; - *HandleCount =3D LocalIndex; - - // - // We have connected all IDE controllers once. No more needed - // - bConnected =3D TRUE; - - // - // Log all onboard controllers. - // - for (Index =3D 0; (Index < LocalIndex) && (AdditionalData !=3D NULL)= ; Index++) { - if ((LocalDevice[Index].Handle !=3D NULL) && - (LocalDevice[Index].Handle =3D=3D IdeHandle)) - { - Status =3D gBS->HandleProtocol ( - LocalDevice[Index].Handle, - &gEfiPciIoProtocolGuid, - (VOID **)&PciIo - ); - PciIo->Pci.Read ( - PciIo, - EfiPciIoWidthUint32, - 0, - sizeof (PciConfigHeader) / sizeof (UINT32), - &PciConfigHeader - ); - if (!EFI_ERROR (Status)) { - PciIo->GetLocation ( - PciIo, - &Segment, - &Bus, - &Device, - &Function - ); - - // - // Be sure to only fill out correct information based on platf= orm - // configuration. - // - HddInfo[HddIndex].Status |=3D HDD_PRIMARY; - HddInfo[HddIndex].Bus =3D (UINT32)Bus; - HddInfo[HddIndex].Device =3D (UINT32)Device; - HddInfo[HddIndex].Function =3D (UINT32)Function; - HddInfo[HddIndex + 1].Status |=3D HDD_SECONDARY; - HddInfo[HddIndex + 1].Bus =3D (UINT32)Bus; - HddInfo[HddIndex + 1].Device =3D (UINT32)Device; - HddInfo[HddIndex + 1].Function =3D (UINT32)Function; - - // - // Primary controller data - // - if ((PciConfigHeader.Hdr.ClassCode[0] & 0x01) !=3D 0) { - HddInfo[HddIndex].CommandBaseAddress =3D - (UINT16)(PciConfigHeader.Device.Bar[0] & 0xfffc); - HddInfo[HddIndex].ControlBaseAddress =3D - (UINT16)((PciConfigHeader.Device.Bar[1] & 0xfffc)+2); - HddInfo[HddIndex].BusMasterAddress =3D - (UINT16)(PciConfigHeader.Device.Bar[4] & 0xfffc); - HddInfo[HddIndex].HddIrq =3D PciConfigHeader.Device.Interrup= tLine; - } else { - HddInfo[HddIndex].HddIrq =3D 14; - HddInfo[HddIndex].CommandBaseAddress =3D 0x1f0; - HddInfo[HddIndex].ControlBaseAddress =3D 0x3f6; - HddInfo[HddIndex].BusMasterAddress =3D 0; - } - - HddIndex++; - - // - // Secondary controller data - // - if ((PciConfigHeader.Hdr.ClassCode[0] & 0x04) !=3D 0) { - HddInfo[HddIndex].CommandBaseAddress =3D - (UINT16)(PciConfigHeader.Device.Bar[2] & 0xfffc); - HddInfo[HddIndex].ControlBaseAddress =3D - (UINT16)((PciConfigHeader.Device.Bar[3] & 0xfffc)+2); - HddInfo[HddIndex].BusMasterAddress =3D - (UINT16)(HddInfo[HddIndex].BusMasterAddress + 8); - HddInfo[HddIndex].HddIrq =3D PciConfigHeader.Device.Interrup= tLine; - } else { - HddInfo[HddIndex].HddIrq =3D 15; - HddInfo[HddIndex].CommandBaseAddress =3D 0x170; - HddInfo[HddIndex].ControlBaseAddress =3D 0x376; - HddInfo[HddIndex].BusMasterAddress =3D 0; - } - - HddIndex++; - } - } - } - - return EFI_SUCCESS; - case EfiGetPlatformIsaBusHandle: - ClassLists[0].Class =3D (UINT8)PCI_CLASS_BRIDGE; - ClassLists[0].SubClass =3D (UINT8)PCI_CLASS_BRIDGE_ISA_PDECODE; - ClassLists[1].Class =3D (UINT8)PCI_CLASS_BRIDGE; - ClassLists[1].SubClass =3D (UINT8)PCI_CLASS_BRIDGE_ISA; - ClassLists[2].Class =3D 0xff; - - // - // Locate all found block io devices - // - FindAllDeviceTypes (ClassLists, LocalDevice, (UINT16 *)(&LocalIndex)= , TRUE); - if (LocalIndex =3D=3D 0) { - return EFI_NOT_FOUND; - } - - // - // Find our ISA bridge. - // - for (Index =3D 0; Index < LocalIndex; Index++) { - if (LocalDevice[Index].Vid =3D=3D V_INTEL_VENDOR_ID) { - TempDevice =3D LocalDevice[0]; - LocalDevice[0] =3D LocalDevice[Index]; - LocalDevice[Index] =3D TempDevice; - } - } - - // - // Perform copy and update return values. - // - for (Index =3D 0; Index < LocalIndex; Index++) { - mIsaHandles[Index] =3D LocalDevice[Index].Handle; - } - - *HandleBuffer =3D &mIsaHandles[0]; - *HandleCount =3D LocalIndex; - return EFI_SUCCESS; - case EfiGetPlatformUsbHandle: - default: - return EFI_UNSUPPORTED; - } -} - -/** - Allows platform to perform any required action after a LegacyBios operat= ion. - Invokes the specific sub function specified by Mode. - - @param This The protocol instance pointer. - @param Mode Specifies what handle to return. See EFI_G= ET_PLATFORM_HOOK_MODE enum. - @param Type Mode specific. See EFI_GET_PLATFORM_HOOK_= MODE enum. - @param DeviceHandle Mode specific. See EFI_GET_PLATFORM_HOOK_= MODE enum. - @param ShadowAddress Mode specific. See EFI_GET_PLATFORM_HOOK_= MODE enum. - @param Compatibility16Table Mode specific. See EFI_GET_PLATFORM_HOOK_= MODE enum. - @param AdditionalData Mode specific. See EFI_GET_PLATFORM_HOOK_= MODE enum. - - @retval EFI_SUCCESS The operation performed successfully. Mode= specific. - @retval EFI_UNSUPPORTED Mode is not supported on the platform. - -**/ -EFI_STATUS -EFIAPI -PlatformHooks ( - IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This, - IN EFI_GET_PLATFORM_HOOK_MODE Mode, - IN UINT16 Type, - OUT EFI_HANDLE DeviceHandle OPTIONAL, - IN OUT UINTN *Shadowaddress OPTIONAL, - IN EFI_COMPATIBILITY16_TABLE *Compatibility16Table OPTIO= NAL, - OUT VOID **AdditionalData OPTIONAL - ) -{ - EFI_IA32_REGISTER_SET Regs; - EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; - EFI_STATUS Status; - - switch (Mode) { - case EfiPlatformHookPrepareToScanRom: - Status =3D gBS->LocateProtocol ( - &gEfiLegacyBiosProtocolGuid, - NULL, - (VOID **)&LegacyBios - ); - - // - // Set the 80x25 Text VGA Mode - // - Regs.H.AH =3D 0x00; - Regs.H.AL =3D 0x03; - Status =3D LegacyBios->Int86 (LegacyBios, 0x10, &Regs); - return Status; - case EfiPlatformHookShadowServiceRoms: - return EFI_SUCCESS; - case EfiPlatformHookAfterRomInit: - default: - return EFI_UNSUPPORTED; - } -} - -/** - Returns information associated with PCI IRQ routing. - This function returns the following information associated with PCI IRQ = routing: - * An IRQ routing table and number of entries in the table. - * The $PIR table and its size. - * A list of PCI IRQs and the priority order to assign them. - - @param This The protocol instance pointer. - @param RoutingTable The pointer to PCI IRQ Routing table. - This location is the $PIR table minus th= e header. - @param RoutingTableEntries The number of entries in table. - @param LocalPirqTable $PIR table. - @param PirqTableSize $PIR table size. - @param LocalIrqPriorityTable A list of interrupts in priority order t= o assign. - @param IrqPriorityTableEntries The number of entries in the priority ta= ble. - - @retval EFI_SUCCESS Data was successfully returned. - -**/ -EFI_STATUS -EFIAPI -GetRoutingTable ( - IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This, - OUT VOID **RoutingTable, - OUT UINTN *RoutingTableEntries, - OUT VOID **LocalPirqTable OPTIONAL, - OUT UINTN *PirqTableSize OPTIONAL, - OUT VOID **LocalIrqPriorityTable OPTIONAL, - OUT UINTN *IrqPriorityTableEntries OPTIONAL - ) -{ - UINT16 PTableSize; - UINT32 Index; - UINT8 Bus; - UINT8 Device; - UINT8 Function; - UINT8 Checksum; - UINT8 *Ptr; - EFI_STATUS Status; - EFI_LEGACY_INTERRUPT_PROTOCOL *LegacyInterrupt; - - Checksum =3D 0; - - if (LocalPirqTable !=3D NULL) { - PTableSize =3D sizeof (EFI_LEGACY_PIRQ_TABLE_HEADER) + - sizeof (EFI_LEGACY_IRQ_ROUTING_ENTRY) * MAX_IRQ_ROUTING_E= NTRIES; - - Status =3D gBS->LocateProtocol ( - &gEfiLegacyInterruptProtocolGuid, - NULL, - (VOID **)&LegacyInterrupt - ); - ASSERT_EFI_ERROR (Status); - LegacyInterrupt->GetLocation ( - LegacyInterrupt, - &Bus, - &Device, - &Function - ); - - // - // Update fields in $PIR table header - // - PirqTableHead.PirqTable.TableSize =3D PTableSize; - PirqTableHead.PirqTable.Bus =3D Bus; - PirqTableHead.PirqTable.DevFun =3D (UINT8)((Device << 3) + Function= ); - Ptr =3D (UINT8 *)(&PirqTableHead); - - // - // Calculate checksum. - // - for (Index =3D 0; Index < PTableSize; Index++) { - Checksum =3D (UINT8)(Checksum + (UINT8)*Ptr); - Ptr +=3D 1; - } - - Checksum =3D (UINT8)(0x00 - Checksum); - PirqTableHead.PirqTable.Checksum =3D Checksum; - - // - // Update return values. - // - *LocalPirqTable =3D (VOID *)(&PirqTableHead); - *PirqTableSize =3D PTableSize; - } - - // - // More items to return. - // - *RoutingTable =3D PirqTableHead.IrqRoutingEntry; - *RoutingTableEntries =3D MAX_IRQ_ROUTING_ENTRIES; - if (LocalIrqPriorityTable !=3D NULL) { - *LocalIrqPriorityTable =3D IrqPriorityTable; - *IrqPriorityTableEntries =3D MAX_IRQ_PRIORITY_ENTRIES; - } - - return EFI_SUCCESS; -} - -/** - Finds the binary data or other platform information. - - @param This The protocol instance pointer. - @param Mode Specifies what data to return. See See EFI= _GET_PLATFORM_INFO_MODE enum. - @param Table Mode specific. See EFI_GET_PLATFORM_INFO_= MODE enum. - @param TableSize Mode specific. See EFI_GET_PLATFORM_INFO_= MODE enum. - @param Location Mode specific. See EFI_GET_PLATFORM_INFO_= MODE enum. - @param Alignment Mode specific. See EFI_GET_PLATFORM_INFO_= MODE enum. - @param LegacySegment Mode specific. See EFI_GET_PLATFORM_INFO_= MODE enum. - @param LegacyOffset Mode specific. See EFI_GET_PLATFORM_INFO_= MODE enum. - - @retval EFI_SUCCESS Data returned successfully. - @retval EFI_UNSUPPORTED Mode is not supported on the platform. - @retval EFI_NOT_FOUND Binary image or table not found. - -**/ -EFI_STATUS -EFIAPI -GetPlatformInfo ( - IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This, - IN EFI_GET_PLATFORM_INFO_MODE Mode, - OUT VOID **Table, - OUT UINTN *TableSize, - OUT UINTN *Location, - OUT UINTN *Alignment, - IN UINT16 LegacySegment, - IN UINT16 LegacyOffset - ) -{ - EFI_STATUS Status; - UINTN Index; - - switch (Mode) { - case EfiGetPlatformBinarySystemRom: - // - // Loop through table of System rom descriptions - // - for (Index =3D 0; mSystemRomTable[Index].Valid !=3D 0; Index++) { - Status =3D GetSectionFromFv ( - &mSystemRomTable[Index].FileName, - EFI_SECTION_RAW, - 0, - Table, - (UINTN *)TableSize - ); - if (EFI_ERROR (Status)) { - continue; - } - - return EFI_SUCCESS; - } - - return EFI_NOT_FOUND; - case EfiGetPlatformBinaryOem16Data: - case EfiGetPlatformBinaryMpTable: - case EfiGetPlatformBinaryOemIntData: - case EfiGetPlatformBinaryOem32Data: - case EfiGetPlatformBinaryTpmBinary: - case EfiGetPlatformPciExpressBase: - default: - return EFI_UNSUPPORTED; - } -} - -/** - Translates the given PIRQ accounting for bridge. - This function translates the given PIRQ back through all buses, if requi= red, - and returns the true PIRQ and associated IRQ. - - @param This The protocol instance pointer. - @param PciBus The PCI bus number for this device. - @param PciDevice The PCI device number for this device. - @param PciFunction The PCI function number for this device. - @param Pirq Input is PIRQ reported by device, and outp= ut is true PIRQ. - @param PciIrq The IRQ already assigned to the PIRQ, or t= he IRQ to be - assigned to the PIRQ. - - @retval EFI_SUCCESS The PIRQ was translated. - -**/ -EFI_STATUS -EFIAPI -TranslatePirq ( - IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This, - IN UINTN PciBus, - IN UINTN PciDevice, - IN UINTN PciFunction, - IN OUT UINT8 *Pirq, - OUT UINT8 *PciIrq - ) -{ - EFI_LEGACY_INTERRUPT_PROTOCOL *LegacyInterrupt; - EFI_STATUS Status; - UINTN Index; - UINTN Index1; - UINT8 LocalPirq; - UINT8 PirqData; - UINT8 MatchData; - - Status =3D gBS->LocateProtocol ( - &gEfiLegacyInterruptProtocolGuid, - NULL, - (VOID **)&LegacyInterrupt - ); - ASSERT_EFI_ERROR (Status); - LocalPirq =3D (UINT8)(*Pirq); - - for (Index =3D 0; Index < MAX_IRQ_ROUTING_ENTRIES; Index++) { - if ((PirqTableHead.IrqRoutingEntry[Index].Bus =3D=3D PciBus) && - (PirqTableHead.IrqRoutingEntry[Index].Device =3D=3D PciDevice)) - { - LocalPirq =3D (UINT8)(PirqTableHead.IrqRoutingEntry[Index].PirqEntry= [LocalPirq].Pirq & 0x0f); - if (LocalPirq > 4) { - LocalPirq -=3D 4; - } - - LegacyInterrupt->ReadPirq (LegacyInterrupt, LocalPirq, &PirqData); - MatchData =3D PCI_UNUSED; - while (PirqData =3D=3D 0) { - for (Index1 =3D 0; Index1 < MAX_IRQ_PRIORITY_ENTRIES; Index1++) { - if ((IrqPriorityTable[Index1].Used =3D=3D MatchData) && - (IrqPriorityTable[Index1].Irq !=3D 0)) - { - PirqData =3D IrqPriorityTable[Index1].Irq; - IrqPriorityTable[Index1].Used =3D 0xff; - LegacyInterrupt->WritePirq ( - LegacyInterrupt, - LocalPirq, - PirqData - ); - break; - } - } - - if (PirqData =3D=3D 0) { - // - // No unused interrupts, so start reusing them. - // - MatchData =3D (UINT8)(~MatchData); - } - } - - *PciIrq =3D PirqData; - *Pirq =3D LocalPirq; - } - } - - return EFI_SUCCESS; -} - -/** - Attempt to legacy boot the BootOption. If the EFI contexted has been - compromised this function will not return. - - @param This The protocol instance pointer. - @param BbsDevicePath The EFI Device Path from BootXXXX variabl= e. - @param BbsTable The Internal BBS table. - @param LoadOptionSize The size of LoadOption in size. - @param LoadOption The LoadOption from BootXXXX variable - @param EfiToLegacy16BootTable A pointer to BootTable structure - - @retval EFI_SUCCESS Ready to boot. - -**/ -EFI_STATUS -EFIAPI -PrepareToBoot ( - IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This, - IN BBS_BBS_DEVICE_PATH *BbsDevicePath, - IN VOID *BbsTable, - IN UINT32 LoadOptionsSize, - IN VOID *LoadOptions, - IN VOID *EfiToLegacy16BootTable - ) -{ - BBS_TABLE *LocalBbsTable; - EFI_TO_COMPATIBILITY16_BOOT_TABLE *Legacy16BootTable; - DEVICE_PRODUCER_DATA_HEADER *SioPtr; - UINT16 DevicePathType; - UINT16 Index; - UINT16 Priority; - - // - // Initialize values - // - Priority =3D 0; - Legacy16BootTable =3D (EFI_TO_COMPATIBILITY16_BOOT_TABLE *)EfiToLegacy16= BootTable; - - // - // Set how Gate A20 is gated by hardware - // - SioPtr =3D &Legacy16BootTable->SioData; - SioPtr->Flags.A20Kybd =3D 1; - SioPtr->Flags.A20Port90 =3D 1; - SioPtr->MousePresent =3D 1; - - LocalBbsTable =3D BbsTable; - - // - // There are 2 cases that must be covered. - // Case 1: Booting to a legacy OS - BbsDevicePath is non-NULL. - // Case 2: Booting to an EFI aware OS - BbsDevicePath is NULL. - // We need to perform the PrepareToBoot function to assign - // drive numbers to HDD devices to allow the shell or EFI - // to access them. - // - if (BbsDevicePath !=3D NULL) { - DevicePathType =3D BbsDevicePath->DeviceType; - } else { - DevicePathType =3D BBS_HARDDISK; - } - - // - // Skip the boot devices where priority is set by BDS and set the next o= ne - // - for (Index =3D 0; Index < Legacy16BootTable->NumberBbsEntries; Index++) { - if ((LocalBbsTable[Index].BootPriority !=3D BBS_UNPRIORITIZED_ENTRY) && - (LocalBbsTable[Index].BootPriority !=3D BBS_IGNORE_ENTRY) && - (LocalBbsTable[Index].BootPriority !=3D BBS_LOWEST_PRIORITY) && - (Priority <=3D LocalBbsTable[Index].BootPriority)) - { - Priority =3D (UINT16)(LocalBbsTable[Index].BootPriority + 1); - } - } - - switch (DevicePathType) { - case BBS_FLOPPY: - case BBS_HARDDISK: - case BBS_CDROM: - case BBS_EMBED_NETWORK: - for (Index =3D 0; Index < Legacy16BootTable->NumberBbsEntries; Index= ++) { - if ((LocalBbsTable[Index].BootPriority =3D=3D BBS_UNPRIORITIZED_EN= TRY) && - (LocalBbsTable[Index].DeviceType =3D=3D DevicePathType)) - { - LocalBbsTable[Index].BootPriority =3D Priority; - ++Priority; - } - } - - break; - case BBS_BEV_DEVICE: - for (Index =3D 0; Index < Legacy16BootTable->NumberBbsEntries; Index= ++) { - if ((LocalBbsTable[Index].BootPriority =3D=3D BBS_UNPRIORITIZED_EN= TRY) && - (LocalBbsTable[Index].Class =3D=3D 01) && - (LocalBbsTable[Index].SubClass =3D=3D 01)) - { - LocalBbsTable[Index].BootPriority =3D Priority; - ++Priority; - } - } - - break; - case BBS_USB: - case BBS_PCMCIA: - case BBS_UNKNOWN: - default: - break; - } - - // - // Set priority for rest of devices - // - for (Index =3D 0; Index < Legacy16BootTable->NumberBbsEntries; Index++) { - if (LocalBbsTable[Index].BootPriority =3D=3D BBS_UNPRIORITIZED_ENTRY) { - LocalBbsTable[Index].BootPriority =3D Priority; - ++Priority; - } - } - - return EFI_SUCCESS; -} - -/** - Initialize Legacy Platform support - - @retval EFI_SUCCESS Successfully initialized - -**/ -EFI_STATUS -LegacyBiosPlatformInstall ( - VOID - ) -{ - EFI_STATUS Status; - LEGACY_BIOS_PLATFORM_INSTANCE *Private; - - mImageHandle =3D gImageHandle; - Private =3D &mPrivateData; - - // - // Grab a copy of all the protocols we depend on. - // - Private->Signature =3D LEGACY_BIOS_PLATFORM_I= NSTANCE_SIGNATURE; - Private->LegacyBiosPlatform.GetPlatformInfo =3D GetPlatformInfo; - Private->LegacyBiosPlatform.GetPlatformHandle =3D GetPlatformHandle; - Private->LegacyBiosPlatform.SmmInit =3D SmmInit; - Private->LegacyBiosPlatform.PlatformHooks =3D PlatformHooks; - Private->LegacyBiosPlatform.GetRoutingTable =3D GetRoutingTable; - Private->LegacyBiosPlatform.TranslatePirq =3D TranslatePirq; - Private->LegacyBiosPlatform.PrepareToBoot =3D PrepareToBoot; - Private->ImageHandle =3D gImageHandle; - - // - // Make a new handle and install the protocol - // - Private->Handle =3D NULL; - Status =3D gBS->InstallProtocolInterface ( - &Private->Handle, - &gEfiLegacyBiosPlatformProtocolGuid, - EFI_NATIVE_INTERFACE, - &Private->LegacyBiosPlatform - ); - return Status; -} diff --git a/OvmfPkg/Csm/CsmSupportLib/LegacyRegion.c b/OvmfPkg/Csm/CsmSupp= ortLib/LegacyRegion.c deleted file mode 100644 index 3c32b75bd692..000000000000 --- a/OvmfPkg/Csm/CsmSupportLib/LegacyRegion.c +++ /dev/null @@ -1,506 +0,0 @@ -/** @file - Legacy Region Support - - Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
- - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "LegacyRegion.h" - -// -// 440/Q35 PAM map. -// -// PAM Range Offset Bits Operation -// 440 Q35 -// =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D =3D=3D=3D= =3D =3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D -// 0xC0000-0xC3FFF 0x5a 0x91 1:0 00 =3D DRAM Disabled, 01=3D Read Onl= y, 10 =3D Write Only, 11 =3D Normal -// 0xC4000-0xC7FFF 0x5a 0x91 5:4 00 =3D DRAM Disabled, 01=3D Read Onl= y, 10 =3D Write Only, 11 =3D Normal -// 0xC8000-0xCBFFF 0x5b 0x92 1:0 00 =3D DRAM Disabled, 01=3D Read Onl= y, 10 =3D Write Only, 11 =3D Normal -// 0xCC000-0xCFFFF 0x5b 0x92 5:4 00 =3D DRAM Disabled, 01=3D Read Onl= y, 10 =3D Write Only, 11 =3D Normal -// 0xD0000-0xD3FFF 0x5c 0x93 1:0 00 =3D DRAM Disabled, 01=3D Read Onl= y, 10 =3D Write Only, 11 =3D Normal -// 0xD4000-0xD7FFF 0x5c 0x93 5:4 00 =3D DRAM Disabled, 01=3D Read Onl= y, 10 =3D Write Only, 11 =3D Normal -// 0xD8000-0xDBFFF 0x5d 0x94 1:0 00 =3D DRAM Disabled, 01=3D Read Onl= y, 10 =3D Write Only, 11 =3D Normal -// 0xDC000-0xDFFFF 0x5d 0x94 5:4 00 =3D DRAM Disabled, 01=3D Read Onl= y, 10 =3D Write Only, 11 =3D Normal -// 0xE0000-0xE3FFF 0x5e 0x95 1:0 00 =3D DRAM Disabled, 01=3D Read Onl= y, 10 =3D Write Only, 11 =3D Normal -// 0xE4000-0xE7FFF 0x5e 0x95 5:4 00 =3D DRAM Disabled, 01=3D Read Onl= y, 10 =3D Write Only, 11 =3D Normal -// 0xE8000-0xEBFFF 0x5f 0x96 1:0 00 =3D DRAM Disabled, 01=3D Read Onl= y, 10 =3D Write Only, 11 =3D Normal -// 0xEC000-0xEFFFF 0x5f 0x96 5:4 00 =3D DRAM Disabled, 01=3D Read Onl= y, 10 =3D Write Only, 11 =3D Normal -// 0xF0000-0xFFFFF 0x59 0x90 5:4 00 =3D DRAM Disabled, 01=3D Read Onl= y, 10 =3D Write Only, 11 =3D Normal -// -STATIC LEGACY_MEMORY_SECTION_INFO mSectionArray[] =3D { - { 0xC0000, SIZE_16KB, FALSE, FALSE }, - { 0xC4000, SIZE_16KB, FALSE, FALSE }, - { 0xC8000, SIZE_16KB, FALSE, FALSE }, - { 0xCC000, SIZE_16KB, FALSE, FALSE }, - { 0xD0000, SIZE_16KB, FALSE, FALSE }, - { 0xD4000, SIZE_16KB, FALSE, FALSE }, - { 0xD8000, SIZE_16KB, FALSE, FALSE }, - { 0xDC000, SIZE_16KB, FALSE, FALSE }, - { 0xE0000, SIZE_16KB, FALSE, FALSE }, - { 0xE4000, SIZE_16KB, FALSE, FALSE }, - { 0xE8000, SIZE_16KB, FALSE, FALSE }, - { 0xEC000, SIZE_16KB, FALSE, FALSE }, - { 0xF0000, SIZE_64KB, FALSE, FALSE } -}; - -STATIC PAM_REGISTER_VALUE mRegisterValues440[] =3D { - { PMC_REGISTER_PIIX4 (PIIX4_PAM1), 0x01, 0x02 }, - { PMC_REGISTER_PIIX4 (PIIX4_PAM1), 0x10, 0x20 }, - { PMC_REGISTER_PIIX4 (PIIX4_PAM2), 0x01, 0x02 }, - { PMC_REGISTER_PIIX4 (PIIX4_PAM2), 0x10, 0x20 }, - { PMC_REGISTER_PIIX4 (PIIX4_PAM3), 0x01, 0x02 }, - { PMC_REGISTER_PIIX4 (PIIX4_PAM3), 0x10, 0x20 }, - { PMC_REGISTER_PIIX4 (PIIX4_PAM4), 0x01, 0x02 }, - { PMC_REGISTER_PIIX4 (PIIX4_PAM4), 0x10, 0x20 }, - { PMC_REGISTER_PIIX4 (PIIX4_PAM5), 0x01, 0x02 }, - { PMC_REGISTER_PIIX4 (PIIX4_PAM5), 0x10, 0x20 }, - { PMC_REGISTER_PIIX4 (PIIX4_PAM6), 0x01, 0x02 }, - { PMC_REGISTER_PIIX4 (PIIX4_PAM6), 0x10, 0x20 }, - { PMC_REGISTER_PIIX4 (PIIX4_PAM0), 0x10, 0x20 } -}; - -STATIC PAM_REGISTER_VALUE mRegisterValuesQ35[] =3D { - { DRAMC_REGISTER_Q35 (MCH_PAM1), 0x01, 0x02 }, - { DRAMC_REGISTER_Q35 (MCH_PAM1), 0x10, 0x20 }, - { DRAMC_REGISTER_Q35 (MCH_PAM2), 0x01, 0x02 }, - { DRAMC_REGISTER_Q35 (MCH_PAM2), 0x10, 0x20 }, - { DRAMC_REGISTER_Q35 (MCH_PAM3), 0x01, 0x02 }, - { DRAMC_REGISTER_Q35 (MCH_PAM3), 0x10, 0x20 }, - { DRAMC_REGISTER_Q35 (MCH_PAM4), 0x01, 0x02 }, - { DRAMC_REGISTER_Q35 (MCH_PAM4), 0x10, 0x20 }, - { DRAMC_REGISTER_Q35 (MCH_PAM5), 0x01, 0x02 }, - { DRAMC_REGISTER_Q35 (MCH_PAM5), 0x10, 0x20 }, - { DRAMC_REGISTER_Q35 (MCH_PAM6), 0x01, 0x02 }, - { DRAMC_REGISTER_Q35 (MCH_PAM6), 0x10, 0x20 }, - { DRAMC_REGISTER_Q35 (MCH_PAM0), 0x10, 0x20 } -}; - -STATIC PAM_REGISTER_VALUE *mRegisterValues; - -// -// Handle used to install the Legacy Region Protocol -// -STATIC EFI_HANDLE mHandle =3D NULL; - -// -// Instance of the Legacy Region Protocol to install into the handle datab= ase -// -STATIC EFI_LEGACY_REGION2_PROTOCOL mLegacyRegion2 =3D { - LegacyRegion2Decode, - LegacyRegion2Lock, - LegacyRegion2BootLock, - LegacyRegion2Unlock, - LegacyRegionGetInfo -}; - -STATIC -EFI_STATUS -LegacyRegionManipulationInternal ( - IN UINT32 Start, - IN UINT32 Length, - IN BOOLEAN *ReadEnable, - IN BOOLEAN *WriteEnable, - OUT UINT32 *Granularity - ) -{ - UINT32 EndAddress; - UINTN Index; - UINTN StartIndex; - - // - // Validate input parameters. - // - if ((Length =3D=3D 0) || (Granularity =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - EndAddress =3D Start + Length - 1; - if ((Start < PAM_BASE_ADDRESS) || (EndAddress > PAM_LIMIT_ADDRESS)) { - return EFI_INVALID_PARAMETER; - } - - // - // Loop to find the start PAM. - // - StartIndex =3D 0; - for (Index =3D 0; Index < ARRAY_SIZE (mSectionArray); Index++) { - if ((Start >=3D mSectionArray[Index].Start) && (Start < (mSectionArray= [Index].Start + mSectionArray[Index].Length))) { - StartIndex =3D Index; - break; - } - } - - ASSERT (Index < ARRAY_SIZE (mSectionArray)); - - // - // Program PAM until end PAM is encountered - // - for (Index =3D StartIndex; Index < ARRAY_SIZE (mSectionArray); Index++) { - if (ReadEnable !=3D NULL) { - if (*ReadEnable) { - PciOr8 ( - mRegisterValues[Index].PAMRegPciLibAddress, - mRegisterValues[Index].ReadEnableData - ); - } else { - PciAnd8 ( - mRegisterValues[Index].PAMRegPciLibAddress, - (UINT8)(~mRegisterValues[Index].ReadEnableData) - ); - } - } - - if (WriteEnable !=3D NULL) { - if (*WriteEnable) { - PciOr8 ( - mRegisterValues[Index].PAMRegPciLibAddress, - mRegisterValues[Index].WriteEnableData - ); - } else { - PciAnd8 ( - mRegisterValues[Index].PAMRegPciLibAddress, - (UINT8)(~mRegisterValues[Index].WriteEnableData) - ); - } - } - - // - // If the end PAM is encountered, record its length as granularity and= jump out. - // - if ((EndAddress >=3D mSectionArray[Index].Start) && (EndAddress < (mSe= ctionArray[Index].Start + mSectionArray[Index].Length))) { - *Granularity =3D mSectionArray[Index].Length; - break; - } - } - - ASSERT (Index < ARRAY_SIZE (mSectionArray)); - - return EFI_SUCCESS; -} - -STATIC -EFI_STATUS -LegacyRegionGetInfoInternal ( - OUT UINT32 *DescriptorCount, - OUT LEGACY_MEMORY_SECTION_INFO **Descriptor - ) -{ - UINTN Index; - UINT8 PamValue; - - // - // Check input parameters - // - if ((DescriptorCount =3D=3D NULL) || (Descriptor =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - // - // Fill in current status of legacy region. - // - *DescriptorCount =3D sizeof (mSectionArray) / sizeof (mSectionArray[0]); - for (Index =3D 0; Index < *DescriptorCount; Index++) { - PamValue =3D PciRead8 (mRegisterValues[Index].= PAMRegPciLibAddress); - mSectionArray[Index].ReadEnabled =3D FALSE; - if ((PamValue & mRegisterValues[Index].ReadEnableData) !=3D 0) { - mSectionArray[Index].ReadEnabled =3D TRUE; - } - - mSectionArray[Index].WriteEnabled =3D FALSE; - if ((PamValue & mRegisterValues[Index].WriteEnableData) !=3D 0) { - mSectionArray[Index].WriteEnabled =3D TRUE; - } - } - - *Descriptor =3D mSectionArray; - return EFI_SUCCESS; -} - -/** - Modify the hardware to allow (decode) or disallow (not decode) memory re= ads in a region. - - If the On parameter evaluates to TRUE, this function enables memory read= s in the address range - Start to (Start + Length - 1). - If the On parameter evaluates to FALSE, this function disables memory re= ads in the address range - Start to (Start + Length - 1). - - @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL i= nstance. - @param Start[in] The beginning of the physical address of t= he region whose attributes - should be modified. - @param Length[in] The number of bytes of memory whose attrib= utes should be modified. - The actual number of bytes modified may be= greater than the number - specified. - @param Granularity[out] The number of bytes in the last region aff= ected. This may be less - than the total number of bytes affected if= the starting address - was not aligned to a region's starting add= ress or if the length - was greater than the number of bytes in th= e first region. - @param On[in] Decode / Non-Decode flag. - - @retval EFI_SUCCESS The region's attributes were successfully = modified. - @retval EFI_INVALID_PARAMETER If Start or Length describe an address not= in the Legacy Region. - -**/ -EFI_STATUS -EFIAPI -LegacyRegion2Decode ( - IN EFI_LEGACY_REGION2_PROTOCOL *This, - IN UINT32 Start, - IN UINT32 Length, - OUT UINT32 *Granularity, - IN BOOLEAN *On - ) -{ - return LegacyRegionManipulationInternal (Start, Length, On, NULL, Granul= arity); -} - -/** - Modify the hardware to disallow memory attribute changes in a region. - - This function makes the attributes of a region read only. Once a region = is boot-locked with this - function, the read and write attributes of that region cannot be changed= until a power cycle has - reset the boot-lock attribute. Calls to Decode(), Lock() and Unlock() wi= ll have no effect. - - @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL i= nstance. - @param Start[in] The beginning of the physical address of t= he region whose - attributes should be modified. - @param Length[in] The number of bytes of memory whose attrib= utes should be modified. - The actual number of bytes modified may be= greater than the number - specified. - @param Granularity[out] The number of bytes in the last region aff= ected. This may be less - than the total number of bytes affected if= the starting address was - not aligned to a region's starting address= or if the length was - greater than the number of bytes in the fi= rst region. - - @retval EFI_SUCCESS The region's attributes were successfully = modified. - @retval EFI_INVALID_PARAMETER If Start or Length describe an address not= in the Legacy Region. - @retval EFI_UNSUPPORTED The chipset does not support locking the c= onfiguration registers in - a way that will not affect memory regions = outside the legacy memory - region. - -**/ -EFI_STATUS -EFIAPI -LegacyRegion2BootLock ( - IN EFI_LEGACY_REGION2_PROTOCOL *This, - IN UINT32 Start, - IN UINT32 Length, - OUT UINT32 *Granularity - ) -{ - if ((Start < 0xC0000) || ((Start + Length - 1) > 0xFFFFF)) { - return EFI_INVALID_PARAMETER; - } - - return EFI_UNSUPPORTED; -} - -/** - Modify the hardware to disallow memory writes in a region. - - This function changes the attributes of a memory range to not allow writ= es. - - @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL i= nstance. - @param Start[in] The beginning of the physical address of t= he region whose - attributes should be modified. - @param Length[in] The number of bytes of memory whose attrib= utes should be modified. - The actual number of bytes modified may be= greater than the number - specified. - @param Granularity[out] The number of bytes in the last region aff= ected. This may be less - than the total number of bytes affected if= the starting address was - not aligned to a region's starting address= or if the length was - greater than the number of bytes in the fi= rst region. - - @retval EFI_SUCCESS The region's attributes were successfully = modified. - @retval EFI_INVALID_PARAMETER If Start or Length describe an address not= in the Legacy Region. - -**/ -EFI_STATUS -EFIAPI -LegacyRegion2Lock ( - IN EFI_LEGACY_REGION2_PROTOCOL *This, - IN UINT32 Start, - IN UINT32 Length, - OUT UINT32 *Granularity - ) -{ - BOOLEAN WriteEnable; - - WriteEnable =3D FALSE; - return LegacyRegionManipulationInternal (Start, Length, NULL, &WriteEnab= le, Granularity); -} - -/** - Modify the hardware to allow memory writes in a region. - - This function changes the attributes of a memory range to allow writes. - - @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL i= nstance. - @param Start[in] The beginning of the physical address of t= he region whose - attributes should be modified. - @param Length[in] The number of bytes of memory whose attrib= utes should be modified. - The actual number of bytes modified may be= greater than the number - specified. - @param Granularity[out] The number of bytes in the last region aff= ected. This may be less - than the total number of bytes affected if= the starting address was - not aligned to a region's starting address= or if the length was - greater than the number of bytes in the fi= rst region. - - @retval EFI_SUCCESS The region's attributes were successfully = modified. - @retval EFI_INVALID_PARAMETER If Start or Length describe an address not= in the Legacy Region. - -**/ -EFI_STATUS -EFIAPI -LegacyRegion2Unlock ( - IN EFI_LEGACY_REGION2_PROTOCOL *This, - IN UINT32 Start, - IN UINT32 Length, - OUT UINT32 *Granularity - ) -{ - BOOLEAN WriteEnable; - - WriteEnable =3D TRUE; - return LegacyRegionManipulationInternal (Start, Length, NULL, &WriteEnab= le, Granularity); -} - -/** - Get region information for the attributes of the Legacy Region. - - This function is used to discover the granularity of the attributes for = the memory in the legacy - region. Each attribute may have a different granularity and the granular= ity may not be the same - for all memory ranges in the legacy region. - - @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL i= nstance. - @param DescriptorCount[out] The number of region descriptor entries re= turned in the Descriptor - buffer. - @param Descriptor[out] A pointer to a pointer used to return a bu= ffer where the legacy - region information is deposited. This buff= er will contain a list of - DescriptorCount number of region descripto= rs. This function will - provide the memory for the buffer. - - @retval EFI_SUCCESS The region's attributes were successfully = modified. - @retval EFI_INVALID_PARAMETER If Start or Length describe an address not= in the Legacy Region. - -**/ -EFI_STATUS -EFIAPI -LegacyRegionGetInfo ( - IN EFI_LEGACY_REGION2_PROTOCOL *This, - OUT UINT32 *DescriptorCount, - OUT EFI_LEGACY_REGION_DESCRIPTOR **Descriptor - ) -{ - LEGACY_MEMORY_SECTION_INFO *SectionInfo; - UINT32 SectionCount; - EFI_LEGACY_REGION_DESCRIPTOR *DescriptorArray; - UINTN Index; - UINTN DescriptorIndex; - - // - // Get section numbers and information - // - LegacyRegionGetInfoInternal (&SectionCount, &SectionInfo); - - // - // Each section has 3 descriptors, corresponding to readability, writeab= ility, and lock status. - // - DescriptorArray =3D AllocatePool (sizeof (EFI_LEGACY_REGION_DESCRIPTOR) = * SectionCount * 3); - if (DescriptorArray =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - DescriptorIndex =3D 0; - for (Index =3D 0; Index < SectionCount; Index++) { - DescriptorArray[DescriptorIndex].Start =3D SectionInfo[Index].St= art; - DescriptorArray[DescriptorIndex].Length =3D SectionInfo[Index].Le= ngth; - DescriptorArray[DescriptorIndex].Granularity =3D SectionInfo[Index].Le= ngth; - if (SectionInfo[Index].ReadEnabled) { - DescriptorArray[DescriptorIndex].Attribute =3D LegacyRegionDecoded; - } else { - DescriptorArray[DescriptorIndex].Attribute =3D LegacyRegionNotDecode= d; - } - - DescriptorIndex++; - - // - // Create descriptor for writeability, according to lock status - // - DescriptorArray[DescriptorIndex].Start =3D SectionInfo[Index].St= art; - DescriptorArray[DescriptorIndex].Length =3D SectionInfo[Index].Le= ngth; - DescriptorArray[DescriptorIndex].Granularity =3D SectionInfo[Index].Le= ngth; - if (SectionInfo[Index].WriteEnabled) { - DescriptorArray[DescriptorIndex].Attribute =3D LegacyRegionWriteEnab= led; - } else { - DescriptorArray[DescriptorIndex].Attribute =3D LegacyRegionWriteDisa= bled; - } - - DescriptorIndex++; - - // - // Chipset does not support bootlock. - // - DescriptorArray[DescriptorIndex].Start =3D SectionInfo[Index].St= art; - DescriptorArray[DescriptorIndex].Length =3D SectionInfo[Index].Le= ngth; - DescriptorArray[DescriptorIndex].Granularity =3D SectionInfo[Index].Le= ngth; - DescriptorArray[DescriptorIndex].Attribute =3D LegacyRegionNotLocked; - DescriptorIndex++; - } - - *DescriptorCount =3D (UINT32)DescriptorIndex; - *Descriptor =3D DescriptorArray; - - return EFI_SUCCESS; -} - -/** - Initialize Legacy Region support - - @retval EFI_SUCCESS Successfully initialized - -**/ -EFI_STATUS -LegacyRegionInit ( - VOID - ) -{ - EFI_STATUS Status; - UINT16 HostBridgeDevId; - - // - // Query Host Bridge DID to determine platform type - // - HostBridgeDevId =3D PcdGet16 (PcdOvmfHostBridgePciDevId); - switch (HostBridgeDevId) { - case INTEL_82441_DEVICE_ID: - mRegisterValues =3D mRegisterValues440; - break; - case INTEL_Q35_MCH_DEVICE_ID: - mRegisterValues =3D mRegisterValuesQ35; - break; - default: - DEBUG (( - DEBUG_ERROR, - "%a: Unknown Host Bridge Device ID: 0x%04x\n", - __func__, - HostBridgeDevId - )); - ASSERT (FALSE); - return RETURN_UNSUPPORTED; - } - - // - // Install the Legacy Region Protocol on a new handle - // - Status =3D gBS->InstallMultipleProtocolInterfaces ( - &mHandle, - &gEfiLegacyRegion2ProtocolGuid, - &mLegacyRegion2, - NULL - ); - ASSERT_EFI_ERROR (Status); - - return Status; -} -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111093): https://edk2.groups.io/g/devel/message/111093 Mute This Topic: https://groups.io/mt/102518662/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-