1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 1993-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 #include "core/core.h"
25 #include "os/os.h"
26 #include "gpu/gpu.h"
27 #include "rmapi/rs_utils.h"
28 
29 #include "gpu/subdevice/subdevice_diag.h"
30 
31 #include "class/cl208f.h" // NV208F_NOTIFIERS_MAXCOUNT
32 #include "ctrl/ctrl208f/ctrl208fevent.h" // NV208F_CTRL_EVENT_SET_NOTIFICATION_ACTION_DISABLE
33 
34 #include "resserv/rs_client.h"
35 
36 
37 
38 //
39 // All state associated with subdevice diag objects is protected by
40 // the API sleep lock (there is no intersection with ISR/DPC code).
41 //
diagapiConstruct_IMPL(DiagApi * pDiagApi,CALL_CONTEXT * pCallContext,RS_RES_ALLOC_PARAMS_INTERNAL * pParams)42 NV_STATUS diagapiConstruct_IMPL
43 (
44     DiagApi                      *pDiagApi,
45     CALL_CONTEXT                 *pCallContext,
46     RS_RES_ALLOC_PARAMS_INTERNAL *pParams
47 )
48 {
49     NvU32 i;
50 
51     for (i = 0; i < NV208F_NOTIFIERS_MAXCOUNT; i++)
52     {
53         pDiagApi->notifyActions[i] =
54             NV208F_CTRL_EVENT_SET_NOTIFICATION_ACTION_DISABLE;
55     }
56 
57     return NV_OK;
58 }
59 
60 NV_STATUS
diagapiControl_IMPL(DiagApi * pDiagApi,CALL_CONTEXT * pCallContext,RS_RES_CONTROL_PARAMS_INTERNAL * pParams)61 diagapiControl_IMPL
62 (
63     DiagApi                        *pDiagApi,
64     CALL_CONTEXT                   *pCallContext,
65     RS_RES_CONTROL_PARAMS_INTERNAL *pParams
66 )
67 {
68     RmCtrlParams *pRmCtrlParams = pParams->pLegacyParams;
69     gpuresControlSetup(pParams, staticCast(pDiagApi, GpuResource));
70 
71     (void)pRmCtrlParams;
72     NV_PRINTF(LEVEL_INFO, "gpuControlSubDevice: cmd 0x%x\n",
73               pRmCtrlParams->cmd);
74 
75     return gpuresControl_IMPL(staticCast(pDiagApi, GpuResource), pCallContext, pParams);
76 }
77 
78 
79 NV_STATUS
diagapiControlFilter_IMPL(DiagApi * pDiagApi,CALL_CONTEXT * pCallContext,RS_RES_CONTROL_PARAMS_INTERNAL * pParams)80 diagapiControlFilter_IMPL
81 (
82     DiagApi *pDiagApi,
83     CALL_CONTEXT *pCallContext,
84     RS_RES_CONTROL_PARAMS_INTERNAL *pParams
85 )
86 {
87     OBJGPU *pGpu = GPU_RES_GET_GPU(pDiagApi);
88     RmCtrlParams *pRmCtrlParams = pParams->pLegacyParams;
89 
90     if (IS_VIRTUAL(pGpu))
91     {
92         switch (pRmCtrlParams->cmd)
93         {
94             // For Guest OS, only below RM controls are supported.
95             case NV208F_CTRL_CMD_FIFO_ENABLE_VIRTUAL_CONTEXT:
96             case NV208F_CTRL_CMD_FIFO_CHECK_ENGINE_CONTEXT:
97             case NV208F_CTRL_CMD_DMA_GET_VAS_BLOCK_DETAILS:
98                 break;
99 
100             // Fall though for unsupported CTRL
101             default:
102                 return NV_ERR_NOT_SUPPORTED;
103         }
104     }
105 
106     return NV_OK;
107 }
108 
109