2 * Copyright 2012 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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 COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
30 #include <linux/math64.h>
31 #include <linux/seq_file.h>
33 #define MC_CG_ARB_FREQ_F0 0x0a
34 #define MC_CG_ARB_FREQ_F1 0x0b
35 #define MC_CG_ARB_FREQ_F2 0x0c
36 #define MC_CG_ARB_FREQ_F3 0x0d
38 #define SMC_RAM_END 0xC000
40 static const struct ni_cac_weights cac_weights_cayman_xt
=
104 { 0, 0, 0, 0, 0, 0, 0, 0 },
109 static const struct ni_cac_weights cac_weights_cayman_pro
=
173 { 0, 0, 0, 0, 0, 0, 0, 0 },
178 static const struct ni_cac_weights cac_weights_cayman_le
=
242 { 0, 0, 0, 0, 0, 0, 0, 0 },
247 #define NISLANDS_MGCG_SEQUENCE 300
249 static const u32 cayman_cgcg_cgls_default
[] =
251 0x000008f8, 0x00000010, 0xffffffff,
252 0x000008fc, 0x00000000, 0xffffffff,
253 0x000008f8, 0x00000011, 0xffffffff,
254 0x000008fc, 0x00000000, 0xffffffff,
255 0x000008f8, 0x00000012, 0xffffffff,
256 0x000008fc, 0x00000000, 0xffffffff,
257 0x000008f8, 0x00000013, 0xffffffff,
258 0x000008fc, 0x00000000, 0xffffffff,
259 0x000008f8, 0x00000014, 0xffffffff,
260 0x000008fc, 0x00000000, 0xffffffff,
261 0x000008f8, 0x00000015, 0xffffffff,
262 0x000008fc, 0x00000000, 0xffffffff,
263 0x000008f8, 0x00000016, 0xffffffff,
264 0x000008fc, 0x00000000, 0xffffffff,
265 0x000008f8, 0x00000017, 0xffffffff,
266 0x000008fc, 0x00000000, 0xffffffff,
267 0x000008f8, 0x00000018, 0xffffffff,
268 0x000008fc, 0x00000000, 0xffffffff,
269 0x000008f8, 0x00000019, 0xffffffff,
270 0x000008fc, 0x00000000, 0xffffffff,
271 0x000008f8, 0x0000001a, 0xffffffff,
272 0x000008fc, 0x00000000, 0xffffffff,
273 0x000008f8, 0x0000001b, 0xffffffff,
274 0x000008fc, 0x00000000, 0xffffffff,
275 0x000008f8, 0x00000020, 0xffffffff,
276 0x000008fc, 0x00000000, 0xffffffff,
277 0x000008f8, 0x00000021, 0xffffffff,
278 0x000008fc, 0x00000000, 0xffffffff,
279 0x000008f8, 0x00000022, 0xffffffff,
280 0x000008fc, 0x00000000, 0xffffffff,
281 0x000008f8, 0x00000023, 0xffffffff,
282 0x000008fc, 0x00000000, 0xffffffff,
283 0x000008f8, 0x00000024, 0xffffffff,
284 0x000008fc, 0x00000000, 0xffffffff,
285 0x000008f8, 0x00000025, 0xffffffff,
286 0x000008fc, 0x00000000, 0xffffffff,
287 0x000008f8, 0x00000026, 0xffffffff,
288 0x000008fc, 0x00000000, 0xffffffff,
289 0x000008f8, 0x00000027, 0xffffffff,
290 0x000008fc, 0x00000000, 0xffffffff,
291 0x000008f8, 0x00000028, 0xffffffff,
292 0x000008fc, 0x00000000, 0xffffffff,
293 0x000008f8, 0x00000029, 0xffffffff,
294 0x000008fc, 0x00000000, 0xffffffff,
295 0x000008f8, 0x0000002a, 0xffffffff,
296 0x000008fc, 0x00000000, 0xffffffff,
297 0x000008f8, 0x0000002b, 0xffffffff,
298 0x000008fc, 0x00000000, 0xffffffff
300 #define CAYMAN_CGCG_CGLS_DEFAULT_LENGTH sizeof(cayman_cgcg_cgls_default) / (3 * sizeof(u32))
302 static const u32 cayman_cgcg_cgls_disable
[] =
304 0x000008f8, 0x00000010, 0xffffffff,
305 0x000008fc, 0xffffffff, 0xffffffff,
306 0x000008f8, 0x00000011, 0xffffffff,
307 0x000008fc, 0xffffffff, 0xffffffff,
308 0x000008f8, 0x00000012, 0xffffffff,
309 0x000008fc, 0xffffffff, 0xffffffff,
310 0x000008f8, 0x00000013, 0xffffffff,
311 0x000008fc, 0xffffffff, 0xffffffff,
312 0x000008f8, 0x00000014, 0xffffffff,
313 0x000008fc, 0xffffffff, 0xffffffff,
314 0x000008f8, 0x00000015, 0xffffffff,
315 0x000008fc, 0xffffffff, 0xffffffff,
316 0x000008f8, 0x00000016, 0xffffffff,
317 0x000008fc, 0xffffffff, 0xffffffff,
318 0x000008f8, 0x00000017, 0xffffffff,
319 0x000008fc, 0xffffffff, 0xffffffff,
320 0x000008f8, 0x00000018, 0xffffffff,
321 0x000008fc, 0xffffffff, 0xffffffff,
322 0x000008f8, 0x00000019, 0xffffffff,
323 0x000008fc, 0xffffffff, 0xffffffff,
324 0x000008f8, 0x0000001a, 0xffffffff,
325 0x000008fc, 0xffffffff, 0xffffffff,
326 0x000008f8, 0x0000001b, 0xffffffff,
327 0x000008fc, 0xffffffff, 0xffffffff,
328 0x000008f8, 0x00000020, 0xffffffff,
329 0x000008fc, 0x00000000, 0xffffffff,
330 0x000008f8, 0x00000021, 0xffffffff,
331 0x000008fc, 0x00000000, 0xffffffff,
332 0x000008f8, 0x00000022, 0xffffffff,
333 0x000008fc, 0x00000000, 0xffffffff,
334 0x000008f8, 0x00000023, 0xffffffff,
335 0x000008fc, 0x00000000, 0xffffffff,
336 0x000008f8, 0x00000024, 0xffffffff,
337 0x000008fc, 0x00000000, 0xffffffff,
338 0x000008f8, 0x00000025, 0xffffffff,
339 0x000008fc, 0x00000000, 0xffffffff,
340 0x000008f8, 0x00000026, 0xffffffff,
341 0x000008fc, 0x00000000, 0xffffffff,
342 0x000008f8, 0x00000027, 0xffffffff,
343 0x000008fc, 0x00000000, 0xffffffff,
344 0x000008f8, 0x00000028, 0xffffffff,
345 0x000008fc, 0x00000000, 0xffffffff,
346 0x000008f8, 0x00000029, 0xffffffff,
347 0x000008fc, 0x00000000, 0xffffffff,
348 0x000008f8, 0x0000002a, 0xffffffff,
349 0x000008fc, 0x00000000, 0xffffffff,
350 0x000008f8, 0x0000002b, 0xffffffff,
351 0x000008fc, 0x00000000, 0xffffffff,
352 0x00000644, 0x000f7902, 0x001f4180,
353 0x00000644, 0x000f3802, 0x001f4180
355 #define CAYMAN_CGCG_CGLS_DISABLE_LENGTH sizeof(cayman_cgcg_cgls_disable) / (3 * sizeof(u32))
357 static const u32 cayman_cgcg_cgls_enable
[] =
359 0x00000644, 0x000f7882, 0x001f4080,
360 0x000008f8, 0x00000010, 0xffffffff,
361 0x000008fc, 0x00000000, 0xffffffff,
362 0x000008f8, 0x00000011, 0xffffffff,
363 0x000008fc, 0x00000000, 0xffffffff,
364 0x000008f8, 0x00000012, 0xffffffff,
365 0x000008fc, 0x00000000, 0xffffffff,
366 0x000008f8, 0x00000013, 0xffffffff,
367 0x000008fc, 0x00000000, 0xffffffff,
368 0x000008f8, 0x00000014, 0xffffffff,
369 0x000008fc, 0x00000000, 0xffffffff,
370 0x000008f8, 0x00000015, 0xffffffff,
371 0x000008fc, 0x00000000, 0xffffffff,
372 0x000008f8, 0x00000016, 0xffffffff,
373 0x000008fc, 0x00000000, 0xffffffff,
374 0x000008f8, 0x00000017, 0xffffffff,
375 0x000008fc, 0x00000000, 0xffffffff,
376 0x000008f8, 0x00000018, 0xffffffff,
377 0x000008fc, 0x00000000, 0xffffffff,
378 0x000008f8, 0x00000019, 0xffffffff,
379 0x000008fc, 0x00000000, 0xffffffff,
380 0x000008f8, 0x0000001a, 0xffffffff,
381 0x000008fc, 0x00000000, 0xffffffff,
382 0x000008f8, 0x0000001b, 0xffffffff,
383 0x000008fc, 0x00000000, 0xffffffff,
384 0x000008f8, 0x00000020, 0xffffffff,
385 0x000008fc, 0xffffffff, 0xffffffff,
386 0x000008f8, 0x00000021, 0xffffffff,
387 0x000008fc, 0xffffffff, 0xffffffff,
388 0x000008f8, 0x00000022, 0xffffffff,
389 0x000008fc, 0xffffffff, 0xffffffff,
390 0x000008f8, 0x00000023, 0xffffffff,
391 0x000008fc, 0xffffffff, 0xffffffff,
392 0x000008f8, 0x00000024, 0xffffffff,
393 0x000008fc, 0xffffffff, 0xffffffff,
394 0x000008f8, 0x00000025, 0xffffffff,
395 0x000008fc, 0xffffffff, 0xffffffff,
396 0x000008f8, 0x00000026, 0xffffffff,
397 0x000008fc, 0xffffffff, 0xffffffff,
398 0x000008f8, 0x00000027, 0xffffffff,
399 0x000008fc, 0xffffffff, 0xffffffff,
400 0x000008f8, 0x00000028, 0xffffffff,
401 0x000008fc, 0xffffffff, 0xffffffff,
402 0x000008f8, 0x00000029, 0xffffffff,
403 0x000008fc, 0xffffffff, 0xffffffff,
404 0x000008f8, 0x0000002a, 0xffffffff,
405 0x000008fc, 0xffffffff, 0xffffffff,
406 0x000008f8, 0x0000002b, 0xffffffff,
407 0x000008fc, 0xffffffff, 0xffffffff
409 #define CAYMAN_CGCG_CGLS_ENABLE_LENGTH sizeof(cayman_cgcg_cgls_enable) / (3 * sizeof(u32))
411 static const u32 cayman_mgcg_default
[] =
413 0x0000802c, 0xc0000000, 0xffffffff,
414 0x00003fc4, 0xc0000000, 0xffffffff,
415 0x00005448, 0x00000100, 0xffffffff,
416 0x000055e4, 0x00000100, 0xffffffff,
417 0x0000160c, 0x00000100, 0xffffffff,
418 0x00008984, 0x06000100, 0xffffffff,
419 0x0000c164, 0x00000100, 0xffffffff,
420 0x00008a18, 0x00000100, 0xffffffff,
421 0x0000897c, 0x06000100, 0xffffffff,
422 0x00008b28, 0x00000100, 0xffffffff,
423 0x00009144, 0x00800200, 0xffffffff,
424 0x00009a60, 0x00000100, 0xffffffff,
425 0x00009868, 0x00000100, 0xffffffff,
426 0x00008d58, 0x00000100, 0xffffffff,
427 0x00009510, 0x00000100, 0xffffffff,
428 0x0000949c, 0x00000100, 0xffffffff,
429 0x00009654, 0x00000100, 0xffffffff,
430 0x00009030, 0x00000100, 0xffffffff,
431 0x00009034, 0x00000100, 0xffffffff,
432 0x00009038, 0x00000100, 0xffffffff,
433 0x0000903c, 0x00000100, 0xffffffff,
434 0x00009040, 0x00000100, 0xffffffff,
435 0x0000a200, 0x00000100, 0xffffffff,
436 0x0000a204, 0x00000100, 0xffffffff,
437 0x0000a208, 0x00000100, 0xffffffff,
438 0x0000a20c, 0x00000100, 0xffffffff,
439 0x00009744, 0x00000100, 0xffffffff,
440 0x00003f80, 0x00000100, 0xffffffff,
441 0x0000a210, 0x00000100, 0xffffffff,
442 0x0000a214, 0x00000100, 0xffffffff,
443 0x000004d8, 0x00000100, 0xffffffff,
444 0x00009664, 0x00000100, 0xffffffff,
445 0x00009698, 0x00000100, 0xffffffff,
446 0x000004d4, 0x00000200, 0xffffffff,
447 0x000004d0, 0x00000000, 0xffffffff,
448 0x000030cc, 0x00000104, 0xffffffff,
449 0x0000d0c0, 0x00000100, 0xffffffff,
450 0x0000d8c0, 0x00000100, 0xffffffff,
451 0x0000802c, 0x40000000, 0xffffffff,
452 0x00003fc4, 0x40000000, 0xffffffff,
453 0x0000915c, 0x00010000, 0xffffffff,
454 0x00009160, 0x00030002, 0xffffffff,
455 0x00009164, 0x00050004, 0xffffffff,
456 0x00009168, 0x00070006, 0xffffffff,
457 0x00009178, 0x00070000, 0xffffffff,
458 0x0000917c, 0x00030002, 0xffffffff,
459 0x00009180, 0x00050004, 0xffffffff,
460 0x0000918c, 0x00010006, 0xffffffff,
461 0x00009190, 0x00090008, 0xffffffff,
462 0x00009194, 0x00070000, 0xffffffff,
463 0x00009198, 0x00030002, 0xffffffff,
464 0x0000919c, 0x00050004, 0xffffffff,
465 0x000091a8, 0x00010006, 0xffffffff,
466 0x000091ac, 0x00090008, 0xffffffff,
467 0x000091b0, 0x00070000, 0xffffffff,
468 0x000091b4, 0x00030002, 0xffffffff,
469 0x000091b8, 0x00050004, 0xffffffff,
470 0x000091c4, 0x00010006, 0xffffffff,
471 0x000091c8, 0x00090008, 0xffffffff,
472 0x000091cc, 0x00070000, 0xffffffff,
473 0x000091d0, 0x00030002, 0xffffffff,
474 0x000091d4, 0x00050004, 0xffffffff,
475 0x000091e0, 0x00010006, 0xffffffff,
476 0x000091e4, 0x00090008, 0xffffffff,
477 0x000091e8, 0x00000000, 0xffffffff,
478 0x000091ec, 0x00070000, 0xffffffff,
479 0x000091f0, 0x00030002, 0xffffffff,
480 0x000091f4, 0x00050004, 0xffffffff,
481 0x00009200, 0x00010006, 0xffffffff,
482 0x00009204, 0x00090008, 0xffffffff,
483 0x00009208, 0x00070000, 0xffffffff,
484 0x0000920c, 0x00030002, 0xffffffff,
485 0x00009210, 0x00050004, 0xffffffff,
486 0x0000921c, 0x00010006, 0xffffffff,
487 0x00009220, 0x00090008, 0xffffffff,
488 0x00009224, 0x00070000, 0xffffffff,
489 0x00009228, 0x00030002, 0xffffffff,
490 0x0000922c, 0x00050004, 0xffffffff,
491 0x00009238, 0x00010006, 0xffffffff,
492 0x0000923c, 0x00090008, 0xffffffff,
493 0x00009240, 0x00070000, 0xffffffff,
494 0x00009244, 0x00030002, 0xffffffff,
495 0x00009248, 0x00050004, 0xffffffff,
496 0x00009254, 0x00010006, 0xffffffff,
497 0x00009258, 0x00090008, 0xffffffff,
498 0x0000925c, 0x00070000, 0xffffffff,
499 0x00009260, 0x00030002, 0xffffffff,
500 0x00009264, 0x00050004, 0xffffffff,
501 0x00009270, 0x00010006, 0xffffffff,
502 0x00009274, 0x00090008, 0xffffffff,
503 0x00009278, 0x00070000, 0xffffffff,
504 0x0000927c, 0x00030002, 0xffffffff,
505 0x00009280, 0x00050004, 0xffffffff,
506 0x0000928c, 0x00010006, 0xffffffff,
507 0x00009290, 0x00090008, 0xffffffff,
508 0x000092a8, 0x00070000, 0xffffffff,
509 0x000092ac, 0x00030002, 0xffffffff,
510 0x000092b0, 0x00050004, 0xffffffff,
511 0x000092bc, 0x00010006, 0xffffffff,
512 0x000092c0, 0x00090008, 0xffffffff,
513 0x000092c4, 0x00070000, 0xffffffff,
514 0x000092c8, 0x00030002, 0xffffffff,
515 0x000092cc, 0x00050004, 0xffffffff,
516 0x000092d8, 0x00010006, 0xffffffff,
517 0x000092dc, 0x00090008, 0xffffffff,
518 0x00009294, 0x00000000, 0xffffffff,
519 0x0000802c, 0x40010000, 0xffffffff,
520 0x00003fc4, 0x40010000, 0xffffffff,
521 0x0000915c, 0x00010000, 0xffffffff,
522 0x00009160, 0x00030002, 0xffffffff,
523 0x00009164, 0x00050004, 0xffffffff,
524 0x00009168, 0x00070006, 0xffffffff,
525 0x00009178, 0x00070000, 0xffffffff,
526 0x0000917c, 0x00030002, 0xffffffff,
527 0x00009180, 0x00050004, 0xffffffff,
528 0x0000918c, 0x00010006, 0xffffffff,
529 0x00009190, 0x00090008, 0xffffffff,
530 0x00009194, 0x00070000, 0xffffffff,
531 0x00009198, 0x00030002, 0xffffffff,
532 0x0000919c, 0x00050004, 0xffffffff,
533 0x000091a8, 0x00010006, 0xffffffff,
534 0x000091ac, 0x00090008, 0xffffffff,
535 0x000091b0, 0x00070000, 0xffffffff,
536 0x000091b4, 0x00030002, 0xffffffff,
537 0x000091b8, 0x00050004, 0xffffffff,
538 0x000091c4, 0x00010006, 0xffffffff,
539 0x000091c8, 0x00090008, 0xffffffff,
540 0x000091cc, 0x00070000, 0xffffffff,
541 0x000091d0, 0x00030002, 0xffffffff,
542 0x000091d4, 0x00050004, 0xffffffff,
543 0x000091e0, 0x00010006, 0xffffffff,
544 0x000091e4, 0x00090008, 0xffffffff,
545 0x000091e8, 0x00000000, 0xffffffff,
546 0x000091ec, 0x00070000, 0xffffffff,
547 0x000091f0, 0x00030002, 0xffffffff,
548 0x000091f4, 0x00050004, 0xffffffff,
549 0x00009200, 0x00010006, 0xffffffff,
550 0x00009204, 0x00090008, 0xffffffff,
551 0x00009208, 0x00070000, 0xffffffff,
552 0x0000920c, 0x00030002, 0xffffffff,
553 0x00009210, 0x00050004, 0xffffffff,
554 0x0000921c, 0x00010006, 0xffffffff,
555 0x00009220, 0x00090008, 0xffffffff,
556 0x00009224, 0x00070000, 0xffffffff,
557 0x00009228, 0x00030002, 0xffffffff,
558 0x0000922c, 0x00050004, 0xffffffff,
559 0x00009238, 0x00010006, 0xffffffff,
560 0x0000923c, 0x00090008, 0xffffffff,
561 0x00009240, 0x00070000, 0xffffffff,
562 0x00009244, 0x00030002, 0xffffffff,
563 0x00009248, 0x00050004, 0xffffffff,
564 0x00009254, 0x00010006, 0xffffffff,
565 0x00009258, 0x00090008, 0xffffffff,
566 0x0000925c, 0x00070000, 0xffffffff,
567 0x00009260, 0x00030002, 0xffffffff,
568 0x00009264, 0x00050004, 0xffffffff,
569 0x00009270, 0x00010006, 0xffffffff,
570 0x00009274, 0x00090008, 0xffffffff,
571 0x00009278, 0x00070000, 0xffffffff,
572 0x0000927c, 0x00030002, 0xffffffff,
573 0x00009280, 0x00050004, 0xffffffff,
574 0x0000928c, 0x00010006, 0xffffffff,
575 0x00009290, 0x00090008, 0xffffffff,
576 0x000092a8, 0x00070000, 0xffffffff,
577 0x000092ac, 0x00030002, 0xffffffff,
578 0x000092b0, 0x00050004, 0xffffffff,
579 0x000092bc, 0x00010006, 0xffffffff,
580 0x000092c0, 0x00090008, 0xffffffff,
581 0x000092c4, 0x00070000, 0xffffffff,
582 0x000092c8, 0x00030002, 0xffffffff,
583 0x000092cc, 0x00050004, 0xffffffff,
584 0x000092d8, 0x00010006, 0xffffffff,
585 0x000092dc, 0x00090008, 0xffffffff,
586 0x00009294, 0x00000000, 0xffffffff,
587 0x0000802c, 0xc0000000, 0xffffffff,
588 0x00003fc4, 0xc0000000, 0xffffffff,
589 0x000008f8, 0x00000010, 0xffffffff,
590 0x000008fc, 0x00000000, 0xffffffff,
591 0x000008f8, 0x00000011, 0xffffffff,
592 0x000008fc, 0x00000000, 0xffffffff,
593 0x000008f8, 0x00000012, 0xffffffff,
594 0x000008fc, 0x00000000, 0xffffffff,
595 0x000008f8, 0x00000013, 0xffffffff,
596 0x000008fc, 0x00000000, 0xffffffff,
597 0x000008f8, 0x00000014, 0xffffffff,
598 0x000008fc, 0x00000000, 0xffffffff,
599 0x000008f8, 0x00000015, 0xffffffff,
600 0x000008fc, 0x00000000, 0xffffffff,
601 0x000008f8, 0x00000016, 0xffffffff,
602 0x000008fc, 0x00000000, 0xffffffff,
603 0x000008f8, 0x00000017, 0xffffffff,
604 0x000008fc, 0x00000000, 0xffffffff,
605 0x000008f8, 0x00000018, 0xffffffff,
606 0x000008fc, 0x00000000, 0xffffffff,
607 0x000008f8, 0x00000019, 0xffffffff,
608 0x000008fc, 0x00000000, 0xffffffff,
609 0x000008f8, 0x0000001a, 0xffffffff,
610 0x000008fc, 0x00000000, 0xffffffff,
611 0x000008f8, 0x0000001b, 0xffffffff,
612 0x000008fc, 0x00000000, 0xffffffff
614 #define CAYMAN_MGCG_DEFAULT_LENGTH sizeof(cayman_mgcg_default) / (3 * sizeof(u32))
616 static const u32 cayman_mgcg_disable
[] =
618 0x0000802c, 0xc0000000, 0xffffffff,
619 0x000008f8, 0x00000000, 0xffffffff,
620 0x000008fc, 0xffffffff, 0xffffffff,
621 0x000008f8, 0x00000001, 0xffffffff,
622 0x000008fc, 0xffffffff, 0xffffffff,
623 0x000008f8, 0x00000002, 0xffffffff,
624 0x000008fc, 0xffffffff, 0xffffffff,
625 0x000008f8, 0x00000003, 0xffffffff,
626 0x000008fc, 0xffffffff, 0xffffffff,
627 0x00009150, 0x00600000, 0xffffffff
629 #define CAYMAN_MGCG_DISABLE_LENGTH sizeof(cayman_mgcg_disable) / (3 * sizeof(u32))
631 static const u32 cayman_mgcg_enable
[] =
633 0x0000802c, 0xc0000000, 0xffffffff,
634 0x000008f8, 0x00000000, 0xffffffff,
635 0x000008fc, 0x00000000, 0xffffffff,
636 0x000008f8, 0x00000001, 0xffffffff,
637 0x000008fc, 0x00000000, 0xffffffff,
638 0x000008f8, 0x00000002, 0xffffffff,
639 0x000008fc, 0x00600000, 0xffffffff,
640 0x000008f8, 0x00000003, 0xffffffff,
641 0x000008fc, 0x00000000, 0xffffffff,
642 0x00009150, 0x96944200, 0xffffffff
645 #define CAYMAN_MGCG_ENABLE_LENGTH sizeof(cayman_mgcg_enable) / (3 * sizeof(u32))
647 #define NISLANDS_SYSLS_SEQUENCE 100
649 static const u32 cayman_sysls_default
[] =
651 /* Register, Value, Mask bits */
652 0x000055e8, 0x00000000, 0xffffffff,
653 0x0000d0bc, 0x00000000, 0xffffffff,
654 0x0000d8bc, 0x00000000, 0xffffffff,
655 0x000015c0, 0x000c1401, 0xffffffff,
656 0x0000264c, 0x000c0400, 0xffffffff,
657 0x00002648, 0x000c0400, 0xffffffff,
658 0x00002650, 0x000c0400, 0xffffffff,
659 0x000020b8, 0x000c0400, 0xffffffff,
660 0x000020bc, 0x000c0400, 0xffffffff,
661 0x000020c0, 0x000c0c80, 0xffffffff,
662 0x0000f4a0, 0x000000c0, 0xffffffff,
663 0x0000f4a4, 0x00680fff, 0xffffffff,
664 0x00002f50, 0x00000404, 0xffffffff,
665 0x000004c8, 0x00000001, 0xffffffff,
666 0x000064ec, 0x00000000, 0xffffffff,
667 0x00000c7c, 0x00000000, 0xffffffff,
668 0x00008dfc, 0x00000000, 0xffffffff
670 #define CAYMAN_SYSLS_DEFAULT_LENGTH sizeof(cayman_sysls_default) / (3 * sizeof(u32))
672 static const u32 cayman_sysls_disable
[] =
674 /* Register, Value, Mask bits */
675 0x0000d0c0, 0x00000000, 0xffffffff,
676 0x0000d8c0, 0x00000000, 0xffffffff,
677 0x000055e8, 0x00000000, 0xffffffff,
678 0x0000d0bc, 0x00000000, 0xffffffff,
679 0x0000d8bc, 0x00000000, 0xffffffff,
680 0x000015c0, 0x00041401, 0xffffffff,
681 0x0000264c, 0x00040400, 0xffffffff,
682 0x00002648, 0x00040400, 0xffffffff,
683 0x00002650, 0x00040400, 0xffffffff,
684 0x000020b8, 0x00040400, 0xffffffff,
685 0x000020bc, 0x00040400, 0xffffffff,
686 0x000020c0, 0x00040c80, 0xffffffff,
687 0x0000f4a0, 0x000000c0, 0xffffffff,
688 0x0000f4a4, 0x00680000, 0xffffffff,
689 0x00002f50, 0x00000404, 0xffffffff,
690 0x000004c8, 0x00000001, 0xffffffff,
691 0x000064ec, 0x00007ffd, 0xffffffff,
692 0x00000c7c, 0x0000ff00, 0xffffffff,
693 0x00008dfc, 0x0000007f, 0xffffffff
695 #define CAYMAN_SYSLS_DISABLE_LENGTH sizeof(cayman_sysls_disable) / (3 * sizeof(u32))
697 static const u32 cayman_sysls_enable
[] =
699 /* Register, Value, Mask bits */
700 0x000055e8, 0x00000001, 0xffffffff,
701 0x0000d0bc, 0x00000100, 0xffffffff,
702 0x0000d8bc, 0x00000100, 0xffffffff,
703 0x000015c0, 0x000c1401, 0xffffffff,
704 0x0000264c, 0x000c0400, 0xffffffff,
705 0x00002648, 0x000c0400, 0xffffffff,
706 0x00002650, 0x000c0400, 0xffffffff,
707 0x000020b8, 0x000c0400, 0xffffffff,
708 0x000020bc, 0x000c0400, 0xffffffff,
709 0x000020c0, 0x000c0c80, 0xffffffff,
710 0x0000f4a0, 0x000000c0, 0xffffffff,
711 0x0000f4a4, 0x00680fff, 0xffffffff,
712 0x00002f50, 0x00000903, 0xffffffff,
713 0x000004c8, 0x00000000, 0xffffffff,
714 0x000064ec, 0x00000000, 0xffffffff,
715 0x00000c7c, 0x00000000, 0xffffffff,
716 0x00008dfc, 0x00000000, 0xffffffff
718 #define CAYMAN_SYSLS_ENABLE_LENGTH sizeof(cayman_sysls_enable) / (3 * sizeof(u32))
720 struct rv7xx_power_info
*rv770_get_pi(struct radeon_device
*rdev
);
721 struct evergreen_power_info
*evergreen_get_pi(struct radeon_device
*rdev
);
723 extern int ni_mc_load_microcode(struct radeon_device
*rdev
);
725 struct ni_power_info
*ni_get_pi(struct radeon_device
*rdev
)
727 struct ni_power_info
*pi
= rdev
->pm
.dpm
.priv
;
732 struct ni_ps
*ni_get_ps(struct radeon_ps
*rps
)
734 struct ni_ps
*ps
= rps
->ps_priv
;
739 static void ni_calculate_leakage_for_v_and_t_formula(const struct ni_leakage_coeffients
*coeff
,
744 s64 kt
, kv
, leakage_w
, i_leakage
, vddc
, temperature
;
746 i_leakage
= div64_s64(drm_int2fixp(ileakage
), 1000);
747 vddc
= div64_s64(drm_int2fixp(v
), 1000);
748 temperature
= div64_s64(drm_int2fixp(t
), 1000);
750 kt
= drm_fixp_mul(div64_s64(drm_int2fixp(coeff
->at
), 1000),
751 drm_fixp_exp(drm_fixp_mul(div64_s64(drm_int2fixp(coeff
->bt
), 1000), temperature
)));
752 kv
= drm_fixp_mul(div64_s64(drm_int2fixp(coeff
->av
), 1000),
753 drm_fixp_exp(drm_fixp_mul(div64_s64(drm_int2fixp(coeff
->bv
), 1000), vddc
)));
755 leakage_w
= drm_fixp_mul(drm_fixp_mul(drm_fixp_mul(i_leakage
, kt
), kv
), vddc
);
757 *leakage
= drm_fixp2int(leakage_w
* 1000);
760 static void ni_calculate_leakage_for_v_and_t(struct radeon_device
*rdev
,
761 const struct ni_leakage_coeffients
*coeff
,
767 ni_calculate_leakage_for_v_and_t_formula(coeff
, v
, t
, i_leakage
, leakage
);
770 bool ni_dpm_vblank_too_short(struct radeon_device
*rdev
)
772 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
773 u32 vblank_time
= r600_dpm_get_vblank_time(rdev
);
774 /* we never hit the non-gddr5 limit so disable it */
775 u32 switch_limit
= pi
->mem_gddr5
? 450 : 0;
777 if (vblank_time
< switch_limit
)
784 static void ni_apply_state_adjust_rules(struct radeon_device
*rdev
,
785 struct radeon_ps
*rps
)
787 struct ni_ps
*ps
= ni_get_ps(rps
);
788 struct radeon_clock_and_voltage_limits
*max_limits
;
789 bool disable_mclk_switching
;
792 u32 max_sclk_vddc
, max_mclk_vddci
, max_mclk_vddc
;
795 if ((rdev
->pm
.dpm
.new_active_crtc_count
> 1) ||
796 ni_dpm_vblank_too_short(rdev
))
797 disable_mclk_switching
= true;
799 disable_mclk_switching
= false;
801 if (rdev
->pm
.dpm
.ac_power
)
802 max_limits
= &rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
;
804 max_limits
= &rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_dc
;
806 if (rdev
->pm
.dpm
.ac_power
== false) {
807 for (i
= 0; i
< ps
->performance_level_count
; i
++) {
808 if (ps
->performance_levels
[i
].mclk
> max_limits
->mclk
)
809 ps
->performance_levels
[i
].mclk
= max_limits
->mclk
;
810 if (ps
->performance_levels
[i
].sclk
> max_limits
->sclk
)
811 ps
->performance_levels
[i
].sclk
= max_limits
->sclk
;
812 if (ps
->performance_levels
[i
].vddc
> max_limits
->vddc
)
813 ps
->performance_levels
[i
].vddc
= max_limits
->vddc
;
814 if (ps
->performance_levels
[i
].vddci
> max_limits
->vddci
)
815 ps
->performance_levels
[i
].vddci
= max_limits
->vddci
;
819 /* limit clocks to max supported clocks based on voltage dependency tables */
820 btc_get_max_clock_from_voltage_dependency_table(&rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
,
822 btc_get_max_clock_from_voltage_dependency_table(&rdev
->pm
.dpm
.dyn_state
.vddci_dependency_on_mclk
,
824 btc_get_max_clock_from_voltage_dependency_table(&rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_mclk
,
827 for (i
= 0; i
< ps
->performance_level_count
; i
++) {
829 if (ps
->performance_levels
[i
].sclk
> max_sclk_vddc
)
830 ps
->performance_levels
[i
].sclk
= max_sclk_vddc
;
832 if (max_mclk_vddci
) {
833 if (ps
->performance_levels
[i
].mclk
> max_mclk_vddci
)
834 ps
->performance_levels
[i
].mclk
= max_mclk_vddci
;
837 if (ps
->performance_levels
[i
].mclk
> max_mclk_vddc
)
838 ps
->performance_levels
[i
].mclk
= max_mclk_vddc
;
842 /* XXX validate the min clocks required for display */
844 /* adjust low state */
845 if (disable_mclk_switching
) {
846 ps
->performance_levels
[0].mclk
=
847 ps
->performance_levels
[ps
->performance_level_count
- 1].mclk
;
848 ps
->performance_levels
[0].vddci
=
849 ps
->performance_levels
[ps
->performance_level_count
- 1].vddci
;
852 btc_skip_blacklist_clocks(rdev
, max_limits
->sclk
, max_limits
->mclk
,
853 &ps
->performance_levels
[0].sclk
,
854 &ps
->performance_levels
[0].mclk
);
856 for (i
= 1; i
< ps
->performance_level_count
; i
++) {
857 if (ps
->performance_levels
[i
].sclk
< ps
->performance_levels
[i
- 1].sclk
)
858 ps
->performance_levels
[i
].sclk
= ps
->performance_levels
[i
- 1].sclk
;
859 if (ps
->performance_levels
[i
].vddc
< ps
->performance_levels
[i
- 1].vddc
)
860 ps
->performance_levels
[i
].vddc
= ps
->performance_levels
[i
- 1].vddc
;
863 /* adjust remaining states */
864 if (disable_mclk_switching
) {
865 mclk
= ps
->performance_levels
[0].mclk
;
866 vddci
= ps
->performance_levels
[0].vddci
;
867 for (i
= 1; i
< ps
->performance_level_count
; i
++) {
868 if (mclk
< ps
->performance_levels
[i
].mclk
)
869 mclk
= ps
->performance_levels
[i
].mclk
;
870 if (vddci
< ps
->performance_levels
[i
].vddci
)
871 vddci
= ps
->performance_levels
[i
].vddci
;
873 for (i
= 0; i
< ps
->performance_level_count
; i
++) {
874 ps
->performance_levels
[i
].mclk
= mclk
;
875 ps
->performance_levels
[i
].vddci
= vddci
;
878 for (i
= 1; i
< ps
->performance_level_count
; i
++) {
879 if (ps
->performance_levels
[i
].mclk
< ps
->performance_levels
[i
- 1].mclk
)
880 ps
->performance_levels
[i
].mclk
= ps
->performance_levels
[i
- 1].mclk
;
881 if (ps
->performance_levels
[i
].vddci
< ps
->performance_levels
[i
- 1].vddci
)
882 ps
->performance_levels
[i
].vddci
= ps
->performance_levels
[i
- 1].vddci
;
886 for (i
= 1; i
< ps
->performance_level_count
; i
++)
887 btc_skip_blacklist_clocks(rdev
, max_limits
->sclk
, max_limits
->mclk
,
888 &ps
->performance_levels
[i
].sclk
,
889 &ps
->performance_levels
[i
].mclk
);
891 for (i
= 0; i
< ps
->performance_level_count
; i
++)
892 btc_adjust_clock_combinations(rdev
, max_limits
,
893 &ps
->performance_levels
[i
]);
895 for (i
= 0; i
< ps
->performance_level_count
; i
++) {
896 btc_apply_voltage_dependency_rules(&rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
,
897 ps
->performance_levels
[i
].sclk
,
898 max_limits
->vddc
, &ps
->performance_levels
[i
].vddc
);
899 btc_apply_voltage_dependency_rules(&rdev
->pm
.dpm
.dyn_state
.vddci_dependency_on_mclk
,
900 ps
->performance_levels
[i
].mclk
,
901 max_limits
->vddci
, &ps
->performance_levels
[i
].vddci
);
902 btc_apply_voltage_dependency_rules(&rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_mclk
,
903 ps
->performance_levels
[i
].mclk
,
904 max_limits
->vddc
, &ps
->performance_levels
[i
].vddc
);
905 btc_apply_voltage_dependency_rules(&rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
,
906 rdev
->clock
.current_dispclk
,
907 max_limits
->vddc
, &ps
->performance_levels
[i
].vddc
);
910 for (i
= 0; i
< ps
->performance_level_count
; i
++) {
911 btc_apply_voltage_delta_rules(rdev
,
912 max_limits
->vddc
, max_limits
->vddci
,
913 &ps
->performance_levels
[i
].vddc
,
914 &ps
->performance_levels
[i
].vddci
);
917 ps
->dc_compatible
= true;
918 for (i
= 0; i
< ps
->performance_level_count
; i
++) {
919 if (ps
->performance_levels
[i
].vddc
> rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_dc
.vddc
)
920 ps
->dc_compatible
= false;
922 if (ps
->performance_levels
[i
].vddc
< rdev
->pm
.dpm
.dyn_state
.min_vddc_for_pcie_gen2
)
923 ps
->performance_levels
[i
].flags
&= ~ATOM_PPLIB_R600_FLAGS_PCIEGEN2
;
927 static void ni_cg_clockgating_default(struct radeon_device
*rdev
)
930 const u32
*ps
= NULL
;
932 ps
= (const u32
*)&cayman_cgcg_cgls_default
;
933 count
= CAYMAN_CGCG_CGLS_DEFAULT_LENGTH
;
935 btc_program_mgcg_hw_sequence(rdev
, ps
, count
);
938 static void ni_gfx_clockgating_enable(struct radeon_device
*rdev
,
942 const u32
*ps
= NULL
;
945 ps
= (const u32
*)&cayman_cgcg_cgls_enable
;
946 count
= CAYMAN_CGCG_CGLS_ENABLE_LENGTH
;
948 ps
= (const u32
*)&cayman_cgcg_cgls_disable
;
949 count
= CAYMAN_CGCG_CGLS_DISABLE_LENGTH
;
952 btc_program_mgcg_hw_sequence(rdev
, ps
, count
);
955 static void ni_mg_clockgating_default(struct radeon_device
*rdev
)
958 const u32
*ps
= NULL
;
960 ps
= (const u32
*)&cayman_mgcg_default
;
961 count
= CAYMAN_MGCG_DEFAULT_LENGTH
;
963 btc_program_mgcg_hw_sequence(rdev
, ps
, count
);
966 static void ni_mg_clockgating_enable(struct radeon_device
*rdev
,
970 const u32
*ps
= NULL
;
973 ps
= (const u32
*)&cayman_mgcg_enable
;
974 count
= CAYMAN_MGCG_ENABLE_LENGTH
;
976 ps
= (const u32
*)&cayman_mgcg_disable
;
977 count
= CAYMAN_MGCG_DISABLE_LENGTH
;
980 btc_program_mgcg_hw_sequence(rdev
, ps
, count
);
983 static void ni_ls_clockgating_default(struct radeon_device
*rdev
)
986 const u32
*ps
= NULL
;
988 ps
= (const u32
*)&cayman_sysls_default
;
989 count
= CAYMAN_SYSLS_DEFAULT_LENGTH
;
991 btc_program_mgcg_hw_sequence(rdev
, ps
, count
);
994 static void ni_ls_clockgating_enable(struct radeon_device
*rdev
,
998 const u32
*ps
= NULL
;
1001 ps
= (const u32
*)&cayman_sysls_enable
;
1002 count
= CAYMAN_SYSLS_ENABLE_LENGTH
;
1004 ps
= (const u32
*)&cayman_sysls_disable
;
1005 count
= CAYMAN_SYSLS_DISABLE_LENGTH
;
1008 btc_program_mgcg_hw_sequence(rdev
, ps
, count
);
1012 static int ni_patch_single_dependency_table_based_on_leakage(struct radeon_device
*rdev
,
1013 struct radeon_clock_voltage_dependency_table
*table
)
1015 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
1019 for (i
= 0; i
< table
->count
; i
++) {
1020 if (0xff01 == table
->entries
[i
].v
) {
1021 if (pi
->max_vddc
== 0)
1023 table
->entries
[i
].v
= pi
->max_vddc
;
1030 static int ni_patch_dependency_tables_based_on_leakage(struct radeon_device
*rdev
)
1034 ret
= ni_patch_single_dependency_table_based_on_leakage(rdev
,
1035 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
);
1037 ret
= ni_patch_single_dependency_table_based_on_leakage(rdev
,
1038 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_mclk
);
1042 static void ni_stop_dpm(struct radeon_device
*rdev
)
1044 WREG32_P(GENERAL_PWRMGT
, 0, ~GLOBAL_PWRMGT_EN
);
1048 static int ni_notify_hw_of_power_source(struct radeon_device
*rdev
,
1052 return (rv770_send_msg_to_smc(rdev
, PPSMC_MSG_RunningOnAC
) == PPSMC_Result_OK
) ?
1059 static PPSMC_Result
ni_send_msg_to_smc_with_parameter(struct radeon_device
*rdev
,
1060 PPSMC_Msg msg
, u32 parameter
)
1062 WREG32(SMC_SCRATCH0
, parameter
);
1063 return rv770_send_msg_to_smc(rdev
, msg
);
1066 static int ni_restrict_performance_levels_before_switch(struct radeon_device
*rdev
)
1068 if (rv770_send_msg_to_smc(rdev
, PPSMC_MSG_NoForcedLevel
) != PPSMC_Result_OK
)
1071 return (ni_send_msg_to_smc_with_parameter(rdev
, PPSMC_MSG_SetEnabledLevels
, 1) == PPSMC_Result_OK
) ?
1075 int ni_dpm_force_performance_level(struct radeon_device
*rdev
,
1076 enum radeon_dpm_forced_level level
)
1078 if (level
== RADEON_DPM_FORCED_LEVEL_HIGH
) {
1079 if (ni_send_msg_to_smc_with_parameter(rdev
, PPSMC_MSG_SetEnabledLevels
, 0) != PPSMC_Result_OK
)
1082 if (ni_send_msg_to_smc_with_parameter(rdev
, PPSMC_MSG_SetForcedLevels
, 1) != PPSMC_Result_OK
)
1084 } else if (level
== RADEON_DPM_FORCED_LEVEL_LOW
) {
1085 if (ni_send_msg_to_smc_with_parameter(rdev
, PPSMC_MSG_SetForcedLevels
, 0) != PPSMC_Result_OK
)
1088 if (ni_send_msg_to_smc_with_parameter(rdev
, PPSMC_MSG_SetEnabledLevels
, 1) != PPSMC_Result_OK
)
1090 } else if (level
== RADEON_DPM_FORCED_LEVEL_AUTO
) {
1091 if (ni_send_msg_to_smc_with_parameter(rdev
, PPSMC_MSG_SetForcedLevels
, 0) != PPSMC_Result_OK
)
1094 if (ni_send_msg_to_smc_with_parameter(rdev
, PPSMC_MSG_SetEnabledLevels
, 0) != PPSMC_Result_OK
)
1098 rdev
->pm
.dpm
.forced_level
= level
;
1103 static void ni_stop_smc(struct radeon_device
*rdev
)
1108 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
1109 tmp
= RREG32(LB_SYNC_RESET_SEL
) & LB_SYNC_RESET_SEL_MASK
;
1117 r7xx_stop_smc(rdev
);
1120 static int ni_process_firmware_header(struct radeon_device
*rdev
)
1122 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
1123 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
1124 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
1128 ret
= rv770_read_smc_sram_dword(rdev
,
1129 NISLANDS_SMC_FIRMWARE_HEADER_LOCATION
+
1130 NISLANDS_SMC_FIRMWARE_HEADER_stateTable
,
1131 &tmp
, pi
->sram_end
);
1136 pi
->state_table_start
= (u16
)tmp
;
1138 ret
= rv770_read_smc_sram_dword(rdev
,
1139 NISLANDS_SMC_FIRMWARE_HEADER_LOCATION
+
1140 NISLANDS_SMC_FIRMWARE_HEADER_softRegisters
,
1141 &tmp
, pi
->sram_end
);
1146 pi
->soft_regs_start
= (u16
)tmp
;
1148 ret
= rv770_read_smc_sram_dword(rdev
,
1149 NISLANDS_SMC_FIRMWARE_HEADER_LOCATION
+
1150 NISLANDS_SMC_FIRMWARE_HEADER_mcRegisterTable
,
1151 &tmp
, pi
->sram_end
);
1156 eg_pi
->mc_reg_table_start
= (u16
)tmp
;
1158 ret
= rv770_read_smc_sram_dword(rdev
,
1159 NISLANDS_SMC_FIRMWARE_HEADER_LOCATION
+
1160 NISLANDS_SMC_FIRMWARE_HEADER_fanTable
,
1161 &tmp
, pi
->sram_end
);
1166 ni_pi
->fan_table_start
= (u16
)tmp
;
1168 ret
= rv770_read_smc_sram_dword(rdev
,
1169 NISLANDS_SMC_FIRMWARE_HEADER_LOCATION
+
1170 NISLANDS_SMC_FIRMWARE_HEADER_mcArbDramAutoRefreshTable
,
1171 &tmp
, pi
->sram_end
);
1176 ni_pi
->arb_table_start
= (u16
)tmp
;
1178 ret
= rv770_read_smc_sram_dword(rdev
,
1179 NISLANDS_SMC_FIRMWARE_HEADER_LOCATION
+
1180 NISLANDS_SMC_FIRMWARE_HEADER_cacTable
,
1181 &tmp
, pi
->sram_end
);
1186 ni_pi
->cac_table_start
= (u16
)tmp
;
1188 ret
= rv770_read_smc_sram_dword(rdev
,
1189 NISLANDS_SMC_FIRMWARE_HEADER_LOCATION
+
1190 NISLANDS_SMC_FIRMWARE_HEADER_spllTable
,
1191 &tmp
, pi
->sram_end
);
1196 ni_pi
->spll_table_start
= (u16
)tmp
;
1202 static void ni_read_clock_registers(struct radeon_device
*rdev
)
1204 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
1206 ni_pi
->clock_registers
.cg_spll_func_cntl
= RREG32(CG_SPLL_FUNC_CNTL
);
1207 ni_pi
->clock_registers
.cg_spll_func_cntl_2
= RREG32(CG_SPLL_FUNC_CNTL_2
);
1208 ni_pi
->clock_registers
.cg_spll_func_cntl_3
= RREG32(CG_SPLL_FUNC_CNTL_3
);
1209 ni_pi
->clock_registers
.cg_spll_func_cntl_4
= RREG32(CG_SPLL_FUNC_CNTL_4
);
1210 ni_pi
->clock_registers
.cg_spll_spread_spectrum
= RREG32(CG_SPLL_SPREAD_SPECTRUM
);
1211 ni_pi
->clock_registers
.cg_spll_spread_spectrum_2
= RREG32(CG_SPLL_SPREAD_SPECTRUM_2
);
1212 ni_pi
->clock_registers
.mpll_ad_func_cntl
= RREG32(MPLL_AD_FUNC_CNTL
);
1213 ni_pi
->clock_registers
.mpll_ad_func_cntl_2
= RREG32(MPLL_AD_FUNC_CNTL_2
);
1214 ni_pi
->clock_registers
.mpll_dq_func_cntl
= RREG32(MPLL_DQ_FUNC_CNTL
);
1215 ni_pi
->clock_registers
.mpll_dq_func_cntl_2
= RREG32(MPLL_DQ_FUNC_CNTL_2
);
1216 ni_pi
->clock_registers
.mclk_pwrmgt_cntl
= RREG32(MCLK_PWRMGT_CNTL
);
1217 ni_pi
->clock_registers
.dll_cntl
= RREG32(DLL_CNTL
);
1218 ni_pi
->clock_registers
.mpll_ss1
= RREG32(MPLL_SS1
);
1219 ni_pi
->clock_registers
.mpll_ss2
= RREG32(MPLL_SS2
);
1223 static int ni_enter_ulp_state(struct radeon_device
*rdev
)
1225 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
1227 if (pi
->gfx_clock_gating
) {
1228 WREG32_P(SCLK_PWRMGT_CNTL
, 0, ~DYN_GFX_CLK_OFF_EN
);
1229 WREG32_P(SCLK_PWRMGT_CNTL
, GFX_CLK_FORCE_ON
, ~GFX_CLK_FORCE_ON
);
1230 WREG32_P(SCLK_PWRMGT_CNTL
, 0, ~GFX_CLK_FORCE_ON
);
1231 RREG32(GB_ADDR_CONFIG
);
1234 WREG32_P(SMC_MSG
, HOST_SMC_MSG(PPSMC_MSG_SwitchToMinimumPower
),
1235 ~HOST_SMC_MSG_MASK
);
1243 static void ni_program_response_times(struct radeon_device
*rdev
)
1245 u32 voltage_response_time
, backbias_response_time
, acpi_delay_time
, vbi_time_out
;
1246 u32 vddc_dly
, bb_dly
, acpi_dly
, vbi_dly
, mclk_switch_limit
;
1247 u32 reference_clock
;
1249 rv770_write_smc_soft_register(rdev
, NI_SMC_SOFT_REGISTER_mvdd_chg_time
, 1);
1251 voltage_response_time
= (u32
)rdev
->pm
.dpm
.voltage_response_time
;
1252 backbias_response_time
= (u32
)rdev
->pm
.dpm
.backbias_response_time
;
1254 if (voltage_response_time
== 0)
1255 voltage_response_time
= 1000;
1257 if (backbias_response_time
== 0)
1258 backbias_response_time
= 1000;
1260 acpi_delay_time
= 15000;
1261 vbi_time_out
= 100000;
1263 reference_clock
= radeon_get_xclk(rdev
);
1265 vddc_dly
= (voltage_response_time
* reference_clock
) / 1600;
1266 bb_dly
= (backbias_response_time
* reference_clock
) / 1600;
1267 acpi_dly
= (acpi_delay_time
* reference_clock
) / 1600;
1268 vbi_dly
= (vbi_time_out
* reference_clock
) / 1600;
1270 mclk_switch_limit
= (460 * reference_clock
) / 100;
1272 rv770_write_smc_soft_register(rdev
, NI_SMC_SOFT_REGISTER_delay_vreg
, vddc_dly
);
1273 rv770_write_smc_soft_register(rdev
, NI_SMC_SOFT_REGISTER_delay_bbias
, bb_dly
);
1274 rv770_write_smc_soft_register(rdev
, NI_SMC_SOFT_REGISTER_delay_acpi
, acpi_dly
);
1275 rv770_write_smc_soft_register(rdev
, NI_SMC_SOFT_REGISTER_mclk_chg_timeout
, vbi_dly
);
1276 rv770_write_smc_soft_register(rdev
, NI_SMC_SOFT_REGISTER_mc_block_delay
, 0xAA);
1277 rv770_write_smc_soft_register(rdev
, NI_SMC_SOFT_REGISTER_mclk_switch_lim
, mclk_switch_limit
);
1280 static void ni_populate_smc_voltage_table(struct radeon_device
*rdev
,
1281 struct atom_voltage_table
*voltage_table
,
1282 NISLANDS_SMC_STATETABLE
*table
)
1286 for (i
= 0; i
< voltage_table
->count
; i
++) {
1287 table
->highSMIO
[i
] = 0;
1288 table
->lowSMIO
[i
] |= cpu_to_be32(voltage_table
->entries
[i
].smio_low
);
1292 static void ni_populate_smc_voltage_tables(struct radeon_device
*rdev
,
1293 NISLANDS_SMC_STATETABLE
*table
)
1295 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
1296 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
1299 if (eg_pi
->vddc_voltage_table
.count
) {
1300 ni_populate_smc_voltage_table(rdev
, &eg_pi
->vddc_voltage_table
, table
);
1301 table
->voltageMaskTable
.highMask
[NISLANDS_SMC_VOLTAGEMASK_VDDC
] = 0;
1302 table
->voltageMaskTable
.lowMask
[NISLANDS_SMC_VOLTAGEMASK_VDDC
] =
1303 cpu_to_be32(eg_pi
->vddc_voltage_table
.mask_low
);
1305 for (i
= 0; i
< eg_pi
->vddc_voltage_table
.count
; i
++) {
1306 if (pi
->max_vddc_in_table
<= eg_pi
->vddc_voltage_table
.entries
[i
].value
) {
1307 table
->maxVDDCIndexInPPTable
= i
;
1313 if (eg_pi
->vddci_voltage_table
.count
) {
1314 ni_populate_smc_voltage_table(rdev
, &eg_pi
->vddci_voltage_table
, table
);
1316 table
->voltageMaskTable
.highMask
[NISLANDS_SMC_VOLTAGEMASK_VDDCI
] = 0;
1317 table
->voltageMaskTable
.lowMask
[NISLANDS_SMC_VOLTAGEMASK_VDDCI
] =
1318 cpu_to_be32(eg_pi
->vddc_voltage_table
.mask_low
);
1322 static int ni_populate_voltage_value(struct radeon_device
*rdev
,
1323 struct atom_voltage_table
*table
,
1325 NISLANDS_SMC_VOLTAGE_VALUE
*voltage
)
1329 for (i
= 0; i
< table
->count
; i
++) {
1330 if (value
<= table
->entries
[i
].value
) {
1331 voltage
->index
= (u8
)i
;
1332 voltage
->value
= cpu_to_be16(table
->entries
[i
].value
);
1337 if (i
>= table
->count
)
1343 static void ni_populate_mvdd_value(struct radeon_device
*rdev
,
1345 NISLANDS_SMC_VOLTAGE_VALUE
*voltage
)
1347 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
1348 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
1350 if (!pi
->mvdd_control
) {
1351 voltage
->index
= eg_pi
->mvdd_high_index
;
1352 voltage
->value
= cpu_to_be16(MVDD_HIGH_VALUE
);
1356 if (mclk
<= pi
->mvdd_split_frequency
) {
1357 voltage
->index
= eg_pi
->mvdd_low_index
;
1358 voltage
->value
= cpu_to_be16(MVDD_LOW_VALUE
);
1360 voltage
->index
= eg_pi
->mvdd_high_index
;
1361 voltage
->value
= cpu_to_be16(MVDD_HIGH_VALUE
);
1365 static int ni_get_std_voltage_value(struct radeon_device
*rdev
,
1366 NISLANDS_SMC_VOLTAGE_VALUE
*voltage
,
1369 if (rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.entries
&&
1370 ((u32
)voltage
->index
< rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.count
))
1371 *std_voltage
= rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.entries
[voltage
->index
].vddc
;
1373 *std_voltage
= be16_to_cpu(voltage
->value
);
1378 static void ni_populate_std_voltage_value(struct radeon_device
*rdev
,
1379 u16 value
, u8 index
,
1380 NISLANDS_SMC_VOLTAGE_VALUE
*voltage
)
1382 voltage
->index
= index
;
1383 voltage
->value
= cpu_to_be16(value
);
1386 static u32
ni_get_smc_power_scaling_factor(struct radeon_device
*rdev
)
1389 u32 xclk
= radeon_get_xclk(rdev
);
1390 u32 tmp
= RREG32(CG_CAC_CTRL
) & TID_CNT_MASK
;
1392 xclk_period
= (1000000000UL / xclk
);
1393 xclk_period
/= 10000UL;
1395 return tmp
* xclk_period
;
1398 static u32
ni_scale_power_for_smc(u32 power_in_watts
, u32 scaling_factor
)
1400 return (power_in_watts
* scaling_factor
) << 2;
1403 static u32
ni_calculate_power_boost_limit(struct radeon_device
*rdev
,
1404 struct radeon_ps
*radeon_state
,
1407 struct ni_ps
*state
= ni_get_ps(radeon_state
);
1408 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
1409 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
1410 u32 power_boost_limit
= 0;
1413 if (ni_pi
->enable_power_containment
&&
1414 ni_pi
->use_power_boost_limit
) {
1415 NISLANDS_SMC_VOLTAGE_VALUE vddc
;
1420 if (state
->performance_level_count
< 3)
1423 ret
= ni_populate_voltage_value(rdev
, &eg_pi
->vddc_voltage_table
,
1424 state
->performance_levels
[state
->performance_level_count
- 2].vddc
,
1429 ret
= ni_get_std_voltage_value(rdev
, &vddc
, &std_vddc_med
);
1433 ret
= ni_populate_voltage_value(rdev
, &eg_pi
->vddc_voltage_table
,
1434 state
->performance_levels
[state
->performance_level_count
- 1].vddc
,
1439 ret
= ni_get_std_voltage_value(rdev
, &vddc
, &std_vddc_high
);
1443 n
= ((u64
)near_tdp_limit
* ((u64
)std_vddc_med
* (u64
)std_vddc_med
) * 90);
1444 d
= ((u64
)std_vddc_high
* (u64
)std_vddc_high
* 100);
1445 tmp
= div64_u64(n
, d
);
1449 power_boost_limit
= (u32
)tmp
;
1452 return power_boost_limit
;
1455 static int ni_calculate_adjusted_tdp_limits(struct radeon_device
*rdev
,
1456 bool adjust_polarity
,
1459 u32
*near_tdp_limit
)
1461 if (tdp_adjustment
> (u32
)rdev
->pm
.dpm
.tdp_od_limit
)
1464 if (adjust_polarity
) {
1465 *tdp_limit
= ((100 + tdp_adjustment
) * rdev
->pm
.dpm
.tdp_limit
) / 100;
1466 *near_tdp_limit
= rdev
->pm
.dpm
.near_tdp_limit
+ (*tdp_limit
- rdev
->pm
.dpm
.tdp_limit
);
1468 *tdp_limit
= ((100 - tdp_adjustment
) * rdev
->pm
.dpm
.tdp_limit
) / 100;
1469 *near_tdp_limit
= rdev
->pm
.dpm
.near_tdp_limit
- (rdev
->pm
.dpm
.tdp_limit
- *tdp_limit
);
1475 static int ni_populate_smc_tdp_limits(struct radeon_device
*rdev
,
1476 struct radeon_ps
*radeon_state
)
1478 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
1479 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
1481 if (ni_pi
->enable_power_containment
) {
1482 NISLANDS_SMC_STATETABLE
*smc_table
= &ni_pi
->smc_statetable
;
1483 u32 scaling_factor
= ni_get_smc_power_scaling_factor(rdev
);
1486 u32 power_boost_limit
;
1489 if (scaling_factor
== 0)
1492 memset(smc_table
, 0, sizeof(NISLANDS_SMC_STATETABLE
));
1494 ret
= ni_calculate_adjusted_tdp_limits(rdev
,
1496 rdev
->pm
.dpm
.tdp_adjustment
,
1502 power_boost_limit
= ni_calculate_power_boost_limit(rdev
, radeon_state
,
1505 smc_table
->dpm2Params
.TDPLimit
=
1506 cpu_to_be32(ni_scale_power_for_smc(tdp_limit
, scaling_factor
));
1507 smc_table
->dpm2Params
.NearTDPLimit
=
1508 cpu_to_be32(ni_scale_power_for_smc(near_tdp_limit
, scaling_factor
));
1509 smc_table
->dpm2Params
.SafePowerLimit
=
1510 cpu_to_be32(ni_scale_power_for_smc((near_tdp_limit
* NISLANDS_DPM2_TDP_SAFE_LIMIT_PERCENT
) / 100,
1512 smc_table
->dpm2Params
.PowerBoostLimit
=
1513 cpu_to_be32(ni_scale_power_for_smc(power_boost_limit
, scaling_factor
));
1515 ret
= rv770_copy_bytes_to_smc(rdev
,
1516 (u16
)(pi
->state_table_start
+ offsetof(NISLANDS_SMC_STATETABLE
, dpm2Params
) +
1517 offsetof(PP_NIslands_DPM2Parameters
, TDPLimit
)),
1518 (u8
*)(&smc_table
->dpm2Params
.TDPLimit
),
1519 sizeof(u32
) * 4, pi
->sram_end
);
1527 int ni_copy_and_switch_arb_sets(struct radeon_device
*rdev
,
1528 u32 arb_freq_src
, u32 arb_freq_dest
)
1530 u32 mc_arb_dram_timing
;
1531 u32 mc_arb_dram_timing2
;
1535 switch (arb_freq_src
) {
1536 case MC_CG_ARB_FREQ_F0
:
1537 mc_arb_dram_timing
= RREG32(MC_ARB_DRAM_TIMING
);
1538 mc_arb_dram_timing2
= RREG32(MC_ARB_DRAM_TIMING2
);
1539 burst_time
= (RREG32(MC_ARB_BURST_TIME
) & STATE0_MASK
) >> STATE0_SHIFT
;
1541 case MC_CG_ARB_FREQ_F1
:
1542 mc_arb_dram_timing
= RREG32(MC_ARB_DRAM_TIMING_1
);
1543 mc_arb_dram_timing2
= RREG32(MC_ARB_DRAM_TIMING2_1
);
1544 burst_time
= (RREG32(MC_ARB_BURST_TIME
) & STATE1_MASK
) >> STATE1_SHIFT
;
1546 case MC_CG_ARB_FREQ_F2
:
1547 mc_arb_dram_timing
= RREG32(MC_ARB_DRAM_TIMING_2
);
1548 mc_arb_dram_timing2
= RREG32(MC_ARB_DRAM_TIMING2_2
);
1549 burst_time
= (RREG32(MC_ARB_BURST_TIME
) & STATE2_MASK
) >> STATE2_SHIFT
;
1551 case MC_CG_ARB_FREQ_F3
:
1552 mc_arb_dram_timing
= RREG32(MC_ARB_DRAM_TIMING_3
);
1553 mc_arb_dram_timing2
= RREG32(MC_ARB_DRAM_TIMING2_3
);
1554 burst_time
= (RREG32(MC_ARB_BURST_TIME
) & STATE3_MASK
) >> STATE3_SHIFT
;
1560 switch (arb_freq_dest
) {
1561 case MC_CG_ARB_FREQ_F0
:
1562 WREG32(MC_ARB_DRAM_TIMING
, mc_arb_dram_timing
);
1563 WREG32(MC_ARB_DRAM_TIMING2
, mc_arb_dram_timing2
);
1564 WREG32_P(MC_ARB_BURST_TIME
, STATE0(burst_time
), ~STATE0_MASK
);
1566 case MC_CG_ARB_FREQ_F1
:
1567 WREG32(MC_ARB_DRAM_TIMING_1
, mc_arb_dram_timing
);
1568 WREG32(MC_ARB_DRAM_TIMING2_1
, mc_arb_dram_timing2
);
1569 WREG32_P(MC_ARB_BURST_TIME
, STATE1(burst_time
), ~STATE1_MASK
);
1571 case MC_CG_ARB_FREQ_F2
:
1572 WREG32(MC_ARB_DRAM_TIMING_2
, mc_arb_dram_timing
);
1573 WREG32(MC_ARB_DRAM_TIMING2_2
, mc_arb_dram_timing2
);
1574 WREG32_P(MC_ARB_BURST_TIME
, STATE2(burst_time
), ~STATE2_MASK
);
1576 case MC_CG_ARB_FREQ_F3
:
1577 WREG32(MC_ARB_DRAM_TIMING_3
, mc_arb_dram_timing
);
1578 WREG32(MC_ARB_DRAM_TIMING2_3
, mc_arb_dram_timing2
);
1579 WREG32_P(MC_ARB_BURST_TIME
, STATE3(burst_time
), ~STATE3_MASK
);
1585 mc_cg_config
= RREG32(MC_CG_CONFIG
) | 0x0000000F;
1586 WREG32(MC_CG_CONFIG
, mc_cg_config
);
1587 WREG32_P(MC_ARB_CG
, CG_ARB_REQ(arb_freq_dest
), ~CG_ARB_REQ_MASK
);
1592 static int ni_init_arb_table_index(struct radeon_device
*rdev
)
1594 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
1595 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
1599 ret
= rv770_read_smc_sram_dword(rdev
, ni_pi
->arb_table_start
,
1600 &tmp
, pi
->sram_end
);
1605 tmp
|= ((u32
)MC_CG_ARB_FREQ_F1
) << 24;
1607 return rv770_write_smc_sram_dword(rdev
, ni_pi
->arb_table_start
,
1611 static int ni_initial_switch_from_arb_f0_to_f1(struct radeon_device
*rdev
)
1613 return ni_copy_and_switch_arb_sets(rdev
, MC_CG_ARB_FREQ_F0
, MC_CG_ARB_FREQ_F1
);
1616 static int ni_force_switch_to_arb_f0(struct radeon_device
*rdev
)
1618 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
1619 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
1623 ret
= rv770_read_smc_sram_dword(rdev
, ni_pi
->arb_table_start
,
1624 &tmp
, pi
->sram_end
);
1628 tmp
= (tmp
>> 24) & 0xff;
1630 if (tmp
== MC_CG_ARB_FREQ_F0
)
1633 return ni_copy_and_switch_arb_sets(rdev
, tmp
, MC_CG_ARB_FREQ_F0
);
1636 static int ni_populate_memory_timing_parameters(struct radeon_device
*rdev
,
1637 struct rv7xx_pl
*pl
,
1638 SMC_NIslands_MCArbDramTimingRegisterSet
*arb_regs
)
1643 arb_regs
->mc_arb_rfsh_rate
=
1644 (u8
)rv770_calculate_memory_refresh_rate(rdev
, pl
->sclk
);
1647 radeon_atom_set_engine_dram_timings(rdev
,
1651 dram_timing
= RREG32(MC_ARB_DRAM_TIMING
);
1652 dram_timing2
= RREG32(MC_ARB_DRAM_TIMING2
);
1654 arb_regs
->mc_arb_dram_timing
= cpu_to_be32(dram_timing
);
1655 arb_regs
->mc_arb_dram_timing2
= cpu_to_be32(dram_timing2
);
1660 static int ni_do_program_memory_timing_parameters(struct radeon_device
*rdev
,
1661 struct radeon_ps
*radeon_state
,
1662 unsigned int first_arb_set
)
1664 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
1665 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
1666 struct ni_ps
*state
= ni_get_ps(radeon_state
);
1667 SMC_NIslands_MCArbDramTimingRegisterSet arb_regs
= { 0 };
1670 for (i
= 0; i
< state
->performance_level_count
; i
++) {
1671 ret
= ni_populate_memory_timing_parameters(rdev
, &state
->performance_levels
[i
], &arb_regs
);
1675 ret
= rv770_copy_bytes_to_smc(rdev
,
1676 (u16
)(ni_pi
->arb_table_start
+
1677 offsetof(SMC_NIslands_MCArbDramTimingRegisters
, data
) +
1678 sizeof(SMC_NIslands_MCArbDramTimingRegisterSet
) * (first_arb_set
+ i
)),
1680 (u16
)sizeof(SMC_NIslands_MCArbDramTimingRegisterSet
),
1688 static int ni_program_memory_timing_parameters(struct radeon_device
*rdev
,
1689 struct radeon_ps
*radeon_new_state
)
1691 return ni_do_program_memory_timing_parameters(rdev
, radeon_new_state
,
1692 NISLANDS_DRIVER_STATE_ARB_INDEX
);
1695 static void ni_populate_initial_mvdd_value(struct radeon_device
*rdev
,
1696 struct NISLANDS_SMC_VOLTAGE_VALUE
*voltage
)
1698 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
1700 voltage
->index
= eg_pi
->mvdd_high_index
;
1701 voltage
->value
= cpu_to_be16(MVDD_HIGH_VALUE
);
1704 static int ni_populate_smc_initial_state(struct radeon_device
*rdev
,
1705 struct radeon_ps
*radeon_initial_state
,
1706 NISLANDS_SMC_STATETABLE
*table
)
1708 struct ni_ps
*initial_state
= ni_get_ps(radeon_initial_state
);
1709 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
1710 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
1711 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
1715 table
->initialState
.levels
[0].mclk
.vMPLL_AD_FUNC_CNTL
=
1716 cpu_to_be32(ni_pi
->clock_registers
.mpll_ad_func_cntl
);
1717 table
->initialState
.levels
[0].mclk
.vMPLL_AD_FUNC_CNTL_2
=
1718 cpu_to_be32(ni_pi
->clock_registers
.mpll_ad_func_cntl_2
);
1719 table
->initialState
.levels
[0].mclk
.vMPLL_DQ_FUNC_CNTL
=
1720 cpu_to_be32(ni_pi
->clock_registers
.mpll_dq_func_cntl
);
1721 table
->initialState
.levels
[0].mclk
.vMPLL_DQ_FUNC_CNTL_2
=
1722 cpu_to_be32(ni_pi
->clock_registers
.mpll_dq_func_cntl_2
);
1723 table
->initialState
.levels
[0].mclk
.vMCLK_PWRMGT_CNTL
=
1724 cpu_to_be32(ni_pi
->clock_registers
.mclk_pwrmgt_cntl
);
1725 table
->initialState
.levels
[0].mclk
.vDLL_CNTL
=
1726 cpu_to_be32(ni_pi
->clock_registers
.dll_cntl
);
1727 table
->initialState
.levels
[0].mclk
.vMPLL_SS
=
1728 cpu_to_be32(ni_pi
->clock_registers
.mpll_ss1
);
1729 table
->initialState
.levels
[0].mclk
.vMPLL_SS2
=
1730 cpu_to_be32(ni_pi
->clock_registers
.mpll_ss2
);
1731 table
->initialState
.levels
[0].mclk
.mclk_value
=
1732 cpu_to_be32(initial_state
->performance_levels
[0].mclk
);
1734 table
->initialState
.levels
[0].sclk
.vCG_SPLL_FUNC_CNTL
=
1735 cpu_to_be32(ni_pi
->clock_registers
.cg_spll_func_cntl
);
1736 table
->initialState
.levels
[0].sclk
.vCG_SPLL_FUNC_CNTL_2
=
1737 cpu_to_be32(ni_pi
->clock_registers
.cg_spll_func_cntl_2
);
1738 table
->initialState
.levels
[0].sclk
.vCG_SPLL_FUNC_CNTL_3
=
1739 cpu_to_be32(ni_pi
->clock_registers
.cg_spll_func_cntl_3
);
1740 table
->initialState
.levels
[0].sclk
.vCG_SPLL_FUNC_CNTL_4
=
1741 cpu_to_be32(ni_pi
->clock_registers
.cg_spll_func_cntl_4
);
1742 table
->initialState
.levels
[0].sclk
.vCG_SPLL_SPREAD_SPECTRUM
=
1743 cpu_to_be32(ni_pi
->clock_registers
.cg_spll_spread_spectrum
);
1744 table
->initialState
.levels
[0].sclk
.vCG_SPLL_SPREAD_SPECTRUM_2
=
1745 cpu_to_be32(ni_pi
->clock_registers
.cg_spll_spread_spectrum_2
);
1746 table
->initialState
.levels
[0].sclk
.sclk_value
=
1747 cpu_to_be32(initial_state
->performance_levels
[0].sclk
);
1748 table
->initialState
.levels
[0].arbRefreshState
=
1749 NISLANDS_INITIAL_STATE_ARB_INDEX
;
1751 table
->initialState
.levels
[0].ACIndex
= 0;
1753 ret
= ni_populate_voltage_value(rdev
, &eg_pi
->vddc_voltage_table
,
1754 initial_state
->performance_levels
[0].vddc
,
1755 &table
->initialState
.levels
[0].vddc
);
1759 ret
= ni_get_std_voltage_value(rdev
,
1760 &table
->initialState
.levels
[0].vddc
,
1763 ni_populate_std_voltage_value(rdev
, std_vddc
,
1764 table
->initialState
.levels
[0].vddc
.index
,
1765 &table
->initialState
.levels
[0].std_vddc
);
1768 if (eg_pi
->vddci_control
)
1769 ni_populate_voltage_value(rdev
,
1770 &eg_pi
->vddci_voltage_table
,
1771 initial_state
->performance_levels
[0].vddci
,
1772 &table
->initialState
.levels
[0].vddci
);
1774 ni_populate_initial_mvdd_value(rdev
, &table
->initialState
.levels
[0].mvdd
);
1776 reg
= CG_R(0xffff) | CG_L(0);
1777 table
->initialState
.levels
[0].aT
= cpu_to_be32(reg
);
1779 table
->initialState
.levels
[0].bSP
= cpu_to_be32(pi
->dsp
);
1781 if (pi
->boot_in_gen2
)
1782 table
->initialState
.levels
[0].gen2PCIE
= 1;
1784 table
->initialState
.levels
[0].gen2PCIE
= 0;
1786 if (pi
->mem_gddr5
) {
1787 table
->initialState
.levels
[0].strobeMode
=
1788 cypress_get_strobe_mode_settings(rdev
,
1789 initial_state
->performance_levels
[0].mclk
);
1791 if (initial_state
->performance_levels
[0].mclk
> pi
->mclk_edc_enable_threshold
)
1792 table
->initialState
.levels
[0].mcFlags
= NISLANDS_SMC_MC_EDC_RD_FLAG
| NISLANDS_SMC_MC_EDC_WR_FLAG
;
1794 table
->initialState
.levels
[0].mcFlags
= 0;
1797 table
->initialState
.levelCount
= 1;
1799 table
->initialState
.flags
|= PPSMC_SWSTATE_FLAG_DC
;
1801 table
->initialState
.levels
[0].dpm2
.MaxPS
= 0;
1802 table
->initialState
.levels
[0].dpm2
.NearTDPDec
= 0;
1803 table
->initialState
.levels
[0].dpm2
.AboveSafeInc
= 0;
1804 table
->initialState
.levels
[0].dpm2
.BelowSafeInc
= 0;
1806 reg
= MIN_POWER_MASK
| MAX_POWER_MASK
;
1807 table
->initialState
.levels
[0].SQPowerThrottle
= cpu_to_be32(reg
);
1809 reg
= MAX_POWER_DELTA_MASK
| STI_SIZE_MASK
| LTI_RATIO_MASK
;
1810 table
->initialState
.levels
[0].SQPowerThrottle_2
= cpu_to_be32(reg
);
1815 static int ni_populate_smc_acpi_state(struct radeon_device
*rdev
,
1816 NISLANDS_SMC_STATETABLE
*table
)
1818 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
1819 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
1820 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
1821 u32 mpll_ad_func_cntl
= ni_pi
->clock_registers
.mpll_ad_func_cntl
;
1822 u32 mpll_ad_func_cntl_2
= ni_pi
->clock_registers
.mpll_ad_func_cntl_2
;
1823 u32 mpll_dq_func_cntl
= ni_pi
->clock_registers
.mpll_dq_func_cntl
;
1824 u32 mpll_dq_func_cntl_2
= ni_pi
->clock_registers
.mpll_dq_func_cntl_2
;
1825 u32 spll_func_cntl
= ni_pi
->clock_registers
.cg_spll_func_cntl
;
1826 u32 spll_func_cntl_2
= ni_pi
->clock_registers
.cg_spll_func_cntl_2
;
1827 u32 spll_func_cntl_3
= ni_pi
->clock_registers
.cg_spll_func_cntl_3
;
1828 u32 spll_func_cntl_4
= ni_pi
->clock_registers
.cg_spll_func_cntl_4
;
1829 u32 mclk_pwrmgt_cntl
= ni_pi
->clock_registers
.mclk_pwrmgt_cntl
;
1830 u32 dll_cntl
= ni_pi
->clock_registers
.dll_cntl
;
1834 table
->ACPIState
= table
->initialState
;
1836 table
->ACPIState
.flags
&= ~PPSMC_SWSTATE_FLAG_DC
;
1838 if (pi
->acpi_vddc
) {
1839 ret
= ni_populate_voltage_value(rdev
,
1840 &eg_pi
->vddc_voltage_table
,
1841 pi
->acpi_vddc
, &table
->ACPIState
.levels
[0].vddc
);
1845 ret
= ni_get_std_voltage_value(rdev
,
1846 &table
->ACPIState
.levels
[0].vddc
, &std_vddc
);
1848 ni_populate_std_voltage_value(rdev
, std_vddc
,
1849 table
->ACPIState
.levels
[0].vddc
.index
,
1850 &table
->ACPIState
.levels
[0].std_vddc
);
1853 if (pi
->pcie_gen2
) {
1854 if (pi
->acpi_pcie_gen2
)
1855 table
->ACPIState
.levels
[0].gen2PCIE
= 1;
1857 table
->ACPIState
.levels
[0].gen2PCIE
= 0;
1859 table
->ACPIState
.levels
[0].gen2PCIE
= 0;
1862 ret
= ni_populate_voltage_value(rdev
,
1863 &eg_pi
->vddc_voltage_table
,
1864 pi
->min_vddc_in_table
,
1865 &table
->ACPIState
.levels
[0].vddc
);
1869 ret
= ni_get_std_voltage_value(rdev
,
1870 &table
->ACPIState
.levels
[0].vddc
,
1873 ni_populate_std_voltage_value(rdev
, std_vddc
,
1874 table
->ACPIState
.levels
[0].vddc
.index
,
1875 &table
->ACPIState
.levels
[0].std_vddc
);
1877 table
->ACPIState
.levels
[0].gen2PCIE
= 0;
1880 if (eg_pi
->acpi_vddci
) {
1881 if (eg_pi
->vddci_control
)
1882 ni_populate_voltage_value(rdev
,
1883 &eg_pi
->vddci_voltage_table
,
1885 &table
->ACPIState
.levels
[0].vddci
);
1889 mpll_ad_func_cntl
&= ~PDNB
;
1891 mpll_ad_func_cntl_2
|= BIAS_GEN_PDNB
| RESET_EN
;
1894 mpll_dq_func_cntl
&= ~PDNB
;
1895 mpll_dq_func_cntl_2
|= BIAS_GEN_PDNB
| RESET_EN
| BYPASS
;
1898 mclk_pwrmgt_cntl
|= (MRDCKA0_RESET
|
1907 mclk_pwrmgt_cntl
&= ~(MRDCKA0_PDNB
|
1916 dll_cntl
|= (MRDCKA0_BYPASS
|
1925 spll_func_cntl_2
&= ~SCLK_MUX_SEL_MASK
;
1926 spll_func_cntl_2
|= SCLK_MUX_SEL(4);
1928 table
->ACPIState
.levels
[0].mclk
.vMPLL_AD_FUNC_CNTL
= cpu_to_be32(mpll_ad_func_cntl
);
1929 table
->ACPIState
.levels
[0].mclk
.vMPLL_AD_FUNC_CNTL_2
= cpu_to_be32(mpll_ad_func_cntl_2
);
1930 table
->ACPIState
.levels
[0].mclk
.vMPLL_DQ_FUNC_CNTL
= cpu_to_be32(mpll_dq_func_cntl
);
1931 table
->ACPIState
.levels
[0].mclk
.vMPLL_DQ_FUNC_CNTL_2
= cpu_to_be32(mpll_dq_func_cntl_2
);
1932 table
->ACPIState
.levels
[0].mclk
.vMCLK_PWRMGT_CNTL
= cpu_to_be32(mclk_pwrmgt_cntl
);
1933 table
->ACPIState
.levels
[0].mclk
.vDLL_CNTL
= cpu_to_be32(dll_cntl
);
1935 table
->ACPIState
.levels
[0].mclk
.mclk_value
= 0;
1937 table
->ACPIState
.levels
[0].sclk
.vCG_SPLL_FUNC_CNTL
= cpu_to_be32(spll_func_cntl
);
1938 table
->ACPIState
.levels
[0].sclk
.vCG_SPLL_FUNC_CNTL_2
= cpu_to_be32(spll_func_cntl_2
);
1939 table
->ACPIState
.levels
[0].sclk
.vCG_SPLL_FUNC_CNTL_3
= cpu_to_be32(spll_func_cntl_3
);
1940 table
->ACPIState
.levels
[0].sclk
.vCG_SPLL_FUNC_CNTL_4
= cpu_to_be32(spll_func_cntl_4
);
1942 table
->ACPIState
.levels
[0].sclk
.sclk_value
= 0;
1944 ni_populate_mvdd_value(rdev
, 0, &table
->ACPIState
.levels
[0].mvdd
);
1946 if (eg_pi
->dynamic_ac_timing
)
1947 table
->ACPIState
.levels
[0].ACIndex
= 1;
1949 table
->ACPIState
.levels
[0].dpm2
.MaxPS
= 0;
1950 table
->ACPIState
.levels
[0].dpm2
.NearTDPDec
= 0;
1951 table
->ACPIState
.levels
[0].dpm2
.AboveSafeInc
= 0;
1952 table
->ACPIState
.levels
[0].dpm2
.BelowSafeInc
= 0;
1954 reg
= MIN_POWER_MASK
| MAX_POWER_MASK
;
1955 table
->ACPIState
.levels
[0].SQPowerThrottle
= cpu_to_be32(reg
);
1957 reg
= MAX_POWER_DELTA_MASK
| STI_SIZE_MASK
| LTI_RATIO_MASK
;
1958 table
->ACPIState
.levels
[0].SQPowerThrottle_2
= cpu_to_be32(reg
);
1963 static int ni_init_smc_table(struct radeon_device
*rdev
)
1965 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
1966 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
1968 struct radeon_ps
*radeon_boot_state
= rdev
->pm
.dpm
.boot_ps
;
1969 NISLANDS_SMC_STATETABLE
*table
= &ni_pi
->smc_statetable
;
1971 memset(table
, 0, sizeof(NISLANDS_SMC_STATETABLE
));
1973 ni_populate_smc_voltage_tables(rdev
, table
);
1975 switch (rdev
->pm
.int_thermal_type
) {
1976 case THERMAL_TYPE_NI
:
1977 case THERMAL_TYPE_EMC2103_WITH_INTERNAL
:
1978 table
->thermalProtectType
= PPSMC_THERMAL_PROTECT_TYPE_INTERNAL
;
1980 case THERMAL_TYPE_NONE
:
1981 table
->thermalProtectType
= PPSMC_THERMAL_PROTECT_TYPE_NONE
;
1984 table
->thermalProtectType
= PPSMC_THERMAL_PROTECT_TYPE_EXTERNAL
;
1988 if (rdev
->pm
.dpm
.platform_caps
& ATOM_PP_PLATFORM_CAP_HARDWAREDC
)
1989 table
->systemFlags
|= PPSMC_SYSTEMFLAG_GPIO_DC
;
1991 if (rdev
->pm
.dpm
.platform_caps
& ATOM_PP_PLATFORM_CAP_REGULATOR_HOT
)
1992 table
->systemFlags
|= PPSMC_SYSTEMFLAG_REGULATOR_HOT
;
1994 if (rdev
->pm
.dpm
.platform_caps
& ATOM_PP_PLATFORM_CAP_STEPVDDC
)
1995 table
->systemFlags
|= PPSMC_SYSTEMFLAG_STEPVDDC
;
1998 table
->systemFlags
|= PPSMC_SYSTEMFLAG_GDDR5
;
2000 ret
= ni_populate_smc_initial_state(rdev
, radeon_boot_state
, table
);
2004 ret
= ni_populate_smc_acpi_state(rdev
, table
);
2008 table
->driverState
= table
->initialState
;
2010 table
->ULVState
= table
->initialState
;
2012 ret
= ni_do_program_memory_timing_parameters(rdev
, radeon_boot_state
,
2013 NISLANDS_INITIAL_STATE_ARB_INDEX
);
2017 return rv770_copy_bytes_to_smc(rdev
, pi
->state_table_start
, (u8
*)table
,
2018 sizeof(NISLANDS_SMC_STATETABLE
), pi
->sram_end
);
2021 static int ni_calculate_sclk_params(struct radeon_device
*rdev
,
2023 NISLANDS_SMC_SCLK_VALUE
*sclk
)
2025 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
2026 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
2027 struct atom_clock_dividers dividers
;
2028 u32 spll_func_cntl
= ni_pi
->clock_registers
.cg_spll_func_cntl
;
2029 u32 spll_func_cntl_2
= ni_pi
->clock_registers
.cg_spll_func_cntl_2
;
2030 u32 spll_func_cntl_3
= ni_pi
->clock_registers
.cg_spll_func_cntl_3
;
2031 u32 spll_func_cntl_4
= ni_pi
->clock_registers
.cg_spll_func_cntl_4
;
2032 u32 cg_spll_spread_spectrum
= ni_pi
->clock_registers
.cg_spll_spread_spectrum
;
2033 u32 cg_spll_spread_spectrum_2
= ni_pi
->clock_registers
.cg_spll_spread_spectrum_2
;
2035 u32 reference_clock
= rdev
->clock
.spll
.reference_freq
;
2036 u32 reference_divider
;
2040 ret
= radeon_atom_get_clock_dividers(rdev
, COMPUTE_ENGINE_PLL_PARAM
,
2041 engine_clock
, false, ÷rs
);
2045 reference_divider
= 1 + dividers
.ref_div
;
2048 tmp
= (u64
) engine_clock
* reference_divider
* dividers
.post_div
* 16834;
2049 do_div(tmp
, reference_clock
);
2052 spll_func_cntl
&= ~(SPLL_PDIV_A_MASK
| SPLL_REF_DIV_MASK
);
2053 spll_func_cntl
|= SPLL_REF_DIV(dividers
.ref_div
);
2054 spll_func_cntl
|= SPLL_PDIV_A(dividers
.post_div
);
2056 spll_func_cntl_2
&= ~SCLK_MUX_SEL_MASK
;
2057 spll_func_cntl_2
|= SCLK_MUX_SEL(2);
2059 spll_func_cntl_3
&= ~SPLL_FB_DIV_MASK
;
2060 spll_func_cntl_3
|= SPLL_FB_DIV(fbdiv
);
2061 spll_func_cntl_3
|= SPLL_DITHEN
;
2064 struct radeon_atom_ss ss
;
2065 u32 vco_freq
= engine_clock
* dividers
.post_div
;
2067 if (radeon_atombios_get_asic_ss_info(rdev
, &ss
,
2068 ASIC_INTERNAL_ENGINE_SS
, vco_freq
)) {
2069 u32 clk_s
= reference_clock
* 5 / (reference_divider
* ss
.rate
);
2070 u32 clk_v
= 4 * ss
.percentage
* fbdiv
/ (clk_s
* 10000);
2072 cg_spll_spread_spectrum
&= ~CLK_S_MASK
;
2073 cg_spll_spread_spectrum
|= CLK_S(clk_s
);
2074 cg_spll_spread_spectrum
|= SSEN
;
2076 cg_spll_spread_spectrum_2
&= ~CLK_V_MASK
;
2077 cg_spll_spread_spectrum_2
|= CLK_V(clk_v
);
2081 sclk
->sclk_value
= engine_clock
;
2082 sclk
->vCG_SPLL_FUNC_CNTL
= spll_func_cntl
;
2083 sclk
->vCG_SPLL_FUNC_CNTL_2
= spll_func_cntl_2
;
2084 sclk
->vCG_SPLL_FUNC_CNTL_3
= spll_func_cntl_3
;
2085 sclk
->vCG_SPLL_FUNC_CNTL_4
= spll_func_cntl_4
;
2086 sclk
->vCG_SPLL_SPREAD_SPECTRUM
= cg_spll_spread_spectrum
;
2087 sclk
->vCG_SPLL_SPREAD_SPECTRUM_2
= cg_spll_spread_spectrum_2
;
2092 static int ni_populate_sclk_value(struct radeon_device
*rdev
,
2094 NISLANDS_SMC_SCLK_VALUE
*sclk
)
2096 NISLANDS_SMC_SCLK_VALUE sclk_tmp
;
2099 ret
= ni_calculate_sclk_params(rdev
, engine_clock
, &sclk_tmp
);
2101 sclk
->sclk_value
= cpu_to_be32(sclk_tmp
.sclk_value
);
2102 sclk
->vCG_SPLL_FUNC_CNTL
= cpu_to_be32(sclk_tmp
.vCG_SPLL_FUNC_CNTL
);
2103 sclk
->vCG_SPLL_FUNC_CNTL_2
= cpu_to_be32(sclk_tmp
.vCG_SPLL_FUNC_CNTL_2
);
2104 sclk
->vCG_SPLL_FUNC_CNTL_3
= cpu_to_be32(sclk_tmp
.vCG_SPLL_FUNC_CNTL_3
);
2105 sclk
->vCG_SPLL_FUNC_CNTL_4
= cpu_to_be32(sclk_tmp
.vCG_SPLL_FUNC_CNTL_4
);
2106 sclk
->vCG_SPLL_SPREAD_SPECTRUM
= cpu_to_be32(sclk_tmp
.vCG_SPLL_SPREAD_SPECTRUM
);
2107 sclk
->vCG_SPLL_SPREAD_SPECTRUM_2
= cpu_to_be32(sclk_tmp
.vCG_SPLL_SPREAD_SPECTRUM_2
);
2113 static int ni_init_smc_spll_table(struct radeon_device
*rdev
)
2115 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
2116 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
2117 SMC_NISLANDS_SPLL_DIV_TABLE
*spll_table
;
2118 NISLANDS_SMC_SCLK_VALUE sclk_params
;
2127 if (ni_pi
->spll_table_start
== 0)
2130 spll_table
= kzalloc(sizeof(SMC_NISLANDS_SPLL_DIV_TABLE
), GFP_KERNEL
);
2131 if (spll_table
== NULL
)
2134 for (i
= 0; i
< 256; i
++) {
2135 ret
= ni_calculate_sclk_params(rdev
, sclk
, &sclk_params
);
2139 p_div
= (sclk_params
.vCG_SPLL_FUNC_CNTL
& SPLL_PDIV_A_MASK
) >> SPLL_PDIV_A_SHIFT
;
2140 fb_div
= (sclk_params
.vCG_SPLL_FUNC_CNTL_3
& SPLL_FB_DIV_MASK
) >> SPLL_FB_DIV_SHIFT
;
2141 clk_s
= (sclk_params
.vCG_SPLL_SPREAD_SPECTRUM
& CLK_S_MASK
) >> CLK_S_SHIFT
;
2142 clk_v
= (sclk_params
.vCG_SPLL_SPREAD_SPECTRUM_2
& CLK_V_MASK
) >> CLK_V_SHIFT
;
2144 fb_div
&= ~0x00001FFF;
2148 if (p_div
& ~(SMC_NISLANDS_SPLL_DIV_TABLE_PDIV_MASK
>> SMC_NISLANDS_SPLL_DIV_TABLE_PDIV_SHIFT
))
2151 if (clk_s
& ~(SMC_NISLANDS_SPLL_DIV_TABLE_CLKS_MASK
>> SMC_NISLANDS_SPLL_DIV_TABLE_CLKS_SHIFT
))
2154 if (clk_s
& ~(SMC_NISLANDS_SPLL_DIV_TABLE_CLKS_MASK
>> SMC_NISLANDS_SPLL_DIV_TABLE_CLKS_SHIFT
))
2157 if (clk_v
& ~(SMC_NISLANDS_SPLL_DIV_TABLE_CLKV_MASK
>> SMC_NISLANDS_SPLL_DIV_TABLE_CLKV_SHIFT
))
2163 tmp
= ((fb_div
<< SMC_NISLANDS_SPLL_DIV_TABLE_FBDIV_SHIFT
) & SMC_NISLANDS_SPLL_DIV_TABLE_FBDIV_MASK
) |
2164 ((p_div
<< SMC_NISLANDS_SPLL_DIV_TABLE_PDIV_SHIFT
) & SMC_NISLANDS_SPLL_DIV_TABLE_PDIV_MASK
);
2165 spll_table
->freq
[i
] = cpu_to_be32(tmp
);
2167 tmp
= ((clk_v
<< SMC_NISLANDS_SPLL_DIV_TABLE_CLKV_SHIFT
) & SMC_NISLANDS_SPLL_DIV_TABLE_CLKV_MASK
) |
2168 ((clk_s
<< SMC_NISLANDS_SPLL_DIV_TABLE_CLKS_SHIFT
) & SMC_NISLANDS_SPLL_DIV_TABLE_CLKS_MASK
);
2169 spll_table
->ss
[i
] = cpu_to_be32(tmp
);
2175 ret
= rv770_copy_bytes_to_smc(rdev
, ni_pi
->spll_table_start
, (u8
*)spll_table
,
2176 sizeof(SMC_NISLANDS_SPLL_DIV_TABLE
), pi
->sram_end
);
2183 static int ni_populate_mclk_value(struct radeon_device
*rdev
,
2186 NISLANDS_SMC_MCLK_VALUE
*mclk
,
2190 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
2191 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
2192 u32 mpll_ad_func_cntl
= ni_pi
->clock_registers
.mpll_ad_func_cntl
;
2193 u32 mpll_ad_func_cntl_2
= ni_pi
->clock_registers
.mpll_ad_func_cntl_2
;
2194 u32 mpll_dq_func_cntl
= ni_pi
->clock_registers
.mpll_dq_func_cntl
;
2195 u32 mpll_dq_func_cntl_2
= ni_pi
->clock_registers
.mpll_dq_func_cntl_2
;
2196 u32 mclk_pwrmgt_cntl
= ni_pi
->clock_registers
.mclk_pwrmgt_cntl
;
2197 u32 dll_cntl
= ni_pi
->clock_registers
.dll_cntl
;
2198 u32 mpll_ss1
= ni_pi
->clock_registers
.mpll_ss1
;
2199 u32 mpll_ss2
= ni_pi
->clock_registers
.mpll_ss2
;
2200 struct atom_clock_dividers dividers
;
2206 ret
= radeon_atom_get_clock_dividers(rdev
, COMPUTE_MEMORY_PLL_PARAM
,
2207 memory_clock
, strobe_mode
, ÷rs
);
2212 mc_seq_misc7
= RREG32(MC_SEQ_MISC7
);
2214 if (mc_seq_misc7
& 0x8000000)
2215 dividers
.post_div
= 1;
2218 ibias
= cypress_map_clkf_to_ibias(rdev
, dividers
.whole_fb_div
);
2220 mpll_ad_func_cntl
&= ~(CLKR_MASK
|
2221 YCLK_POST_DIV_MASK
|
2225 mpll_ad_func_cntl
|= CLKR(dividers
.ref_div
);
2226 mpll_ad_func_cntl
|= YCLK_POST_DIV(dividers
.post_div
);
2227 mpll_ad_func_cntl
|= CLKF(dividers
.whole_fb_div
);
2228 mpll_ad_func_cntl
|= CLKFRAC(dividers
.frac_fb_div
);
2229 mpll_ad_func_cntl
|= IBIAS(ibias
);
2231 if (dividers
.vco_mode
)
2232 mpll_ad_func_cntl_2
|= VCO_MODE
;
2234 mpll_ad_func_cntl_2
&= ~VCO_MODE
;
2236 if (pi
->mem_gddr5
) {
2237 mpll_dq_func_cntl
&= ~(CLKR_MASK
|
2238 YCLK_POST_DIV_MASK
|
2242 mpll_dq_func_cntl
|= CLKR(dividers
.ref_div
);
2243 mpll_dq_func_cntl
|= YCLK_POST_DIV(dividers
.post_div
);
2244 mpll_dq_func_cntl
|= CLKF(dividers
.whole_fb_div
);
2245 mpll_dq_func_cntl
|= CLKFRAC(dividers
.frac_fb_div
);
2246 mpll_dq_func_cntl
|= IBIAS(ibias
);
2249 mpll_dq_func_cntl
&= ~PDNB
;
2251 mpll_dq_func_cntl
|= PDNB
;
2253 if (dividers
.vco_mode
)
2254 mpll_dq_func_cntl_2
|= VCO_MODE
;
2256 mpll_dq_func_cntl_2
&= ~VCO_MODE
;
2260 struct radeon_atom_ss ss
;
2261 u32 vco_freq
= memory_clock
* dividers
.post_div
;
2263 if (radeon_atombios_get_asic_ss_info(rdev
, &ss
,
2264 ASIC_INTERNAL_MEMORY_SS
, vco_freq
)) {
2265 u32 reference_clock
= rdev
->clock
.mpll
.reference_freq
;
2266 u32 decoded_ref
= rv740_get_decoded_reference_divider(dividers
.ref_div
);
2267 u32 clk_s
= reference_clock
* 5 / (decoded_ref
* ss
.rate
);
2268 u32 clk_v
= ss
.percentage
*
2269 (0x4000 * dividers
.whole_fb_div
+ 0x800 * dividers
.frac_fb_div
) / (clk_s
* 625);
2271 mpll_ss1
&= ~CLKV_MASK
;
2272 mpll_ss1
|= CLKV(clk_v
);
2274 mpll_ss2
&= ~CLKS_MASK
;
2275 mpll_ss2
|= CLKS(clk_s
);
2279 dll_speed
= rv740_get_dll_speed(pi
->mem_gddr5
,
2282 mclk_pwrmgt_cntl
&= ~DLL_SPEED_MASK
;
2283 mclk_pwrmgt_cntl
|= DLL_SPEED(dll_speed
);
2285 mclk_pwrmgt_cntl
|= (MRDCKA0_PDNB
|
2294 mclk_pwrmgt_cntl
&= ~(MRDCKA0_PDNB
|
2304 mclk
->mclk_value
= cpu_to_be32(memory_clock
);
2305 mclk
->vMPLL_AD_FUNC_CNTL
= cpu_to_be32(mpll_ad_func_cntl
);
2306 mclk
->vMPLL_AD_FUNC_CNTL_2
= cpu_to_be32(mpll_ad_func_cntl_2
);
2307 mclk
->vMPLL_DQ_FUNC_CNTL
= cpu_to_be32(mpll_dq_func_cntl
);
2308 mclk
->vMPLL_DQ_FUNC_CNTL_2
= cpu_to_be32(mpll_dq_func_cntl_2
);
2309 mclk
->vMCLK_PWRMGT_CNTL
= cpu_to_be32(mclk_pwrmgt_cntl
);
2310 mclk
->vDLL_CNTL
= cpu_to_be32(dll_cntl
);
2311 mclk
->vMPLL_SS
= cpu_to_be32(mpll_ss1
);
2312 mclk
->vMPLL_SS2
= cpu_to_be32(mpll_ss2
);
2317 static void ni_populate_smc_sp(struct radeon_device
*rdev
,
2318 struct radeon_ps
*radeon_state
,
2319 NISLANDS_SMC_SWSTATE
*smc_state
)
2321 struct ni_ps
*ps
= ni_get_ps(radeon_state
);
2322 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
2325 for (i
= 0; i
< ps
->performance_level_count
- 1; i
++)
2326 smc_state
->levels
[i
].bSP
= cpu_to_be32(pi
->dsp
);
2328 smc_state
->levels
[ps
->performance_level_count
- 1].bSP
=
2329 cpu_to_be32(pi
->psp
);
2332 static int ni_convert_power_level_to_smc(struct radeon_device
*rdev
,
2333 struct rv7xx_pl
*pl
,
2334 NISLANDS_SMC_HW_PERFORMANCE_LEVEL
*level
)
2336 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
2337 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
2338 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
2342 u32 tmp
= RREG32(DC_STUTTER_CNTL
);
2344 level
->gen2PCIE
= pi
->pcie_gen2
?
2345 ((pl
->flags
& ATOM_PPLIB_R600_FLAGS_PCIEGEN2
) ? 1 : 0) : 0;
2347 ret
= ni_populate_sclk_value(rdev
, pl
->sclk
, &level
->sclk
);
2352 if (pi
->mclk_stutter_mode_threshold
&&
2353 (pl
->mclk
<= pi
->mclk_stutter_mode_threshold
) &&
2354 !eg_pi
->uvd_enabled
&&
2355 (tmp
& DC_STUTTER_ENABLE_A
) &&
2356 (tmp
& DC_STUTTER_ENABLE_B
))
2357 level
->mcFlags
|= NISLANDS_SMC_MC_STUTTER_EN
;
2359 if (pi
->mem_gddr5
) {
2360 if (pl
->mclk
> pi
->mclk_edc_enable_threshold
)
2361 level
->mcFlags
|= NISLANDS_SMC_MC_EDC_RD_FLAG
;
2362 if (pl
->mclk
> eg_pi
->mclk_edc_wr_enable_threshold
)
2363 level
->mcFlags
|= NISLANDS_SMC_MC_EDC_WR_FLAG
;
2365 level
->strobeMode
= cypress_get_strobe_mode_settings(rdev
, pl
->mclk
);
2367 if (level
->strobeMode
& NISLANDS_SMC_STROBE_ENABLE
) {
2368 if (cypress_get_mclk_frequency_ratio(rdev
, pl
->mclk
, true) >=
2369 ((RREG32(MC_SEQ_MISC7
) >> 16) & 0xf))
2370 dll_state_on
= ((RREG32(MC_SEQ_MISC5
) >> 1) & 0x1) ? true : false;
2372 dll_state_on
= ((RREG32(MC_SEQ_MISC6
) >> 1) & 0x1) ? true : false;
2374 dll_state_on
= false;
2375 if (pl
->mclk
> ni_pi
->mclk_rtt_mode_threshold
)
2376 level
->mcFlags
|= NISLANDS_SMC_MC_RTT_ENABLE
;
2379 ret
= ni_populate_mclk_value(rdev
, pl
->sclk
, pl
->mclk
,
2381 (level
->strobeMode
& NISLANDS_SMC_STROBE_ENABLE
) != 0,
2384 ret
= ni_populate_mclk_value(rdev
, pl
->sclk
, pl
->mclk
, &level
->mclk
, 1, 1);
2389 ret
= ni_populate_voltage_value(rdev
, &eg_pi
->vddc_voltage_table
,
2390 pl
->vddc
, &level
->vddc
);
2394 ret
= ni_get_std_voltage_value(rdev
, &level
->vddc
, &std_vddc
);
2398 ni_populate_std_voltage_value(rdev
, std_vddc
,
2399 level
->vddc
.index
, &level
->std_vddc
);
2401 if (eg_pi
->vddci_control
) {
2402 ret
= ni_populate_voltage_value(rdev
, &eg_pi
->vddci_voltage_table
,
2403 pl
->vddci
, &level
->vddci
);
2408 ni_populate_mvdd_value(rdev
, pl
->mclk
, &level
->mvdd
);
2413 static int ni_populate_smc_t(struct radeon_device
*rdev
,
2414 struct radeon_ps
*radeon_state
,
2415 NISLANDS_SMC_SWSTATE
*smc_state
)
2417 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
2418 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
2419 struct ni_ps
*state
= ni_get_ps(radeon_state
);
2425 if (state
->performance_level_count
>= 9)
2428 if (state
->performance_level_count
< 2) {
2429 a_t
= CG_R(0xffff) | CG_L(0);
2430 smc_state
->levels
[0].aT
= cpu_to_be32(a_t
);
2434 smc_state
->levels
[0].aT
= cpu_to_be32(0);
2436 for (i
= 0; i
<= state
->performance_level_count
- 2; i
++) {
2437 if (eg_pi
->uvd_enabled
)
2438 ret
= r600_calculate_at(
2439 1000 * (i
* (eg_pi
->smu_uvd_hs
? 2 : 8) + 2),
2441 state
->performance_levels
[i
+ 1].sclk
,
2442 state
->performance_levels
[i
].sclk
,
2446 ret
= r600_calculate_at(
2449 state
->performance_levels
[i
+ 1].sclk
,
2450 state
->performance_levels
[i
].sclk
,
2455 t_h
= (i
+ 1) * 1000 - 50 * R600_AH_DFLT
;
2456 t_l
= (i
+ 1) * 1000 + 50 * R600_AH_DFLT
;
2459 a_t
= be32_to_cpu(smc_state
->levels
[i
].aT
) & ~CG_R_MASK
;
2460 a_t
|= CG_R(t_l
* pi
->bsp
/ 20000);
2461 smc_state
->levels
[i
].aT
= cpu_to_be32(a_t
);
2463 high_bsp
= (i
== state
->performance_level_count
- 2) ?
2466 a_t
= CG_R(0xffff) | CG_L(t_h
* high_bsp
/ 20000);
2467 smc_state
->levels
[i
+ 1].aT
= cpu_to_be32(a_t
);
2473 static int ni_populate_power_containment_values(struct radeon_device
*rdev
,
2474 struct radeon_ps
*radeon_state
,
2475 NISLANDS_SMC_SWSTATE
*smc_state
)
2477 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
2478 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
2479 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
2480 struct ni_ps
*state
= ni_get_ps(radeon_state
);
2487 u32 power_boost_limit
;
2490 if (ni_pi
->enable_power_containment
== false)
2493 if (state
->performance_level_count
== 0)
2496 if (smc_state
->levelCount
!= state
->performance_level_count
)
2499 ret
= ni_calculate_adjusted_tdp_limits(rdev
,
2501 rdev
->pm
.dpm
.tdp_adjustment
,
2507 power_boost_limit
= ni_calculate_power_boost_limit(rdev
, radeon_state
, near_tdp_limit
);
2509 ret
= rv770_write_smc_sram_dword(rdev
,
2510 pi
->state_table_start
+
2511 offsetof(NISLANDS_SMC_STATETABLE
, dpm2Params
) +
2512 offsetof(PP_NIslands_DPM2Parameters
, PowerBoostLimit
),
2513 ni_scale_power_for_smc(power_boost_limit
, ni_get_smc_power_scaling_factor(rdev
)),
2516 power_boost_limit
= 0;
2518 smc_state
->levels
[0].dpm2
.MaxPS
= 0;
2519 smc_state
->levels
[0].dpm2
.NearTDPDec
= 0;
2520 smc_state
->levels
[0].dpm2
.AboveSafeInc
= 0;
2521 smc_state
->levels
[0].dpm2
.BelowSafeInc
= 0;
2522 smc_state
->levels
[0].stateFlags
|= power_boost_limit
? PPSMC_STATEFLAG_POWERBOOST
: 0;
2524 for (i
= 1; i
< state
->performance_level_count
; i
++) {
2525 prev_sclk
= state
->performance_levels
[i
-1].sclk
;
2526 max_sclk
= state
->performance_levels
[i
].sclk
;
2527 max_ps_percent
= (i
!= (state
->performance_level_count
- 1)) ?
2528 NISLANDS_DPM2_MAXPS_PERCENT_M
: NISLANDS_DPM2_MAXPS_PERCENT_H
;
2530 if (max_sclk
< prev_sclk
)
2533 if ((max_ps_percent
== 0) || (prev_sclk
== max_sclk
) || eg_pi
->uvd_enabled
)
2534 min_sclk
= max_sclk
;
2536 min_sclk
= prev_sclk
;
2538 min_sclk
= (prev_sclk
* (u32
)max_ps_percent
) / 100;
2540 if (min_sclk
< state
->performance_levels
[0].sclk
)
2541 min_sclk
= state
->performance_levels
[0].sclk
;
2546 smc_state
->levels
[i
].dpm2
.MaxPS
=
2547 (u8
)((NISLANDS_DPM2_MAX_PULSE_SKIP
* (max_sclk
- min_sclk
)) / max_sclk
);
2548 smc_state
->levels
[i
].dpm2
.NearTDPDec
= NISLANDS_DPM2_NEAR_TDP_DEC
;
2549 smc_state
->levels
[i
].dpm2
.AboveSafeInc
= NISLANDS_DPM2_ABOVE_SAFE_INC
;
2550 smc_state
->levels
[i
].dpm2
.BelowSafeInc
= NISLANDS_DPM2_BELOW_SAFE_INC
;
2551 smc_state
->levels
[i
].stateFlags
|=
2552 ((i
!= (state
->performance_level_count
- 1)) && power_boost_limit
) ?
2553 PPSMC_STATEFLAG_POWERBOOST
: 0;
2559 static int ni_populate_sq_ramping_values(struct radeon_device
*rdev
,
2560 struct radeon_ps
*radeon_state
,
2561 NISLANDS_SMC_SWSTATE
*smc_state
)
2563 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
2564 struct ni_ps
*state
= ni_get_ps(radeon_state
);
2565 u32 sq_power_throttle
;
2566 u32 sq_power_throttle2
;
2567 bool enable_sq_ramping
= ni_pi
->enable_sq_ramping
;
2570 if (state
->performance_level_count
== 0)
2573 if (smc_state
->levelCount
!= state
->performance_level_count
)
2576 if (rdev
->pm
.dpm
.sq_ramping_threshold
== 0)
2579 if (NISLANDS_DPM2_SQ_RAMP_MAX_POWER
> (MAX_POWER_MASK
>> MAX_POWER_SHIFT
))
2580 enable_sq_ramping
= false;
2582 if (NISLANDS_DPM2_SQ_RAMP_MIN_POWER
> (MIN_POWER_MASK
>> MIN_POWER_SHIFT
))
2583 enable_sq_ramping
= false;
2585 if (NISLANDS_DPM2_SQ_RAMP_MAX_POWER_DELTA
> (MAX_POWER_DELTA_MASK
>> MAX_POWER_DELTA_SHIFT
))
2586 enable_sq_ramping
= false;
2588 if (NISLANDS_DPM2_SQ_RAMP_STI_SIZE
> (STI_SIZE_MASK
>> STI_SIZE_SHIFT
))
2589 enable_sq_ramping
= false;
2591 if (NISLANDS_DPM2_SQ_RAMP_LTI_RATIO
<= (LTI_RATIO_MASK
>> LTI_RATIO_SHIFT
))
2592 enable_sq_ramping
= false;
2594 for (i
= 0; i
< state
->performance_level_count
; i
++) {
2595 sq_power_throttle
= 0;
2596 sq_power_throttle2
= 0;
2598 if ((state
->performance_levels
[i
].sclk
>= rdev
->pm
.dpm
.sq_ramping_threshold
) &&
2599 enable_sq_ramping
) {
2600 sq_power_throttle
|= MAX_POWER(NISLANDS_DPM2_SQ_RAMP_MAX_POWER
);
2601 sq_power_throttle
|= MIN_POWER(NISLANDS_DPM2_SQ_RAMP_MIN_POWER
);
2602 sq_power_throttle2
|= MAX_POWER_DELTA(NISLANDS_DPM2_SQ_RAMP_MAX_POWER_DELTA
);
2603 sq_power_throttle2
|= STI_SIZE(NISLANDS_DPM2_SQ_RAMP_STI_SIZE
);
2604 sq_power_throttle2
|= LTI_RATIO(NISLANDS_DPM2_SQ_RAMP_LTI_RATIO
);
2606 sq_power_throttle
|= MAX_POWER_MASK
| MIN_POWER_MASK
;
2607 sq_power_throttle2
|= MAX_POWER_DELTA_MASK
| STI_SIZE_MASK
| LTI_RATIO_MASK
;
2610 smc_state
->levels
[i
].SQPowerThrottle
= cpu_to_be32(sq_power_throttle
);
2611 smc_state
->levels
[i
].SQPowerThrottle_2
= cpu_to_be32(sq_power_throttle2
);
2617 static int ni_enable_power_containment(struct radeon_device
*rdev
,
2618 struct radeon_ps
*radeon_new_state
,
2621 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
2622 PPSMC_Result smc_result
;
2625 if (ni_pi
->enable_power_containment
) {
2627 if (!r600_is_uvd_state(radeon_new_state
->class, radeon_new_state
->class2
)) {
2628 smc_result
= rv770_send_msg_to_smc(rdev
, PPSMC_TDPClampingActive
);
2629 if (smc_result
!= PPSMC_Result_OK
) {
2631 ni_pi
->pc_enabled
= false;
2633 ni_pi
->pc_enabled
= true;
2637 smc_result
= rv770_send_msg_to_smc(rdev
, PPSMC_TDPClampingInactive
);
2638 if (smc_result
!= PPSMC_Result_OK
)
2640 ni_pi
->pc_enabled
= false;
2647 static int ni_convert_power_state_to_smc(struct radeon_device
*rdev
,
2648 struct radeon_ps
*radeon_state
,
2649 NISLANDS_SMC_SWSTATE
*smc_state
)
2651 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
2652 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
2653 struct ni_ps
*state
= ni_get_ps(radeon_state
);
2655 u32 threshold
= state
->performance_levels
[state
->performance_level_count
- 1].sclk
* 100 / 100;
2657 if (!(radeon_state
->caps
& ATOM_PPLIB_DISALLOW_ON_DC
))
2658 smc_state
->flags
|= PPSMC_SWSTATE_FLAG_DC
;
2660 smc_state
->levelCount
= 0;
2662 if (state
->performance_level_count
> NISLANDS_MAX_SMC_PERFORMANCE_LEVELS_PER_SWSTATE
)
2665 for (i
= 0; i
< state
->performance_level_count
; i
++) {
2666 ret
= ni_convert_power_level_to_smc(rdev
, &state
->performance_levels
[i
],
2667 &smc_state
->levels
[i
]);
2668 smc_state
->levels
[i
].arbRefreshState
=
2669 (u8
)(NISLANDS_DRIVER_STATE_ARB_INDEX
+ i
);
2674 if (ni_pi
->enable_power_containment
)
2675 smc_state
->levels
[i
].displayWatermark
=
2676 (state
->performance_levels
[i
].sclk
< threshold
) ?
2677 PPSMC_DISPLAY_WATERMARK_LOW
: PPSMC_DISPLAY_WATERMARK_HIGH
;
2679 smc_state
->levels
[i
].displayWatermark
= (i
< 2) ?
2680 PPSMC_DISPLAY_WATERMARK_LOW
: PPSMC_DISPLAY_WATERMARK_HIGH
;
2682 if (eg_pi
->dynamic_ac_timing
)
2683 smc_state
->levels
[i
].ACIndex
= NISLANDS_MCREGISTERTABLE_FIRST_DRIVERSTATE_SLOT
+ i
;
2685 smc_state
->levels
[i
].ACIndex
= 0;
2687 smc_state
->levelCount
++;
2690 rv770_write_smc_soft_register(rdev
, NI_SMC_SOFT_REGISTER_watermark_threshold
,
2691 cpu_to_be32(threshold
/ 512));
2693 ni_populate_smc_sp(rdev
, radeon_state
, smc_state
);
2695 ret
= ni_populate_power_containment_values(rdev
, radeon_state
, smc_state
);
2697 ni_pi
->enable_power_containment
= false;
2699 ret
= ni_populate_sq_ramping_values(rdev
, radeon_state
, smc_state
);
2701 ni_pi
->enable_sq_ramping
= false;
2703 return ni_populate_smc_t(rdev
, radeon_state
, smc_state
);
2706 static int ni_upload_sw_state(struct radeon_device
*rdev
,
2707 struct radeon_ps
*radeon_new_state
)
2709 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
2710 u16 address
= pi
->state_table_start
+
2711 offsetof(NISLANDS_SMC_STATETABLE
, driverState
);
2712 u16 state_size
= sizeof(NISLANDS_SMC_SWSTATE
) +
2713 ((NISLANDS_MAX_SMC_PERFORMANCE_LEVELS_PER_SWSTATE
- 1) * sizeof(NISLANDS_SMC_HW_PERFORMANCE_LEVEL
));
2715 NISLANDS_SMC_SWSTATE
*smc_state
= kzalloc(state_size
, GFP_KERNEL
);
2717 if (smc_state
== NULL
)
2720 ret
= ni_convert_power_state_to_smc(rdev
, radeon_new_state
, smc_state
);
2724 ret
= rv770_copy_bytes_to_smc(rdev
, address
, (u8
*)smc_state
, state_size
, pi
->sram_end
);
2732 static int ni_set_mc_special_registers(struct radeon_device
*rdev
,
2733 struct ni_mc_reg_table
*table
)
2735 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
2739 for (i
= 0, j
= table
->last
; i
< table
->last
; i
++) {
2740 switch (table
->mc_reg_address
[i
].s1
) {
2741 case MC_SEQ_MISC1
>> 2:
2742 if (j
>= SMC_NISLANDS_MC_REGISTER_ARRAY_SIZE
)
2744 temp_reg
= RREG32(MC_PMG_CMD_EMRS
);
2745 table
->mc_reg_address
[j
].s1
= MC_PMG_CMD_EMRS
>> 2;
2746 table
->mc_reg_address
[j
].s0
= MC_SEQ_PMG_CMD_EMRS_LP
>> 2;
2747 for (k
= 0; k
< table
->num_entries
; k
++)
2748 table
->mc_reg_table_entry
[k
].mc_data
[j
] =
2749 ((temp_reg
& 0xffff0000)) |
2750 ((table
->mc_reg_table_entry
[k
].mc_data
[i
] & 0xffff0000) >> 16);
2752 if (j
>= SMC_NISLANDS_MC_REGISTER_ARRAY_SIZE
)
2755 temp_reg
= RREG32(MC_PMG_CMD_MRS
);
2756 table
->mc_reg_address
[j
].s1
= MC_PMG_CMD_MRS
>> 2;
2757 table
->mc_reg_address
[j
].s0
= MC_SEQ_PMG_CMD_MRS_LP
>> 2;
2758 for(k
= 0; k
< table
->num_entries
; k
++) {
2759 table
->mc_reg_table_entry
[k
].mc_data
[j
] =
2760 (temp_reg
& 0xffff0000) |
2761 (table
->mc_reg_table_entry
[k
].mc_data
[i
] & 0x0000ffff);
2763 table
->mc_reg_table_entry
[k
].mc_data
[j
] |= 0x100;
2766 if (j
> SMC_NISLANDS_MC_REGISTER_ARRAY_SIZE
)
2769 case MC_SEQ_RESERVE_M
>> 2:
2770 temp_reg
= RREG32(MC_PMG_CMD_MRS1
);
2771 table
->mc_reg_address
[j
].s1
= MC_PMG_CMD_MRS1
>> 2;
2772 table
->mc_reg_address
[j
].s0
= MC_SEQ_PMG_CMD_MRS1_LP
>> 2;
2773 for (k
= 0; k
< table
->num_entries
; k
++)
2774 table
->mc_reg_table_entry
[k
].mc_data
[j
] =
2775 (temp_reg
& 0xffff0000) |
2776 (table
->mc_reg_table_entry
[k
].mc_data
[i
] & 0x0000ffff);
2778 if (j
> SMC_NISLANDS_MC_REGISTER_ARRAY_SIZE
)
2791 static bool ni_check_s0_mc_reg_index(u16 in_reg
, u16
*out_reg
)
2796 case MC_SEQ_RAS_TIMING
>> 2:
2797 *out_reg
= MC_SEQ_RAS_TIMING_LP
>> 2;
2799 case MC_SEQ_CAS_TIMING
>> 2:
2800 *out_reg
= MC_SEQ_CAS_TIMING_LP
>> 2;
2802 case MC_SEQ_MISC_TIMING
>> 2:
2803 *out_reg
= MC_SEQ_MISC_TIMING_LP
>> 2;
2805 case MC_SEQ_MISC_TIMING2
>> 2:
2806 *out_reg
= MC_SEQ_MISC_TIMING2_LP
>> 2;
2808 case MC_SEQ_RD_CTL_D0
>> 2:
2809 *out_reg
= MC_SEQ_RD_CTL_D0_LP
>> 2;
2811 case MC_SEQ_RD_CTL_D1
>> 2:
2812 *out_reg
= MC_SEQ_RD_CTL_D1_LP
>> 2;
2814 case MC_SEQ_WR_CTL_D0
>> 2:
2815 *out_reg
= MC_SEQ_WR_CTL_D0_LP
>> 2;
2817 case MC_SEQ_WR_CTL_D1
>> 2:
2818 *out_reg
= MC_SEQ_WR_CTL_D1_LP
>> 2;
2820 case MC_PMG_CMD_EMRS
>> 2:
2821 *out_reg
= MC_SEQ_PMG_CMD_EMRS_LP
>> 2;
2823 case MC_PMG_CMD_MRS
>> 2:
2824 *out_reg
= MC_SEQ_PMG_CMD_MRS_LP
>> 2;
2826 case MC_PMG_CMD_MRS1
>> 2:
2827 *out_reg
= MC_SEQ_PMG_CMD_MRS1_LP
>> 2;
2829 case MC_SEQ_PMG_TIMING
>> 2:
2830 *out_reg
= MC_SEQ_PMG_TIMING_LP
>> 2;
2832 case MC_PMG_CMD_MRS2
>> 2:
2833 *out_reg
= MC_SEQ_PMG_CMD_MRS2_LP
>> 2;
2843 static void ni_set_valid_flag(struct ni_mc_reg_table
*table
)
2847 for (i
= 0; i
< table
->last
; i
++) {
2848 for (j
= 1; j
< table
->num_entries
; j
++) {
2849 if (table
->mc_reg_table_entry
[j
-1].mc_data
[i
] != table
->mc_reg_table_entry
[j
].mc_data
[i
]) {
2850 table
->valid_flag
|= 1 << i
;
2857 static void ni_set_s0_mc_reg_index(struct ni_mc_reg_table
*table
)
2862 for (i
= 0; i
< table
->last
; i
++)
2863 table
->mc_reg_address
[i
].s0
=
2864 ni_check_s0_mc_reg_index(table
->mc_reg_address
[i
].s1
, &address
) ?
2865 address
: table
->mc_reg_address
[i
].s1
;
2868 static int ni_copy_vbios_mc_reg_table(struct atom_mc_reg_table
*table
,
2869 struct ni_mc_reg_table
*ni_table
)
2873 if (table
->last
> SMC_NISLANDS_MC_REGISTER_ARRAY_SIZE
)
2875 if (table
->num_entries
> MAX_AC_TIMING_ENTRIES
)
2878 for (i
= 0; i
< table
->last
; i
++)
2879 ni_table
->mc_reg_address
[i
].s1
= table
->mc_reg_address
[i
].s1
;
2880 ni_table
->last
= table
->last
;
2882 for (i
= 0; i
< table
->num_entries
; i
++) {
2883 ni_table
->mc_reg_table_entry
[i
].mclk_max
=
2884 table
->mc_reg_table_entry
[i
].mclk_max
;
2885 for (j
= 0; j
< table
->last
; j
++)
2886 ni_table
->mc_reg_table_entry
[i
].mc_data
[j
] =
2887 table
->mc_reg_table_entry
[i
].mc_data
[j
];
2889 ni_table
->num_entries
= table
->num_entries
;
2894 static int ni_initialize_mc_reg_table(struct radeon_device
*rdev
)
2896 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
2898 struct atom_mc_reg_table
*table
;
2899 struct ni_mc_reg_table
*ni_table
= &ni_pi
->mc_reg_table
;
2900 u8 module_index
= rv770_get_memory_module_index(rdev
);
2902 table
= kzalloc(sizeof(struct atom_mc_reg_table
), GFP_KERNEL
);
2906 WREG32(MC_SEQ_RAS_TIMING_LP
, RREG32(MC_SEQ_RAS_TIMING
));
2907 WREG32(MC_SEQ_CAS_TIMING_LP
, RREG32(MC_SEQ_CAS_TIMING
));
2908 WREG32(MC_SEQ_MISC_TIMING_LP
, RREG32(MC_SEQ_MISC_TIMING
));
2909 WREG32(MC_SEQ_MISC_TIMING2_LP
, RREG32(MC_SEQ_MISC_TIMING2
));
2910 WREG32(MC_SEQ_PMG_CMD_EMRS_LP
, RREG32(MC_PMG_CMD_EMRS
));
2911 WREG32(MC_SEQ_PMG_CMD_MRS_LP
, RREG32(MC_PMG_CMD_MRS
));
2912 WREG32(MC_SEQ_PMG_CMD_MRS1_LP
, RREG32(MC_PMG_CMD_MRS1
));
2913 WREG32(MC_SEQ_WR_CTL_D0_LP
, RREG32(MC_SEQ_WR_CTL_D0
));
2914 WREG32(MC_SEQ_WR_CTL_D1_LP
, RREG32(MC_SEQ_WR_CTL_D1
));
2915 WREG32(MC_SEQ_RD_CTL_D0_LP
, RREG32(MC_SEQ_RD_CTL_D0
));
2916 WREG32(MC_SEQ_RD_CTL_D1_LP
, RREG32(MC_SEQ_RD_CTL_D1
));
2917 WREG32(MC_SEQ_PMG_TIMING_LP
, RREG32(MC_SEQ_PMG_TIMING
));
2918 WREG32(MC_SEQ_PMG_CMD_MRS2_LP
, RREG32(MC_PMG_CMD_MRS2
));
2920 ret
= radeon_atom_init_mc_reg_table(rdev
, module_index
, table
);
2925 ret
= ni_copy_vbios_mc_reg_table(table
, ni_table
);
2930 ni_set_s0_mc_reg_index(ni_table
);
2932 ret
= ni_set_mc_special_registers(rdev
, ni_table
);
2937 ni_set_valid_flag(ni_table
);
2945 static void ni_populate_mc_reg_addresses(struct radeon_device
*rdev
,
2946 SMC_NIslands_MCRegisters
*mc_reg_table
)
2948 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
2951 for (i
= 0, j
= 0; j
< ni_pi
->mc_reg_table
.last
; j
++) {
2952 if (ni_pi
->mc_reg_table
.valid_flag
& (1 << j
)) {
2953 if (i
>= SMC_NISLANDS_MC_REGISTER_ARRAY_SIZE
)
2955 mc_reg_table
->address
[i
].s0
=
2956 cpu_to_be16(ni_pi
->mc_reg_table
.mc_reg_address
[j
].s0
);
2957 mc_reg_table
->address
[i
].s1
=
2958 cpu_to_be16(ni_pi
->mc_reg_table
.mc_reg_address
[j
].s1
);
2962 mc_reg_table
->last
= (u8
)i
;
2966 static void ni_convert_mc_registers(struct ni_mc_reg_entry
*entry
,
2967 SMC_NIslands_MCRegisterSet
*data
,
2968 u32 num_entries
, u32 valid_flag
)
2972 for (i
= 0, j
= 0; j
< num_entries
; j
++) {
2973 if (valid_flag
& (1 << j
)) {
2974 data
->value
[i
] = cpu_to_be32(entry
->mc_data
[j
]);
2980 static void ni_convert_mc_reg_table_entry_to_smc(struct radeon_device
*rdev
,
2981 struct rv7xx_pl
*pl
,
2982 SMC_NIslands_MCRegisterSet
*mc_reg_table_data
)
2984 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
2987 for (i
= 0; i
< ni_pi
->mc_reg_table
.num_entries
; i
++) {
2988 if (pl
->mclk
<= ni_pi
->mc_reg_table
.mc_reg_table_entry
[i
].mclk_max
)
2992 if ((i
== ni_pi
->mc_reg_table
.num_entries
) && (i
> 0))
2995 ni_convert_mc_registers(&ni_pi
->mc_reg_table
.mc_reg_table_entry
[i
],
2997 ni_pi
->mc_reg_table
.last
,
2998 ni_pi
->mc_reg_table
.valid_flag
);
3001 static void ni_convert_mc_reg_table_to_smc(struct radeon_device
*rdev
,
3002 struct radeon_ps
*radeon_state
,
3003 SMC_NIslands_MCRegisters
*mc_reg_table
)
3005 struct ni_ps
*state
= ni_get_ps(radeon_state
);
3008 for (i
= 0; i
< state
->performance_level_count
; i
++) {
3009 ni_convert_mc_reg_table_entry_to_smc(rdev
,
3010 &state
->performance_levels
[i
],
3011 &mc_reg_table
->data
[NISLANDS_MCREGISTERTABLE_FIRST_DRIVERSTATE_SLOT
+ i
]);
3015 static int ni_populate_mc_reg_table(struct radeon_device
*rdev
,
3016 struct radeon_ps
*radeon_boot_state
)
3018 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
3019 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
3020 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
3021 struct ni_ps
*boot_state
= ni_get_ps(radeon_boot_state
);
3022 SMC_NIslands_MCRegisters
*mc_reg_table
= &ni_pi
->smc_mc_reg_table
;
3024 memset(mc_reg_table
, 0, sizeof(SMC_NIslands_MCRegisters
));
3026 rv770_write_smc_soft_register(rdev
, NI_SMC_SOFT_REGISTER_seq_index
, 1);
3028 ni_populate_mc_reg_addresses(rdev
, mc_reg_table
);
3030 ni_convert_mc_reg_table_entry_to_smc(rdev
, &boot_state
->performance_levels
[0],
3031 &mc_reg_table
->data
[0]);
3033 ni_convert_mc_registers(&ni_pi
->mc_reg_table
.mc_reg_table_entry
[0],
3034 &mc_reg_table
->data
[1],
3035 ni_pi
->mc_reg_table
.last
,
3036 ni_pi
->mc_reg_table
.valid_flag
);
3038 ni_convert_mc_reg_table_to_smc(rdev
, radeon_boot_state
, mc_reg_table
);
3040 return rv770_copy_bytes_to_smc(rdev
, eg_pi
->mc_reg_table_start
,
3042 sizeof(SMC_NIslands_MCRegisters
),
3046 static int ni_upload_mc_reg_table(struct radeon_device
*rdev
,
3047 struct radeon_ps
*radeon_new_state
)
3049 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
3050 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
3051 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
3052 struct ni_ps
*ni_new_state
= ni_get_ps(radeon_new_state
);
3053 SMC_NIslands_MCRegisters
*mc_reg_table
= &ni_pi
->smc_mc_reg_table
;
3056 memset(mc_reg_table
, 0, sizeof(SMC_NIslands_MCRegisters
));
3058 ni_convert_mc_reg_table_to_smc(rdev
, radeon_new_state
, mc_reg_table
);
3060 address
= eg_pi
->mc_reg_table_start
+
3061 (u16
)offsetof(SMC_NIslands_MCRegisters
, data
[NISLANDS_MCREGISTERTABLE_FIRST_DRIVERSTATE_SLOT
]);
3063 return rv770_copy_bytes_to_smc(rdev
, address
,
3064 (u8
*)&mc_reg_table
->data
[NISLANDS_MCREGISTERTABLE_FIRST_DRIVERSTATE_SLOT
],
3065 sizeof(SMC_NIslands_MCRegisterSet
) * ni_new_state
->performance_level_count
,
3069 static int ni_init_driver_calculated_leakage_table(struct radeon_device
*rdev
,
3070 PP_NIslands_CACTABLES
*cac_tables
)
3072 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
3073 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
3075 unsigned int i
, j
, table_size
;
3077 u32 smc_leakage
, max_leakage
= 0;
3080 table_size
= eg_pi
->vddc_voltage_table
.count
;
3082 if (SMC_NISLANDS_LKGE_LUT_NUM_OF_VOLT_ENTRIES
< table_size
)
3083 table_size
= SMC_NISLANDS_LKGE_LUT_NUM_OF_VOLT_ENTRIES
;
3085 scaling_factor
= ni_get_smc_power_scaling_factor(rdev
);
3087 for (i
= 0; i
< SMC_NISLANDS_LKGE_LUT_NUM_OF_TEMP_ENTRIES
; i
++) {
3088 for (j
= 0; j
< table_size
; j
++) {
3089 t
= (1000 * ((i
+ 1) * 8));
3091 if (t
< ni_pi
->cac_data
.leakage_minimum_temperature
)
3092 t
= ni_pi
->cac_data
.leakage_minimum_temperature
;
3094 ni_calculate_leakage_for_v_and_t(rdev
,
3095 &ni_pi
->cac_data
.leakage_coefficients
,
3096 eg_pi
->vddc_voltage_table
.entries
[j
].value
,
3098 ni_pi
->cac_data
.i_leakage
,
3101 smc_leakage
= ni_scale_power_for_smc(leakage
, scaling_factor
) / 1000;
3102 if (smc_leakage
> max_leakage
)
3103 max_leakage
= smc_leakage
;
3105 cac_tables
->cac_lkge_lut
[i
][j
] = cpu_to_be32(smc_leakage
);
3109 for (j
= table_size
; j
< SMC_NISLANDS_LKGE_LUT_NUM_OF_VOLT_ENTRIES
; j
++) {
3110 for (i
= 0; i
< SMC_NISLANDS_LKGE_LUT_NUM_OF_TEMP_ENTRIES
; i
++)
3111 cac_tables
->cac_lkge_lut
[i
][j
] = cpu_to_be32(max_leakage
);
3116 static int ni_init_simplified_leakage_table(struct radeon_device
*rdev
,
3117 PP_NIslands_CACTABLES
*cac_tables
)
3119 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
3120 struct radeon_cac_leakage_table
*leakage_table
=
3121 &rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
;
3122 u32 i
, j
, table_size
;
3123 u32 smc_leakage
, max_leakage
= 0;
3129 table_size
= leakage_table
->count
;
3131 if (eg_pi
->vddc_voltage_table
.count
!= table_size
)
3132 table_size
= (eg_pi
->vddc_voltage_table
.count
< leakage_table
->count
) ?
3133 eg_pi
->vddc_voltage_table
.count
: leakage_table
->count
;
3135 if (SMC_NISLANDS_LKGE_LUT_NUM_OF_VOLT_ENTRIES
< table_size
)
3136 table_size
= SMC_NISLANDS_LKGE_LUT_NUM_OF_VOLT_ENTRIES
;
3138 if (table_size
== 0)
3141 scaling_factor
= ni_get_smc_power_scaling_factor(rdev
);
3143 for (j
= 0; j
< table_size
; j
++) {
3144 smc_leakage
= leakage_table
->entries
[j
].leakage
;
3146 if (smc_leakage
> max_leakage
)
3147 max_leakage
= smc_leakage
;
3149 for (i
= 0; i
< SMC_NISLANDS_LKGE_LUT_NUM_OF_TEMP_ENTRIES
; i
++)
3150 cac_tables
->cac_lkge_lut
[i
][j
] =
3151 cpu_to_be32(ni_scale_power_for_smc(smc_leakage
, scaling_factor
));
3154 for (j
= table_size
; j
< SMC_NISLANDS_LKGE_LUT_NUM_OF_VOLT_ENTRIES
; j
++) {
3155 for (i
= 0; i
< SMC_NISLANDS_LKGE_LUT_NUM_OF_TEMP_ENTRIES
; i
++)
3156 cac_tables
->cac_lkge_lut
[i
][j
] =
3157 cpu_to_be32(ni_scale_power_for_smc(max_leakage
, scaling_factor
));
3162 static int ni_initialize_smc_cac_tables(struct radeon_device
*rdev
)
3164 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
3165 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
3166 PP_NIslands_CACTABLES
*cac_tables
= NULL
;
3170 if (ni_pi
->enable_cac
== false)
3173 cac_tables
= kzalloc(sizeof(PP_NIslands_CACTABLES
), GFP_KERNEL
);
3177 reg
= RREG32(CG_CAC_CTRL
) & ~(TID_CNT_MASK
| TID_UNIT_MASK
);
3178 reg
|= (TID_CNT(ni_pi
->cac_weights
->tid_cnt
) |
3179 TID_UNIT(ni_pi
->cac_weights
->tid_unit
));
3180 WREG32(CG_CAC_CTRL
, reg
);
3182 for (i
= 0; i
< NISLANDS_DCCAC_MAX_LEVELS
; i
++)
3183 ni_pi
->dc_cac_table
[i
] = ni_pi
->cac_weights
->dc_cac
[i
];
3185 for (i
= 0; i
< SMC_NISLANDS_BIF_LUT_NUM_OF_ENTRIES
; i
++)
3186 cac_tables
->cac_bif_lut
[i
] = ni_pi
->cac_weights
->pcie_cac
[i
];
3188 ni_pi
->cac_data
.i_leakage
= rdev
->pm
.dpm
.cac_leakage
;
3189 ni_pi
->cac_data
.pwr_const
= 0;
3190 ni_pi
->cac_data
.dc_cac_value
= ni_pi
->dc_cac_table
[NISLANDS_DCCAC_LEVEL_0
];
3191 ni_pi
->cac_data
.bif_cac_value
= 0;
3192 ni_pi
->cac_data
.mc_wr_weight
= ni_pi
->cac_weights
->mc_write_weight
;
3193 ni_pi
->cac_data
.mc_rd_weight
= ni_pi
->cac_weights
->mc_read_weight
;
3194 ni_pi
->cac_data
.allow_ovrflw
= 0;
3195 ni_pi
->cac_data
.l2num_win_tdp
= ni_pi
->lta_window_size
;
3196 ni_pi
->cac_data
.num_win_tdp
= 0;
3197 ni_pi
->cac_data
.lts_truncate_n
= ni_pi
->lts_truncate
;
3199 if (ni_pi
->driver_calculate_cac_leakage
)
3200 ret
= ni_init_driver_calculated_leakage_table(rdev
, cac_tables
);
3202 ret
= ni_init_simplified_leakage_table(rdev
, cac_tables
);
3207 cac_tables
->pwr_const
= cpu_to_be32(ni_pi
->cac_data
.pwr_const
);
3208 cac_tables
->dc_cacValue
= cpu_to_be32(ni_pi
->cac_data
.dc_cac_value
);
3209 cac_tables
->bif_cacValue
= cpu_to_be32(ni_pi
->cac_data
.bif_cac_value
);
3210 cac_tables
->AllowOvrflw
= ni_pi
->cac_data
.allow_ovrflw
;
3211 cac_tables
->MCWrWeight
= ni_pi
->cac_data
.mc_wr_weight
;
3212 cac_tables
->MCRdWeight
= ni_pi
->cac_data
.mc_rd_weight
;
3213 cac_tables
->numWin_TDP
= ni_pi
->cac_data
.num_win_tdp
;
3214 cac_tables
->l2numWin_TDP
= ni_pi
->cac_data
.l2num_win_tdp
;
3215 cac_tables
->lts_truncate_n
= ni_pi
->cac_data
.lts_truncate_n
;
3217 ret
= rv770_copy_bytes_to_smc(rdev
, ni_pi
->cac_table_start
, (u8
*)cac_tables
,
3218 sizeof(PP_NIslands_CACTABLES
), pi
->sram_end
);
3222 ni_pi
->enable_cac
= false;
3223 ni_pi
->enable_power_containment
= false;
3231 static int ni_initialize_hardware_cac_manager(struct radeon_device
*rdev
)
3233 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
3236 if (!ni_pi
->enable_cac
||
3237 !ni_pi
->cac_configuration_required
)
3240 if (ni_pi
->cac_weights
== NULL
)
3243 reg
= RREG32_CG(CG_CAC_REGION_1_WEIGHT_0
) & ~(WEIGHT_TCP_SIG0_MASK
|
3244 WEIGHT_TCP_SIG1_MASK
|
3245 WEIGHT_TA_SIG_MASK
);
3246 reg
|= (WEIGHT_TCP_SIG0(ni_pi
->cac_weights
->weight_tcp_sig0
) |
3247 WEIGHT_TCP_SIG1(ni_pi
->cac_weights
->weight_tcp_sig1
) |
3248 WEIGHT_TA_SIG(ni_pi
->cac_weights
->weight_ta_sig
));
3249 WREG32_CG(CG_CAC_REGION_1_WEIGHT_0
, reg
);
3251 reg
= RREG32_CG(CG_CAC_REGION_1_WEIGHT_1
) & ~(WEIGHT_TCC_EN0_MASK
|
3252 WEIGHT_TCC_EN1_MASK
|
3253 WEIGHT_TCC_EN2_MASK
);
3254 reg
|= (WEIGHT_TCC_EN0(ni_pi
->cac_weights
->weight_tcc_en0
) |
3255 WEIGHT_TCC_EN1(ni_pi
->cac_weights
->weight_tcc_en1
) |
3256 WEIGHT_TCC_EN2(ni_pi
->cac_weights
->weight_tcc_en2
));
3257 WREG32_CG(CG_CAC_REGION_1_WEIGHT_1
, reg
);
3259 reg
= RREG32_CG(CG_CAC_REGION_2_WEIGHT_0
) & ~(WEIGHT_CB_EN0_MASK
|
3260 WEIGHT_CB_EN1_MASK
|
3261 WEIGHT_CB_EN2_MASK
|
3262 WEIGHT_CB_EN3_MASK
);
3263 reg
|= (WEIGHT_CB_EN0(ni_pi
->cac_weights
->weight_cb_en0
) |
3264 WEIGHT_CB_EN1(ni_pi
->cac_weights
->weight_cb_en1
) |
3265 WEIGHT_CB_EN2(ni_pi
->cac_weights
->weight_cb_en2
) |
3266 WEIGHT_CB_EN3(ni_pi
->cac_weights
->weight_cb_en3
));
3267 WREG32_CG(CG_CAC_REGION_2_WEIGHT_0
, reg
);
3269 reg
= RREG32_CG(CG_CAC_REGION_2_WEIGHT_1
) & ~(WEIGHT_DB_SIG0_MASK
|
3270 WEIGHT_DB_SIG1_MASK
|
3271 WEIGHT_DB_SIG2_MASK
|
3272 WEIGHT_DB_SIG3_MASK
);
3273 reg
|= (WEIGHT_DB_SIG0(ni_pi
->cac_weights
->weight_db_sig0
) |
3274 WEIGHT_DB_SIG1(ni_pi
->cac_weights
->weight_db_sig1
) |
3275 WEIGHT_DB_SIG2(ni_pi
->cac_weights
->weight_db_sig2
) |
3276 WEIGHT_DB_SIG3(ni_pi
->cac_weights
->weight_db_sig3
));
3277 WREG32_CG(CG_CAC_REGION_2_WEIGHT_1
, reg
);
3279 reg
= RREG32_CG(CG_CAC_REGION_2_WEIGHT_2
) & ~(WEIGHT_SXM_SIG0_MASK
|
3280 WEIGHT_SXM_SIG1_MASK
|
3281 WEIGHT_SXM_SIG2_MASK
|
3282 WEIGHT_SXS_SIG0_MASK
|
3283 WEIGHT_SXS_SIG1_MASK
);
3284 reg
|= (WEIGHT_SXM_SIG0(ni_pi
->cac_weights
->weight_sxm_sig0
) |
3285 WEIGHT_SXM_SIG1(ni_pi
->cac_weights
->weight_sxm_sig1
) |
3286 WEIGHT_SXM_SIG2(ni_pi
->cac_weights
->weight_sxm_sig2
) |
3287 WEIGHT_SXS_SIG0(ni_pi
->cac_weights
->weight_sxs_sig0
) |
3288 WEIGHT_SXS_SIG1(ni_pi
->cac_weights
->weight_sxs_sig1
));
3289 WREG32_CG(CG_CAC_REGION_2_WEIGHT_2
, reg
);
3291 reg
= RREG32_CG(CG_CAC_REGION_3_WEIGHT_0
) & ~(WEIGHT_XBR_0_MASK
|
3294 WEIGHT_SPI_SIG0_MASK
);
3295 reg
|= (WEIGHT_XBR_0(ni_pi
->cac_weights
->weight_xbr_0
) |
3296 WEIGHT_XBR_1(ni_pi
->cac_weights
->weight_xbr_1
) |
3297 WEIGHT_XBR_2(ni_pi
->cac_weights
->weight_xbr_2
) |
3298 WEIGHT_SPI_SIG0(ni_pi
->cac_weights
->weight_spi_sig0
));
3299 WREG32_CG(CG_CAC_REGION_3_WEIGHT_0
, reg
);
3301 reg
= RREG32_CG(CG_CAC_REGION_3_WEIGHT_1
) & ~(WEIGHT_SPI_SIG1_MASK
|
3302 WEIGHT_SPI_SIG2_MASK
|
3303 WEIGHT_SPI_SIG3_MASK
|
3304 WEIGHT_SPI_SIG4_MASK
|
3305 WEIGHT_SPI_SIG5_MASK
);
3306 reg
|= (WEIGHT_SPI_SIG1(ni_pi
->cac_weights
->weight_spi_sig1
) |
3307 WEIGHT_SPI_SIG2(ni_pi
->cac_weights
->weight_spi_sig2
) |
3308 WEIGHT_SPI_SIG3(ni_pi
->cac_weights
->weight_spi_sig3
) |
3309 WEIGHT_SPI_SIG4(ni_pi
->cac_weights
->weight_spi_sig4
) |
3310 WEIGHT_SPI_SIG5(ni_pi
->cac_weights
->weight_spi_sig5
));
3311 WREG32_CG(CG_CAC_REGION_3_WEIGHT_1
, reg
);
3313 reg
= RREG32_CG(CG_CAC_REGION_4_WEIGHT_0
) & ~(WEIGHT_LDS_SIG0_MASK
|
3314 WEIGHT_LDS_SIG1_MASK
|
3316 reg
|= (WEIGHT_LDS_SIG0(ni_pi
->cac_weights
->weight_lds_sig0
) |
3317 WEIGHT_LDS_SIG1(ni_pi
->cac_weights
->weight_lds_sig1
) |
3318 WEIGHT_SC(ni_pi
->cac_weights
->weight_sc
));
3319 WREG32_CG(CG_CAC_REGION_4_WEIGHT_0
, reg
);
3321 reg
= RREG32_CG(CG_CAC_REGION_4_WEIGHT_1
) & ~(WEIGHT_BIF_MASK
|
3323 WEIGHT_PA_SIG0_MASK
|
3324 WEIGHT_PA_SIG1_MASK
|
3325 WEIGHT_VGT_SIG0_MASK
);
3326 reg
|= (WEIGHT_BIF(ni_pi
->cac_weights
->weight_bif
) |
3327 WEIGHT_CP(ni_pi
->cac_weights
->weight_cp
) |
3328 WEIGHT_PA_SIG0(ni_pi
->cac_weights
->weight_pa_sig0
) |
3329 WEIGHT_PA_SIG1(ni_pi
->cac_weights
->weight_pa_sig1
) |
3330 WEIGHT_VGT_SIG0(ni_pi
->cac_weights
->weight_vgt_sig0
));
3331 WREG32_CG(CG_CAC_REGION_4_WEIGHT_1
, reg
);
3333 reg
= RREG32_CG(CG_CAC_REGION_4_WEIGHT_2
) & ~(WEIGHT_VGT_SIG1_MASK
|
3334 WEIGHT_VGT_SIG2_MASK
|
3335 WEIGHT_DC_SIG0_MASK
|
3336 WEIGHT_DC_SIG1_MASK
|
3337 WEIGHT_DC_SIG2_MASK
);
3338 reg
|= (WEIGHT_VGT_SIG1(ni_pi
->cac_weights
->weight_vgt_sig1
) |
3339 WEIGHT_VGT_SIG2(ni_pi
->cac_weights
->weight_vgt_sig2
) |
3340 WEIGHT_DC_SIG0(ni_pi
->cac_weights
->weight_dc_sig0
) |
3341 WEIGHT_DC_SIG1(ni_pi
->cac_weights
->weight_dc_sig1
) |
3342 WEIGHT_DC_SIG2(ni_pi
->cac_weights
->weight_dc_sig2
));
3343 WREG32_CG(CG_CAC_REGION_4_WEIGHT_2
, reg
);
3345 reg
= RREG32_CG(CG_CAC_REGION_4_WEIGHT_3
) & ~(WEIGHT_DC_SIG3_MASK
|
3346 WEIGHT_UVD_SIG0_MASK
|
3347 WEIGHT_UVD_SIG1_MASK
|
3348 WEIGHT_SPARE0_MASK
|
3349 WEIGHT_SPARE1_MASK
);
3350 reg
|= (WEIGHT_DC_SIG3(ni_pi
->cac_weights
->weight_dc_sig3
) |
3351 WEIGHT_UVD_SIG0(ni_pi
->cac_weights
->weight_uvd_sig0
) |
3352 WEIGHT_UVD_SIG1(ni_pi
->cac_weights
->weight_uvd_sig1
) |
3353 WEIGHT_SPARE0(ni_pi
->cac_weights
->weight_spare0
) |
3354 WEIGHT_SPARE1(ni_pi
->cac_weights
->weight_spare1
));
3355 WREG32_CG(CG_CAC_REGION_4_WEIGHT_3
, reg
);
3357 reg
= RREG32_CG(CG_CAC_REGION_5_WEIGHT_0
) & ~(WEIGHT_SQ_VSP_MASK
|
3358 WEIGHT_SQ_VSP0_MASK
);
3359 reg
|= (WEIGHT_SQ_VSP(ni_pi
->cac_weights
->weight_sq_vsp
) |
3360 WEIGHT_SQ_VSP0(ni_pi
->cac_weights
->weight_sq_vsp0
));
3361 WREG32_CG(CG_CAC_REGION_5_WEIGHT_0
, reg
);
3363 reg
= RREG32_CG(CG_CAC_REGION_5_WEIGHT_1
) & ~(WEIGHT_SQ_GPR_MASK
);
3364 reg
|= WEIGHT_SQ_GPR(ni_pi
->cac_weights
->weight_sq_gpr
);
3365 WREG32_CG(CG_CAC_REGION_5_WEIGHT_1
, reg
);
3367 reg
= RREG32_CG(CG_CAC_REGION_4_OVERRIDE_4
) & ~(OVR_MODE_SPARE_0_MASK
|
3368 OVR_VAL_SPARE_0_MASK
|
3369 OVR_MODE_SPARE_1_MASK
|
3370 OVR_VAL_SPARE_1_MASK
);
3371 reg
|= (OVR_MODE_SPARE_0(ni_pi
->cac_weights
->ovr_mode_spare_0
) |
3372 OVR_VAL_SPARE_0(ni_pi
->cac_weights
->ovr_val_spare_0
) |
3373 OVR_MODE_SPARE_1(ni_pi
->cac_weights
->ovr_mode_spare_1
) |
3374 OVR_VAL_SPARE_1(ni_pi
->cac_weights
->ovr_val_spare_1
));
3375 WREG32_CG(CG_CAC_REGION_4_OVERRIDE_4
, reg
);
3377 reg
= RREG32(SQ_CAC_THRESHOLD
) & ~(VSP_MASK
|
3380 reg
|= (VSP(ni_pi
->cac_weights
->vsp
) |
3381 VSP0(ni_pi
->cac_weights
->vsp0
) |
3382 GPR(ni_pi
->cac_weights
->gpr
));
3383 WREG32(SQ_CAC_THRESHOLD
, reg
);
3385 reg
= (MCDW_WR_ENABLE
|
3390 WREG32(MC_CG_CONFIG
, reg
);
3392 reg
= (READ_WEIGHT(ni_pi
->cac_weights
->mc_read_weight
) |
3393 WRITE_WEIGHT(ni_pi
->cac_weights
->mc_write_weight
) |
3395 WREG32(MC_CG_DATAPORT
, reg
);
3400 static int ni_enable_smc_cac(struct radeon_device
*rdev
,
3401 struct radeon_ps
*radeon_new_state
,
3404 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
3406 PPSMC_Result smc_result
;
3408 if (ni_pi
->enable_cac
) {
3410 if (!r600_is_uvd_state(radeon_new_state
->class, radeon_new_state
->class2
)) {
3411 smc_result
= rv770_send_msg_to_smc(rdev
, PPSMC_MSG_CollectCAC_PowerCorreln
);
3413 if (ni_pi
->support_cac_long_term_average
) {
3414 smc_result
= rv770_send_msg_to_smc(rdev
, PPSMC_CACLongTermAvgEnable
);
3415 if (PPSMC_Result_OK
!= smc_result
)
3416 ni_pi
->support_cac_long_term_average
= false;
3419 smc_result
= rv770_send_msg_to_smc(rdev
, PPSMC_MSG_EnableCac
);
3420 if (PPSMC_Result_OK
!= smc_result
)
3423 ni_pi
->cac_enabled
= (PPSMC_Result_OK
== smc_result
) ? true : false;
3425 } else if (ni_pi
->cac_enabled
) {
3426 smc_result
= rv770_send_msg_to_smc(rdev
, PPSMC_MSG_DisableCac
);
3428 ni_pi
->cac_enabled
= false;
3430 if (ni_pi
->support_cac_long_term_average
) {
3431 smc_result
= rv770_send_msg_to_smc(rdev
, PPSMC_CACLongTermAvgDisable
);
3432 if (PPSMC_Result_OK
!= smc_result
)
3433 ni_pi
->support_cac_long_term_average
= false;
3441 static int ni_pcie_performance_request(struct radeon_device
*rdev
,
3442 u8 perf_req
, bool advertise
)
3444 #if defined(CONFIG_ACPI)
3445 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
3447 if ((perf_req
== PCIE_PERF_REQ_PECI_GEN1
) ||
3448 (perf_req
== PCIE_PERF_REQ_PECI_GEN2
)) {
3449 if (eg_pi
->pcie_performance_request_registered
== false)
3450 radeon_acpi_pcie_notify_device_ready(rdev
);
3451 eg_pi
->pcie_performance_request_registered
= true;
3452 return radeon_acpi_pcie_performance_request(rdev
, perf_req
, advertise
);
3453 } else if ((perf_req
== PCIE_PERF_REQ_REMOVE_REGISTRY
) &&
3454 eg_pi
->pcie_performance_request_registered
) {
3455 eg_pi
->pcie_performance_request_registered
= false;
3456 return radeon_acpi_pcie_performance_request(rdev
, perf_req
, advertise
);
3462 static int ni_advertise_gen2_capability(struct radeon_device
*rdev
)
3464 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
3467 tmp
= RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL
);
3469 if ((tmp
& LC_OTHER_SIDE_EVER_SENT_GEN2
) &&
3470 (tmp
& LC_OTHER_SIDE_SUPPORTS_GEN2
))
3471 pi
->pcie_gen2
= true;
3473 pi
->pcie_gen2
= false;
3476 ni_pcie_performance_request(rdev
, PCIE_PERF_REQ_PECI_GEN2
, true);
3481 static void ni_enable_bif_dynamic_pcie_gen2(struct radeon_device
*rdev
,
3484 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
3487 tmp
= RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL
);
3489 if ((tmp
& LC_OTHER_SIDE_EVER_SENT_GEN2
) &&
3490 (tmp
& LC_OTHER_SIDE_SUPPORTS_GEN2
)) {
3492 if (!pi
->boot_in_gen2
) {
3493 bif
= RREG32(CG_BIF_REQ_AND_RSP
) & ~CG_CLIENT_REQ_MASK
;
3494 bif
|= CG_CLIENT_REQ(0xd);
3495 WREG32(CG_BIF_REQ_AND_RSP
, bif
);
3497 tmp
&= ~LC_HW_VOLTAGE_IF_CONTROL_MASK
;
3498 tmp
|= LC_HW_VOLTAGE_IF_CONTROL(1);
3499 tmp
|= LC_GEN2_EN_STRAP
;
3501 tmp
|= LC_CLR_FAILED_SPD_CHANGE_CNT
;
3502 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL
, tmp
);
3504 tmp
&= ~LC_CLR_FAILED_SPD_CHANGE_CNT
;
3505 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL
, tmp
);
3507 if (!pi
->boot_in_gen2
) {
3508 bif
= RREG32(CG_BIF_REQ_AND_RSP
) & ~CG_CLIENT_REQ_MASK
;
3509 bif
|= CG_CLIENT_REQ(0xd);
3510 WREG32(CG_BIF_REQ_AND_RSP
, bif
);
3512 tmp
&= ~LC_HW_VOLTAGE_IF_CONTROL_MASK
;
3513 tmp
&= ~LC_GEN2_EN_STRAP
;
3515 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL
, tmp
);
3520 static void ni_enable_dynamic_pcie_gen2(struct radeon_device
*rdev
,
3523 ni_enable_bif_dynamic_pcie_gen2(rdev
, enable
);
3526 WREG32_P(GENERAL_PWRMGT
, ENABLE_GEN2PCIE
, ~ENABLE_GEN2PCIE
);
3528 WREG32_P(GENERAL_PWRMGT
, 0, ~ENABLE_GEN2PCIE
);
3531 void ni_set_uvd_clock_before_set_eng_clock(struct radeon_device
*rdev
,
3532 struct radeon_ps
*new_ps
,
3533 struct radeon_ps
*old_ps
)
3535 struct ni_ps
*new_state
= ni_get_ps(new_ps
);
3536 struct ni_ps
*current_state
= ni_get_ps(old_ps
);
3538 if ((new_ps
->vclk
== old_ps
->vclk
) &&
3539 (new_ps
->dclk
== old_ps
->dclk
))
3542 if (new_state
->performance_levels
[new_state
->performance_level_count
- 1].sclk
>=
3543 current_state
->performance_levels
[current_state
->performance_level_count
- 1].sclk
)
3546 radeon_set_uvd_clocks(rdev
, new_ps
->vclk
, new_ps
->dclk
);
3549 void ni_set_uvd_clock_after_set_eng_clock(struct radeon_device
*rdev
,
3550 struct radeon_ps
*new_ps
,
3551 struct radeon_ps
*old_ps
)
3553 struct ni_ps
*new_state
= ni_get_ps(new_ps
);
3554 struct ni_ps
*current_state
= ni_get_ps(old_ps
);
3556 if ((new_ps
->vclk
== old_ps
->vclk
) &&
3557 (new_ps
->dclk
== old_ps
->dclk
))
3560 if (new_state
->performance_levels
[new_state
->performance_level_count
- 1].sclk
<
3561 current_state
->performance_levels
[current_state
->performance_level_count
- 1].sclk
)
3564 radeon_set_uvd_clocks(rdev
, new_ps
->vclk
, new_ps
->dclk
);
3567 void ni_dpm_setup_asic(struct radeon_device
*rdev
)
3569 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
3572 r
= ni_mc_load_microcode(rdev
);
3574 DRM_ERROR("Failed to load MC firmware!\n");
3575 ni_read_clock_registers(rdev
);
3576 btc_read_arb_registers(rdev
);
3577 rv770_get_memory_type(rdev
);
3578 if (eg_pi
->pcie_performance_request
)
3579 ni_advertise_gen2_capability(rdev
);
3580 rv770_get_pcie_gen2_status(rdev
);
3581 rv770_enable_acpi_pm(rdev
);
3584 void ni_update_current_ps(struct radeon_device
*rdev
,
3585 struct radeon_ps
*rps
)
3587 struct ni_ps
*new_ps
= ni_get_ps(rps
);
3588 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
3589 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
3591 eg_pi
->current_rps
= *rps
;
3592 ni_pi
->current_ps
= *new_ps
;
3593 eg_pi
->current_rps
.ps_priv
= &ni_pi
->current_ps
;
3596 void ni_update_requested_ps(struct radeon_device
*rdev
,
3597 struct radeon_ps
*rps
)
3599 struct ni_ps
*new_ps
= ni_get_ps(rps
);
3600 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
3601 struct ni_power_info
*ni_pi
= ni_get_pi(rdev
);
3603 eg_pi
->requested_rps
= *rps
;
3604 ni_pi
->requested_ps
= *new_ps
;
3605 eg_pi
->requested_rps
.ps_priv
= &ni_pi
->requested_ps
;
3608 int ni_dpm_enable(struct radeon_device
*rdev
)
3610 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
3611 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
3612 struct radeon_ps
*boot_ps
= rdev
->pm
.dpm
.boot_ps
;
3615 if (pi
->gfx_clock_gating
)
3616 ni_cg_clockgating_default(rdev
);
3617 if (btc_dpm_enabled(rdev
))
3619 if (pi
->mg_clock_gating
)
3620 ni_mg_clockgating_default(rdev
);
3621 if (eg_pi
->ls_clock_gating
)
3622 ni_ls_clockgating_default(rdev
);
3623 if (pi
->voltage_control
) {
3624 rv770_enable_voltage_control(rdev
, true);
3625 ret
= cypress_construct_voltage_tables(rdev
);
3627 DRM_ERROR("cypress_construct_voltage_tables failed\n");
3631 if (eg_pi
->dynamic_ac_timing
) {
3632 ret
= ni_initialize_mc_reg_table(rdev
);
3634 eg_pi
->dynamic_ac_timing
= false;
3637 cypress_enable_spread_spectrum(rdev
, true);
3638 if (pi
->thermal_protection
)
3639 rv770_enable_thermal_protection(rdev
, true);
3640 rv770_setup_bsp(rdev
);
3641 rv770_program_git(rdev
);
3642 rv770_program_tp(rdev
);
3643 rv770_program_tpp(rdev
);
3644 rv770_program_sstp(rdev
);
3645 cypress_enable_display_gap(rdev
);
3646 rv770_program_vc(rdev
);
3647 if (pi
->dynamic_pcie_gen2
)
3648 ni_enable_dynamic_pcie_gen2(rdev
, true);
3649 ret
= rv770_upload_firmware(rdev
);
3651 DRM_ERROR("rv770_upload_firmware failed\n");
3654 ret
= ni_process_firmware_header(rdev
);
3656 DRM_ERROR("ni_process_firmware_header failed\n");
3659 ret
= ni_initial_switch_from_arb_f0_to_f1(rdev
);
3661 DRM_ERROR("ni_initial_switch_from_arb_f0_to_f1 failed\n");
3664 ret
= ni_init_smc_table(rdev
);
3666 DRM_ERROR("ni_init_smc_table failed\n");
3669 ret
= ni_init_smc_spll_table(rdev
);
3671 DRM_ERROR("ni_init_smc_spll_table failed\n");
3674 ret
= ni_init_arb_table_index(rdev
);
3676 DRM_ERROR("ni_init_arb_table_index failed\n");
3679 if (eg_pi
->dynamic_ac_timing
) {
3680 ret
= ni_populate_mc_reg_table(rdev
, boot_ps
);
3682 DRM_ERROR("ni_populate_mc_reg_table failed\n");
3686 ret
= ni_initialize_smc_cac_tables(rdev
);
3688 DRM_ERROR("ni_initialize_smc_cac_tables failed\n");
3691 ret
= ni_initialize_hardware_cac_manager(rdev
);
3693 DRM_ERROR("ni_initialize_hardware_cac_manager failed\n");
3696 ret
= ni_populate_smc_tdp_limits(rdev
, boot_ps
);
3698 DRM_ERROR("ni_populate_smc_tdp_limits failed\n");
3701 ni_program_response_times(rdev
);
3702 r7xx_start_smc(rdev
);
3703 ret
= cypress_notify_smc_display_change(rdev
, false);
3705 DRM_ERROR("cypress_notify_smc_display_change failed\n");
3708 cypress_enable_sclk_control(rdev
, true);
3709 if (eg_pi
->memory_transition
)
3710 cypress_enable_mclk_control(rdev
, true);
3711 cypress_start_dpm(rdev
);
3712 if (pi
->gfx_clock_gating
)
3713 ni_gfx_clockgating_enable(rdev
, true);
3714 if (pi
->mg_clock_gating
)
3715 ni_mg_clockgating_enable(rdev
, true);
3716 if (eg_pi
->ls_clock_gating
)
3717 ni_ls_clockgating_enable(rdev
, true);
3719 rv770_enable_auto_throttle_source(rdev
, RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL
, true);
3721 ni_update_current_ps(rdev
, boot_ps
);
3726 void ni_dpm_disable(struct radeon_device
*rdev
)
3728 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
3729 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
3730 struct radeon_ps
*boot_ps
= rdev
->pm
.dpm
.boot_ps
;
3732 if (!btc_dpm_enabled(rdev
))
3734 rv770_clear_vc(rdev
);
3735 if (pi
->thermal_protection
)
3736 rv770_enable_thermal_protection(rdev
, false);
3737 ni_enable_power_containment(rdev
, boot_ps
, false);
3738 ni_enable_smc_cac(rdev
, boot_ps
, false);
3739 cypress_enable_spread_spectrum(rdev
, false);
3740 rv770_enable_auto_throttle_source(rdev
, RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL
, false);
3741 if (pi
->dynamic_pcie_gen2
)
3742 ni_enable_dynamic_pcie_gen2(rdev
, false);
3744 if (rdev
->irq
.installed
&&
3745 r600_is_internal_thermal_sensor(rdev
->pm
.int_thermal_type
)) {
3746 rdev
->irq
.dpm_thermal
= false;
3747 radeon_irq_set(rdev
);
3750 if (pi
->gfx_clock_gating
)
3751 ni_gfx_clockgating_enable(rdev
, false);
3752 if (pi
->mg_clock_gating
)
3753 ni_mg_clockgating_enable(rdev
, false);
3754 if (eg_pi
->ls_clock_gating
)
3755 ni_ls_clockgating_enable(rdev
, false);
3757 btc_reset_to_default(rdev
);
3759 ni_force_switch_to_arb_f0(rdev
);
3761 ni_update_current_ps(rdev
, boot_ps
);
3764 static int ni_power_control_set_level(struct radeon_device
*rdev
)
3766 struct radeon_ps
*new_ps
= rdev
->pm
.dpm
.requested_ps
;
3769 ret
= ni_restrict_performance_levels_before_switch(rdev
);
3772 ret
= rv770_halt_smc(rdev
);
3775 ret
= ni_populate_smc_tdp_limits(rdev
, new_ps
);
3778 ret
= rv770_resume_smc(rdev
);
3781 ret
= rv770_set_sw_state(rdev
);
3788 int ni_dpm_pre_set_power_state(struct radeon_device
*rdev
)
3790 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
3791 struct radeon_ps requested_ps
= *rdev
->pm
.dpm
.requested_ps
;
3792 struct radeon_ps
*new_ps
= &requested_ps
;
3794 ni_update_requested_ps(rdev
, new_ps
);
3796 ni_apply_state_adjust_rules(rdev
, &eg_pi
->requested_rps
);
3801 int ni_dpm_set_power_state(struct radeon_device
*rdev
)
3803 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
3804 struct radeon_ps
*new_ps
= &eg_pi
->requested_rps
;
3805 struct radeon_ps
*old_ps
= &eg_pi
->current_rps
;
3808 ret
= ni_restrict_performance_levels_before_switch(rdev
);
3810 DRM_ERROR("ni_restrict_performance_levels_before_switch failed\n");
3813 ni_set_uvd_clock_before_set_eng_clock(rdev
, new_ps
, old_ps
);
3814 ret
= ni_enable_power_containment(rdev
, new_ps
, false);
3816 DRM_ERROR("ni_enable_power_containment failed\n");
3819 ret
= ni_enable_smc_cac(rdev
, new_ps
, false);
3821 DRM_ERROR("ni_enable_smc_cac failed\n");
3824 ret
= rv770_halt_smc(rdev
);
3826 DRM_ERROR("rv770_halt_smc failed\n");
3829 if (eg_pi
->smu_uvd_hs
)
3830 btc_notify_uvd_to_smc(rdev
, new_ps
);
3831 ret
= ni_upload_sw_state(rdev
, new_ps
);
3833 DRM_ERROR("ni_upload_sw_state failed\n");
3836 if (eg_pi
->dynamic_ac_timing
) {
3837 ret
= ni_upload_mc_reg_table(rdev
, new_ps
);
3839 DRM_ERROR("ni_upload_mc_reg_table failed\n");
3843 ret
= ni_program_memory_timing_parameters(rdev
, new_ps
);
3845 DRM_ERROR("ni_program_memory_timing_parameters failed\n");
3848 ret
= rv770_resume_smc(rdev
);
3850 DRM_ERROR("rv770_resume_smc failed\n");
3853 ret
= rv770_set_sw_state(rdev
);
3855 DRM_ERROR("rv770_set_sw_state failed\n");
3858 ni_set_uvd_clock_after_set_eng_clock(rdev
, new_ps
, old_ps
);
3859 ret
= ni_enable_smc_cac(rdev
, new_ps
, true);
3861 DRM_ERROR("ni_enable_smc_cac failed\n");
3864 ret
= ni_enable_power_containment(rdev
, new_ps
, true);
3866 DRM_ERROR("ni_enable_power_containment failed\n");
3871 ret
= ni_power_control_set_level(rdev
);
3873 DRM_ERROR("ni_power_control_set_level failed\n");
3880 void ni_dpm_post_set_power_state(struct radeon_device
*rdev
)
3882 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
3883 struct radeon_ps
*new_ps
= &eg_pi
->requested_rps
;
3885 ni_update_current_ps(rdev
, new_ps
);
3888 void ni_dpm_reset_asic(struct radeon_device
*rdev
)
3890 ni_restrict_performance_levels_before_switch(rdev
);
3891 rv770_set_boot_state(rdev
);
3895 struct _ATOM_POWERPLAY_INFO info
;
3896 struct _ATOM_POWERPLAY_INFO_V2 info_2
;
3897 struct _ATOM_POWERPLAY_INFO_V3 info_3
;
3898 struct _ATOM_PPLIB_POWERPLAYTABLE pplib
;
3899 struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2
;
3900 struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3
;
3903 union pplib_clock_info
{
3904 struct _ATOM_PPLIB_R600_CLOCK_INFO r600
;
3905 struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780
;
3906 struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen
;
3907 struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo
;
3910 union pplib_power_state
{
3911 struct _ATOM_PPLIB_STATE v1
;
3912 struct _ATOM_PPLIB_STATE_V2 v2
;
3915 static void ni_parse_pplib_non_clock_info(struct radeon_device
*rdev
,
3916 struct radeon_ps
*rps
,
3917 struct _ATOM_PPLIB_NONCLOCK_INFO
*non_clock_info
,
3920 rps
->caps
= le32_to_cpu(non_clock_info
->ulCapsAndSettings
);
3921 rps
->class = le16_to_cpu(non_clock_info
->usClassification
);
3922 rps
->class2
= le16_to_cpu(non_clock_info
->usClassification2
);
3924 if (ATOM_PPLIB_NONCLOCKINFO_VER1
< table_rev
) {
3925 rps
->vclk
= le32_to_cpu(non_clock_info
->ulVCLK
);
3926 rps
->dclk
= le32_to_cpu(non_clock_info
->ulDCLK
);
3927 } else if (r600_is_uvd_state(rps
->class, rps
->class2
)) {
3928 rps
->vclk
= RV770_DEFAULT_VCLK_FREQ
;
3929 rps
->dclk
= RV770_DEFAULT_DCLK_FREQ
;
3935 if (rps
->class & ATOM_PPLIB_CLASSIFICATION_BOOT
)
3936 rdev
->pm
.dpm
.boot_ps
= rps
;
3937 if (rps
->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE
)
3938 rdev
->pm
.dpm
.uvd_ps
= rps
;
3941 static void ni_parse_pplib_clock_info(struct radeon_device
*rdev
,
3942 struct radeon_ps
*rps
, int index
,
3943 union pplib_clock_info
*clock_info
)
3945 struct rv7xx_power_info
*pi
= rv770_get_pi(rdev
);
3946 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
3947 struct ni_ps
*ps
= ni_get_ps(rps
);
3948 struct rv7xx_pl
*pl
= &ps
->performance_levels
[index
];
3950 ps
->performance_level_count
= index
+ 1;
3952 pl
->sclk
= le16_to_cpu(clock_info
->evergreen
.usEngineClockLow
);
3953 pl
->sclk
|= clock_info
->evergreen
.ucEngineClockHigh
<< 16;
3954 pl
->mclk
= le16_to_cpu(clock_info
->evergreen
.usMemoryClockLow
);
3955 pl
->mclk
|= clock_info
->evergreen
.ucMemoryClockHigh
<< 16;
3957 pl
->vddc
= le16_to_cpu(clock_info
->evergreen
.usVDDC
);
3958 pl
->vddci
= le16_to_cpu(clock_info
->evergreen
.usVDDCI
);
3959 pl
->flags
= le32_to_cpu(clock_info
->evergreen
.ulFlags
);
3961 /* patch up vddc if necessary */
3962 if (pl
->vddc
== 0xff01) {
3964 pl
->vddc
= pi
->max_vddc
;
3967 if (rps
->class & ATOM_PPLIB_CLASSIFICATION_ACPI
) {
3968 pi
->acpi_vddc
= pl
->vddc
;
3969 eg_pi
->acpi_vddci
= pl
->vddci
;
3970 if (ps
->performance_levels
[0].flags
& ATOM_PPLIB_R600_FLAGS_PCIEGEN2
)
3971 pi
->acpi_pcie_gen2
= true;
3973 pi
->acpi_pcie_gen2
= false;
3976 if (rps
->class2
& ATOM_PPLIB_CLASSIFICATION2_ULV
) {
3977 eg_pi
->ulv
.supported
= true;
3981 if (pi
->min_vddc_in_table
> pl
->vddc
)
3982 pi
->min_vddc_in_table
= pl
->vddc
;
3984 if (pi
->max_vddc_in_table
< pl
->vddc
)
3985 pi
->max_vddc_in_table
= pl
->vddc
;
3987 /* patch up boot state */
3988 if (rps
->class & ATOM_PPLIB_CLASSIFICATION_BOOT
) {
3989 u16 vddc
, vddci
, mvdd
;
3990 radeon_atombios_get_default_voltages(rdev
, &vddc
, &vddci
, &mvdd
);
3991 pl
->mclk
= rdev
->clock
.default_mclk
;
3992 pl
->sclk
= rdev
->clock
.default_sclk
;
3997 if ((rps
->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK
) ==
3998 ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE
) {
3999 rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
.sclk
= pl
->sclk
;
4000 rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
.mclk
= pl
->mclk
;
4001 rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
.vddc
= pl
->vddc
;
4002 rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
.vddci
= pl
->vddci
;
4006 static int ni_parse_power_table(struct radeon_device
*rdev
)
4008 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
4009 struct _ATOM_PPLIB_NONCLOCK_INFO
*non_clock_info
;
4010 union pplib_power_state
*power_state
;
4012 union pplib_clock_info
*clock_info
;
4013 union power_info
*power_info
;
4014 int index
= GetIndexIntoMasterTable(DATA
, PowerPlayInfo
);
4019 if (!atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
4020 &frev
, &crev
, &data_offset
))
4022 power_info
= (union power_info
*)(mode_info
->atom_context
->bios
+ data_offset
);
4024 rdev
->pm
.dpm
.ps
= kzalloc(sizeof(struct radeon_ps
) *
4025 power_info
->pplib
.ucNumStates
, GFP_KERNEL
);
4026 if (!rdev
->pm
.dpm
.ps
)
4028 rdev
->pm
.dpm
.platform_caps
= le32_to_cpu(power_info
->pplib
.ulPlatformCaps
);
4029 rdev
->pm
.dpm
.backbias_response_time
= le16_to_cpu(power_info
->pplib
.usBackbiasTime
);
4030 rdev
->pm
.dpm
.voltage_response_time
= le16_to_cpu(power_info
->pplib
.usVoltageTime
);
4032 for (i
= 0; i
< power_info
->pplib
.ucNumStates
; i
++) {
4033 power_state
= (union pplib_power_state
*)
4034 (mode_info
->atom_context
->bios
+ data_offset
+
4035 le16_to_cpu(power_info
->pplib
.usStateArrayOffset
) +
4036 i
* power_info
->pplib
.ucStateEntrySize
);
4037 non_clock_info
= (struct _ATOM_PPLIB_NONCLOCK_INFO
*)
4038 (mode_info
->atom_context
->bios
+ data_offset
+
4039 le16_to_cpu(power_info
->pplib
.usNonClockInfoArrayOffset
) +
4040 (power_state
->v1
.ucNonClockStateIndex
*
4041 power_info
->pplib
.ucNonClockSize
));
4042 if (power_info
->pplib
.ucStateEntrySize
- 1) {
4044 ps
= kzalloc(sizeof(struct ni_ps
), GFP_KERNEL
);
4046 kfree(rdev
->pm
.dpm
.ps
);
4049 rdev
->pm
.dpm
.ps
[i
].ps_priv
= ps
;
4050 ni_parse_pplib_non_clock_info(rdev
, &rdev
->pm
.dpm
.ps
[i
],
4052 power_info
->pplib
.ucNonClockSize
);
4053 idx
= (u8
*)&power_state
->v1
.ucClockStateIndices
[0];
4054 for (j
= 0; j
< (power_info
->pplib
.ucStateEntrySize
- 1); j
++) {
4055 clock_info
= (union pplib_clock_info
*)
4056 (mode_info
->atom_context
->bios
+ data_offset
+
4057 le16_to_cpu(power_info
->pplib
.usClockInfoArrayOffset
) +
4058 (idx
[j
] * power_info
->pplib
.ucClockInfoSize
));
4059 ni_parse_pplib_clock_info(rdev
,
4060 &rdev
->pm
.dpm
.ps
[i
], j
,
4065 rdev
->pm
.dpm
.num_ps
= power_info
->pplib
.ucNumStates
;
4069 int ni_dpm_init(struct radeon_device
*rdev
)
4071 struct rv7xx_power_info
*pi
;
4072 struct evergreen_power_info
*eg_pi
;
4073 struct ni_power_info
*ni_pi
;
4074 struct atom_clock_dividers dividers
;
4077 ni_pi
= kzalloc(sizeof(struct ni_power_info
), GFP_KERNEL
);
4080 rdev
->pm
.dpm
.priv
= ni_pi
;
4084 rv770_get_max_vddc(rdev
);
4086 eg_pi
->ulv
.supported
= false;
4088 eg_pi
->acpi_vddci
= 0;
4089 pi
->min_vddc_in_table
= 0;
4090 pi
->max_vddc_in_table
= 0;
4092 ret
= ni_parse_power_table(rdev
);
4095 ret
= r600_parse_extended_power_table(rdev
);
4099 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
=
4100 kzalloc(4 * sizeof(struct radeon_clock_voltage_dependency_entry
), GFP_KERNEL
);
4101 if (!rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
) {
4102 r600_free_extended_power_table(rdev
);
4105 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.count
= 4;
4106 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
[0].clk
= 0;
4107 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
[0].v
= 0;
4108 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
[1].clk
= 36000;
4109 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
[1].v
= 720;
4110 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
[2].clk
= 54000;
4111 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
[2].v
= 810;
4112 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
[3].clk
= 72000;
4113 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
[3].v
= 900;
4115 ni_patch_dependency_tables_based_on_leakage(rdev
);
4117 if (rdev
->pm
.dpm
.voltage_response_time
== 0)
4118 rdev
->pm
.dpm
.voltage_response_time
= R600_VOLTAGERESPONSETIME_DFLT
;
4119 if (rdev
->pm
.dpm
.backbias_response_time
== 0)
4120 rdev
->pm
.dpm
.backbias_response_time
= R600_BACKBIASRESPONSETIME_DFLT
;
4122 ret
= radeon_atom_get_clock_dividers(rdev
, COMPUTE_ENGINE_PLL_PARAM
,
4123 0, false, ÷rs
);
4125 pi
->ref_div
= dividers
.ref_div
+ 1;
4127 pi
->ref_div
= R600_REFERENCEDIVIDER_DFLT
;
4129 pi
->rlp
= RV770_RLP_DFLT
;
4130 pi
->rmp
= RV770_RMP_DFLT
;
4131 pi
->lhp
= RV770_LHP_DFLT
;
4132 pi
->lmp
= RV770_LMP_DFLT
;
4134 eg_pi
->ats
[0].rlp
= RV770_RLP_DFLT
;
4135 eg_pi
->ats
[0].rmp
= RV770_RMP_DFLT
;
4136 eg_pi
->ats
[0].lhp
= RV770_LHP_DFLT
;
4137 eg_pi
->ats
[0].lmp
= RV770_LMP_DFLT
;
4139 eg_pi
->ats
[1].rlp
= BTC_RLP_UVD_DFLT
;
4140 eg_pi
->ats
[1].rmp
= BTC_RMP_UVD_DFLT
;
4141 eg_pi
->ats
[1].lhp
= BTC_LHP_UVD_DFLT
;
4142 eg_pi
->ats
[1].lmp
= BTC_LMP_UVD_DFLT
;
4144 eg_pi
->smu_uvd_hs
= true;
4146 if (rdev
->pdev
->device
== 0x6707) {
4147 pi
->mclk_strobe_mode_threshold
= 55000;
4148 pi
->mclk_edc_enable_threshold
= 55000;
4149 eg_pi
->mclk_edc_wr_enable_threshold
= 55000;
4151 pi
->mclk_strobe_mode_threshold
= 40000;
4152 pi
->mclk_edc_enable_threshold
= 40000;
4153 eg_pi
->mclk_edc_wr_enable_threshold
= 40000;
4155 ni_pi
->mclk_rtt_mode_threshold
= eg_pi
->mclk_edc_wr_enable_threshold
;
4157 pi
->voltage_control
=
4158 radeon_atom_is_voltage_gpio(rdev
, SET_VOLTAGE_TYPE_ASIC_VDDC
, 0);
4161 radeon_atom_is_voltage_gpio(rdev
, SET_VOLTAGE_TYPE_ASIC_MVDDC
, 0);
4163 eg_pi
->vddci_control
=
4164 radeon_atom_is_voltage_gpio(rdev
, SET_VOLTAGE_TYPE_ASIC_VDDCI
, 0);
4166 rv770_get_engine_memory_ss(rdev
);
4168 pi
->asi
= RV770_ASI_DFLT
;
4169 pi
->pasi
= CYPRESS_HASI_DFLT
;
4170 pi
->vrc
= CYPRESS_VRC_DFLT
;
4172 pi
->power_gating
= false;
4174 pi
->gfx_clock_gating
= true;
4176 pi
->mg_clock_gating
= true;
4177 pi
->mgcgtssm
= true;
4178 eg_pi
->ls_clock_gating
= false;
4179 eg_pi
->sclk_deep_sleep
= false;
4181 pi
->dynamic_pcie_gen2
= true;
4183 if (rdev
->pm
.int_thermal_type
!= THERMAL_TYPE_NONE
)
4184 pi
->thermal_protection
= true;
4186 pi
->thermal_protection
= false;
4188 pi
->display_gap
= true;
4194 eg_pi
->dynamic_ac_timing
= true;
4197 eg_pi
->light_sleep
= true;
4198 eg_pi
->memory_transition
= true;
4199 #if defined(CONFIG_ACPI)
4200 eg_pi
->pcie_performance_request
=
4201 radeon_acpi_is_pcie_performance_request_supported(rdev
);
4203 eg_pi
->pcie_performance_request
= false;
4206 eg_pi
->dll_default_on
= false;
4208 eg_pi
->sclk_deep_sleep
= false;
4210 pi
->mclk_stutter_mode_threshold
= 0;
4212 pi
->sram_end
= SMC_RAM_END
;
4214 rdev
->pm
.dpm
.dyn_state
.mclk_sclk_ratio
= 3;
4215 rdev
->pm
.dpm
.dyn_state
.vddc_vddci_delta
= 200;
4216 rdev
->pm
.dpm
.dyn_state
.min_vddc_for_pcie_gen2
= 900;
4217 rdev
->pm
.dpm
.dyn_state
.valid_sclk_values
.count
= ARRAY_SIZE(btc_valid_sclk
);
4218 rdev
->pm
.dpm
.dyn_state
.valid_sclk_values
.values
= btc_valid_sclk
;
4219 rdev
->pm
.dpm
.dyn_state
.valid_mclk_values
.count
= 0;
4220 rdev
->pm
.dpm
.dyn_state
.valid_mclk_values
.values
= NULL
;
4221 rdev
->pm
.dpm
.dyn_state
.sclk_mclk_delta
= 12500;
4223 ni_pi
->cac_data
.leakage_coefficients
.at
= 516;
4224 ni_pi
->cac_data
.leakage_coefficients
.bt
= 18;
4225 ni_pi
->cac_data
.leakage_coefficients
.av
= 51;
4226 ni_pi
->cac_data
.leakage_coefficients
.bv
= 2957;
4228 switch (rdev
->pdev
->device
) {
4234 ni_pi
->cac_weights
= &cac_weights_cayman_xt
;
4241 ni_pi
->cac_weights
= &cac_weights_cayman_pro
;
4248 ni_pi
->cac_weights
= &cac_weights_cayman_le
;
4252 if (ni_pi
->cac_weights
->enable_power_containment_by_default
) {
4253 ni_pi
->enable_power_containment
= true;
4254 ni_pi
->enable_cac
= true;
4255 ni_pi
->enable_sq_ramping
= true;
4257 ni_pi
->enable_power_containment
= false;
4258 ni_pi
->enable_cac
= false;
4259 ni_pi
->enable_sq_ramping
= false;
4262 ni_pi
->driver_calculate_cac_leakage
= false;
4263 ni_pi
->cac_configuration_required
= true;
4265 if (ni_pi
->cac_configuration_required
) {
4266 ni_pi
->support_cac_long_term_average
= true;
4267 ni_pi
->lta_window_size
= ni_pi
->cac_weights
->l2_lta_window_size
;
4268 ni_pi
->lts_truncate
= ni_pi
->cac_weights
->lts_truncate
;
4270 ni_pi
->support_cac_long_term_average
= false;
4271 ni_pi
->lta_window_size
= 0;
4272 ni_pi
->lts_truncate
= 0;
4275 ni_pi
->use_power_boost_limit
= true;
4277 /* make sure dc limits are valid */
4278 if ((rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_dc
.sclk
== 0) ||
4279 (rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_dc
.mclk
== 0))
4280 rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_dc
=
4281 rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
;
4286 void ni_dpm_fini(struct radeon_device
*rdev
)
4290 for (i
= 0; i
< rdev
->pm
.dpm
.num_ps
; i
++) {
4291 kfree(rdev
->pm
.dpm
.ps
[i
].ps_priv
);
4293 kfree(rdev
->pm
.dpm
.ps
);
4294 kfree(rdev
->pm
.dpm
.priv
);
4295 kfree(rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
);
4296 r600_free_extended_power_table(rdev
);
4299 void ni_dpm_print_power_state(struct radeon_device
*rdev
,
4300 struct radeon_ps
*rps
)
4302 struct ni_ps
*ps
= ni_get_ps(rps
);
4303 struct rv7xx_pl
*pl
;
4306 r600_dpm_print_class_info(rps
->class, rps
->class2
);
4307 r600_dpm_print_cap_info(rps
->caps
);
4308 printk("\tuvd vclk: %d dclk: %d\n", rps
->vclk
, rps
->dclk
);
4309 for (i
= 0; i
< ps
->performance_level_count
; i
++) {
4310 pl
= &ps
->performance_levels
[i
];
4311 if (rdev
->family
>= CHIP_TAHITI
)
4312 printk("\t\tpower level %d sclk: %u mclk: %u vddc: %u vddci: %u pcie gen: %u\n",
4313 i
, pl
->sclk
, pl
->mclk
, pl
->vddc
, pl
->vddci
, pl
->pcie_gen
+ 1);
4315 printk("\t\tpower level %d sclk: %u mclk: %u vddc: %u vddci: %u\n",
4316 i
, pl
->sclk
, pl
->mclk
, pl
->vddc
, pl
->vddci
);
4318 r600_dpm_print_ps_status(rdev
, rps
);
4321 void ni_dpm_debugfs_print_current_performance_level(struct radeon_device
*rdev
,
4324 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
4325 struct radeon_ps
*rps
= &eg_pi
->current_rps
;
4326 struct ni_ps
*ps
= ni_get_ps(rps
);
4327 struct rv7xx_pl
*pl
;
4329 (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX
) & CURRENT_STATE_INDEX_MASK
) >>
4330 CURRENT_STATE_INDEX_SHIFT
;
4332 if (current_index
>= ps
->performance_level_count
) {
4333 seq_printf(m
, "invalid dpm profile %d\n", current_index
);
4335 pl
= &ps
->performance_levels
[current_index
];
4336 seq_printf(m
, "uvd vclk: %d dclk: %d\n", rps
->vclk
, rps
->dclk
);
4337 seq_printf(m
, "power level %d sclk: %u mclk: %u vddc: %u vddci: %u\n",
4338 current_index
, pl
->sclk
, pl
->mclk
, pl
->vddc
, pl
->vddci
);
4342 u32
ni_dpm_get_sclk(struct radeon_device
*rdev
, bool low
)
4344 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
4345 struct ni_ps
*requested_state
= ni_get_ps(&eg_pi
->requested_rps
);
4348 return requested_state
->performance_levels
[0].sclk
;
4350 return requested_state
->performance_levels
[requested_state
->performance_level_count
- 1].sclk
;
4353 u32
ni_dpm_get_mclk(struct radeon_device
*rdev
, bool low
)
4355 struct evergreen_power_info
*eg_pi
= evergreen_get_pi(rdev
);
4356 struct ni_ps
*requested_state
= ni_get_ps(&eg_pi
->requested_rps
);
4359 return requested_state
->performance_levels
[0].mclk
;
4361 return requested_state
->performance_levels
[requested_state
->performance_level_count
- 1].mclk
;