aboutsummaryrefslogtreecommitdiffstats
path: root/include/boardobj/boardobjgrp.c
diff options
context:
space:
mode:
Diffstat (limited to 'include/boardobj/boardobjgrp.c')
-rw-r--r--include/boardobj/boardobjgrp.c1046
1 files changed, 1046 insertions, 0 deletions
diff --git a/include/boardobj/boardobjgrp.c b/include/boardobj/boardobjgrp.c
new file mode 100644
index 0000000..6832070
--- /dev/null
+++ b/include/boardobj/boardobjgrp.c
@@ -0,0 +1,1046 @@
1/*
2* Copyright (c) 2016-2018, NVIDIA CORPORATION. All rights reserved.
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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21*/
22#include <nvgpu/bug.h>
23#include <nvgpu/gk20a.h>
24
25#include "boardobjgrp.h"
26#include "ctrl/ctrlboardobj.h"
27#include "boardobj.h"
28
29static boardobjgrp_objinsert boardobjgrp_objinsert_final;
30static boardobjgrp_objgetbyidx boardobjgrp_objgetbyidx_final;
31static boardobjgrp_objgetnext boardobjgrp_objgetnext_final;
32static boardobjgrp_objremoveanddestroy boardobjgrp_objremoveanddestroy_final;
33static boardobjgrp_pmudatainstget boardobjgrp_pmudatainstget_stub;
34static boardobjgrp_pmustatusinstget boardobjgrp_pmustatusinstget_stub;
35static int boardobjgrp_pmucmdsend(struct gk20a *g,
36 struct boardobjgrp *pboardobjgrp,
37 struct boardobjgrp_pmu_cmd *pcmd);
38static int boardobjgrp_pmucmdsend_rpc(struct gk20a *g,
39 struct boardobjgrp *pboardobjgrp,
40 struct boardobjgrp_pmu_cmd *pcmd,
41 bool copy_out);
42struct boardobjgrp_pmucmdhandler_params {
43 /* Pointer to the BOARDOBJGRP associated with this CMD */
44 struct boardobjgrp *pboardobjgrp;
45 /* Pointer to structure representing this NV_PMU_BOARDOBJ_CMD_GRP */
46 struct boardobjgrp_pmu_cmd *pcmd;
47 /* Boolean indicating whether the PMU successfully handled the CMD */
48 u32 success;
49};
50
51int boardobjgrp_construct_super(struct gk20a *g,
52 struct boardobjgrp *pboardobjgrp)
53{
54 nvgpu_log_info(g, " ");
55
56 if (pboardobjgrp == NULL) {
57 return -EINVAL;
58 }
59
60 if (pboardobjgrp->ppobjects == NULL) {
61 return -EINVAL;
62 }
63
64 if (pboardobjgrp->mask == NULL) {
65 return -EINVAL;
66 }
67
68 pboardobjgrp->g = g;
69 pboardobjgrp->objmask = 0;
70
71 pboardobjgrp->classid = 0;
72 pboardobjgrp->pmu.unitid = BOARDOBJGRP_UNIT_ID_INVALID;
73 pboardobjgrp->pmu.classid = BOARDOBJGRP_GRP_CLASS_ID_INVALID;
74 pboardobjgrp->pmu.bset = false;
75 pboardobjgrp->pmu.rpc_func_id = BOARDOBJGRP_GRP_RPC_FUNC_ID_INVALID;
76 pboardobjgrp->pmu.set.id = BOARDOBJGRP_GRP_CMD_ID_INVALID;
77 pboardobjgrp->pmu.getstatus.id = BOARDOBJGRP_GRP_CMD_ID_INVALID;
78
79 /* Initialize basic interfaces */
80 pboardobjgrp->destruct = boardobjgrp_destruct_super;
81 pboardobjgrp->objinsert = boardobjgrp_objinsert_final;
82 pboardobjgrp->objgetbyidx = boardobjgrp_objgetbyidx_final;
83 pboardobjgrp->objgetnext = boardobjgrp_objgetnext_final;
84 pboardobjgrp->objremoveanddestroy =
85 boardobjgrp_objremoveanddestroy_final;
86
87 pboardobjgrp->pmuinithandle = boardobjgrp_pmuinithandle_impl;
88 pboardobjgrp->pmuhdrdatainit = boardobjgrp_pmuhdrdatainit_super;
89 pboardobjgrp->pmudatainit = boardobjgrp_pmudatainit_super;
90 pboardobjgrp->pmuset =
91 g->ops.pmu_ver.boardobj.boardobjgrp_pmuset_impl;
92 pboardobjgrp->pmugetstatus =
93 g->ops.pmu_ver.boardobj.boardobjgrp_pmugetstatus_impl;
94
95 pboardobjgrp->pmudatainstget = boardobjgrp_pmudatainstget_stub;
96 pboardobjgrp->pmustatusinstget = boardobjgrp_pmustatusinstget_stub;
97
98 pboardobjgrp->objmaxidx = CTRL_BOARDOBJ_IDX_INVALID;
99 pboardobjgrp->bconstructed = true;
100
101 nvgpu_list_add(&pboardobjgrp->node, &g->boardobjgrp_head);
102
103 return 0;
104}
105
106int boardobjgrp_destruct_impl(struct boardobjgrp *pboardobjgrp)
107{
108 struct gk20a *g = pboardobjgrp->g;
109
110 nvgpu_log_info(g, " ");
111
112 if (pboardobjgrp == NULL) {
113 return -EINVAL;
114 }
115
116 if (!pboardobjgrp->bconstructed) {
117 return 0;
118 }
119
120 return pboardobjgrp->destruct(pboardobjgrp);
121}
122
123int boardobjgrp_destruct_super(struct boardobjgrp *pboardobjgrp)
124{
125 struct boardobj *pboardobj;
126 struct gk20a *g = pboardobjgrp->g;
127 int status = 0;
128 int stat;
129 u8 index;
130
131 nvgpu_log_info(g, " ");
132
133 if (pboardobjgrp->mask == NULL) {
134 return -EINVAL;
135 }
136 if (pboardobjgrp->ppobjects == NULL) {
137 return -EINVAL;
138 }
139
140 BOARDOBJGRP_FOR_EACH(pboardobjgrp, struct boardobj*, pboardobj, index) {
141 stat = pboardobjgrp->objremoveanddestroy(pboardobjgrp, index);
142 if (status == 0) {
143 status = stat;
144 }
145
146 pboardobjgrp->ppobjects[index] = NULL;
147 pboardobjgrp->objmask &= ~BIT(index);
148 }
149
150 pboardobjgrp->objmask = 0;
151
152 if (pboardobjgrp->objmaxidx != CTRL_BOARDOBJ_IDX_INVALID) {
153 if (status == 0) {
154 status = -EINVAL;
155 }
156
157 WARN_ON(true);
158 }
159
160 /* Destroy the PMU CMD data */
161 stat = boardobjgrp_pmucmd_destroy_impl(g, &pboardobjgrp->pmu.set);
162 if (status == 0) {
163 status = stat;
164 }
165
166 stat = boardobjgrp_pmucmd_destroy_impl(g, &pboardobjgrp->pmu.getstatus);
167 if (status == 0) {
168 status = stat;
169 }
170
171 nvgpu_list_del(&pboardobjgrp->node);
172
173 pboardobjgrp->bconstructed = false;
174
175 return status;
176}
177
178int boardobjgrp_pmucmd_construct_impl(struct gk20a *g, struct boardobjgrp
179 *pboardobjgrp, struct boardobjgrp_pmu_cmd *cmd, u8 id, u8 msgid,
180 u16 hdrsize, u16 entrysize, u16 fbsize, u32 ss_offset, u8 rpc_func_id)
181{
182 nvgpu_log_info(g, " ");
183
184 /* Copy the parameters into the CMD*/
185 cmd->id = id;
186 cmd->msgid = msgid;
187 cmd->hdrsize = (u8) hdrsize;
188 cmd->entrysize = (u8) entrysize;
189 cmd->fbsize = fbsize;
190
191 return 0;
192}
193
194int boardobjgrp_pmucmd_construct_impl_v1(struct gk20a *g, struct boardobjgrp
195 *pboardobjgrp, struct boardobjgrp_pmu_cmd *cmd, u8 id, u8 msgid,
196 u16 hdrsize, u16 entrysize, u16 fbsize, u32 ss_offset, u8 rpc_func_id)
197{
198 nvgpu_log_fn(g, " ");
199
200 /* Copy the parameters into the CMD*/
201 cmd->dmem_buffer_size = ((hdrsize > entrysize) ? hdrsize : entrysize);
202 cmd->super_surface_offset = ss_offset;
203 pboardobjgrp->pmu.rpc_func_id = rpc_func_id;
204 cmd->fbsize = fbsize;
205
206 nvgpu_log_fn(g, "DONE");
207 return 0;
208}
209
210int boardobjgrp_pmucmd_destroy_impl(struct gk20a *g,
211 struct boardobjgrp_pmu_cmd *cmd)
212{
213 struct nvgpu_mem *mem = &cmd->surf.sysmem_desc;
214
215 nvgpu_pmu_surface_free(g, mem);
216 return 0;
217}
218
219int is_boardobjgrp_pmucmd_id_valid_