1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2022-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 NV_FIRMWARE_H
25 #define NV_FIRMWARE_H
26 
27 
28 
29 #include <nvtypes.h>
30 #include <nvmisc.h>
31 
32 typedef enum
33 {
34     NV_FIRMWARE_TYPE_GSP,
35     NV_FIRMWARE_TYPE_GSP_LOG
36 } nv_firmware_type_t;
37 
38 typedef enum
39 {
40     NV_FIRMWARE_CHIP_FAMILY_NULL = 0,
41     NV_FIRMWARE_CHIP_FAMILY_TU10X = 1,
42     NV_FIRMWARE_CHIP_FAMILY_TU11X = 2,
43     NV_FIRMWARE_CHIP_FAMILY_GA100 = 3,
44     NV_FIRMWARE_CHIP_FAMILY_GA10X = 4,
45     NV_FIRMWARE_CHIP_FAMILY_AD10X = 5,
46     NV_FIRMWARE_CHIP_FAMILY_GH100 = 6,
47     NV_FIRMWARE_CHIP_FAMILY_END,
48 } nv_firmware_chip_family_t;
49 
nv_firmware_chip_family_to_string(nv_firmware_chip_family_t fw_chip_family)50 static inline const char *nv_firmware_chip_family_to_string(
51     nv_firmware_chip_family_t fw_chip_family
52 )
53 {
54     switch (fw_chip_family) {
55         case NV_FIRMWARE_CHIP_FAMILY_GH100: return "gh100";
56         case NV_FIRMWARE_CHIP_FAMILY_AD10X: return "ad10x";
57         case NV_FIRMWARE_CHIP_FAMILY_GA10X: return "ga10x";
58         case NV_FIRMWARE_CHIP_FAMILY_GA100: return "ga100";
59         case NV_FIRMWARE_CHIP_FAMILY_TU11X: return "tu11x";
60         case NV_FIRMWARE_CHIP_FAMILY_TU10X: return "tu10x";
61 
62         case NV_FIRMWARE_CHIP_FAMILY_END:  // fall through
63         case NV_FIRMWARE_CHIP_FAMILY_NULL:
64             return NULL;
65     }
66     return NULL;
67 }
68 
69 // The includer (presumably nv.c) may optionally define
70 // NV_FIRMWARE_PATH_FOR_FILENAME(filename)
71 // to return a string "path" given a gsp_*.bin or gsp_log_*.bin filename.
72 //
73 // The function nv_firmware_path will then be available.
74 #if defined(NV_FIRMWARE_PATH_FOR_FILENAME)
nv_firmware_path(nv_firmware_type_t fw_type,nv_firmware_chip_family_t fw_chip_family)75 static inline const char *nv_firmware_path(
76     nv_firmware_type_t fw_type,
77     nv_firmware_chip_family_t fw_chip_family
78 )
79 {
80     if (fw_type == NV_FIRMWARE_TYPE_GSP)
81     {
82         switch (fw_chip_family)
83         {
84             case NV_FIRMWARE_CHIP_FAMILY_GH100:  // fall through
85             case NV_FIRMWARE_CHIP_FAMILY_AD10X:  // fall through
86             case NV_FIRMWARE_CHIP_FAMILY_GA10X:
87                 return NV_FIRMWARE_PATH_FOR_FILENAME("gsp_ga10x.bin");
88 
89             case NV_FIRMWARE_CHIP_FAMILY_GA100:  // fall through
90             case NV_FIRMWARE_CHIP_FAMILY_TU11X:  // fall through
91             case NV_FIRMWARE_CHIP_FAMILY_TU10X:
92                 return NV_FIRMWARE_PATH_FOR_FILENAME("gsp_tu10x.bin");
93 
94             case NV_FIRMWARE_CHIP_FAMILY_END:  // fall through
95             case NV_FIRMWARE_CHIP_FAMILY_NULL:
96                 return "";
97         }
98     }
99     else if (fw_type == NV_FIRMWARE_TYPE_GSP_LOG)
100     {
101         switch (fw_chip_family)
102         {
103             case NV_FIRMWARE_CHIP_FAMILY_GH100:  // fall through
104             case NV_FIRMWARE_CHIP_FAMILY_AD10X:  // fall through
105             case NV_FIRMWARE_CHIP_FAMILY_GA10X:
106                 return NV_FIRMWARE_PATH_FOR_FILENAME("gsp_log_ga10x.bin");
107 
108             case NV_FIRMWARE_CHIP_FAMILY_GA100:  // fall through
109             case NV_FIRMWARE_CHIP_FAMILY_TU11X:  // fall through
110             case NV_FIRMWARE_CHIP_FAMILY_TU10X:
111                 return NV_FIRMWARE_PATH_FOR_FILENAME("gsp_log_tu10x.bin");
112 
113             case NV_FIRMWARE_CHIP_FAMILY_END:  // fall through
114             case NV_FIRMWARE_CHIP_FAMILY_NULL:
115                 return "";
116         }
117     }
118 
119     return "";
120 }
121 #endif  // defined(NV_FIRMWARE_PATH_FOR_FILENAME)
122 
123 // The includer (presumably nv.c) may optionally define
124 // NV_FIRMWARE_DECLARE_GSP_FILENAME(filename)
125 // which will then be invoked (at the top-level) for each
126 // gsp_*.bin (but not gsp_log_*.bin)
127 #if defined(NV_FIRMWARE_DECLARE_GSP_FILENAME)
128 NV_FIRMWARE_DECLARE_GSP_FILENAME("gsp_ga10x.bin")
129 NV_FIRMWARE_DECLARE_GSP_FILENAME("gsp_tu10x.bin")
130 #endif  // defined(NV_FIRMWARE_DECLARE_GSP_FILENAME)
131 
132 #endif  // NV_FIRMWARE_DECLARE_GSP_FILENAME
133