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 [40.107.220.121]) by mx.groups.io with SMTP id smtpd.web09.5410.1622023905760514680 for ; Wed, 26 May 2021 03:11:45 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@os.amperecomputing.com header.s=selector2 header.b=nN4SsTiz; spf=pass (domain: os.amperecomputing.com, ip: 40.107.220.121, mailfrom: nhi@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DCd5ArOFTtiLppk4S7SgJ2frdu4TBL6qcrTzwiHOm4qQXV4kwwy2GfHASUlUcB0itmHBGJYgCNWIqVc0LRVSQUbDUNRd49Daqr05rCaaD/nq5jQEr4uPU1gxoYWRJQxnVXGI/A9cMYGEiNmkn24AJRX2dRtBdZg86TLR/P362kUMVfvSKzoKLLzG9YhItruCtAbD4uZnps1ifbPNtr/VBxXfeMUWznHlpxZhN3PbeJHzPcu/dF9OPvn77mKNoTlXHCAR+Lc0Df2ATZI3AMRVtf4Vj/H7ll9xD0GR2SJSnOaBYxUK3KZvS3S6MhVJH58l8iJC5pnWroPK980mPe8wFQ== 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=/1L2fLFqkw2p5/4PYTu6F4LWmSD9p8pg8CHZeeqqTPA=; b=kML8gZ0WeCsxKkdPEmWl+qObZX50fIqeMo5nkaL5naqM0fH/3Jrs62b4NYdbeiaqRwxdA3DCncUpYTEQT9E6lHsdw+7tFrzmFCs8Us4vtyRMN6dZ8LfhzDzXafGPjM1Akue5J5TNQD9Xl815qUQZX3/36u+BHdVj+sfJLt/PAQzH7jRv+D/H2amnBtfBOawMVcyTUNyn5kSYRrk8A3FaienWA/MFMITWDReHTgzsiAyo8HGvBwFMH7Q68vm/xUCUKobWGW470UNp5djzEW1NTxcPFiBKGGkWp7iCTpwenmMLAo4fPjSdb5TQoCNmZt49T+OE8rEC0yIwmRW2fRM+jA== 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=/1L2fLFqkw2p5/4PYTu6F4LWmSD9p8pg8CHZeeqqTPA=; b=nN4SsTizQBQyj3XiLnkFh5BVz8Dpd7ZzFFREcJ12UDzSRiVmR+FzfZDpcs2HtWQXgaT1i9rYHgTnIPZASGQmtJ1Yk71Q+JgQBRVGSmwqrVEUQV/UwPkfNcSaYkf727KHM7L/gQjZli3ELmP6CVYCsSUiKjgLhJSslmY6eItzP5c= 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 DM5PR0101MB3067.prod.exchangelabs.com (2603:10b6:4:31::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.28; Wed, 26 May 2021 10:11:44 +0000 Received: from DM6PR01MB5849.prod.exchangelabs.com ([fe80::60d2:86dd:1f1c:51dd]) by DM6PR01MB5849.prod.exchangelabs.com ([fe80::60d2:86dd:1f1c:51dd%7]) with mapi id 15.20.4173.020; Wed, 26 May 2021 10:11:44 +0000 From: "Nhi Pham" To: devel@edk2.groups.io CC: Nhi Pham , Thang Nguyen , Chuong Tran , Phong Vo , Leif Lindholm , Michael D Kinney , Ard Biesheuvel , Nate DeSimone Subject: [edk2-platforms][PATCH v2 11/32] AmperePlatformPkg: Add AcpiPccLib to support ACPI PCCT Table Date: Wed, 26 May 2021 17:07:03 +0700 Message-ID: <20210526100724.5359-13-nhi@os.amperecomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210526100724.5359-1-nhi@os.amperecomputing.com> References: <20210526100724.5359-1-nhi@os.amperecomputing.com> X-Originating-IP: [118.69.219.201] X-ClientProxiedBy: HKAPR04CA0008.apcprd04.prod.outlook.com (2603:1096:203:d0::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 localhost.localdomain (118.69.219.201) by HKAPR04CA0008.apcprd04.prod.outlook.com (2603:1096:203:d0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20 via Frontend Transport; Wed, 26 May 2021 10:11:41 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b992817c-4252-474c-3054-08d9202ea9f7 X-MS-TrafficTypeDiagnostic: DM5PR0101MB3067: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: H51FBf06HyzHpd+H35ThwwrcW+0kx5231RielCTS8L8CkdTmzjyscepPurC84jkQwypqyMZaUNzYDyT07BiS/eWF7YqcviMZU9wU9tcx9PxaTgtQPTy5BUlGCOVJHgpKVdeJ9dJuYH8HIxNTPA5icVFHvJ1DegdqxAgK4XvumJvJSOyckzOU7d0mjXqANoGSegkCoQI8MjWFKTv3K7U6g/9h280G8zLP/MRdElkoN46Aln0MUHd7l4yFlOvkAHXch5e0IJmA25PPGm4WecGKn46sdNuUj/BL8/0ApgzIioeyMbBci1DSraRtvNg+PP6lBI1/2Q6CEDjyPuikSdV255NTkGL1HvQC5KJP+DaU0RZdl0PuKlBSDvWDHUVNY/S2k/35wXwzXZfnxzwkTg4xGMq5NgRJl16md5WREe+0I/pXmcPF677QCkwj2IwLhxqYXQzZIMp7Sejloi79SkarTIEuWr12UO1Y3VQ7IJhvyiA3fqlXwZuA7HMPqziMIRxioN9Xw8w9+FcfGH6JjrzZqrhURQ4wH6foRzJDPjM4+4c1YEprITODLx9Z8naMXmjI7xmO52g37wgbpvZETEDvz5SobC6r7dg8phGlVRSDiw9DVDcgJU2t+tFaWsznf1CZ3F2e6ghgIqzToWhfZHwk0ThJBb6x4JZlFNPrSmJkaYtA6yYUKlRtB67VGPT66Im8 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)(39850400004)(396003)(346002)(136003)(376002)(366004)(4326008)(26005)(6666004)(1076003)(2616005)(38350700002)(6506007)(83380400001)(86362001)(2906002)(6486002)(8676002)(30864003)(956004)(52116002)(8936002)(186003)(54906003)(66556008)(6916009)(66476007)(6512007)(66946007)(38100700002)(5660300002)(16526019)(478600001)(316002)(69590400013);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?nJxINq9slG4u+Wt9q2F+Uqn+1cmzvjJmFDFvVY0MGFd77ngOaxd7v5wk4wmX?= =?us-ascii?Q?gYJ8TrM53qLSFia1PHAQ71ezmxl5T6Ijrh8nBhDIHB4LtXwB5PZ9ip4t5yPE?= =?us-ascii?Q?31U7J5e7syOTwQkXwN/7nMlgkX2Pbd4eTsUVuqam9grZ3qawYo+8akS3KDcL?= =?us-ascii?Q?7K117KIk262yDb1P4yKfjxRARaqccb+ESrdushjbw+wUAa/weKXziWJ2YG2Z?= =?us-ascii?Q?wDrwNqtVeWxiZS7LRaiHaJYH+8Y4hZkkNo+LT+U/47C92CEuqpxJKEk2i5Sx?= =?us-ascii?Q?dWAKZaaOu/RNTvHsrZiLQHlgAbq60h0jFSKjS0nm2BuzWKFITfcsVPybJiQf?= =?us-ascii?Q?M895Fyp+TpRVV1CnP3G2/9pFrf7QsGxbUa7jylviS5bSC8PblR403MU3s8/e?= =?us-ascii?Q?g6R7UuqlfjYIcH6YHyqWQHn2HiwCtabd3LnP4dwAZWA8kMnpEv90jJzAU38+?= =?us-ascii?Q?RREeTAPSYcKStyx3o6QqvRL0Ycqv0yDz4N1nPy6yLhjpo76KpLhrkFoRKVst?= =?us-ascii?Q?tYmNvqi23b771u6LP5BU0+2bGydS5A279qIvRuymaNV30Za3a5tGq047vVgD?= =?us-ascii?Q?7tx93RhcX9/sYwv2unHxzTrhIe2sUtUNpb3WWfllOOkv1b7Z1PMOiV/D7WLo?= =?us-ascii?Q?BJU8KZZXF2UT/KxBQ6Rwt25kQFhdqz0BM7xfb0Xm1iRfP8sr5D/OFeU4sfmu?= =?us-ascii?Q?gzfkHyugUhEXAICpd6iH+yC5E2jhvx9wjyO6Dl2q+QUPmPqgkDKrIbsiTNEZ?= =?us-ascii?Q?W7kvrvmZ47C3rqmpyNdB8tABLcwqjWQB6I+b/+Y+YlwyX4s9tAjPdJ7Mmp3D?= =?us-ascii?Q?q+eGVzKOKWHdGGVuTkAr+iLgO5PF2Z5zSApK7eTrch9PtLcOiKCdZr5peBmP?= =?us-ascii?Q?xVyO9rTukcTzcqVnwt9/Usn7vuRGnLHoNf4dYiIgr95hPoCUy5m0wl1jim4K?= =?us-ascii?Q?x6ZTnixAVULJGJd/5drIk3gkwZeVsmw9wz9xh3bGSxtA6iP4oH7xvceZ7KYE?= =?us-ascii?Q?Y6Zg6Z2/kVM6gz27MZGwO2vMl3DkLSRHpjT+c7RypFjsQiIPsAD6XV5Ymuk8?= =?us-ascii?Q?kTCTk8vgvHRWYl+AGpSdS6vIzTYLSQyo2NIGuTaUQI6CNsXBUpJWn7lT6h0G?= =?us-ascii?Q?wm0R4czoUzjSVeiLpNiZiskyzX2DDjhW6nMgT5efLh3holfVCGndYXaXFdNn?= =?us-ascii?Q?K+tk4Psel3J1HZskCMEHgs8wM8phMl3eW4cKg1k1Z4hU4BfWnn8uisv380YB?= =?us-ascii?Q?vWROah2dRZpYuqYbZKZiQNjtG53BfrtWjGr3mhQpyW3+9UA98r5iPu9XmSG2?= =?us-ascii?Q?vrDqQsXanNGlMgkV/jICztCF?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: b992817c-4252-474c-3054-08d9202ea9f7 X-MS-Exchange-CrossTenant-AuthSource: DM6PR01MB5849.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 May 2021 10:11:44.3538 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: m0fUDBomqXqWxoJwwZ00sDHDbmOZajqlMvONGiQ8/fpTxkWuS48SxffA7qrrPIsF/Fur22ff4wXKvRKzDj6bO+9X10q3iQL1ewdNqrR19jY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR0101MB3067 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain The AcpiPccLib provides functions to allocate and get the physical address of PCC shared memory. Cc: Thang Nguyen Cc: Chuong Tran Cc: Phong Vo Cc: Leif Lindholm Cc: Michael D Kinney Cc: Ard Biesheuvel Cc: Nate DeSimone Signed-off-by: Nhi Pham --- Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec | 2 = + Platform/Ampere/AmperePlatformPkg/Library/AcpiPccLib/AcpiPccLib.inf | 41 = ++++ Silicon/Ampere/AmpereSiliconPkg/Include/Library/AcpiPccLib.h | 166 = ++++++++++++++ Platform/Ampere/AmperePlatformPkg/Library/AcpiPccLib/AcpiPccLib.c | 241 = ++++++++++++++++++++ 4 files changed, 450 insertions(+) diff --git a/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec b/Silicon= /Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec index a72205aa5316..8193ff617600 100755 --- a/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec +++ b/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec @@ -25,6 +25,8 @@ [Includes.common] Include # Root include for the package =20 [LibraryClasses] + ## @libraryclass Provides functions to create the ACPI PCCT Table whic= h which advertises PCC mailbox channel information. + AcpiPccLib|Silicon/Ampere/AmpereSiliconPkg/Include/Library/AcpiPccLib.h =20 [Guids] gAmpereTokenSpaceGuid =3D { 0xdbd4436e, 0x89cb, 0x44dc, { 0xb5, 0xc0, 0x= 49, 0xc3, 0x91, 0x35, 0xbf, 0xdf } } diff --git a/Platform/Ampere/AmperePlatformPkg/Library/AcpiPccLib/AcpiPccLi= b.inf b/Platform/Ampere/AmperePlatformPkg/Library/AcpiPccLib/AcpiPccLib.inf new file mode 100755 index 000000000000..9f38e1e77145 --- /dev/null +++ b/Platform/Ampere/AmperePlatformPkg/Library/AcpiPccLib/AcpiPccLib.inf @@ -0,0 +1,41 @@ +## @file +# +# Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D AcpiPccLib + FILE_GUID =3D 790519F0-F344-11E3-AC10-0800200C9A66 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D AcpiPccLib + +[Sources.common] + AcpiPccLib.c + +[Packages] + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + MdePkg/MdePkg.dec + Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec + Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec + +[LibraryClasses] + ArmLib + BaseLib + BaseMemoryLib + DebugLib + IoLib + MailboxInterfaceLib + PrintLib + SystemFirmwareInterfaceLib + TimerLib + UefiBootServicesTableLib + +[Pcd] + gAmpereTokenSpaceGuid.PcdPmproDbBaseReg + gAmpereTokenSpaceGuid.PcdSmproDbBaseReg diff --git a/Silicon/Ampere/AmpereSiliconPkg/Include/Library/AcpiPccLib.h b= /Silicon/Ampere/AmpereSiliconPkg/Include/Library/AcpiPccLib.h new file mode 100644 index 000000000000..d8ae48e7612a --- /dev/null +++ b/Silicon/Ampere/AmpereSiliconPkg/Include/Library/AcpiPccLib.h @@ -0,0 +1,166 @@ +/** @file + + Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef ACPI_PCC_LIB_H_ +#define ACPI_PCC_LIB_H_ + +#include +#include + +// Send a message with dummy payload is to advertise the shared memory add= ress +#define DB_PCC_PAYLOAD_DUMMY 0x0F000000 + +#define DB_PCC_MSG_PAYLOAD_SIZE 12 // Number of Bytes + +// +// ACPI Platform Communication Channel (PCC) +// +#define ACPI_PCC_SUBSPACE_SHARED_MEM_SIGNATURE 0x50434300 // "PCC" +#define ACPI_PCC_SUBSPACE_SHARED_MEM_SIZE 0x4000 // Number of By= tes + +// +// Reserved Doorbell Mask +// Bit 0 --> 31 correspond to Doorbell 0 --> 31 +// +// List of reserved Doorbells +// 1. Doorbell 4: PCIe Hot-plug +// +#define ACPI_PCC_AVAILABLE_DOORBELL_MASK 0xEFFFEFFF +#define ACPI_PCC_NUMBER_OF_RESERVED_DOORBELLS 1 + +// Supported doorbells in the platform +#define ACPI_PCC_MAX_DOORBELL (NUMBER_OF_DOORBELLS_PER_SOCKET= * PLATFORM_CPU_MAX_SOCKET) + +// Valid doorbells for use +#define ACPI_PCC_MAX_SUBPACE_PER_SOCKET (NUMBER_OF_DOORBELLS_PER_SOCKET= - ACPI_PCC_NUMBER_OF_RESERVED_DOORBELLS) +#define ACPI_PCC_MAX_SUBPACE (ACPI_PCC_MAX_SUBPACE_PER_SOCKE= T * PLATFORM_CPU_MAX_SOCKET) + +#define ACPI_PCC_NOMINAL_LATENCY_US 1000 // us +#define ACPI_PCC_MAX_PERIODIC_ACCESS_RATE 0 // no limitation +#define ACPI_PCC_MIN_REQ_TURNAROUND_TIME_US 0 + +// Polling interval for PCC Command Complete +#define ACPI_PCC_COMMAND_POLL_INTERVAL_US 10 + +#define ACPI_PCC_COMMAND_POLL_COUNT (ACPI_PCC_NOMINAL_LATENCY_US / ACPI_P= CC_COMMAND_POLL_INTERVAL_US) + +// +// PCC subspace 2 (PMpro Doorbell Channel 2) is used for ACPI CPPC +// +#define ACPI_PCC_CPPC_DOORBELL_ID (PMproDoorbellChannel2) + +#define ACPI_PCC_CPPC_NOMINAL_LATENCY_US 100 +#define ACPI_PCC_CPPC_MIN_REQ_TURNAROUND_TIME_US 110 + + +/** + Allocate memory pages for the PCC shared memory region. + + @param PccSharedMemoryPtr Pointer to the shared memory address. + @param NumberOfSubspaces Number of subspaces slot in the shared me= mory region. + + @retval EFI_SUCCESS Send the message successfully. + @retval EFI_INVALID_PARAMETER TheNumberOfSubspaces is out of the valid = range. + @retval Otherwise Return errors from call to gBS->AllocateP= ages(). + +**/ +EFI_STATUS +EFIAPI +AcpiPccAllocateSharedMemory ( + OUT EFI_PHYSICAL_ADDRESS *PccSharedMemPointer, + IN UINT16 NumberOfSubspaces + ); + +/** + Free the whole shared memory region that is allocated by + the AcpiPccAllocateSharedMemory() function. + +**/ +VOID +EFIAPI +AcpiPccFreeSharedMemory ( + VOID + ); + +/** + Send a PCC message to the platform (SMpro/PMpro). + + @param Socket The Socket ID. + @param Doorbell The Doorbell index from supported Doorbells per socket= . + @param Subspace The Subspace index in the shared memory region. + + @retval EFI_SUCCESS Send the message successfully. + @retval EFI_INVALID_PARAMETER The Socket, Doorbell or Subspace is out o= f the valid range. + The data buffer is NULL or the size of da= ta buffer is zero. + @retval EFI_NOT_READY The shared memory region is NULL. + @retval EFI_TIMEOUT Timeout occurred when polling the PCC Com= mand Complete bit. + +**/ +EFI_STATUS +EFIAPI +AcpiPccSendMessage ( + IN UINT8 Socket, + IN UINT16 Doorbell, + IN UINT16 Subspace, + IN VOID *DataBuffer, + IN UINT32 DataSize + ); + +/** + Initialize the shared memory in the SMpro/PMpro Doorbell handler. + This function is to advertise the shared memory region address to the pl= atform (SMpro/PMpro). + + @param Socket The Socket ID. + @param Doorbell The Doorbell index from supported Doorbells per socket= . + @param Subspace The Subspace index in the shared memory region. + + @retval EFI_SUCCESS Initialize successfully. + @retval EFI_INVALID_PARAMETER The Socket, Doorbell or Subspace is out o= f the valid range. + +**/ +EFI_STATUS +EFIAPI +AcpiPccInitSharedMemory ( + IN UINT8 Socket, + IN UINT16 Doorbell, + IN UINT16 Subspace + ); + +/** + Unmask the Doorbell interrupt. + + @param Socket The Socket ID. + @param Doorbell The Doorbell index from supported Doorbells per socket= . + + @retval EFI_SUCCESS Unmask the Doorbell interrupt successfull= y. + @retval EFI_INVALID_PARAMETER The Socket or Doorbell is out of the vali= d range. + +**/ +EFI_STATUS +EFIAPI +AcpiPccUnmaskDoorbellInterrupt ( + IN UINT8 Socket, + IN UINT16 Doorbell + ); + +/** + Check whether the Doorbell is reserved or not. + + @param Doorbell The Doorbell index from supported Doorbells. + + @retval TRUE The Doorbell is reserved for private use or invalid= . + @retval FALSE The Doorbell is available. + +**/ +BOOLEAN +EFIAPI +AcpiPccIsDoorbellReserved ( + IN UINT16 Doorbell + ); + +#endif /* ACPI_PCC_LIB_H_ */ diff --git a/Platform/Ampere/AmperePlatformPkg/Library/AcpiPccLib/AcpiPccLi= b.c b/Platform/Ampere/AmperePlatformPkg/Library/AcpiPccLib/AcpiPccLib.c new file mode 100644 index 000000000000..48e0b9e876ef --- /dev/null +++ b/Platform/Ampere/AmperePlatformPkg/Library/AcpiPccLib/AcpiPccLib.c @@ -0,0 +1,241 @@ +/** @file + + Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +STATIC EFI_PHYSICAL_ADDRESS mPccSharedMemoryAddress; +STATIC UINTN mPccSharedMemorySize; + +EFI_STATUS +AcpiPccGetSharedMemoryAddress ( + IN UINT8 Socket, + IN UINT16 Subspace, + OUT VOID **SharedMemoryAddress + ) +{ + if (Socket >=3D PLATFORM_CPU_MAX_SOCKET + || Subspace >=3D ACPI_PCC_MAX_SUBPACE) + { + return EFI_INVALID_PARAMETER; + } + + if (mPccSharedMemoryAddress =3D=3D 0) { + return EFI_NOT_READY; + } + + *SharedMemoryAddress =3D (VOID *)(mPccSharedMemoryAddress + ACPI_PCC_SUB= SPACE_SHARED_MEM_SIZE * Subspace); + + return EFI_SUCCESS; +} + +/** + Allocate memory pages for the PCC shared memory region. + + @param PccSharedMemoryPtr Pointer to the shared memory address. + @param NumberOfSubspaces Number of subspaces slot in the shared me= mory region. + + @retval EFI_SUCCESS Send the message successfully. + @retval EFI_INVALID_PARAMETER TheNumberOfSubspaces is out of the valid = range. + @retval Otherwise Return errors from call to gBS->AllocateP= ages(). + +**/ +EFI_STATUS +EFIAPI +AcpiPccAllocateSharedMemory ( + OUT EFI_PHYSICAL_ADDRESS *PccSharedMemoryPtr, + IN UINT16 NumberOfSubspaces + ) +{ + EFI_STATUS Status; + + if (NumberOfSubspaces > ACPI_PCC_MAX_SUBPACE) { + return EFI_INVALID_PARAMETER; + } + + mPccSharedMemorySize =3D ACPI_PCC_SUBSPACE_SHARED_MEM_SIZE * NumberOfSub= spaces; + + Status =3D gBS->AllocatePages ( + AllocateAnyPages, + EfiRuntimeServicesData, + EFI_SIZE_TO_PAGES (mPccSharedMemorySize), + &mPccSharedMemoryAddress + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to allocate PCC shared memory\n")); + mPccSharedMemorySize =3D 0; + return Status; + } + + *PccSharedMemoryPtr =3D mPccSharedMemoryAddress; + + return EFI_SUCCESS; +} + +/** + Free the whole shared memory region that is allocated by + the AcpiPccAllocateSharedMemory() function. + +**/ +VOID +EFIAPI +AcpiPccFreeSharedMemory ( + VOID + ) +{ + if (mPccSharedMemoryAddress !=3D 0 && mPccSharedMemorySize !=3D 0) + { + gBS->FreePages ( + mPccSharedMemoryAddress, + EFI_SIZE_TO_PAGES (mPccSharedMemorySize) + ); + + mPccSharedMemoryAddress =3D 0; + } +} + +/** + Initialize the shared memory in the SMpro/PMpro Doorbell handler. + This function is to advertise the shared memory region address to the pl= atform (SMpro/PMpro). + + @param Socket The Socket ID. + @param Doorbell The Doorbell index from supported Doorbells per socket= . + @param Subspace The Subspace index in the shared memory region. + + @retval EFI_SUCCESS Initialize successfully. + @retval EFI_INVALID_PARAMETER The Socket, Doorbell or Subspace is out o= f the valid range. + +**/ +EFI_STATUS +EFIAPI +AcpiPccInitSharedMemory ( + IN UINT8 Socket, + IN UINT16 Doorbell, + IN UINT16 Subspace + ) +{ + EFI_STATUS Status; + EFI_ACPI_6_3_PCCT_GENERIC_SHARED_MEMORY_REGION_HEADER *PcctSharedMemoryR= egion; + UINT32 CommunicationData; + UINTN Timeout; + + if (Socket >=3D PLATFORM_CPU_MAX_SOCKET + || Doorbell >=3D NUMBER_OF_DOORBELLS_PER_SOCKET + || Subspace >=3D ACPI_PCC_MAX_SUBPACE) + { + return EFI_INVALID_PARAMETER; + } + + Status =3D AcpiPccGetSharedMemoryAddress (Socket, Subspace, (VOID **)&Pc= ctSharedMemoryRegion); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Zero shared memory region for each PCC subspace + // + SetMem ( + (VOID *)PcctSharedMemoryRegion, + sizeof (EFI_ACPI_6_3_PCCT_GENERIC_SHARED_MEMORY_REGION_HEADER) + DB_PC= C_MSG_PAYLOAD_SIZE, + 0 + ); + + // Advertise shared memory address to Platform (SMpro/PMpro) + // by ringing the doorbell with dummy PCC message + // + CommunicationData =3D DB_PCC_PAYLOAD_DUMMY; + + // + // Write Data into Communication Space Region + // + CopyMem ((VOID *)(PcctSharedMemoryRegion + 1), &CommunicationData, sizeo= f (CommunicationData)); + + PcctSharedMemoryRegion->Status.CommandComplete =3D 0; + PcctSharedMemoryRegion->Signature =3D ACPI_PCC_SUBSPACE_SHARED_MEM_SIGNA= TURE | Subspace; + + Status =3D MailboxMsgSetPccSharedMem (Socket, Doorbell, TRUE, (UINT64)Pc= ctSharedMemoryRegion); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to send mailbox message!\n", __FUNCTI= ON__)); + ASSERT_EFI_ERROR (Status); + return Status; + } + + // + // Polling CMD_COMPLETE bit + // + Timeout =3D ACPI_PCC_COMMAND_POLL_COUNT; + while (PcctSharedMemoryRegion->Status.CommandComplete !=3D 1) { + if (--Timeout <=3D 0) { + DEBUG ((DEBUG_ERROR, "%a - Timeout occurred when polling the PCC Sta= tus Complete\n", __FUNCTION__)); + return EFI_TIMEOUT; + } + MicroSecondDelay (ACPI_PCC_COMMAND_POLL_INTERVAL_US); + } + + return EFI_SUCCESS; +} + +/** + Unmask the Doorbell interrupt. + + @param Socket The Socket ID. + @param Doorbell The Doorbell index from supported Doorbells per socket= . + + @retval EFI_SUCCESS Unmask the Doorbell interrupt successfull= y. + @retval EFI_INVALID_PARAMETER The Socket or Doorbell is out of the vali= d range. + +**/ +EFI_STATUS +EFIAPI +AcpiPccUnmaskDoorbellInterrupt ( + IN UINT8 Socket, + IN UINT16 Doorbell + ) +{ + return MailboxUnmaskInterrupt (Socket, Doorbell); +} + +/** + Check whether the Doorbell is reserved or not. + + @param Doorbell The Doorbell index from supported Doorbells. + + @retval TRUE The Doorbell is reserved for private use or invalid= . + @retval FALSE The Doorbell is available. + +**/ +BOOLEAN +EFIAPI +AcpiPccIsDoorbellReserved ( + IN UINT16 Doorbell + ) +{ + if (Doorbell >=3D ACPI_PCC_MAX_DOORBELL) { + ASSERT (FALSE); + return TRUE; + } + + if (((1 << Doorbell) & ACPI_PCC_AVAILABLE_DOORBELL_MASK) =3D=3D 0) { + // + // The doorbell is reserved for private use. + // + return TRUE; + } + + return FALSE; +} --=20 2.17.1