diff options
Diffstat (limited to 'drivers/gpu/nvgpu/therm/thrmchannel.c')
-rw-r--r-- | drivers/gpu/nvgpu/therm/thrmchannel.c | 253 |
1 files changed, 253 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/therm/thrmchannel.c b/drivers/gpu/nvgpu/therm/thrmchannel.c new file mode 100644 index 00000000..f8be8430 --- /dev/null +++ b/drivers/gpu/nvgpu/therm/thrmchannel.c | |||
@@ -0,0 +1,253 @@ | |||
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/bios.h> | ||
24 | #include <nvgpu/pmuif/nvgpu_gpmu_cmdif.h> | ||
25 | |||
26 | #include "gk20a/gk20a.h" | ||
27 | #include "thrmchannel.h" | ||
28 | #include "boardobj/boardobjgrp.h" | ||
29 | #include "boardobj/boardobjgrp_e32.h" | ||
30 | #include "gp106/bios_gp106.h" | ||
31 | |||
32 | static u32 _therm_channel_pmudatainit_device(struct gk20a *g, | ||
33 | struct boardobj *board_obj_ptr, | ||
34 | struct nv_pmu_boardobj *ppmudata) | ||
35 | { | ||
36 | u32 status = 0; | ||
37 | struct therm_channel *pchannel; | ||
38 | struct therm_channel_device *ptherm_channel; | ||
39 | struct nv_pmu_therm_therm_channel_device_boardobj_set *pset; | ||
40 | |||
41 | status = boardobj_pmudatainit_super(g, board_obj_ptr, ppmudata); | ||
42 | if (status) { | ||
43 | nvgpu_err(g, | ||
44 | "error updating pmu boardobjgrp for therm channel 0x%x", | ||
45 | status); | ||
46 | status = -ENOMEM; | ||
47 | goto done; | ||
48 | } | ||
49 | |||
50 | pchannel = (struct therm_channel *)board_obj_ptr; | ||
51 | pset = (struct nv_pmu_therm_therm_channel_device_boardobj_set *)ppmudata; | ||
52 | ptherm_channel = (struct therm_channel_device *)board_obj_ptr; | ||
53 | |||
54 | pset->super.scaling = pchannel->scaling; | ||
55 | pset->super.offset = pchannel->offset; | ||
56 | pset->super.temp_min = pchannel->temp_min; | ||
57 | pset->super.temp_max = pchannel->temp_max; | ||
58 | |||
59 | pset->therm_dev_idx = ptherm_channel->therm_dev_idx; | ||
60 | pset->therm_dev_prov_idx = ptherm_channel->therm_dev_prov_idx; | ||
61 | |||
62 | done: | ||
63 | return status; | ||
64 | } | ||
65 | static struct boardobj *construct_channel_device(struct gk20a *g, | ||
66 | void *pargs, u16 pargs_size, u8 type) | ||
67 | { | ||
68 | struct boardobj *board_obj_ptr = NULL; | ||
69 | struct therm_channel *pchannel; | ||
70 | struct therm_channel_device *pchannel_device; | ||
71 | u32 status; | ||
72 | struct therm_channel_device *therm_device = (struct therm_channel_device*)pargs; | ||
73 | |||
74 | status = boardobj_construct_super(g, &board_obj_ptr, | ||
75 | pargs_size, pargs); | ||
76 | if (status) | ||
77 | return NULL; | ||
78 | |||
79 | /* Set Super class interfaces */ | ||
80 | board_obj_ptr->pmudatainit = _therm_channel_pmudatainit_device; | ||
81 | |||
82 | pchannel = (struct therm_channel *)board_obj_ptr; | ||
83 | pchannel_device = (struct therm_channel_device *)board_obj_ptr; | ||
84 | |||
85 | g->ops.therm.get_internal_sensor_limits(&pchannel->temp_max, | ||
86 | &pchannel->temp_min); | ||
87 | pchannel->scaling = (1 << 8); | ||
88 | pchannel->offset = 0; | ||
89 | |||
90 | pchannel_device->therm_dev_idx = therm_device->therm_dev_idx; | ||
91 | pchannel_device->therm_dev_prov_idx = therm_device->therm_dev_prov_idx; | ||
92 | |||
93 | gk20a_dbg_info(" Done"); | ||
94 | |||
95 | return board_obj_ptr; | ||
96 | } | ||
97 | |||
98 | static u32 _therm_channel_pmudata_instget(struct gk20a *g, | ||
99 | struct nv_pmu_boardobjgrp *pmuboardobjgrp, | ||
100 | struct nv_pmu_boardobj **ppboardobjpmudata, | ||
101 | u8 idx) | ||
102 | { | ||
103 | struct nv_pmu_therm_therm_channel_boardobj_grp_set *pgrp_set = | ||
104 | (struct nv_pmu_therm_therm_channel_boardobj_grp_set *) | ||
105 | pmuboardobjgrp; | ||
106 | |||
107 | gk20a_dbg_info(""); | ||
108 | |||
109 | /*check whether pmuboardobjgrp has a valid boardobj in index*/ | ||
110 | if (((u32)BIT(idx) & | ||
111 | pgrp_set->hdr.data.super.obj_mask.super.data[0]) == 0) | ||
112 | return -EINVAL; | ||
113 | |||
114 | *ppboardobjpmudata = (struct nv_pmu_boardobj *) | ||
115 | &pgrp_set->objects[idx].data.board_obj; | ||
116 | |||
117 | gk20a_dbg_info(" Done"); | ||
118 | |||
119 | return 0; | ||
120 | } | ||
121 | |||
122 | static u32 devinit_get_therm_channel_table(struct gk20a *g, | ||
123 | struct therm_channels *pthermchannelobjs) | ||
124 | { | ||
125 | u32 status = 0; | ||
126 | u8 *therm_channel_table_ptr = NULL; | ||
127 | u8 *curr_therm_channel_table_ptr = NULL; | ||
128 | struct boardobj *boardobj; | ||
129 | struct therm_channel_1x_header therm_channel_table_header = { 0 }; | ||
130 | struct therm_channel_1x_entry *therm_channel_table_entry = NULL; | ||
131 | u32 index; | ||
132 | u32 obj_index = 0; | ||
133 | u16 therm_channel_size = 0; | ||
134 | union { | ||
135 | struct boardobj boardobj; | ||
136 | struct therm_channel therm_channel; | ||
137 | struct therm_channel_device device; | ||
138 | } therm_channel_data; | ||
139 | |||
140 | gk20a_dbg_info(""); | ||
141 | |||
142 | therm_channel_table_ptr = (u8 *)nvgpu_bios_get_perf_table_ptrs(g, | ||
143 | g->bios.perf_token, THERMAL_CHANNEL_TABLE); | ||
144 | if (therm_channel_table_ptr == NULL) { | ||
145 | status = -EINVAL; | ||
146 | goto done; | ||
147 | } | ||
148 | |||
149 | memcpy(&therm_channel_table_header, therm_channel_table_ptr, | ||
150 | VBIOS_THERM_CHANNEL_1X_HEADER_SIZE_09); | ||
151 | |||
152 | if (therm_channel_table_header.version != | ||
153 | VBIOS_THERM_CHANNEL_VERSION_1X) { | ||
154 | status = -EINVAL; | ||
155 | goto done; | ||
156 | } | ||
157 | |||
158 | if (therm_channel_table_header.header_size < | ||
159 | VBIOS_THERM_CHANNEL_1X_HEADER_SIZE_09) { | ||
160 | status = -EINVAL; | ||
161 | goto done; | ||
162 | } | ||
163 | |||
164 | curr_therm_channel_table_ptr = (therm_channel_table_ptr + | ||
165 | VBIOS_THERM_CHANNEL_1X_HEADER_SIZE_09); | ||
166 | |||
167 | for (index = 0; index < therm_channel_table_header.num_table_entries; | ||
168 | index++) { | ||
169 | therm_channel_table_entry = (struct therm_channel_1x_entry *) | ||
170 | (curr_therm_channel_table_ptr + | ||
171 | (therm_channel_table_header.table_entry_size * index)); | ||
172 | |||
173 | if (therm_channel_table_entry->class_id != | ||
174 | NV_VBIOS_THERM_CHANNEL_1X_ENTRY_CLASS_DEVICE) { | ||
175 | continue; | ||
176 | } | ||
177 | |||
178 | therm_channel_data.device.therm_dev_idx = therm_channel_table_entry->param0; | ||
179 | therm_channel_data.device.therm_dev_prov_idx = therm_channel_table_entry->param1; | ||
180 | |||
181 | therm_channel_size = sizeof(struct therm_channel_device); | ||
182 | therm_channel_data.boardobj.type = CTRL_THERMAL_THERM_CHANNEL_CLASS_DEVICE; | ||
183 | |||
184 | boardobj = construct_channel_device(g, &therm_channel_data, | ||
185 | therm_channel_size, therm_channel_data.boardobj.type); | ||
186 | |||
187 | if (!boardobj) { | ||
188 | nvgpu_err(g, | ||
189 | "unable to create thermal device for %d type %d", | ||
190 | index, therm_channel_data.boardobj.type); | ||
191 | status = -EINVAL; | ||
192 | goto done; | ||
193 | } | ||
194 | |||
195 | status = boardobjgrp_objinsert(&pthermchannelobjs->super.super, | ||
196 | boardobj, obj_index); | ||
197 | |||
198 | if (status) { | ||
199 | nvgpu_err(g, | ||
200 | "unable to insert thermal device boardobj for %d", index); | ||
201 | status = -EINVAL; | ||
202 | goto done; | ||
203 | } | ||
204 | |||
205 | ++obj_index; | ||
206 | } | ||
207 | |||
208 | done: | ||
209 | gk20a_dbg_info(" done status %x", status); | ||
210 | return status; | ||
211 | } | ||
212 | |||
213 | u32 therm_channel_sw_setup(struct gk20a *g) | ||
214 | { | ||
215 | u32 status; | ||
216 | struct boardobjgrp *pboardobjgrp = NULL; | ||
217 | struct therm_channels *pthermchannelobjs; | ||
218 | |||
219 | /* Construct the Super Class and override the Interfaces */ | ||
220 | status = boardobjgrpconstruct_e32(g, | ||
221 | &g->therm_pmu.therm_channelobjs.super); | ||
222 | if (status) { | ||
223 | nvgpu_err(g, | ||
224 | "error creating boardobjgrp for therm devices, status - 0x%x", | ||
225 | status); | ||
226 | goto done; | ||
227 | } | ||
228 | |||
229 | pboardobjgrp = &g->therm_pmu.therm_channelobjs.super.super; | ||
230 | pthermchannelobjs = &(g->therm_pmu.therm_channelobjs); | ||
231 | |||
232 | /* Override the Interfaces */ | ||
233 | pboardobjgrp->pmudatainstget = _therm_channel_pmudata_instget; | ||
234 | |||
235 | status = devinit_get_therm_channel_table(g, pthermchannelobjs); | ||
236 | if (status) | ||
237 | goto done; | ||
238 | |||
239 | BOARDOBJGRP_PMU_CONSTRUCT(pboardobjgrp, THERM, THERM_CHANNEL); | ||
240 | |||
241 | status = BOARDOBJGRP_PMU_CMD_GRP_SET_CONSTRUCT(g, pboardobjgrp, | ||
242 | therm, THERM, therm_channel, THERM_CHANNEL); | ||
243 | if (status) { | ||
244 | nvgpu_err(g, | ||
245 | "error constructing PMU_BOARDOBJ_CMD_GRP_SET interface - 0x%x", | ||
246 | status); | ||
247 | goto done; | ||
248 | } | ||
249 | |||
250 | done: | ||
251 | gk20a_dbg_info(" done status %x", status); | ||
252 | return status; | ||
253 | } | ||