M0203.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright 2014 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/M0203.h>
  27. u32
  28. nvbios_M0203Te(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
  29. {
  30. struct bit_entry bit_M;
  31. u32 data = 0x00000000;
  32. if (!bit_entry(bios, 'M', &bit_M)) {
  33. if (bit_M.version == 2 && bit_M.length > 0x04)
  34. data = nvbios_rd16(bios, bit_M.offset + 0x03);
  35. if (data) {
  36. *ver = nvbios_rd08(bios, data + 0x00);
  37. switch (*ver) {
  38. case 0x10:
  39. *hdr = nvbios_rd08(bios, data + 0x01);
  40. *len = nvbios_rd08(bios, data + 0x02);
  41. *cnt = nvbios_rd08(bios, data + 0x03);
  42. return data;
  43. default:
  44. break;
  45. }
  46. }
  47. }
  48. return 0x00000000;
  49. }
  50. u32
  51. nvbios_M0203Tp(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len,
  52. struct nvbios_M0203T *info)
  53. {
  54. u32 data = nvbios_M0203Te(bios, ver, hdr, cnt, len);
  55. memset(info, 0x00, sizeof(*info));
  56. switch (!!data * *ver) {
  57. case 0x10:
  58. info->type = nvbios_rd08(bios, data + 0x04);
  59. info->pointer = nvbios_rd16(bios, data + 0x05);
  60. break;
  61. default:
  62. break;
  63. }
  64. return data;
  65. }
  66. u32
  67. nvbios_M0203Ee(struct nvkm_bios *bios, int idx, u8 *ver, u8 *hdr)
  68. {
  69. u8 cnt, len;
  70. u32 data = nvbios_M0203Te(bios, ver, hdr, &cnt, &len);
  71. if (data && idx < cnt) {
  72. data = data + *hdr + idx * len;
  73. *hdr = len;
  74. return data;
  75. }
  76. return 0x00000000;
  77. }
  78. u32
  79. nvbios_M0203Ep(struct nvkm_bios *bios, int idx, u8 *ver, u8 *hdr,
  80. struct nvbios_M0203E *info)
  81. {
  82. u32 data = nvbios_M0203Ee(bios, idx, ver, hdr);
  83. memset(info, 0x00, sizeof(*info));
  84. switch (!!data * *ver) {
  85. case 0x10:
  86. info->type = (nvbios_rd08(bios, data + 0x00) & 0x0f) >> 0;
  87. info->strap = (nvbios_rd08(bios, data + 0x00) & 0xf0) >> 4;
  88. info->group = (nvbios_rd08(bios, data + 0x01) & 0x0f) >> 0;
  89. return data;
  90. default:
  91. break;
  92. }
  93. return 0x00000000;
  94. }
  95. u32
  96. nvbios_M0203Em(struct nvkm_bios *bios, u8 ramcfg, u8 *ver, u8 *hdr,
  97. struct nvbios_M0203E *info)
  98. {
  99. struct nvkm_subdev *subdev = &bios->subdev;
  100. struct nvbios_M0203T M0203T;
  101. u8 cnt, len, idx = 0xff;
  102. u32 data;
  103. if (!nvbios_M0203Tp(bios, ver, hdr, &cnt, &len, &M0203T)) {
  104. nvkm_warn(subdev, "M0203T not found\n");
  105. return 0x00000000;
  106. }
  107. while ((data = nvbios_M0203Ep(bios, ++idx, ver, hdr, info))) {
  108. switch (M0203T.type) {
  109. case M0203T_TYPE_RAMCFG:
  110. if (info->strap != ramcfg)
  111. continue;
  112. return data;
  113. default:
  114. nvkm_warn(subdev, "M0203T type %02x\n", M0203T.type);
  115. return 0x00000000;
  116. }
  117. }
  118. return data;
  119. }