xref: /linux/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/ctrl.c (revision ab93e0dd72c37d378dd936f031ffb83ff2bd87ce)
1 /*
2  * Copyright 2023 Red Hat Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  */
22 #include <rm/rpc.h>
23 
24 #include "nvrm/ctrl.h"
25 #include "nvrm/rpcfn.h"
26 
27 static void
r535_gsp_rpc_rm_ctrl_done(struct nvkm_gsp_object * object,void * params)28 r535_gsp_rpc_rm_ctrl_done(struct nvkm_gsp_object *object, void *params)
29 {
30 	rpc_gsp_rm_control_v03_00 *rpc = to_payload_hdr(params, rpc);
31 
32 	if (!params)
33 		return;
34 	nvkm_gsp_rpc_done(object->client->gsp, rpc);
35 }
36 
37 static int
r535_gsp_rpc_rm_ctrl_push(struct nvkm_gsp_object * object,void ** params,u32 repc)38 r535_gsp_rpc_rm_ctrl_push(struct nvkm_gsp_object *object, void **params, u32 repc)
39 {
40 	rpc_gsp_rm_control_v03_00 *rpc = to_payload_hdr((*params), rpc);
41 	struct nvkm_gsp *gsp = object->client->gsp;
42 	int ret = 0;
43 
44 	rpc = nvkm_gsp_rpc_push(gsp, rpc, NVKM_GSP_RPC_REPLY_RECV, repc);
45 	if (IS_ERR_OR_NULL(rpc)) {
46 		*params = NULL;
47 		return PTR_ERR(rpc);
48 	}
49 
50 	if (rpc->status) {
51 		ret = r535_rpc_status_to_errno(rpc->status);
52 		if (ret != -EAGAIN && ret != -EBUSY)
53 			nvkm_error(&gsp->subdev, "cli:0x%08x obj:0x%08x ctrl cmd:0x%08x failed: 0x%08x\n",
54 				   object->client->object.handle, object->handle, rpc->cmd, rpc->status);
55 	}
56 
57 	if (repc)
58 		*params = rpc->params;
59 	else
60 		nvkm_gsp_rpc_done(gsp, rpc);
61 
62 	return ret;
63 }
64 
65 static void *
r535_gsp_rpc_rm_ctrl_get(struct nvkm_gsp_object * object,u32 cmd,u32 params_size)66 r535_gsp_rpc_rm_ctrl_get(struct nvkm_gsp_object *object, u32 cmd, u32 params_size)
67 {
68 	struct nvkm_gsp_client *client = object->client;
69 	struct nvkm_gsp *gsp = client->gsp;
70 	rpc_gsp_rm_control_v03_00 *rpc;
71 
72 	nvkm_debug(&gsp->subdev, "cli:0x%08x obj:0x%08x ctrl cmd:0x%08x params_size:%d\n",
73 		   client->object.handle, object->handle, cmd, params_size);
74 
75 	rpc = nvkm_gsp_rpc_get(gsp, NV_VGPU_MSG_FUNCTION_GSP_RM_CONTROL,
76 			       sizeof(*rpc) + params_size);
77 	if (IS_ERR(rpc))
78 		return rpc;
79 
80 	rpc->hClient    = client->object.handle;
81 	rpc->hObject    = object->handle;
82 	rpc->cmd	= cmd;
83 	rpc->status     = 0;
84 	rpc->paramsSize = params_size;
85 	return rpc->params;
86 }
87 
88 const struct nvkm_rm_api_ctrl
89 r535_ctrl = {
90 	.get = r535_gsp_rpc_rm_ctrl_get,
91 	.push = r535_gsp_rpc_rm_ctrl_push,
92 	.done = r535_gsp_rpc_rm_ctrl_done,
93 };
94