diff options
author | Vijayakumar Subbu <vsubbu@nvidia.com> | 2016-07-28 01:29:15 -0400 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2016-09-29 16:17:46 -0400 |
commit | b17d9708c9e9930778de43de1edf1385acb13ebd (patch) | |
tree | fc485e96cc19575d463c61c8b80a09dd89745f3f /drivers/gpu/nvgpu/boardobj/boardobjgrp.h | |
parent | 27b47b1969d7d9cdd3de9fd6f0131ad357f4b0fa (diff) |
gpu: nvgpu: Add dGPU clocks support
JIRA DNVGPU-45
Change-Id: I237ce81e31b036c05c82d46eea8694ffe1c2e3df
Signed-off-by: Mahantesh Kumbar <mkumbar@nvidia.com>
Signed-off-by: Vijayakumar Subbu <vsubbu@nvidia.com>
Reviewed-on: http://git-master/r/1205849
(cherry picked from commit 9a4006f76b75a8ad525e7aa5ad1f609aaae49126)
Reviewed-on: http://git-master/r/1227256
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/boardobj/boardobjgrp.h')
-rw-r--r-- | drivers/gpu/nvgpu/boardobj/boardobjgrp.h | 390 |
1 files changed, 390 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/boardobj/boardobjgrp.h b/drivers/gpu/nvgpu/boardobj/boardobjgrp.h new file mode 100644 index 00000000..e98a6cdb --- /dev/null +++ b/drivers/gpu/nvgpu/boardobj/boardobjgrp.h | |||
@@ -0,0 +1,390 @@ | |||
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 | #ifndef _BOARDOBJGRP_H_ | ||
15 | #define _BOARDOBJGRP_H_ | ||
16 | |||
17 | struct boardobjgrp; | ||
18 | |||
19 | /* ------------------------ Includes ----------------------------------------*/ | ||
20 | #include <linux/nvgpu.h> | ||
21 | #include "gk20a/gk20a.h" | ||
22 | #include "gk20a/pmu_gk20a.h" | ||
23 | #include "ctrl/ctrlboardobj.h" | ||
24 | #include "boardobj.h" | ||
25 | #include "boardobjgrpmask.h" | ||
26 | #include "pmuif/gpmuifboardobj.h" | ||
27 | |||
28 | /* | ||
29 | * Board Object Group destructor. | ||
30 | * | ||
31 | */ | ||
32 | typedef u32 boardobjgrp_destruct(struct boardobjgrp *pboardobjgrp); | ||
33 | |||
34 | /* | ||
35 | * Inserts a previously constructed Board Object into a Board Object Group for | ||
36 | * tracking. Objects are inserted in the array based on the given index. | ||
37 | */ | ||
38 | typedef u32 boardobjgrp_objinsert(struct boardobjgrp *pboardobjgrp, | ||
39 | struct boardobj *pboardobj, u8 index); | ||
40 | |||
41 | /* | ||
42 | * Retrieves a Board Object from a Board Object Group using the group's index. | ||
43 | * | ||
44 | */ | ||
45 | typedef struct boardobj *boardobjgrp_objgetbyidx( | ||
46 | struct boardobjgrp *pBobrdobjgrp, u8 index); | ||
47 | |||
48 | /* | ||
49 | * Retrieve Board Object immediately following one pointed by @ref pcurrentindex | ||
50 | * filtered out by the provided mask. If (pMask == NULL) => no filtering. | ||
51 | */ | ||
52 | typedef struct boardobj *boardobjgrp_objgetnext( | ||
53 | struct boardobjgrp *pboardobjgrp, | ||
54 | u8 *currentindex, struct boardobjgrpmask *mask); | ||
55 | |||
56 | /* | ||
57 | * Board Object Group Remover and destructor. This is used to remove and | ||
58 | * destruct specific entry from the Board Object Group. | ||
59 | */ | ||
60 | typedef u32 boardobjgrp_objremoveanddestroy(struct boardobjgrp *pboardobjgrp, | ||
61 | u8 index); | ||
62 | |||
63 | /* | ||
64 | * BOARDOBJGRP handler for PMU_UNIT_INIT. Calls the PMU_UNIT_INIT handlers | ||
65 | * for the constructed PMU CMDs, and then sets the object via the | ||
66 | * PMU_BOARDOBJ_CMD_GRP interface (if constructed). | ||
67 | */ | ||
68 | typedef u32 boardobjgrp_pmuinithandle(struct gk20a *g, | ||
69 | struct boardobjgrp *pboardobjGrp); | ||
70 | |||
71 | /* | ||
72 | * Fills out the appropriate the PMU_BOARDOBJGRP_<xyz> driver<->PMU description | ||
73 | * header structure, more specifically a mask of BOARDOBJs. | ||
74 | */ | ||
75 | typedef u32 boardobjgrp_pmuhdrdatainit(struct gk20a *g, | ||
76 | struct boardobjgrp *pboardobjgrp, | ||
77 | struct nv_pmu_boardobjgrp_super *pboardobjgrppmu, | ||
78 | struct boardobjgrpmask *mask); | ||
79 | |||
80 | /* | ||
81 | * Fills out the appropriate the PMU_BOARDOBJGRP_<xyz> driver->PMU description | ||
82 | * structure, describing the BOARDOBJGRP and all of its BOARDOBJs to the PMU. | ||
83 | */ | ||
84 | typedef u32 boardobjgrp_pmudatainit(struct gk20a *g, | ||
85 | struct boardobjgrp *pboardobjgrp, | ||
86 | struct nv_pmu_boardobjgrp_super *pboardobjgrppmu); | ||
87 | |||
88 | /* | ||
89 | * Sends a BOARDOBJGRP to the PMU via the PMU_BOARDOBJ_CMD_GRP interface. | ||
90 | * This interface leverages @ref boardobjgrp_pmudatainit to populate the | ||
91 | * structure. | ||
92 | */ | ||
93 | typedef u32 boardobjgrp_pmuset(struct gk20a *g, | ||
94 | struct boardobjgrp *pboardobjgrp); | ||
95 | |||
96 | /* | ||
97 | * Gets the dynamic status of the PMU BOARDOBJGRP via the | ||
98 | * PMU_BOARDOBJ_CMD_GRP GET_STATUS interface. | ||
99 | */ | ||
100 | typedef u32 boardobjgrp_pmugetstatus(struct gk20a *g, | ||
101 | struct boardobjgrp *pboardobjgrp, | ||
102 | struct boardobjgrpmask *mask); | ||
103 | |||
104 | typedef u32 boardobjgrp_pmudatainstget(struct gk20a *g, | ||
105 | struct nv_pmu_boardobjgrp *boardobjgrppmu, | ||
106 | struct nv_pmu_boardobj **ppboardobjpmudata, u8 idx); | ||
107 | |||
108 | typedef u32 boardobjgrp_pmustatusinstget(struct gk20a *g, void *pboardobjgrppmu, | ||
109 | struct nv_pmu_boardobj_query **ppBoardobjpmustatus, u8 idx); | ||
110 | |||
111 | /* | ||
112 | * Structure describing an PMU CMD for interacting with the representaition | ||
113 | * of this BOARDOBJGRP within the PMU. | ||
114 | */ | ||
115 | struct boardobjgrp_pmu_cmd { | ||
116 | u8 id; | ||
117 | u8 msgid; | ||
118 | u8 hdrsize; | ||
119 | u8 entrysize; | ||
120 | u16 fbsize; | ||
121 | struct nv_pmu_boardobjgrp_super *buf; | ||
122 | struct pmu_surface surf; | ||
123 | }; | ||
124 | |||
125 | /* | ||
126 | * Structure of state describing how to communicate with representation of this | ||
127 | * BOARDOBJGRP in the PMU. | ||
128 | */ | ||
129 | struct boardobjgrp_pmu { | ||
130 | u8 unitid; | ||
131 | u8 classid; | ||
132 | bool bset; | ||
133 | struct boardobjgrp_pmu_cmd set; | ||
134 | struct boardobjgrp_pmu_cmd getstatus; | ||
135 | }; | ||
136 | |||
137 | /* | ||
138 | * Function by which a class which implements BOARDOBJGRP can construct a PMU | ||
139 | * CMD. This provides the various information describing the PMU CMD including | ||
140 | * the CMD and MSG ID and the size of the various sturctures in the payload. | ||
141 | */ | ||
142 | typedef u32 boardobjgrp_pmucmd_construct(struct gk20a *g, | ||
143 | struct boardobjgrp *pboardobjgrp, | ||
144 | struct boardobjgrp_pmu_cmd *cmd, u8 id, u8 msgid, | ||
145 | u8 hdrsize, u8 entrysize, u16 fbsize); | ||
146 | |||
147 | /* | ||
148 | * Destroys BOARDOBJGRP PMU SW state. CMD. | ||
149 | */ | ||
150 | typedef u32 boardobjgrp_pmucmd_destroy(struct boardobjgrp_pmu_cmd *cmd); | ||
151 | |||
152 | /* | ||
153 | * init handler for the BOARDOBJGRP PMU CMD. Allocates and maps the | ||
154 | * PMU CMD payload within both the PMU and driver so that it can be referenced | ||
155 | * at run-time. | ||
156 | */ | ||
157 | typedef u32 boardobjgrp_pmucmd_pmuinithandle(struct gk20a *g, | ||
158 | struct boardobjgrp *pboardobjgrp, | ||
159 | struct boardobjgrp_pmu_cmd *cmd); | ||
160 | |||
161 | /* | ||
162 | * Base Class Group for all physical or logical device on the PCB. | ||
163 | * Contains fields common to all devices on the board. Specific types of | ||
164 | * devices groups may extend this object adding any details specific to that | ||
165 | * device group or device-type. | ||
166 | */ | ||
167 | struct boardobjgrp { | ||
168 | u32 objmask; | ||
169 | bool bconstructed; | ||
170 | u8 type; | ||
171 | u8 classid; | ||
172 | struct boardobj **ppobjects; | ||
173 | struct boardobjgrpmask *mask; | ||
174 | u8 objslots; | ||
175 | u8 objmaxidx; | ||
176 | struct boardobjgrp_pmu pmu; | ||
177 | |||
178 | /* Basic interfaces */ | ||
179 | boardobjgrp_destruct *destruct; | ||
180 | boardobjgrp_objinsert *objinsert; | ||
181 | boardobjgrp_objgetbyidx *objgetbyidx; | ||
182 | boardobjgrp_objgetnext *objgetnext; | ||
183 | boardobjgrp_objremoveanddestroy *objremoveanddestroy; | ||
184 | |||
185 | /* PMU interfaces */ | ||
186 | boardobjgrp_pmuinithandle *pmuinithandle; | ||
187 | boardobjgrp_pmuhdrdatainit *pmuhdrdatainit; | ||
188 | boardobjgrp_pmudatainit *pmudatainit; | ||
189 | boardobjgrp_pmuset *pmuset; | ||
190 | boardobjgrp_pmugetstatus *pmugetstatus; | ||
191 | |||
192 | boardobjgrp_pmudatainstget *pmudatainstget; | ||
193 | boardobjgrp_pmustatusinstget *pmustatusinstget; | ||
194 | }; | ||
195 | |||
196 | /* | ||
197 | * Macro test whether a specified index into the BOARDOBJGRP is valid. | ||
198 | * | ||
199 | */ | ||
200 | #define boardobjgrp_idxisvalid(_pboardobjgrp, _idx) \ | ||
201 | (((_idx) < (_pboardobjgrp)->objslots) && \ | ||
202 | ((_pboardobjgrp)->ppobjects[(_idx)] != NULL)) | ||
203 | |||
204 | /* | ||
205 | * Macro test whether a specified BOARDOBJGRP is empty. | ||
206 | */ | ||
207 | #define BOARDOBJGRP_IS_EMPTY(_pboardobjgrp) \ | ||
208 | ((!((_pboardobjgrp)->bconstructed)) || \ | ||
209 | ((_pboardobjgrp)->objmaxidx == CTRL_BOARDOBJ_IDX_INVALID)) | ||
210 | |||
211 | #define boardobjgrp_objinsert(_pboardobjgrp, _pboardobj, _idx) \ | ||
212 | ((_pboardobjgrp)->objinsert((_pboardobjgrp), (_pboardobj), (_idx))) | ||
213 | |||
214 | /* | ||
215 | * Helper macro to determine the "next" open/empty index after all allocated | ||
216 | * objects. This is intended to be used to find the index at which objects can | ||
217 | * be inserted contiguously (i.e. w/o fear of colliding with existing objects). | ||
218 | */ | ||
219 | #define BOARDOBJGRP_NEXT_EMPTY_IDX(_pboardobjgrp) \ | ||
220 | ((CTRL_BOARDOBJ_IDX_INVALID == (_pboardobjgrp)->objmaxidx) ? 0 : \ | ||
221 | ((((_pboardobjgrp)->objmaxidx + 1) >= (_pboardobjgrp)->objslots) ? \ | ||
222 | (u8)CTRL_BOARDOBJ_IDX_INVALID : (u8)((_pboardobjgrp)->objmaxidx + 1))) | ||
223 | |||
224 | /* | ||
225 | * Helper macro to determine the number of @ref BOARDOBJ pointers | ||
226 | * that are required to be allocated in PMU @ref ppObjects. | ||
227 | */ | ||
228 | #define BOARDOBJGRP_PMU_SLOTS_GET(_pboardobjgrp) \ | ||
229 | ((CTRL_BOARDOBJ_IDX_INVALID == (_pboardobjgrp)->objmaxidx) ? 0 : \ | ||
230 | (u8)((_pboardobjgrp)->objmaxidx + 1)) | ||
231 | |||
232 | #define BOARDOBJGRP_OBJ_GET_BY_IDX(_pboardobjgrp, _idx) \ | ||
233 | ((_pboardobjgrp)->objgetbyidx((_pboardobjgrp), (_idx))) | ||
234 | |||
235 | /* | ||
236 | * macro to look-up next object while tolerating error if | ||
237 | * Board Object Group is not constructed. | ||
238 | */ | ||
239 | |||
240 | #define boardobjgrpobjgetnextsafe(_pgrp, _pindex, _pmask) \ | ||
241 | ((_pgrp)->bconstructed ? \ | ||
242 | (_pgrp)->objgetnext((_pgrp), (_pindex), (_pmask)) : NULL) | ||
243 | |||
244 | /* | ||
245 | * Used to traverse all Board Objects stored within @ref _pgrp in the increasing | ||
246 | * index order. | ||
247 | * If @ref _pmask is provided only objects specified by the mask are traversed. | ||
248 | */ | ||
249 | #define BOARDOBJGRP_ITERATOR(_pgrp, _ptype, _pobj, _index, _pmask) \ | ||
250 | for (_index = CTRL_BOARDOBJ_IDX_INVALID, \ | ||
251 | _pobj = (_ptype)boardobjgrpobjgetnextsafe((_pgrp), &_index, (_pmask));\ | ||
252 | _pobj != NULL; \ | ||
253 | _pobj = (_ptype)boardobjgrpobjgetnextsafe((_pgrp), &_index, (_pmask))) | ||
254 | #define BOARDOBJGRP_FOR_EACH(_pgrp, _ptype, _pobj, _index) \ | ||
255 | BOARDOBJGRP_ITERATOR(_pgrp, _ptype, _pobj, _index, NULL) | ||
256 | |||
257 | /*! | ||
258 | * Invalid UNIT_ID. Used to indicate that the implementing class has not set | ||
259 | * @ref BOARDOBJGRP::unitId and, thus, certain BOARDOBJGRP PMU interfaces are | ||
260 | * not supported. | ||
261 | */ | ||
262 | #define BOARDOBJGRP_UNIT_ID_INVALID 255 | ||
263 | |||
264 | /*! | ||
265 | * Invalid UNIT_ID. Used to indicate that the implementing class has not set | ||
266 | * @ref BOARDOBJGRP::grpType and, thus, certain BOARDOBJGRP PMU interfaces are | ||
267 | * not supported. | ||
268 | */ | ||
269 | #define BOARDOBJGRP_GRP_CLASS_ID_INVALID 255 | ||
270 | |||
271 | /*! | ||
272 | * Invalid UNIT_ID. Used to indicate that the implementing class has not set | ||
273 | * @ref BOARDOBJGRP::grpSetCmdId and, thus, certain BOARDOBJGRP PMU interfaces | ||
274 | * are not supported. | ||
275 | */ | ||
276 | #define BOARDOBJGRP_GRP_CMD_ID_INVALID 255 | ||
277 | |||
278 | /*! | ||
279 | * Helper macro to construct a BOARDOBJGRP's PMU SW state. | ||
280 | * | ||
281 | * @param[out] pboardobjgrp BOARDOBJGRP pointer | ||
282 | * @param[in] _eng | ||
283 | * Implementing engine/unit which manages the BOARDOBJGRP. | ||
284 | * @param[in] _class | ||
285 | * Class ID of BOARDOBJGRP. | ||
286 | */ | ||
287 | #define BOARDOBJGRP_PMU_CONSTRUCT(pboardobjgrp, _ENG, _CLASS) \ | ||
288 | do { \ | ||
289 | (pboardobjgrp)->pmu.unitid = PMU_UNIT_##_ENG; \ | ||
290 | (pboardobjgrp)->pmu.classid = \ | ||
291 | NV_PMU_##_ENG##_BOARDOBJGRP_CLASS_ID_##_CLASS; \ | ||
292 | } while (0) | ||
293 | |||
294 | #define BOARDOBJGRP_PMU_CMD_GRP_SET_CONSTRUCT(pgpu, pboardobjgrp, eng, ENG, \ | ||
295 | class, CLASS) \ | ||
296 | boardobjgrp_pmucmd_construct_impl( \ | ||
297 | pgpu, /* pgpu */ \ | ||
298 | pboardobjgrp, /* pboardobjgrp */ \ | ||
299 | &((pboardobjgrp)->pmu.set), /* pcmd */ \ | ||
300 | NV_PMU_##ENG##_CMD_ID_BOARDOBJ_GRP_SET, /* id */ \ | ||
301 | NV_PMU_##ENG##_MSG_ID_BOARDOBJ_GRP_SET, /* msgid */ \ | ||
302 | (u32)sizeof(union nv_pmu_##eng##_##class##_boardobjgrp_set_header_aligned), \ | ||
303 | (u32)sizeof(union nv_pmu_##eng##_##class##_boardobj_set_union_aligned), \ | ||
304 | (u32)sizeof(struct nv_pmu_##eng##_##class##_boardobj_grp_set)) | ||
305 | |||
306 | #define BOARDOBJGRP_PMU_CMD_GRP_GET_STATUS_CONSTRUCT(pgpu, pboardobjgrp, \ | ||
307 | eng, ENG, class, CLASS) \ | ||
308 | boardobjgrp_pmucmd_construct_impl( \ | ||
309 | pgpu, /* pGpu */ \ | ||
310 | pboardobjgrp, /* pBoardObjGrp */ \ | ||
311 | &((pboardobjgrp)->pmu.getstatus), /* pCmd */ \ | ||
312 | NV_PMU_##ENG##_CMD_ID_BOARDOBJ_GRP_GET_STATUS, /* id */ \ | ||
313 | NV_PMU_##ENG##_MSG_ID_BOARDOBJ_GRP_SET, /* msgid */ \ | ||
314 | (u32)sizeof(union nv_pmu_##eng##_##class##_boardobjgrp_get_status_header_aligned), \ | ||
315 | (u32)sizeof(union nv_pmu_##eng##_##class##_boardobj_get_status_union_aligned), \ | ||
316 | (u32)sizeof(struct nv_pmu_##eng##_##class##_boardobj_grp_get_status)) | ||
317 | |||
318 | /* ------------------------ Function Prototypes ----------------------------- */ | ||
319 | /* Constructor and destructor */ | ||
320 | u32 boardobjgrp_construct_super(struct boardobjgrp *pboardobjgrp); | ||
321 | boardobjgrp_destruct boardobjgrp_destruct_impl; | ||
322 | boardobjgrp_destruct boardobjgrp_destruct_super; | ||
323 | |||
324 | /* PMU_CMD interfaces */ | ||
325 | boardobjgrp_pmucmd_construct boardobjgrp_pmucmd_construct_impl; | ||
326 | boardobjgrp_pmucmd_destroy boardobjgrp_pmucmd_destroy_impl; | ||
327 | boardobjgrp_pmucmd_pmuinithandle boardobjgrp_pmucmd_pmuinithandle_impl; | ||
328 | |||
329 | /* BOARDOBJGRP interfaces */ | ||
330 | boardobjgrp_pmuinithandle boardobjgrp_pmuinithandle_impl; | ||
331 | boardobjgrp_pmuhdrdatainit boardobjgrp_pmuhdrdatainit_super; | ||
332 | boardobjgrp_pmudatainit boardobjgrp_pmudatainit_super; | ||
333 | |||
334 | boardobjgrp_pmudatainit boardobjgrp_pmudatainit_legacy; | ||
335 | boardobjgrp_pmuset boardobjgrp_pmuset_impl; | ||
336 | boardobjgrp_pmugetstatus boardobjgrp_pmugetstatus_impl; | ||
337 | |||
338 | void boardobjgrpe32hdrset(struct nv_pmu_boardobjgrp *hdr, u32 objmask); | ||
339 | |||
340 | /* ------------------------ Include Derived Types --------------------------- */ | ||
341 | #include "boardobj/boardobjgrp_e32.h" | ||
342 | #include "boardobj/boardobjgrp_e255.h" | ||
343 | |||
344 | #define HIGHESTBITIDX_32(n32) \ | ||
345 | { \ | ||
346 | u32 count = 0; \ | ||
347 | while (n32 >>= 1) \ | ||
348 | count++; \ | ||
349 | n32 = count; \ | ||
350 | } | ||
351 | |||
352 | #define LOWESTBIT(x) ((x) & (((x)-1) ^ (x))) | ||
353 | |||
354 | #define HIGHESTBIT(n32) \ | ||
355 | { \ | ||
356 | HIGHESTBITIDX_32(n32); \ | ||
357 | n32 = NVBIT(n32); \ | ||
358 | } | ||
359 | |||
360 | #define ONEBITSET(x) ((x) && (((x) & ((x)-1)) == 0)) | ||
361 | |||
362 | #define LOWESTBITIDX_32(n32) \ | ||
363 | { \ | ||
364 | n32 = LOWESTBIT(n32); \ | ||
365 | IDX_32(n32); \ | ||
366 | } | ||
367 | |||
368 | #define NUMSETBITS_32(n32) \ | ||
369 | { \ | ||
370 | n32 = n32 - ((n32 >> 1) & 0x55555555); \ | ||
371 | n32 = (n32 & 0x33333333) + ((n32 >> 2) & 0x33333333); \ | ||
372 | n32 = (((n32 + (n32 >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24; \ | ||
373 | } | ||
374 | |||
375 | #define IDX_32(n32) \ | ||
376 | { \ | ||
377 | u32 idx = 0; \ | ||
378 | if ((n32) & 0xFFFF0000) \ | ||
379 | idx += 16; \ | ||
380 | if ((n32) & 0xFF00FF00) \ | ||
381 | idx += 8; \ | ||
382 | if ((n32) & 0xF0F0F0F0) \ | ||
383 | idx += 4; \ | ||
384 | if ((n32) & 0xCCCCCCCC) \ | ||
385 | idx += 2; \ | ||
386 | if ((n32) & 0xAAAAAAAA) \ | ||
387 | idx += 1; \ | ||
388 | (n32) = idx; \ | ||
389 | } | ||
390 | #endif | ||