diff options
author | Lakshmanan M <lm@nvidia.com> | 2016-10-21 07:27:15 -0400 |
---|---|---|
committer | Deepak Nibade <dnibade@nvidia.com> | 2016-12-27 04:56:51 -0500 |
commit | 58b85dd106f35d16ff568f8836dcbc7a019854b4 (patch) | |
tree | a87c10e83f020bd9f414fa4dd0bea74d961034b3 /drivers/gpu/nvgpu/therm/thrmchannel.c | |
parent | 2f4405ddcb1cd7bb939d3b22ab72789afb435da6 (diff) |
gpu: nvgpu: Add thermal module support
The following CL contains the following VBIOS thermal table parsing
and PMU interface support.
1) Thermal device table
2) Thermal channel table
JIRA DNVGPU-130
Change-Id: Ie3abab4bf099a022b1b59db96811c2ed44079519
Signed-off-by: Lakshmanan M <lm@nvidia.com>
Reviewed-on: http://git-master/r/1240630
(cherry picked from commit 814962a4be0a8cd0cddc7bc5211c62308ab1fea2)
Reviewed-on: http://git-master/r/1246210
GVS: Gerrit_Virtual_Submit
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/therm/thrmchannel.c')
-rw-r--r-- | drivers/gpu/nvgpu/therm/thrmchannel.c | 247 |
1 files changed, 247 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..015e065b --- /dev/null +++ b/drivers/gpu/nvgpu/therm/thrmchannel.c | |||
@@ -0,0 +1,247 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
11 | * more details. | ||
12 | */ | ||
13 | |||
14 | #include "gk20a/gk20a.h" | ||
15 | #include "thrmchannel.h" | ||
16 | #include "include/bios.h" | ||
17 | #include "boardobj/boardobjgrp.h" | ||
18 | #include "boardobj/boardobjgrp_e32.h" | ||
19 | #include "pmuif/gpmuifboardobj.h" | ||
20 | #include "pmuif/gpmuifthermsensor.h" | ||
21 | #include "gm206/bios_gm206.h" | ||
22 | #include "gk20a/pmu_gk20a.h" | ||
23 | |||
24 | static u32 _therm_channel_pmudatainit_device(struct gk20a *g, | ||
25 | struct boardobj *board_obj_ptr, | ||
26 | struct nv_pmu_boardobj *ppmudata) | ||
27 | { | ||
28 | u32 status = 0; | ||
29 | struct therm_channel *pchannel; | ||
30 | struct therm_channel_device *ptherm_channel; | ||
31 | struct nv_pmu_therm_therm_channel_device_boardobj_set *pset; | ||
32 | |||
33 | status = boardobj_pmudatainit_super(g, board_obj_ptr, ppmudata); | ||
34 | if (status) { | ||
35 | gk20a_err(dev_from_gk20a(g), | ||
36 | "error updating pmu boardobjgrp for therm channel 0x%x", | ||
37 | status); | ||
38 | status = -ENOMEM; | ||
39 | goto done; | ||
40 | } | ||
41 | |||
42 | pchannel = (struct therm_channel *)board_obj_ptr; | ||
43 | pset = (struct nv_pmu_therm_therm_channel_device_boardobj_set *)ppmudata; | ||
44 | ptherm_channel = (struct therm_channel_device *)board_obj_ptr; | ||
45 | |||
46 | pset->super.scaling = pchannel->scaling; | ||
47 | pset->super.offset = pchannel->offset; | ||
48 | pset->super.temp_min = pchannel->temp_min; | ||
49 | pset->super.temp_max = pchannel->temp_max; | ||
50 | |||
51 | pset->therm_dev_idx = ptherm_channel->therm_dev_idx; | ||
52 | pset->therm_dev_prov_idx = ptherm_channel->therm_dev_prov_idx; | ||
53 | |||
54 | done: | ||
55 | return status; | ||
56 | } | ||
57 | static struct boardobj *construct_channel_device(struct gk20a *g, | ||
58 | void *pargs, u16 pargs_size, u8 type) | ||
59 | { | ||
60 | struct boardobj *board_obj_ptr = NULL; | ||
61 | struct therm_channel *pchannel; | ||
62 | struct therm_channel_device *pchannel_device; | ||
63 | u32 status; | ||
64 | struct therm_channel_device *therm_device = (struct therm_channel_device*)pargs; | ||
65 | |||
66 | status = boardobj_construct_super(g, &board_obj_ptr, | ||
67 | pargs_size, pargs); | ||
68 | if (status) | ||
69 | return NULL; | ||
70 | |||
71 | /* Set Super class interfaces */ | ||
72 | board_obj_ptr->pmudatainit = _therm_channel_pmudatainit_device; | ||
73 | |||
74 | pchannel = (struct therm_channel *)board_obj_ptr; | ||
75 | pchannel_device = (struct therm_channel_device *)board_obj_ptr; | ||
76 | |||
77 | pchannel->temp_min = 0; | ||
78 | pchannel->temp_max = 0; | ||
79 | |||
80 | pchannel->scaling = (1 << 8); | ||
81 | pchannel->offset = 0; | ||
82 | |||
83 | pchannel_device->therm_dev_idx = therm_device->therm_dev_idx; | ||
84 | pchannel_device->therm_dev_prov_idx = therm_device->therm_dev_prov_idx; | ||
85 | |||
86 | gk20a_dbg_info(" Done"); | ||
87 | |||
88 | return board_obj_ptr; | ||
89 | } | ||
90 | |||
91 | static u32 _therm_channel_pmudata_instget(struct gk20a *g, | ||
92 | struct nv_pmu_boardobjgrp *pmuboardobjgrp, | ||
93 | struct nv_pmu_boardobj **ppboardobjpmudata, | ||
94 | u8 idx) | ||
95 | { | ||
96 | struct nv_pmu_therm_therm_channel_boardobj_grp_set *pgrp_set = | ||
97 | (struct nv_pmu_therm_therm_channel_boardobj_grp_set *) | ||
98 | pmuboardobjgrp; | ||
99 | |||
100 | gk20a_dbg_info(""); | ||
101 | |||
102 | /*check whether pmuboardobjgrp has a valid boardobj in index*/ | ||
103 | if (((u32)BIT(idx) & | ||
104 | pgrp_set->hdr.data.super.obj_mask.super.data[0]) == 0) | ||
105 | return -EINVAL; | ||
106 | |||
107 | *ppboardobjpmudata = (struct nv_pmu_boardobj *) | ||
108 | &pgrp_set->objects[idx].data.board_obj; | ||
109 | |||
110 | gk20a_dbg_info(" Done"); | ||
111 | |||
112 | return 0; | ||
113 | } | ||
114 | |||
115 | static u32 devinit_get_therm_channel_table(struct gk20a *g, | ||
116 | struct therm_channels *pthermchannelobjs) | ||
117 | { | ||
118 | u32 status = 0; | ||
119 | u8 *therm_channel_table_ptr = NULL; | ||
120 | u8 *curr_therm_channel_table_ptr = NULL; | ||
121 | struct boardobj *boardobj; | ||
122 | struct therm_channel_1x_header therm_channel_table_header = { 0 }; | ||
123 | struct therm_channel_1x_entry *therm_channel_table_entry = NULL; | ||
124 | u32 index; | ||
125 | u32 obj_index = 0; | ||
126 | u16 therm_channel_size = 0; | ||
127 | union { | ||
128 | struct boardobj boardobj; | ||
129 | struct therm_channel therm_channel; | ||
130 | struct therm_channel_device device; | ||
131 | } therm_channel_data; | ||
132 | |||
133 | gk20a_dbg_info(""); | ||
134 | |||
135 | if (g->ops.bios.get_perf_table_ptrs) { | ||
136 | therm_channel_table_ptr = (u8 *)g->ops.bios.get_perf_table_ptrs(g, | ||
137 | g->bios.perf_token, THERMAL_CHANNEL_TABLE); | ||
138 | if (therm_channel_table_ptr == NULL) { | ||
139 | status = -EINVAL; | ||
140 | goto done; | ||
141 | } | ||
142 | } | ||
143 | |||
144 | memcpy(&therm_channel_table_header, therm_channel_table_ptr, | ||
145 | VBIOS_THERM_CHANNEL_1X_HEADER_SIZE_09); | ||
146 | |||
147 | if (therm_channel_table_header.version != | ||
148 | VBIOS_THERM_CHANNEL_VERSION_1X) { | ||
149 | status = -EINVAL; | ||
150 | goto done; | ||
151 | } | ||
152 | |||
153 | if (therm_channel_table_header.header_size < | ||
154 | VBIOS_THERM_CHANNEL_1X_HEADER_SIZE_09) { | ||
155 | status = -EINVAL; | ||
156 | goto done; | ||
157 | } | ||
158 | |||
159 | curr_therm_channel_table_ptr = (therm_channel_table_ptr + | ||
160 | VBIOS_THERM_CHANNEL_1X_HEADER_SIZE_09); | ||
161 | |||
162 | for (index = 0; index < therm_channel_table_header.num_table_entries; | ||
163 | index++) { | ||
164 | therm_channel_table_entry = (struct therm_channel_1x_entry *) | ||
165 | (curr_therm_channel_table_ptr + | ||
166 | (therm_channel_table_header.table_entry_size * index)); | ||
167 | |||
168 | if (therm_channel_table_entry->class_id != | ||
169 | NV_VBIOS_THERM_CHANNEL_1X_ENTRY_CLASS_DEVICE) { | ||
170 | continue; | ||
171 | } | ||
172 | |||
173 | therm_channel_data.device.therm_dev_idx = therm_channel_table_entry->param0; | ||
174 | therm_channel_data.device.therm_dev_prov_idx = therm_channel_table_entry->param1; | ||
175 | |||
176 | therm_channel_size = sizeof(struct therm_channel_device); | ||
177 | therm_channel_data.boardobj.type = CTRL_THERMAL_THERM_CHANNEL_CLASS_DEVICE; | ||
178 | |||
179 | boardobj = construct_channel_device(g, &therm_channel_data, | ||
180 | therm_channel_size, therm_channel_data.boardobj.type); | ||
181 | |||
182 | if (!boardobj) { | ||
183 | gk20a_err(dev_from_gk20a(g), | ||
184 | "unable to create thermal device for %d type %d", | ||
185 | index, therm_channel_data.boardobj.type); | ||
186 | status = -EINVAL; | ||
187 | goto done; | ||
188 | } | ||
189 | |||
190 | status = boardobjgrp_objinsert(&pthermchannelobjs->super.super, | ||
191 | boardobj, obj_index); | ||
192 | |||
193 | if (status) { | ||
194 | gk20a_err(dev_from_gk20a(g), | ||
195 | "unable to insert thermal device boardobj for %d", index); | ||
196 | status = -EINVAL; | ||
197 | goto done; | ||
198 | } | ||
199 | |||
200 | ++obj_index; | ||
201 | } | ||
202 | |||
203 | done: | ||
204 | gk20a_dbg_info(" done status %x", status); | ||
205 | return status; | ||
206 | } | ||
207 | |||
208 | u32 therm_channel_sw_setup(struct gk20a *g) | ||
209 | { | ||
210 | u32 status; | ||
211 | struct boardobjgrp *pboardobjgrp = NULL; | ||
212 | struct therm_channels *pthermchannelobjs; | ||
213 | |||
214 | /* Construct the Super Class and override the Interfaces */ | ||
215 | status = boardobjgrpconstruct_e32(&g->therm_pmu.therm_channelobjs.super); | ||
216 | if (status) { | ||
217 | gk20a_err(dev_from_gk20a(g), | ||
218 | "error creating boardobjgrp for therm devices, status - 0x%x", | ||
219 | status); | ||
220 | goto done; | ||
221 | } | ||
222 | |||
223 | pboardobjgrp = &g->therm_pmu.therm_channelobjs.super.super; | ||
224 | pthermchannelobjs = &(g->therm_pmu.therm_channelobjs); | ||
225 | |||
226 | /* Override the Interfaces */ | ||
227 | pboardobjgrp->pmudatainstget = _therm_channel_pmudata_instget; | ||
228 | |||
229 | status = devinit_get_therm_channel_table(g, pthermchannelobjs); | ||
230 | if (status) | ||
231 | goto done; | ||
232 | |||
233 | BOARDOBJGRP_PMU_CONSTRUCT(pboardobjgrp, THERM, THERM_CHANNEL); | ||
234 | |||
235 | status = BOARDOBJGRP_PMU_CMD_GRP_SET_CONSTRUCT(g, pboardobjgrp, | ||
236 | therm, THERM, therm_channel, THERM_CHANNEL); | ||
237 | if (status) { | ||
238 | gk20a_err(dev_from_gk20a(g), | ||
239 | "error constructing PMU_BOARDOBJ_CMD_GRP_SET interface - 0x%x", | ||
240 | status); | ||
241 | goto done; | ||
242 | } | ||
243 | |||
244 | done: | ||
245 | gk20a_dbg_info(" done status %x", status); | ||
246 | return status; | ||
247 | } | ||