1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #pragma once
25 
26 #include <nvtypes.h>
27 
28 //
29 // This file was generated with FINN, an NVIDIA coding tool.
30 // Source file:      ctrl/ctrl2080/ctrl2080spdm.finn
31 //
32 
33 
34 
35 /*************************** SPDM COMMANDS ************************************/
36 
37 #include "cc_drv.h"
38 
39 /*!
40  * @brief SPDM Command Types
41  *
42  */
43 #define RM_GSP_SPDM_CMD_ID_CC_INIT           (0x1)
44 #define RM_GSP_SPDM_CMD_ID_CC_DEINIT         (0x2)
45 #define RM_GSP_SPDM_CMD_ID_CC_CTRL           (0x3)
46 #define RM_GSP_SPDM_CMD_ID_CC_INIT_RM_DATA   (0x4)
47 #define RM_GSP_SPDM_CMD_ID_CC_HEARTBEAT_CTRL (0x5)
48 #define RM_GSP_SPDM_CMD_ID_FIPS_SELFTEST     (0x6)
49 
50 
51 #define RM_GSP_SPDM_CMD_ID_INVALID_COMMAND   (0xFF)
52 
53 
54 
55 #define RSVD7_SIZE                           16
56 
57 #define RSVD8_SIZE                           2
58 
59 /*!
60  * Guest RM provides INIT context
61  */
62 typedef struct RM_GSP_SPDM_CMD_CC_INIT {
63     // Command must be first as this struct is the part of union
64     NvU8 cmdType;
65 } RM_GSP_SPDM_CMD_CC_INIT;
66 typedef struct RM_GSP_SPDM_CMD_CC_INIT *PRM_GSP_SPDM_CMD_CC_INIT;
67 
68 /*!
69  * Guest RM provides INIT context
70  */
71 typedef struct RM_GSP_SPDM_CMD_CC_DEINIT {
72     // Command must be first as this struct is the part of union
73     NvU8 cmdType;
74 } RM_GSP_SPDM_CMD_CC_DEINIT;
75 typedef struct RM_GSP_SPDM_CMD_CC_DEINIT *PRM_GSP_SPDM_CMD_CC_DEINIT;
76 
77 /*!
78  * RM provides the SPDM request info to GSP
79  */
80 typedef struct RM_GSP_SPDM_CMD_CC_CTRL {
81     // Command must be first as this struct is the part of union
82     NvU8 cmdType;
83 } RM_GSP_SPDM_CMD_CC_CTRL;
84 typedef struct RM_GSP_SPDM_CMD_CC_CTRL *PRM_GSP_SPDM_CMD_CC_CTRL;
85 
86 typedef struct RM_GSP_SPDM_CMD_CC_INIT_RM_DATA {
87     // Command must be first as this struct is the part of union
88     NvU8  cmdType;
89 
90     NvU32 rsvd0[2];
91 
92     NvU32 rsvd1;
93 
94     char  rsvd2[9];
95 
96     char  rsvd3[5];
97 
98     char  rsvd4[5];
99 
100     char  rsvd5[5];
101 
102     char  rsvd6[2];
103 
104     char  rsvd7[RSVD7_SIZE];
105 
106     NvU32 rsvd8[RSVD8_SIZE];
107 } RM_GSP_SPDM_CMD_CC_INIT_RM_DATA;
108 typedef struct RM_GSP_SPDM_CMD_CC_INIT_RM_DATA *PRM_GSP_SPDM_CMD_CC_INIT_RM_DATA;
109 
110 typedef struct RM_GSP_SPDM_CMD_CC_HEARTBEAT_CTRL {
111     // Command must be first as this struct is the part of union
112     NvU8   cmdType;
113 
114     // Whether to enable or disable heartbeats
115     NvBool bEnable;
116 } RM_GSP_SPDM_CMD_CC_HEARTBEAT_CTRL;
117 typedef struct RM_GSP_SPDM_CMD_CC_HEARTBEAT_CTRL *PRM_GSP_SPDM_CMD_CC_HEARTBEAT_CTRL;
118 
119 
120 
121 /*!
122  * HCC FIPS Self-test.
123  */
124 #define CE_FIPS_SELF_TEST_DATA_SIZE     16
125 #define CE_FIPS_SELF_TEST_AUTH_TAG_SIZE 16
126 #define CE_FIPS_SELF_TEST_IV_SIZE       12
127 
128 typedef struct RM_GSP_SPDM_CMD_FIPS_SELFTEST {
129     NvU8   cmdType;
130     NvU8   isEnc;
131     CC_KMB kmb;
132     NvU8   text[CE_FIPS_SELF_TEST_DATA_SIZE];
133     NvU8   authTag[CE_FIPS_SELF_TEST_AUTH_TAG_SIZE];
134 } RM_GSP_SPDM_CMD_FIPS_SELFTEST;
135 typedef struct RM_GSP_SPDM_CMD_FIPS_SELFTEST *PRM_GSP_SPDM_CMD_FIPS_SELFTEST;
136 
137 
138 
139 /*!
140  * NOTE : Do not include structure members that have alignment requirement >= 8 to avoid alignment directives
141  * getting added in FINN generated structures / unions as RM_GSP_SPDM_CMD / RM_GSP_SPDM_MSG are pragma packed in
142  * other structures like RM_FLCN_CMD_GSP / RM_FLCN_MSG_GSP and pragma pack does not produce consistent behavior
143  * when paired with alignment directives on Linux and Windows.
144  */
145 
146 /*!
147  * A union of all SPDM Commands.
148  */
149 typedef union RM_GSP_SPDM_CMD {
150     NvU8                              cmdType;
151     RM_GSP_SPDM_CMD_CC_INIT           ccInit;
152     RM_GSP_SPDM_CMD_CC_DEINIT         ccDeinit;
153     RM_GSP_SPDM_CMD_CC_CTRL           ccCtrl;
154     RM_GSP_SPDM_CMD_CC_INIT_RM_DATA   rmDataInitCmd;
155     RM_GSP_SPDM_CMD_CC_HEARTBEAT_CTRL ccHeartbeatCtrl;
156 
157 
158     RM_GSP_SPDM_CMD_FIPS_SELFTEST     ccFipsTest;
159 
160 } RM_GSP_SPDM_CMD;
161 typedef union RM_GSP_SPDM_CMD *PRM_GSP_SPDM_CMD;
162 
163 /***************************** SPDM MESSAGES  *********************************/
164 
165 /*!
166  * SPDM Message Status
167  */
168 
169 /*!
170  * Returns the status for program CE keys to RM
171  */
172 #define RM_GSP_SPDM_MSG_ID_CC_INIT           (0x1)
173 #define RM_GSP_SPDM_MSG_ID_CC_DEINIT         (0x2)
174 #define RM_GSP_SPDM_MSG_ID_CC_CTRL           (0x3)
175 #define RM_GSP_SPDM_MSG_ID_CC_INIT_RM_DATA   (0x4)
176 #define RM_GSP_SPDM_MSG_ID_CC_HEARTBEAT_CTRL (0x5)
177 #define RM_GSP_SPDM_MSG_ID_FIPS_SELFTEST     (0x6)
178 
179 
180 
181 /*!
182  * Returns the Error Status for Invalid Command
183  */
184 #define RM_GSP_SPDM_MSG_ID_INVALID_COMMAND   (0xFF)
185 
186 /*!
187  * NOTE : Do not include structure members that have alignment requirement >= 8 to avoid alignment directives
188  * getting added in FINN generated structures / unions as RM_GSP_SPDM_CMD / RM_GSP_SPDM_MSG are pragma packed in
189  * other structures like RM_FLCN_CMD_GSP / RM_FLCN_MSG_GSP and pragma pack does not produce consistent behavior
190  * when paired with alignment directives on Linux and Windows.
191  */
192 
193 /*!
194  * SPDM message structure.
195  */
196 typedef struct RM_GSP_SPDM_MSG {
197     NvU8  msgType;
198 
199     // status returned from GSP message infrastructure.
200     NvU32 status;
201 
202     NvU32 rsvd1;
203 
204     NvU32 rsvd2;
205 
206     NvU32 rsvd3;
207 
208     NvU32 rsvd4;
209 
210     NvU32 rsvd5;
211 } RM_GSP_SPDM_MSG;
212 typedef struct RM_GSP_SPDM_MSG *PRM_GSP_SPDM_MSG;
213 
214 /*
215  * NV2080_CTRL_CMD_INTERNAL_SPDM_PARTITION
216  *
217  * This command does a partition switch to SPDM partition
218  *
219  */
220 #define NV2080_CTRL_INTERNAL_SPDM_PARTITION (0x20800ad9) /* finn: Evaluated from "(FINN_NV20_SUBDEVICE_0_INTERNAL_INTERFACE_ID << 8) | NV2080_CTRL_INTERNAL_SPDM_PARTITION_PARAMS_MESSAGE_ID" */
221 
222 #define NV2080_CTRL_INTERNAL_SPDM_PARTITION_PARAMS_MESSAGE_ID (0xD9U)
223 
224 typedef struct NV2080_CTRL_INTERNAL_SPDM_PARTITION_PARAMS {
225     NvU8            index;
226     RM_GSP_SPDM_CMD cmd;
227     RM_GSP_SPDM_MSG msg;
228 } NV2080_CTRL_INTERNAL_SPDM_PARTITION_PARAMS;
229 
230 
231 
232