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 190B8AC1716 for ; Tue, 30 Apr 2024 14:06:12 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=9+u1BCYQFfp0zBZ0aHiF3KV9jUPrm+5BvkDkWyfnfsI=; c=relaxed/simple; d=groups.io; h=Received-SPF: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=1714485971; v=1; b=ipGUd52wZy9QQCN5EE6IdW9rCPrAg/7g03ZWdU7YDzkLtABg6Si+ofv0P2Mcbs+uTLN9SSO+ KhDRZDK58fjtQwuekd087M73SZL3EcWuAOI/H2p5RCyRyB1NlLcSDqJvFYOgYTHonFEgDBmXEIz r2njrgzwHV7jhnC6jcwTlzeYO9SZSUAEwOBIUiVGtqa8HXz+x0ZOBuxBn+kv5ZvIYAVIlZjotRA Q5DsX/nOIbwPlBAuCInLi/twfwC/fP/JIeSC5iSeDufUoqOknKu/9+YaIwlNThch9rLr+0MEV0B W54y1Omt/WG/Ee2+G/HowsUQRLHQ44QU7Y2z19iqZ0UqQ== X-Received: by 127.0.0.2 with SMTP id jtlAYY7687511xE1KnJCGJlh; Tue, 30 Apr 2024 07:06:11 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.88]) by mx.groups.io with SMTP id smtpd.web10.16513.1714485970906149224 for ; Tue, 30 Apr 2024 07:06:11 -0700 X-Received: from CH0PR04CA0030.namprd04.prod.outlook.com (2603:10b6:610:76::35) by DS7PR12MB9043.namprd12.prod.outlook.com (2603:10b6:8:db::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.35; Tue, 30 Apr 2024 14:05:59 +0000 X-Received: from CH2PEPF00000099.namprd02.prod.outlook.com (2603:10b6:610:76:cafe::2b) by CH0PR04CA0030.outlook.office365.com (2603:10b6:610:76::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.35 via Frontend Transport; Tue, 30 Apr 2024 14:05:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CH2PEPF00000099.mail.protection.outlook.com (10.167.244.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7544.18 via Frontend Transport; Tue, 30 Apr 2024 14:05:59 +0000 X-Received: from AUS-BIOSDEV-68.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 30 Apr 2024 09:05:57 -0500 From: "Chesley, Brit via groups.io" To: CC: Abner Chang , Abdul Lateef Attar Subject: [edk2-devel] [PATCH 4/5] MdeModulePkg: SpiHc: SpiHc Drivers Date: Tue, 30 Apr 2024 09:05:35 -0500 Message-ID: <20240430140536.4252-5-brit.chesley@amd.com> In-Reply-To: <20240430140536.4252-1-brit.chesley@amd.com> References: <20240430140536.4252-1-brit.chesley@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000099:EE_|DS7PR12MB9043:EE_ X-MS-Office365-Filtering-Correlation-Id: 6d61e59f-909f-4926-8409-08dc691ea962 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?mfJtkrP2suEHQuGnOat6UK+AtfBvkJVFhEl5AAs9qpMv+PkD7Ag9ceUxsrac?= =?us-ascii?Q?t9VGJSaWjn3ISZLGaj1ByZ8UeHnH0BIzCZT3TnN90lNaI/a7uPMkcd3dO502?= =?us-ascii?Q?i+HAHx7Da2/5Dh0t+o9wcw8Dgw1jqoiwDzXlig4rNFxt7PoCvPy1DknQfm/s?= =?us-ascii?Q?Z18d1PPEWg+iZc7geWdzrLivmkw1Au8m5HEA2XJH4nDR7uqZ7oRzBp4bhBJZ?= =?us-ascii?Q?rXqsVLbbQb1q8/cA744B3gu/ZkrOb7WwOCbB02sjS9PO2TXY2Bha9MZtZhP5?= =?us-ascii?Q?4aDeOYpLg2lsFjQA30iqD41HGpdzD3cpTrIWbGr5h+SMJe+WFSh5LrLH99ON?= =?us-ascii?Q?uEAYoojiYXtQwr4OYG4SPB+LmiEdSwIiZzbCqUE9fFsPRh4J1fUD7kFMyvtH?= =?us-ascii?Q?kEfBd45XPFqQHt0feRitnkOkrFL7OM1njVqewE/zHHK8Z3kgyaQSVkZD4Bca?= =?us-ascii?Q?XXCQ3NeYBRqsH2LUBG2QIOK3+nJYQ1qiYWNaUaSzgQW7XM6QlOhnpFv/7yIO?= =?us-ascii?Q?fk32hDYMFtPlT/WOUgjOu8XsZLIrads7+2aP1M+IQRvIg+IMW8kFt8qQ/O/P?= =?us-ascii?Q?izCcIYID2GPrm1CEk9ZgsiEIfonYIz4DmEHvtJN3G+k2crXgwmSPBziSbmkf?= =?us-ascii?Q?3HC+aupLnObhtJd705PxUTJkMk/BHhm2oOF4jBEjw5P0x9pgUPfwnVKFccCV?= =?us-ascii?Q?p5yTV5KRenGvy0fs3fn2LG6jpj2JDD665TAWT7A/sYb9ORa4cbf5NOlM3sGO?= =?us-ascii?Q?ReAiJ6XvYiUePI6A6KvHfzr/ZkGVVIfwX+jYISVX69L1mum7IxtHoh5xwesh?= =?us-ascii?Q?a2vFevVmXA52yBrHwo/kqE2dAW+vQZDKzM3S8aVZzuei7jqAvc8n6sUeiMwJ?= =?us-ascii?Q?tNVCSTeZ+CmmDvEPkolwYODrdBXDNjFmWCqY+4HByIy24c07s4ATQHW7QwUg?= =?us-ascii?Q?iJ1YlbzDMUlcYMXTn3OG//h6VPu+M4/Y8fbgUvVFdZ+gdvDZ5j0gBDiz5Tyc?= =?us-ascii?Q?1kn7ivcjo3MQJKKNnJSZM+kRuNAL5onx+AcIqAJ2vUkH7+X0Rf1LxcmLve9Q?= =?us-ascii?Q?pPWVXSO88WCa8UOlg/hOd6CF5v7BWNcyCBHdVQImj6KS6AW54qMJl6ZyE932?= =?us-ascii?Q?7n0J5+dAA7UjMFRyA40/Ar1QQxuPTTiTC/pyAqiLDSr6/cI2NGGHMy5Bf9tJ?= =?us-ascii?Q?uW/vH1Vj1//F+QpKL7pP9lclJmACLLC4rp5d183s8uxpFcWw/HL8zJozdQRd?= =?us-ascii?Q?U1kJX1mS9Mkk3dadT1k3QCXLrXcjVgg5vGxN0SvL4t7ecFEE+ZLnHEFmSlYy?= =?us-ascii?Q?B79yvoHIf77B/kSzoauLLjwM/r/RIcoWN3PCxQKqRk7ksSDfQw0yIBQSvB0t?= =?us-ascii?Q?B21iHtM=3D?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2024 14:05:59.0571 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6d61e59f-909f-4926-8409-08dc691ea962 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF00000099.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB9043 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: Tue, 30 Apr 2024 07:06:11 -0700 Resent-From: brit.chesley@amd.com Reply-To: devel@edk2.groups.io,brit.chesley@amd.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: mOlQD74jCpGIzc8O35iGRoTZx7686176AA= 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=ipGUd52w; 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 From: Brit Chesley Added SpiHc DXE and SMM drivers. This code receives bus transactions from the SpiBus layer and passes them onto the SpiHcPlatformLib Platform Initialization Spec 1.7 volume 5 section 18.1.7 Bugzilla #4753 Cc: Abner Chang Cc: Abdul Lateef Attar Signed-off-by: Brit Chesley --- MdeModulePkg/Bus/Spi/SpiHc/SpiHcDxe.inf | 46 ++++++++++ MdeModulePkg/Bus/Spi/SpiHc/SpiHcSmm.inf | 44 +++++++++ MdeModulePkg/Bus/Spi/SpiHc/SpiHc.h | 111 +++++++++++++++++++++++ MdeModulePkg/Bus/Spi/SpiHc/SpiHc.c | 115 ++++++++++++++++++++++++ MdeModulePkg/Bus/Spi/SpiHc/SpiHcDxe.c | 101 +++++++++++++++++++++ MdeModulePkg/Bus/Spi/SpiHc/SpiHcSmm.c | 79 ++++++++++++++++ MdeModulePkg/Bus/Spi/SpiHc/SpiHc.uni | 10 +++ 7 files changed, 506 insertions(+) create mode 100644 MdeModulePkg/Bus/Spi/SpiHc/SpiHcDxe.inf create mode 100644 MdeModulePkg/Bus/Spi/SpiHc/SpiHcSmm.inf create mode 100644 MdeModulePkg/Bus/Spi/SpiHc/SpiHc.h create mode 100644 MdeModulePkg/Bus/Spi/SpiHc/SpiHc.c create mode 100644 MdeModulePkg/Bus/Spi/SpiHc/SpiHcDxe.c create mode 100644 MdeModulePkg/Bus/Spi/SpiHc/SpiHcSmm.c create mode 100644 MdeModulePkg/Bus/Spi/SpiHc/SpiHc.uni diff --git a/MdeModulePkg/Bus/Spi/SpiHc/SpiHcDxe.inf b/MdeModulePkg/Bus/Spi= /SpiHc/SpiHcDxe.inf new file mode 100644 index 000000000000..49fa7d831fce --- /dev/null +++ b/MdeModulePkg/Bus/Spi/SpiHc/SpiHcDxe.inf @@ -0,0 +1,46 @@ +#/** @file +# +# Component description file for SPI Host Controller Module +# +# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#**/ +[Defines] + INF_VERSION =3D 1.27 + BASE_NAME =3D SpiHcDxe + FILE_GUID =3D 95D148FF-5A23-43B9-9FC4-80AE0DD48D32 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 0.1 + PI_SPECIFICATION_VERSION =3D 0x0001000A + ENTRY_POINT =3D SpiHcProtocolEntry + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + DevicePathLib + MemoryAllocationLib + SpiHcPlatformLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiLib + UefiRuntimeServicesTableLib + +[Sources] + SpiHc.h + SpiHc.c + SpiHcDxe.c + +[Protocols] + gEfiSpiHcProtocolGuid + +[Depex] + TRUE + +[UserExtensions.TianoCore."ExtraFiles"] + SpiHc.uni diff --git a/MdeModulePkg/Bus/Spi/SpiHc/SpiHcSmm.inf b/MdeModulePkg/Bus/Spi= /SpiHc/SpiHcSmm.inf new file mode 100644 index 000000000000..deef4d7cf3fa --- /dev/null +++ b/MdeModulePkg/Bus/Spi/SpiHc/SpiHcSmm.inf @@ -0,0 +1,44 @@ +#/** @file +# +# Component description file for SPI Host Controller Module +# +# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#**/ +[Defines] + INF_VERSION =3D 1.27 + BASE_NAME =3D SpiHcSmm + FILE_GUID =3D 0CDAE298-CB3B-480A-BDC4-A6840FFE1F5E + MODULE_TYPE =3D DXE_SMM_DRIVER + VERSION_STRING =3D 0.1 + PI_SPECIFICATION_VERSION =3D 0x0001000A + ENTRY_POINT =3D SpiHcProtocolEntry + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + MmServicesTableLib + SpiHcPlatformLib + UefiDriverEntryPoint + UefiLib + +[Sources] + SpiHc.h + SpiHc.c + SpiHcSmm.c + +[Protocols] + gEfiSpiSmmHcProtocolGuid + +[Depex] + TRUE + +[UserExtensions.TianoCore."ExtraFiles"] + SpiHc.uni diff --git a/MdeModulePkg/Bus/Spi/SpiHc/SpiHc.h b/MdeModulePkg/Bus/Spi/SpiH= c/SpiHc.h new file mode 100644 index 000000000000..80448c5c536a --- /dev/null +++ b/MdeModulePkg/Bus/Spi/SpiHc/SpiHc.h @@ -0,0 +1,111 @@ +/** @file + + SPI Host Controller function declarations + + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include +#include +#include +#include +#include +#include +#include + +/** + Assert or deassert the SPI chip select. + + This routine is called at TPL_NOTIFY. + Update the value of the chip select line for a SPI peripheral. The SPI b= us + layer calls this routine either in the board layer or in the SPI control= ler + to manipulate the chip select pin at the start and end of a SPI transact= ion. + + @param[in] This Pointer to an EFI_SPI_HC_PROTOCOL structure. + @param[in] SpiPeripheral The address of an EFI_SPI_PERIPHERAL data stru= cture + describing the SPI peripheral whose chip selec= t pin + is to be manipulated. The routine may access t= he + ChipSelectParameter field to gain sufficient + context to complete the operati on. + @param[in] PinValue The value to be applied to the chip select lin= e of + the SPI peripheral. + + @retval EFI_SUCCESS The chip select was set as requested + @retval EFI_NOT_READY Support for the chip select is not proper= ly + initialized + @retval EFI_INVALID_PARAMETER The ChipSeLect value or its contents are + invalid + +**/ +EFI_STATUS +EFIAPI +ChipSelect ( + IN CONST EFI_SPI_HC_PROTOCOL *This, + IN CONST EFI_SPI_PERIPHERAL *SpiPeripheral, + IN BOOLEAN PinValue + ); + +/** + Set up the clock generator to produce the correct clock frequency, phase= and + polarity for a SPI chip. + + This routine is called at TPL_NOTIFY. + This routine updates the clock generator to generate the correct frequen= cy + and polarity for the SPI clock. + + @param[in] This Pointer to an EFI_SPI_HC_PROTOCOL structure. + @param[in] SpiPeripheral Pointer to a EFI_SPI_PERIPHERAL data structure= from + which the routine can access the ClockParamete= r, + ClockPhase and ClockPolarity fields. The routi= ne + also has access to the names for the SPI bus a= nd + chip which can be used during debugging. + @param[in] ClockHz Pointer to the requested clock frequency. The = SPI + host controller will choose a supported clock + frequency which is less then or equal to this + value. Specify zero to turn the clock generato= r + off. The actual clock frequency supported by t= he + SPI host controller will be returned. + + @retval EFI_SUCCESS The clock was set up successfully + @retval EFI_UNSUPPORTED The SPI controller was not able to support the + frequency requested by ClockHz + +**/ +EFI_STATUS +EFIAPI +Clock ( + IN CONST EFI_SPI_HC_PROTOCOL *This, + IN CONST EFI_SPI_PERIPHERAL *SpiPeripheral, + IN UINT32 *ClockHz + ); + +/** + Perform the SPI transaction on the SPI peripheral using the SPI host + controller. + + This routine is called at TPL_NOTIFY. + This routine synchronously returns EFI_SUCCESS indicating that the + asynchronous SPI transaction was started. The routine then waits for + completion of the SPI transaction prior to returning the final transacti= on + status. + + @param[in] This Pointer to an EFI_SPI_HC_PROTOCOL structure. + @param[in] BusTransaction Pointer to a EFI_SPI_BUS_ TRANSACTION contain= ing + the description of the SPI transaction to per= form. + + @retval EFI_SUCCESS The transaction completed successfully + @retval EFI_BAD_BUFFER_SIZE The BusTransaction->WriteBytes value is inva= lid, + or the BusTransaction->ReadinBytes value is + invalid + @retval EFI_UNSUPPORTED The BusTransaction-> Transaction Type is + unsupported + @retval EFI_DEVICE_ERROR SPI Host Controller failed transaction + +**/ +EFI_STATUS +EFIAPI +Transaction ( + IN CONST EFI_SPI_HC_PROTOCOL *This, + IN EFI_SPI_BUS_TRANSACTION *BusTransaction + ); diff --git a/MdeModulePkg/Bus/Spi/SpiHc/SpiHc.c b/MdeModulePkg/Bus/Spi/SpiH= c/SpiHc.c new file mode 100644 index 000000000000..9d7bf9f542ef --- /dev/null +++ b/MdeModulePkg/Bus/Spi/SpiHc/SpiHc.c @@ -0,0 +1,115 @@ +/** @file + + SPI Host Controller shell implementation, as host controller code is pla= tform + specfic. + + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include "SpiHc.h" + +/** + Assert or deassert the SPI chip select. + + This routine is called at TPL_NOTIFY. + Update the value of the chip select line for a SPI peripheral. The SPI b= us + layer calls this routine either in the board layer or in the SPI control= ler + to manipulate the chip select pin at the start and end of a SPI transact= ion. + + @param[in] This Pointer to an EFI_SPI_HC_PROTOCOL structure. + @param[in] SpiPeripheral The address of an EFI_SPI_PERIPHERAL data stru= cture + describing the SPI peripheral whose chip selec= t pin + is to be manipulated. The routine may access t= he + ChipSelectParameter field to gain sufficient + context to complete the operati on. + @param[in] PinValue The value to be applied to the chip select lin= e of + the SPI peripheral. + + @retval EFI_SUCCESS The chip select was set as requested + @retval EFI_NOT_READY Support for the chip select is not proper= ly + initialized + @retval EFI_INVALID_PARAMETER The ChipSeLect value or its contents are + invalid + +**/ +EFI_STATUS +EFIAPI +ChipSelect ( + IN CONST EFI_SPI_HC_PROTOCOL *This, + IN CONST EFI_SPI_PERIPHERAL *SpiPeripheral, + IN BOOLEAN PinValue + ) +{ + return PlatformSpiHcChipSelect (This, SpiPeripheral, PinValue); +} + +/** + Set up the clock generator to produce the correct clock frequency, phase= and + polarity for a SPI chip. + + This routine is called at TPL_NOTIFY. + This routine updates the clock generator to generate the correct frequen= cy + and polarity for the SPI clock. + + @param[in] This Pointer to an EFI_SPI_HC_PROTOCOL structure. + @param[in] SpiPeripheral Pointer to a EFI_SPI_PERIPHERAL data structure= from + which the routine can access the ClockParamete= r, + ClockPhase and ClockPolarity fields. The routi= ne + also has access to the names for the SPI bus a= nd + chip which can be used during debugging. + @param[in] ClockHz Pointer to the requested clock frequency. The = SPI + host controller will choose a supported clock + frequency which is less then or equal to this + value. Specify zero to turn the clock generato= r + off. The actual clock frequency supported by t= he + SPI host controller will be returned. + + @retval EFI_SUCCESS The clock was set up successfully + @retval EFI_UNSUPPORTED The SPI controller was not able to support the + frequency requested by ClockHz + +**/ +EFI_STATUS +EFIAPI +Clock ( + IN CONST EFI_SPI_HC_PROTOCOL *This, + IN CONST EFI_SPI_PERIPHERAL *SpiPeripheral, + IN UINT32 *ClockHz + ) +{ + return PlatformSpiHcClock (This, SpiPeripheral, ClockHz); +} + +/** + Perform the SPI transaction on the SPI peripheral using the SPI host + controller. + + This routine is called at TPL_NOTIFY. + This routine synchronously returns EFI_SUCCESS indicating that the + asynchronous SPI transaction was started. The routine then waits for + completion of the SPI transaction prior to returning the final transacti= on + status. + + @param[in] This Pointer to an EFI_SPI_HC_PROTOCOL structure. + @param[in] BusTransaction Pointer to a EFI_SPI_BUS_ TRANSACTION contain= ing + the description of the SPI transaction to per= form. + + @retval EFI_SUCCESS The transaction completed successfully + @retval EFI_BAD_BUFFER_SIZE The BusTransaction->WriteBytes value is inva= lid, + or the BusTransaction->ReadinBytes value is + invalid + @retval EFI_UNSUPPORTED The BusTransaction-> Transaction Type is + unsupported + @retval EFI_DEVICE_ERROR SPI Host Controller failed transaction + +**/ +EFI_STATUS +EFIAPI +Transaction ( + IN CONST EFI_SPI_HC_PROTOCOL *This, + IN EFI_SPI_BUS_TRANSACTION *BusTransaction + ) +{ + return PlatformSpiHcTransaction (This, BusTransaction); +} diff --git a/MdeModulePkg/Bus/Spi/SpiHc/SpiHcDxe.c b/MdeModulePkg/Bus/Spi/S= piHc/SpiHcDxe.c new file mode 100644 index 000000000000..d0e9827eb67c --- /dev/null +++ b/MdeModulePkg/Bus/Spi/SpiHc/SpiHcDxe.c @@ -0,0 +1,101 @@ +/** @file + + SPI Host controller entry point for DXE + + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SpiHc.h" + +EFI_HANDLE mSpiHcHandle =3D 0; + +/** + Entry point of the SPI Host Controller driver. Installs the EFI_SPI_HC_P= ROTOCOL on mSpiHcHandle. + Also installs the EFI_DEVICE_PATH_PROTOCOL corresponding to the SPI Host= controller on the same + mSpiHcHandle. + + @param[in] ImageHandle Image handle of this driver. + @param[in] SystemTable Pointer to standard EFI system table. + + @retval EFI_SUCCESS Succeed. + @retval EFI_OUT_RESOURCES If the system has run out of memory +**/ +EFI_STATUS +EFIAPI +SpiHcProtocolEntry ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_SPI_HC_PROTOCOL *HcProtocol; + EFI_DEVICE_PATH_PROTOCOL *HcDevicePath; + + DEBUG ((DEBUG_VERBOSE, "%a - ENTRY\n", __func__)); + + // Allocate the SPI Host Controller protocol + HcProtocol =3D AllocateZeroPool (sizeof (EFI_SPI_HC_PROTOCOL)); + ASSERT (HcProtocol !=3D NULL); + if (HcProtocol =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // Fill in the SPI Host Controller Protocol + Status =3D GetPlatformSpiHcDetails ( + &HcProtocol->Attributes, + &HcProtocol->FrameSizeSupportMask, + &HcProtocol->MaximumTransferBytes + ); + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "Error, no Platform SPI HC details\n")); + return Status; + } + + HcProtocol->ChipSelect =3D ChipSelect; + HcProtocol->Clock =3D Clock; + HcProtocol->Transaction =3D Transaction; + + // Install Host Controller protocol + Status =3D gBS->InstallProtocolInterface ( + &mSpiHcHandle, + &gEfiSpiHcProtocolGuid, + EFI_NATIVE_INTERFACE, + HcProtocol + ); + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "Error installing gEfiSpiHcProtocolGuid\n")); + return Status; + } + + Status =3D GetSpiHcDevicePath (&HcDevicePath); + + // Install HC device path here on this handle as well + Status =3D gBS->InstallProtocolInterface ( + &mSpiHcHandle, + &gEfiDevicePathProtocolGuid, + EFI_NATIVE_INTERFACE, + HcDevicePath + ); + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "Error installing gEfiDevicePathProtocolGuid\n"= )); + } + + DEBUG ((DEBUG_VERBOSE, "%a - EXIT Status=3D%r\n", __func__, Status)); + + return Status; +} diff --git a/MdeModulePkg/Bus/Spi/SpiHc/SpiHcSmm.c b/MdeModulePkg/Bus/Spi/S= piHc/SpiHcSmm.c new file mode 100644 index 000000000000..adebff97631a --- /dev/null +++ b/MdeModulePkg/Bus/Spi/SpiHc/SpiHcSmm.c @@ -0,0 +1,79 @@ +/** @file + + SPI Host controller entry point for SMM + + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SpiHc.h" + +EFI_HANDLE mSpiHcHandle =3D 0; + +/** + Entry point of the SPI Host Controller driver. Installs the EFI_SPI_HC_P= ROTOCOL on mSpiHcHandle. + Also installs the EFI_DEVICE_PATH_PROTOCOL corresponding to the SPI Host= controller on the same + mSpiHcHandle. + + @param[in] ImageHandle Image handle of this driver. + @param[in] SystemTable Pointer to standard EFI system table. + + @retval EFI_SUCCESS Succeed. + @retval EFI_OUT_RESOURCES If the system has run out of memory +**/ +EFI_STATUS +EFIAPI +SpiHcProtocolEntry ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_SPI_HC_PROTOCOL *HcProtocol; + + DEBUG ((DEBUG_VERBOSE, "%a - ENTRY\n", __func__)); + + // Allocate the SPI Host Controller protocol + HcProtocol =3D AllocateZeroPool (sizeof (EFI_SPI_HC_PROTOCOL)); + ASSERT (HcProtocol !=3D NULL); + if (HcProtocol =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // Fill in the SPI Host Controller Protocol + Status =3D GetPlatformSpiHcDetails ( + &HcProtocol->Attributes, + &HcProtocol->FrameSizeSupportMask, + &HcProtocol->MaximumTransferBytes + ); + + HcProtocol->ChipSelect =3D ChipSelect; + HcProtocol->Clock =3D Clock; + HcProtocol->Transaction =3D Transaction; + + Status =3D gMmst->MmInstallProtocolInterface ( + &mSpiHcHandle, + &gEfiSpiSmmHcProtocolGuid, + EFI_NATIVE_INTERFACE, + HcProtocol + ); + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "Error installing gEfiSpiSmmHcProtocolGuid\n"))= ; + } + + DEBUG ((DEBUG_VERBOSE, "%a - EXIT Status=3D%r\n", __func__, Status)); + + return Status; +} diff --git a/MdeModulePkg/Bus/Spi/SpiHc/SpiHc.uni b/MdeModulePkg/Bus/Spi/Sp= iHc/SpiHc.uni new file mode 100644 index 000000000000..9fab0a7433c5 --- /dev/null +++ b/MdeModulePkg/Bus/Spi/SpiHc/SpiHc.uni @@ -0,0 +1,10 @@ +// /** @file +// +// Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved. +// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +#string STR_PROPERTIES_MODULE_NAME +#language en-US "SPI host controller driver" --=20 2.42.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 (#118443): https://edk2.groups.io/g/devel/message/118443 Mute This Topic: https://groups.io/mt/105821494/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-