From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id 1AC8E780091 for ; Thu, 1 Aug 2024 09:39:53 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=yoh4d7KdC/aGJ3OwQ1IPXrAwgT3Gulz1HI42/iDHbEM=; 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:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20240206; t=1722505193; v=1; b=cO7Tob0yWTJy+q2ig2hGuOL65FTBqtyeU4Nsr7Ud7sv3tLOus9pAwM06WecH3kVtvXHygtf4 uzr1BahpE3b5fATLzPRiP/mI6XJ7QHmSwXT4Hyvlt4LudzVIS3WgJXJVpHubxnySUYD7im96WaU X3tg8mL/HG6uQmqMO7hiBVq28UuDhXWj2+EwSPxGuM2wxCWQGhVKa3hV18tiTNDCXFNjlpmojhe KPz1ckJzVWTQLGwCvQgJLXmSa/CtOxr9ubsTaMzDcOrpei971fwQ3cGcknpr4l5llpveq0MEWzr 9FiotuDbmsNplqawaHh9Yng2MXXkJQWnT1wMFXAZZU/OA== X-Received: by 127.0.0.2 with SMTP id CTi5YY7687511xu1yucr9Pbr; Thu, 01 Aug 2024 02:39:52 -0700 X-Received: from BL2PR02CU003.outbound.protection.outlook.com (BL2PR02CU003.outbound.protection.outlook.com [52.101.51.141]) by mx.groups.io with SMTP id smtpd.web11.64319.1722505159479075774 for ; Thu, 01 Aug 2024 02:39:52 -0700 X-Received: from PH0PR01MB7287.prod.exchangelabs.com (2603:10b6:510:10a::21) by PH7PR01MB7959.prod.exchangelabs.com (2603:10b6:510:277::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.22; Thu, 1 Aug 2024 09:39:06 +0000 X-Received: from PH0PR01MB7287.prod.exchangelabs.com ([fe80::fc79:e629:93aa:8b8f]) by PH0PR01MB7287.prod.exchangelabs.com ([fe80::fc79:e629:93aa:8b8f%3]) with mapi id 15.20.7807.026; Thu, 1 Aug 2024 09:39:06 +0000 From: "Nhi Pham via groups.io" To: devel@edk2.groups.io CC: quic_llindhol@quicinc.com, chuong@os.amperecomputing.com, rebecca@os.amperecomputing.com, nhi@os.amperecomputing.com Subject: [edk2-devel] [edk2-platforms][PATCH 3/5] AmpereAltraPkg: Add SmbusHc PEI and DXE drivers Date: Thu, 1 Aug 2024 16:36:16 +0700 Message-ID: <20240801093618.191274-4-nhi@os.amperecomputing.com> In-Reply-To: <20240801093618.191274-1-nhi@os.amperecomputing.com> References: <20240801093618.191274-1-nhi@os.amperecomputing.com> X-ClientProxiedBy: SI2PR01CA0051.apcprd01.prod.exchangelabs.com (2603:1096:4:193::6) To PH0PR01MB7287.prod.exchangelabs.com (2603:10b6:510:10a::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR01MB7287:EE_|PH7PR01MB7959:EE_ X-MS-Office365-Filtering-Correlation-Id: b47c44a7-07ce-488a-f4db-08dcb20dc981 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Ap1V9SZfzi31mPF1jfI2LCypFG0hNI3RGXOsG0/FnkNArI/qWrCf/MQuiKdz?= =?us-ascii?Q?UgSaqG4CLIjbbh8cHELOM+4SuYxyQum7oblDuoEioxPsjxS/UuoKlC0gDwz9?= =?us-ascii?Q?xDpsnis+5B/6ZsC7PWISUiYu/Ja48aWNhvtn+x9SCvuur/BkUMKhN4oJpBhC?= =?us-ascii?Q?Ay/C2LG4KrO0sbuIAhqXY9wEqkfJ18YYq0nK1oS/byUxkHQ+S7JN0uFTGd9D?= =?us-ascii?Q?IiKW14wKJO2Ll/9iHEuzmaJpE+eYocpVphVamHvMEhhfxbpLPYxoabLtigax?= =?us-ascii?Q?FyzsbVUF1+n90XfTbXoleTBMMIoE5kqieSiEDXqSlAGC1SEcXNAw2+37Y0mW?= =?us-ascii?Q?jskRp8mnliUAZbH/6Jlm9TJ3ojQtUIKE5eN6uBD6D03oOFGFCIakXcOairaS?= =?us-ascii?Q?p8fdnaNviQmUqa4V66pCgA/aky2j5gE19BdCJEiJYvehypLoiLygI8vqC9AD?= =?us-ascii?Q?8jfUDSyf3spjrAqD944EerP99qli/hAWRwoBsQO9PbjoLpPfFZ2egdr4559p?= =?us-ascii?Q?cjecxYbxamTcUMHwfzKYXyz10zRHc7SqXmG4ajpIrLJvySDDuIUOfRZw6ff7?= =?us-ascii?Q?jzGCBme4mEh0bDYnlhctYw0lv3NZhUS5MNPvFHMBsQushIWTBSw9N7S8tjH/?= =?us-ascii?Q?sXMMaF7K/zEfN0LixNQWQnudM9OqAztzv1x7h3eZM/AX7qY+v5ALJfZJGBRo?= =?us-ascii?Q?6On7FF/mnkUHgX6hxfL1l2ATOqekgcfslwlqX7rbmQWalvrx5/sZOs/bLTCw?= =?us-ascii?Q?NxSK9ot7vv+dOSZPntoUBwB8r2cD6EVExkyAbmpkJdCGVhdtodolylJwUCs/?= =?us-ascii?Q?219bopVOw+DOlPLduFyycAVdrCcQ2T5jUEJYlgMIEtMueSmuHMxOAS7FiEfw?= =?us-ascii?Q?QHXlzQMYw3h7cdJqhAqYbgXBB6jpQo3O6vdmaNhBHlRqxqHAslBy3cMmmikX?= =?us-ascii?Q?nPrV1mRFT1jzfyUVsH1TJcNg8ecvHiqykT1tpijuU+OFhbwOQl5+YAnD44Dj?= =?us-ascii?Q?et9j9bcLQxwfKkMpaPZvKFUbM0h+cDcGqsS8d5URB95IBx1QTFzyDf7iTqDP?= =?us-ascii?Q?6fEjgwWAbeKXuhjOU1Y6pcnArYyxwrLKkJLTHL+PrG8oA25xG8Xm+x1LNhOZ?= =?us-ascii?Q?4xJ4hNyPyiXnZJEuSPdfD7JlFBkhbKWg//ELrThIEibehWS3+wvw6WnGUoJs?= =?us-ascii?Q?r4r0cHWRdzYStPZMQTqGzLhvlbRtYDboVFlISxE9OCbFHTtMCb1NTzfDjdzW?= =?us-ascii?Q?+tK1Ba46PTWjX8jJ5kD0SVY1S9vtKufdyNxEXXb8cxEHlAYX34Frp8gZHfDZ?= =?us-ascii?Q?f0t6SwQXeeDX9HuUPmP2u398tdlhNKEP5VatnAePq7bJeKq5xqtE6G04NGrJ?= =?us-ascii?Q?s8JQhalKhP8QiK8IXIzqnZaKQ6Nh4Ep/21XI5zbmjQyjlGWaWQ=3D=3D?= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?jHTQkabThzOFjwO5kNvrjQPmnRfDgI1+N4E1mdJ3dJmzDcgZzX5jFYndvs/t?= =?us-ascii?Q?0rvFzeMOLUAZu72GNbG0VNXolbQcQ1yRPlt2ZAsnCJMPwVd7NUYpxVuyRnA+?= =?us-ascii?Q?Hd/iVbiDhSehblVaaM4LPTYFjRSATOk6+fgK9JZoZfaTSrsEURQ9FEzCIS4L?= =?us-ascii?Q?RT9J54twr9NIqEtEUeXvpxWNcWVGzm91WnPE2qdUiISIcPGw4AZM0/CJBXea?= =?us-ascii?Q?7q5B4hlWBpXdPXt1I/yOcP5TErwp7lsZNjeYaUWiheLVXA4g6zKwi1GkbaTi?= =?us-ascii?Q?OCwnCDlwdLhuqDy8wU17g5x0mhxZStzLYEM9/H3GqjiRrvF2nX/oZpu/7ird?= =?us-ascii?Q?6lLHYNK/qlxR1EugctKSh4KGgKWU+fXRJOr92yhPEjSVHH7LiIieiS/f4sVP?= =?us-ascii?Q?84RIFQF9nE+LHROkstL7MXJ/ASc1qrTw5z6cNYvlym9VYdLZcQDhm092/Zt1?= =?us-ascii?Q?bIMWDl9nMnHpnJN7ti0y/2Eye27WWVVzgyE51Rx7cm3zpJnrXPapCboeNz4i?= =?us-ascii?Q?i0LGDDkm/8Lliu+AocwwBRkwSpyOJgxRDmxzcZ6VCWlQ6Elz8svtFoUqyDgw?= =?us-ascii?Q?N8sDKPyc8AD2LmIXLjX7BW7gXCWFjoosTjqy5OXIi7q4LcuZV7DEnQzvkirj?= =?us-ascii?Q?a6HqUoeJ5fUmW3WS1L3ISqHk8ydIaDrCwsx8gxvZjdmKK7slkJprA/6sRrMd?= =?us-ascii?Q?HTFUMa+22VHWO1ZHgVD2MJ8fCssk7FUYUELAqQh/0QZDrUl7g3XV5Wzo/Xae?= =?us-ascii?Q?uQXKTBzbqtIGzD/Prf8GSdZp09zPLWhmXFdNIBlFgxZ5RJfz8PdrfYXF/oQT?= =?us-ascii?Q?jJq7poruB3vrVrfLNY8m1g1EbDHhYvvnuLvjMo7KHI1hBrtEvQbPoaHK7BjT?= =?us-ascii?Q?3sE0q7gSXfxClJ9R++evQkLxWOIcNIDQsvNLhpGhhDuclFEF648HMc/de9lp?= =?us-ascii?Q?nfc9Ea7uu490lvk4oyIPhklDTPm63uNsWkLVyPn4GVT0ms29QKBPY0XDndmR?= =?us-ascii?Q?ssD6L6e3sNrINnvwZDfERrjec1PV9jC8xxkkECc0fRv811jCdC3S6psJq3mi?= =?us-ascii?Q?VcBmge5VlART9n8ON15uMhVkKziKMQXyshnA12R7CR1EdokSi+T0rap0x09E?= =?us-ascii?Q?FkXBvwY9+NpO6WY7QMNwF2PsLZvA7v6+dNVwd6lND9IYGNuXrpWqnz78HJtf?= =?us-ascii?Q?FCaPZBK3vVWl7dXMrhrS1sBq6ubFHwHrFUJDrcELBCJ2dEzFP4NmRnjADlQm?= =?us-ascii?Q?U0i/AgetYREi7ylN0qTTZjFCBuuEr5g20Wiz+53AP4p/yRurOy6r+9FKTXxb?= =?us-ascii?Q?6ZFygqyWR5qzTU72S3VX/31zJNlTkfW2T1g9OeRLJenJyW2ujOYFmRW9by3c?= =?us-ascii?Q?YjceR01kxma1OXOcSQ76gEj2Qthtjwpx658sfzC5cbP+VFh8/Art8AkJy1PZ?= =?us-ascii?Q?oPKQxqs6LkQyw+VnRei53FV2Zylxn4lfPCjzdfLAna+Nts39/vnKStmB9Zyx?= =?us-ascii?Q?3qFXzsheZu00ZjdQ0eMmmeTVfeAjDMj4Zd9HWSnPbIAiqyDxBlYMMHMeY89Z?= =?us-ascii?Q?jhr7uCybXAJc+QvVeqhR7p9UKMXq5f8Cq7vN05vJKqoKxYqzf8MNUrTQU8+k?= =?us-ascii?Q?dxLVaGNiTolkiTiLgZJGXrQ=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: b47c44a7-07ce-488a-f4db-08dcb20dc981 X-MS-Exchange-CrossTenant-AuthSource: PH0PR01MB7287.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2024 09:39:06.7402 (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: 7ktFB63i5bEiEm4m2BSZshPH0IVP5FnXv2g//AGyoigbbDXfvT3G+WLPgXrlWBH1stZnzlsJ7eT7VjNDjqIsQNRv0Q7sjQXricxgNXlxPYg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR01MB7959 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 Resent-Date: Thu, 01 Aug 2024 02:39:52 -0700 Resent-From: nhi@os.amperecomputing.com Reply-To: devel@edk2.groups.io,nhi@os.amperecomputing.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: DjfwDgnHkvAdzbgb19KMOZYmx7686176AA= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=cO7Tob0y; dmarc=pass (policy=none) header.from=groups.io; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io This adds the implementation of SMBUS PPI and Protocol to produce SMBUS interface in both PEI and DXE phases for use by IPMI SSIF. Signed-off-by: Nhi Pham --- Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.inf | 43 +++ Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.inf | 43 +++ Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcCommon.h | 95 ++++++= + Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcCommon.c | 262 ++++++= ++++++++++++ Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.c | 277 ++++++= ++++++++++++++ Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.c | 263 ++++++= +++++++++++++ 6 files changed, 983 insertions(+) diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.inf b= /Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.inf new file mode 100644 index 000000000000..7e8c8176658e --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.inf @@ -0,0 +1,43 @@ +## @file +# +# Copyright (c) 2024, Ampere Computing LLC. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D SmbusHcDxe + FILE_GUID =3D A92C6874-B59E-49A7-957D-8511C9D8520E + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D InitializeSmbus + +[Sources] + SmbusHcCommon.c + SmbusHcDxe.c + +[Packages] + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec + Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec + +[LibraryClasses] + BaseMemoryLib + DebugLib + GpioLib + I2cLib + UefiBootServicesTableLib + UefiDriverEntryPoint + +[Protocols] + gEfiSmbusHcProtocolGuid # PRODUCES + +[Pcd] + gAmpereTokenSpaceGuid.PcdSmbusI2cBusNumber + gAmpereTokenSpaceGuid.PcdSmbusI2cBusSpeed + +[Depex] + TRUE diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.inf b= /Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.inf new file mode 100644 index 000000000000..810a583feab3 --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.inf @@ -0,0 +1,43 @@ +## @file +# +# Copyright (c) 2024, Ampere Computing LLC. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D SmbusHcPeim + FILE_GUID =3D 1D770ACE-36E9-4B74-B548-4F423B60A26C + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D InitializeSmbusPeim + +[Sources] + SmbusHcCommon.c + SmbusHcPei.c + +[Packages] + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec + Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec + +[LibraryClasses] + BaseMemoryLib + DebugLib + GpioLib + I2cLib + PeimEntryPoint + PeiServicesLib + +[Ppis] + gEfiPeiSmbus2PpiGuid # PRODUCES + +[Pcd] + gAmpereTokenSpaceGuid.PcdSmbusI2cBusNumber + gAmpereTokenSpaceGuid.PcdSmbusI2cBusSpeed + +[Depex] + TRUE diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcCommon.h = b/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcCommon.h new file mode 100644 index 000000000000..db19d50b0f2a --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcCommon.h @@ -0,0 +1,95 @@ +/** @file + + Copyright (c) 2024, Ampere Computing LLC. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef SMBUS_HC_COMMON_LIB_H_ +#define SMBUS_HC_COMMON_LIB_H_ + +#include +#include +#include + +// +// I2C Based SMBus info +// +#define I2C_BUS_NUMBER (FixedPcdGet8 (PcdSmbusI2cBusNumber)) +#define I2C_BUS_SPEED (FixedPcdGet32 (PcdSmbusI2cBusSpeed)) +#define I2C_WRITE_ADDRESS(Addr) ((Addr) << 1 | 0) +#define I2C_READ_ADDRESS(Addr) ((Addr) << 1 | 1) + +// +// SMBus 2.0 +// +#define SMBUS_MAX_BLOCK_LENGTH 0x20 +#define SMBUS_READ_TEMP_LENGTH (SMBUS_MAX_BLOCK_LENGTH + 2) // Length += 32 Bytes + PEC +#define SMBUS_WRITE_TEMP_LENGTH (SMBUS_MAX_BLOCK_LENGTH + 3) // CMD + Le= ngth + 32 Bytes + PEC + +// +// SMBus PEC +// +#define CRC8_POLYNOMINAL_KEY 0x107 // X^8 + X^2 + X + 1 + +/** + Executes an SMBus operation to an SMBus controller. Returns when either = the command has been + executed or an error is encountered in doing the operation. + + The Execute() function provides a standard way to execute an operation a= s defined in the System + Management Bus (SMBus) Specification. The resulting transaction will be = either that the SMBus + slave devices accept this transaction or that this function returns with= error. + + @param This A pointer to the EFI_SMBUS_HC_PROTOCOL i= nstance. + @param SlaveAddress The SMBus slave address of the device wi= th which to communicate. + @param Command This command is transmitted by the SMBus= host controller to the + SMBus slave device and the interpretatio= n is SMBus slave device + specific. It can mean the offset to a li= st of functions inside an + SMBus slave device. Not all operations o= r slave devices support + this command's registers. + @param Operation Signifies which particular SMBus hardwar= e protocol instance that + it will use to execute the SMBus transac= tions. This SMBus + hardware protocol is defined by the SMBu= s Specification and is + not related to EFI. + @param PecCheck Defines if Packet Error Code (PEC) check= ing is required for this + operation. + @param Length Signifies the number of bytes that this = operation will do. The + maximum number of bytes can be revision = specific and operation + specific. This field will contain the ac= tual number of bytes that + are executed for this operation. Not all= operations require this + argument. + @param Buffer Contains the value of data to execute to= the SMBus slave device. + Not all operations require this argument= . The length of this + buffer is identified by Length. + + @retval EFI_SUCCESS The last data that was returned from the= access matched the poll + exit criteria. + @retval EFI_CRC_ERROR Checksum is not correct (PEC is incorrec= t). + @retval EFI_TIMEOUT Timeout expired before the operation was= completed. Timeout is + determined by the SMBus host controller = device. + @retval EFI_OUT_OF_RESOURCES The request could not be completed due t= o a lack of resources. + @retval EFI_DEVICE_ERROR The request was not completed because a = failure that was + reflected in the Host Status Register bi= t. Device errors are a + result of a transaction collision, illeg= al command field, + unclaimed cycle (host initiated), or bus= errors (collisions). + @retval EFI_INVALID_PARAMETER Operation is not defined in EFI_SMBUS_OP= ERATION. + @retval EFI_INVALID_PARAMETER Length/Buffer is NULL for operations exc= ept for EfiSmbusQuickRead + and EfiSmbusQuickWrite. Length is outsid= e the range of valid + values. + @retval EFI_UNSUPPORTED The SMBus operation or PEC is not suppor= ted. + @retval EFI_BUFFER_TOO_SMALL Buffer is not sufficient for this operat= ion. + +**/ +EFI_STATUS +EFIAPI +SmbusHcCommonExecute ( + IN EFI_SMBUS_DEVICE_ADDRESS SlaveAddress, + IN EFI_SMBUS_DEVICE_COMMAND Command, + IN EFI_SMBUS_OPERATION Operation, + IN BOOLEAN PecCheck, + IN OUT UINTN *Length, + IN OUT VOID *Buffer + ); + +#endif /* SMBUS_HC_COMMON_LIB_H_ */ diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcCommon.c = b/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcCommon.c new file mode 100644 index 000000000000..6219c99cda18 --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcCommon.c @@ -0,0 +1,262 @@ +/** @file + SmbusHcCommon implement common api for SmbusHc + + Copyright (c) 2024, Ampere Computing LLC. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include + +#include "SmbusHcCommon.h" + +/** + Incremental calculate Pec base on previous Pec value and CRC8 of data ar= ray + pointed to by Buffer + + @param Pec Previous Pec + @param Buffer Pointer to data array + @param Length Array count + + @retval Pec + +**/ +UINT8 +CalculatePec ( + UINT8 Pec, + UINT8 *Buffer, + UINT32 Length + ) +{ + UINT8 Offset, Index; + + for (Offset =3D 0; Offset < Length; Offset++) { + Pec ^=3D Buffer[Offset]; + for (Index =3D 0; Index < 8; Index++) { + if ((Pec & 0x80) !=3D 0) { + Pec =3D (UINT8)((Pec << 1) ^ CRC8_POLYNOMINAL_KEY); + } else { + Pec <<=3D 1; + } + } + } + + return Pec & 0xFF; +} + +/** + Executes an SMBus operation to an SMBus controller. Returns when either = the command has been + executed or an error is encountered in doing the operation. + + The Execute() function provides a standard way to execute an operation a= s defined in the System + Management Bus (SMBus) Specification. The resulting transaction will be = either that the SMBus + slave devices accept this transaction or that this function returns with= error. + + @param SlaveAddress The SMBus slave address of the device wi= th which to communicate. + @param Command This command is transmitted by the SMBus= host controller to the + SMBus slave device and the interpretatio= n is SMBus slave device + specific. It can mean the offset to a li= st of functions inside an + SMBus slave device. Not all operations o= r slave devices support + this command's registers. + @param Operation Signifies which particular SMBus hardwar= e protocol instance that + it will use to execute the SMBus transac= tions. This SMBus + hardware protocol is defined by the SMBu= s Specification and is + not related to EFI. + @param PecCheck Defines if Packet Error Code (PEC) check= ing is required for this + operation. + @param Length Signifies the number of bytes that this = operation will do. The + maximum number of bytes can be revision = specific and operation + specific. This field will contain the ac= tual number of bytes that + are executed for this operation. Not all= operations require this + argument. + @param Buffer Contains the value of data to execute to= the SMBus slave device. + Not all operations require this argument= . The length of this + buffer is identified by Length. + + @retval EFI_SUCCESS The last data that was returned from the= access matched the poll + exit criteria. + @retval EFI_CRC_ERROR Checksum is not correct (PEC is incorrec= t). + @retval EFI_TIMEOUT Timeout expired before the operation was= completed. Timeout is + determined by the SMBus host controller = device. + @retval EFI_OUT_OF_RESOURCES The request could not be completed due t= o a lack of resources. + @retval EFI_DEVICE_ERROR The request was not completed because a = failure that was + reflected in the Host Status Register bi= t. Device errors are a + result of a transaction collision, illeg= al command field, + unclaimed cycle (host initiated), or bus= errors (collisions). + @retval EFI_INVALID_PARAMETER Operation is not defined in EFI_SMBUS_OP= ERATION. + @retval EFI_INVALID_PARAMETER Length/Buffer is NULL for operations exc= ept for EfiSmbusQuickRead + and EfiSmbusQuickWrite. Length is outsid= e the range of valid + values. + @retval EFI_UNSUPPORTED The SMBus operation or PEC is not suppor= ted. + @retval EFI_BUFFER_TOO_SMALL Buffer is not sufficient for this operat= ion. + +**/ +EFI_STATUS +EFIAPI +SmbusHcCommonExecute ( + IN EFI_SMBUS_DEVICE_ADDRESS SlaveAddress, + IN EFI_SMBUS_DEVICE_COMMAND Command, + IN EFI_SMBUS_OPERATION Operation, + IN BOOLEAN PecCheck, + IN OUT UINTN *Length, + IN OUT VOID *Buffer + ) +{ + EFI_STATUS Status; + UINTN DataLen, Idx; + UINT8 ReadTemp[SMBUS_READ_TEMP_LENGTH]; + UINT8 WriteTemp[SMBUS_WRITE_TEMP_LENGTH]; + UINT8 CrcTemp[10]; + UINT8 Pec; + + if ( ((Operation !=3D EfiSmbusQuickRead) && (Operation !=3D EfiSmbusQui= ckWrite)) + && ((Length =3D=3D NULL) || (Buffer =3D=3D NULL))) + { + return EFI_INVALID_PARAMETER; + } + + // + // Switch to correct I2C bus and speed + // + Status =3D I2cProbe (I2C_BUS_NUMBER, I2C_BUS_SPEED); + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; + } + + // + // Process Operation + // + switch (Operation) { + case EfiSmbusWriteBlock: + if (*Length > SMBUS_MAX_BLOCK_LENGTH) { + return EFI_INVALID_PARAMETER; + } + + WriteTemp[0] =3D Command; + WriteTemp[1] =3D *Length; + CopyMem (&WriteTemp[2], Buffer, *Length); + DataLen =3D *Length + 2; + + // + // PEC handling + // + if (PecCheck) { + CrcTemp[0] =3D I2C_WRITE_ADDRESS (SlaveAddress.SmbusDeviceAddress)= ; + Pec =3D CalculatePec (0, &CrcTemp[0], 1); + Pec =3D CalculatePec (Pec, WriteTemp, DataLen); + DEBUG ((DEBUG_VERBOSE, "\nWriteBlock PEC =3D 0x%x \n", Pec)); + WriteTemp[DataLen] =3D Pec; + DataLen +=3D 1; + } + + DEBUG ((DEBUG_VERBOSE, "W %d: ", DataLen)); + for (Idx =3D 0; Idx < DataLen; Idx++) { + DEBUG ((DEBUG_VERBOSE, "0x%x ", WriteTemp[Idx])); + } + + DEBUG ((DEBUG_VERBOSE, "\n")); + + Status =3D I2cWrite ( + I2C_BUS_NUMBER, + SlaveAddress.SmbusDeviceAddress, + WriteTemp, + (UINT32 *)&DataLen + ); + if (EFI_ERROR (Status)) { + if (Status !=3D EFI_TIMEOUT) { + Status =3D EFI_DEVICE_ERROR; + } + } + + break; + + case EfiSmbusReadBlock: + WriteTemp[0] =3D Command; + DataLen =3D *Length + 2; // +1 byte for Data Length +1 byte for= PEC + Status =3D SmbusRead ( + I2C_BUS_NUMBER, + SlaveAddress.SmbusDeviceAddress, + WriteTemp, + 1, + ReadTemp, + (UINT32 *)&DataLen, + PecCheck + ); + if (EFI_ERROR (Status)) { + if (Status !=3D EFI_TIMEOUT) { + Status =3D EFI_DEVICE_ERROR; + } + + *Length =3D 0; + break; + } + + DEBUG ((DEBUG_VERBOSE, "R %d: ", DataLen)); + for (Idx =3D 0; Idx < DataLen; Idx++) { + DEBUG ((DEBUG_VERBOSE, "0x%x ", ReadTemp[Idx])); + } + + DEBUG ((DEBUG_VERBOSE, "\n")); + + DataLen =3D ReadTemp[0]; + + // + // PEC handling + // + if (PecCheck) { + CrcTemp[0] =3D I2C_WRITE_ADDRESS (SlaveAddress.SmbusDeviceAddress)= ; + CrcTemp[1] =3D Command; + CrcTemp[2] =3D I2C_READ_ADDRESS (SlaveAddress.SmbusDeviceAddress); + + Pec =3D CalculatePec (0, &CrcTemp[0], 3); + Pec =3D CalculatePec (Pec, ReadTemp, DataLen + 1); + + if (Pec !=3D ReadTemp[DataLen + 1]) { + DEBUG ((DEBUG_ERROR, "ReadBlock PEC cal =3D 0x%x !=3D 0x%x\n", P= ec, ReadTemp[DataLen + 1])); + return EFI_CRC_ERROR; + } else { + DEBUG ((DEBUG_VERBOSE, "ReadBlock PEC 0x%x\n", ReadTemp[DataLen = + 1])); + } + } + + if ((DataLen =3D=3D 0) || (DataLen > SMBUS_MAX_BLOCK_LENGTH)) { + DEBUG ((DEBUG_ERROR, "%a: Invalid length =3D %d\n", __func__, Data= Len)); + *Length =3D 0; + Status =3D EFI_INVALID_PARAMETER; + } else if (DataLen > *Length) { + DEBUG ((DEBUG_ERROR, "%a: Buffer too small\n", __func__)); + *Length =3D 0; + Status =3D EFI_BUFFER_TOO_SMALL; + } else { + *Length =3D DataLen; + CopyMem (Buffer, &ReadTemp[1], DataLen); + } + + break; + + case EfiSmbusQuickRead: + case EfiSmbusQuickWrite: + case EfiSmbusReceiveByte: + case EfiSmbusSendByte: + case EfiSmbusReadByte: + case EfiSmbusWriteByte: + case EfiSmbusReadWord: + case EfiSmbusWriteWord: + case EfiSmbusProcessCall: + case EfiSmbusBWBRProcessCall: + DEBUG ((DEBUG_ERROR, "%a: Unsupported command\n", __func__)); + Status =3D EFI_UNSUPPORTED; + break; + + default: + Status =3D EFI_INVALID_PARAMETER; + } + + return Status; +} diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.c b/S= ilicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.c new file mode 100644 index 000000000000..49a16a2c3d7e --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.c @@ -0,0 +1,277 @@ +/** SmbusHc protocol implementation follows SMBus 2.0 specification. + + Copyright (c) 2024, Ampere Computing LLC. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include + +#include "SmbusHcCommon.h" + +// +// Handle to install SMBus Host Controller protocol. +// +EFI_HANDLE mSmbusHcHandle =3D NULL; + +/** + Executes an SMBus operation to an SMBus controller. Returns when either = the command has been + executed or an error is encountered in doing the operation. + + The Execute() function provides a standard way to execute an operation a= s defined in the System + Management Bus (SMBus) Specification. The resulting transaction will be = either that the SMBus + slave devices accept this transaction or that this function returns with= error. + + @param This A pointer to the EFI_SMBUS_HC_PROTOCOL i= nstance. + @param SlaveAddress The SMBus slave address of the device wi= th which to communicate. + @param Command This command is transmitted by the SMBus= host controller to the + SMBus slave device and the interpretatio= n is SMBus slave device + specific. It can mean the offset to a li= st of functions inside an + SMBus slave device. Not all operations o= r slave devices support + this command's registers. + @param Operation Signifies which particular SMBus hardwar= e protocol instance that + it will use to execute the SMBus transac= tions. This SMBus + hardware protocol is defined by the SMBu= s Specification and is + not related to EFI. + @param PecCheck Defines if Packet Error Code (PEC) check= ing is required for this + operation. + @param Length Signifies the number of bytes that this = operation will do. The + maximum number of bytes can be revision = specific and operation + specific. This field will contain the ac= tual number of bytes that + are executed for this operation. Not all= operations require this + argument. + @param Buffer Contains the value of data to execute to= the SMBus slave device. + Not all operations require this argument= . The length of this + buffer is identified by Length. + + @retval EFI_SUCCESS The last data that was returned from the= access matched the poll + exit criteria. + @retval EFI_CRC_ERROR Checksum is not correct (PEC is incorrec= t). + @retval EFI_TIMEOUT Timeout expired before the operation was= completed. Timeout is + determined by the SMBus host controller = device. + @retval EFI_OUT_OF_RESOURCES The request could not be completed due t= o a lack of resources. + @retval EFI_DEVICE_ERROR The request was not completed because a = failure that was + reflected in the Host Status Register bi= t. Device errors are a + result of a transaction collision, illeg= al command field, + unclaimed cycle (host initiated), or bus= errors (collisions). + @retval EFI_INVALID_PARAMETER Operation is not defined in EFI_SMBUS_OP= ERATION. + @retval EFI_INVALID_PARAMETER Length/Buffer is NULL for operations exc= ept for EfiSmbusQuickRead + and EfiSmbusQuickWrite. Length is outsid= e the range of valid + values. + @retval EFI_UNSUPPORTED The SMBus operation or PEC is not suppor= ted. + @retval EFI_BUFFER_TOO_SMALL Buffer is not sufficient for this operat= ion. + +**/ +EFI_STATUS +EFIAPI +SmbusHcExecute ( + IN CONST EFI_SMBUS_HC_PROTOCOL *This, + IN EFI_SMBUS_DEVICE_ADDRESS SlaveAddress, + IN EFI_SMBUS_DEVICE_COMMAND Command, + IN EFI_SMBUS_OPERATION Operation, + IN BOOLEAN PecCheck, + IN OUT UINTN *Length, + IN OUT VOID *Buffer + ) +{ + EFI_STATUS Status; + EFI_TPL OldTpl; + + ASSERT (This !=3D NULL); + + OldTpl =3D gBS->RaiseTPL (TPL_HIGH_LEVEL); + + Status =3D SmbusHcCommonExecute (SlaveAddress, Command, Operation, PecCh= eck, Length, Buffer); + + gBS->RestoreTPL (OldTpl); + + return Status; +} + +/** + + The SmbusHcArpDevice() function provides a standard way for a device dri= ver to + enumerate the entire SMBus or specific devices on the bus. + + @param This A pointer to the EFI_SMBUS_HC_PROTOCOL instance. + + @param ArpAll A Boolean expression that indicates if the + host drivers need to enumerate all the devices + or enumerate only the device that is + identified by SmbusUdid. If ArpAll is TRUE, + SmbusUdid and SlaveAddress are optional. If + ArpAll is FALSE, ArpDevice will enumerate + SmbusUdid and the address will be at + SlaveAddress. + + @param SmbusUdid The Unique Device Identifier (UDID) that is + associated with this device. Type + EFI_SMBUS_UDID is defined in + EFI_PEI_SMBUS_PPI.ArpDevice() in the + Platform Initialization SMBus PPI + Specification. + + @param SlaveAddress The SMBus slave address that is + associated with an SMBus UDID. + + @retval EFI_SUCCESS The last data that was returned from the + access matched the poll exit criteria. + + @retval EFI_CRC_ERROR Checksum is not correct (PEC is + incorrect). + + @retval EFI_TIMEOUT Timeout expired before the operation was + completed. Timeout is determined by the + SMBus host controller device. + + @retval EFI_OUT_OF_RESOURCES The request could not be + completed due to a lack of + resources. + + @retval EFI_DEVICE_ERROR The request was not completed + because a failure was reflected in + the Host Status Register bit. Device + Errors are a result of a transaction + collision, illegal command field, + unclaimed cycle (host initiated), or + bus errors (collisions). + + @retval EFI_UNSUPPORTED ArpDevice, GetArpMap, and Notify are + not implemented by this driver. + +**/ +EFI_STATUS +EFIAPI +SmbusHcArpDevice ( + IN CONST EFI_SMBUS_HC_PROTOCOL *This, + IN BOOLEAN ArpAll, + IN EFI_SMBUS_UDID *SmbusUdid, OPTIONAL + IN OUT EFI_SMBUS_DEVICE_ADDRESS *SlaveAddress OPTIONAL + ) +{ + // + // Not supported + // + return EFI_UNSUPPORTED; +} + +/** + The SmbusHcGetArpMap() function returns the mapping of all the SMBus dev= ices + that were enumerated by the SMBus host driver. + + @param This A pointer to the EFI_SMBUS_HC_PROTOCOL instance. + + @param Length Size of the buffer that contains the SMBus + device map. + + @param SmbusDeviceMap The pointer to the device map as + enumerated by the SMBus controller + driver. + + @retval EFI_SUCCESS The SMBus returned the current device map. + + @retval EFI_UNSUPPORTED ArpDevice, GetArpMap, and Notify are + not implemented by this driver. + +**/ +EFI_STATUS +EFIAPI +SmbusHcGetArpMap ( + IN CONST EFI_SMBUS_HC_PROTOCOL *This, + IN OUT UINTN *Length, + IN OUT EFI_SMBUS_DEVICE_MAP **SmbusDeviceMap + ) +{ + // + // Not supported + // + return EFI_UNSUPPORTED; +} + +/** + + The SmbusHcNotify() function registers all the callback functions to + allow the bus driver to call these functions when the + SlaveAddress/Data pair happens. + + @param This A pointer to the EFI_SMBUS_HC_PROTOCOL instance. + + @param SlaveAddress Address that the host controller detects + as sending a message and calls all the registere= d function. + + @param Data Data that the host controller detects as sending + message and calls all the registered function. + + + @param NotifyFunction The function to call when the bus + driver detects the SlaveAddress and + Data pair. + + @retval EFI_SUCCESS NotifyFunction was registered. + + @retval EFI_UNSUPPORTED ArpDevice, GetArpMap, and Notify are + not implemented by this driver. + +**/ +EFI_STATUS +EFIAPI +SmbusHcNotify ( + IN CONST EFI_SMBUS_HC_PROTOCOL *This, + IN EFI_SMBUS_DEVICE_ADDRESS SlaveAddress, + IN UINTN Data, + IN EFI_SMBUS_NOTIFY_FUNCTION NotifyFunction + ) +{ + // + // Not supported + // + return EFI_UNSUPPORTED; +} + +// +// Interface defintion of SMBUS Host Controller Protocol. +// +EFI_SMBUS_HC_PROTOCOL mSmbusHcProtocol =3D { + SmbusHcExecute, + SmbusHcArpDevice, + SmbusHcGetArpMap, + SmbusHcNotify +}; + +/** + SmbusHc driver entry point + + @param[in] ImageHandle ImageHandle of this module + @param[in] SystemTable EFI System Table + + @retval EFI_SUCCESS Driver initializes successfully + @retval Other values Some error occurred +**/ +EFI_STATUS +InitializeSmbus ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + // + // Install Smbus protocol + // + Status =3D gBS->InstallMultipleProtocolInterfaces ( + &mSmbusHcHandle, + &gEfiSmbusHcProtocolGuid, + &mSmbusHcProtocol, + NULL + ); + ASSERT_EFI_ERROR (Status); + + return Status; +} diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.c b/S= ilicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.c new file mode 100644 index 000000000000..39483a2a602a --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.c @@ -0,0 +1,263 @@ +/** @file + SmbusHc protocol implementation follows SMBus 2.0 specification. + + Copyright (c) 2024, Ampere Computing LLC. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include + +#include "SmbusHcCommon.h" + +/** + Executes an SMBus operation to an SMBus controller. Returns when either = the command has been + executed or an error is encountered in doing the operation. + + The Execute() function provides a standard way to execute an operation a= s defined in the System + Management Bus (SMBus) Specification. The resulting transaction will be = either that the SMBus + slave devices accept this transaction or that this function returns with= error. + + @param This A pointer to the EFI_PEI_SMBUS2_PPI inst= ance. + @param SlaveAddress The SMBus slave address of the device wi= th which to communicate. + @param Command This command is transmitted by the SMBus= host controller to the + SMBus slave device and the interpretatio= n is SMBus slave device + specific. It can mean the offset to a li= st of functions inside an + SMBus slave device. Not all operations o= r slave devices support + this command's registers. + @param Operation Signifies which particular SMBus hardwar= e protocol instance that + it will use to execute the SMBus transac= tions. This SMBus + hardware protocol is defined by the SMBu= s Specification and is + not related to EFI. + @param PecCheck Defines if Packet Error Code (PEC) check= ing is required for this + operation. + @param Length Signifies the number of bytes that this = operation will do. The + maximum number of bytes can be revision = specific and operation + specific. This field will contain the ac= tual number of bytes that + are executed for this operation. Not all= operations require this + argument. + @param Buffer Contains the value of data to execute to= the SMBus slave device. + Not all operations require this argument= . The length of this + buffer is identified by Length. + + @retval EFI_SUCCESS The last data that was returned from the= access matched the poll + exit criteria. + @retval EFI_CRC_ERROR Checksum is not correct (PEC is incorrec= t). + @retval EFI_TIMEOUT Timeout expired before the operation was= completed. Timeout is + determined by the SMBus host controller = device. + @retval EFI_OUT_OF_RESOURCES The request could not be completed due t= o a lack of resources. + @retval EFI_DEVICE_ERROR The request was not completed because a = failure that was + reflected in the Host Status Register bi= t. Device errors are a + result of a transaction collision, illeg= al command field, + unclaimed cycle (host initiated), or bus= errors (collisions). + @retval EFI_INVALID_PARAMETER Operation is not defined in EFI_SMBUS_OP= ERATION. + @retval EFI_INVALID_PARAMETER Length/Buffer is NULL for operations exc= ept for EfiSmbusQuickRead + and EfiSmbusQuickWrite. Length is outsid= e the range of valid + values. + @retval EFI_UNSUPPORTED The SMBus operation or PEC is not suppor= ted. + @retval EFI_BUFFER_TOO_SMALL Buffer is not sufficient for this operat= ion. + +**/ +EFI_STATUS +EFIAPI +SmbusHcExecute ( + IN CONST EFI_PEI_SMBUS2_PPI *This, + IN EFI_SMBUS_DEVICE_ADDRESS SlaveAddress, + IN EFI_SMBUS_DEVICE_COMMAND Command, + IN EFI_SMBUS_OPERATION Operation, + IN BOOLEAN PecCheck, + IN OUT UINTN *Length, + IN OUT VOID *Buffer + ) +{ + ASSERT (This !=3D NULL); + return SmbusHcCommonExecute (SlaveAddress, Command, Operation, PecCheck,= Length, Buffer); +} + +/** + + The SmbusHcArpDevice() function provides a standard way for a device dri= ver to + enumerate the entire SMBus or specific devices on the bus. + + @param This A pointer to the EFI_PEI_SMBUS2_PPI instance. + + @param ArpAll A Boolean expression that indicates if the + host drivers need to enumerate all the devices + or enumerate only the device that is + identified by SmbusUdid. If ArpAll is TRUE, + SmbusUdid and SlaveAddress are optional. If + ArpAll is FALSE, ArpDevice will enumerate + SmbusUdid and the address will be at + SlaveAddress. + + @param SmbusUdid The Unique Device Identifier (UDID) that is + associated with this device. Type + EFI_SMBUS_UDID is defined in + EFI_PEI_SMBUS_PPI.ArpDevice() in the + Platform Initialization SMBus PPI + Specification. + + @param SlaveAddress The SMBus slave address that is + associated with an SMBus UDID. + + @retval EFI_SUCCESS The last data that was returned from the + access matched the poll exit criteria. + + @retval EFI_CRC_ERROR Checksum is not correct (PEC is + incorrect). + + @retval EFI_TIMEOUT Timeout expired before the operation was + completed. Timeout is determined by the + SMBus host controller device. + + @retval EFI_OUT_OF_RESOURCES The request could not be + completed due to a lack of + resources. + + @retval EFI_DEVICE_ERROR The request was not completed + because a failure was reflected in + the Host Status Register bit. Device + Errors are a result of a transaction + collision, illegal command field, + unclaimed cycle (host initiated), or + bus errors (collisions). + + @retval EFI_UNSUPPORTED ArpDevice, GetArpMap, and Notify are + not implemented by this driver. + +**/ +EFI_STATUS +EFIAPI +SmbusHcArpDevice ( + IN CONST EFI_PEI_SMBUS2_PPI *This, + IN BOOLEAN ArpAll, + IN EFI_SMBUS_UDID *SmbusUdid, OPTIONAL + IN OUT EFI_SMBUS_DEVICE_ADDRESS *SlaveAddress OPTIONAL + ) +{ + // + // Not supported + // + return EFI_UNSUPPORTED; +} + +/** + The SmbusHcGetArpMap() function returns the mapping of all the SMBus dev= ices + that were enumerated by the SMBus host driver. + + @param This A pointer to the EFI_PEI_SMBUS2_PPI instance. + + @param Length Size of the buffer that contains the SMBus + device map. + + @param SmbusDeviceMap The pointer to the device map as + enumerated by the SMBus controller + driver. + + @retval EFI_SUCCESS The SMBus returned the current device map. + + @retval EFI_UNSUPPORTED ArpDevice, GetArpMap, and Notify are + not implemented by this driver. + +**/ +EFI_STATUS +EFIAPI +SmbusHcGetArpMap ( + IN CONST EFI_PEI_SMBUS2_PPI *This, + IN OUT UINTN *Length, + IN OUT EFI_SMBUS_DEVICE_MAP **SmbusDeviceMap + ) +{ + // + // Not supported + // + return EFI_UNSUPPORTED; +} + +/** + + The SmbusHcNotify() function registers all the callback functions to + allow the bus driver to call these functions when the + SlaveAddress/Data pair happens. + + @param This A pointer to the EFI_PEI_SMBUS2_PPI instance. + + @param SlaveAddress Address that the host controller detects + as sending a message and calls all the registere= d function. + + @param Data Data that the host controller detects as sending + message and calls all the registered function. + + + @param NotifyFunction The function to call when the bus + driver detects the SlaveAddress and + Data pair. + + @retval EFI_SUCCESS NotifyFunction was registered. + + @retval EFI_UNSUPPORTED ArpDevice, GetArpMap, and Notify are + not implemented by this driver. + +**/ +EFI_STATUS +EFIAPI +SmbusHcNotify ( + IN CONST EFI_PEI_SMBUS2_PPI *This, + IN EFI_SMBUS_DEVICE_ADDRESS SlaveAddress, + IN UINTN Data, + IN EFI_PEI_SMBUS_NOTIFY2_FUNCTION NotifyFunction + ) +{ + // + // Not supported + // + return EFI_UNSUPPORTED; +} + +// +// Interface defintion of SMBUS Host Controller Protocol. +// +EFI_PEI_SMBUS2_PPI mSmbusHcPpi =3D { + SmbusHcExecute, + SmbusHcArpDevice, + SmbusHcGetArpMap, + SmbusHcNotify +}; + +EFI_PEI_PPI_DESCRIPTOR gPpiSmbusHcPpiList =3D { + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gEfiPeiSmbus2PpiGuid, + &mSmbusHcPpi +}; + +/** + SmbusHc driver entry point + + @param[in] ImageHandle ImageHandle of this module + @param[in] PeiServices An indirect pointer to the PEI Services = Table + published by the PEI Foundation. + + @retval EFI_SUCCESS Driver initializes successfully + @retval Other values Some error occurred +**/ +EFI_STATUS +EFIAPI +InitializeSmbusPeim ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + EFI_STATUS Status; + + // + // Install Smbus Ppi + // + Status =3D PeiServicesInstallPpi (&gPpiSmbusHcPpiList); + ASSERT_EFI_ERROR (Status); + + return Status; +} --=20 2.25.1 -=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 (#120165): https://edk2.groups.io/g/devel/message/120165 Mute This Topic: https://groups.io/mt/107662237/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-