gm200.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 "nv50.h"
  25. #include <subdev/bios.h>
  26. #include <subdev/bios/bit.h>
  27. #include <subdev/bios/pmu.h>
  28. #include <subdev/timer.h>
  29. static void
  30. pmu_code(struct nv50_devinit *init, u32 pmu, u32 img, u32 len, bool sec)
  31. {
  32. struct nvkm_device *device = init->base.subdev.device;
  33. struct nvkm_bios *bios = device->bios;
  34. int i;
  35. nvkm_wr32(device, 0x10a180, 0x01000000 | (sec ? 0x10000000 : 0) | pmu);
  36. for (i = 0; i < len; i += 4) {
  37. if ((i & 0xff) == 0)
  38. nvkm_wr32(device, 0x10a188, (pmu + i) >> 8);
  39. nvkm_wr32(device, 0x10a184, nvbios_rd32(bios, img + i));
  40. }
  41. while (i & 0xff) {
  42. nvkm_wr32(device, 0x10a184, 0x00000000);
  43. i += 4;
  44. }
  45. }
  46. static void
  47. pmu_data(struct nv50_devinit *init, u32 pmu, u32 img, u32 len)
  48. {
  49. struct nvkm_device *device = init->base.subdev.device;
  50. struct nvkm_bios *bios = device->bios;
  51. int i;
  52. nvkm_wr32(device, 0x10a1c0, 0x01000000 | pmu);
  53. for (i = 0; i < len; i += 4)
  54. nvkm_wr32(device, 0x10a1c4, nvbios_rd32(bios, img + i));
  55. }
  56. static u32
  57. pmu_args(struct nv50_devinit *init, u32 argp, u32 argi)
  58. {
  59. struct nvkm_device *device = init->base.subdev.device;
  60. nvkm_wr32(device, 0x10a1c0, argp);
  61. nvkm_wr32(device, 0x10a1c0, nvkm_rd32(device, 0x10a1c4) + argi);
  62. return nvkm_rd32(device, 0x10a1c4);
  63. }
  64. static void
  65. pmu_exec(struct nv50_devinit *init, u32 init_addr)
  66. {
  67. struct nvkm_device *device = init->base.subdev.device;
  68. nvkm_wr32(device, 0x10a104, init_addr);
  69. nvkm_wr32(device, 0x10a10c, 0x00000000);
  70. nvkm_wr32(device, 0x10a100, 0x00000002);
  71. }
  72. static int
  73. pmu_load(struct nv50_devinit *init, u8 type, bool post,
  74. u32 *init_addr_pmu, u32 *args_addr_pmu)
  75. {
  76. struct nvkm_subdev *subdev = &init->base.subdev;
  77. struct nvkm_bios *bios = subdev->device->bios;
  78. struct nvbios_pmuR pmu;
  79. if (!nvbios_pmuRm(bios, type, &pmu)) {
  80. nvkm_error(subdev, "VBIOS PMU fuc %02x not found\n", type);
  81. return -EINVAL;
  82. }
  83. if (!post)
  84. return 0;
  85. pmu_code(init, pmu.boot_addr_pmu, pmu.boot_addr, pmu.boot_size, false);
  86. pmu_code(init, pmu.code_addr_pmu, pmu.code_addr, pmu.code_size, true);
  87. pmu_data(init, pmu.data_addr_pmu, pmu.data_addr, pmu.data_size);
  88. if (init_addr_pmu) {
  89. *init_addr_pmu = pmu.init_addr_pmu;
  90. *args_addr_pmu = pmu.args_addr_pmu;
  91. return 0;
  92. }
  93. return pmu_exec(init, pmu.init_addr_pmu), 0;
  94. }
  95. static int
  96. gm200_devinit_post(struct nvkm_devinit *base, bool post)
  97. {
  98. struct nv50_devinit *init = nv50_devinit(base);
  99. struct nvkm_subdev *subdev = &init->base.subdev;
  100. struct nvkm_device *device = subdev->device;
  101. struct nvkm_bios *bios = device->bios;
  102. struct bit_entry bit_I;
  103. u32 exec, args;
  104. int ret;
  105. if (bit_entry(bios, 'I', &bit_I) || bit_I.version != 1 ||
  106. bit_I.length < 0x1c) {
  107. nvkm_error(subdev, "VBIOS PMU init data not found\n");
  108. return -EINVAL;
  109. }
  110. ret = pmu_load(init, 0x04, post, &exec, &args);
  111. if (ret)
  112. return ret;
  113. /* upload first chunk of init data */
  114. if (post) {
  115. // devinit tables
  116. u32 pmu = pmu_args(init, args + 0x08, 0x08);
  117. u32 img = nvbios_rd16(bios, bit_I.offset + 0x14);
  118. u32 len = nvbios_rd16(bios, bit_I.offset + 0x16);
  119. pmu_data(init, pmu, img, len);
  120. }
  121. /* upload second chunk of init data */
  122. if (post) {
  123. // devinit boot scripts
  124. u32 pmu = pmu_args(init, args + 0x08, 0x10);
  125. u32 img = nvbios_rd16(bios, bit_I.offset + 0x18);
  126. u32 len = nvbios_rd16(bios, bit_I.offset + 0x1a);
  127. pmu_data(init, pmu, img, len);
  128. }
  129. /* execute init tables */
  130. if (post) {
  131. nvkm_wr32(device, 0x10a040, 0x00005000);
  132. pmu_exec(init, exec);
  133. if (nvkm_msec(device, 2000,
  134. if (nvkm_rd32(device, 0x10a040) & 0x00002000)
  135. break;
  136. ) < 0)
  137. return -ETIMEDOUT;
  138. }
  139. /* load and execute some other ucode image (bios therm?) */
  140. return pmu_load(init, 0x01, post, NULL, NULL);
  141. }
  142. static const struct nvkm_devinit_func
  143. gm200_devinit = {
  144. .preinit = gf100_devinit_preinit,
  145. .init = nv50_devinit_init,
  146. .post = gm200_devinit_post,
  147. .pll_set = gf100_devinit_pll_set,
  148. .disable = gm107_devinit_disable,
  149. };
  150. int
  151. gm200_devinit_new(struct nvkm_device *device, int index,
  152. struct nvkm_devinit **pinit)
  153. {
  154. return nv50_devinit_new_(&gm200_devinit, device, index, pinit);
  155. }