core507d.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright 2018 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. #include "core.h"
  23. #include "head.h"
  24. #include <nvif/cl507d.h>
  25. #include "nouveau_bo.h"
  26. void
  27. core507d_update(struct nv50_core *core, u32 *interlock, bool ntfy)
  28. {
  29. u32 *push;
  30. if ((push = evo_wait(&core->chan, 5))) {
  31. if (ntfy) {
  32. evo_mthd(push, 0x0084, 1);
  33. evo_data(push, 0x80000000 | NV50_DISP_CORE_NTFY);
  34. }
  35. evo_mthd(push, 0x0080, 2);
  36. evo_data(push, interlock[NV50_DISP_INTERLOCK_BASE] |
  37. interlock[NV50_DISP_INTERLOCK_OVLY]);
  38. evo_data(push, 0x00000000);
  39. evo_kick(push, &core->chan);
  40. }
  41. }
  42. int
  43. core507d_ntfy_wait_done(struct nouveau_bo *bo, u32 offset,
  44. struct nvif_device *device)
  45. {
  46. s64 time = nvif_msec(device, 2000ULL,
  47. if (nouveau_bo_rd32(bo, offset / 4))
  48. break;
  49. usleep_range(1, 2);
  50. );
  51. return time < 0 ? time : 0;
  52. }
  53. void
  54. core507d_ntfy_init(struct nouveau_bo *bo, u32 offset)
  55. {
  56. nouveau_bo_wr32(bo, offset / 4, 0x00000000);
  57. }
  58. void
  59. core507d_init(struct nv50_core *core)
  60. {
  61. u32 *push;
  62. if ((push = evo_wait(&core->chan, 2))) {
  63. evo_mthd(push, 0x0088, 1);
  64. evo_data(push, core->chan.sync.handle);
  65. evo_kick(push, &core->chan);
  66. }
  67. }
  68. static const struct nv50_core_func
  69. core507d = {
  70. .init = core507d_init,
  71. .ntfy_init = core507d_ntfy_init,
  72. .ntfy_wait_done = core507d_ntfy_wait_done,
  73. .update = core507d_update,
  74. .head = &head507d,
  75. .dac = &dac507d,
  76. .sor = &sor507d,
  77. .pior = &pior507d,
  78. };
  79. int
  80. core507d_new_(const struct nv50_core_func *func, struct nouveau_drm *drm,
  81. s32 oclass, struct nv50_core **pcore)
  82. {
  83. struct nv50_disp_core_channel_dma_v0 args = {};
  84. struct nv50_disp *disp = nv50_disp(drm->dev);
  85. struct nv50_core *core;
  86. int ret;
  87. if (!(core = *pcore = kzalloc(sizeof(*core), GFP_KERNEL)))
  88. return -ENOMEM;
  89. core->func = func;
  90. ret = nv50_dmac_create(&drm->client.device, &disp->disp->object,
  91. &oclass, 0, &args, sizeof(args),
  92. disp->sync->bo.offset, &core->chan);
  93. if (ret) {
  94. NV_ERROR(drm, "core%04x allocation failed: %d\n", oclass, ret);
  95. return ret;
  96. }
  97. return 0;
  98. }
  99. int
  100. core507d_new(struct nouveau_drm *drm, s32 oclass, struct nv50_core **pcore)
  101. {
  102. return core507d_new_(&core507d, drm, oclass, pcore);
  103. }