summaryrefslogtreecommitdiff
path: root/Silicon/Atmel/AtSha204a/AtSha204aDriver.h
blob: 315a450d34f284f5791e05f3103b77917aff8d97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/** @file
  Device driver for the Atmel ATSHA204A random number generator.

  Copyright (c) 2018, Linaro Ltd. All rights reserved.<BR>

  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 <Uefi.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>

#include <Protocol/Rng.h>
#include <Protocol/I2cIo.h>

#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_