From patchwork Tue Feb 20 17:49:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 128939 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp4897966ljc; Tue, 20 Feb 2018 09:50:00 -0800 (PST) X-Google-Smtp-Source: AH8x227852of0UdchA8AwJCS/HVuyPLKajkutBxPDgPBSdb/ZJPYB4tF8MXuLV6Sj7rQEReyyYQx X-Received: by 10.99.123.74 with SMTP id k10mr327436pgn.217.1519149000572; Tue, 20 Feb 2018 09:50:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519149000; cv=none; d=google.com; s=arc-20160816; b=jYkxC95rZ+aAzBwW/Z5mYvh2v+4qGC68E3eYAXLer3DfnYpKfva2MVv+S76VD4XJrj 7t1hvFughIUeHSVWF5aQEFx4fMm2CEw9JgObUa1uOImIxIDlaDUoTOH7YGRWm3bTQR8M Pm8ojLU7MdMbiRshrTtH4tgl5y/adSNnD+V9fIGrPDNQjuP6hk9ZJu/PX/1YvqhN2byv 1oJYbpPhFQmGPRixy6QRLwaI1zKuKdUJhfdx3BTvXbFsAVr1VNRCmgmZKMHaOdksAQs1 BasrPjYnxZIOLLBRWsuPElqPPzHALcdmZz9EwyQ7Wqn7/lO0mjzlOuaZWzP8Y84YV433 F2lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=CQ26Z9f37S8q2lha7y+6CQ+28TGHIy9J1FhmJxJDP54=; b=U4DzjbFJFEVK5r8lD41GtPKOrpQBhihCUKsHivPOLN9jH8i7raGAGhP54eP2j7MmjY cuxxn8kvGa9H9JJx4XGZieFiwMvf37FEzszTsnfaRdFhRhbaYV7HUQR2K24n4tR1ILS2 w9cRZtW5EmvrwgFwNIUJNPQ6goGDDVBcT7Wcejxi4k5fYs/tV6Ke0m4reUMqSzDM13nY 0FZejvd+AI8QckRHdnraTnBMPyEo/jGF6REQFbpsEBziG21lZ0L1cgXo3fUrzTKbhkt+ qWmzGsNVouJat2i200dezfZ2Y8jxp71u1yWZKjmGwx7kUVxyI8y52zaGumtHK6s3YwQt hq7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fgRMlN7c; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id x62si173299pgd.611.2018.02.20.09.50.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 09:50:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fgRMlN7c; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.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 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) 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-Received: by 10.223.195.97 with SMTP id e30mr400755wrg.181.1519148996514; Tue, 20 Feb 2018 09:49:56 -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) 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 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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 --- 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(+) -- 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Leif Lindholm diff --git a/Silicon/Atmel/AtSha204a/AtSha204a.dec b/Silicon/Atmel/AtSha204a/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 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] + DEC_SPECIFICATION = 0x0001001A + PACKAGE_NAME = AtSha204a + PACKAGE_GUID = 86085a5b-355b-4e72-92ab-fc3e1d71c9ad + PACKAGE_VERSION = 0.1 + +[Guids] + gAtSha204aI2cDeviceGuid = { 0x52e9b64b, 0x4ec1, 0x4bd6, { 0x9e, 0x1c, 0x6d, 0xac, 0xef, 0x35, 0x18, 0x21 } } diff --git a/Silicon/Atmel/AtSha204a/AtSha204aDriver.c b/Silicon/Atmel/AtSha204a/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 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 "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 instance. + @param[in,out] AlgorithmListSize On input, the size in bytes of AlgorithmList + On output with a return code of EFI_SUCCESS, + 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 list. + @param[out] AlgorithmList A caller-allocated memory buffer filled by + the driver with one EFI_RNG_ALGORITHM + element for each supported RNG algorithm. + The list must not change across multiple + 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 incorrect. + @retval EFI_BUFFER_TOO_SMALL The buffer RNGAlgorithmList is too small 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 = sizeof (EFI_GUID); + + if (*AlgorithmListSize < Size) { + *AlgorithmListSize = Size; + return EFI_BUFFER_TOO_SMALL; + } + + CopyGuid (AlgorithmList, &gEfiRngAlgorithmRaw); + *AlgorithmListSize = 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 instance. + @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 available to + satisfy the length requested by + RNGValueLength. + @retval EFI_INVALID_PARAMETER RNGValue is NULL or RNGValueLength is zero. + +**/ +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 != NULL && !CompareGuid (Algorithm, &gEfiRngAlgorithmRaw)) { + return EFI_UNSUPPORTED; + } + + AtSha204a = ATSHA204A_DEV_FROM_THIS (This); + + Request.OperationCount = 1; + Request.Operation.Flags = 0; + + Command.Command = ATSHA204A_COMMAND; + Command.Count = sizeof (Command) - 1; + Command.Opcode = ATSHA204A_OPCODE_RANDOM; + Command.Param1 = 0; + Command.Param2 = 0; + Command.Crc = OPCODE_COMMAND_PACKET_CRC; + + Response.OperationCount = 1; + Response.Operation.Flags = I2C_FLAG_READ; + Response.Operation.LengthInBytes = sizeof (Result); + Response.Operation.Buffer = (VOID *)&Result; + + Retries = 0; + while (ValueLength > 0) { + // + // The AtSha204a will go back to sleep right in the middle of a transaction + // 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 0x0. + // + Request.Operation.LengthInBytes = 0; + Status = 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 = sizeof (Command); + Request.Operation.Buffer = (VOID *)&Command; + Status = AtSha204a->I2cIo->QueueRequest (AtSha204a->I2cIo, 0, NULL, + (VOID *)&Request, NULL); + if (EFI_ERROR (Status)) { + if (++Retries <= MAX_RETRIES) { + continue; + } + DEBUG ((DEBUG_ERROR, "%a: I2C request transfer failed, Status == %r\n", + __FUNCTION__, Status)); + return EFI_DEVICE_ERROR; + } + + gBS->Stall (50 * 1000); // 50 ms max execution time for RANDOM opcode + + Status = AtSha204a->I2cIo->QueueRequest (AtSha204a->I2cIo, 0, NULL, + (VOID *)&Response, NULL); + if (EFI_ERROR (Status)) { + if (++Retries <= MAX_RETRIES) { + continue; + } + DEBUG ((DEBUG_ERROR, "%a: I2C response transfer failed, Status == %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 <= 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 += ATSHA204A_OUTPUT_SIZE; + ValueLength -= ATSHA204A_OUTPUT_SIZE; + Retries = 0; + } + return EFI_SUCCESS; +} + +EFI_STATUS +AtSha204aInit ( + IN EFI_HANDLE DriverBindingHandle, + IN EFI_HANDLE ControllerHandle + ) +{ + EFI_STATUS Status; + ATSHA204A_DEV *AtSha204a; + + Status = gBS->AllocatePool (EfiBootServicesData, sizeof (ATSHA204A_DEV), + (VOID **) &AtSha204a); + if (EFI_ERROR (Status)) { + return EFI_OUT_OF_RESOURCES; + } + + AtSha204a->Signature = ATSHA204A_DEV_SIGNATURE; + AtSha204a->Rng.GetInfo = AtSha240aGetInfo; + AtSha204a->Rng.GetRNG = AtSha240aGetRNG; + + // + // Open I2C I/O Protocol + // + Status = gBS->OpenProtocol (ControllerHandle, + &gEfiI2cIoProtocolGuid, + (VOID **)&AtSha204a->I2cIo, + DriverBindingHandle, + ControllerHandle, + EFI_OPEN_PROTOCOL_BY_DRIVER); + if (EFI_ERROR (Status)) { + goto ErrorFreeDev; + } + + Status = gBS->InstallProtocolInterface (&ControllerHandle, + &gEfiRngProtocolGuid, + EFI_NATIVE_INTERFACE, + &AtSha204a->Rng); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, + "Failed to install RNG protocol interface (Status == %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 = gBS->HandleProtocol (ControllerHandle, + &gEfiRngProtocolGuid, + (VOID **)&Rng); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return Status; + } + + AtSha204a = ATSHA204A_DEV_FROM_THIS (Rng); + + Status = gBS->UninstallProtocolInterface (ControllerHandle, + &gEfiRngProtocolGuid, + Rng); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = 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/AtSha204a/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 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. + +**/ + +#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/AtSha204a/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 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 = 0x0001001A + BASE_NAME = AtSha204aDxe + FILE_GUID = 8b8f683b-f376-4ba0-b8d7-b4bbd30319cc + MODULE_TYPE = UEFI_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = EntryPoint + UNLOAD_IMAGE = UnloadImage + +# +# VALID_ARCHITECTURES = 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/AtSha204a/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 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 "AtSha204aDriver.h" + +STATIC EFI_UNICODE_STRING_TABLE mAtSha204aDriverNameTable[] = { + { + "en", + (CHAR16 *)L"AtSha204a RNG I2C driver" + }, + { } +}; + +STATIC EFI_UNICODE_STRING_TABLE mAtSha204aControllerNameTable[] = { + { + "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 of 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 specified + 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_PROTOCOL 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 caller 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 format. + + @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 specified by + This and the language specified by Language 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 support + 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 controller + that is being managed by a driver. + + This function retrieves the user readable name of the controller specified 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 specified by + Language, then a pointer to the controller name is returned in ControllerName, + and EFI_SUCCESS is returned. If the driver specified by This is not currently + 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 returned. + + @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL 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 retrieve + the name of. This is an optional parameter that + may be NULL. It will be NULL for device + drivers. It will also be NULL for a bus drivers + 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 caller 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 format. + + @param ControllerName[out] A pointer to the Unicode string to return. + This Unicode string is the name of the + controller specified by ControllerHandle and + ChildHandle in the language specified by + Language from the point of view of the driver + specified by This. + + @retval EFI_SUCCESS The Unicode string for the user readable name 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 valid + 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 currently + managing the controller specified by + ControllerHandle and ChildHandle. + + @retval EFI_UNSUPPORTED The driver specified by This does not support + the language specified by Language. + +**/ +STATIC +EFI_STATUS +EFIAPI +AtSha204aGetControllerName ( + IN EFI_COMPONENT_NAME2_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_HANDLE ChildHandle OPTIONAL, + IN CHAR8 *Language, + OUT CHAR16 **ControllerName + ) +{ + if (ChildHandle != NULL) { + return EFI_UNSUPPORTED; + } + + return LookupUnicodeString2 (Language, + This->SupportedLanguages, + mAtSha204aControllerNameTable, + ControllerName, + FALSE); +} + +// +// EFI Component Name 2 Protocol +// +EFI_COMPONENT_NAME2_PROTOCOL gAtSha204aDriverComponentName2 = { + AtSha204aGetDriverName, + AtSha204aGetControllerName, + "en" +}; diff --git a/Silicon/Atmel/AtSha204a/DriverBinding.c b/Silicon/Atmel/AtSha204a/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 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 + +#include "AtSha204aDriver.h" + +/** + Tests to see if this driver supports a given controller. + + @param This[in] A pointer to the EFI_DRIVER_BINDING_PROTOCOL + 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 ControllerHandle is + already being managed by the driver specified + by This. + @retval EFI_UNSUPPORTED The device specified by ControllerHandle is + not supported by the driver specified by 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 = 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 = EFI_SUCCESS; + } else { + Status = 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_PROTOCOL + instance. + @param[in] ControllerHandle The handle of the device to start. This + handle must support a protocol interface that + supplies an I/O abstraction to the driver. + @param[in] RemainingDevicePath The remaining portion of the device path. + (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_PROTOCOL + instance. + @param[in] ControllerHandle A handle to the device being stopped. The handle + must support a bus specific I/O protocol for 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 device + 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 = { + 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 normally. + @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 = EfiLibInstallDriverBindingComponentName2 ( + ImageHandle, SystemTable, &gI2cHwrngDriverBinding, ImageHandle, + 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 = 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 = 0; Index < HandleCount; Index++) { + Status = gBS->DisconnectController (HandleBuffer[Index], + gImageHandle, + NULL); + } + + // + // Free the handle array + // + gBS->FreePool (HandleBuffer); + + // + // Uninstall protocols installed by the driver in its entrypoint + // + Status = gBS->UninstallMultipleProtocolInterfaces (ImageHandle, + &gEfiDriverBindingProtocolGuid, + &gI2cHwrngDriverBinding, + NULL + ); + + return EFI_SUCCESS; +} From patchwork Tue Feb 20 17:49:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 128940 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp4898004ljc; Tue, 20 Feb 2018 09:50:03 -0800 (PST) X-Google-Smtp-Source: AH8x227nNuNIwvy95V9MFedCWfDVC3UBdv0hnq650Tqc7FtPHHmTMxIJVB6lEdOd1nD7HFIwhOEw X-Received: by 10.98.248.4 with SMTP id d4mr433746pfh.78.1519149003031; Tue, 20 Feb 2018 09:50:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519149003; cv=none; d=google.com; s=arc-20160816; b=gQKeYxrBSouILjgQVmagneYJDqJpLhzqcY0+1RV0Rn/wh/6tw0F5ixrHlET0EZwSDs RlLMgWzz/4GC7bDMhei9uSW+TPhjsdw7KDnvKd3WKUwHZDaoIUVyhZP/9RcDSsw0afPB +lfz56EBg9OyET/OQZZ2WGa0/W/54RG39xv7RiYQ7j0B8qw7Z0kiNJkVDiD0uqmjlT/Z FsK9ATMXxwcQ8PwlX97yMo+Qx6rEIV9FlvELaX6Y8/RkMFaA0eviC1PBgqPZxEd4/ft6 3wyCR5ZoziJzFbuHBXRGrZBcbzdqn6k84zTe981Vy5v4vOcr7BETkAa4pp2vgWLq8cNp nNOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=cVBDFB2I3V+RGB78mT0Yv0RL4gi6Z3w6I2zaDpfjPCY=; b=BH4/3ZL+rwNlbDb5bGaQ37siun6fP2rRpj+bYEi0ciafhmigO6XH4PhvZw/T2nfAdl F77lvLvz5UPnnfkwibV0MOuAibOdgKAP+Bnrzw51TYBf36E78Za6uR7VboRhz2d9oBQA VKrehRfFTJL7KnLEBKSuY3CAjx04GQAMDug+GNCDLCLNVfRFctpVrUY3lP/thR+kGqd/ HgOHkiPQBm6QvxhsmIC21+/5f0FZPrrNkIFiYfVARywvxHU+ZwkgcXhrE++LMFHnQqdT pPWBVMPCJehp1Sj2HX5jcfPXNSZu9FBJVg6OePs958ihBHlbev4q2IyiPZmMcuzSPcXV PF+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=HyGsGSMG; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id b10si6988265pge.563.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) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=HyGsGSMG; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.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 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) 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-Received: by 10.223.148.195 with SMTP id 61mr434463wrr.248.1519148998542; 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.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 09:49:57 -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 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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(+) -- 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Platform/NinetySixBoards/Include/Protocol/Mezzanine.h b/Platform/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 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. + +**/ + +#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 connector + // + CONST EFI_SPI_PERIPHERAL *SpiDeviceLinkedList; +}; + +extern EFI_GUID gNinetySixBoardsMezzanineProtocolGuid; + +#endif // _MEZZANINE_H_ diff --git a/Platform/NinetySixBoards/NinetySixBoards.dec b/Platform/NinetySixBoards/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 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] + DEC_SPECIFICATION = 0x0001001A + PACKAGE_NAME = NinetySixBoards + PACKAGE_GUID = ce4a4683-6e2d-4ec3-bc11-974289a09ab0 + PACKAGE_VERSION = 0.1 + +[Includes] + Include + +[Protocols] + ## Include/Protocol/Mezzanine.h + gNinetySixBoardsMezzanineProtocolGuid = { 0xf0467a37, 0x3436, 0x40ef, { 0x94, 0x09, 0x4d, 0x1d, 0x7f, 0x51, 0x06, 0xd3 } } + +[Guids] + # PCD scope GUID + gNinetySixBoardsTokenSpaceGuid = { 0xe0d2f33a, 0xb7dd, 0x4a69, { 0xb6, 0x76, 0xda, 0xe8, 0xa4, 0x17, 0xa7, 0xb5 } } + + # GUIDs to be installed as protocols to identify which controller connects to which bus + gNinetySixBoardsI2c0MasterGuid = { 0xba10e402, 0xcfdd, 0x4b87, { 0xbd, 0x02, 0x6e, 0x26, 0x9f, 0x01, 0x94, 0x11 } } + gNinetySixBoardsI2c1MasterGuid = { 0xcf64ac46, 0xd0be, 0x4a69, { 0x90, 0xa2, 0xf2, 0x82, 0x5b, 0x92, 0x25, 0x61 } } + gNinetySixBoardsSpiMasterGuid = { 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 == GPIO_ACTIVE_HIGH, 1 == 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 From patchwork Tue Feb 20 17:49:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 128941 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp4898064ljc; Tue, 20 Feb 2018 09:50:08 -0800 (PST) X-Google-Smtp-Source: AH8x227XO1zphfDi33ySrgkI/OcX8/OlwOPOet4IbL3mT7+eifXj9dFsQIxPCwIEuK0hyDcQ3ADk X-Received: by 2002:a17:902:9a04:: with SMTP id v4-v6mr391781plp.252.1519149008030; Tue, 20 Feb 2018 09:50:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519149008; cv=none; d=google.com; s=arc-20160816; b=FD7XC6awIz7Ic634//8GpsjeDV4qjVngx8M0sGJo2Io+xRjOj6n1lZawKYYAuJ+1ZD cn1GX88VgNkmGahH/O54+AYckZGc4qni9GrA08xWcx/s8H6/p5gl2i/DVwD4wg4Nrayw AdNk7kue/YrDsqlhHAjFaBo9SqEMts/ufMS8hG6eAiTjy1uu4DFCX3ivcbvvqG4gUbEq z6LkdXNvXIFNgiq8BCXf2gkUbYCt+35j1QLECYigM7wJgzCs2F1jhNjZB63QtYmyvUus Qgh6F5M4s0QPYlCDN9EzuYqO1RFEP3l4PJSkHrUjsOrszEae+fvb7JBtDz+vpm2KwY6d UNcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=J0AFvEw+77f5KO5gUNpnDEX/7UKNPMqESchbW1u0BHc=; b=CJa1KF3RzbzxXXyCGH7LkmIz+lUUnVL5YNHMe2/Fc32W1JQiu6OYMvbUEKIhSvfCxD wC6FJeezJHAZnWE7t9b7nP6WBupcXyp7QhTCDJ8TKbxqp91snUTiONnSQlSrW3YiBb3N z/7v7JnQHhMIx18DNGAeKPQBz78ZhxWdB3quQSqSBc09v+O9mDgzkiP80ucWnMN+/uM6 bhPDpQi7AoVHQnFv97M0Cjr1QKZepf4nv0kLLBRPHhuXK216DeaeuecB60M+eerqKU+N 9C+PVM5/ytP9jVDNwXH4q4DhJEa9/D3q3Q4Q/9YXyHkp0GgkdyE4ID4wu8sM6IctW8xx 9COg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=KOrkG1AT; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id u8-v6si164851plk.130.2018.02.20.09.50.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 09:50:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=KOrkG1AT; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.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 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) 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-Received: by 10.28.22.145 with SMTP id 139mr914339wmw.56.1519149000725; 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.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 09:49:59 -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 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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(+) -- 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Platform/NinetySixBoards/NinetySixBoardsI2cDxe/NinetySixBoardsI2cDxe.c b/Platform/NinetySixBoards/NinetySixBoardsI2cDxe/NinetySixBoardsI2cDxe.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 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 +#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 == NULL) { + return EFI_INVALID_PARAMETER; + } + + Bus = BASE_CR (This, I2C_BUS, I2cEnumerate); + + if (*Device == NULL) { + *Device = &Bus->Devices[0]; + } else if (*Device >= &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 == NULL) { + return EFI_INVALID_PARAMETER; + } + + if (I2cBusConfiguration > 0) { + return EFI_NO_MAPPING; + } + + Bus = BASE_CR (This, I2C_BUS, I2cEnumerate); + + *BusClockHertz = Bus->BusFrequency; + + return EFI_SUCCESS; +} + +STATIC +EFI_STATUS +EFIAPI +EnableI2cBusConfiguration ( + IN CONST EFI_I2C_BUS_CONFIGURATION_MANAGEMENT_PROTOCOL *This, + IN UINTN I2cBusConfiguration, + IN EFI_EVENT Event OPTIONAL, + IN EFI_STATUS *I2cStatus OPTIONAL + ) +{ + EFI_I2C_MASTER_PROTOCOL *I2cMaster; + EFI_STATUS Status; + UINTN BusClockHertz; + I2C_BUS *Bus; + + if (I2cBusConfiguration > 0) { + return EFI_NO_MAPPING; + } + + Bus = BASE_CR (This, I2C_BUS, I2cConfigManagement); + + Status = 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 = Bus->BusFrequency; + Status = I2cMaster->SetBusFrequency (I2cMaster, &BusClockHertz); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: I2cMaster->SetBusFrequency() failed - %r\n", + __FUNCTION__, Status)); + return Status; + } + + if (Event != NULL) { + *I2cStatus = EFI_SUCCESS; + gBS->SignalEvent (Event); + } + return EFI_SUCCESS; +} + +STATIC I2C_BUS mI2cBus0 = { + { I2cEnumerate, I2cGetBusFrequency }, + { EnableI2cBusConfiguration }, + NULL, + FixedPcdGet32 (PcdI2c0BusFrequencyHz), + 0, + NULL, +}; + +STATIC I2C_BUS mI2cBus1 = { + { 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 = sizeof (EFI_HANDLE); + Status = gBS->LocateHandle (ByProtocol, Guid, NULL, &BufferSize, + &I2cBus->I2cMasterHandle); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: gBS->LocateHandle() failed - %r\n", __FUNCTION__, + Status)); + return; + } + + I2cBus->NumDevices = NumDevices; + I2cBus->Devices = Devices; + + Status = gBS->InstallMultipleProtocolInterfaces (&I2cBus->I2cMasterHandle, + &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 = 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/NinetySixBoardsI2cDxe.inf b/Platform/NinetySixBoards/NinetySixBoardsI2cDxe/NinetySixBoardsI2cDxe.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 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 = 0x0001001A + BASE_NAME = NinetySixBoardsI2cDxe + FILE_GUID = a59176bc-a151-49c8-b54a-b4ac96f436c3 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 0.1 + ENTRY_POINT = 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 From patchwork Tue Feb 20 17:49:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 128942 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp4898136ljc; Tue, 20 Feb 2018 09:50:12 -0800 (PST) X-Google-Smtp-Source: AH8x227LARYaJU/WIiIPjS9aEfwv3O0LLnMIR2YZdHIYiKANqN69DPRizmf73hKorWjBabrTj28W X-Received: by 10.101.77.12 with SMTP id i12mr327641pgt.75.1519149012410; Tue, 20 Feb 2018 09:50:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519149012; cv=none; d=google.com; s=arc-20160816; b=Igw9NfbFaWr0rzeagCH1CJ74LTeoe/n6gZUK6QjS6SVCqdXilM11AOYuVgInlaLgG/ EnwK5zT7YGMvbBn4kkB7sLVZhyDIHolsdLs7XW1kUwG4bNPIgpxaCi0sCOxChuUGfY8x TyHYk89kgcea+z45sQeRvEViniAuPNGNZc4TMbzbsq+jJhnwiK0ynk/nrufOuWZoJvXY ZBCfbEPqZe0NxMA572Nc9etE3yIT6dYp8DX3qemNduYgVGuXQ46nPT5BF6bYmFACf+aQ bgp8Wwr8+67q0TRV82qFqpZF2xx3WsDBF9XOxvHQKg1qhLy5jpF9i4qU3H9x46mIuo/q ysxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=+4FbDh1IsXoRdzNBcVUUAvgR+gr4igqeCaLi8kN+lhE=; b=Paghp90wPzdJUt5DBx8S5u+XP08CRLw5+sxePJ2DC76f5YnAch3kFQGIjwGA6DJGQD M0uUeUGl8ELE5LZAYSODCJ9eUMDGwO5oZwLnBwrnkUUEtq8OSUW+fFQ/yPHtV4Uk9Y55 aCcnMg1zMa2PPrcjThhsLFEvjaju1eA+5NQus7A9cEdk0zZ7/yNY1C37ueHrEdMxhWhO yr6bD4zwqftCLVDqYcJtXkuXeKXX+CSiQSpWkIWVYYsZUTBdWSjwPnVb/+uO98QfneDT 5p+0kyffm4rrfbB7nOu7EcAjnwiQhxnfTvNWeSKOOBko3a1J+WseEaqRGh4N5Uhhfcf8 Ck6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=WVp4jMDw; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id k67si6322465pgk.246.2018.02.20.09.50.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 09:50:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=WVp4jMDw; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.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 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) 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-Received: by 10.223.176.201 with SMTP id j9mr430777wra.210.1519149002635; 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.50.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 09:50:01 -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 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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(+) -- 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Platform/NinetySixBoards/Include/Protocol/LsConnector.h b/Platform/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 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. + +**/ + +#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/NinetySixBoards/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 = { 0xf0467a37, 0x3436, 0x40ef, { 0x94, 0x09, 0x4d, 0x1d, 0x7f, 0x51, 0x06, 0xd3 } } + ## Include/Protocol/LsConnector.h + gNinetySixBoardsLsConnectorProtocolGuid = { 0xae548d4c, 0x9062, 0x4eed, { 0x83, 0x5f, 0xf5, 0x10, 0xf8, 0xfc, 0x48, 0xaf } } + [Guids] # PCD scope GUID gNinetySixBoardsTokenSpaceGuid = { 0xe0d2f33a, 0xb7dd, 0x4a69, { 0xb6, 0x76, 0xda, 0xe8, 0xa4, 0x17, 0xa7, 0xb5 } } From patchwork Tue Feb 20 17:49:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 128943 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp4898201ljc; Tue, 20 Feb 2018 09:50:16 -0800 (PST) X-Google-Smtp-Source: AH8x225STa6C1lkYZNuJBRruPlmciRbEhiJla8xP4i1PAuaDwx1KU0zhawm3d6qf/38/oiI9ykNU X-Received: by 2002:a17:902:5a5:: with SMTP id f34-v6mr413086plf.134.1519149016079; Tue, 20 Feb 2018 09:50:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519149016; cv=none; d=google.com; s=arc-20160816; b=g6ChGkglur8cgAS/8YMHTn6LmxqaplQWF26vZbGPJyfW8vjZnIbS1w2a+dRtDLwD1V Fy6hFtQTjOdZaE+0yH0lJIfXlYcMcym3s/2X9DW4qkTlbVjBYrOP5K+YDX9/dB1aYanK xSHi2gI632GfDXGsUyZHvuaM3rgxyjfa0gzulJHZjzjFKtc2PBZEEYdp5Y/6Py7Mu7Cp 9eec3XGuqnFQJRXdu6V8iSQrOgaJRfFepXCftx32tHvVq7/k6X7YOl5cElWiBCDENeKl 8+yuMDRdqMjc523b2MbtxtdEIVYxjd4pahZRT8g+K9W1A1PMjmxZmpGDEBwLbsuG4CEi DyTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=iBZ3mIcczkiQaPowYZmfSnU7H3HlC/M/i6m4Ki7L3gk=; b=RHo2rkd91qUF1fMjwrf5z+8XVljZR6g/Q6FF6YpBSjbvhxUYif4UyuxJa0jcpzxPjM 5DrK8aNpK5I+JcUcvNvK+njOHd0o6NkeQebRi7bsJyERdnQ026jE/LoPvonAmL8Kub/I fTXgP18rdslJ7KHmc81kNSk9aqFcZ7hklgCWhBDBvF/x6XXJagxTRnB6ovKYEf51/c6u AkH/RUtx3glf0b2Y2Svg/e/rlaM429XZabknDcRDbAGFG2wi12Iw3DOfoTbwPZJDhPPj dg8SFPU+PdzFCwJnizpXbtobImBIscaLsO2QHRlo6QUYns+cwLdRbx/4CGpNm9i4pEqt YG0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=a60cpkRX; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id 64-v6si4705899plk.152.2018.02.20.09.50.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 09:50:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=a60cpkRX; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.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 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) 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-Received: by 10.223.197.197 with SMTP id v5mr407728wrg.161.1519149004819; 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.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 09:50:03 -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 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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(+) -- 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Platform/NinetySixBoards/Secure96Dxe/Secure96.dts b/Platform/NinetySixBoards/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 = "I2C_PARENT_PLACEHOLDER_STRING"; + __overlay__ { + ATSHA204A_DT_NODENAME { + compatible = "atmel,atsha204a"; + reg = ; + }; + ATECC508A_DT_NODENAME { + compatible = "atmel,atecc508a"; + reg = ; + }; + }; + }; + + fragment@1 { + target-path = "SPI_PARENT_PLACEHOLDER_STRING"; + __overlay__ { + INFINEON_SLB9670_DT_NODENAME { + compatible = "infineon,slb9670"; + reg = ; + spi-max-frequency = <22500000>; + }; + }; + }; + + fragment@2 { + target-path = "/"; + __overlay__ { + gpio-leds { + compatible = "gpio-leds"; + + secure96-u1 { + gpios = ; + }; + secure96-u2 { + gpios = ; + }; + secure96-u3 { + gpios = ; + }; + secure96-u4 { + gpios = ; + }; + }; + }; + }; +}; diff --git a/Platform/NinetySixBoards/Secure96Dxe/Secure96.h b/Platform/NinetySixBoards/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 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. +**/ + +#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 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Secure96.h" + +STATIC CONST UINT32 mI2cAtmelSha204aSlaveAddress[] = { + ATSHA204A_SLAVE_ADDRESS, + + // + // The Atmel AtSha204a has an annoying 'wake' mode where it will only wake + // up if SDA is held low for a certain amount of time. Attempting to access + // 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[] = { + { + &gAtSha204aI2cDeviceGuid, // DeviceGuid + 0, // DeviceIndex + 0, // HardwareRevision + 0, // I2C bus configuration + ARRAY_SIZE (mI2cAtmelSha204aSlaveAddress), // SlaveAddressCount + mI2cAtmelSha204aSlaveAddress // SlaveAddressArray + } +}; + +STATIC CONST CHAR8 mLedNodes[][46] = { + "/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 = fdt_path_offset (Overlay, NodeName); + ASSERT (Node > 0); + + Err = 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 = fdt_path_offset (Dtb, FixedPcdGetPtr (PcdGpioParent)); + ASSERT (Node > 0); + + GpioPhandle = fdt_get_phandle (Dtb, Node); + if (!GpioPhandle) { + // + // Node has no phandle yet -> create one + // + GpioPhandle = 1 + fdt_get_max_phandle (Dtb); + ASSERT (GpioPhandle >= 1); + + Err = 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 = 0; Idx < ARRAY_SIZE (mLedNodes); Idx++) { + Node = fdt_path_offset (Overlay, mLedNodes[Idx]); + ASSERT (Node > 0); + + GpioProp = fdt_getprop_w (Overlay, Node, "gpios", NULL); + ASSERT (GpioProp != NULL); + + *GpioProp = 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 = 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 = 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 = { + 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 = gBS->LocateProtocol (&gNinetySixBoardsLsConnectorProtocolGuid, NULL, + (VOID **)&LsConnector); + ASSERT_EFI_ERROR (Status); + + if (LsConnector->MezzanineType != MezzanineSecure96) { + return EFI_NOT_FOUND; + } + + return gBS->InstallProtocolInterface (&ImageHandle, + &gNinetySixBoardsMezzanineProtocolGuid, + EFI_NATIVE_INTERFACE, + &mMezzanine); +} diff --git a/Platform/NinetySixBoards/Secure96Dxe/Secure96Dxe.inf b/Platform/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 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 = 0x0001001A + BASE_NAME = Secure96Dxe + FILE_GUID = 31519ec4-65f1-4790-b223-aa9330dd75fd + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = 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 = -q From patchwork Tue Feb 20 17:49:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 128944 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp4898259ljc; Tue, 20 Feb 2018 09:50:20 -0800 (PST) X-Google-Smtp-Source: AH8x224s7oDAbeO4JyuPJUw8lTHpsBQERBR1JVYVLwy7OqpANDjjGDH1yIoiQaJMrhrMuSas/IoR X-Received: by 10.167.130.193 with SMTP id f1mr384106pfn.241.1519149020260; Tue, 20 Feb 2018 09:50:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519149020; cv=none; d=google.com; s=arc-20160816; b=kxIx3nS+ezp9BHNbHHZtnBPgD5wjmzvFu6VVASovsKpZEIOBjAlETuvtZg/6oQSRIw hJtVTwieiuLsC6YoCpyxm3OM7vR22/vHWXaCRzt22eSkv3CRmJhHOaI8bLD0pua8NIZC UzFiFdx/m1NsXLgoBHMz/6FCB2pp292sSYO7jHSf581PAVO2Fp7Nnsxi7NvgmuFXiz+Q iIjFwPXt67cg1S/STEWoH9UYEImQEw7XNBVHPbTfRoDFCtWHaQjBgVyEASTNOOrruVen pUJqN/aC8yl7N79WZzimRBatjm2O6WaUYHsKcVScGL8RUkpPP6YJxVvTCyxpZX98oWC8 hk9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=FR0yG1JJPzc4BA7cp1oW1cXh2IfiSAL4u0q8roQPNxI=; b=CBvTXW4R51geE/a7NbNEkcF0bAxYg1BItJHffVOTaGcS0pGSytH0Cd0cnJF2w5aG6p sgr2SxbVECoMqGSMN1mKeFf4kOMfg5et7+jYuzJ35ByWFCOx9iJ8ClHAcFYq6jHZVCDt 8KFbvHAM+1eKCwwUUmg8n9UokD2hwJTjneBJyzjijW7P1iSPq6wn5fbW4UCK2vuG7SeK m108JLrrwQnkDTnBNwoixXWxvZrFdfYuj2q604G7IZy1d2Z/od95UZy+3cOyvvchHpvM nUKm7CjcwDOjQAtzWOVPte4fcJBOlvhHzUHLqftAkYpoHzA02ApqWEWHrVLpPRogYOvP KvWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=HdGf8r9y; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id m14si1409103pgt.277.2018.02.20.09.50.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 09:50:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=HdGf8r9y; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.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 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) 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-Received: by 10.223.185.112 with SMTP id b45mr410689wrg.159.1519149006827; 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.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); 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 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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(+) -- 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Platform/NinetySixBoards/Include/Guid/FormSet.h b/Platform/NinetySixBoards/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 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. + +**/ + +#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/NinetySixBoards/NinetySixBoards.dec index 5c3fe43dbb24..e7d1705d47ff 100644 --- a/Platform/NinetySixBoards/NinetySixBoards.dec +++ b/Platform/NinetySixBoards/NinetySixBoards.dec @@ -37,6 +37,9 @@ [Guids] gNinetySixBoardsI2c1MasterGuid = { 0xcf64ac46, 0xd0be, 0x4a69, { 0x90, 0xa2, 0xf2, 0x82, 0x5b, 0x92, 0x25, 0x61 } } gNinetySixBoardsSpiMasterGuid = { 0x9703fd99, 0xe638, 0x42b8, { 0xab, 0x81, 0x52, 0x61, 0x1b, 0xf7, 0xf7, 0x5d } } + # GUID for the HII configuration form + gNinetySixBoardsFormsetGuid = { 0x7500c9d2, 0x9203, 0x4a37, { 0x84, 0xbb, 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 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 +#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 = { + { + { + 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 = NULL; + Status = gBS->InstallMultipleProtocolInterfaces (&DriverHandle, + &gEfiDevicePathProtocolGuid, + &mNinetySixBoardsDxeVendorDevicePath, + NULL); + if (EFI_ERROR (Status)) { + return Status; + } + + HiiHandle = HiiAddPackages (&gNinetySixBoardsFormsetGuid, + DriverHandle, + NinetySixBoardsDxeStrings, + NinetySixBoardsHiiBin, + NULL); + + if (HiiHandle == 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 = EfiGetSystemConfigurationTable (&gFdtTableGuid, &Dtb); + if (Status == EFI_NOT_FOUND) { + return; + } + ASSERT_EFI_ERROR (Status); + + Status = gBS->LocateProtocol (&gNinetySixBoardsMezzanineProtocolGuid, NULL, + (VOID **)&Mezzanine); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: no mezzanine driver active\n", __FUNCTION__)); + return; + } + + Status = Mezzanine->ApplyDeviceTreeOverlay (Mezzanine, Dtb); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "%a: failed to apply DT overlay - %r\n", __FUNCTION__, + 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 = sizeof (ConfigData); + Status = gRT->GetVariable (NINETY_SIX_BOARDS_CONFIG_VARIABLE_NAME, + &gNinetySixBoardsFormsetGuid, NULL, &BufferSize, &ConfigData); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: no config data found\n", __FUNCTION__)); + ConfigData.MezzanineType = 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 = MEZZANINE_NONE; + Status = 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 = gRT->SetVariable (NINETY_SIX_BOARDS_CONFIG_VARIABLE_NAME, + &gNinetySixBoardsFormsetGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + 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 = MezzanineSecure96; + break; + default: + mLsConnector.MezzanineType = MezzanineUnknown; + } + + Status = gBS->InstallProtocolInterface (&ImageHandle, + &gNinetySixBoardsLsConnectorProtocolGuid, + EFI_NATIVE_INTERFACE, + &mLsConnector); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = 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 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. + +**/ + +#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 = 0x0001001A + BASE_NAME = NinetySixBoardsDxe + FILE_GUID = 3f68e889-cb77-4efc-bc84-afa0a64ad26e + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = 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 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. + +**/ + +#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 installed 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 mezzanine 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 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 "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 = NINETY_SIX_BOARDS_FORMSET_GUID, + title = STRING_TOKEN(STR_FORM_SET_TITLE), + help = STRING_TOKEN(STR_FORM_SET_TITLE_HELP), + classguid = EFI_HII_PLATFORM_SETUP_FORMSET_GUID, + + efivarstore NINETY_SIX_BOARDS_CONFIG_DATA, + attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, // EFI variable attributes + name = NinetySixBoardsConfig, + guid = NINETY_SIX_BOARDS_FORMSET_GUID; + + form formid = 0x1000, + title = STRING_TOKEN(STR_MAIN_FORM_TITLE); + + oneof varid = NinetySixBoardsConfig.MezzanineType, + prompt = STRING_TOKEN(STR_MEZZANINE_SELECT_PROMPT), + help = STRING_TOKEN(STR_MEZZANINE_SELECT_HELP), + flags = NUMERIC_SIZE_1 | INTERACTIVE | RESET_REQUIRED, + option text = STRING_TOKEN(STR_MEZZANINE_NONE), value = MEZZANINE_NONE, flags = DEFAULT; + option text = STRING_TOKEN(STR_MEZZANINE_SECURE96), value = MEZZANINE_SECURE96, flags = 0; + endoneof; + + subtitle text = STRING_TOKEN(STR_NULL_STRING); + + endform; + +endformset; From patchwork Tue Feb 20 17:49:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 128945 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp4898321ljc; Tue, 20 Feb 2018 09:50:24 -0800 (PST) X-Google-Smtp-Source: AH8x225adS7Dpt0pbAYnxF1bb+azXvDavCx3xDaxrjt2nX8ClKyRucETRilNQCd+S0eyxXX2QlXp X-Received: by 2002:a17:902:bcc1:: with SMTP id o1-v6mr410356pls.218.1519149024093; Tue, 20 Feb 2018 09:50:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519149024; cv=none; d=google.com; s=arc-20160816; b=GSk3Yg12oyv+nnnBmxlx4VNiTekSIuo/znKgZg7PTXnpOvkzlyqUAIHb+uaVukYl0A D++ts+ffsCmmjXLEgjHEVl38vxbfzOQ1nNAsZWtsj1O9lV4hFXOQGwNH72zhvbbNwrw3 ZVN+lK2v9+R3wpv9Dp193ztfBe4Je2dLWjRe1L/GXRToRNBkd3isCxndI6/5i82opNOq /G0unrsPjJIYy86aUVi3IDgvU2rdbx0mxaORbBrr/C/AWbjWs5vBv7omHg8UUpTG0rFy EYtJAokxVutE3ow4USv/LZmQPF4EPlTGir7wkxwfhTmt7NOv3NmxaRKjniB09qwahtM8 VeUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=iSWeYTNSz4AKpnN2qfbPCymZYIGozcNFsqGTXyboSyg=; b=ugtU4z2QQJUKYJZt1AKOrJqjKd0ZaVLRMbXgS7u4r7eljc+cb7avPU9Rg+9Aw9gYzn L7CVfIO/nXDVEcjdB6iPw2iieo9QKZvBBAhlfYV0E/uMcIQbaTf+LymlllWh8X21f/iT fVGzJTePgjDzgjjXYD7QtPyufz2PkFkyuiRvMABvBHuP0zYT1KW4Dz+lMf1anQ0I57Z1 5mbClDUFL8Vux4tuPXXr2vPIyaV9VEiB3hdyCtCwzHmcmZeGU5vim0gtsHttzT1XBY1i HJ6MJ56U87Q/fO7N//M/00QmdjdRvis8V6JlwlKa9QSLgfjQnG5Yyp0qonf5I4TeyC+w M2og== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=HTRqp6dl; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id r26si6950251pfi.378.2018.02.20.09.50.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 09:50:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=HTRqp6dl; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.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 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) 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-Received: by 10.28.51.6 with SMTP id z6mr891831wmz.26.1519149008903; 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.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 09:50:07 -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 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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(+) -- 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Platform/Socionext/DeveloperBox/DeveloperBox.dsc b/Platform/Socionext/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 = -DMDEPKG_NDEBUG -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 + # add ample padding to the DTC so we can apply 96boards mezzanine overlays + *_*_*_DTC_FLAGS = -p 1024 + [BuildOptions.common.EDKII.DXE_CORE,BuildOptions.common.EDKII.DXE_DRIVER,BuildOptions.common.EDKII.UEFI_DRIVER,BuildOptions.common.EDKII.UEFI_APPLICATION] GCC:*_*_*_DLINK_FLAGS = -z common-page-size=0x1000 @@ -398,6 +401,28 @@ [PcdsFixedAtBuild.common] !endif gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareRevision|$(BUILD_NUMBER) + # + # 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 # + # 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 Platform/Socionext/DeveloperBox/OsInstallerMenuDxe/OsInstallerMenuDxe.inf diff --git a/Platform/Socionext/DeveloperBox/DeveloperBox.fdf b/Platform/Socionext/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] } # + # 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 INF Platform/Socionext/DeveloperBox/OsInstallerMenuDxe/OsInstallerMenuDxe.inf @@ -430,6 +439,7 @@ [Rule.Common.DXE_DRIVER] DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi UI STRING="$(MODULE_NAME)" Optional + RAW BIN Optional |.dtb } [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); + // + // Install the gNinetySixBoardsI2c0MasterGuid GUID onto the same handle, + // identifying I2C #1 on our SoC as I2C #0 on the 96boards low speed connector + // + Status = gBS->InstallProtocolInterface (&Handle, + &gNinetySixBoardsI2c0MasterGuid, + EFI_NATIVE_INTERFACE, NULL); + ASSERT_EFI_ERROR (Status); + SmmuEnableCoherentDma (); SetMmioTimerFrequency (); diff --git a/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.inf 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 [Guids] + gNinetySixBoardsI2c0MasterGuid gEfiHiiPlatformSetupFormsetGuid gFdtTableGuid gNetsecNonDiscoverableDeviceGuid