summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/boardobj/boardobj.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/boardobj/boardobj.c')
-rw-r--r--drivers/gpu/nvgpu/boardobj/boardobj.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/boardobj/boardobj.c b/drivers/gpu/nvgpu/boardobj/boardobj.c
new file mode 100644
index 00000000..f9be6981
--- /dev/null
+++ b/drivers/gpu/nvgpu/boardobj/boardobj.c
@@ -0,0 +1,94 @@
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
23#include <nvgpu/kmem.h>
24
25#include "gk20a/gk20a.h"
26#include "boardobj.h"
27#include "ctrl/ctrlboardobj.h"
28
29u32 boardobj_construct_super(struct gk20a *g, struct boardobj **ppboardobj,
30 u16 size, void *args)
31{
32 struct boardobj *pboardobj = NULL;
33 struct boardobj *devtmp = (struct boardobj *)args;
34
35 gk20a_dbg_info(" ");
36
37 if (devtmp == NULL)
38 return -EINVAL;
39
40 if (*ppboardobj == NULL) {
41 *ppboardobj = nvgpu_kzalloc(g, size);
42 if (*ppboardobj == NULL)
43 return -ENOMEM;
44 (*ppboardobj)->allocated = true;
45 }
46
47 pboardobj = *ppboardobj;
48 pboardobj->g = g;
49 pboardobj->type = devtmp->type;
50 pboardobj->idx = CTRL_BOARDOBJ_IDX_INVALID;
51 pboardobj->type_mask = BIT(pboardobj->type) | devtmp->type_mask;
52
53 pboardobj->implements = boardobj_implements_super;
54 pboardobj->destruct = boardobj_destruct_super;
55 pboardobj->pmudatainit = boardobj_pmudatainit_super;
56
57 nvgpu_list_add(&pboardobj->node, &g->boardobj_head);
58
59 return 0;
60}
61
62u32 boardobj_destruct_super(struct boardobj *pboardobj)
63{
64 gk20a_dbg_info("");
65 if (pboardobj == NULL)
66 return -EINVAL;
67
68 nvgpu_list_del(&pboardobj->node);
69 if (pboardobj->allocated)
70 nvgpu_kfree(pboardobj->g, pboardobj);
71
72 return 0;
73}
74
75bool boardobj_implements_super(struct gk20a *g, struct boardobj *pboardobj,
76 u8 type)
77{
78 gk20a_dbg_info("");
79
80 return (0 != (pboardobj->type_mask & BIT(type)));
81}
82
83u32 boardobj_pmudatainit_super(struct gk20a *g, struct boardobj *pboardobj,
84 struct nv_pmu_boardobj *pmudata)
85{
86 gk20a_dbg_info("");
87 if (pboardobj == NULL)
88 return -EINVAL;
89 if (pmudata == NULL)
90 return -EINVAL;
91 pmudata->type = pboardobj->type;
92 gk20a_dbg_info(" Done");
93 return 0;
94}