summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/boardobj/boardobjgrp.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/boardobj/boardobjgrp.c')
-rw-r--r--drivers/gpu/nvgpu/boardobj/boardobjgrp.c787
1 files changed, 787 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/boardobj/boardobjgrp.c b/drivers/gpu/nvgpu/boardobj/boardobjgrp.c
new file mode 100644
index 00000000..caed11e9
--- /dev/null
+++ b/drivers/gpu/nvgpu/boardobj/boardobjgrp.c
@@ -0,0 +1,787 @@
1/*
2* Copyright (c) 2016-2017, 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
24#include "gk20a/gk20a.h"
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 u32 boardobjgrp_pmucmdsend(struct gk20a *g,
36 struct boardobjgrp *pboardobjgrp,
37 struct boardobjgrp_pmu_cmd *pcmd);
38struct boardobjgrp_pmucmdhandler_params {
39 /* Pointer to the BOARDOBJGRP associated with this CMD */
40 struct boardobjgrp *pboardobjgrp;
41 /* Pointer to structure representing this NV_PMU_BOARDOBJ_CMD_GRP */
42 struct boardobjgrp_pmu_cmd *pcmd;
43 /* Boolean indicating whether the PMU successfully handled the CMD */
44 u32 success;
45};
46
47u32 boardobjgrp_construct_super(struct gk20a *g, struct boardobjgrp *pboardobjgrp)
48{
49 gk20a_dbg_info("");
50
51 if (pboardobjgrp == NULL)
52 return -EINVAL;
53
54 if (pboardobjgrp->ppobjects == NULL)
55 return -EINVAL;
56
57 if (pboardobjgrp->mask == NULL)
58 return -EINVAL;
59
60 pboardobjgrp->g = g;
61 pboardobjgrp->objmask = 0;
62
63 pboardobjgrp->classid = 0;
64 pboardobjgrp->pmu.unitid = BOARDOBJGRP_UNIT_ID_INVALID;
65 pboardobjgrp->pmu.classid = BOARDOBJGRP_GRP_CLASS_ID_INVALID;
66 pboardobjgrp->pmu.set.id = BOARDOBJGRP_GRP_CMD_ID_INVALID;
67 pboardobjgrp->pmu.getstatus.id = BOARDOBJGRP_GRP_CMD_ID_INVALID;
68
69 /* Initialize basic interfaces */
70 pboardobjgrp->destruct = boardobjgrp_destruct_super;
71 pboardobjgrp->objinsert = boardobjgrp_objinsert_final;
72 pboardobjgrp->objgetbyidx = boardobjgrp_objgetbyidx_final;
73 pboardobjgrp->objgetnext = boardobjgrp_objgetnext_final;
74 pboardobjgrp->objremoveanddestroy =
75 boardobjgrp_objremoveanddestroy_final;
76
77 pboardobjgrp->pmuinithandle = boardobjgrp_pmuinithandle_impl;
78 pboardobjgrp->pmuhdrdatainit = boardobjgrp_pmuhdrdatainit_super;
79 pboardobjgrp->pmudatainit = boardobjgrp_pmudatainit_super;
80 pboardobjgrp->pmuset = boardobjgrp_pmuset_impl;
81 pboardobjgrp->pmugetstatus = boardobjgrp_pmugetstatus_impl;
82
83 pboardobjgrp->pmudatainstget = boardobjgrp_pmudatainstget_stub;
84 pboardobjgrp->pmustatusinstget = boardobjgrp_pmustatusinstget_stub;
85
86 pboardobjgrp->objmaxidx = CTRL_BOARDOBJ_IDX_INVALID;
87 pboardobjgrp->bconstructed = true;
88
89 nvgpu_list_add(&pboardobjgrp->node, &g->boardobjgrp_head);
90
91 return 0;
92}
93
94u32 boardobjgrp_destruct_impl(struct boardobjgrp *pboardobjgrp)
95{
96 gk20a_dbg_info("");
97
98 if (pboardobjgrp == NULL)
99 return -EINVAL;
100
101 if (!pboardobjgrp->bconstructed)
102 return 0;
103
104 return pboardobjgrp->destruct(pboardobjgrp);
105}
106
107u32 boardobjgrp_destruct_super(struct boardobjgrp *pboardobjgrp)
108{
109 struct boardobj *pboardobj;
110 struct gk20a *g = pboardobjgrp->g;
111 u32 status = 0;
112 u32 stat;
113 u8 index;
114
115 gk20a_dbg_info("");
116
117 if (pboardobjgrp->mask == NULL)
118 return -EINVAL;
119 if (pboardobjgrp->ppobjects == NULL)
120 return -EINVAL;
121
122 BOARDOBJGRP_FOR_EACH(pboardobjgrp, struct boardobj*, pboardobj, index) {
123 stat = pboardobjgrp->objremoveanddestroy(pboardobjgrp, index);
124 if (status == 0)
125 status = stat;
126
127 pboardobjgrp->ppobjects[index] = NULL;
128 pboardobjgrp->objmask &= ~BIT(index);
129 }
130
131 pboardobjgrp->objmask = 0;
132
133 if (pboardobjgrp->objmaxidx != CTRL_BOARDOBJ_IDX_INVALID) {
134 if (status == 0)
135 status = -EINVAL;
136
137 WARN_ON(true);
138 }
139
140 /* Destroy the PMU CMD data */
141 stat = boardobjgrp_pmucmd_destroy_impl(g, &pboardobjgrp->pmu.set);
142 if (status == 0)
143 status = stat;
144
145 stat = boardobjgrp_pmucmd_destroy_impl(g, &pboardobjgrp->pmu.getstatus);
146 if (status == 0)
147 status = stat;
148
149 nvgpu_list_del(&pboardobjgrp->node);
150
151 pboardobjgrp->bconstructed = false;
152
153 return status;
154}
155
156u32 boardobjgrp_pmucmd_construct_impl(struct gk20a *g, struct boardobjgrp
157 *pboardobjgrp, struct boardobjgrp_pmu_cmd *cmd, u8 id, u8 msgid,
158 u8 hdrsize, u8 entrysize, u16 fbsize)
159{
160 gk20a_dbg_info("");
161
162 /* Copy the parameters into the CMD*/
163 cmd->id = id;
164 cmd->msgid = msgid;
165 cmd->hdrsize = hdrsize;
166 cmd->entrysize = entrysize;
167 cmd->fbsize = fbsize;
168
169 return 0;
170}
171
172u32 boardobjgrp_pmucmd_destroy_impl(struct gk20a *g,
173 struct boardobjgrp_pmu_cmd *cmd)
174{
175 struct nvgpu_mem *mem = &cmd->surf.sysmem_desc;
176
177 nvgpu_pmu_surface_free(g, mem);
178 return 0;
179}
180
181u32 boardobjgrp_pmucmd_pmuinithandle_impl(struct gk20a *g,
182 struct boardobjgrp *pboardobjgrp,
183 struct boardobjgrp_pmu_cmd *pcmd)
184{
185 u32 status = 0;
186 struct nvgpu_mem *sysmem_desc = &pcmd->surf.sysmem_desc;
187
188 gk20a_dbg_info("");
189
190 if (pcmd->id == BOARDOBJGRP_GRP_CMD_ID_INVALID)
191 goto boardobjgrp_pmucmd_pmuinithandle_exit;
192
193 nvgpu_pmu_sysmem_surface_alloc(g, sysmem_desc, pcmd->fbsize);
194 /* we only have got sysmem later this will get copied to vidmem
195 surface*/
196 pcmd->surf.vidmem_desc.size = 0;
197
198 pcmd->buf = (struct nv_pmu_boardobjgrp_super *)sysmem_desc->cpu_va;
199
200boardobjgrp_pmucmd_pmuinithandle_exit:
201 return status;
202}
203
204u32 boardobjgrp_pmuinithandle_impl(struct gk20a *g,
205 struct boardobjgrp *pboardobjgrp)
206{
207 u32 status = 0;
208
209 gk20a_dbg_info("");
210
211 status = boardobjgrp_pmucmd_pmuinithandle_impl(g, pboardobjgrp,
212 &pboardobjgrp->pmu.set);
213 if (status) {
214 nvgpu_err(g, "failed to init pmu set cmd");
215 goto boardobjgrp_pmuinithandle_exit;
216 }
217
218 status = boardobjgrp_pmucmd_pmuinithandle_impl(g, pboardobjgrp,
219 &pboardobjgrp->pmu.getstatus);
220 if (status) {
221 nvgpu_err(g, "failed to init get status command");
222 goto boardobjgrp_pmuinithandle_exit;
223 }
224
225 /* If the GRP_SET CMD has not been allocated, nothing left to do. */
226 if (((pboardobjgrp->pmu.set.id) == BOARDOBJGRP_GRP_CMD_ID_INVALID) ||
227 (BOARDOBJGRP_IS_EMPTY(pboardobjgrp)))
228 goto boardobjgrp_pmuinithandle_exit;
229
230 /* Send the BOARDOBJGRP to the pmu via RM_PMU_BOARDOBJ_CMD_GRP. */
231 status = pboardobjgrp->pmuset(g, pboardobjgrp);
232 if (status)
233 nvgpu_err(g, "failed to send boardobg grp to PMU");
234
235boardobjgrp_pmuinithandle_exit:
236 return status;
237}
238
239
240u32 boardobjgrp_pmuhdrdatainit_super(struct gk20a *g, struct boardobjgrp
241 *pboardobjgrp, struct nv_pmu_boardobjgrp_super *pboardobjgrppmu,
242 struct boardobjgrpmask *mask)
243{
244 gk20a_dbg_info("");
245
246 if (pboardobjgrp == NULL)
247 return -EINVAL;
248 if (pboardobjgrppmu == NULL)
249 return -EINVAL;
250 pboardobjgrppmu->type = pboardobjgrp->type;
251 pboardobjgrppmu->class_id = pboardobjgrp->classid;
252 pboardobjgrppmu->obj_slots = BOARDOBJGRP_PMU_SLOTS_GET(pboardobjgrp);
253
254 gk20a_dbg_info(" Done");
255 return 0;
256}
257
258static u32 boardobjgrp_pmudatainstget_stub(struct gk20a *g,
259 struct nv_pmu_boardobjgrp *boardobjgrppmu,
260 struct nv_pmu_boardobj **ppboardobjpmudata, u8 idx)
261{
262 gk20a_dbg_info("");
263 return -EINVAL;
264}
265
266
267static u32 boardobjgrp_pmustatusinstget_stub(struct gk20a *g,
268 void *pboardobjgrppmu,
269 struct nv_pmu_boardobj_query **ppBoardobjpmustatus, u8 idx)
270{
271 gk20a_dbg_info("");
272 return -EINVAL;
273}
274
275u32 boardobjgrp_pmudatainit_legacy(struct gk20a *g,
276 struct boardobjgrp *pboardobjgrp,
277 struct nv_pmu_boardobjgrp_super *pboardobjgrppmu)
278{
279 u32 status = 0;
280 struct boardobj *pboardobj = NULL;
281 struct nv_pmu_boardobj *ppmudata = NULL;
282 u8 index;
283
284 gk20a_dbg_info("");
285
286 if (pboardobjgrp == NULL)
287 return -EINVAL;
288 if (pboardobjgrppmu == NULL)
289 return -EINVAL;
290
291 boardobjgrpe32hdrset((struct nv_pmu_boardobjgrp *)pboardobjgrppmu,
292 pboardobjgrp->objmask);
293
294 BOARDOBJGRP_FOR_EACH_INDEX_IN_MASK(32, index, pboardobjgrp->objmask) {
295 /* Obtain pointer to the current instance of the Object from the Group */
296 pboardobj = pboardobjgrp->objgetbyidx(pboardobjgrp, index);
297 if (NULL == pboardobj) {
298 nvgpu_err(g, "could not get object instance");
299 status = -EINVAL;
300 goto boardobjgrppmudatainit_legacy_done;
301 }
302
303 status = pboardobjgrp->pmudatainstget(g,
304 (struct nv_pmu_boardobjgrp *)pboardobjgrppmu,
305 &ppmudata, index);
306 if (status) {
307 nvgpu_err(g, "could not get object instance");
308 goto boardobjgrppmudatainit_legacy_done;
309 }
310
311 /* Initialize the PMU Data */
312 status = pboardobj->pmudatainit(g, pboardobj, ppmudata);
313 if (status) {
314 nvgpu_err(g,
315 "could not parse pmu for device %d", index);
316 goto boardobjgrppmudatainit_legacy_done;
317 }
318 }
319 BOARDOBJGRP_FOR_EACH_INDEX_IN_MASK_END
320
321boardobjgrppmudatainit_legacy_done:
322 gk20a_dbg_info(" Done");
323 return status;
324}
325
326u32 boardobjgrp_pmudatainit_super(struct gk20a *g, struct boardobjgrp
327 *pboardobjgrp, struct nv_pmu_boardobjgrp_super *pboardobjgrppmu)
328{
329 u32 status = 0;
330 struct boardobj *pboardobj = NULL;
331 struct nv_pmu_boardobj *ppmudata = NULL;
332 u8 index;
333
334 gk20a_dbg_info("");
335
336 if (pboardobjgrp == NULL)
337 return -EINVAL;
338 if (pboardobjgrppmu == NULL)
339 return -EINVAL;
340
341 /* Initialize the PMU HDR data.*/
342 status = pboardobjgrp->pmuhdrdatainit(g, pboardobjgrp, pboardobjgrppmu,
343 pboardobjgrp->mask);
344 if (status) {
345 nvgpu_err(g, "unable to init boardobjgrp pmuhdr data");
346 goto boardobjgrppmudatainit_super_done;
347 }
348
349 BOARDOBJGRP_FOR_EACH(pboardobjgrp, struct boardobj*, pboardobj, index) {
350 status = pboardobjgrp->pmudatainstget(g,
351 (struct nv_pmu_boardobjgrp *)pboardobjgrppmu,
352 &ppmudata, index);
353 if (status) {
354 nvgpu_err(g, "could not get object instance");
355 goto boardobjgrppmudatainit_super_done;
356 }
357
358 /* Initialize the PMU Data and send to PMU */
359 status = pboardobj->pmudatainit(g, pboardobj, ppmudata);
360 if (status) {
361 nvgpu_err(g,
362 "could not parse pmu for device %d", index);
363 goto boardobjgrppmudatainit_super_done;
364 }
365 }
366
367boardobjgrppmudatainit_super_done:
368 gk20a_dbg_info(" Done");
369 return status;
370}
371
372u32 boardobjgrp_pmuset_impl(struct gk20a *g, struct boardobjgrp *pboardobjgrp)
373{
374 u32 status = 0;
375 struct boardobjgrp_pmu_cmd *pcmd = &pboardobjgrp->pmu.set;
376 gk20a_dbg_info("");
377
378 if (pboardobjgrp == NULL)
379 return -EINVAL;
380
381 if (!pboardobjgrp->bconstructed)
382 return -EINVAL;
383
384 if (pboardobjgrp->pmu.unitid == BOARDOBJGRP_UNIT_ID_INVALID)
385 return -EINVAL;
386
387 if (pboardobjgrp->pmu.classid == BOARDOBJGRP_GRP_CLASS_ID_INVALID)
388 return -EINVAL;
389
390 if (pboardobjgrp->pmu.set.id == BOARDOBJGRP_GRP_CMD_ID_INVALID)
391 return -EINVAL;
392
393 if ((pcmd->hdrsize == 0) ||
394 (pcmd->entrysize == 0) ||
395 (pcmd->buf == NULL))
396 return -EINVAL;
397
398 /* If no objects in the group, return early */
399 if (BOARDOBJGRP_IS_EMPTY(pboardobjgrp))
400 return -EINVAL;
401
402 /* Initialize PMU buffer with BOARDOBJGRP data. */
403 memset(pcmd->buf, 0x0, pcmd->fbsize);
404 status = pboardobjgrp->pmudatainit(g, pboardobjgrp,
405 pcmd->buf);
406 if (status) {
407 nvgpu_err(g, "could not parse pmu data");
408 goto boardobjgrp_pmuset_exit;
409 }
410
411 /*
412 * Reset the boolean that indicates set status for most recent
413 * instance of BOARDOBJGRP.
414 */
415 pboardobjgrp->pmu.bset = false;
416
417 /*
418 * alloc mem in vidmem & copy constructed pmu boardobjgrp data from
419 * sysmem to vidmem
420 */
421 if (pcmd->surf.vidmem_desc.size == 0) {
422 nvgpu_pmu_vidmem_surface_alloc(g, &pcmd->surf.vidmem_desc,
423 pcmd->fbsize);
424 }
425 nvgpu_mem_wr_n(g, &pcmd->surf.vidmem_desc, 0, pcmd->buf, pcmd->fbsize);
426
427 /* Send the SET PMU CMD to the PMU */
428 status = boardobjgrp_pmucmdsend(g, pboardobjgrp,
429 pcmd);
430 if (status) {
431 nvgpu_err(g, "could not send SET CMD to PMU");
432 goto boardobjgrp_pmuset_exit;
433 }
434
435 pboardobjgrp->pmu.bset = true;
436
437boardobjgrp_pmuset_exit:
438 return status;
439}
440
441u32
442boardobjgrp_pmugetstatus_impl(struct gk20a *g, struct boardobjgrp *pboardobjgrp,
443 struct boardobjgrpmask *mask)
444{
445 u32 status = 0;
446 struct boardobjgrp_pmu_cmd *pcmd = &pboardobjgrp->pmu.getstatus;
447 struct boardobjgrp_pmu_cmd *pset = &pboardobjgrp->pmu.set;
448
449 gk20a_dbg_info("");
450
451 if (pboardobjgrp == NULL)
452 return -EINVAL;
453
454 if (!pboardobjgrp->bconstructed)
455 return -EINVAL;
456
457 if (pboardobjgrp->pmu.unitid == BOARDOBJGRP_UNIT_ID_INVALID)
458 return -EINVAL;
459
460 if (pboardobjgrp->pmu.classid == BOARDOBJGRP_GRP_CLASS_ID_INVALID)
461 return -EINVAL;
462
463 if (pboardobjgrp->pmu.set.id == BOARDOBJGRP_GRP_CMD_ID_INVALID)
464 return -EINVAL;
465
466 if ((pcmd->hdrsize == 0) ||
467 (pcmd->entrysize == 0) ||
468 (pcmd->buf == NULL))
469 return -EINVAL;
470
471 /* If no objects in the group, return early */
472 if (BOARDOBJGRP_IS_EMPTY(pboardobjgrp))
473 return -EINVAL;
474
475 /*
476 * Can only GET_STATUS if the BOARDOBJGRP has been previously SET to the
477 * PMU
478 */
479 if (!pboardobjgrp->pmu.bset)
480 return -EINVAL;
481
482 /*
483 * alloc mem in vidmem & copy constructed pmu boardobjgrp data from
484 * sysmem to vidmem
485 */
486 if (pcmd->surf.vidmem_desc.size == 0) {
487 nvgpu_pmu_vidmem_surface_alloc(g, &pcmd->surf.vidmem_desc,
488 pcmd->fbsize);
489 }
490
491 /*
492 * Initialize PMU buffer with the mask of BOARDOBJGRPs for which to
493 * retrieve status
494 */
495
496 memset(pcmd->buf, 0x0, pcmd->fbsize);
497 status = pboardobjgrp->pmuhdrdatainit(g, pboardobjgrp,
498 pcmd->buf, mask);
499 if (status) {
500 nvgpu_err(g, "could not init PMU HDR data");
501 goto boardobjgrp_pmugetstatus_exit;
502 }
503
504 nvgpu_mem_wr_n(g, &pcmd->surf.vidmem_desc, 0, pset->buf, pset->hdrsize);
505 /* Send the GET_STATUS PMU CMD to the PMU */
506 status = boardobjgrp_pmucmdsend(g, pboardobjgrp,
507 &pboardobjgrp->pmu.getstatus);
508 if (status) {
509 nvgpu_err(g, "could not send GET_STATUS cmd to PMU");
510 goto boardobjgrp_pmugetstatus_exit;
511 }
512
513 /*copy the data back to sysmem buffer that belongs to command*/
514 nvgpu_mem_rd_n(g, &pcmd->surf.vidmem_desc, 0, pcmd->buf, pcmd->fbsize);
515
516boardobjgrp_pmugetstatus_exit:
517 return status;
518}
519
520static u32
521boardobjgrp_objinsert_final(struct boardobjgrp *pboardobjgrp,
522 struct boardobj *pboardobj, u8 index)
523{
524
525 gk20a_dbg_info("");
526
527 if (pboardobjgrp == NULL)
528 return -EINVAL;
529
530 if (pboardobj == NULL)
531 return -EINVAL;
532
533 if (index > pboardobjgrp->objslots)
534 return -EINVAL;
535
536 if (pboardobjgrp->ppobjects[index] != NULL)
537 return -EINVAL;
538
539 /*
540 * Check that this BOARDOBJ has not already been added to a
541 * BOARDOBJGRP
542 */
543 if (pboardobj->idx != CTRL_BOARDOBJ_IDX_INVALID)
544 return -EINVAL;
545
546 pboardobjgrp->ppobjects[index] = pboardobj;
547 pboardobjgrp->objmaxidx = BOARDOBJGRP_IS_EMPTY(pboardobjgrp) ?
548 index : max(pboardobjgrp->objmaxidx, index);
549 pboardobj->idx = index;
550
551 pboardobjgrp->objmask |= BIT(index);
552
553 gk20a_dbg_info(" Done");
554
555 return boardobjgrpmask_bitset(pboardobjgrp->mask, index);
556}
557
558static struct boardobj *boardobjgrp_objgetbyidx_final(
559 struct boardobjgrp *pboardobjgrp, u8 index)
560{
561 if (!boardobjgrp_idxisvalid(pboardobjgrp, index))
562 return NULL;
563 return pboardobjgrp->ppobjects[index];
564}
565
566static struct boardobj *boardobjgrp_objgetnext_final(
567 struct boardobjgrp *pboardobjgrp, u8 *currentindex,
568 struct boardobjgrpmask *mask)
569{
570 struct boardobj *pboardobjnext = NULL;
571 u8 objmaxidx;
572 u8 index;
573
574 if (currentindex == NULL)
575 return NULL;
576
577 if (pboardobjgrp == NULL)
578 return NULL;
579
580 /* Search from next element unless first object was requested */
581 index = (*currentindex != CTRL_BOARDOBJ_IDX_INVALID) ?
582 (*currentindex + 1) : 0;
583
584 /* For the cases below in which we have to return NULL */
585 *currentindex = CTRL_BOARDOBJ_IDX_INVALID;
586
587
588 /* Validate provided mask */
589 if (mask != NULL) {
590 if (!(boardobjgrpmask_sizeeq(pboardobjgrp->mask, mask)))
591 return NULL;
592 }
593
594 objmaxidx = pboardobjgrp->objmaxidx;
595
596 if (objmaxidx != CTRL_BOARDOBJ_IDX_INVALID) {
597 for (; index <= objmaxidx; index++) {
598 pboardobjnext = pboardobjgrp->ppobjects[index];
599 if (pboardobjnext != NULL) {
600 /* Filter results using client provided mask.*/
601 if (mask != NULL) {
602 if (!boardobjgrpmask_bitget(mask,
603 index)) {
604 pboardobjnext = NULL;
605 continue;
606 }
607 }
608 *currentindex = index;
609 break;
610 }
611 }
612 }
613
614 return pboardobjnext;
615}
616
617static u32 boardobjgrp_objremoveanddestroy_final(
618 struct boardobjgrp *pboardobjgrp,
619 u8 index)
620{
621 u32 status = 0;
622 u32 stat;
623
624 gk20a_dbg_info("");
625
626 if (!boardobjgrp_idxisvalid(pboardobjgrp, index))
627 return -EINVAL;
628
629 if (pboardobjgrp->objmaxidx == CTRL_BOARDOBJ_IDX_INVALID)
630 return -EINVAL;
631
632 status = pboardobjgrp->ppobjects[index]->destruct(
633 pboardobjgrp->ppobjects[index]);
634
635 pboardobjgrp->ppobjects[index] = NULL;
636
637 pboardobjgrp->objmask &= ~BIT(index);
638
639 stat = boardobjgrpmask_bitclr(pboardobjgrp->mask, index);
640 if (stat) {
641 if (status == 0)
642 status = stat;
643 }
644
645 /* objmaxidx requires update only if that very object was removed */
646 if (pboardobjgrp->objmaxidx == index) {
647 pboardobjgrp->objmaxidx =
648 boardobjgrpmask_bitidxhighest(pboardobjgrp->mask);
649 }
650
651 return status;
652}
653
654void boardobjgrpe32hdrset(struct nv_pmu_boardobjgrp *hdr, u32 objmask)
655{
656 u32 slots = objmask;
657
658 gk20a_dbg_info("");
659
660 HIGHESTBITIDX_32(slots);
661 slots++;
662
663 hdr->super.type = CTRL_BOARDOBJGRP_TYPE_E32;
664 hdr->super.class_id = 0;
665 hdr->super.obj_slots = (u8)slots;
666 hdr->obj_mask = objmask;
667}
668
669static void boardobjgrp_pmucmdhandler(struct gk20a *g, struct pmu_msg *msg,
670 void *param, u32 handle, u32 status)
671{
672 struct nv_pmu_boardobj_msg_grp *pgrpmsg;
673 struct boardobjgrp_pmucmdhandler_params *phandlerparams =
674 (struct boardobjgrp_pmucmdhandler_params *)param;
675 struct boardobjgrp *pboardobjgrp = phandlerparams->pboardobjgrp;
676 struct boardobjgrp_pmu_cmd *pgrpcmd = phandlerparams->pcmd;
677
678 gk20a_dbg_info("");
679
680 pgrpmsg = &msg->msg.boardobj.grp;
681
682 if (pgrpmsg->class_id != pboardobjgrp->pmu.classid) {
683 nvgpu_err(g,
684 "Unrecognized GRP type: unit %x class id=0x%02x cmd id %x",
685 msg->hdr.unit_id, pboardobjgrp->pmu.classid,
686 pgrpcmd->id);
687 return;
688 }
689
690 if (msg->msg.boardobj.msg_type != pgrpcmd->msgid) {
691 nvgpu_err(g,
692 "unsupported msg for unit %x class %x cmd id %x msg %x",
693 msg->hdr.unit_id, pboardobjgrp->pmu.classid,
694 pgrpcmd->id, msg->msg.boardobj.msg_type);
695 return;
696 }
697
698 if (msg->msg.boardobj.grp_set.flcn_status != 0) {
699 nvgpu_err(g,
700 "cmd abort for unit %x class %x cmd id %x status %x",
701 msg->hdr.unit_id, pboardobjgrp->pmu.classid,
702 pgrpcmd->id,
703 msg->msg.boardobj.grp_set.flcn_status);
704 return;
705 }
706
707 phandlerparams->success = pgrpmsg->b_success ? 1 : 0;
708
709 if (!pgrpmsg->b_success) {
710 nvgpu_err(g,
711 "failed GRPCMD: msgtype=0x%x, classid=0x%x, cmd id %x",
712 pgrpmsg->msg_type, pgrpmsg->class_id,
713 pgrpcmd->id);
714 return;
715 }
716}
717
718static u32 boardobjgrp_pmucmdsend(struct gk20a *g,
719 struct boardobjgrp *pboardobjgrp,
720 struct boardobjgrp_pmu_cmd *pcmd)
721{
722 struct boardobjgrp_pmucmdhandler_params handlerparams;
723 struct pmu_payload payload;
724 struct nv_pmu_boardobj_cmd_grp *pgrpcmd;
725 struct pmu_cmd cmd;
726 u32 seqdesc;
727 u32 status = 0;
728
729 gk20a_dbg_info("");
730
731 memset(&payload, 0, sizeof(payload));
732 memset(&handlerparams, 0, sizeof(handlerparams));
733 memset(&cmd, 0, sizeof(struct pmu_cmd));
734 cmd.hdr.unit_id = pboardobjgrp->pmu.unitid;
735 cmd.hdr.size = sizeof(struct nv_pmu_boardobj_cmd_grp) +
736 sizeof(struct pmu_hdr);
737
738 pgrpcmd = &cmd.cmd.boardobj.grp;
739 pgrpcmd->cmd_type = pcmd->id;
740 pgrpcmd->class_id = pboardobjgrp->pmu.classid;
741 pgrpcmd->grp.hdr_size = pcmd->hdrsize;
742 pgrpcmd->grp.entry_size = pcmd->entrysize;
743
744 /*
745 * copy vidmem information to boardobj_cmd_grp
746 */
747 nvgpu_pmu_surface_describe(g, &pcmd->surf.vidmem_desc,
748 &pgrpcmd->grp.fb);
749
750 /*
751 * PMU reads command from sysmem so assigned
752 * "payload.in.buf = pcmd->buf"
753 * but PMU access pmu boardobjgrp data from vidmem copied above
754 */
755 payload.in.buf = pcmd->buf;
756 payload.in.size = max(pcmd->hdrsize, pcmd->entrysize);
757 payload.in.fb_size = PMU_CMD_SUBMIT_PAYLOAD_PARAMS_FB_SIZE_UNUSED;
758 payload.in.offset = offsetof(struct nv_pmu_boardobj_cmd_grp, grp);
759
760 /* Setup the handler params to communicate back results.*/
761 handlerparams.pboardobjgrp = pboardobjgrp;
762 handlerparams.pcmd = pcmd;
763 handlerparams.success = 0;
764
765 status = nvgpu_pmu_cmd_post(g, &cmd, NULL, &payload,
766 PMU_COMMAND_QUEUE_LPQ,
767 boardobjgrp_pmucmdhandler,
768 (void *)&handlerparams,
769 &seqdesc, ~0);
770 if (status) {
771 nvgpu_err(g,
772 "unable to post boardobj grp cmd for unit %x cmd id %x",
773 cmd.hdr.unit_id, pcmd->id);
774 goto boardobjgrp_pmucmdsend_exit;
775 }
776 pmu_wait_message_cond(&g->pmu,
777 gk20a_get_gr_idle_timeout(g),
778 &handlerparams.success, 1);
779 if (handlerparams.success == 0) {
780 nvgpu_err(g, "could not process cmd");
781 status = -ETIMEDOUT;
782 goto boardobjgrp_pmucmdsend_exit;
783 }
784
785boardobjgrp_pmucmdsend_exit:
786 return status;
787}