cstep.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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/cstep.h>
  27. u32
  28. nvbios_cstepTe(struct nvkm_bios *bios,
  29. u8 *ver, u8 *hdr, u8 *cnt, u8 *len, u8 *xnr, u8 *xsz)
  30. {
  31. struct bit_entry bit_P;
  32. u32 cstep = 0;
  33. if (!bit_entry(bios, 'P', &bit_P)) {
  34. if (bit_P.version == 2)
  35. cstep = nvbios_rd32(bios, bit_P.offset + 0x34);
  36. if (cstep) {
  37. *ver = nvbios_rd08(bios, cstep + 0);
  38. switch (*ver) {
  39. case 0x10:
  40. *hdr = nvbios_rd08(bios, cstep + 1);
  41. *cnt = nvbios_rd08(bios, cstep + 3);
  42. *len = nvbios_rd08(bios, cstep + 2);
  43. *xnr = nvbios_rd08(bios, cstep + 5);
  44. *xsz = nvbios_rd08(bios, cstep + 4);
  45. return cstep;
  46. default:
  47. break;
  48. }
  49. }
  50. }
  51. return 0;
  52. }
  53. u32
  54. nvbios_cstepEe(struct nvkm_bios *bios, int idx, u8 *ver, u8 *hdr)
  55. {
  56. u8 cnt, len, xnr, xsz;
  57. u32 data = nvbios_cstepTe(bios, ver, hdr, &cnt, &len, &xnr, &xsz);
  58. if (data && idx < cnt) {
  59. data = data + *hdr + (idx * len);
  60. *hdr = len;
  61. return data;
  62. }
  63. return 0;
  64. }
  65. u32
  66. nvbios_cstepEp(struct nvkm_bios *bios, int idx, u8 *ver, u8 *hdr,
  67. struct nvbios_cstepE *info)
  68. {
  69. u32 data = nvbios_cstepEe(bios, idx, ver, hdr);
  70. memset(info, 0x00, sizeof(*info));
  71. if (data) {
  72. info->pstate = (nvbios_rd16(bios, data + 0x00) & 0x01e0) >> 5;
  73. info->index = nvbios_rd08(bios, data + 0x03);
  74. }
  75. return data;
  76. }
  77. u32
  78. nvbios_cstepEm(struct nvkm_bios *bios, u8 pstate, u8 *ver, u8 *hdr,
  79. struct nvbios_cstepE *info)
  80. {
  81. u32 data, idx = 0;
  82. while ((data = nvbios_cstepEp(bios, idx++, ver, hdr, info))) {
  83. if (info->pstate == pstate)
  84. break;
  85. }
  86. return data;
  87. }
  88. u32
  89. nvbios_cstepXe(struct nvkm_bios *bios, int idx, u8 *ver, u8 *hdr)
  90. {
  91. u8 cnt, len, xnr, xsz;
  92. u32 data = nvbios_cstepTe(bios, ver, hdr, &cnt, &len, &xnr, &xsz);
  93. if (data && idx < xnr) {
  94. data = data + *hdr + (cnt * len) + (idx * xsz);
  95. *hdr = xsz;
  96. return data;
  97. }
  98. return 0;
  99. }
  100. u32
  101. nvbios_cstepXp(struct nvkm_bios *bios, int idx, u8 *ver, u8 *hdr,
  102. struct nvbios_cstepX *info)
  103. {
  104. u32 data = nvbios_cstepXe(bios, idx, ver, hdr);
  105. memset(info, 0x00, sizeof(*info));
  106. if (data) {
  107. info->freq = nvbios_rd16(bios, data + 0x00) * 1000;
  108. info->unkn[0] = nvbios_rd08(bios, data + 0x02);
  109. info->unkn[1] = nvbios_rd08(bios, data + 0x03);
  110. info->voltage = nvbios_rd08(bios, data + 0x04);
  111. }
  112. return data;
  113. }