summaryrefslogtreecommitdiff
path: root/arch/arm/mach-tegra/nvddk/nvddk_aes_core_ap20.h
blob: 728a3e276165605b549ae47c2cd9f0b84088d767 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
 * Copyright (c) 2007-2009 NVIDIA Corporation.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * Neither the name of the NVIDIA Corporation nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */

#ifndef INCLUDED_NVDDK_AES_CORE_AP20_H
#define INCLUDED_NVDDK_AES_CORE_AP20_H

#ifdef __cplusplus
extern "C" {
#endif

/**
 * Disable the selected AES engine.  No further operations can be
 * performed using the AES engine until the entire chip is reset.
 *
 * @param Engine AES engine to disable.
 * @param pEngineVirAddr AES engine virtual address.
 *
 * @retval NvSuccess if engine successfully disabled else NvError_AesDisableCryptoFailed.
 */
NvError NvAesCoreAp20DisableEngine(const AesHwEngine Engine, const NvU32 *const pEngineVirAddr);

/**
 * Read the AES engine disable status.
 *
 * @param Engine AES engine to disable.
 * @param pEngineVirAddr AES engine virtual address.
 *
 * @retval NV_TRUE if engine is disabled else NV_FALSE.
 */
NvBool NvAesCoreAp20IsEngineDisabled(const AesHwEngine Engine, const NvU32 *const pEngineVirAddr);

/**
 * Wait till the engine is idle.
 *
 * @param Engine The engine which needs to be in idle state.
 * @param pEngineVirAddr AES engine virtual address.
 *
 * @retval None.
 */
void NvAesCoreAp20WaitTillEngineIdle(const AesHwEngine Engine, const NvU32 *const pEngineVirAddr);

/**
 * Set up the key table.
 *
 * @param Engine The AES engine to setup the Key table.
 * @param pEngineVirAddr AES engine virtual address.
 * @param KeyTablePhyAddr The physical address of the keytable.
 * @param Slot AES Key slot to use for setting up the key table.
 *
 * @retval None.
 */
void
NvAesCoreAp20SetupTable(
    const AesHwEngine Engine,
    const NvU32 *const pEngineVirAddr,
    const NvU32 KeyTablePhyAddr,
    const NvU32 Slot);

/**
 * Select the Key slot for updating the IV vectors.
 *
 * @param Engine The AES engine to be used.
 * @param pEngineVirAddr AES engine virtual address.
 * @param Slot The slot to be selected.
 *
 * @retval None.
 */
void NvAesCoreAp20SelectKeyIvSlot(const AesHwEngine Engine, const NvU32 *const pEngineVirAddr, const NvU32 Slot);

/**
 * Set the IV in key table.
 *
 * @param Engine The AES engine to be used.
 * @param pEngineVirAddr AES engine virtual address.
 * @param Slot The slot of the engine to be used.
 * @param Start The start location within the keytable.
 * @param End The end location of keytable.
 * @param pKeyTable The physical address of the engine keytable.
 * @param KeyTableSize Size of key table in bytes.
 * @param pIvAddress The IV to set, if NULL then the IV is cleared.
 *
 * @retval None.
 */
void
NvAesCoreAp20SetIv(
    const AesHwEngine Engine,
    const NvU32 *const pEngineVirAddr,
    const NvU32 Slot,
    const NvU32 Start,
    const NvU32 End,
    const NvU32 *const pKeyTable,
    const NvU32 KeyTableSize,
    const NvU32 *const pIvAddress);

/**
 * Get the IV.
 *
 * @param Engine The AES engine to be used.
 * @param pEngineVirAddr AES engine virtual address.
 * @param Slot The slot of the engine to be used.
 * @param Start The start location within the keytable.
 * @param End The end location of keytable.
 * @param pIvAddress The pointer to the location where the IV will be stored.
 *
 * @retval None.
 */
void
NvAesCoreAp20GetIv(
    const AesHwEngine Engine,
    const NvU32 *const pEngineVirAddr,
    const NvU32 Slot,
    const NvU32 Start,
    const NvU32 End,
    const NvU32 *const pIvAddress);

/**
 * Enable/Disable the key schedule generation in hardware.
 *
 * @param Engine The engine for which the key generation needs to be disabled.
 * @param pEngineVirAddr AES engine virtual address.
 * @param IsEnabled NV_TRUE to enable the key schedule generation, NV_FALSE otherwise.
 *
 * @retval None.
 */
void
NvAesCoreAp20ControlKeyScheduleGeneration(
    const AesHwEngine Engine,
    const NvU32 *const pEngineVirAddr,
    const NvBool IsEnabled);

/**
 * Lock down the permissions for SSK.
 *
 * @param Engine The engine which needs to be locked.
 * @param pEngineVirAddr AES engine virtual address.
 *
 * @retval None.
 */
void NvAesCoreAp20LockSskReadWrites(const AesHwEngine Engine, const NvU32 *const pEngineVirAddr);

/**
 * Encrypt/Decrypt blocks of data.
 *
 * @param Engine The engine to be used.
 * @param pEngineVirAddr AES engine virtual address.
 * @param SrcPhyAddress The physical address of source buffer.
 * @param DestPhyAddress The physical address of destination buffer.
 * @param NumBlocks Number of blocks in Source buffer
 * @param IsEncryption NV_TRUE if encryption else NV_FALSE.
 * @param OpMode Specifies the AES operational mode.
 *
 * @retval None.
 */
void
NvAesCoreAp20ProcessBuffer(
    const AesHwEngine Engine,
    const NvU32 *const pEngineVirAddr,
    const NvU32 SrcPhyAddress,
    const NvU32 DestPhyAddress,
    const NvU32 NumBlocks,
    const NvBool IsEncryption,
    const NvDdkAesOperationalMode OpMode);

/**
 * Load the SSK key into secure scratch resgister and disables the write permissions.
 *
 * @param pPmicBaseAddr Pointer to the PMIC base address.
 * @param pKey Pointer to the key.
 * @param Size Length of the aperture in bytes.
 *
 * @retval None.
 */
void
NvAesCoreAp20LoadSskToSecureScratchAndLock(
    const NvU32 PmicBaseAddr,
    const NvU32 *const pKey,
    const size_t Size);

/**
 * Disables read access to the given key slot
 *
 * @param Engine AES engine for which read access needs to be disabled
 *               for the given key slot
 * @param Slot Key slot number for which read access needs to be disabled.
 * @param pEngineVirAddr AES engine virtual address.
 *
 * @retval None
 */
void
NvAesCoreAp20KeyReadDisable(
    const AesHwEngine Engine,
    const AesHwKeySlot Slot,
    const NvU32 *const pEngineVirAddr);

#ifdef __cplusplus
};
#endif

#endif // #define INCLUDED_NVDDK_AES_CORE_AP20_H