1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2019-2020 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 _SOEIFTHERM_H_
25 #define _SOEIFTHERM_H_
26 
27 #include "nvfixedtypes.h"
28 
29 /*!
30  * @file   soeiftherm.h
31  * @brief  SOE Thermal Command Queue
32  *
33  *         The Therm unit ID will be used for sending and recieving
34  *         Command Messages between driver and Thermal unt of SOE
35  */
36 
37 /* ------------------------ Defines ---------------------------------*/
38 
39 // Macros for FXP9.5 conversion
40 
41 #define NV_TSENSE_FXP_9_5_INTEGER            13:4
42 #define NV_TSENSE_FXP_9_5_FRACTIONAL         4:0
43 
44 // Convert 32 bit Signed integer or Floating Point value to FXP9.5
45 #define NV_TSENSE_CONVERT_TO_FXP_9_5(val)  \
46        (NvU32) (val *(1 << DRF_SIZE(NV_TSENSE_FXP_9_5_FRACTIONAL)))
47 
48 // Convert FXP 9.5 to Celsius (Works only for temperatures >= 0)
49 #define NV_TSENSE_FXP_9_5_TO_CELSIUS(fxp)    \
50        (NvU32) (fxp /(1 << DRF_SIZE(NV_TSENSE_FXP_9_5_FRACTIONAL)))
51 
52 // Convert FXP 9.5 to NvTemp
53 #define NV_TSENSE_FXP_9_5_SIGN(fxp)  \
54     DRF_VAL(_TYPES, _SFXP, _INTEGER_SIGN(9,5), fxp)
55 
56 #define NV_TSENSE_FXP_9_5_TO_24_8(fxp)                  \
57     (NvTemp) ((NV_TSENSE_FXP_9_5_SIGN(fxp) ==           \
58              NV_TYPES_SFXP_INTEGER_SIGN_NEGATIVE ?      \
59              DRF_SHIFTMASK(31:17) : 0x0) | (fxp << 3))
60 
61 /*!
62  * Macros for NvType <-> Celsius temperature conversion.
63  */
64 #define RM_SOE_CELSIUS_TO_NV_TEMP(cel)                                      \
65                                 NV_TYPES_S32_TO_SFXP_X_Y(24,8,(cel))
66 #define RM_SOE_NV_TEMP_TO_CELSIUS_TRUNCED(nvt)                              \
67                                 NV_TYPES_SFXP_X_Y_TO_S32(24,8,(nvt))
68 #define RM_SOE_NV_TEMP_TO_CELSIUS_ROUNDED(nvt)                              \
69                                 NV_TYPES_SFXP_X_Y_TO_S32_ROUNDED(24,8,(nvt))
70 
71 /*!
72  * Thermal Message IDs
73  */
74 enum
75 {
76     RM_SOE_THERM_MSG_ID_SLOWDOWN_STATUS,
77     RM_SOE_THERM_MSG_ID_SHUTDOWN_STATUS,
78     RM_SOE_THERM_MSG_ID_ACK_FORCE_SLOWDOWN,
79 };
80 
81 /*!
82  * @brief message for thermal shutdown
83  */
84 typedef struct
85 {
86     NvU8   msgType;
87     NvTemp maxTemperature;
88     NvTemp overtThreshold;
89 
90     struct
91     {
92         NvBool bTsense;
93         NvBool bPmgr;
94     }source;
95 } RM_SOE_THERM_MSG_SHUTDOWN_STATUS;
96 
97 /*!
98  * @brief message for thermal slowdown
99  */
100 typedef struct
101 {
102     NvU8   msgType;
103     NvBool bSlowdown;
104     NvTemp maxTemperature;
105     NvTemp warnThreshold;
106     NvBool bLinksL1Status;
107 
108     struct
109     {
110         NvBool bTsense;
111         NvBool bPmgr;
112     }source;
113 } RM_SOE_THERM_MSG_SLOWDOWN_STATUS;
114 
115 /*!
116  * A simple union of all the Thermal messages.
117  * Use the 'msgType' variable to determine the actual type of the message.
118  */
119 typedef union
120 {
121     NvU8  msgType;
122     // The following structs are expected to include cmdType as the first member
123     RM_SOE_THERM_MSG_SLOWDOWN_STATUS  slowdown;
124     RM_SOE_THERM_MSG_SHUTDOWN_STATUS  shutdown;
125 }RM_SOE_THERM_MSG;
126 
127 /*!
128  * Thermal Command types
129  */
130 enum
131 {
132     RM_SOE_THERM_FORCE_SLOWDOWN,
133     RM_SOE_THERM_SEND_MSG_TO_DRIVER,
134 };
135 
136 /*!
137  * @brief Force Thermal slowdown
138  */
139 typedef struct
140 {
141     NvU8   cmdType;
142     NvBool slowdown;
143     NvU32  periodUs;
144 } RM_SOE_THERM_CMD_FORCE_SLOWDOWN;
145 
146 /*!
147  * @brief Send aysncronous message about thermal events.
148  */
149 typedef struct
150 {
151     NvU8   cmdType;
152     union
153     {
154         NvU8 msgType;
155         RM_SOE_THERM_MSG_SLOWDOWN_STATUS  slowdown;
156         RM_SOE_THERM_MSG_SHUTDOWN_STATUS  shutdown;
157     } status;
158 } RM_SOE_THERM_CMD_SEND_ASYNC_MSG;
159 
160 /*!
161  * A simple union of all the therm commands. Use the 'cmdType' variable to
162  * determine the actual type of the command.
163  */
164 typedef union
165 {
166     NvU8  cmdType;
167     // The following structs are expected to include cmdType as the first member
168     RM_SOE_THERM_CMD_FORCE_SLOWDOWN  slowdown;
169     RM_SOE_THERM_CMD_SEND_ASYNC_MSG  msg;
170 }RM_SOE_THERM_CMD;
171 
172 #endif  // _SOEIFTHERM_H_
173 
174