1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
|
/*
* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*/
#include <nvgpu/kmem.h>
#include <nvgpu/pmuif/nvgpu_gpmu_cmdif.h>
#include "gk20a/gk20a.h"
#include "gm206/bios_gm206.h"
#include "gk20a/pmu_gk20a.h"
#include "boardobj/boardobjgrp.h"
#include "boardobj/boardobjgrp_e32.h"
#include "pwrdev.h"
#include "pmgrpmu.h"
struct pmgr_pmucmdhandler_params {
u32 success;
};
static void pmgr_pmucmdhandler(struct gk20a *g, struct pmu_msg *msg,
void *param, u32 handle, u32 status)
{
struct pmgr_pmucmdhandler_params *phandlerparams =
(struct pmgr_pmucmdhandler_params *)param;
if ((msg->msg.pmgr.msg_type != NV_PMU_PMGR_MSG_ID_SET_OBJECT) &&
(msg->msg.pmgr.msg_type != NV_PMU_PMGR_MSG_ID_QUERY) &&
(msg->msg.pmgr.msg_type != NV_PMU_PMGR_MSG_ID_LOAD)) {
gk20a_err(dev_from_gk20a(g),
"unknow msg %x",
msg->msg.pmgr.msg_type);
return;
}
if (msg->msg.pmgr.msg_type == NV_PMU_PMGR_MSG_ID_SET_OBJECT) {
if ((msg->msg.pmgr.set_object.b_success != 1) ||
(msg->msg.pmgr.set_object.flcnstatus != 0) ) {
gk20a_err(dev_from_gk20a(g),
"pmgr msg failed %x %x %x %x",
msg->msg.pmgr.set_object.msg_type,
msg->msg.pmgr.set_object.b_success,
msg->msg.pmgr.set_object.flcnstatus,
msg->msg.pmgr.set_object.object_type);
return;
}
} else if (msg->msg.pmgr.msg_type == NV_PMU_PMGR_MSG_ID_QUERY) {
if ((msg->msg.pmgr.query.b_success != 1) ||
(msg->msg.pmgr.query.flcnstatus != 0) ) {
gk20a_err(dev_from_gk20a(g),
"pmgr msg failed %x %x %x %x",
msg->msg.pmgr.query.msg_type,
msg->msg.pmgr.query.b_success,
msg->msg.pmgr.query.flcnstatus,
msg->msg.pmgr.query.cmd_type);
return;
}
} else if (msg->msg.pmgr.msg_type == NV_PMU_PMGR_MSG_ID_LOAD) {
if ((msg->msg.pmgr.query.b_success != 1) ||
(msg->msg.pmgr.query.flcnstatus != 0) ) {
gk20a_err(dev_from_gk20a(g),
"pmgr msg failed %x %x %x",
msg->msg.pmgr.load.msg_type,
msg->msg.pmgr.load.b_success,
msg->msg.pmgr.load.flcnstatus);
return;
}
}
phandlerparams->success = 1;
}
static u32 pmgr_pmu_set_object(struct gk20a *g,
u8 type,
u16 dmem_size,
u16 fb_size,
void *pobj)
{
struct pmu_cmd cmd = { {0} };
struct pmu_payload payload = { {0} };
struct nv_pmu_pmgr_cmd_set_object *pcmd;
u32 status;
u32 seqdesc;
struct pmgr_pmucmdhandler_params handlerparams = {0};
cmd.hdr.unit_id = PMU_UNIT_PMGR;
cmd.hdr.size = (u32)sizeof(struct nv_pmu_pmgr_cmd_set_object) +
(u32)sizeof(struct pmu_hdr);;
pcmd = &cmd.cmd.pmgr.set_object;
pcmd->cmd_type = NV_PMU_PMGR_CMD_ID_SET_OBJECT;
pcmd->object_type = type;
payload.in.buf = pobj;
payload.in.size = dmem_size;
payload.in.fb_size = fb_size;
payload.in.offset = NV_PMU_PMGR_SET_OBJECT_ALLOC_OFFSET;
/* Setup the handler params to communicate back results.*/
handlerparams.success = 0;
status = gk20a_pmu_cmd_post(g, &cmd, NULL, &payload,
PMU_COMMAND_QUEUE_LPQ,
pmgr_pmucmdhandler,
(void *)&handlerparams,
&seqdesc, ~0);
if (status) {
gk20a_err(dev_from_gk20a(g),
"unable to post pmgr cmd for unit %x cmd id %x obj type %x",
cmd.hdr.unit_id, pcmd->cmd_type, pcmd->object_type);
goto exit;
}
pmu_wait_message_cond(&g->pmu,
gk20a_get_gr_idle_timeout(g),
&handlerparams.success, 1);
if (handlerparams.success == 0) {
gk20a_err(dev_from_gk20a(g), "could not process cmd\n");
status = -ETIMEDOUT;
goto exit;
}
exit:
return status;
}
static u32 pmgr_send_i2c_device_topology_to_pmu(struct gk20a *g)
{
struct nv_pmu_pmgr_i2c_device_desc_table i2c_desc_table;
u32 status = 0;
/* INA3221 I2C device info */
i2c_desc_table.dev_mask = 0x01;
/* INA3221 */
i2c_desc_table.devices[0].super.type = 0x4E;
i2c_desc_table.devices[0].dcb_index = 0;
i2c_desc_table.devices[0].i2c_address = 0x84;
i2c_desc_table.devices[0].i2c_flags = 0xC2F;
i2c_desc_table.devices[0].i2c_port = 0x2;
/* Pass the table down the PMU as an object */
status = pmgr_pmu_set_object(
g,
NV_PMU_PMGR_OBJECT_I2C_DEVICE_DESC_TABLE,
(u16)sizeof(struct nv_pmu_pmgr_i2c_device_desc_table),
PMU_CMD_SUBMIT_PAYLOAD_PARAMS_FB_SIZE_UNUSED,
&i2c_desc_table);
if (status)
gk20a_err(dev_from_gk20a(g),
"pmgr_pmu_set_object failed %x",
status);
return status;
}
static u32 pmgr_send_pwr_device_topology_to_pmu(struct gk20a *g)
{
struct nv_pmu_pmgr_pwr_device_desc_table pwr_desc_table;
struct nv_pmu_pmgr_pwr_device_desc_table_header *ppwr_desc_header;
u32 status = 0;
/* Set the BA-device-independent HW information */
ppwr_desc_header = &(pwr_desc_table.hdr.data);
ppwr_desc_header->ba_info.b_initialized_and_used = false;
/* populate the table */
boardobjgrpe32hdrset((struct nv_pmu_boardobjgrp *)&ppwr_desc_header->super,
g->pmgr_pmu.pmgr_deviceobjs.super.super.objmask);
status = boardobjgrp_pmudatainit_legacy(g,
&g->pmgr_pmu.pmgr_deviceobjs.super.super,
(struct nv_pmu_boardobjgrp_super *)&pwr_desc_table);
if (status) {
gk20a_err(dev_from_gk20a(g),
"boardobjgrp_pmudatainit_legacy failed %x",
status);
goto exit;
}
/* Pass the table down the PMU as an object */
status = pmgr_pmu_set_object(
g,
NV_PMU_PMGR_OBJECT_PWR_DEVICE_DESC_TABLE,
(u16)sizeof(
union nv_pmu_pmgr_pwr_device_dmem_size),
(u16)sizeof(struct nv_pmu_pmgr_pwr_device_desc_table),
&pwr_desc_table);
if (status)
gk20a_err(dev_from_gk20a(g),
"pmgr_pmu_set_object failed %x",
status);
exit:
return status;
}
static u32 pmgr_send_pwr_mointer_to_pmu(struct gk20a *g)
{
struct nv_pmu_pmgr_pwr_monitor_pack pwr_monitor_pack;
struct nv_pmu_pmgr_pwr_channel_header *pwr_channel_hdr;
struct nv_pmu_pmgr_pwr_chrelationship_header *pwr_chrelationship_header;
u32 max_dmem_size;
u32 status = 0;
/* Copy all the global settings from the RM copy */
pwr_channel_hdr = &(pwr_monitor_pack.channels.hdr.data);
pwr_monitor_pack = g->pmgr_pmu.pmgr_monitorobjs.pmu_data;
boardobjgrpe32hdrset((struct nv_pmu_boardobjgrp *)&pwr_channel_hdr->super,
g->pmgr_pmu.pmgr_monitorobjs.pwr_channels.super.objmask);
/* Copy in each channel */
status = boardobjgrp_pmudatainit_legacy(g,
&g->pmgr_pmu.pmgr_monitorobjs.pwr_channels.super,
(struct nv_pmu_boardobjgrp_super *)&(pwr_monitor_pack.channels));
if (status) {
gk20a_err(dev_from_gk20a(g),
"boardobjgrp_pmudatainit_legacy failed %x",
status);
goto exit;
}
/* Copy in each channel relationship */
pwr_chrelationship_header = &(pwr_monitor_pack.ch_rels.hdr.data);
boardobjgrpe32hdrset((struct nv_pmu_boardobjgrp *)&pwr_chrelationship_header->super,
g->pmgr_pmu.pmgr_monitorobjs.pwr_ch_rels.super.objmask);
pwr_channel_hdr->physical_channel_mask = g->pmgr_pmu.pmgr_monitorobjs.physical_channel_mask;
pwr_channel_hdr->type = NV_PMU_PMGR_PWR_MONITOR_TYPE_NO_POLLING;
status = boardobjgrp_pmudatainit_legacy(g,
&g->pmgr_pmu.pmgr_monitorobjs.pwr_ch_rels.super,
(struct nv_pmu_boardobjgrp_super *)&(pwr_monitor_pack.ch_rels));
if (status) {
gk20a_err(dev_from_gk20a(g),
"boardobjgrp_pmudatainit_legacy failed %x",
status);
goto exit;
}
/* Calculate the max Dmem buffer size */
max_dmem_size = sizeof(union nv_pmu_pmgr_pwr_monitor_dmem_size);
/* Pass the table down the PMU as an object */
status = pmgr_pmu_set_object(
g,
NV_PMU_PMGR_OBJECT_PWR_MONITOR,
(u16)max_dmem_size,
(u16)sizeof(struct nv_pmu_pmgr_pwr_monitor_pack),
&pwr_monitor_pack);
if (status)
gk20a_err(dev_from_gk20a(g),
"pmgr_pmu_set_object failed %x",
status);
exit:
return status;
}
u32 pmgr_send_pwr_policy_to_pmu(struct gk20a *g)
{
struct nv_pmu_pmgr_pwr_policy_pack *ppwrpack = NULL;
struct pwr_policy *ppolicy = NULL;
u32 status = 0;
u8 indx;
u32 max_dmem_size;
ppwrpack = nvgpu_kzalloc(g, sizeof(struct nv_pmu_pmgr_pwr_policy_pack));
if (!ppwrpack) {
gk20a_err(dev_from_gk20a(g),
"pwr policy alloc failed %x",
status);
status = -ENOMEM;
goto exit;
}
ppwrpack->policies.hdr.data.version = g->pmgr_pmu.pmgr_policyobjs.version;
ppwrpack->policies.hdr.data.b_enabled = g->pmgr_pmu.pmgr_policyobjs.b_enabled;
boardobjgrpe32hdrset((struct nv_pmu_boardobjgrp *)
&ppwrpack->policies.hdr.data.super,
g->pmgr_pmu.pmgr_policyobjs.pwr_policies.super.objmask);
memset(&ppwrpack->policies.hdr.data.reserved_pmu_policy_mask,
0,
sizeof(ppwrpack->policies.hdr.data.reserved_pmu_policy_mask));
ppwrpack->policies.hdr.data.base_sample_period =
g->pmgr_pmu.pmgr_policyobjs.base_sample_period;
ppwrpack->policies.hdr.data.min_client_sample_period =
g->pmgr_pmu.pmgr_policyobjs.min_client_sample_period;
ppwrpack->policies.hdr.data.low_sampling_mult =
g->pmgr_pmu.pmgr_policyobjs.low_sampling_mult;
memcpy(&ppwrpack->policies.hdr.data.global_ceiling,
&g->pmgr_pmu.pmgr_policyobjs.global_ceiling,
sizeof(struct nv_pmu_perf_domain_group_limits));
memcpy(&ppwrpack->policies.hdr.data.semantic_policy_tbl,
&g->pmgr_pmu.pmgr_policyobjs.policy_idxs,
sizeof(g->pmgr_pmu.pmgr_policyobjs.policy_idxs));
BOARDOBJGRP_FOR_EACH_INDEX_IN_MASK(32, indx,
ppwrpack->policies.hdr.data.super.obj_mask.super.data[0]) {
ppolicy = PMGR_GET_PWR_POLICY(g, indx);
status = ((struct boardobj *)ppolicy)->pmudatainit(g, (struct boardobj *)ppolicy,
(struct nv_pmu_boardobj *)&(ppwrpack->policies.policies[indx].data));
if (status) {
gk20a_err(dev_from_gk20a(g),
"pmudatainit failed %x indx %x",
status, indx);
status = -ENOMEM;
goto exit;
}
}
BOARDOBJGRP_FOR_EACH_INDEX_IN_MASK_END;
boardobjgrpe32hdrset((struct nv_pmu_boardobjgrp *)
&ppwrpack->policy_rels.hdr.data.super,
g->pmgr_pmu.pmgr_policyobjs.pwr_policy_rels.super.objmask);
boardobjgrpe32hdrset((struct nv_pmu_boardobjgrp *)
&ppwrpack->violations.hdr.data.super,
g->pmgr_pmu.pmgr_policyobjs.pwr_violations.super.objmask);
max_dmem_size = sizeof(union nv_pmu_pmgr_pwr_policy_dmem_size);
/* Pass the table down the PMU as an object */
status = pmgr_pmu_set_object(
g,
NV_PMU_PMGR_OBJECT_PWR_POLICY,
(u16)max_dmem_size,
(u16)sizeof(struct nv_pmu_pmgr_pwr_policy_pack),
ppwrpack);
if (status)
gk20a_err(dev_from_gk20a(g),
"pmgr_pmu_set_object failed %x",
status);
exit:
if (ppwrpack) {
nvgpu_kfree(g, ppwrpack);
}
return status;
}
u32 pmgr_pmu_pwr_devices_query_blocking(
struct gk20a *g,
u32 pwr_dev_mask,
struct nv_pmu_pmgr_pwr_devices_query_payload *ppayload)
{
struct pmu_cmd cmd = { {0} };
struct pmu_payload payload = { {0} };
struct nv_pmu_pmgr_cmd_pwr_devices_query *pcmd;
u32 status;
u32 seqdesc;
struct pmgr_pmucmdhandler_params handlerparams = {0};
cmd.hdr.unit_id = PMU_UNIT_PMGR;
cmd.hdr.size = (u32)sizeof(struct nv_pmu_pmgr_cmd_pwr_devices_query) +
(u32)sizeof(struct pmu_hdr);
pcmd = &cmd.cmd.pmgr.pwr_dev_query;
pcmd->cmd_type = NV_PMU_PMGR_CMD_ID_PWR_DEVICES_QUERY;
pcmd->dev_mask = pwr_dev_mask;
payload.out.buf = ppayload;
payload.out.size = sizeof(struct nv_pmu_pmgr_pwr_devices_query_payload);
payload.out.fb_size = PMU_CMD_SUBMIT_PAYLOAD_PARAMS_FB_SIZE_UNUSED;
payload.out.offset = NV_PMU_PMGR_PWR_DEVICES_QUERY_ALLOC_OFFSET;
/* Setup the handler params to communicate back results.*/
handlerparams.success = 0;
status = gk20a_pmu_cmd_post(g, &cmd, NULL, &payload,
PMU_COMMAND_QUEUE_LPQ,
pmgr_pmucmdhandler,
(void *)&handlerparams,
&seqdesc, ~0);
if (status) {
gk20a_err(dev_from_gk20a(g),
"unable to post pmgr query cmd for unit %x cmd id %x dev mask %x",
cmd.hdr.unit_id, pcmd->cmd_type, pcmd->dev_mask);
goto exit;
}
pmu_wait_message_cond(&g->pmu,
gk20a_get_gr_idle_timeout(g),
&handlerparams.success, 1);
if (handlerparams.success == 0) {
gk20a_err(dev_from_gk20a(g), "could not process cmd\n");
status = -ETIMEDOUT;
goto exit;
}
exit:
return status;
}
static u32 pmgr_pmu_load_blocking(struct gk20a *g)
{
struct pmu_cmd cmd = { {0} };
struct nv_pmu_pmgr_cmd_load *pcmd;
u32 status;
u32 seqdesc;
struct pmgr_pmucmdhandler_params handlerparams = {0};
cmd.hdr.unit_id = PMU_UNIT_PMGR;
cmd.hdr.size = (u32)sizeof(struct nv_pmu_pmgr_cmd_load) +
(u32)sizeof(struct pmu_hdr);
pcmd = &cmd.cmd.pmgr.load;
pcmd->cmd_type = NV_PMU_PMGR_CMD_ID_LOAD;
/* Setup the handler params to communicate back results.*/
handlerparams.success = 0;
status = gk20a_pmu_cmd_post(g, &cmd, NULL, NULL,
PMU_COMMAND_QUEUE_LPQ,
pmgr_pmucmdhandler,
(void *)&handlerparams,
&seqdesc, ~0);
if (status) {
gk20a_err(dev_from_gk20a(g),
"unable to post pmgr load cmd for unit %x cmd id %x",
cmd.hdr.unit_id, pcmd->cmd_type);
goto exit;
}
pmu_wait_message_cond(&g->pmu,
gk20a_get_gr_idle_timeout(g),
&handlerparams.success, 1);
if (handlerparams.success == 0) {
gk20a_err(dev_from_gk20a(g), "could not process cmd\n");
status = -ETIMEDOUT;
goto exit;
}
exit:
return status;
}
u32 pmgr_send_pmgr_tables_to_pmu(struct gk20a *g)
{
u32 status = 0;
status = pmgr_send_i2c_device_topology_to_pmu(g);
if (status) {
gk20a_err(dev_from_gk20a(g),
"pmgr_send_i2c_device_topology_to_pmu failed %x",
status);
goto exit;
}
if (!BOARDOBJGRP_IS_EMPTY(&g->pmgr_pmu.pmgr_deviceobjs.super.super)) {
status = pmgr_send_pwr_device_topology_to_pmu(g);
if (status) {
gk20a_err(dev_from_gk20a(g),
"pmgr_send_pwr_device_topology_to_pmu failed %x",
status);
goto exit;
}
}
if (!(BOARDOBJGRP_IS_EMPTY(
&g->pmgr_pmu.pmgr_monitorobjs.pwr_channels.super)) ||
!(BOARDOBJGRP_IS_EMPTY(
&g->pmgr_pmu.pmgr_monitorobjs.pwr_ch_rels.super))) {
status = pmgr_send_pwr_mointer_to_pmu(g);
if (status) {
gk20a_err(dev_from_gk20a(g),
"pmgr_send_pwr_mointer_to_pmu failed %x", status);
goto exit;
}
}
if (!(BOARDOBJGRP_IS_EMPTY(
&g->pmgr_pmu.pmgr_policyobjs.pwr_policies.super)) ||
!(BOARDOBJGRP_IS_EMPTY(
&g->pmgr_pmu.pmgr_policyobjs.pwr_policy_rels.super)) ||
!(BOARDOBJGRP_IS_EMPTY(
&g->pmgr_pmu.pmgr_policyobjs.pwr_violations.super))) {
status = pmgr_send_pwr_policy_to_pmu(g);
if (status) {
gk20a_err(dev_from_gk20a(g),
"pmgr_send_pwr_policy_to_pmu failed %x", status);
goto exit;
}
}
status = pmgr_pmu_load_blocking(g);
if (status) {
gk20a_err(dev_from_gk20a(g),
"pmgr_send_pwr_mointer_to_pmu failed %x", status);
goto exit;
}
exit:
return status;
}
|