diff options
Diffstat (limited to 'drivers/gpu/nvgpu/therm/thrmchannel.c')
-rw-r--r-- | drivers/gpu/nvgpu/therm/thrmchannel.c | 246 |
1 files changed, 246 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..b5a7dfd2 --- /dev/null +++ b/drivers/gpu/nvgpu/therm/thrmchannel.c | |||
@@ -0,0 +1,246 @@ | |||
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 | g->ops.therm.get_internal_sensor_limits(&pchannel->temp_max, | ||
78 | &pchannel->temp_min); | ||
79 | pchannel->scaling = (1 << 8); | ||
80 | pchannel->offset = 0; | ||
81 | |||
82 | pchannel_device->therm_dev_idx = therm_device->therm_dev_idx; | ||
83 | pchannel_device->therm_dev_prov_idx = therm_device->therm_dev_prov_idx; | ||
84 | |||
85 | gk20a_dbg_info(" Done"); | ||
86 | |||
87 | return board_obj_ptr; | ||
88 | } | ||
89 | |||
90 | static u32 _therm_channel_pmudata_instget(struct gk20a *g, | ||
91 | struct nv_pmu_boardobjgrp *pmuboardobjgrp, | ||
92 | struct nv_pmu_boardobj **ppboardobjpmudata, | ||
93 | u8 idx) | ||
94 | { | ||
95 | struct nv_pmu_therm_therm_channel_boardobj_grp_set *pgrp_set = | ||
96 | (struct nv_pmu_therm_therm_channel_boardobj_grp_set *) | ||
97 | pmuboardobjgrp; | ||
98 | |||
99 | gk20a_dbg_info(""); | ||
100 | |||
101 | /*check whether pmuboardobjgrp has a valid boardobj in index*/ | ||
102 | if (((u32)BIT(idx) & | ||
103 | pgrp_set->hdr.data.super.obj_mask.super.data[0]) == 0) | ||
104 | return -EINVAL; | ||
105 | |||
106 | *ppboardobjpmudata = (struct nv_pmu_boardobj *) | ||
107 | &pgrp_set->objects[idx].data.board_obj; | ||
108 | |||
109 | gk20a_dbg_info(" Done"); | ||
110 | |||
111 | return 0; | ||
112 | } | ||
113 | |||
114 | static u32 devinit_get_therm_channel_table(struct gk20a *g, | ||
115 | struct therm_channels *pthermchannelobjs) | ||
116 | { | ||
117 | u32 status = 0; | ||
118 | u8 *therm_channel_table_ptr = NULL; | ||
119 | u8 *curr_therm_channel_table_ptr = NULL; | ||
120 | struct boardobj *boardobj; | ||
121 | struct therm_channel_1x_header therm_channel_table_header = { 0 }; | ||
122 | struct therm_channel_1x_entry *therm_channel_table_entry = NULL; | ||
123 | u32 index; | ||
124 | u32 obj_index = 0; | ||
125 | u16 therm_channel_size = 0; | ||
126 | union { | ||
127 | struct boardobj boardobj; | ||
128 | struct therm_channel therm_channel; | ||
129 | struct therm_channel_device device; | ||
130 | } therm_channel_data; | ||
131 | |||
132 | gk20a_dbg_info(""); | ||
133 | |||
134 | if (g->ops.bios.get_perf_table_ptrs) { | ||
135 | therm_channel_table_ptr = (u8 *)g->ops.bios.get_perf_table_ptrs(g, | ||
136 | g->bios.perf_token, THERMAL_CHANNEL_TABLE); | ||
137 | if (therm_channel_table_ptr == NULL) { | ||
138 | status = -EINVAL; | ||
139 | goto done; | ||
140 | } | ||
141 | } | ||
142 | |||
143 | memcpy(&therm_channel_table_header, therm_channel_table_ptr, | ||
144 | VBIOS_THERM_CHANNEL_1X_HEADER_SIZE_09); | ||
145 | |||
146 | if (therm_channel_table_header.version != | ||
147 | VBIOS_THERM_CHANNEL_VERSION_1X) { | ||
148 | status = -EINVAL; | ||
149 | goto done; | ||
150 | } | ||
151 | |||
152 | if (therm_channel_table_header.header_size < | ||
153 | VBIOS_THERM_CHANNEL_1X_HEADER_SIZE_09) { | ||
154 | status = -EINVAL; | ||
155 | goto done; | ||
156 | } | ||
157 | |||
158 | curr_therm_channel_table_ptr = (therm_channel_table_ptr + | ||
159 | VBIOS_THERM_CHANNEL_1X_HEADER_SIZE_09); | ||
160 | |||
161 | for (index = 0; index < therm_channel_table_header.num_table_entries; | ||
162 | index++) { | ||
163 | therm_channel_table_entry = (struct therm_channel_1x_entry *) | ||
164 | (curr_therm_channel_table_ptr + | ||
165 | (therm_channel_table_header.table_entry_size * index)); | ||
166 | |||
167 | if (therm_channel_table_entry->class_id != | ||
168 | NV_VBIOS_THERM_CHANNEL_1X_ENTRY_CLASS_DEVICE) { | ||
169 | continue; | ||
170 | } | ||
171 | |||
172 | therm_channel_data.device.therm_dev_idx = therm_channel_table_entry->param0; | ||
173 | therm_channel_data.device.therm_dev_prov_idx = therm_channel_table_entry->param1; | ||
174 | |||
175 | therm_channel_size = sizeof(struct therm_channel_device); | ||
176 | therm_channel_data.boardobj.type = CTRL_THERMAL_THERM_CHANNEL_CLASS_DEVICE; | ||
177 | |||
178 | boardobj = construct_channel_device(g, &therm_channel_data, | ||
179 | therm_channel_size, therm_channel_data.boardobj.type); | ||
180 | |||
181 | if (!boardobj) { | ||
182 | gk20a_err(dev_from_gk20a(g), | ||
183 | "unable to create thermal device for %d type %d", | ||
184 | index, therm_channel_data.boardobj.type); | ||
185 | status = -EINVAL; | ||
186 | goto done; | ||
187 | } | ||
188 | |||
189 | status = boardobjgrp_objinsert(&pthermchannelobjs->super.super, | ||
190 | boardobj, obj_index); | ||
191 | |||
192 | if (status) { | ||
193 | gk20a_err(dev_from_gk20a(g), | ||
194 | "unable to insert thermal device boardobj for %d", index); | ||
195 | status = -EINVAL; | ||
196 | goto done; | ||
197 | } | ||
198 | |||
199 | ++obj_index; | ||
200 | } | ||
201 | |||
202 | done: | ||
203 | gk20a_dbg_info(" done status %x", status); | ||
204 | return status; | ||
205 | } | ||
206 | |||
207 | u32 therm_channel_sw_setup(struct gk20a *g) | ||
208 | { | ||
209 | u32 status; | ||
210 | struct boardobjgrp *pboardobjgrp = NULL; | ||
211 | struct therm_channels *pthermchannelobjs; | ||
212 | |||
213 | /* Construct the Super Class and override the Interfaces */ | ||
214 | status = boardobjgrpconstruct_e32(&g->therm_pmu.therm_channelobjs.super); | ||
215 | if (status) { | ||
216 | gk20a_err(dev_from_gk20a(g), | ||
217 | "error creating boardobjgrp for therm devices, status - 0x%x", | ||
218 | status); | ||
219 | goto done; | ||
220 | } | ||
221 | |||
222 | pboardobjgrp = &g->therm_pmu.therm_channelobjs.super.super; | ||
223 | pthermchannelobjs = &(g->therm_pmu.therm_channelobjs); | ||
224 | |||
225 | /* Override the Interfaces */ | ||
226 | pboardobjgrp->pmudatainstget = _therm_channel_pmudata_instget; | ||
227 | |||
228 | status = devinit_get_therm_channel_table(g, pthermchannelobjs); | ||
229 | if (status) | ||
230 | goto done; | ||
231 | |||
232 | BOARDOBJGRP_PMU_CONSTRUCT(pboardobjgrp, THERM, THERM_CHANNEL); | ||
233 | |||
234 | status = BOARDOBJGRP_PMU_CMD_GRP_SET_CONSTRUCT(g, pboardobjgrp, | ||
235 | therm, THERM, therm_channel, THERM_CHANNEL); | ||
236 | if (status) { | ||
237 | gk20a_err(dev_from_gk20a(g), | ||
238 | "error constructing PMU_BOARDOBJ_CMD_GRP_SET interface - 0x%x", | ||
239 | status); | ||
240 | goto done; | ||
241 | } | ||
242 | |||
243 | done: | ||
244 | gk20a_dbg_info(" done status %x", status); | ||
245 | return status; | ||
246 | } | ||