From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (NAM02-SN1-obe.outbound.protection.outlook.com [40.92.5.97]) by mx.groups.io with SMTP id smtpd.web12.1585.1609873206760904138 for ; Tue, 05 Jan 2021 11:00:07 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@outlook.com header.s=selector1 header.b=twlZbqNn; spf=pass (domain: outlook.com, ip: 40.92.5.97, mailfrom: kun.q@outlook.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b2nz9GiMhC3VPw37AChvbGAI1oAIc3h5g3Y4LcM8p06kC/f8MZOVo8j20RbzngQ55maln0rWVnbpo/u48RUXDmvKtK6R52Vo3AUUdaFsteI5l+5mwRQS7jl0Evb1QZJeKHOfMN5NC6dz5n3SqrJZX9WdjmHKIaRpoCGxjhUd97KqKp7CNhzu5oIkGPVjRi2k+3ZH1S2pr5VXi0u/iuIHW89XyZYHIdgRAm74KYzdq11KR2JM0qcxSSlvLyL3OT3+IbIWWN8cQ8n1RuXdeYjhhdnfzkjmEr/Jcp4a5aEaLG4dBpQ3xiaD/XHIUY5AS9+zN2+Mlb3+2KXCD/pHFcpYuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Sp3K3yNtc1uU0kZ8ykA9TZmzgiW5nUgkOBUXaOvMB2g=; b=UUGXXSMtD2oRoObeFsk2q3H3QsIsSVaKmGMYyb8XRMLHVFMi3e4JAZEZ1UTb8ByqCVqGIEso6vE1dD2AZC9NoCM00Z9sHxBJiD0dZX0ycEUgqeK+h0Tv19hFEYLoriPCnbavGcVcbQs1dqp6AOXx2VJqswIB2LnJgbSYsfZZ+yBzPIZXyLtRFK+W4VhPNs9PPFhQ4ifBYy1XzfwyW3A/8WociISnQTSlKWT9fkoIPZwF1UwxNhQ5ZrePVaqGWf81SNhkhQFm1rPao5HoOaFDsBS99TMfir8hxJVkiuSY+IZoKljkJygvXnyHWLozLWfCtPgVHxft3ROAasmQLIUOMg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Sp3K3yNtc1uU0kZ8ykA9TZmzgiW5nUgkOBUXaOvMB2g=; b=twlZbqNnjJYaIoHuIeFCfp2UaQjP1+VaCynkVg6CFh7N2qPQ1FIyHhrFYUcXFdojaAQr+mCW3xzn4Z4KjJYOKze6JDFBzBMQ4txc8IlkPUA7rVrV9tpcXEunQ5ru9IoVmHENVtBYW+ANo9oVj6yXEgFAuvj3yMtUFd+UYH3rkl+0Af1RGndtEFnkHjMUjwrR6bGHIDlpYxyeUmyAWxvOpmb1ye2TZ8g3TGD8WDfa/VX26EXa6ntCjMjNKGdSgFT7jOe7LJPYEGblId90aK51e81HWjjfcp+TLwAE5RMZWDXyoe9/dkDX1/6ZJZwXFuJ5F4XiCXdQJKzPvZR7O14LOw== Received: from CY1NAM02FT003.eop-nam02.prod.protection.outlook.com (10.152.74.51) by CY1NAM02HT012.eop-nam02.prod.protection.outlook.com (10.152.74.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.22; Tue, 5 Jan 2021 19:00:04 +0000 Received: from MWHPR06MB3102.namprd06.prod.outlook.com (2a01:111:e400:7e45::53) by CY1NAM02FT003.mail.protection.outlook.com (2a01:111:e400:7e45::151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.22 via Frontend Transport; Tue, 5 Jan 2021 19:00:04 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:55FD2BEE6772B0AC499D91CA97F50D2D047E952A513C486ECB98467B8EB91DB9;UpperCasedChecksum:36CEDF249B2438867BFB10788C264A77D8CD2691C0A866C415876365C8F8B0BE;SizeAsReceived:7479;Count:47 Received: from MWHPR06MB3102.namprd06.prod.outlook.com ([fe80::acb3:ab69:563d:b0d6]) by MWHPR06MB3102.namprd06.prod.outlook.com ([fe80::acb3:ab69:563d:b0d6%5]) with mapi id 15.20.3721.024; Tue, 5 Jan 2021 19:00:03 +0000 From: "Kun Qin" To: devel@edk2.groups.io CC: Eric Dong , Ray Ni , Laszlo Ersek , Rahul Kumar Subject: [PATCH v2 15/16] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm Date: Tue, 5 Jan 2021 10:59:34 -0800 Message-ID: X-Mailer: git-send-email 2.30.0.windows.1 In-Reply-To: <20210105185935.3769-1-kun.q@outlook.com> References: <20210105185935.3769-1-kun.q@outlook.com> X-TMN: [dNJ1aFrMu79pC33+FeU8s4Eut7gihIND] X-ClientProxiedBy: MWHPR22CA0045.namprd22.prod.outlook.com (2603:10b6:300:69::31) To MWHPR06MB3102.namprd06.prod.outlook.com (2603:10b6:301:3e::35) Return-Path: kun.q@outlook.com X-Microsoft-Original-Message-ID: <20210105185935.3769-16-kun.q@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (50.35.88.161) by MWHPR22CA0045.namprd22.prod.outlook.com (2603:10b6:300:69::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Tue, 5 Jan 2021 19:00:03 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 47 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 075add9c-dce7-4078-bd8f-08d8b1ac1c01 X-MS-TrafficTypeDiagnostic: CY1NAM02HT012: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GcKeMf5mOE6KlLoVq184syuS3rKlodC6Ii3SPtvJpps8JfI1RPBAQc2dyaw8SRouG56caOWsjmPxXTfefrO1oC4rpi31d8CSTFYbtdehjjdaQi51IenUz9pGAgzoqL4M3WIbFKjUWglg/6mVsgumECheiGx5tqJeXV4CcWT5mln9lNttYs5RBlhBefdBzTjW4VmHzx4qme2KqB30FvnMVJU/uAw4Zc2b9UKxFnWQp502896QMZ1ZGlTTSmyEI+/U X-MS-Exchange-AntiSpam-MessageData: 4mNjYYxXtE55Ed85A8kzRaUcm3aCB97Jdn+2BfgO32YRhXoqv8CF9Ty1Mr8F5lw1My/bdGYqeDhhlWmskDDe8yh/XV7k5CfHMa06KYRVPH62bUxB7NrOI1twxqvViKt9WxlFLOS1GjfRF8N1Qshc0w== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2021 19:00:03.4602 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-Network-Message-Id: 075add9c-dce7-4078-bd8f-08d8b1ac1c01 X-MS-Exchange-CrossTenant-AuthSource: CY1NAM02FT003.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1NAM02HT012 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain This change added support of CpuIo driver under StandaloneMm. The core services switched to gMmst based instead of gMmst. It also abstracts standalone and traditional MM driver entrypoints into separate files to allow maximal common implementations. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Cc: Rahul Kumar Signed-off-by: Kun Qin --- Notes: v2: - Removed "EFIAPI" for internal functions. UefiCpuPkg/CpuIo2Smm/{CpuIo2Smm.c =3D> CpuIo2Common.c} | 15 +- UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c | 384 +----= --------------- UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.c | 31 ++ UefiCpuPkg/CpuIo2Smm/{CpuIo2Smm.h =3D> CpuIo2Common.h} | 17 +- UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf | 7 +- UefiCpuPkg/CpuIo2Smm/{CpuIo2Smm.inf =3D> CpuIo2StandaloneMm.inf} | 23 +- UefiCpuPkg/UefiCpuPkg.dsc | 6 + 7 files changed, 75 insertions(+), 408 deletions(-) diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c b/UefiCpuPkg/CpuIo2Smm/CpuIo2= Common.c similarity index 94% copy from UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c copy to UefiCpuPkg/CpuIo2Smm/CpuIo2Common.c index b840d3e10cae..fef434795908 100644 --- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Common.c @@ -6,7 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 -#include "CpuIo2Smm.h" +#include "CpuIo2Common.h" =20 // // Handle for the SMM CPU I/O Protocol @@ -371,18 +371,13 @@ CpuIoServiceWrite ( /** The module Entry Point SmmCpuIoProtocol driver =20 - @param[in] ImageHandle The firmware allocated handle for the EFI image. - @param[in] SystemTable A pointer to the EFI System Table. - @retval EFI_SUCCESS The entry point is executed successfully. @retval Other Some error occurs when executing this entry point. =20 **/ EFI_STATUS -EFIAPI -SmmCpuIo2Initialize ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +CommonCpuIo2Initialize ( + VOID ) { EFI_STATUS Status; @@ -390,12 +385,12 @@ SmmCpuIo2Initialize ( // // Copy the SMM CPU I/O Protocol instance into the System Management Sys= tem Table // - CopyMem (&gSmst->SmmIo, &mSmmCpuIo2, sizeof (mSmmCpuIo2)); + CopyMem (&gMmst->MmIo, &mSmmCpuIo2, sizeof (mSmmCpuIo2)); =20 // // Install the SMM CPU I/O Protocol into the SMM protocol database // - Status =3D gSmst->SmmInstallProtocolInterface ( + Status =3D gMmst->MmInstallProtocolInterface ( &mHandle, &gEfiSmmCpuIo2ProtocolGuid, EFI_NATIVE_INTERFACE, diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c b/UefiCpuPkg/CpuIo2Smm/CpuIo2= Smm.c index b840d3e10cae..062d1a47a09f 100644 --- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c @@ -6,367 +6,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 -#include "CpuIo2Smm.h" +#include =20 -// -// Handle for the SMM CPU I/O Protocol -// -EFI_HANDLE mHandle =3D NULL; - -// -// SMM CPU I/O Protocol instance -// -EFI_SMM_CPU_IO2_PROTOCOL mSmmCpuIo2 =3D { - { - CpuMemoryServiceRead, - CpuMemoryServiceWrite - }, - { - CpuIoServiceRead, - CpuIoServiceWrite - } -}; - -// -// Lookup table for increment values based on transfer widths -// -UINT8 mStride[] =3D { - 1, // SMM_IO_UINT8 - 2, // SMM_IO_UINT16 - 4, // SMM_IO_UINT32 - 8 // SMM_IO_UINT64 -}; - -/** - Check parameters to a SMM CPU I/O Protocol service request. - - @param[in] MmioOperation TRUE for an MMIO operation, FALSE for I/O Por= t operation. - @param[in] Width Signifies the width of the I/O operations. - @param[in] Address The base address of the I/O operations. The = caller is - responsible for aligning the Address if requi= red. - @param[in] Count The number of I/O operations to perform. - @param[in] Buffer For read operations, the destination buffer t= o store - the results. For write operations, the sourc= e buffer - from which to write data. - - @retval EFI_SUCCESS The data was read from or written to the = device. - @retval EFI_UNSUPPORTED The Address is not valid for this system. - @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid. - -**/ -EFI_STATUS -CpuIoCheckParameter ( - IN BOOLEAN MmioOperation, - IN EFI_SMM_IO_WIDTH Width, - IN UINT64 Address, - IN UINTN Count, - IN VOID *Buffer - ) -{ - UINT64 MaxCount; - UINT64 Limit; - - // - // Check to see if Buffer is NULL - // - if (Buffer =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - // - // Check to see if Width is in the valid range - // - if ((UINT32)Width > SMM_IO_UINT64) { - return EFI_INVALID_PARAMETER; - } - - // - // Check to see if Width is in the valid range for I/O Port operations - // - if (!MmioOperation && (Width =3D=3D SMM_IO_UINT64)) { - return EFI_INVALID_PARAMETER; - } - - // - // Check to see if any address associated with this transfer exceeds the= maximum - // allowed address. The maximum address implied by the parameters passe= d in is - // Address + Size * Count. If the following condition is met, then the = transfer - // is not supported. - // - // Address + Size * Count > (MmioOperation ? MAX_ADDRESS : MAX_IO_POR= T_ADDRESS) + 1 - // - // Since MAX_ADDRESS can be the maximum integer value supported by the C= PU and Count - // can also be the maximum integer value supported by the CPU, this rang= e - // check must be adjusted to avoid all overflow conditions. - // - // The following form of the range check is equivalent but assumes that - // MAX_ADDRESS and MAX_IO_PORT_ADDRESS are of the form (2^n - 1). - // - Limit =3D (MmioOperation ? MAX_ADDRESS : MAX_IO_PORT_ADDRESS); - if (Count =3D=3D 0) { - if (Address > Limit) { - return EFI_UNSUPPORTED; - } - } else { - MaxCount =3D RShiftU64 (Limit, Width); - if (MaxCount < (Count - 1)) { - return EFI_UNSUPPORTED; - } - if (Address > LShiftU64 (MaxCount - Count + 1, Width)) { - return EFI_UNSUPPORTED; - } - } - - // - // Check to see if Address is aligned - // - if ((Address & ((UINT64)mStride[Width] - 1)) !=3D 0) { - return EFI_UNSUPPORTED; - } - - return EFI_SUCCESS; -} - -/** - Reads memory-mapped registers. - - The I/O operations are carried out exactly as requested. The caller is - responsible for any alignment and I/O width issues that the bus, device, - platform, or type of I/O might require. - - @param[in] This The EFI_SMM_CPU_IO2_PROTOCOL instance. - @param[in] Width Signifies the width of the I/O operations. - @param[in] Address The base address of the I/O operations. The caller= is - responsible for aligning the Address if required. - @param[in] Count The number of I/O operations to perform. - @param[out] Buffer For read operations, the destination buffer to stor= e - the results. For write operations, the source buff= er - from which to write data. - - @retval EFI_SUCCESS The data was read from or written to the = device. - @retval EFI_UNSUPPORTED The Address is not valid for this system. - @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid. - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to= a - lack of resources - -**/ -EFI_STATUS -EFIAPI -CpuMemoryServiceRead ( - IN CONST EFI_SMM_CPU_IO2_PROTOCOL *This, - IN EFI_SMM_IO_WIDTH Width, - IN UINT64 Address, - IN UINTN Count, - OUT VOID *Buffer - ) -{ - EFI_STATUS Status; - UINT8 Stride; - UINT8 *Uint8Buffer; - - Status =3D CpuIoCheckParameter (TRUE, Width, Address, Count, Buffer); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Select loop based on the width of the transfer - // - Stride =3D mStride[Width]; - for (Uint8Buffer =3D Buffer; Count > 0; Address +=3D Stride, Uint8Buffer= +=3D Stride, Count--) { - if (Width =3D=3D SMM_IO_UINT8) { - *Uint8Buffer =3D MmioRead8 ((UINTN)Address); - } else if (Width =3D=3D SMM_IO_UINT16) { - *((UINT16 *)Uint8Buffer) =3D MmioRead16 ((UINTN)Address); - } else if (Width =3D=3D SMM_IO_UINT32) { - *((UINT32 *)Uint8Buffer) =3D MmioRead32 ((UINTN)Address); - } else if (Width =3D=3D SMM_IO_UINT64) { - *((UINT64 *)Uint8Buffer) =3D MmioRead64 ((UINTN)Address); - } - } - return EFI_SUCCESS; -} - -/** - Writes memory-mapped registers. - - The I/O operations are carried out exactly as requested. The caller is - responsible for any alignment and I/O width issues that the bus, device, - platform, or type of I/O might require. - - @param[in] This The EFI_SMM_CPU_IO2_PROTOCOL instance. - @param[in] Width Signifies the width of the I/O operations. - @param[in] Address The base address of the I/O operations. The caller= is - responsible for aligning the Address if required. - @param[in] Count The number of I/O operations to perform. - @param[in] Buffer For read operations, the destination buffer to stor= e - the results. For write operations, the source buff= er - from which to write data. - - @retval EFI_SUCCESS The data was read from or written to the = device. - @retval EFI_UNSUPPORTED The Address is not valid for this system. - @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid. - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to= a - lack of resources - -**/ -EFI_STATUS -EFIAPI -CpuMemoryServiceWrite ( - IN CONST EFI_SMM_CPU_IO2_PROTOCOL *This, - IN EFI_SMM_IO_WIDTH Width, - IN UINT64 Address, - IN UINTN Count, - IN VOID *Buffer - ) -{ - EFI_STATUS Status; - UINT8 Stride; - UINT8 *Uint8Buffer; - - Status =3D CpuIoCheckParameter (TRUE, Width, Address, Count, Buffer); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Select loop based on the width of the transfer - // - Stride =3D mStride[Width]; - for (Uint8Buffer =3D Buffer; Count > 0; Address +=3D Stride, Uint8Buffer= +=3D Stride, Count--) { - if (Width =3D=3D SMM_IO_UINT8) { - MmioWrite8 ((UINTN)Address, *Uint8Buffer); - } else if (Width =3D=3D SMM_IO_UINT16) { - MmioWrite16 ((UINTN)Address, *((UINT16 *)Uint8Buffer)); - } else if (Width =3D=3D SMM_IO_UINT32) { - MmioWrite32 ((UINTN)Address, *((UINT32 *)Uint8Buffer)); - } else if (Width =3D=3D SMM_IO_UINT64) { - MmioWrite64 ((UINTN)Address, *((UINT64 *)Uint8Buffer)); - } - } - return EFI_SUCCESS; -} - -/** - Reads I/O registers. - - The I/O operations are carried out exactly as requested. The caller is - responsible for any alignment and I/O width issues that the bus, device, - platform, or type of I/O might require. - - @param[in] This The EFI_SMM_CPU_IO2_PROTOCOL instance. - @param[in] Width Signifies the width of the I/O operations. - @param[in] Address The base address of the I/O operations. The caller= is - responsible for aligning the Address if required. - @param[in] Count The number of I/O operations to perform. - @param[out] Buffer For read operations, the destination buffer to stor= e - the results. For write operations, the source buff= er - from which to write data. - - @retval EFI_SUCCESS The data was read from or written to the = device. - @retval EFI_UNSUPPORTED The Address is not valid for this system. - @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid. - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to= a - lack of resources - -**/ -EFI_STATUS -EFIAPI -CpuIoServiceRead ( - IN CONST EFI_SMM_CPU_IO2_PROTOCOL *This, - IN EFI_SMM_IO_WIDTH Width, - IN UINT64 Address, - IN UINTN Count, - OUT VOID *Buffer - ) -{ - EFI_STATUS Status; - UINT8 Stride; - UINT8 *Uint8Buffer; - - Status =3D CpuIoCheckParameter (FALSE, Width, Address, Count, Buffer); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Select loop based on the width of the transfer - // - Stride =3D mStride[Width]; - for (Uint8Buffer =3D Buffer; Count > 0; Address +=3D Stride, Uint8Buffer= +=3D Stride, Count--) { - if (Width =3D=3D SMM_IO_UINT8) { - *Uint8Buffer =3D IoRead8 ((UINTN)Address); - } else if (Width =3D=3D SMM_IO_UINT16) { - *((UINT16 *)Uint8Buffer) =3D IoRead16 ((UINTN)Address); - } else if (Width =3D=3D SMM_IO_UINT32) { - *((UINT32 *)Uint8Buffer) =3D IoRead32 ((UINTN)Address); - } - } - - return EFI_SUCCESS; -} - -/** - Write I/O registers. - - The I/O operations are carried out exactly as requested. The caller is - responsible for any alignment and I/O width issues that the bus, device, - platform, or type of I/O might require. - - @param[in] This The EFI_SMM_CPU_IO2_PROTOCOL instance. - @param[in] Width Signifies the width of the I/O operations. - @param[in] Address The base address of the I/O operations. The caller= is - responsible for aligning the Address if required. - @param[in] Count The number of I/O operations to perform. - @param[in] Buffer For read operations, the destination buffer to stor= e - the results. For write operations, the source buff= er - from which to write data. - - @retval EFI_SUCCESS The data was read from or written to the = device. - @retval EFI_UNSUPPORTED The Address is not valid for this system. - @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid. - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to= a - lack of resources - -**/ -EFI_STATUS -EFIAPI -CpuIoServiceWrite ( - IN CONST EFI_SMM_CPU_IO2_PROTOCOL *This, - IN EFI_SMM_IO_WIDTH Width, - IN UINT64 Address, - IN UINTN Count, - IN VOID *Buffer - ) -{ - EFI_STATUS Status; - UINT8 Stride; - UINT8 *Uint8Buffer; - - // - // Make sure the parameters are valid - // - Status =3D CpuIoCheckParameter (FALSE, Width, Address, Count, Buffer); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Select loop based on the width of the transfer - // - Stride =3D mStride[Width]; - for (Uint8Buffer =3D (UINT8 *)Buffer; Count > 0; Address +=3D Stride, Ui= nt8Buffer +=3D Stride, Count--) { - if (Width =3D=3D SMM_IO_UINT8) { - IoWrite8 ((UINTN)Address, *Uint8Buffer); - } else if (Width =3D=3D SMM_IO_UINT16) { - IoWrite16 ((UINTN)Address, *((UINT16 *)Uint8Buffer)); - } else if (Width =3D=3D SMM_IO_UINT32) { - IoWrite32 ((UINTN)Address, *((UINT32 *)Uint8Buffer)); - } - } - - return EFI_SUCCESS; -} +#include "CpuIo2Common.h" =20 /** The module Entry Point SmmCpuIoProtocol driver @@ -380,28 +22,10 @@ CpuIoServiceWrite ( **/ EFI_STATUS EFIAPI -SmmCpuIo2Initialize ( +TraditionalMmCpuIo2Initialize ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { - EFI_STATUS Status; - - // - // Copy the SMM CPU I/O Protocol instance into the System Management Sys= tem Table - // - CopyMem (&gSmst->SmmIo, &mSmmCpuIo2, sizeof (mSmmCpuIo2)); - - // - // Install the SMM CPU I/O Protocol into the SMM protocol database - // - Status =3D gSmst->SmmInstallProtocolInterface ( - &mHandle, - &gEfiSmmCpuIo2ProtocolGuid, - EFI_NATIVE_INTERFACE, - &mSmmCpuIo2 - ); - ASSERT_EFI_ERROR (Status); - - return Status; + return CommonCpuIo2Initialize (); } diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.c b/UefiCpuPkg/CpuIo2S= mm/CpuIo2StandaloneMm.c new file mode 100644 index 000000000000..2978f82eb815 --- /dev/null +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.c @@ -0,0 +1,31 @@ +/** @file + Produces the SMM CPU I/O Protocol. + +Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include "CpuIo2Common.h" + +/** + The module Entry Point SmmCpuIoProtocol driver + + @param[in] ImageHandle The firmware allocated handle for the EFI image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval Other Some error occurs when executing this entry point. + +**/ +EFI_STATUS +EFIAPI +StandaloneMmCpuIo2Initialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_MM_SYSTEM_TABLE *SystemTable + ) +{ + return CommonCpuIo2Initialize (); +} diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h b/UefiCpuPkg/CpuIo2Smm/CpuIo2= Common.h similarity index 92% rename from UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h rename to UefiCpuPkg/CpuIo2Smm/CpuIo2Common.h index 4c133b58c9f4..6759cc1c8777 100644 --- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Common.h @@ -9,14 +9,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #ifndef _CPU_IO2_SMM_H_ #define _CPU_IO2_SMM_H_ =20 -#include +#include =20 #include =20 #include #include #include -#include +#include #include =20 #define MAX_IO_PORT_ADDRESS 0xFFFF @@ -153,4 +153,17 @@ CpuIoServiceWrite ( IN VOID *Buffer ); =20 + +/** + The module Entry Point SmmCpuIoProtocol driver + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval Other Some error occurs when executing this entry point. + +**/ +EFI_STATUS +CommonCpuIo2Initialize ( + VOID + ); + #endif diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf b/UefiCpuPkg/CpuIo2Smm/CpuI= o2Smm.inf index bc78fa4e42d2..031db1d100b9 100644 --- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf @@ -14,7 +14,7 @@ [Defines] MODULE_TYPE =3D DXE_SMM_DRIVER VERSION_STRING =3D 1.0 PI_SPECIFICATION_VERSION =3D 0x0001000A - ENTRY_POINT =3D SmmCpuIo2Initialize + ENTRY_POINT =3D TraditionalMmCpuIo2Initialize =20 # # The following information is for reference only and not required by the = build tools. @@ -24,7 +24,8 @@ [Defines] =20 [Sources] CpuIo2Smm.c - CpuIo2Smm.h + CpuIo2Common.c + CpuIo2Common.h =20 [Packages] MdePkg/MdePkg.dec @@ -34,7 +35,7 @@ [LibraryClasses] BaseLib DebugLib IoLib - SmmServicesTableLib + MmServicesTableLib BaseMemoryLib =20 [Protocols] diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf b/UefiCpuPkg/CpuIo2Smm/CpuI= o2StandaloneMm.inf similarity index 56% copy from UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf copy to UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.inf index bc78fa4e42d2..cce7742bee7a 100644 --- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.inf @@ -8,13 +8,12 @@ =20 [Defines] INF_VERSION =3D 0x00010005 - BASE_NAME =3D CpuIo2Smm - MODULE_UNI_FILE =3D CpuIo2Smm.uni - FILE_GUID =3D A47EE2D8-F60E-42fd-8E58-7BD65EE4C29B - MODULE_TYPE =3D DXE_SMM_DRIVER + BASE_NAME =3D CpuIo2StandaloneMm + FILE_GUID =3D E3121A26-BB1C-4A18-8E23-2EA3F0412248 + MODULE_TYPE =3D MM_STANDALONE VERSION_STRING =3D 1.0 - PI_SPECIFICATION_VERSION =3D 0x0001000A - ENTRY_POINT =3D SmmCpuIo2Initialize + PI_SPECIFICATION_VERSION =3D 0x00010032 + ENTRY_POINT =3D StandaloneMmCpuIo2Initialize =20 # # The following information is for reference only and not required by the = build tools. @@ -23,18 +22,19 @@ [Defines] # =20 [Sources] - CpuIo2Smm.c - CpuIo2Smm.h + CpuIo2StandaloneMm.c + CpuIo2Common.c + CpuIo2Common.h =20 [Packages] MdePkg/MdePkg.dec =20 [LibraryClasses] - UefiDriverEntryPoint + StandaloneMmDriverEntryPoint BaseLib DebugLib IoLib - SmmServicesTableLib + MmServicesTableLib BaseMemoryLib =20 [Protocols] @@ -42,6 +42,3 @@ [Protocols] =20 [Depex] TRUE - -[UserExtensions.TianoCore."ExtraFiles"] - CpuIo2SmmExtra.uni diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index b2b6d78a71b0..4e46c600788f 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -38,6 +38,7 @@ [LibraryClasses] UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/U= efiRuntimeServicesTableLib.inf UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBoo= tServicesTableLib.inf UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntry= Point.inf + StandaloneMmDriverEntryPoint|MdePkg/Library/StandaloneMmDriverEntryPoint= /StandaloneMmDriverEntryPoint.inf DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableL= ib.inf PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf @@ -89,10 +90,14 @@ [LibraryClasses.common.DXE_DRIVER] =20 [LibraryClasses.common.DXE_SMM_DRIVER] SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableL= ib.inf + MmServicesTableLib|MdePkg/Library/MmServicesTableLib/MmServicesTableLib.= inf MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAlloc= ationLib.inf HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuE= xceptionHandlerLib.inf =20 +[LibraryClasses.common.MM_STANDALONE] + MmServicesTableLib|MdePkg/Library/StandaloneMmServicesTableLib/Standalon= eMmServicesTableLib.inf + [LibraryClasses.common.UEFI_APPLICATION] UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiA= pplicationEntryPoint.inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAll= ocationLib.inf @@ -121,6 +126,7 @@ [Components.IA32, Components.X64] NULL|UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.in= f } UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf + UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.inf UefiCpuPkg/CpuMpPei/CpuMpPei.inf UefiCpuPkg/CpuS3DataDxe/CpuS3DataDxe.inf UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf --=20 2.30.0.windows.1