boost.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright 2013 Red Hat Inc.
  3. *
  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:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  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.
  21. *
  22. * Authors: Ben Skeggs
  23. */
  24. #include <subdev/bios.h>
  25. #include <subdev/bios/bit.h>
  26. #include <subdev/bios/boost.h>
  27. u32
  28. nvbios_boostTe(struct nvkm_bios *bios,
  29. u8 *ver, u8 *hdr, u8 *cnt, u8 *len, u8 *snr, u8 *ssz)
  30. {
  31. struct bit_entry bit_P;
  32. u32 boost = 0;
  33. if (!bit_entry(bios, 'P', &bit_P)) {
  34. if (bit_P.version == 2)
  35. boost = nvbios_rd32(bios, bit_P.offset + 0x30);
  36. if (boost) {
  37. *ver = nvbios_rd08(bios, boost + 0);
  38. switch (*ver) {
  39. case 0x11:
  40. *hdr = nvbios_rd08(bios, boost + 1);
  41. *cnt = nvbios_rd08(bios, boost + 5);
  42. *len = nvbios_rd08(bios, boost + 2);
  43. *snr = nvbios_rd08(bios, boost + 4);
  44. *ssz = nvbios_rd08(bios, boost + 3);
  45. return boost;
  46. default:
  47. break;
  48. }
  49. }
  50. }
  51. return 0;
  52. }
  53. u32
  54. nvbios_boostEe(struct nvkm_bios *bios, int idx,
  55. u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
  56. {
  57. u8 snr, ssz;
  58. u32 data = nvbios_boostTe(bios, ver, hdr, cnt, len, &snr, &ssz);
  59. if (data && idx < *cnt) {
  60. data = data + *hdr + (idx * (*len + (snr * ssz)));
  61. *hdr = *len;
  62. *cnt = snr;
  63. *len = ssz;
  64. return data;
  65. }
  66. return 0;
  67. }
  68. u32
  69. nvbios_boostEp(struct nvkm_bios *bios, int idx,
  70. u8 *ver, u8 *hdr, u8 *cnt, u8 *len, struct nvbios_boostE *info)
  71. {
  72. u32 data = nvbios_boostEe(bios, idx, ver, hdr, cnt, len);
  73. memset(info, 0x00, sizeof(*info));
  74. if (data) {
  75. info->pstate = (nvbios_rd16(bios, data + 0x00) & 0x01e0) >> 5;
  76. info->min = nvbios_rd16(bios, data + 0x02) * 1000;
  77. info->max = nvbios_rd16(bios, data + 0x04) * 1000;
  78. }
  79. return data;
  80. }
  81. u32
  82. nvbios_boostEm(struct nvkm_bios *bios, u8 pstate,
  83. u8 *ver, u8 *hdr, u8 *cnt, u8 *len, struct nvbios_boostE *info)
  84. {
  85. u32 data, idx = 0;
  86. while ((data = nvbios_boostEp(bios, idx++, ver, hdr, cnt, len, info))) {
  87. if (info->pstate == pstate)
  88. break;
  89. }
  90. return data;
  91. }
  92. u32
  93. nvbios_boostSe(struct nvkm_bios *bios, int idx,
  94. u32 data, u8 *ver, u8 *hdr, u8 cnt, u8 len)
  95. {
  96. if (data && idx < cnt) {
  97. data = data + *hdr + (idx * len);
  98. *hdr = len;
  99. return data;
  100. }
  101. return 0;
  102. }
  103. u32
  104. nvbios_boostSp(struct nvkm_bios *bios, int idx,
  105. u32 data, u8 *ver, u8 *hdr, u8 cnt, u8 len,
  106. struct nvbios_boostS *info)
  107. {
  108. data = nvbios_boostSe(bios, idx, data, ver, hdr, cnt, len);
  109. memset(info, 0x00, sizeof(*info));
  110. if (data) {
  111. info->domain = nvbios_rd08(bios, data + 0x00);
  112. info->percent = nvbios_rd08(bios, data + 0x01);
  113. info->min = nvbios_rd16(bios, data + 0x02) * 1000;
  114. info->max = nvbios_rd16(bios, data + 0x04) * 1000;
  115. }
  116. return data;
  117. }