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 7682974003E for ; Wed, 1 May 2024 19:05:55 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=lEi7FO6kF2/Oi9cqLIScAWZlN3oArs8vu6WnIXUUwW0=; 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=1714590354; v=1; b=lO48l1PoBKvStTxNKFWyTMUBx1mFV3GZ2tbX5cEq3BqfHiEkA6Eh5O/6dYd8Dzu+cyzyH4Xi au/yZeLS8f87U1eGl0R9koZkzzcZE/up6yi35uJb3FfvRpkfcnDYs0881Z+EXjkAXQTnYR5MCZ1 ng+XXoSRJoG5/P202iTwfh2xk4Cna/H/BcFUTV+Cwsi2756pSWRTDm2vaywPVZOBNgw+Fes9s/+ rU1chpiURnVOO/j/i0YP7FR7BSdTz83LgnUWJ7SH/wleH1i7epGxpKY8i1WKNHKuF4y+OxDGSJM vM4Sv8b0MEaSPQ+Zyjp8VilleDBUlnWzi/JeT7VIidnyw== X-Received: by 127.0.0.2 with SMTP id szKSYY7687511xuSwuv1w1xc; Wed, 01 May 2024 12:05:54 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.45]) by mx.groups.io with SMTP id smtpd.web10.5170.1714590352813725592 for ; Wed, 01 May 2024 12:05:53 -0700 X-Received: from SJ0PR05CA0117.namprd05.prod.outlook.com (2603:10b6:a03:334::32) by MN2PR12MB4423.namprd12.prod.outlook.com (2603:10b6:208:24f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.36; Wed, 1 May 2024 19:05:48 +0000 X-Received: from SJ5PEPF000001CD.namprd05.prod.outlook.com (2603:10b6:a03:334:cafe::f7) by SJ0PR05CA0117.outlook.office365.com (2603:10b6:a03:334::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.23 via Frontend Transport; Wed, 1 May 2024 19:05:47 +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 SJ5PEPF000001CD.mail.protection.outlook.com (10.167.242.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7544.18 via Frontend Transport; Wed, 1 May 2024 19:05:47 +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; Wed, 1 May 2024 14:05:44 -0500 From: "Chesley, Brit via groups.io" To: CC: Abner Chang , Abdul Lateef Attar Subject: [edk2-devel] [PATCH v1 5/6] MdeModulePkg: SpiHc: SpiHc Drivers Date: Wed, 1 May 2024 14:05:26 -0500 Message-ID: <20240501190527.200937-6-brit.chesley@amd.com> In-Reply-To: <20240501190527.200937-1-brit.chesley@amd.com> References: <20240501190527.200937-1-brit.chesley@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF000001CD:EE_|MN2PR12MB4423:EE_ X-MS-Office365-Filtering-Correlation-Id: 1bb55043-1c76-4c88-3ae0-08dc6a11b5d9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?YEkWaZg/gs6z5M3I+1yyec1Mb2IHFOg5oJwk9VIlY8c9wLgQBPQCXle3v9mc?= =?us-ascii?Q?bG6qcmckMp/910pt7Hm4J6wgwQukIm1smYIDe3P5a2fME9dATksJBGcRuY4/?= =?us-ascii?Q?ktrep8EtzZd+WrN2AaJGqKzM0tui54YRAN2CAgMqC+6JuaBI2hcvKzW/JLd0?= =?us-ascii?Q?QmZx3j+IfWHVAR/eI7zg55S/VEbmqIZDmTsM1z3OMSshbX1uB5rkLofFixrP?= =?us-ascii?Q?SDqT8OatGvqsgi06mSbTa/CaKvj5rXkSBEmn+PO8Fw7Vzvw8e0pg3d0ObBsF?= =?us-ascii?Q?9nKuZ5uz0Wx+TncRhwo8aTmrHKjzW/T3p9KVwKvFt4qSzcq2Vlm0Cot6eRuI?= =?us-ascii?Q?LolypOkpXugJ50rQz1TEl3t5MnE0YXjkEEz7wWsoCjjnbrjAfMy6yJ7YUdwP?= =?us-ascii?Q?mD+liIiI3Wz19SrchREjwsca2vr9lX7x9G+R8Pex0AkOV7hLRAhyMQri2Ktf?= =?us-ascii?Q?KFe1e7ubJVVaiDGgxaByjsbDIsEznw/b1i6+rsjQyvlA4Rf32MhNd3tKhh73?= =?us-ascii?Q?zMxA4JcIszm4p32N0mFv7UVzlh/K0E0QWk248i2g8f694bRF5c+AYE/7f94d?= =?us-ascii?Q?+B69AfaTJsd4CuDqfv078SG4G+pl2R5+Tmo8AhlDy/zPVDnvOu7DLxY2WYE6?= =?us-ascii?Q?3H70X2L2XMp9PlMHhGslngbldNplMS0cWKxcABE/UTzaI269m5oKfpjeuI1l?= =?us-ascii?Q?iAxVsy3VpLNU08qyu/m3Eps1l+R+/Y1v23GLrVq0TYAF7n0hWFHxcwDwQzRN?= =?us-ascii?Q?nr7eDkUIsLdPKyq8iJWI86kYIc95itd6JQgtjCCTtoychX9MUn+fgEgI4AOX?= =?us-ascii?Q?VVQ0GZ+IX4VfLM56FVUHd2SmrAC1lRFWoJEF7zmxo+hDbOS6N8R5C/1gzqHx?= =?us-ascii?Q?+bNFL8W2QufZWdz74eKNiJb3ntd3PRma2WBGMsqBoy2WJ0AoA+Mm6LbKwVu7?= =?us-ascii?Q?ElXgLrseVTlfLoYY765lnBpOgmRugGOdbdIT6ggs971ssVJzyM3mZHle6XCU?= =?us-ascii?Q?C/rfIrL+Jq8Nr4uN3zSw5ba5UHSqu8SE0nn1I5Gv7kie8w36GB7WN2QmQsuM?= =?us-ascii?Q?zakXngE2yvobhF2547VCScgEVSDMlSF8svgKjI37V5O3bFQPMT0Bc4BmPsKR?= =?us-ascii?Q?Y2JBZuq3lQ/8IbJbeKNDsDP1ofTPx1ojm/jLI1Z04bqNJBTuhxSrJLGbatq8?= =?us-ascii?Q?P4eKgEHdbS51NWTt7dQtajI7qMcegLOryrkV5qa+rTrgmY3pq7UyRmKzNyVL?= =?us-ascii?Q?hg5RLVNfdCXHFe0uvipR41gCl1u0NdwKLCnr9lAcXbVWZXfPQxw2ATM7WuVL?= =?us-ascii?Q?VDdr25vlX318v94kvltBBcZzsZ+degHULUbdcnTcCie6/D6fnPeeiA3jsYBF?= =?us-ascii?Q?OJ6UYv4=3D?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2024 19:05:47.6418 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1bb55043-1c76-4c88-3ae0-08dc6a11b5d9 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: SJ5PEPF000001CD.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4423 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: Wed, 01 May 2024 12:05:53 -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: 2r9DIaUTDhDLtWPYR8Ah7YBYx7686176AA= 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=lO48l1Po; 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 | 47 ++++++++++ MdeModulePkg/Bus/Spi/SpiHc/SpiHcSmm.inf | 45 +++++++++ MdeModulePkg/Bus/Spi/SpiHc/SpiHc.h | 117 ++++++++++++++++++++++++ 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, 514 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..b71f1535cd46 --- /dev/null +++ b/MdeModulePkg/Bus/Spi/SpiHc/SpiHcDxe.inf @@ -0,0 +1,47 @@ +## @file +# The SPI Host Controller Module DXE driver INF file +# +# 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..95d5466d904b --- /dev/null +++ b/MdeModulePkg/Bus/Spi/SpiHc/SpiHcSmm.inf @@ -0,0 +1,45 @@ +## @file +# The SPI Host Controller Module SMM driver INF file +# +# 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..c6e4c5893d53 --- /dev/null +++ b/MdeModulePkg/Bus/Spi/SpiHc/SpiHc.h @@ -0,0 +1,117 @@ +/** @file + + SPI Host Controller function declarations + + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef SPI_HC_H_ +#define SPI_HC_H_ + +#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 + ); + +#endif //SPI_HC_H_ 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 (#118479): https://edk2.groups.io/g/devel/message/118479 Mute This Topic: https://groups.io/mt/105849138/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-