1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2023 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 #ifndef _FSPRPC_NVSWITCH_H_
25 #define _FSPRPC_NVSWITCH_H_
26 
27 #include "fsp/fsp_emem_channels.h"
28 #include "fsp/nvdm_payload_cmd_response.h"
29 #include "fsp/fsp_nvdm_format.h"
30 #include "fsp/fsp_mctp_format.h"
31 #include "fsp/fsp_tnvl_rpc.h"
32 
33 #define FSP_OK                          (0x00U)
34 #define FSP_ERR_IFS_ERR_INVALID_STATE   (0x9EU)
35 #define FSP_ERR_IFR_FILE_NOT_FOUND      (0x9FU)
36 #define FSP_ERR_IFS_ERR_NOT_SUPPORTED   (0xA0U)
37 #define FSP_ERR_IFS_ERR_INVALID_DATA    (0xA1U)
38 
39 #pragma pack(1)
40 typedef struct mctp_header
41 {
42     NvU32 constBlob;
43     NvU8 msgType;
44     NvU16 vendorId;
45 } MCTP_HEADER;
46 
47 // Needed to remove unnecessary padding
48 #pragma pack(1)
49 typedef struct nvdm_payload_cot
50 {
51     NvU16 version;
52     NvU16 size;
53     NvU64 gspFmcSysmemOffset;
54     NvU64 frtsSysmemOffset;
55     NvU32 frtsSysmemSize;
56 
57     // Note this is an offset from the end of FB
58     NvU64 frtsVidmemOffset;
59     NvU32 frtsVidmemSize;
60 
61     // Authentication related fields
62     NvU32 hash384[12];
63     NvU32 publicKey[96];
64     NvU32 signature[96];
65 
66     NvU64 gspBootArgsSysmemOffset;
67 } NVDM_PAYLOAD_COT;
68 #pragma pack()
69 
70 typedef struct nvdm_packet
71 {
72     NvU8 nvdmType;
73 
74     // We can make this a union when adding more NVDM payloads
75     NVDM_PAYLOAD_COT cotPayload;
76 } NVDM_PACKET;
77 
78 // The structure cannot have embedded pointers to send as byte stream
79 typedef struct mctp_packet
80 {
81     MCTP_HEADER header;
82     NVDM_PACKET nvdmPacket;
83 } MCTP_PACKET, *PMCTP_PACKET;
84 
85 // Type of packet, can either be SOM, EOM, neither, or both (1-packet messages)
86 typedef enum mctp_packet_state
87 {
88     MCTP_PACKET_STATE_START,
89     MCTP_PACKET_STATE_INTERMEDIATE,
90     MCTP_PACKET_STATE_END,
91     MCTP_PACKET_STATE_SINGLE_PACKET
92 } MCTP_PACKET_STATE, *PMCTP_PACKET_STATE;
93 
94 NvlStatus nvswitch_fsp_read_message(nvswitch_device *device, NvU8 *pPayloadBuffer, NvU32 payloadBufferSize);
95 NvlStatus nvswitch_fsp_send_packet(nvswitch_device  *device, NvU8 *pPacket, NvU32 packetSize);
96 NvlStatus nvswitch_fsp_send_and_read_message(nvswitch_device  *device, NvU8 *pPayload, NvU32 size, NvU32 nvdmType, NvU8 *pResponsePayload, NvU32 responseBufferSize);
97 
98 #endif //_FSPRPC_NVSWITCH_H_
99