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(+)
diff --git a/Silicon/Atmel/AtSha204a/AtSha204a.dec
b/Silicon/Atmel/AtSha204a/AtSha204a.dec
new file mode 100644
index ..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 ..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