rootnv04.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #define nv04_disp_root(p) container_of((p), struct nv04_disp_root, object)
  25. #include "priv.h"
  26. #include <core/client.h>
  27. #include <nvif/class.h>
  28. #include <nvif/unpack.h>
  29. struct nv04_disp_root {
  30. struct nvkm_object object;
  31. struct nvkm_disp *disp;
  32. };
  33. static int
  34. nv04_disp_scanoutpos(struct nv04_disp_root *root,
  35. void *data, u32 size, int head)
  36. {
  37. struct nvkm_device *device = root->disp->engine.subdev.device;
  38. struct nvkm_object *object = &root->object;
  39. const u32 hoff = head * 0x2000;
  40. union {
  41. struct nv04_disp_scanoutpos_v0 v0;
  42. } *args = data;
  43. u32 line;
  44. int ret;
  45. nvif_ioctl(object, "disp scanoutpos size %d\n", size);
  46. if (nvif_unpack(args->v0, 0, 0, false)) {
  47. nvif_ioctl(object, "disp scanoutpos vers %d\n",
  48. args->v0.version);
  49. args->v0.vblanks = nvkm_rd32(device, 0x680800 + hoff) & 0xffff;
  50. args->v0.vtotal = nvkm_rd32(device, 0x680804 + hoff) & 0xffff;
  51. args->v0.vblanke = args->v0.vtotal - 1;
  52. args->v0.hblanks = nvkm_rd32(device, 0x680820 + hoff) & 0xffff;
  53. args->v0.htotal = nvkm_rd32(device, 0x680824 + hoff) & 0xffff;
  54. args->v0.hblanke = args->v0.htotal - 1;
  55. /*
  56. * If output is vga instead of digital then vtotal/htotal is
  57. * invalid so we have to give up and trigger the timestamping
  58. * fallback in the drm core.
  59. */
  60. if (!args->v0.vtotal || !args->v0.htotal)
  61. return -ENOTSUPP;
  62. args->v0.time[0] = ktime_to_ns(ktime_get());
  63. line = nvkm_rd32(device, 0x600868 + hoff);
  64. args->v0.time[1] = ktime_to_ns(ktime_get());
  65. args->v0.hline = (line & 0xffff0000) >> 16;
  66. args->v0.vline = (line & 0x0000ffff);
  67. } else
  68. return ret;
  69. return 0;
  70. }
  71. static int
  72. nv04_disp_mthd(struct nvkm_object *object, u32 mthd, void *data, u32 size)
  73. {
  74. struct nv04_disp_root *root = nv04_disp_root(object);
  75. union {
  76. struct nv04_disp_mthd_v0 v0;
  77. } *args = data;
  78. int head, ret;
  79. nvif_ioctl(object, "disp mthd size %d\n", size);
  80. if (nvif_unpack(args->v0, 0, 0, true)) {
  81. nvif_ioctl(object, "disp mthd vers %d mthd %02x head %d\n",
  82. args->v0.version, args->v0.method, args->v0.head);
  83. mthd = args->v0.method;
  84. head = args->v0.head;
  85. } else
  86. return ret;
  87. if (head < 0 || head >= 2)
  88. return -ENXIO;
  89. switch (mthd) {
  90. case NV04_DISP_SCANOUTPOS:
  91. return nv04_disp_scanoutpos(root, data, size, head);
  92. default:
  93. break;
  94. }
  95. return -EINVAL;
  96. }
  97. static struct nvkm_object_func
  98. nv04_disp_root = {
  99. .mthd = nv04_disp_mthd,
  100. .ntfy = nvkm_disp_ntfy,
  101. };
  102. static int
  103. nv04_disp_root_new(struct nvkm_disp *disp, const struct nvkm_oclass *oclass,
  104. void *data, u32 size, struct nvkm_object **pobject)
  105. {
  106. struct nv04_disp_root *root;
  107. if (!(root = kzalloc(sizeof(*root), GFP_KERNEL)))
  108. return -ENOMEM;
  109. root->disp = disp;
  110. *pobject = &root->object;
  111. nvkm_object_ctor(&nv04_disp_root, oclass, &root->object);
  112. return 0;
  113. }
  114. const struct nvkm_disp_oclass
  115. nv04_disp_root_oclass = {
  116. .base.oclass = NV04_DISP,
  117. .base.minver = -1,
  118. .base.maxver = -1,
  119. .ctor = nv04_disp_root_new,
  120. };