disp.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright 2012 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/disp.h>
  27. u16
  28. nvbios_disp_table(struct nvkm_bios *bios,
  29. u8 *ver, u8 *hdr, u8 *cnt, u8 *len, u8 *sub)
  30. {
  31. struct bit_entry U;
  32. if (!bit_entry(bios, 'U', &U)) {
  33. if (U.version == 1) {
  34. u16 data = nvbios_rd16(bios, U.offset);
  35. if (data) {
  36. *ver = nvbios_rd08(bios, data + 0x00);
  37. switch (*ver) {
  38. case 0x20:
  39. case 0x21:
  40. case 0x22:
  41. *hdr = nvbios_rd08(bios, data + 0x01);
  42. *len = nvbios_rd08(bios, data + 0x02);
  43. *cnt = nvbios_rd08(bios, data + 0x03);
  44. *sub = nvbios_rd08(bios, data + 0x04);
  45. return data;
  46. default:
  47. break;
  48. }
  49. }
  50. }
  51. }
  52. return 0x0000;
  53. }
  54. u16
  55. nvbios_disp_entry(struct nvkm_bios *bios, u8 idx, u8 *ver, u8 *len, u8 *sub)
  56. {
  57. u8 hdr, cnt;
  58. u16 data = nvbios_disp_table(bios, ver, &hdr, &cnt, len, sub);
  59. if (data && idx < cnt)
  60. return data + hdr + (idx * *len);
  61. *ver = 0x00;
  62. return 0x0000;
  63. }
  64. u16
  65. nvbios_disp_parse(struct nvkm_bios *bios, u8 idx, u8 *ver, u8 *len, u8 *sub,
  66. struct nvbios_disp *info)
  67. {
  68. u16 data = nvbios_disp_entry(bios, idx, ver, len, sub);
  69. if (data && *len >= 2) {
  70. info->data = nvbios_rd16(bios, data + 0);
  71. return data;
  72. }
  73. return 0x0000;
  74. }
  75. u16
  76. nvbios_outp_entry(struct nvkm_bios *bios, u8 idx,
  77. u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
  78. {
  79. struct nvbios_disp info;
  80. u16 data = nvbios_disp_parse(bios, idx, ver, len, hdr, &info);
  81. if (data) {
  82. *cnt = nvbios_rd08(bios, info.data + 0x05);
  83. *len = 0x06;
  84. data = info.data;
  85. }
  86. return data;
  87. }
  88. u16
  89. nvbios_outp_parse(struct nvkm_bios *bios, u8 idx,
  90. u8 *ver, u8 *hdr, u8 *cnt, u8 *len, struct nvbios_outp *info)
  91. {
  92. u16 data = nvbios_outp_entry(bios, idx, ver, hdr, cnt, len);
  93. if (data && *hdr >= 0x0a) {
  94. info->type = nvbios_rd16(bios, data + 0x00);
  95. info->mask = nvbios_rd32(bios, data + 0x02);
  96. if (*ver <= 0x20) /* match any link */
  97. info->mask |= 0x00c0;
  98. info->script[0] = nvbios_rd16(bios, data + 0x06);
  99. info->script[1] = nvbios_rd16(bios, data + 0x08);
  100. info->script[2] = 0x0000;
  101. if (*hdr >= 0x0c)
  102. info->script[2] = nvbios_rd16(bios, data + 0x0a);
  103. return data;
  104. }
  105. return 0x0000;
  106. }
  107. u16
  108. nvbios_outp_match(struct nvkm_bios *bios, u16 type, u16 mask,
  109. u8 *ver, u8 *hdr, u8 *cnt, u8 *len, struct nvbios_outp *info)
  110. {
  111. u16 data, idx = 0;
  112. while ((data = nvbios_outp_parse(bios, idx++, ver, hdr, cnt, len, info)) || *ver) {
  113. if (data && info->type == type) {
  114. if ((info->mask & mask) == mask)
  115. break;
  116. }
  117. }
  118. return data;
  119. }
  120. u16
  121. nvbios_ocfg_entry(struct nvkm_bios *bios, u16 outp, u8 idx,
  122. u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
  123. {
  124. if (idx < *cnt)
  125. return outp + *hdr + (idx * *len);
  126. return 0x0000;
  127. }
  128. u16
  129. nvbios_ocfg_parse(struct nvkm_bios *bios, u16 outp, u8 idx,
  130. u8 *ver, u8 *hdr, u8 *cnt, u8 *len, struct nvbios_ocfg *info)
  131. {
  132. u16 data = nvbios_ocfg_entry(bios, outp, idx, ver, hdr, cnt, len);
  133. if (data) {
  134. info->proto = nvbios_rd08(bios, data + 0x00);
  135. info->flags = nvbios_rd16(bios, data + 0x01);
  136. info->clkcmp[0] = nvbios_rd16(bios, data + 0x02);
  137. info->clkcmp[1] = nvbios_rd16(bios, data + 0x04);
  138. }
  139. return data;
  140. }
  141. u16
  142. nvbios_ocfg_match(struct nvkm_bios *bios, u16 outp, u8 proto, u8 flags,
  143. u8 *ver, u8 *hdr, u8 *cnt, u8 *len, struct nvbios_ocfg *info)
  144. {
  145. u16 data, idx = 0;
  146. while ((data = nvbios_ocfg_parse(bios, outp, idx++, ver, hdr, cnt, len, info))) {
  147. if ((info->proto == proto || info->proto == 0xff) &&
  148. (info->flags == flags))
  149. break;
  150. }
  151. return data;
  152. }
  153. u16
  154. nvbios_oclk_match(struct nvkm_bios *bios, u16 cmp, u32 khz)
  155. {
  156. while (cmp) {
  157. if (khz / 10 >= nvbios_rd16(bios, cmp + 0x00))
  158. return nvbios_rd16(bios, cmp + 0x02);
  159. cmp += 0x04;
  160. }
  161. return 0x0000;
  162. }