From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web11.4122.1607505859328223336 for ; Wed, 09 Dec 2020 01:24:20 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=PveDH6FO; spf=fail (domain: os.amperecomputing.com, ip: , mailfrom: nhi@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V4Xnma+mCFbZjCUs6woXwau9MjB1X8l18CXQZ1QE2ryR2cgLVqK08ysFi4Hbav1fHZlmf/Kgi703V77Zhp2ECyV7qKaYkQQ734Lxve6XHEFurAkgktZhUsxJKkLEXMTa3zCOXW6vW4NhPlUmOz7W5toTN4XYT1g1zQG1VVBNcyfaYIc5k7EM27d/EfzM9VrMq3q5p23ML46TMShaTRFfgZi3/2YCXXizXH6ANnLSBg6riKhcdMAsda0i5Cird1d2THMLNzrdmXQgHuL9GxJpGtti2v8mROl4M0eVyQFUyVY2rR5WW+eDshR86qs5c/3LopdY6TTmx1wDYKQAFyCdoA== 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=JXv82SMs7xZ+OD0ZVrZnv8QVxYikDRBRwB1bvnZR4qk=; b=R0ukbNPslCURzQJNkZXbSL0eHKnxsxCrv4qfLWcl0oHFG74ei2S9dr6Q0doDyae/xpGx/gK4XgL73e4knfANeG/FCdHXqN4aWl9A9zJtu8HEmopEV2Lt+RtYzKFdcqGS6cFlyiiD2t9pxNHwR28uRG/mPkTV87DuR9GjaLqqNQqx7p5ZsTEHwMJRtEmdOVhnoCIcomdif/vmvZ/O1Bxe28mEM1koxhgMjMRz+u/k5sOD2+qJbr2j3fF1vaAo6dvWD9Fpr59LxRApPuBcsqDB1LXoMmz4rc5GpooK7DR+473ZPYDavob6ZMH+HuZOHETy6173KBxUwooX2gP8F7+A9A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JXv82SMs7xZ+OD0ZVrZnv8QVxYikDRBRwB1bvnZR4qk=; b=PveDH6FOkndMnHWVf2vQqK7c3zDsYsUDoI7DZAfFQ8sKAl0lId1hfO7g9pu004Klxc+/vSUz0Ge9jJ/+RVaykyHF/wfoMZQce+fQRgJIXoQ3JvUYOyvVtvd+YmOd5KfuPvL4yhtEdAo52xZsKNb8eyc3wM/DCa+o9BWrEvPlc5Q= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=os.amperecomputing.com; Received: from DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) by DM6PR01MB5609.prod.exchangelabs.com (2603:10b6:5:157::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.21; Wed, 9 Dec 2020 09:24:19 +0000 Received: from DM6PR01MB5849.prod.exchangelabs.com ([fe80::c814:9a08:5c2e:4076]) by DM6PR01MB5849.prod.exchangelabs.com ([fe80::c814:9a08:5c2e:4076%5]) with mapi id 15.20.3632.023; Wed, 9 Dec 2020 09:24:19 +0000 From: "Nhi Pham" To: devel@edk2.groups.io Cc: Nhi Pham Subject: [edk2-platforms][PATCH 06/34] Platform/Ampere: Add AcpiPccLib to support ACPI PCCT Table Date: Wed, 9 Dec 2020 16:25:03 +0700 Message-Id: <20201209092531.30867-7-nhi@os.amperecomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201209092531.30867-1-nhi@os.amperecomputing.com> References: <20201209092531.30867-1-nhi@os.amperecomputing.com> X-Originating-IP: [118.69.219.201] X-ClientProxiedBy: HK0PR01CA0054.apcprd01.prod.exchangelabs.com (2603:1096:203:a6::18) To DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) Return-Path: nhi@os.amperecomputing.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sw004.amperecomputing.com (118.69.219.201) by HK0PR01CA0054.apcprd01.prod.exchangelabs.com (2603:1096:203:a6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.12 via Frontend Transport; Wed, 9 Dec 2020 09:24:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 40e55716-4164-4466-5e46-08d89c2434dd X-MS-TrafficTypeDiagnostic: DM6PR01MB5609: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3TIW+sfNWpDDsYiV7q8RJHOJoQECKyyttnJt9RmwAIZkNvynk9gWibGfmf0p0B8Q9+rqpnw+XZ//3vWFldZdEQPabMYfI1mh6Dym2ii72XJMuCrf0aiKMzRHU6ePm8taL8fVWZSbSoQczYY79qqMpgMDqq7WnyBuyEC0yrBAYhIvtg+54OTLeGja2o4icqTV0XRm+sJa9QJ/Hhryh45ug3DDlpZQlN/RydOyKGBDPxE+8z8NEgjv1Nphj9KQ+fsdAUMJU3wO8uAw71pWMYk8ugN4TYx6TZUuF/7ot+mW3A8/5IVwcZXEPhTfEh55b3pWerCFRm5qtKSnXod6+yhlq6yL2WJ2SXHqwjRgJbLf4gWrXupuyFmLdfIhQ/1Np10j X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR01MB5849.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(136003)(346002)(366004)(5660300002)(956004)(508600001)(52116002)(30864003)(66946007)(6916009)(2616005)(1076003)(19627235002)(86362001)(6512007)(66476007)(26005)(8936002)(16526019)(107886003)(6666004)(186003)(6486002)(8676002)(6506007)(83380400001)(2906002)(34490700003)(66556008)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?TTkM+DnbauSNtwnrqC7dedZHKl9bwUoWmJaHgz6sYE3I+6/SaTAOBCPWRQ0U?= =?us-ascii?Q?nYGnCXQEZcXZ2ghh7vQM+FLu3q6AeV+ad/MJrH8APRF5riyiWiZNz3qV814w?= =?us-ascii?Q?XjlaGAMVlKXNASFsJlEi9OIBZOU1GSYzgvSL8HdTrpyTTQv7ZQjfmhOZNlyf?= =?us-ascii?Q?PE5GxKKTb0nC0AxzXQhrCsqTyq947VCHbyMB0hke6HsBUKACQjf0s5l/yIj1?= =?us-ascii?Q?1LUyLNW0oz8t7VTLmV7tLr6/sWYGRWZYQG8oU0u7fgKXHVBoIQYpYCDlrHTe?= =?us-ascii?Q?SENZEgO+vE750gyqOZzeTAI+QFjLg0NT/ZKeekCIJNDMw2sdlkEppuZN4fNM?= =?us-ascii?Q?R6a8iciH3MB8y/zFZ4hT0awabzMDH2zzrD/j7bZ5ONrx9TUMkjne5vobg9ds?= =?us-ascii?Q?sojfZtvPKEZrPFdhwalqpaU4d2df1EXoxSlam9DJTNHuB6aR4gBtWH08ldCb?= =?us-ascii?Q?EAr+cpJlHyrrTGpW3MHxnJ8DZZj9gxUrsaJhOhsg+IgocAzSoIo5R/UD5HRf?= =?us-ascii?Q?P6CuH+HBEwkrVE7cgl7a7jnz66Xp1y5HkEo3w4d74hGHQwgfPWIxM6tOIOak?= =?us-ascii?Q?KhIo55ZdvQ2LZTYTZpvQi0ddrlR7aI3T9b7it1t/HD7l7zoUwVNk+RVAw9cR?= =?us-ascii?Q?hED98UAa/hC5aZQDSpmmyWa/YiD+EkYhF/ZRFTxx29RXbI5x6k8vi1j//1/+?= =?us-ascii?Q?145TVdRqtP7IVEI3fig1gpGZH9sz6BsxaqCdcrTnasXtINGX35cV3t0Hx7FI?= =?us-ascii?Q?eO2lIZRLDxPzfKlyVnOpJ995wQijpl+lmouFxuXzi8VoDjPf/2dYwSSufzls?= =?us-ascii?Q?yzlVaEoLpV9TorCfxhwNSSzNMWrWjC0ouKQvHQC2ONxrQgcOMGHmbUgNYjNh?= =?us-ascii?Q?eohj5f4svXQpHQehb98YbVQ3rny80yLOr9EJdGb42OCdy03r+Y3mciU9BOya?= =?us-ascii?Q?wreWwYkQbfZtR4GHdoJQcw4ZjVyP45eUFN0KW+pyAs5YR+TZwK4IWEU3EfTA?= =?us-ascii?Q?LYxk?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-AuthSource: DM6PR01MB5849.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2020 09:24:19.2143 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-Network-Message-Id: 40e55716-4164-4466-5e46-08d89c2434dd X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fMsQoQQcEBLePsE3xNWhKCLs+cONeZZ3NDhl+PIZhZ0Gcm3vJQSeCdmVfPZ4pFKVrP1EhjEk9XSCr/ahSSueqeKB56LUaOjuBzsc6XVXng8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB5609 Content-Type: text/plain The AcpiPccLib provides functions to allocate and get the physical address of PCC shared memory. Signed-off-by: Nhi Pham --- Silicon/Ampere/AmperePkg.dec | 4 + Platform/Ampere/Library/AcpiPccLib/AcpiPccLib.inf | 45 +++ Silicon/Ampere/Include/Library/AcpiPccLib.h | 91 ++++++ Platform/Ampere/Library/AcpiPccLib/AcpiPccLib.c | 322 ++++++++++++++++++++ 4 files changed, 462 insertions(+) diff --git a/Silicon/Ampere/AmperePkg.dec b/Silicon/Ampere/AmperePkg.dec index 47b29f508185..fa5b7074f749 100755 --- a/Silicon/Ampere/AmperePkg.dec +++ b/Silicon/Ampere/AmperePkg.dec @@ -22,8 +22,12 @@ [Defines] # ################################################################################ [Includes.common] + Include # Root include for the package [LibraryClasses] + ## @libraryclass Provides functions to create the ACPI PCCT Table which which advertises PCC mailbox channel information. + AcpiPccLib|Silicon/Ampere/Include/Library/AcpiPccLib.h + [Guids] gAmpereTokenSpaceGuid = { 0xdbd4436e, 0x89cb, 0x44dc, { 0xb5, 0xc0, 0x49, 0xc3, 0x91, 0x35, 0xbf, 0xdf } } diff --git a/Platform/Ampere/Library/AcpiPccLib/AcpiPccLib.inf b/Platform/Ampere/Library/AcpiPccLib/AcpiPccLib.inf new file mode 100755 index 000000000000..d4b48e0fa248 --- /dev/null +++ b/Platform/Ampere/Library/AcpiPccLib/AcpiPccLib.inf @@ -0,0 +1,45 @@ +## @file +# +# Copyright (c) 2020, Ampere Computing LLC. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = AcpiPccLib + FILE_GUID = 790519F0-F344-11E3-AC10-0800200C9A66 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = AcpiPccLib + +[Sources.common] + AcpiPccLib.c + +[FeaturePcd] + +[Pcd] + +[FixedPcd] + +[Packages] + ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + Silicon/Ampere/AmperePkg.dec + Silicon/Ampere/AmpereAltraPkg/Ac01Pkg.dec + +[LibraryClasses] + ArmLib + BaseLib + DebugLib + IoLib + PrintLib + TimerLib + BaseMemoryLib + UefiBootServicesTableLib + +[Pcd] + gAmpereTokenSpaceGuid.PcdPmproDbBaseReg + gAmpereTokenSpaceGuid.PcdSmproDbBaseReg diff --git a/Silicon/Ampere/Include/Library/AcpiPccLib.h b/Silicon/Ampere/Include/Library/AcpiPccLib.h new file mode 100755 index 000000000000..7ec761adaec1 --- /dev/null +++ b/Silicon/Ampere/Include/Library/AcpiPccLib.h @@ -0,0 +1,91 @@ +/** @file + + Copyright (c) 2020, Ampere Computing LLC. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _ACPI_PCC_LIB_H_ +#define _ACPI_PCC_LIB_H_ + +struct ACPI_PCCT_SHARED_MEMORY { + UINT32 Signature; + union { + UINT16 Command; + struct PCC_COMMAND { + UINT16 CommandCode:8; + UINT16 Reserved:7; + UINT16 Interrupt:1; + } __attribute__ ((packed)) CmdT; + } CmdData; + union { + UINT16 Status; + struct PCC_STATUS { + UINT16 CommandComplete:1; + UINT16 SciDb:1; + UINT16 Error:1; + UINT16 PlatformNotification:1; + UINT16 Reserved:12; + } __attribute__ ((packed)) StatusT; + } StatusData; +} __attribute__((packed)); + +EFI_STATUS +EFIAPI +AcpiPccSendMsg ( + IN UINT32 Socket, + IN UINT32 Subspace, + IN VOID *MsgBuf, + IN UINT32 Length + ); + +EFI_STATUS +EFIAPI +AcpiPccUnmaskInt ( + IN UINT32 Socket, + IN UINT32 Subspace + ); + +EFI_STATUS +EFIAPI +AcpiPccSyncSharedMemAddr ( + IN UINT32 Socket, + IN UINT32 Subspace + ); + +EFI_STATUS +EFIAPI +AcpiPccSharedMemInit ( + IN UINT32 Socket, + IN UINT32 Subspace + ); + +EFI_STATUS +EFIAPI +AcpiPccSharedMemInitV2 ( + IN UINT32 Socket, + IN UINT32 Subspace + ); + +EFI_STATUS +EFIAPI +AcpiIppPccIsSupported ( + VOID + ); + +EFI_STATUS +EFIAPI +AcpiPccAllocSharedMemory ( + OUT UINT64 *PccSharedMemPointer, + IN UINT32 SubspaceNum + ); + +VOID +EFIAPI +AcpiPccFreeSharedMemory ( + OUT UINT64 *PccSharedMemPointer, + IN UINT32 SubspaceNum + ); + +#endif /* _ACPI_PCC_LIB_H_*/ diff --git a/Platform/Ampere/Library/AcpiPccLib/AcpiPccLib.c b/Platform/Ampere/Library/AcpiPccLib/AcpiPccLib.c new file mode 100755 index 000000000000..94e55ce34505 --- /dev/null +++ b/Platform/Ampere/Library/AcpiPccLib/AcpiPccLib.c @@ -0,0 +1,322 @@ +/** @file + + Copyright (c) 2020, Ampere Computing LLC. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PCC_NULL_MSG 0x0F000000 + +STATIC UINT64 PccSharedMemAddr = 0; + +STATIC EFI_STATUS +AcpiPccGetSharedMemAddr ( + IN UINT32 Socket, + IN UINT32 Subspace, + OUT VOID **AcpiPcct + ) +{ + if ((Subspace >= PCC_MAX_SUBSPACES_PER_SOCKET) + || (Socket >= PLATFORM_CPU_MAX_SOCKET)) { + return EFI_INVALID_PARAMETER; + } + + if (PccSharedMemAddr == 0) { + return EFI_NOT_READY; + } + + *AcpiPcct = (VOID *) (PccSharedMemAddr + PCC_SUBSPACE_SHARED_MEM_SIZE * + (Subspace + PCC_MAX_SUBSPACES_PER_SOCKET * Socket)); + + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +AcpiPccSendMsg ( + IN UINT32 Socket, + IN UINT32 Subspace, + IN VOID *MsgBuf, + IN UINT32 Length + ) +{ + INTN TimeoutCnt = PCC_NOMINAL_LATENCY / PCC_CMD_POLL_UDELAY; + VOID *CommunicationSpacePtr; + struct ACPI_PCCT_SHARED_MEMORY *AcpiPcct; + EFI_STATUS Status; + UINT32 PccMsg; + + if ((Subspace >= PCC_MAX_SUBSPACES_PER_SOCKET) + || (Socket >= PLATFORM_CPU_MAX_SOCKET)) { + return EFI_INVALID_PARAMETER; + } + + Status = AcpiPccGetSharedMemAddr (Socket, Subspace, (VOID **) &AcpiPcct); + if (EFI_ERROR (Status)) { + return Status; + } + + CommunicationSpacePtr = AcpiPcct + 1; + + /* Write Data into Communication Space Region */ + CopyMem (CommunicationSpacePtr, MsgBuf, Length); + /* Flip CMD_COMPLETE bit */ + AcpiPcct->StatusData.StatusT.CommandComplete = 0; + /* PCC signature */ + AcpiPcct->Signature = PCC_SIGNATURE_MASK | Subspace; + /* Ring the Doorbell */ + PccMsg = PCC_MSG; + /* Store the upper address (Bit 40-43) of PCC shared memory */ + PccMsg |= ((UINT64) AcpiPcct >> 40) & PCP_MSG_UPPER_ADDR_MASK; + if (Subspace < PMPRO_MAX_DB) { + MmioWrite32 (PMPRO_DBx_REG (Socket, Subspace, DB_OUT), PccMsg); + } else { + MmioWrite32 (SMPRO_DBx_REG (Socket, Subspace - PMPRO_MAX_DB, DB_OUT), + PccMsg); + } + + /* Polling CMD_COMPLETE bit */ + while (AcpiPcct->StatusData.StatusT.CommandComplete != 1) { + if (--TimeoutCnt <= 0) { + return EFI_TIMEOUT; + } + MicroSecondDelay (PCC_CMD_POLL_UDELAY); + }; + + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +AcpiPccUnmaskInt ( + IN UINT32 Socket, + IN UINT32 Subspace + ) +{ + if ((Subspace >= PCC_MAX_SUBSPACES_PER_SOCKET) + || (Socket >= PLATFORM_CPU_MAX_SOCKET)) { + return EFI_INVALID_PARAMETER; + } + + /* Unmask Interrupt */ + if (Subspace < PMPRO_MAX_DB) { + MmioWrite32 ( + PMPRO_DBx_REG (Socket, Subspace, DB_STATUSMASK), + ~DB_AVAIL_MASK + ); + } else { + MmioWrite32 ( + SMPRO_DBx_REG (Socket, Subspace - PMPRO_MAX_DB, DB_STATUSMASK), + ~DB_AVAIL_MASK + ); + } + + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +AcpiPccSyncSharedMemAddr ( + IN UINT32 Socket, + IN UINT32 Subspace + ) +{ + UINT32 PccData; + + if ((Subspace >= PCC_MAX_SUBSPACES_PER_SOCKET) + || (Socket >= PLATFORM_CPU_MAX_SOCKET)) { + return EFI_INVALID_PARAMETER; + } + + /* + * Advertise shared memory address to Platform (SMPro/PMPro) + * by ring the doorbell with dummy PCC message + */ + PccData = PCC_NULL_MSG; + + return AcpiPccSendMsg (Socket, Subspace, &PccData, 4); +} + +EFI_STATUS +EFIAPI +AcpiPccSharedMemInit ( + IN UINT32 Socket, + IN UINT32 Subspace + ) +{ + struct ACPI_PCCT_SHARED_MEMORY *AcpiPcct; + EFI_STATUS Status; + + if ((Subspace >= PCC_MAX_SUBSPACES_PER_SOCKET) + || (Socket >= PLATFORM_CPU_MAX_SOCKET)) { + return EFI_INVALID_PARAMETER; + } + + Status = AcpiPccGetSharedMemAddr (Socket, Subspace, (VOID **) &AcpiPcct); + if (EFI_ERROR (Status)) { + return Status; + } + + /* Set Shared Memory address into DB OUT register */ + if (Subspace < PMPRO_MAX_DB) { + MmioWrite32 ( + PMPRO_DBx_REG (Socket, Subspace, DB_OUT0), + (UINT32) ((UINT64) AcpiPcct >> 8) + ); + } else { + MmioWrite32 ( + SMPRO_DBx_REG(Socket, Subspace - PMPRO_MAX_DB, DB_OUT0), + (UINT32) ((UINT64) AcpiPcct >> 8) + ); + } + + /* Init shared memory for each PCC subspaces */ + SetMem ( + (VOID *) AcpiPcct, + sizeof (struct ACPI_PCCT_SHARED_MEMORY) + PCC_MSG_SIZE, + 0x0 + ); + AcpiPcct->StatusData.StatusT.CommandComplete = 1; + + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +AcpiPccSharedMemInitV2 ( + IN UINT32 Socket, + IN UINT32 Subspace + ) +{ + struct ACPI_PCCT_SHARED_MEMORY *AcpiPcct; + EFI_STATUS Status; + UINT32 AlignBit; + + if ((Subspace >= PCC_MAX_SUBSPACES_PER_SOCKET) + || (Socket >= PLATFORM_CPU_MAX_SOCKET)) { + return EFI_INVALID_PARAMETER; + } + + Status = AcpiPccGetSharedMemAddr (Socket, Subspace, (VOID **) &AcpiPcct); + if (EFI_ERROR (Status)) { + return Status; + } + + if ((PCC_MSG & PCC_256_ALIGN_ADDR) != 0) { + AlignBit = 8; + } + + /* Set Shared Memory address into DB OUT register */ + if (Subspace < PMPRO_MAX_DB) { + MmioWrite32 ( + PMPRO_DBx_REG (Socket, Subspace, DB_OUT0), + (UINT32) ((UINT64) AcpiPcct >> AlignBit) + ); + + MmioWrite32 ( + (PMPRO_DBx_REG (Socket, Subspace, DB_OUT1)), + (UINT32) ((UINT64) AcpiPcct >> (32 + AlignBit)) + ); + } else { + MmioWrite32 ( + SMPRO_DBx_REG (Socket, Subspace - PMPRO_MAX_DB, DB_OUT0), + (UINT32) ((UINT64) AcpiPcct >> AlignBit) + ); + + MmioWrite32 ( + SMPRO_DBx_REG (Socket, Subspace - PMPRO_MAX_DB, DB_OUT1), + (UINT32) ((UINT64) AcpiPcct >> (32 + AlignBit)) + ); + } + + /* Init shared memory for each PCC subspaces */ + SetMem ( + (VOID *) AcpiPcct, + sizeof (struct ACPI_PCCT_SHARED_MEMORY) + PCC_MSG_SIZE, + 0x0 + ); + AcpiPcct->StatusData.StatusT.CommandComplete = 1; + + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +AcpiIppPccIsSupported ( + VOID + ) +{ + EFI_STATUS Status; + + /* Send a PCC NULL command to check if IPP supports PCC request */ + AcpiPccSharedMemInit (0, 0); + + Status = AcpiPccSyncSharedMemAddr (0, 0); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +AcpiPccAllocSharedMemory ( + OUT UINT64 *PccSharedMemPointer, + IN UINT32 SubspaceNum + ) +{ + EFI_STATUS Status; + + if (SubspaceNum > PCC_MAX_SUBSPACES) { + return EFI_INVALID_PARAMETER; + } + + Status = gBS->AllocatePages ( + AllocateAnyPages, + EfiRuntimeServicesData, + EFI_SIZE_TO_PAGES (PCC_SUBSPACE_SHARED_MEM_SIZE * SubspaceNum), + &PccSharedMemAddr + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to allocate PCC shared memory\n")); + return Status; + } + + *PccSharedMemPointer = PccSharedMemAddr; + + return EFI_SUCCESS; +} + +VOID +EFIAPI +AcpiPccFreeSharedMemory ( + OUT UINT64 *PccSharedMemPointer, + IN UINT32 SubspaceNum + ) +{ + if (SubspaceNum > PCC_MAX_SUBSPACES) { + return; + } + + gBS->FreePages ( + *PccSharedMemPointer, + EFI_SIZE_TO_PAGES (PCC_SUBSPACE_SHARED_MEM_SIZE * SubspaceNum) + ); + + PccSharedMemAddr = 0; +} -- 2.17.1