From nobody Mon Dec 23 05:20:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1519149001280393.5832178454841; Tue, 20 Feb 2018 09:50:01 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 691E421CF1D02; Tue, 20 Feb 2018 09:44:01 -0800 (PST) Received: from mail-wr0-x235.google.com (mail-wr0-x235.google.com [IPv6:2a00:1450:400c:c0c::235]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 1F74720954CBD for ; Tue, 20 Feb 2018 09:44:00 -0800 (PST) Received: by mail-wr0-x235.google.com with SMTP id z12so10668747wrg.4 for ; Tue, 20 Feb 2018 09:49:58 -0800 (PST) Received: from localhost.localdomain ([105.149.187.179]) by smtp.gmail.com with ESMTPSA id u63sm18282208wrc.26.2018.02.20.09.49.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 09:49:55 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::235; helo=mail-wr0-x235.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YJm5gg2aHMaqQhWHlhGdY72O/GkwU9RINUTIaF1vlAA=; b=fgRMlN7crsbbt3G+zsiEu9gkTOMvBVC1AHqh5dnAHrwV2jwXB0Rmj6Dg2wXjGGmjDo 0nM4Cjpd1/9n/yH47xcyQUYEY45Av2gJGEIYg/U0qew6+ipbzW91ktIOr4LsatS0kQvw mNf5at0+mf8Yn+zkUEF9Wgqy8hsm/k6NDAkEs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YJm5gg2aHMaqQhWHlhGdY72O/GkwU9RINUTIaF1vlAA=; b=YGGdsbGcjxENZn6jKpmvgTbs7tkh40d1yOoE4cb7NvTUsqI41zZi/SdqzOk0LWoM+a kdUVAzznZqv8Am403hdDEbJyHc5EToAT8rr8qnhVF7vc7CjLoUQWHt1dORZVteJK4SCb ULi192B9ClcBbxbt4ao5QM6E77/lgGBccKo2NOdFPhE55fqVRh5JNSxuGVtDPDXWoY8c faremNDOBgzvcKpWtdqIOoo45pnb2oY6s+Iod6UWNEdxF/TRihV5kjy1M+pdA9pEp3jJ DxxgsJz5JkSkybSxHXrS+UfdIXGKwDkmEcf2iNJlc14mtXfRU5N7aZattAdDxAoihwi7 uBLg== X-Gm-Message-State: APf1xPAAl5Z95wfJiQ9GCMGSYDg4tFgDRF0aZtOA+GRl4l7lzM0aUGSg tTKsVSSGdJu6/ryMP52W4/QQ4nGXVHk= X-Google-Smtp-Source: AH8x227EtgNAFj4GRW7eL1q85MXrqLOSv3xYzjEw41ACN65JhSm/wvQTU6Vu2IEpOTYjwIofVxsZUg== X-Received: by 10.223.195.97 with SMTP id e30mr400755wrg.181.1519148996514; Tue, 20 Feb 2018 09:49:56 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Tue, 20 Feb 2018 17:49:38 +0000 Message-Id: <20180220174944.525-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180220174944.525-1-ard.biesheuvel@linaro.org> References: <20180220174944.525-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH edk2-platforms v2 1/7] Silicon/Atmel: add support for AtSha204a RNG X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: leif.lindholm@linaro.org, Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This adds support for using the random number generator in the Atmel AtSha204a over I2C. Other functionality of the chip is currently unsupported. Note that the the I2C support in this device essentially violates the protocol layering, by requiring that the device is woken up by driving SDA low for a certain amount of time, which is something that cannot be expressed in terms of an I2C packet sent to the device's slave address. Instead, the slave address 0x0 is added to the device's address array, and the wake is sent by sending a dummy write to address 0x0, and ignoring the subsequent error. This requires the I2C bus to be clocked at 100 kHz. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm --- Silicon/Atmel/AtSha204a/AtSha204a.dec | 22 ++ Silicon/Atmel/AtSha204a/AtSha204aDriver.c | 309 ++++++++++++++++++++ Silicon/Atmel/AtSha204a/AtSha204aDriver.h | 81 +++++ Silicon/Atmel/AtSha204a/AtSha204aDxe.inf | 52 ++++ Silicon/Atmel/AtSha204a/ComponentName.c | 186 ++++++++++++ Silicon/Atmel/AtSha204a/DriverBinding.c | 242 +++++++++++++++ 6 files changed, 892 insertions(+) diff --git a/Silicon/Atmel/AtSha204a/AtSha204a.dec b/Silicon/Atmel/AtSha204= a/AtSha204a.dec new file mode 100644 index 000000000000..f1fdea59843d --- /dev/null +++ b/Silicon/Atmel/AtSha204a/AtSha204a.dec @@ -0,0 +1,22 @@ +## @file +# +# Copyright (c) 2018, Linaro Ltd. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD License +# which accompanies this distribution. The full text of the license may = be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IM= PLIED. +# +## + +[Defines] + DEC_SPECIFICATION =3D 0x0001001A + PACKAGE_NAME =3D AtSha204a + PACKAGE_GUID =3D 86085a5b-355b-4e72-92ab-fc3e1d71c9ad + PACKAGE_VERSION =3D 0.1 + +[Guids] + gAtSha204aI2cDeviceGuid =3D { 0x52e9b64b, 0x4ec1, 0x4bd6, { 0x9e, 0x1c, = 0x6d, 0xac, 0xef, 0x35, 0x18, 0x21 } } diff --git a/Silicon/Atmel/AtSha204a/AtSha204aDriver.c b/Silicon/Atmel/AtSh= a204a/AtSha204aDriver.c new file mode 100644 index 000000000000..5db2de21a731 --- /dev/null +++ b/Silicon/Atmel/AtSha204a/AtSha204aDriver.c @@ -0,0 +1,309 @@ +/** @file + Device driver for the Atmel ATSHA204A random number generator. + + Copyright (c) 2018, Linaro Ltd. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD + License which accompanies this distribution. The full text of the licens= e may + be found at http://opensource.org/licenses/bsd-license.php. + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#include "AtSha204aDriver.h" + +#include +#include +#include + +#define MAX_RETRIES 5 + +// Don't bother calculating the CRC for the immutable RANDOM opcode packet +#define OPCODE_COMMAND_PACKET_CRC 0xcd24 + +/** + Returns information about the random number generation implementation. + + @param[in] This A pointer to the EFI_RNG_PROTOCOL inst= ance. + @param[in,out] AlgorithmListSize On input, the size in bytes of Algorit= hmList + On output with a return code of EFI_SU= CCESS, + the size in bytes of the data returned= in + AlgorithmList. On output with a return + code of EFI_BUFFER_TOO_SMALL, the size= of + AlgorithmList required to obtain the l= ist. + @param[out] AlgorithmList A caller-allocated memory buffer fille= d by + the driver with one EFI_RNG_ALGORITHM + element for each supported RNG algorit= hm. + The list must not change across multip= le + calls to the same driver. The first + algorithm in the list is the default + algorithm for the driver. + + @retval EFI_SUCCESS The RNG algorithm list was returned + successfully. + @retval EFI_UNSUPPORTED The services is not supported by this = driver + @retval EFI_DEVICE_ERROR The list of algorithms could not be + retrieved due to a hardware or firmware + error. + @retval EFI_INVALID_PARAMETER One or more of the parameters are inco= rrect. + @retval EFI_BUFFER_TOO_SMALL The buffer RNGAlgorithmList is too sma= ll to + hold the result. + +**/ +STATIC +EFI_STATUS +EFIAPI +AtSha240aGetInfo ( + IN EFI_RNG_PROTOCOL *This, + IN OUT UINTN *AlgorithmListSize, + OUT EFI_RNG_ALGORITHM *AlgorithmList +) +{ + UINTN Size; + + // + // We only implement the raw algorithm + // + Size =3D sizeof (EFI_GUID); + + if (*AlgorithmListSize < Size) { + *AlgorithmListSize =3D Size; + return EFI_BUFFER_TOO_SMALL; + } + + CopyGuid (AlgorithmList, &gEfiRngAlgorithmRaw); + *AlgorithmListSize =3D Size; + + return EFI_SUCCESS; +} + + +/** + Produces and returns an RNG value using either the default or specified = RNG + algorithm. + + @param[in] This A pointer to the EFI_RNG_PROTOCOL instan= ce. + @param[in] Algorithm A pointer to the EFI_RNG_ALGORITHM that + identifies the RNG algorithm to use. May= be + NULL in which case the function will use= its + default RNG algorithm. + @param[in] ValueLength The length in bytes of the memory buffer + pointed to by RNGValue. The driver shall + return exactly this numbers of bytes. + @param[out] Value A caller-allocated memory buffer filled = by the + driver with the resulting RNG value. + + @retval EFI_SUCCESS The RNG value was returned successfully. + @retval EFI_UNSUPPORTED The algorithm specified by RNGAlgorithm = is not + supported by this driver. + @retval EFI_DEVICE_ERROR An RNG value could not be retrieved due = to a + hardware or firmware error. + @retval EFI_NOT_READY There is not enough random data availabl= e to + satisfy the length requested by + RNGValueLength. + @retval EFI_INVALID_PARAMETER RNGValue is NULL or RNGValueLength is ze= ro. + +**/ +STATIC +EFI_STATUS +EFIAPI +AtSha240aGetRNG ( + IN EFI_RNG_PROTOCOL *This, + IN EFI_RNG_ALGORITHM *Algorithm OPTIONAL, + IN UINTN ValueLength, + OUT UINT8 *Value +) +{ + EFI_STATUS Status; + ATSHA204A_DEV *AtSha204a; + ATSHA204A_I2C_RNG_COMMAND Command; + ATSHA204A_I2C_RNG_RESULT Result; + I2C_RNG_REQUEST Request; + I2C_RNG_REQUEST Response; + UINTN Retries; + + if (Algorithm !=3D NULL && !CompareGuid (Algorithm, &gEfiRngAlgorithmRaw= )) { + return EFI_UNSUPPORTED; + } + + AtSha204a =3D ATSHA204A_DEV_FROM_THIS (This); + + Request.OperationCount =3D 1; + Request.Operation.Flags =3D 0; + + Command.Command =3D ATSHA204A_COMMAND; + Command.Count =3D sizeof (Command) - 1; + Command.Opcode =3D ATSHA204A_OPCODE_RANDOM; + Command.Param1 =3D 0; + Command.Param2 =3D 0; + Command.Crc =3D OPCODE_COMMAND_PACKET_CRC; + + Response.OperationCount =3D 1; + Response.Operation.Flags =3D I2C_FLAG_READ; + Response.Operation.LengthInBytes =3D sizeof (Result); + Response.Operation.Buffer =3D (VOID *)&Result; + + Retries =3D 0; + while (ValueLength > 0) { + // + // The AtSha204a will go back to sleep right in the middle of a transa= ction + // if it does not complete in ~1.3 seconds. So send the wake sequence = for + // each iteration, which consists of a dummy write to slave address 0x= 0. + // + Request.Operation.LengthInBytes =3D 0; + Status =3D AtSha204a->I2cIo->QueueRequest (AtSha204a->I2cIo, 1, NULL, + (VOID *)&Request, NULL); + DEBUG ((DEBUG_INFO, "%a: wake AtSha204a: I2cIo->QueueRequest() - %r\n", + __FUNCTION__, Status)); + + gBS->Stall (2500); // wait 2.5 ms for wake to complete + + Request.Operation.LengthInBytes =3D sizeof (Command); + Request.Operation.Buffer =3D (VOID *)&Command; + Status =3D AtSha204a->I2cIo->QueueRequest (AtSha204a->I2cIo, 0, NULL, + (VOID *)&Request, NULL); + if (EFI_ERROR (Status)) { + if (++Retries <=3D MAX_RETRIES) { + continue; + } + DEBUG ((DEBUG_ERROR, "%a: I2C request transfer failed, Status =3D=3D= %r\n", + __FUNCTION__, Status)); + return EFI_DEVICE_ERROR; + } + + gBS->Stall (50 * 1000); // 50 ms max execution time for RANDOM opcode + + Status =3D AtSha204a->I2cIo->QueueRequest (AtSha204a->I2cIo, 0, NULL, + (VOID *)&Response, NULL); + if (EFI_ERROR (Status)) { + if (++Retries <=3D MAX_RETRIES) { + continue; + } + DEBUG ((DEBUG_ERROR, "%a: I2C response transfer failed, Status =3D= =3D %r\n", + __FUNCTION__, Status)); + return EFI_DEVICE_ERROR; + } + + if (Result.Count < sizeof (Result)) { + // + // Incomplete packet received, most likely due to an error. Retry. + // + if (++Retries <=3D MAX_RETRIES) { + continue; + } + DEBUG ((DEBUG_WARN, "%a: incomplete packet received\n", __FUNCTION__= )); + return EFI_DEVICE_ERROR; + } + + gBS->CopyMem (Value, Result.Result, MIN (ValueLength, + ATSHA204A_OUTPUT_SIZE)); + if (ValueLength < ATSHA204A_OUTPUT_SIZE) { + break; + } + + Value +=3D ATSHA204A_OUTPUT_SIZE; + ValueLength -=3D ATSHA204A_OUTPUT_SIZE; + Retries =3D 0; + } + return EFI_SUCCESS; +} + +EFI_STATUS +AtSha204aInit ( + IN EFI_HANDLE DriverBindingHandle, + IN EFI_HANDLE ControllerHandle + ) +{ + EFI_STATUS Status; + ATSHA204A_DEV *AtSha204a; + + Status =3D gBS->AllocatePool (EfiBootServicesData, sizeof (ATSHA204A_DEV= ), + (VOID **) &AtSha204a); + if (EFI_ERROR (Status)) { + return EFI_OUT_OF_RESOURCES; + } + + AtSha204a->Signature =3D ATSHA204A_DEV_SIGNATURE; + AtSha204a->Rng.GetInfo =3D AtSha240aGetInfo; + AtSha204a->Rng.GetRNG =3D AtSha240aGetRNG; + + // + // Open I2C I/O Protocol + // + Status =3D gBS->OpenProtocol (ControllerHandle, + &gEfiI2cIoProtocolGuid, + (VOID **)&AtSha204a->I2cIo, + DriverBindingHandle, + ControllerHandle, + EFI_OPEN_PROTOCOL_BY_DRIVER); + if (EFI_ERROR (Status)) { + goto ErrorFreeDev; + } + + Status =3D gBS->InstallProtocolInterface (&ControllerHandle, + &gEfiRngProtocolGuid, + EFI_NATIVE_INTERFACE, + &AtSha204a->Rng); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, + "Failed to install RNG protocol interface (Status =3D=3D %r)\n", + Status)); + goto ErrorCloseProtocol; + } + + return EFI_SUCCESS; + +ErrorCloseProtocol: + gBS->CloseProtocol (ControllerHandle, &gEfiI2cIoProtocolGuid, + DriverBindingHandle, ControllerHandle); + +ErrorFreeDev: + gBS->FreePool (AtSha204a); + + return Status; +} + +EFI_STATUS +AtSha204aRelease ( + IN EFI_HANDLE DriverBindingHandle, + IN EFI_HANDLE ControllerHandle + ) +{ + EFI_RNG_PROTOCOL *Rng; + ATSHA204A_DEV *AtSha204a; + EFI_STATUS Status; + + Status =3D gBS->HandleProtocol (ControllerHandle, + &gEfiRngProtocolGuid, + (VOID **)&Rng); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return Status; + } + + AtSha204a =3D ATSHA204A_DEV_FROM_THIS (Rng); + + Status =3D gBS->UninstallProtocolInterface (ControllerHandle, + &gEfiRngProtocolGuid, + Rng); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D gBS->CloseProtocol (ControllerHandle, + &gEfiI2cIoProtocolGuid, + DriverBindingHandle, + ControllerHandle); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return Status; + } + + gBS->FreePool (AtSha204a); + + return EFI_SUCCESS; +} diff --git a/Silicon/Atmel/AtSha204a/AtSha204aDriver.h b/Silicon/Atmel/AtSh= a204a/AtSha204aDriver.h new file mode 100644 index 000000000000..315a450d34f2 --- /dev/null +++ b/Silicon/Atmel/AtSha204a/AtSha204aDriver.h @@ -0,0 +1,81 @@ +/** @file + Device driver for the Atmel ATSHA204A random number generator. + + Copyright (c) 2018, Linaro Ltd. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD + License which accompanies this distribution. The full text of the licens= e may + be found at http://opensource.org/licenses/bsd-license.php. + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#ifndef _ATSHA204A_I2C_HWRNG_DRIVER_H_ +#define _ATSHA204A_I2C_HWRNG_DRIVER_H_ + +#include +#include +#include +#include +#include + +#include +#include + +#define ATSHA204A_OUTPUT_SIZE 32 + +#define ATSHA204A_DEV_SIGNATURE SIGNATURE_32('a','t','s','h') + +typedef struct { + UINT32 Signature; + EFI_I2C_IO_PROTOCOL *I2cIo; + EFI_RNG_PROTOCOL Rng; +} ATSHA204A_DEV; + +#define ATSHA204A_DEV_FROM_THIS(a) \ + CR(a, ATSHA204A_DEV, Rng, ATSHA204A_DEV_SIGNATURE) + +#pragma pack(1) +typedef struct { + UINT8 Command; + UINT8 Count; + UINT8 Opcode; + UINT8 Param1; + UINT16 Param2; + UINT16 Crc; +} ATSHA204A_I2C_RNG_COMMAND; + +typedef struct { + UINT8 Count; + UINT8 Result[ATSHA204A_OUTPUT_SIZE]; + UINT16 Crc; +} ATSHA204A_I2C_RNG_RESULT; +#pragma pack() + +typedef struct { + UINTN OperationCount; + EFI_I2C_OPERATION Operation; +} I2C_RNG_REQUEST; + +#define ATSHA204A_COMMAND 0x3 + +#define ATSHA204A_OPCODE_RANDOM 0x1b + +extern EFI_COMPONENT_NAME2_PROTOCOL gAtSha204aDriverComponentName2; + +EFI_STATUS +AtSha204aInit ( + IN EFI_HANDLE DriverBindingHandle, + IN EFI_HANDLE ControllerHandle + ); + +EFI_STATUS +AtSha204aRelease ( + IN EFI_HANDLE DriverBindingHandle, + IN EFI_HANDLE ControllerHandle + ); + +#endif // _ATSHA204A_I2C_HWRNG_DRIVER_H_ diff --git a/Silicon/Atmel/AtSha204a/AtSha204aDxe.inf b/Silicon/Atmel/AtSha= 204a/AtSha204aDxe.inf new file mode 100644 index 000000000000..fe90cc538114 --- /dev/null +++ b/Silicon/Atmel/AtSha204a/AtSha204aDxe.inf @@ -0,0 +1,52 @@ +## @file +# Device driver for the Atmel ATSHA204A random number generator. +# +# Copyright (c) 2018, Linaro Ltd. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD +# License which accompanies this distribution. The full text of the licen= se may +# be found at http://opensource.org/licenses/bsd-license.php. +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IM= PLIED. +# +## + +[Defines] + INF_VERSION =3D 0x0001001A + BASE_NAME =3D AtSha204aDxe + FILE_GUID =3D 8b8f683b-f376-4ba0-b8d7-b4bbd30319cc + MODULE_TYPE =3D UEFI_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D EntryPoint + UNLOAD_IMAGE =3D UnloadImage + +# +# VALID_ARCHITECTURES =3D AARCH64 ARM EBC IA32 IPF X64 +# + +[Sources] + AtSha204aDriver.c + AtSha204aDriver.h + ComponentName.c + DriverBinding.c + +[Packages] + MdePkg/MdePkg.dec + Silicon/Atmel/AtSha204a/AtSha204a.dec + +[LibraryClasses] + BaseMemoryLib + DebugLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiLib + +[Protocols] + gEfiRngProtocolGuid # PROTOCOL BY_START + gEfiI2cIoProtocolGuid # PROTOCOL TO_START + +[Guids] + gAtSha204aI2cDeviceGuid + gEfiRngAlgorithmRaw diff --git a/Silicon/Atmel/AtSha204a/ComponentName.c b/Silicon/Atmel/AtSha2= 04a/ComponentName.c new file mode 100644 index 000000000000..9893e7c4c2bf --- /dev/null +++ b/Silicon/Atmel/AtSha204a/ComponentName.c @@ -0,0 +1,186 @@ +/** @file + UEFI Component Name(2) protocol implementation for AtSha204a driver. + + Copyright (c) 2018, Linaro Ltd. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#include "AtSha204aDriver.h" + +STATIC EFI_UNICODE_STRING_TABLE mAtSha204aDriverNameTable[] =3D { + { + "en", + (CHAR16 *)L"AtSha204a RNG I2C driver" + }, + { } +}; + +STATIC EFI_UNICODE_STRING_TABLE mAtSha204aControllerNameTable[] =3D { + { + "en", + (CHAR16 *)L"AtSha204a Random Number Generator (I2C)" + }, + { } +}; + +/** + Retrieves a Unicode string that is the user readable name of the driver. + + This function retrieves the user readable name of a driver in the form o= f a + Unicode string. If the driver specified by This has a user readable name= in + the language specified by Language, then a pointer to the driver name is + returned in DriverName, and EFI_SUCCESS is returned. If the driver speci= fied + by This does not support the language specified by Language, + then EFI_UNSUPPORTED is returned. + + @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTO= COL or + EFI_COMPONENT_NAME_PROTOCOL instance. + + @param Language[in] A pointer to a Null-terminated ASCII string + array indicating the language. This is the + language of the driver name that the calle= r is + requesting, and it must match one of the + languages specified in SupportedLanguages.= The + number of languages supported by a driver = is up + to the driver writer. Language is specified + in RFC 4646 or ISO 639-2 language code for= mat. + + @param DriverName[out] A pointer to the Unicode string to return. + This Unicode string is the name of the + driver specified by This in the language + specified by Language. + + @retval EFI_SUCCESS The Unicode string for the Driver specifie= d by + This and the language specified by Languag= e was + returned in DriverName. + + @retval EFI_INVALID_PARAMETER Language is NULL. + + @retval EFI_INVALID_PARAMETER DriverName is NULL. + + @retval EFI_UNSUPPORTED The driver specified by This does not supp= ort + the language specified by Language. + +**/ +STATIC +EFI_STATUS +EFIAPI +AtSha204aGetDriverName ( + IN EFI_COMPONENT_NAME2_PROTOCOL *This, + IN CHAR8 *Language, + OUT CHAR16 **DriverName + ) +{ + return LookupUnicodeString2 (Language, + This->SupportedLanguages, + mAtSha204aDriverNameTable, + DriverName, + FALSE); +} + +/** + Retrieves a Unicode string that is the user readable name of the control= ler + that is being managed by a driver. + + This function retrieves the user readable name of the controller specifi= ed by + ControllerHandle and ChildHandle in the form of a Unicode string. If the + driver specified by This has a user readable name in the language specif= ied by + Language, then a pointer to the controller name is returned in Controlle= rName, + and EFI_SUCCESS is returned. If the driver specified by This is not cur= rently + managing the controller specified by ControllerHandle and ChildHandle, + then EFI_UNSUPPORTED is returned. If the driver specified by This does = not + support the language specified by Language, then EFI_UNSUPPORTED is retu= rned. + + @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTO= COL or + EFI_COMPONENT_NAME_PROTOCOL instance. + + @param ControllerHandle[in] The handle of a controller that the driver + specified by This is managing. This handle + specifies the controller whose name is to = be + returned. + + @param ChildHandle[in] The handle of the child controller to retr= ieve + the name of. This is an optional paramete= r that + may be NULL. It will be NULL for device + drivers. It will also be NULL for a bus d= rivers + that wish to retrieve the name of the bus + controller. It will not be NULL for a bus + driver that wishes to retrieve the name of= a + child controller. + + @param Language[in] A pointer to a Null-terminated ASCII string + array indicating the language. This is the + language of the driver name that the calle= r is + requesting, and it must match one of the + languages specified in SupportedLanguages.= The + number of languages supported by a driver = is up + to the driver writer. Language is specifie= d in + RFC 4646 or ISO 639-2 language code format. + + @param ControllerName[out] A pointer to the Unicode string to return. + This Unicode string is the name of the + controller specified by ControllerHandle a= nd + ChildHandle in the language specified by + Language from the point of view of the dri= ver + specified by This. + + @retval EFI_SUCCESS The Unicode string for the user readable n= ame in + the language specified by Language for the + driver specified by This was returned in + DriverName. + + @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. + + @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a va= lid + EFI_HANDLE. + + @retval EFI_INVALID_PARAMETER Language is NULL. + + @retval EFI_INVALID_PARAMETER ControllerName is NULL. + + @retval EFI_UNSUPPORTED The driver specified by This is not curren= tly + managing the controller specified by + ControllerHandle and ChildHandle. + + @retval EFI_UNSUPPORTED The driver specified by This does not supp= ort + the language specified by Language. + +**/ +STATIC +EFI_STATUS +EFIAPI +AtSha204aGetControllerName ( + IN EFI_COMPONENT_NAME2_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_HANDLE ChildHandle O= PTIONAL, + IN CHAR8 *Language, + OUT CHAR16 **ControllerName + ) +{ + if (ChildHandle !=3D NULL) { + return EFI_UNSUPPORTED; + } + + return LookupUnicodeString2 (Language, + This->SupportedLanguages, + mAtSha204aControllerNameTable, + ControllerName, + FALSE); +} + +// +// EFI Component Name 2 Protocol +// +EFI_COMPONENT_NAME2_PROTOCOL gAtSha204aDriverComponentName2 =3D { + AtSha204aGetDriverName, + AtSha204aGetControllerName, + "en" +}; diff --git a/Silicon/Atmel/AtSha204a/DriverBinding.c b/Silicon/Atmel/AtSha2= 04a/DriverBinding.c new file mode 100644 index 000000000000..17e61f96e8c5 --- /dev/null +++ b/Silicon/Atmel/AtSha204a/DriverBinding.c @@ -0,0 +1,242 @@ +/** @file + Device driver for the Atmel ATSHA204A random number generator. + + Copyright (c) 2018, Linaro Ltd. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD + License which accompanies this distribution. The full text of the licens= e may + be found at http://opensource.org/licenses/bsd-license.php. + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#include + +#include "AtSha204aDriver.h" + +/** + Tests to see if this driver supports a given controller. + + @param This[in] A pointer to the EFI_DRIVER_BINDING_PRO= TOCOL + instance. + @param ControllerHandle[in] The handle of the controller to test. + @param RemainingDevicePath[in] The remaining device path. + (Ignored - this is not a bus driver.) + + @retval EFI_SUCCESS The driver supports this controller. + @retval EFI_ALREADY_STARTED The device specified by ControllerHandl= e is + already being managed by the driver spe= cified + by This. + @retval EFI_UNSUPPORTED The device specified by ControllerHandl= e is + not supported by the driver specified b= y This. + +**/ +EFI_STATUS +EFIAPI +I2cHwrngDriverBindingSupported ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath + ) +{ + EFI_I2C_IO_PROTOCOL *I2cIo; + EFI_STATUS Status; + + // + // Connect to the I2C stack + // + Status =3D gBS->OpenProtocol (ControllerHandle, + &gEfiI2cIoProtocolGuid, + (VOID **) &I2cIo, + This->DriverBindingHandle, + ControllerHandle, + EFI_OPEN_PROTOCOL_BY_DRIVER); + if (EFI_ERROR (Status)) { + return Status; + } + + if (CompareGuid (I2cIo->DeviceGuid, &gAtSha204aI2cDeviceGuid)) { + DEBUG ((DEBUG_INIT | DEBUG_INFO, "Detected AtSha204a RNG device\n")); + Status =3D EFI_SUCCESS; + } else { + Status =3D EFI_UNSUPPORTED; + } + + // + // Clean up. + // + gBS->CloseProtocol (ControllerHandle, + &gEfiI2cIoProtocolGuid, + This->DriverBindingHandle, + ControllerHandle); + + return Status; +} + + +/** + Starts a device controller or a bus controller. + + @param[in] This A pointer to the EFI_DRIVER_BINDING_PRO= TOCOL + instance. + @param[in] ControllerHandle The handle of the device to start. This + handle must support a protocol interfac= e that + supplies an I/O abstraction to the driv= er. + @param[in] RemainingDevicePath The remaining portion of the device pat= h. + (Ignored - this is not a bus driver.) + + @retval EFI_SUCCESS The device was started. + @retval EFI_DEVICE_ERROR The device could not be started due to a + device error. + @retval EFI_OUT_OF_RESOURCES The request could not be completed due = to a + lack of resources. + +**/ +EFI_STATUS +EFIAPI +I2cHwrngDriverBindingStart ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL + ) +{ + return AtSha204aInit (This->DriverBindingHandle, ControllerHandle); +} + + +/** + Stops a device controller or a bus controller. + + @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOC= OL + instance. + @param[in] ControllerHandle A handle to the device being stopped. The = handle + must support a bus specific I/O protocol f= or the + driver to use to stop the device. + @param[in] NumberOfChildren The number of child device handles in + ChildHandleBuffer. + @param[in] ChildHandleBuffer An array of child handles to be freed. May= be + NULL if NumberOfChildren is 0. + + @retval EFI_SUCCESS The device was stopped. + @retval EFI_DEVICE_ERROR The device could not be stopped due to a d= evice + error. + +**/ +EFI_STATUS +EFIAPI +I2cHwrngDriverBindingStop ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN UINTN NumberOfChildren, + IN EFI_HANDLE *ChildHandleBuffer OPTIONAL + ) +{ + return AtSha204aRelease (This->DriverBindingHandle, ControllerHandle); +} + + +STATIC +EFI_DRIVER_BINDING_PROTOCOL gI2cHwrngDriverBinding =3D { + I2cHwrngDriverBindingSupported, + I2cHwrngDriverBindingStart, + I2cHwrngDriverBindingStop, + 0xa, + NULL, + NULL +}; + + +/** + The entry point of AtSha204a UEFI Driver. + + @param ImageHandle The image handle of the UEFI Driver. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The Driver or UEFI Driver exited norm= ally. + @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than + SystemTable->Hdr.Revision. + +**/ +EFI_STATUS +EFIAPI +EntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + // + // Add the driver to the list of drivers + // + Status =3D EfiLibInstallDriverBindingComponentName2 ( + ImageHandle, SystemTable, &gI2cHwrngDriverBinding, ImageHandl= e, + NULL, &gAtSha204aDriverComponentName2); + ASSERT_EFI_ERROR (Status); + + DEBUG ((DEBUG_INIT | DEBUG_INFO, "*** Installed AtSha204a driver! ***\n"= )); + + return EFI_SUCCESS; +} + + +/** + Unload function for the AtSha204a Driver. + + @param ImageHandle[in] The allocated handle for the EFI image + + @retval EFI_SUCCESS The driver was unloaded successfully + @retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle. + +**/ +EFI_STATUS +EFIAPI +UnloadImage ( + IN EFI_HANDLE ImageHandle + ) +{ + EFI_STATUS Status; + EFI_HANDLE *HandleBuffer; + UINTN HandleCount; + UINTN Index; + + // + // Retrieve all I2C I/O handles in the handle database + // + Status =3D gBS->LocateHandleBuffer (ByProtocol, + &gEfiI2cIoProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Disconnect the driver from the handles in the handle database + // + for (Index =3D 0; Index < HandleCount; Index++) { + Status =3D gBS->DisconnectController (HandleBuffer[Index], + gImageHandle, + NULL); + } + + // + // Free the handle array + // + gBS->FreePool (HandleBuffer); + + // + // Uninstall protocols installed by the driver in its entrypoint + // + Status =3D gBS->UninstallMultipleProtocolInterfaces (ImageHandle, + &gEfiDriverBindingProtocolGuid, + &gI2cHwrngDriverBinding, + NULL + ); + + return EFI_SUCCESS; +} --=20 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Mon Dec 23 05:20:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1519149003613960.1410006156254; Tue, 20 Feb 2018 09:50:03 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C6D2F20954CBD; Tue, 20 Feb 2018 09:44:03 -0800 (PST) Received: from mail-wr0-x242.google.com (mail-wr0-x242.google.com [IPv6:2a00:1450:400c:c0c::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0024320954CBD for ; Tue, 20 Feb 2018 09:44:01 -0800 (PST) Received: by mail-wr0-x242.google.com with SMTP id s5so16850029wra.0 for ; Tue, 20 Feb 2018 09:50:00 -0800 (PST) Received: from localhost.localdomain ([105.149.187.179]) by smtp.gmail.com with ESMTPSA id u63sm18282208wrc.26.2018.02.20.09.49.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 09:49:57 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::242; helo=mail-wr0-x242.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FJYVDeOQmv+DMdmwSxjtl61kZOTF+xx3seo8gDkemUQ=; b=HyGsGSMGtsK9KMixqFzN2M7MRGGpyJZ1C7TeeIqAdswGaJSLRs0APfVf7Bnvg8dWGl yf/nkjS4TGBLZgBsCUg98YNsZ0tiMLz6u4QDyEAy14D9oETZlcIwhHkloeXgfHANznnu AswZVA+mcoXuf8f+ybshKde/q5r1hnQNSgsV0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FJYVDeOQmv+DMdmwSxjtl61kZOTF+xx3seo8gDkemUQ=; b=SQKK+KDxMHr0AQIYEbHSf7nYDjnziP3Y0n9Ea6YH1X/Py5XfHKiyRBcqVhstpldauY FzPIr4UefsP9lbK/RqDt91blGCmXq6Ey+Nn8DBsunTU9gQ8kCDh8Xrlq5L5iD5wv40/5 pcBb7ib9FhFP25Bs3qDEybYfS32vSZWZhr26bKTv34MsX+k3pxu0fMGy/5dU4NeIgVwz hqKPcocnRlwLlnXJ89yJ18okAaCSw3SCeCe4WAjUL7p9M5uB7WnlPFEzBnhUo1j5vt7q 8fPtfeAUaNmDHQZIKS/tAu7x9lc9KgH5RT2lrc9qYgdv8BnC6iXR6d4qhebL/1vNovuY WOAw== X-Gm-Message-State: APf1xPCmSX41ZEAxu6j9Xwr/6NXYFbDspBSSF5zmD16fdAi7WufPn9K9 ZWSZeokX+PWAPlnXLYCk4WkhDc5vs1A= X-Google-Smtp-Source: AH8x224HLe/JQ8ZCcf60IpCTTVsCfG199pf4CPaLHqB2yFVS0A6Mah2SO6NdO2ar2q+V7HfaUg0y9A== X-Received: by 10.223.148.195 with SMTP id 61mr434463wrr.248.1519148998542; Tue, 20 Feb 2018 09:49:58 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Tue, 20 Feb 2018 17:49:39 +0000 Message-Id: <20180220174944.525-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180220174944.525-1-ard.biesheuvel@linaro.org> References: <20180220174944.525-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH edk2-platforms v2 2/7] Platform/NinetySixBoards: introduce package and mezzanine protocol X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: leif.lindholm@linaro.org, Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Introduce the mezzanine protocol and the 96boards package defining the PCDs and GUIDs that may be used by implementations of the protocol. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- Platform/NinetySixBoards/Include/Protocol/Mezzanine.h | 71 +++++++++++++++= +++++ Platform/NinetySixBoards/NinetySixBoards.dec | 67 +++++++++++++++= +++ 2 files changed, 138 insertions(+) diff --git a/Platform/NinetySixBoards/Include/Protocol/Mezzanine.h b/Platfo= rm/NinetySixBoards/Include/Protocol/Mezzanine.h new file mode 100644 index 000000000000..7869ea979b48 --- /dev/null +++ b/Platform/NinetySixBoards/Include/Protocol/Mezzanine.h @@ -0,0 +1,71 @@ +/** @file + + Copyright (c) 2018, Linaro, Ltd. All rights reserved.
+ + This program and the accompanying materials are licensed and made availa= ble + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#ifndef _MEZZANINE_H_ +#define _MEZZANINE_H_ + +#include +#include + +#define MEZZANINE_PROTOCOL_GUID \ + { 0xf0467a37, 0x3436, 0x40ef, { 0x94, 0x09, 0x4d, 0x1d, 0x7f, 0x51, 0x06= , 0xd3 } } + +typedef struct _MEZZANINE_PROTOCOL MEZZANINE_PROTOCOL; + +/** + Apply the mezzanine's DT overlay + + @param[in] This Pointer to the MEZZANINE_PROTOCOL instance. + @param[in,out] Dtb Pointer to the device tree blob + + @return EFI_SUCCESS Operation succeeded. + @return other An error has occurred. +**/ +typedef +EFI_STATUS +(EFIAPI *APPLY_DEVICE_TREE_OVERLAY) ( + IN MEZZANINE_PROTOCOL *This, + IN OUT VOID *Dtb + ); + +struct _MEZZANINE_PROTOCOL { + // + // Get the device tree overlay for this mezzanine board + // + APPLY_DEVICE_TREE_OVERLAY ApplyDeviceTreeOverlay; + // + // The number of devices on LS connector I2C bus #0 + // + UINT32 I2c0NumDevices; + // + // The number of devices on LS connector I2C bus #1 + // + UINT32 I2c1NumDevices; + // + // Linear array of I2C devices on LS connector bus #0 + // + CONST EFI_I2C_DEVICE *I2c0DeviceArray; + // + // Linear array of I2C devices on LS connector bus #0 + // + CONST EFI_I2C_DEVICE *I2c1DeviceArray; + // + // NULL terminated linked list of SPI devices attached to the LS connect= or + // + CONST EFI_SPI_PERIPHERAL *SpiDeviceLinkedList; +}; + +extern EFI_GUID gNinetySixBoardsMezzanineProtocolGuid; + +#endif // _MEZZANINE_H_ diff --git a/Platform/NinetySixBoards/NinetySixBoards.dec b/Platform/Ninety= SixBoards/NinetySixBoards.dec new file mode 100644 index 000000000000..f7e2b01459d7 --- /dev/null +++ b/Platform/NinetySixBoards/NinetySixBoards.dec @@ -0,0 +1,67 @@ +## @file +# +# Copyright (c) 2018, Linaro Ltd. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD License +# which accompanies this distribution. The full text of the license may = be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IM= PLIED. +# +## + +[Defines] + DEC_SPECIFICATION =3D 0x0001001A + PACKAGE_NAME =3D NinetySixBoards + PACKAGE_GUID =3D ce4a4683-6e2d-4ec3-bc11-974289a09ab0 + PACKAGE_VERSION =3D 0.1 + +[Includes] + Include + +[Protocols] + ## Include/Protocol/Mezzanine.h + gNinetySixBoardsMezzanineProtocolGuid =3D { 0xf0467a37, 0x3436, 0x40ef, = { 0x94, 0x09, 0x4d, 0x1d, 0x7f, 0x51, 0x06, 0xd3 } } + +[Guids] + # PCD scope GUID + gNinetySixBoardsTokenSpaceGuid =3D { 0xe0d2f33a, 0xb7dd, 0x4a69, { 0xb6,= 0x76, 0xda, 0xe8, 0xa4, 0x17, 0xa7, 0xb5 } } + + # GUIDs to be installed as protocols to identify which controller connec= ts to which bus + gNinetySixBoardsI2c0MasterGuid =3D { 0xba10e402, 0xcfdd, 0x4b87, { 0xbd,= 0x02, 0x6e, 0x26, 0x9f, 0x01, 0x94, 0x11 } } + gNinetySixBoardsI2c1MasterGuid =3D { 0xcf64ac46, 0xd0be, 0x4a69, { 0x90,= 0xa2, 0xf2, 0x82, 0x5b, 0x92, 0x25, 0x61 } } + gNinetySixBoardsSpiMasterGuid =3D { 0x9703fd99, 0xe638, 0x42b8, { 0xab, = 0x81, 0x52, 0x61, 0x1b, 0xf7, 0xf7, 0x5d } } + +[PcdsFixedAtBuild] + # ASCII DT paths to the I2C parent nodes of the 96boards LS connector + gNinetySixBoardsTokenSpaceGuid.PcdI2c0Parent|""|VOID*|0x00000001 + gNinetySixBoardsTokenSpaceGuid.PcdI2c1Parent|""|VOID*|0x00000002 + + # I2C bus frequency in Hertz + gNinetySixBoardsTokenSpaceGuid.PcdI2c0BusFrequencyHz|0|UINT32|0x00000003 + gNinetySixBoardsTokenSpaceGuid.PcdI2c1BusFrequencyHz|0|UINT32|0x00000004 + + # ASCII DT path to the SPI parent node of the 96boards LS connector + gNinetySixBoardsTokenSpaceGuid.PcdSpiParent|""|VOID*|0x00000005 + + # ASCII DT path to the GPIO parent node of the 96boards LS connector + gNinetySixBoardsTokenSpaceGuid.PcdGpioParent|""|VOID*|0x00000006 + + # Polarity of the 96boards LS connector GPIOs (0 =3D=3D GPIO_ACTIVE_HIGH= , 1 =3D=3D GPIO_ACTIVE_LOW) + gNinetySixBoardsTokenSpaceGuid.PcdGpioPolarity|0|UINT32|0x00000007 + + # Pin numbers of the 96boards LS connector GPIOs + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinA|0|UINT32|0x00000010 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinB|0|UINT32|0x00000011 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinC|0|UINT32|0x00000012 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinD|0|UINT32|0x00000013 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinE|0|UINT32|0x00000014 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinF|0|UINT32|0x00000015 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinG|0|UINT32|0x00000016 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinH|0|UINT32|0x00000017 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinI|0|UINT32|0x00000018 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinJ|0|UINT32|0x00000019 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinK|0|UINT32|0x0000001A + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinL|0|UINT32|0x0000001B --=20 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Mon Dec 23 05:20:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1519149009126403.59662147576614; Tue, 20 Feb 2018 09:50:09 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7982F21FD73CF; Tue, 20 Feb 2018 09:44:06 -0800 (PST) Received: from mail-wr0-x244.google.com (mail-wr0-x244.google.com [IPv6:2a00:1450:400c:c0c::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0687F21FD73C8 for ; Tue, 20 Feb 2018 09:44:03 -0800 (PST) Received: by mail-wr0-x244.google.com with SMTP id v65so16793784wrc.11 for ; Tue, 20 Feb 2018 09:50:02 -0800 (PST) Received: from localhost.localdomain ([105.149.187.179]) by smtp.gmail.com with ESMTPSA id u63sm18282208wrc.26.2018.02.20.09.49.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 09:49:59 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::244; helo=mail-wr0-x244.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dzRKFSaO1bmI29LeUUjeoeBYAGu84mYY5BMsMXXPRFg=; b=KOrkG1ATxcF1tRbj02IGuzSpHVGTYM4U7fUHp3NGlBJNxOka272HtTIsYSKKAyUJS3 HmyfxRzRCQSg5SEf0A2xlWbiEkTqX8c1r7UySPaAKXMaPc7vpuBUTDWqvFjL9mM0MJVa V+wNZxE8bjNUEWOj+KNgrYO5GMBWJNbk2f6qw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dzRKFSaO1bmI29LeUUjeoeBYAGu84mYY5BMsMXXPRFg=; b=IiNucugRQlIxpiFpaBz5NAmgc7l+DKMMh/uGVgVLad4nQFdhH2RkIkuX1Vq2jIUHCe AQ3+lBgUONvey8j/lBOy9A990+VC3d0zLby9c0mw5b4jdfSTgRMac9q+4fsSaBGeSO6y GSWK5FRg026ewhFlecHqZfgwZUEdXs5WGT8fhm9BlH+RlTBHxLHv6H+M6MmfZoBz/feX 5ej88XttCGUuJP7++/1/fcGsy4K/VR6gh6fyob/WyvxxhOBq7CUqp25ywAp+wxymSX1q SLWI+Gjby1cGGBQqFCYbKwUhxDWSrmKDxo00/+W3E2F+WZmbXCG+OJLEQpU2s3UZtggz cWmg== X-Gm-Message-State: APf1xPBjHWsi1gmDqcjbvDEKx4Eo+yNcjC41Wk9x7YRZRLK10rNOtfPm KL9AkTYpF4/+0vy0AJVIvNs2G3ij3nE= X-Google-Smtp-Source: AH8x224GwPy2WBxqmrzMprPFr6520OiUdEW9NihcmWmK2qAXylsQYK0L3qMkmvqiPpXrLz69WEhN2g== X-Received: by 10.28.22.145 with SMTP id 139mr914339wmw.56.1519149000725; Tue, 20 Feb 2018 09:50:00 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Tue, 20 Feb 2018 17:49:40 +0000 Message-Id: <20180220174944.525-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180220174944.525-1-ard.biesheuvel@linaro.org> References: <20180220174944.525-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH edk2-platforms v2 3/7] Platform/NinetySixBoards: introduce I2C driver X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: leif.lindholm@linaro.org, Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Implement a I2C DXE driver that wires up the I2C devices exposed by a 96boards mezzanine into the EDK2 I2C stack. Note that this requires the platform to identify its I2C master implementations using special GUIDs-as-protocols. It also assumes [for now] that I2C buses are not shared between the 96boards connector and other platform peripherals. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- Platform/NinetySixBoards/NinetySixBoardsI2cDxe/NinetySixBoardsI2cDxe.c |= 202 ++++++++++++++++++++ Platform/NinetySixBoards/NinetySixBoardsI2cDxe/NinetySixBoardsI2cDxe.inf |= 51 +++++ 2 files changed, 253 insertions(+) diff --git a/Platform/NinetySixBoards/NinetySixBoardsI2cDxe/NinetySixBoards= I2cDxe.c b/Platform/NinetySixBoards/NinetySixBoardsI2cDxe/NinetySixBoardsI2= cDxe.c new file mode 100644 index 000000000000..9a779626b19f --- /dev/null +++ b/Platform/NinetySixBoards/NinetySixBoardsI2cDxe/NinetySixBoardsI2cDxe.c @@ -0,0 +1,202 @@ +/** @file + + Copyright (c) 2018, Linaro, Ltd. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may be= found at + http://opensource.org/licenses/bsd-license.php + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +STATIC MEZZANINE_PROTOCOL *mMezzanine; + +typedef struct { + EFI_I2C_ENUMERATE_PROTOCOL I2cEnumerate; + EFI_I2C_BUS_CONFIGURATION_MANAGEMENT_PROTOCOL I2cConfigManagement; + EFI_HANDLE I2cMasterHandle; + UINT32 BusFrequency; + UINTN NumDevices; + CONST EFI_I2C_DEVICE *Devices; +} I2C_BUS; + +STATIC +EFI_STATUS +EFIAPI +I2cEnumerate ( + IN CONST EFI_I2C_ENUMERATE_PROTOCOL *This, + IN OUT CONST EFI_I2C_DEVICE **Device + ) +{ + I2C_BUS *Bus; + + if (Device =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Bus =3D BASE_CR (This, I2C_BUS, I2cEnumerate); + + if (*Device =3D=3D NULL) { + *Device =3D &Bus->Devices[0]; + } else if (*Device >=3D &Bus->Devices[0] && + *Device < &Bus->Devices[Bus->NumDevices - 2]) { + ++*Device; + } else { + return EFI_NO_MAPPING; + } + return EFI_SUCCESS; +} + +STATIC +EFI_STATUS +EFIAPI +I2cGetBusFrequency ( + IN CONST EFI_I2C_ENUMERATE_PROTOCOL *This, + IN UINTN I2cBusConfiguration, + OUT UINTN *BusClockHertz + ) +{ + I2C_BUS *Bus; + + if (BusClockHertz =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (I2cBusConfiguration > 0) { + return EFI_NO_MAPPING; + } + + Bus =3D BASE_CR (This, I2C_BUS, I2cEnumerate); + + *BusClockHertz =3D Bus->BusFrequency; + + return EFI_SUCCESS; +} + +STATIC +EFI_STATUS +EFIAPI +EnableI2cBusConfiguration ( + IN CONST EFI_I2C_BUS_CONFIGURATION_MANAGEMENT_PROTOCOL *This, + IN UINTN I2cBusConfigurat= ion, + IN EFI_EVENT Event OPTI= ONAL, + IN EFI_STATUS *I2cStatus OPTI= ONAL + ) +{ + EFI_I2C_MASTER_PROTOCOL *I2cMaster; + EFI_STATUS Status; + UINTN BusClockHertz; + I2C_BUS *Bus; + + if (I2cBusConfiguration > 0) { + return EFI_NO_MAPPING; + } + + Bus =3D BASE_CR (This, I2C_BUS, I2cConfigManagement); + + Status =3D gBS->HandleProtocol (Bus->I2cMasterHandle, + &gEfiI2cMasterProtocolGuid, (VOID **)&I2cMaster); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: gBS->HandleProtocol() failed - %r\n", + __FUNCTION__, Status)); + return Status; + } + + BusClockHertz =3D Bus->BusFrequency; + Status =3D I2cMaster->SetBusFrequency (I2cMaster, &BusClockHertz); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: I2cMaster->SetBusFrequency() failed - %r\n", + __FUNCTION__, Status)); + return Status; + } + + if (Event !=3D NULL) { + *I2cStatus =3D EFI_SUCCESS; + gBS->SignalEvent (Event); + } + return EFI_SUCCESS; +} + +STATIC I2C_BUS mI2cBus0 =3D { + { I2cEnumerate, I2cGetBusFrequency }, + { EnableI2cBusConfiguration }, + NULL, + FixedPcdGet32 (PcdI2c0BusFrequencyHz), + 0, + NULL, +}; + +STATIC I2C_BUS mI2cBus1 =3D { + { I2cEnumerate, I2cGetBusFrequency }, + { EnableI2cBusConfiguration }, + NULL, + FixedPcdGet32 (PcdI2c1BusFrequencyHz), + 0, + NULL, +}; + +STATIC +VOID +RegisterI2cBus ( + IN EFI_GUID *Guid, + IN I2C_BUS *I2cBus, + IN UINTN NumDevices, + IN CONST EFI_I2C_DEVICE *Devices + ) +{ + EFI_STATUS Status; + UINTN BufferSize; + + BufferSize =3D sizeof (EFI_HANDLE); + Status =3D gBS->LocateHandle (ByProtocol, Guid, NULL, &BufferSize, + &I2cBus->I2cMasterHandle); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: gBS->LocateHandle() failed - %r\n", __FUNCTIO= N__, + Status)); + return; + } + + I2cBus->NumDevices =3D NumDevices; + I2cBus->Devices =3D Devices; + + Status =3D gBS->InstallMultipleProtocolInterfaces (&I2cBus->I2cMasterHan= dle, + &gEfiI2cEnumerateProtocolGuid, + &I2cBus->I2cEnumerate, + &gEfiI2cBusConfigurationManagementProtocolGuid, + &I2cBus->I2cConfigManagement, + NULL); + ASSERT_EFI_ERROR (Status); +} + +EFI_STATUS +EFIAPI +EntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status =3D gBS->LocateProtocol (&gNinetySixBoardsMezzanineProtocolGuid, = NULL, + (VOID **)&mMezzanine); + ASSERT_EFI_ERROR (Status); + + RegisterI2cBus (&gNinetySixBoardsI2c0MasterGuid, &mI2cBus0, + mMezzanine->I2c0NumDevices, mMezzanine->I2c0DeviceArray); + RegisterI2cBus (&gNinetySixBoardsI2c1MasterGuid, &mI2cBus1, + mMezzanine->I2c1NumDevices, mMezzanine->I2c1DeviceArray); + + return EFI_SUCCESS; +} diff --git a/Platform/NinetySixBoards/NinetySixBoardsI2cDxe/NinetySixBoards= I2cDxe.inf b/Platform/NinetySixBoards/NinetySixBoardsI2cDxe/NinetySixBoards= I2cDxe.inf new file mode 100644 index 000000000000..9875566b6425 --- /dev/null +++ b/Platform/NinetySixBoards/NinetySixBoardsI2cDxe/NinetySixBoardsI2cDxe.= inf @@ -0,0 +1,51 @@ +## @file +# +# Copyright (c) 2018, Linaro Ltd. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD +# License which accompanies this distribution. The full text of the licen= se may +# be found at http://opensource.org/licenses/bsd-license.php. +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IM= PLIED. +# +## + +[Defines] + INF_VERSION =3D 0x0001001A + BASE_NAME =3D NinetySixBoardsI2cDxe + FILE_GUID =3D a59176bc-a151-49c8-b54a-b4ac96f436c3 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 0.1 + ENTRY_POINT =3D EntryPoint + +[Sources] + NinetySixBoardsI2cDxe.c + +[Packages] + MdePkg/MdePkg.dec + Platform/NinetySixBoards/NinetySixBoards.dec + +[LibraryClasses] + DebugLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiLib + +[Protocols] + gNinetySixBoardsMezzanineProtocolGuid ## CONSUMES + gEfiI2cBusConfigurationManagementProtocolGuid ## PRODUCES + gEfiI2cEnumerateProtocolGuid ## PRODUCES + gEfiI2cMasterProtocolGuid ## CONSUMES + +[Guids] + gNinetySixBoardsI2c0MasterGuid + gNinetySixBoardsI2c1MasterGuid + +[FixedPcd] + gNinetySixBoardsTokenSpaceGuid.PcdI2c0BusFrequencyHz + gNinetySixBoardsTokenSpaceGuid.PcdI2c1BusFrequencyHz + +[Depex] + gNinetySixBoardsMezzanineProtocolGuid AND gNinetySixBoardsI2c0MasterGuid= OR gNinetySixBoardsI2c1MasterGuid --=20 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Mon Dec 23 05:20:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1519149013184134.0689891742237; Tue, 20 Feb 2018 09:50:13 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id DBD7121FD73E9; Tue, 20 Feb 2018 09:44:08 -0800 (PST) Received: from mail-wr0-x243.google.com (mail-wr0-x243.google.com [IPv6:2a00:1450:400c:c0c::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 98C7C21F0DA69 for ; Tue, 20 Feb 2018 09:44:05 -0800 (PST) Received: by mail-wr0-x243.google.com with SMTP id z12so10669464wrg.4 for ; Tue, 20 Feb 2018 09:50:04 -0800 (PST) Received: from localhost.localdomain ([105.149.187.179]) by smtp.gmail.com with ESMTPSA id u63sm18282208wrc.26.2018.02.20.09.50.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 09:50:01 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::243; helo=mail-wr0-x243.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OJQ1Q/xN8f8k4owBiYwjYAanesAXGXWxjMh/lYthl6o=; b=WVp4jMDwmFspCmY2AhaG6OBcEo6HkyqNYIksfiWHsPtPtaoQXf1tljvSLROqPnrF4o 2Sx2Hv9k3DCTCT9qHSyVcdkfheeIis003HloOFaFsRA11rk5MfuT0y6eeFFHj7ALJ8ET hojxuLbTdSkgnWr+PV1xmLX9v6+iISJbRgMug= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OJQ1Q/xN8f8k4owBiYwjYAanesAXGXWxjMh/lYthl6o=; b=tMAYaQ0uGczRKqI2zyj60WJ2G4EgHUhCCW3utZCF0eqLYXhEU1OF6TJ/AXjmSRnAr3 CPfciUSNd3K/pQaYY1XoBYuB47J1cuUrIY6jh6lO5QzTHK6yiL186jXqTMPdznYd93Hs /pung7cdl8lV/F6mb+rECFkpIXplNxnnXGDUlAyzBDRWwAQ6029cAW4g4vSRx5VFY4h2 8XDQJ8ENuryqJfWUV+qwNbAcAOdopLxvb7Yqm+O9YxZJLFIMMpfl+/KxTeN5SIOys3Kl 2lCDNgJBCwdh6It/7E8OyEP/STBfLYxPS2JWZNNrRy6L10SkiX3EqI5PLCQ26EcrxfKz 8JzQ== X-Gm-Message-State: APf1xPDr24zO77h4GNDjBFSuvBfj/I66w6yp5Fy5KyhqmI9OQ/RQTnca YS1LxZ0ZU0v0bI0BGhfbHM88M9Wh8hA= X-Google-Smtp-Source: AH8x227y632kLcgIuSWrpZJ/j1hIlO7FXo/jn4yrSgxDH3+9fE7gAN8yBvQJTWnfCcOqIKzzBn4C+Q== X-Received: by 10.223.176.201 with SMTP id j9mr430777wra.210.1519149002635; Tue, 20 Feb 2018 09:50:02 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Tue, 20 Feb 2018 17:49:41 +0000 Message-Id: <20180220174944.525-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180220174944.525-1-ard.biesheuvel@linaro.org> References: <20180220174944.525-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH edk2-platforms v2 4/7] Platform/NinetySixBoards: introduce LsConnector protocol X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: leif.lindholm@linaro.org, Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Introduce a protocol describing the presence of a 96boards LS connector, and identifying the type of mezzanine that has been installed. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- Platform/NinetySixBoards/Include/Protocol/LsConnector.h | 35 +++++++++++++= +++++++ Platform/NinetySixBoards/NinetySixBoards.dec | 3 ++ 2 files changed, 38 insertions(+) diff --git a/Platform/NinetySixBoards/Include/Protocol/LsConnector.h b/Plat= form/NinetySixBoards/Include/Protocol/LsConnector.h new file mode 100644 index 000000000000..a1f0132c85ae --- /dev/null +++ b/Platform/NinetySixBoards/Include/Protocol/LsConnector.h @@ -0,0 +1,35 @@ +/** @file + + Copyright (c) 2018, Linaro, Ltd. All rights reserved.
+ + This program and the accompanying materials are licensed and made availa= ble + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#ifndef _LS_CONNECTOR_H_ +#define _LS_CONNECTOR_H_ + +#define LS_CONNECTOR_PROTOCOL_GUID \ + { 0xae548d4c, 0x9062, 0x4eed, { 0x83, 0x5f, 0xf5, 0x10, 0xf8, 0xfc, 0x48= , 0xaf } } + +typedef struct _LS_CONNECTOR_PROTOCOL LS_CONNECTOR_PROTOCOL; + +typedef enum { + MezzanineUnknown, + MezzanineSecure96, + MezzanineMax +} MEZZANINE_TYPE; + +struct _LS_CONNECTOR_PROTOCOL { + MEZZANINE_TYPE MezzanineType; +}; + +extern EFI_GUID gNinetySixBoardsLsConnectorProtocolGuid; + +#endif // _LS_CONNECTOR_H_ diff --git a/Platform/NinetySixBoards/NinetySixBoards.dec b/Platform/Ninety= SixBoards/NinetySixBoards.dec index f7e2b01459d7..5c3fe43dbb24 100644 --- a/Platform/NinetySixBoards/NinetySixBoards.dec +++ b/Platform/NinetySixBoards/NinetySixBoards.dec @@ -25,6 +25,9 @@ [Protocols] ## Include/Protocol/Mezzanine.h gNinetySixBoardsMezzanineProtocolGuid =3D { 0xf0467a37, 0x3436, 0x40ef, = { 0x94, 0x09, 0x4d, 0x1d, 0x7f, 0x51, 0x06, 0xd3 } } =20 + ## Include/Protocol/LsConnector.h + gNinetySixBoardsLsConnectorProtocolGuid =3D { 0xae548d4c, 0x9062, 0x4eed= , { 0x83, 0x5f, 0xf5, 0x10, 0xf8, 0xfc, 0x48, 0xaf } } + [Guids] # PCD scope GUID gNinetySixBoardsTokenSpaceGuid =3D { 0xe0d2f33a, 0xb7dd, 0x4a69, { 0xb6,= 0x76, 0xda, 0xe8, 0xa4, 0x17, 0xa7, 0xb5 } } --=20 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Mon Dec 23 05:20:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 151914901711092.7712489803838; Tue, 20 Feb 2018 09:50:17 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5786F220F33DA; Tue, 20 Feb 2018 09:44:10 -0800 (PST) Received: from mail-wr0-x241.google.com (mail-wr0-x241.google.com [IPv6:2a00:1450:400c:c0c::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id DA45821CF1CF3 for ; Tue, 20 Feb 2018 09:44:07 -0800 (PST) Received: by mail-wr0-x241.google.com with SMTP id p104so15482035wrc.12 for ; Tue, 20 Feb 2018 09:50:06 -0800 (PST) Received: from localhost.localdomain ([105.149.187.179]) by smtp.gmail.com with ESMTPSA id u63sm18282208wrc.26.2018.02.20.09.50.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 09:50:03 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::241; helo=mail-wr0-x241.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mugOs5n6PaJbGQvxVaCLOln8APdd3/1MEwgcUf/WoiE=; b=a60cpkRXeAvZhUGhbHUZppVBJWkKgXYJsreuA2gFVOJQF7KyZ04mYjkoW/BFSqn2Zv FSbQbFhhbV+rhY4fKo8q0i+jGWAA+yUKRAYFTsPv11HiFqzmzVBUHq4TtFBOURVGu9wP BaSSGTbs43fSnoErC/6wgqCaakxiMJdJcmy7w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mugOs5n6PaJbGQvxVaCLOln8APdd3/1MEwgcUf/WoiE=; b=XAYNet9bQychXG9MMM2reTFfcShoz7BSVxB/GQkAcRTtV/EVpJvsdtkLn8jPUlspir EaanrKeubUHiM0hEd4faig/9LTbVeSTQVSx5YZzVECtG8pvxmWSJjlBDV1ErggHaPPKk MqpKeZaTh1qqqbLbXo5rRYa569G8ukNwU7WdPd4SsRqmIfHt/Ei/hTJHowCp0K+3/Xqp ZmEBrqoR96zh9B7waAiUrC4lBb1KcKGG8k8f+sutzA3mxNTcu1i4RpwHAr1HcfJoGoDf GV9LwJyOF6JwIvRHbKZRU4+9NB8J4J4JkJdVjtH8/0w2/6mC9YHS79Jv7O9fVFcE2EcB MEUQ== X-Gm-Message-State: APf1xPDaEgVep4jTIgO+hj7TjEvBs1vC/XeZFt2ZgCtbpgQxTLtVoGZw pAICUlwEPCBY047TZcfA4IEkzvCxh9E= X-Google-Smtp-Source: AH8x2242eZTdFo1h5ekgR8PxgLOFJfEPPSy0qW+DJHj6xNaXrI2Fneh6CmQQppOlzLt7ZvJUv9DL4g== X-Received: by 10.223.197.197 with SMTP id v5mr407728wrg.161.1519149004819; Tue, 20 Feb 2018 09:50:04 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Tue, 20 Feb 2018 17:49:42 +0000 Message-Id: <20180220174944.525-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180220174944.525-1-ard.biesheuvel@linaro.org> References: <20180220174944.525-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH edk2-platforms v2 5/7] Platform/NinetySixBoards: add a driver for the Secure96 mezzanine board X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: leif.lindholm@linaro.org, Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a driver that describes the Secure96 mezzanine board, and exposes both the information required to describe it to the OS using a DT overlay, and to describe it to UEFI itself. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- Platform/NinetySixBoards/Secure96Dxe/Secure96.dts | 76 +++++++ Platform/NinetySixBoards/Secure96Dxe/Secure96.h | 26 +++ Platform/NinetySixBoards/Secure96Dxe/Secure96Dxe.c | 211 +++++++++++++++= +++++ Platform/NinetySixBoards/Secure96Dxe/Secure96Dxe.inf | 67 +++++++ 4 files changed, 380 insertions(+) diff --git a/Platform/NinetySixBoards/Secure96Dxe/Secure96.dts b/Platform/N= inetySixBoards/Secure96Dxe/Secure96.dts new file mode 100644 index 000000000000..08f59978c06f --- /dev/null +++ b/Platform/NinetySixBoards/Secure96Dxe/Secure96.dts @@ -0,0 +1,76 @@ +/** @file + * Copyright (c) 2018, Linaro Limited. All rights reserved. + * + * This program and the accompanying materials are licensed and made + * available under the terms and conditions of the BSD License which + * accompanies this distribution. The full text of the license may be + * found at http://opensource.org/licenses/bsd-license.php + * + * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR + * IMPLIED. + */ + +#include "Secure96.h" + +#define GPIO_PARENT_PLACEHOLDER_PHANDLE 0x0 + +/dts-v1/; +/plugin/; + +/ { + fragment@0 { + target-path =3D "I2C_PARENT_PLACEHOLDER_STRING"; + __overlay__ { + ATSHA204A_DT_NODENAME { + compatible =3D "atmel,atsha204a"; + reg =3D ; + }; + ATECC508A_DT_NODENAME { + compatible =3D "atmel,atecc508a"; + reg =3D ; + }; + }; + }; + + fragment@1 { + target-path =3D "SPI_PARENT_PLACEHOLDER_STRING"; + __overlay__ { + INFINEON_SLB9670_DT_NODENAME { + compatible =3D "infineon,slb9670"; + reg =3D ; + spi-max-frequency =3D <22500000>; + }; + }; + }; + + fragment@2 { + target-path =3D "/"; + __overlay__ { + gpio-leds { + compatible =3D "gpio-leds"; + + secure96-u1 { + gpios =3D ; + }; + secure96-u2 { + gpios =3D ; + }; + secure96-u3 { + gpios =3D ; + }; + secure96-u4 { + gpios =3D ; + }; + }; + }; + }; +}; diff --git a/Platform/NinetySixBoards/Secure96Dxe/Secure96.h b/Platform/Nin= etySixBoards/Secure96Dxe/Secure96.h new file mode 100644 index 000000000000..84b8aed13d1e --- /dev/null +++ b/Platform/NinetySixBoards/Secure96Dxe/Secure96.h @@ -0,0 +1,26 @@ +/** @file + + Copyright (c) 2018, Linaro, Ltd. All rights reserved.
+ + This program and the accompanying materials are licensed and made availa= ble + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. +**/ + +#ifndef _SECURE96_H_ +#define _SECURE96_H_ + +#define ATSHA204A_SLAVE_ADDRESS 0x60 +#define ATSHA204A_DT_NODENAME atsha204a@60 + +#define ATECC508A_SLAVE_ADDRESS 0x51 +#define ATECC508A_DT_NODENAME atecc508a@51 + +#define INFINEON_SLB9670_SPI_CS 0x0 +#define INFINEON_SLB9670_DT_NODENAME tpm@0 + +#endif // _SECURE96_H_ diff --git a/Platform/NinetySixBoards/Secure96Dxe/Secure96Dxe.c b/Platform/= NinetySixBoards/Secure96Dxe/Secure96Dxe.c new file mode 100644 index 000000000000..000f4b4abba4 --- /dev/null +++ b/Platform/NinetySixBoards/Secure96Dxe/Secure96Dxe.c @@ -0,0 +1,211 @@ +/** @file + 96boards Secure96 mezzanine board DXE driver. + + Copyright (c) 2018, Linaro, Ltd. All rights reserved.
+ + This program and the accompanying materials are licensed and made availa= ble + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Secure96.h" + +STATIC CONST UINT32 mI2cAtmelSha204aSlaveAddress[] =3D { + ATSHA204A_SLAVE_ADDRESS, + + // + // The Atmel AtSha204a has an annoying 'wake' mode where it will only wa= ke + // up if SDA is held low for a certain amount of time. Attempting to acc= ess + // a device at address 0x0 at 100 kHz should be sufficient to create this + // wake condition, so add address 0x0 to the slave addresses. + // + 0 +}; + +STATIC CONST EFI_I2C_DEVICE mI2c0Devices[] =3D { + { + &gAtSha204aI2cDeviceGuid, // DeviceGuid + 0, // DeviceIndex + 0, // HardwareRevision + 0, // I2C bus configuration + ARRAY_SIZE (mI2cAtmelSha204aSlaveAddress), // SlaveAddressCount + mI2cAtmelSha204aSlaveAddress // SlaveAddressArray + } +}; + +STATIC CONST CHAR8 mLedNodes[][46] =3D { + "/fragment@2/__overlay__/gpio-leds/secure96-u1", + "/fragment@2/__overlay__/gpio-leds/secure96-u2", + "/fragment@2/__overlay__/gpio-leds/secure96-u3", + "/fragment@2/__overlay__/gpio-leds/secure96-u4", +}; + +STATIC +VOID +SetOverlayFragmentTarget ( + VOID *Overlay, + CONST CHAR8 *NodeName, + CONST CHAR8 *Target + ) +{ + INT32 Node; + INT32 Err; + + Node =3D fdt_path_offset (Overlay, NodeName); + ASSERT (Node > 0); + + Err =3D fdt_setprop (Overlay, Node, "target-path", Target, + AsciiStrLen (Target) + 1); + if (Err) { + DEBUG ((DEBUG_ERROR, "%a: fdt_setprop() failed - %a\n", + __FUNCTION__, fdt_strerror (Err))); + } +} + +STATIC +VOID +FixupOverlay ( + VOID *Dtb, + VOID *Overlay + ) +{ + INT32 Node; + UINT32 GpioPhandle; + UINTN Idx; + UINT32 *GpioProp; + INT32 Err; + + // + // Set the correct GPIO phandle in the LED nodes + // + Node =3D fdt_path_offset (Dtb, FixedPcdGetPtr (PcdGpioParent)); + ASSERT (Node > 0); + + GpioPhandle =3D fdt_get_phandle (Dtb, Node); + if (!GpioPhandle) { + // + // Node has no phandle yet -> create one + // + GpioPhandle =3D 1 + fdt_get_max_phandle (Dtb); + ASSERT (GpioPhandle >=3D 1); + + Err =3D fdt_setprop_u32 (Dtb, Node, "phandle", GpioPhandle); + if (Err) { + DEBUG ((DEBUG_ERROR, + "%a: fdt_setprop_u32(.., .., \"phandle\", 0x%x) failed - %a\n", + __FUNCTION__, GpioPhandle, fdt_strerror (Err))); + } + } + + for (Idx =3D 0; Idx < ARRAY_SIZE (mLedNodes); Idx++) { + Node =3D fdt_path_offset (Overlay, mLedNodes[Idx]); + ASSERT (Node > 0); + + GpioProp =3D fdt_getprop_w (Overlay, Node, "gpios", NULL); + ASSERT (GpioProp !=3D NULL); + + *GpioProp =3D cpu_to_fdt32 (GpioPhandle); + } + + SetOverlayFragmentTarget (Overlay, "/fragment@0", + FixedPcdGetPtr (PcdI2c0Parent)); + + SetOverlayFragmentTarget (Overlay, "/fragment@1", + FixedPcdGetPtr (PcdSpiParent)); +} + +/** + Apply the mezzanine's DT overlay + + @param[in] This Pointer to the MEZZANINE_PROTOCOL instance. + @param[in,out] Dtb Pointer to the device tree blob + + @return EFI_SUCCESS Operation succeeded. + @return other An error has occurred. +**/ +STATIC +EFI_STATUS +ApplyDeviceTreeOverlay ( + IN MEZZANINE_PROTOCOL *This, + IN OUT VOID *Dtb + ) +{ + VOID *Overlay; + UINTN OverlaySize; + EFI_STATUS Status; + INT32 Err; + + // + // Load the raw overlay DTB image from the raw section of this FFS file. + // + Status =3D GetSectionFromFv (&gEfiCallerIdGuid, + EFI_SECTION_RAW, 0, &Overlay, &OverlaySize); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return EFI_NOT_FOUND; + } + + // + // Fix up unresolved references in the overlay. + // + FixupOverlay (Dtb, Overlay); + + // + // Merge the overlay with the DTB + // + Err =3D fdt_overlay_apply (Dtb, Overlay); + if (Err) { + DEBUG ((DEBUG_ERROR, "%a: fdt_overlay_apply() failed - %a\n", + __FUNCTION__, fdt_strerror (Err))); + return EFI_NOT_FOUND; + } + + return EFI_SUCCESS; +} + +STATIC MEZZANINE_PROTOCOL mMezzanine =3D { + ApplyDeviceTreeOverlay, + ARRAY_SIZE (mI2c0Devices), + 0, + mI2c0Devices, + NULL, + NULL, +}; + +EFI_STATUS +EFIAPI +Secure96DxeEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LS_CONNECTOR_PROTOCOL *LsConnector; + + Status =3D gBS->LocateProtocol (&gNinetySixBoardsLsConnectorProtocolGuid= , NULL, + (VOID **)&LsConnector); + ASSERT_EFI_ERROR (Status); + + if (LsConnector->MezzanineType !=3D MezzanineSecure96) { + return EFI_NOT_FOUND; + } + + return gBS->InstallProtocolInterface (&ImageHandle, + &gNinetySixBoardsMezzanineProtocolGuid, + EFI_NATIVE_INTERFACE, + &mMezzanine); +} diff --git a/Platform/NinetySixBoards/Secure96Dxe/Secure96Dxe.inf b/Platfor= m/NinetySixBoards/Secure96Dxe/Secure96Dxe.inf new file mode 100644 index 000000000000..e5686b9f5382 --- /dev/null +++ b/Platform/NinetySixBoards/Secure96Dxe/Secure96Dxe.inf @@ -0,0 +1,67 @@ +## @file +# +# Copyright (c) 2018, Linaro, Ltd. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD License +# which accompanies this distribution. The full text of the license may = be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IM= PLIED. +# +## + +[Defines] + INF_VERSION =3D 0x0001001A + BASE_NAME =3D Secure96Dxe + FILE_GUID =3D 31519ec4-65f1-4790-b223-aa9330dd75fd + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D Secure96DxeEntryPoint + +[Sources] + Secure96.dts + Secure96.h + Secure96Dxe.c + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + Platform/NinetySixBoards/NinetySixBoards.dec + Silicon/Atmel/AtSha204a/AtSha204a.dec + +[LibraryClasses] + BaseLib + DebugLib + DxeServicesLib + FdtLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiLib + +[Protocols] + gNinetySixBoardsLsConnectorProtocolGuid ## CONSUMES + gNinetySixBoardsMezzanineProtocolGuid ## PRODUCES + +[Guids] + gAtSha204aI2cDeviceGuid + gFdtTableGuid + +[FixedPcd] + gNinetySixBoardsTokenSpaceGuid.PcdGpioParent + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinF + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinG + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinH + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinI + gNinetySixBoardsTokenSpaceGuid.PcdGpioPolarity + gNinetySixBoardsTokenSpaceGuid.PcdI2c0Parent + gNinetySixBoardsTokenSpaceGuid.PcdSpiParent + +[Depex] + gNinetySixBoardsLsConnectorProtocolGuid + +[BuildOptions] + # dtc emits lots of spurious warnings for overlays + *_*_*_DTC_FLAGS =3D -q --=20 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Mon Dec 23 05:20:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1519149020907397.0957918528817; Tue, 20 Feb 2018 09:50:20 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C8794220F33CE; Tue, 20 Feb 2018 09:44:12 -0800 (PST) Received: from mail-wr0-x244.google.com (mail-wr0-x244.google.com [IPv6:2a00:1450:400c:c0c::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3EE6821FD73F2 for ; Tue, 20 Feb 2018 09:44:10 -0800 (PST) Received: by mail-wr0-x244.google.com with SMTP id n7so16834434wrn.5 for ; Tue, 20 Feb 2018 09:50:08 -0800 (PST) Received: from localhost.localdomain ([105.149.187.179]) by smtp.gmail.com with ESMTPSA id u63sm18282208wrc.26.2018.02.20.09.50.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 09:50:06 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::244; helo=mail-wr0-x244.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kjToITdSeV/ql6RH6cp91+Ht7EJVBNJzx2QYi+bVneM=; b=HdGf8r9yzTyXu7mfEjNfK+ZjYaCxWoStBszFyG4pcN6xKGBVxq5qplGtJNR7vr+P4h IALKQm/A59h3pqJt4Vj98Qv2zwJMvkobcIKAuhIw3jQnyI8rKumWGw1/FBeiQJ+lWmP0 JrhEHoY5iBoJaLB2yepDnWZIZdT8RksG1yFmc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kjToITdSeV/ql6RH6cp91+Ht7EJVBNJzx2QYi+bVneM=; b=oaKQ7VeIOJnWQOBNB9nqBGWfjUhOTGrVMLDQJdiXCx81cJno7P4x1n1CXiFE9/E8B1 cwc6taSVX8sj83MSz27bQy3q2/uYOvN33oZ0ZyJWo+RhRlj/gK9tI7lGFqZ32knj/0rC 4LqZj4p3IeZxzTkIDzQDSGNkwhxlivEhAi1jDUBYhuxdJV9h3gYmFMJHJHGjgNqhcgot Kx/xKInkcNgcl2qeVoOPX7fKXkOAICxNOYY4jzPM0qtIrxf4qrxTsrvKoKEP/cUCYV/Z aZeXw/5WZfCX1soFQPSXfTUCj96U40NW2o47HS2u0nOPwHLh0WSMRBQ5uE2tk2vcRG7Z N5XQ== X-Gm-Message-State: APf1xPATRTePo5lfreDegHJTBz7DgnLwcIhaJgt8I9pW5hNNNSyFhoBy Yg78rL6YuyRR9HmOVVr6hEQYRrZz8Kg= X-Google-Smtp-Source: AH8x2240wxZYv6snMorH73bNycEJ4/Swi4n0VYEzhHbPQfMwGEoTiYLHGb1laBXPRplEgx8FRzbYpg== X-Received: by 10.223.185.112 with SMTP id b45mr410689wrg.159.1519149006827; Tue, 20 Feb 2018 09:50:06 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Tue, 20 Feb 2018 17:49:43 +0000 Message-Id: <20180220174944.525-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180220174944.525-1-ard.biesheuvel@linaro.org> References: <20180220174944.525-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH edk2-platforms v2 6/7] Platform/NinetySixBoards: add core driver for LS connector and config X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: leif.lindholm@linaro.org, Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This adds a driver that manages the 96boards LS connector, i.e, it installs a HII page to configure the type of mezzanine that is installed in the slot, and it exposes this information via the LS connector protocol. It is also in charge of applying the overlay to the platform device tree at end of DXE. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- Platform/NinetySixBoards/Include/Guid/FormSet.h | 23 ++ Platform/NinetySixBoards/NinetySixBoards.dec | 3 + Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsDxe.c | 221 += +++++++++++++++++++ Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsDxe.h | 32 += ++ Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsDxe.inf | 57 += ++++ Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsHii.uni | 27 += ++ Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsHii.vfr | 51 += ++++ 7 files changed, 414 insertions(+) diff --git a/Platform/NinetySixBoards/Include/Guid/FormSet.h b/Platform/Nin= etySixBoards/Include/Guid/FormSet.h new file mode 100644 index 000000000000..db16657f0848 --- /dev/null +++ b/Platform/NinetySixBoards/Include/Guid/FormSet.h @@ -0,0 +1,23 @@ +/** @file + + Copyright (c) 2018, Linaro Limited. All rights reserved. + + This program and the accompanying materials are licensed and made availa= ble + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#ifndef __NINETY_SIX_BOARDS_FORMSET_H__ +#define __NINETY_SIX_BOARDS_FORMSET_H__ + +#define NINETY_SIX_BOARDS_FORMSET_GUID \ + { 0x7500c9d2, 0x9203, 0x4a37, { 0x84, 0xbb, 0x92, 0xa9, 0xce, 0x34, 0x38= , 0xbd } } + +extern EFI_GUID gNinetySixBoardsFormsetGuid; + +#endif // __NINETY_SIX_BOARDS_FORMSET_H__ diff --git a/Platform/NinetySixBoards/NinetySixBoards.dec b/Platform/Ninety= SixBoards/NinetySixBoards.dec index 5c3fe43dbb24..e7d1705d47ff 100644 --- a/Platform/NinetySixBoards/NinetySixBoards.dec +++ b/Platform/NinetySixBoards/NinetySixBoards.dec @@ -37,6 +37,9 @@ [Guids] gNinetySixBoardsI2c1MasterGuid =3D { 0xcf64ac46, 0xd0be, 0x4a69, { 0x90,= 0xa2, 0xf2, 0x82, 0x5b, 0x92, 0x25, 0x61 } } gNinetySixBoardsSpiMasterGuid =3D { 0x9703fd99, 0xe638, 0x42b8, { 0xab, = 0x81, 0x52, 0x61, 0x1b, 0xf7, 0xf7, 0x5d } } =20 + # GUID for the HII configuration form + gNinetySixBoardsFormsetGuid =3D { 0x7500c9d2, 0x9203, 0x4a37, { 0x84, 0x= bb, 0x92, 0xa9, 0xce, 0x34, 0x38, 0xbd } } + [PcdsFixedAtBuild] # ASCII DT paths to the I2C parent nodes of the 96boards LS connector gNinetySixBoardsTokenSpaceGuid.PcdI2c0Parent|""|VOID*|0x00000001 diff --git a/Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsDxe= .c b/Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsDxe.c new file mode 100644 index 000000000000..6dc5f549e560 --- /dev/null +++ b/Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsDxe.c @@ -0,0 +1,221 @@ +/** @file + + Copyright (c) 2018, Linaro, Ltd. All rights reserved. + + This program and the accompanying materials are licensed and made availa= ble + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "NinetySixBoardsDxe.h" + +extern UINT8 NinetySixBoardsHiiBin[]; +extern UINT8 NinetySixBoardsDxeStrings[]; + +typedef struct { + VENDOR_DEVICE_PATH VendorDevicePath; + EFI_DEVICE_PATH_PROTOCOL End; +} HII_VENDOR_DEVICE_PATH; + +STATIC HII_VENDOR_DEVICE_PATH mNinetySixBoardsDxeVendorDevicePath =3D { + { + { + HARDWARE_DEVICE_PATH, + HW_VENDOR_DP, + { + (UINT8) (sizeof (VENDOR_DEVICE_PATH)), + (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) + } + }, + NINETY_SIX_BOARDS_FORMSET_GUID + }, + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { + (UINT8) (END_DEVICE_PATH_LENGTH), + (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8) + } + } +}; + +STATIC LS_CONNECTOR_PROTOCOL mLsConnector; +STATIC EFI_EVENT EndOfDxeEvent; + +STATIC +EFI_STATUS +InstallHiiPages ( + VOID + ) +{ + EFI_STATUS Status; + EFI_HII_HANDLE HiiHandle; + EFI_HANDLE DriverHandle; + + DriverHandle =3D NULL; + Status =3D gBS->InstallMultipleProtocolInterfaces (&DriverHandle, + &gEfiDevicePathProtocolGuid, + &mNinetySixBoardsDxeVendorDevicePath, + NULL); + if (EFI_ERROR (Status)) { + return Status; + } + + HiiHandle =3D HiiAddPackages (&gNinetySixBoardsFormsetGuid, + DriverHandle, + NinetySixBoardsDxeStrings, + NinetySixBoardsHiiBin, + NULL); + + if (HiiHandle =3D=3D NULL) { + gBS->UninstallMultipleProtocolInterfaces (DriverHandle, + &gEfiDevicePathProtocolGuid, + &mNinetySixBoardsDxeVendorDevicePath, + NULL); + return EFI_OUT_OF_RESOURCES; + } + return EFI_SUCCESS; +} + +STATIC +VOID +EFIAPI +ApplyDeviceTreeOverlay ( + EFI_EVENT Event, + VOID *Context + ) +{ + VOID *Dtb; + MEZZANINE_PROTOCOL *Mezzanine; + EFI_STATUS Status; + + // + // Find the DTB in the configuration table array. If it isn't there, just + // bail without an error: we may be running on an ACPI platform even if + // this driver does not support it [yet]. + // + Status =3D EfiGetSystemConfigurationTable (&gFdtTableGuid, &Dtb); + if (Status =3D=3D EFI_NOT_FOUND) { + return; + } + ASSERT_EFI_ERROR (Status); + + Status =3D gBS->LocateProtocol (&gNinetySixBoardsMezzanineProtocolGuid, = NULL, + (VOID **)&Mezzanine); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: no mezzanine driver active\n", __FUNCTION__)); + return; + } + + Status =3D Mezzanine->ApplyDeviceTreeOverlay (Mezzanine, Dtb); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "%a: failed to apply DT overlay - %r\n", __FUNCTIO= N__, + Status)); + } +} + +/** + The entry point for NinetySixBoardsDxe driver. + + @param[in] ImageHandle The image handle of the driver. + @param[in] SystemTable The system table. + + @retval EFI_ALREADY_STARTED The driver already exists in system. + @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack = of + resources. + @retval EFI_SUCCES All the related protocols are installed = on + the driver. + +**/ +EFI_STATUS +EFIAPI +EntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + NINETY_SIX_BOARDS_CONFIG_DATA ConfigData; + UINTN BufferSize; + + // + // Get the current config settings from the EFI variable. + // + BufferSize =3D sizeof (ConfigData); + Status =3D gRT->GetVariable (NINETY_SIX_BOARDS_CONFIG_VARIABLE_NAME, + &gNinetySixBoardsFormsetGuid, NULL, &BufferSize, &Config= Data); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: no config data found\n", __FUNCTION__)); + ConfigData.MezzanineType =3D MEZZANINE_NONE; + } + + if (!EFI_ERROR (Status) && + ConfigData.MezzanineType > MEZZANINE_MAX) { + DEBUG ((DEBUG_WARN, + "%a: invalid value for %s, defaulting to MEZZANINE_NONE\n", + __FUNCTION__, NINETY_SIX_BOARDS_CONFIG_VARIABLE_NAME)); + ConfigData.MezzanineType =3D MEZZANINE_NONE; + Status =3D EFI_INVALID_PARAMETER; // trigger setvar below + } + + // + // Write the newly selected value back to the variable store. + // + if (EFI_ERROR (Status)) { + ZeroMem (&ConfigData.Reserved, sizeof (ConfigData.Reserved)); + Status =3D gRT->SetVariable (NINETY_SIX_BOARDS_CONFIG_VARIABLE_NAME, + &gNinetySixBoardsFormsetGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_A= CCESS, + sizeof (ConfigData), &ConfigData); + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: gRT->SetVariable () failed - %r\n", + __FUNCTION__, Status)); + return Status; + } + } + + switch (ConfigData.MezzanineType) { + case MEZZANINE_SECURE96: + mLsConnector.MezzanineType =3D MezzanineSecure96; + break; + default: + mLsConnector.MezzanineType =3D MezzanineUnknown; + } + + Status =3D gBS->InstallProtocolInterface (&ImageHandle, + &gNinetySixBoardsLsConnectorProtocolGuid, + EFI_NATIVE_INTERFACE, + &mLsConnector); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + ApplyDeviceTreeOverlay, + NULL, + &gEfiEndOfDxeEventGroupGuid, + &EndOfDxeEvent); + ASSERT_EFI_ERROR (Status); + + return InstallHiiPages (); +} diff --git a/Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsDxe= .h b/Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsDxe.h new file mode 100644 index 000000000000..e94a115a5929 --- /dev/null +++ b/Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsDxe.h @@ -0,0 +1,32 @@ +/** @file + + Copyright (c) 2018, Linaro Limited. All rights reserved. + + This program and the accompanying materials are licensed and made availa= ble + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#ifndef __NINETY_SIX_BOARDS_DXE_H__ +#define __NINETY_SIX_BOARDS_DXE_H__ + +#include +#include + +#define MEZZANINE_NONE 0x0 +#define MEZZANINE_SECURE96 0x1 +#define MEZZANINE_MAX 0x1 + +#define NINETY_SIX_BOARDS_CONFIG_VARIABLE_NAME L"NinetySixBoardsConfig" + +typedef struct { + UINT8 MezzanineType; + UINT8 Reserved[7]; +} NINETY_SIX_BOARDS_CONFIG_DATA; + +#endif // __NINETY_SIX_BOARDS_DXE_H__ diff --git a/Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsDxe= .inf b/Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsDxe.inf new file mode 100644 index 000000000000..5c6f863e8db4 --- /dev/null +++ b/Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsDxe.inf @@ -0,0 +1,57 @@ +## @file +# +# Copyright (c) 2018, Linaro, Ltd. All rights reserved.
+# +# This program and the accompanying materials are licensed and made +# available under the terms and conditions of the BSD License which +# accompanies this distribution. The full text of the license may be +# found at http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR +# IMPLIED. +# +## + +[Defines] + INF_VERSION =3D 0x0001001A + BASE_NAME =3D NinetySixBoardsDxe + FILE_GUID =3D 3f68e889-cb77-4efc-bc84-afa0a64ad26e + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D EntryPoint + +[Sources] + NinetySixBoardsDxe.c + NinetySixBoardsDxe.h + NinetySixBoardsHii.vfr + NinetySixBoardsHii.uni + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + Platform/NinetySixBoards/NinetySixBoards.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + HiiLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiLib + UefiRuntimeServicesTableLib + +[Protocols] + gNinetySixBoardsLsConnectorProtocolGuid ## PRODUCES + gNinetySixBoardsMezzanineProtocolGuid ## CONSUMES + +[Guids] + gEfiEndOfDxeEventGroupGuid + gFdtTableGuid + gNinetySixBoardsFormsetGuid + +[Depex] + gEfiVariableArchProtocolGuid AND + gEfiVariableWriteArchProtocolGuid diff --git a/Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsHii= .uni b/Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsHii.uni new file mode 100644 index 000000000000..23f4c5859207 --- /dev/null +++ b/Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsHii.uni @@ -0,0 +1,27 @@ +/** @file + + Copyright (c) 2018, Linaro, Ltd. All rights reserved. + + This program and the accompanying materials are licensed and made availa= ble + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#langdef en-US "English" + +#string STR_FORM_SET_TITLE #language en-US "96boards Mezzanine= options" +#string STR_FORM_SET_TITLE_HELP #language en-US "Configure the inst= alled 96boards mezzanine" + +#string STR_MAIN_FORM_TITLE #language en-US "96boards Mezzanine= options" +#string STR_NULL_STRING #language en-US "" + +#string STR_MEZZANINE_SELECT_PROMPT #language en-US "96boards mezzanine" +#string STR_MEZZANINE_SELECT_HELP #language en-US "The type of mezzan= ine board plugged into the 96boards LS connector" + +#string STR_MEZZANINE_NONE #language en-US "None/Unknown" +#string STR_MEZZANINE_SECURE96 #language en-US "Secure96" diff --git a/Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsHii= .vfr b/Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsHii.vfr new file mode 100644 index 000000000000..7e78c9cfa22f --- /dev/null +++ b/Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsHii.vfr @@ -0,0 +1,51 @@ +/** @file + + Copyright (c) 2018, Linaro, Ltd. All rights reserved. + + This program and the accompanying materials are licensed and made availa= ble + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#include "NinetySixBoardsDxe.h" + +// +// EFI Variable attributes +// +#define EFI_VARIABLE_NON_VOLATILE 0x00000001 +#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002 +#define EFI_VARIABLE_RUNTIME_ACCESS 0x00000004 +#define EFI_VARIABLE_READ_ONLY 0x00000008 + +formset + guid =3D NINETY_SIX_BOARDS_FORMSET_GUID, + title =3D STRING_TOKEN(STR_FORM_SET_TITLE), + help =3D STRING_TOKEN(STR_FORM_SET_TITLE_HELP), + classguid =3D EFI_HII_PLATFORM_SETUP_FORMSET_GUID, + + efivarstore NINETY_SIX_BOARDS_CONFIG_DATA, + attribute =3D EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLAT= ILE, // EFI variable attributes + name =3D NinetySixBoardsConfig, + guid =3D NINETY_SIX_BOARDS_FORMSET_GUID; + + form formid =3D 0x1000, + title =3D STRING_TOKEN(STR_MAIN_FORM_TITLE); + + oneof varid =3D NinetySixBoardsConfig.MezzanineType, + prompt =3D STRING_TOKEN(STR_MEZZANINE_SELECT_PROMPT), + help =3D STRING_TOKEN(STR_MEZZANINE_SELECT_HELP), + flags =3D NUMERIC_SIZE_1 | INTERACTIVE | RESET_REQUIRED, + option text =3D STRING_TOKEN(STR_MEZZANINE_NONE), value =3D MEZZAN= INE_NONE, flags =3D DEFAULT; + option text =3D STRING_TOKEN(STR_MEZZANINE_SECURE96), value =3D ME= ZZANINE_SECURE96, flags =3D 0; + endoneof; + + subtitle text =3D STRING_TOKEN(STR_NULL_STRING); + + endform; + +endformset; --=20 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Mon Dec 23 05:20:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1519149024930332.3596379786575; Tue, 20 Feb 2018 09:50:24 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2E5EC220F33F4; Tue, 20 Feb 2018 09:44:14 -0800 (PST) Received: from mail-wr0-x243.google.com (mail-wr0-x243.google.com [IPv6:2a00:1450:400c:c0c::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id EBC8821FD73E6 for ; Tue, 20 Feb 2018 09:44:11 -0800 (PST) Received: by mail-wr0-x243.google.com with SMTP id u49so12177170wrc.10 for ; Tue, 20 Feb 2018 09:50:10 -0800 (PST) Received: from localhost.localdomain ([105.149.187.179]) by smtp.gmail.com with ESMTPSA id u63sm18282208wrc.26.2018.02.20.09.50.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 09:50:07 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::243; helo=mail-wr0-x243.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=B+NhtysjwTe0RVa7aV+wMjT840a+fwn2z7JdoF9U1VY=; b=HTRqp6dl9mb5xa6gXgM8vyH9mGNo+ESjy7Gp3f923zeMOdT6fwfwLju120BHyeNYeI 114InPM8kg+tNWV5Mgt0L3XWadbCrAaKPcg4z7+1jH3mMNbGt+LPA0+K36BuEGo3DNN5 NKrETJhr/dPRROpBhMbVkLGIe+hFhQFFzjrVg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=B+NhtysjwTe0RVa7aV+wMjT840a+fwn2z7JdoF9U1VY=; b=bTtCBJIHoR7v7Aa208bzA7D0F2NCVn5s+0970lxr0ZVc1wx1hJpf7B0q28aGPoyMIB oxlXaoyUPT8VfjS7OFZLQNuYhUYPGx+6+3k6KFH5iallgnyVNldIx49I311+LtU3Ef3K 3qvv1H93m2/Fm1weqilwpqHwsK4h/+XGqlMm8Ai1yhd1DzTjAoWZgMiTD6U0nAgdkbzs k7O4FC+nlwA+wuh6X7k9WkH8PZSDyIheF33fvWz43MXUe+vtencUKn/frSig5vop5uCV dR1xl6p01LiFqdfJACsTmKKCQqSqboCl5RuU+D/FWHzmWDjW3EcFJl7VN1/Qdm/Bh/OY nYAA== X-Gm-Message-State: APf1xPDz1F0t//iLbJsV/XK124antowcBX+21PXI8Quu+4DnIZ2/hZSg fD1XlLT5rt+fUW8HX7H9HANEZFg9c3o= X-Google-Smtp-Source: AH8x224tQnXPeZaV8XAZ8BhRyYl50zu4c4bpCvT0MWQAjvlhBmn6Wz70K8IcPPl0K2Ynt3rAmRX0Ww== X-Received: by 10.28.51.6 with SMTP id z6mr891831wmz.26.1519149008903; Tue, 20 Feb 2018 09:50:08 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Tue, 20 Feb 2018 17:49:44 +0000 Message-Id: <20180220174944.525-8-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180220174944.525-1-ard.biesheuvel@linaro.org> References: <20180220174944.525-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH edk2-platforms v2 7/7] Platform/Socionext/DeveloperBox: add 96boards mezzanine support X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: leif.lindholm@linaro.org, Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Wire up the various drivers for the 96boards LS connector and the optional Secure96 mezzanine board. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- Platform/Socionext/DeveloperBox/DeveloperBox.dsc | 34 +++++= +++++++++++++++ Platform/Socionext/DeveloperBox/DeveloperBox.fdf | 10 ++++++ Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.c | 9 ++++++ Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.inf | 2 ++ 4 files changed, 55 insertions(+) diff --git a/Platform/Socionext/DeveloperBox/DeveloperBox.dsc b/Platform/So= cionext/DeveloperBox/DeveloperBox.dsc index 9c95618a20fe..39f40534bb39 100644 --- a/Platform/Socionext/DeveloperBox/DeveloperBox.dsc +++ b/Platform/Socionext/DeveloperBox/DeveloperBox.dsc @@ -33,6 +33,9 @@ [Defines] [BuildOptions] RELEASE_*_*_CC_FLAGS =3D -DMDEPKG_NDEBUG -U_FORTIFY_SOURCE -D_FORTIFY_S= OURCE=3D0 =20 + # add ample padding to the DTC so we can apply 96boards mezzanine overla= ys + *_*_*_DTC_FLAGS =3D -p 1024 + [BuildOptions.common.EDKII.DXE_CORE,BuildOptions.common.EDKII.DXE_DRIVER,B= uildOptions.common.EDKII.UEFI_DRIVER,BuildOptions.common.EDKII.UEFI_APPLICA= TION] GCC:*_*_*_DLINK_FLAGS =3D -z common-page-size=3D0x1000 =20 @@ -398,6 +401,28 @@ [PcdsFixedAtBuild.common] !endif gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareRevision|$(BUILD_NUMBER) =20 + # + # 96boards mezzanine support + # + gNinetySixBoardsTokenSpaceGuid.PcdI2c0Parent|"/i2c@51210000" + gNinetySixBoardsTokenSpaceGuid.PcdI2c0BusFrequencyHz|100000 + gNinetySixBoardsTokenSpaceGuid.PcdSpiParent|"/spi@54810000" + gNinetySixBoardsTokenSpaceGuid.PcdGpioParent|"/gpio@51000000" + gNinetySixBoardsTokenSpaceGuid.PcdGpioPolarity|0 + + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinA|10 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinB|11 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinC|12 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinD|13 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinE|18 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinF|19 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinG|20 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinH|21 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinI|22 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinJ|23 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinK|24 + gNinetySixBoardsTokenSpaceGuid.PcdGpioPinL|25 + [PcdsPatchableInModule] gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution|0 gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution|0 @@ -644,8 +669,17 @@ [Components.common] SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.= inf =20 # + # 96board mezzanine support + # + Platform/NinetySixBoards/Secure96Dxe/Secure96Dxe.inf + Silicon/Atmel/AtSha204a/AtSha204aDxe.inf + Platform/NinetySixBoards/NinetySixBoardsI2cDxe/NinetySixBoardsI2cDxe.inf + Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsDxe.inf + + # # I2C # Silicon/Socionext/SynQuacer/Drivers/SynQuacerI2cDxe/SynQuacerI2cDxe.inf + MdeModulePkg/Bus/I2c/I2cDxe/I2cDxe.inf =20 Platform/Socionext/DeveloperBox/OsInstallerMenuDxe/OsInstallerMenuDxe.inf diff --git a/Platform/Socionext/DeveloperBox/DeveloperBox.fdf b/Platform/So= cionext/DeveloperBox/DeveloperBox.fdf index c2bc5aa85739..636bfaa3dd29 100644 --- a/Platform/Socionext/DeveloperBox/DeveloperBox.fdf +++ b/Platform/Socionext/DeveloperBox/DeveloperBox.fdf @@ -237,9 +237,18 @@ [FV.FvMain] } =20 # + # 96board mezzanine support + # + INF Platform/NinetySixBoards/Secure96Dxe/Secure96Dxe.inf + INF Platform/NinetySixBoards/NinetySixBoardsI2cDxe/NinetySixBoardsI2cDxe= .inf + INF Silicon/Atmel/AtSha204a/AtSha204aDxe.inf + INF Platform/NinetySixBoards/NinetySixBoardsDxe/NinetySixBoardsDxe.inf + + # # I2C # INF Silicon/Socionext/SynQuacer/Drivers/SynQuacerI2cDxe/SynQuacerI2cDxe.= inf + INF MdeModulePkg/Bus/I2c/I2cDxe/I2cDxe.inf =20 INF Platform/Socionext/DeveloperBox/OsInstallerMenuDxe/OsInstallerMenuDx= e.inf =20 @@ -430,6 +439,7 @@ [Rule.Common.DXE_DRIVER] DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NA= ME).depex PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi UI STRING=3D"$(MODULE_NAME)" Optional + RAW BIN Optional |.dtb } =20 [Rule.Common.DXE_RUNTIME_DRIVER] diff --git a/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.c = b/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.c index aab830dc3a5a..11c0648c2ca0 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.c +++ b/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.c @@ -313,6 +313,15 @@ PlatformDxeEntryPoint ( &Handle); ASSERT_EFI_ERROR (Status); =20 + // + // Install the gNinetySixBoardsI2c0MasterGuid GUID onto the same handle, + // identifying I2C #1 on our SoC as I2C #0 on the 96boards low speed con= nector + // + Status =3D gBS->InstallProtocolInterface (&Handle, + &gNinetySixBoardsI2c0MasterGuid, + EFI_NATIVE_INTERFACE, NULL); + ASSERT_EFI_ERROR (Status); + SmmuEnableCoherentDma (); SetMmioTimerFrequency (); =20 diff --git a/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.in= f b/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.inf index 49d9deee57ea..4ba8bf4f761e 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.inf +++ b/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.inf @@ -34,6 +34,7 @@ [Packages] EmbeddedPkg/EmbeddedPkg.dec MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec + Platform/NinetySixBoards/NinetySixBoards.dec Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.dec Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.dec Silicon/Socionext/SynQuacer/SynQuacer.dec @@ -56,6 +57,7 @@ [LibraryClasses] UefiRuntimeServicesTableLib =20 [Guids] + gNinetySixBoardsI2c0MasterGuid gEfiHiiPlatformSetupFormsetGuid gFdtTableGuid gNetsecNonDiscoverableDeviceGuid --=20 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel