rootgf119.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 "rootnv50.h"
  25. #include "dmacnv50.h"
  26. #include <core/client.h>
  27. #include <core/ramht.h>
  28. #include <subdev/timer.h>
  29. #include <nvif/class.h>
  30. #include <nvif/cl5070.h>
  31. #include <nvif/unpack.h>
  32. int
  33. gf119_disp_root_scanoutpos(NV50_DISP_MTHD_V0)
  34. {
  35. struct nvkm_device *device = disp->base.engine.subdev.device;
  36. const u32 total = nvkm_rd32(device, 0x640414 + (head * 0x300));
  37. const u32 blanke = nvkm_rd32(device, 0x64041c + (head * 0x300));
  38. const u32 blanks = nvkm_rd32(device, 0x640420 + (head * 0x300));
  39. union {
  40. struct nv50_disp_scanoutpos_v0 v0;
  41. } *args = data;
  42. int ret = -ENOSYS;
  43. nvif_ioctl(object, "disp scanoutpos size %d\n", size);
  44. if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
  45. nvif_ioctl(object, "disp scanoutpos vers %d\n",
  46. args->v0.version);
  47. args->v0.vblanke = (blanke & 0xffff0000) >> 16;
  48. args->v0.hblanke = (blanke & 0x0000ffff);
  49. args->v0.vblanks = (blanks & 0xffff0000) >> 16;
  50. args->v0.hblanks = (blanks & 0x0000ffff);
  51. args->v0.vtotal = ( total & 0xffff0000) >> 16;
  52. args->v0.htotal = ( total & 0x0000ffff);
  53. args->v0.time[0] = ktime_to_ns(ktime_get());
  54. args->v0.vline = /* vline read locks hline */
  55. nvkm_rd32(device, 0x616340 + (head * 0x800)) & 0xffff;
  56. args->v0.time[1] = ktime_to_ns(ktime_get());
  57. args->v0.hline =
  58. nvkm_rd32(device, 0x616344 + (head * 0x800)) & 0xffff;
  59. } else
  60. return ret;
  61. return 0;
  62. }
  63. void
  64. gf119_disp_root_fini(struct nv50_disp_root *root)
  65. {
  66. struct nvkm_device *device = root->disp->base.engine.subdev.device;
  67. /* disable all interrupts */
  68. nvkm_wr32(device, 0x6100b0, 0x00000000);
  69. }
  70. int
  71. gf119_disp_root_init(struct nv50_disp_root *root)
  72. {
  73. struct nv50_disp *disp = root->disp;
  74. struct nvkm_device *device = disp->base.engine.subdev.device;
  75. u32 tmp;
  76. int i;
  77. /* The below segments of code copying values from one register to
  78. * another appear to inform EVO of the display capabilities or
  79. * something similar.
  80. */
  81. /* ... CRTC caps */
  82. for (i = 0; i < disp->base.head.nr; i++) {
  83. tmp = nvkm_rd32(device, 0x616104 + (i * 0x800));
  84. nvkm_wr32(device, 0x6101b4 + (i * 0x800), tmp);
  85. tmp = nvkm_rd32(device, 0x616108 + (i * 0x800));
  86. nvkm_wr32(device, 0x6101b8 + (i * 0x800), tmp);
  87. tmp = nvkm_rd32(device, 0x61610c + (i * 0x800));
  88. nvkm_wr32(device, 0x6101bc + (i * 0x800), tmp);
  89. }
  90. /* ... DAC caps */
  91. for (i = 0; i < disp->func->dac.nr; i++) {
  92. tmp = nvkm_rd32(device, 0x61a000 + (i * 0x800));
  93. nvkm_wr32(device, 0x6101c0 + (i * 0x800), tmp);
  94. }
  95. /* ... SOR caps */
  96. for (i = 0; i < disp->func->sor.nr; i++) {
  97. tmp = nvkm_rd32(device, 0x61c000 + (i * 0x800));
  98. nvkm_wr32(device, 0x6301c4 + (i * 0x800), tmp);
  99. }
  100. /* steal display away from vbios, or something like that */
  101. if (nvkm_rd32(device, 0x6100ac) & 0x00000100) {
  102. nvkm_wr32(device, 0x6100ac, 0x00000100);
  103. nvkm_mask(device, 0x6194e8, 0x00000001, 0x00000000);
  104. if (nvkm_msec(device, 2000,
  105. if (!(nvkm_rd32(device, 0x6194e8) & 0x00000002))
  106. break;
  107. ) < 0)
  108. return -EBUSY;
  109. }
  110. /* point at display engine memory area (hash table, objects) */
  111. nvkm_wr32(device, 0x610010, (root->instmem->addr >> 8) | 9);
  112. /* enable supervisor interrupts, disable everything else */
  113. nvkm_wr32(device, 0x610090, 0x00000000);
  114. nvkm_wr32(device, 0x6100a0, 0x00000000);
  115. nvkm_wr32(device, 0x6100b0, 0x00000307);
  116. /* disable underflow reporting, preventing an intermittent issue
  117. * on some gk104 boards where the production vbios left this
  118. * setting enabled by default.
  119. *
  120. * ftp://download.nvidia.com/open-gpu-doc/gk104-disable-underflow-reporting/1/gk104-disable-underflow-reporting.txt
  121. */
  122. for (i = 0; i < disp->base.head.nr; i++)
  123. nvkm_mask(device, 0x616308 + (i * 0x800), 0x00000111, 0x00000010);
  124. return 0;
  125. }
  126. static const struct nv50_disp_root_func
  127. gf119_disp_root = {
  128. .init = gf119_disp_root_init,
  129. .fini = gf119_disp_root_fini,
  130. .dmac = {
  131. &gf119_disp_core_oclass,
  132. &gf119_disp_base_oclass,
  133. &gf119_disp_ovly_oclass,
  134. },
  135. .pioc = {
  136. &gf119_disp_oimm_oclass,
  137. &gf119_disp_curs_oclass,
  138. },
  139. };
  140. static int
  141. gf119_disp_root_new(struct nvkm_disp *disp, const struct nvkm_oclass *oclass,
  142. void *data, u32 size, struct nvkm_object **pobject)
  143. {
  144. return nv50_disp_root_new_(&gf119_disp_root, disp, oclass,
  145. data, size, pobject);
  146. }
  147. const struct nvkm_disp_oclass
  148. gf119_disp_root_oclass = {
  149. .base.oclass = GF110_DISP,
  150. .base.minver = -1,
  151. .base.maxver = -1,
  152. .ctor = gf119_disp_root_new,
  153. };