nouveau_nvif.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 <bskeggs@redhat.com>
  23. */
  24. /*******************************************************************************
  25. * NVIF client driver - NVKM directly linked
  26. ******************************************************************************/
  27. #include <core/client.h>
  28. #include <core/notify.h>
  29. #include <core/ioctl.h>
  30. #include <nvif/client.h>
  31. #include <nvif/driver.h>
  32. #include <nvif/notify.h>
  33. #include <nvif/event.h>
  34. #include <nvif/ioctl.h>
  35. #include "nouveau_drm.h"
  36. #include "nouveau_usif.h"
  37. static void
  38. nvkm_client_unmap(void *priv, void __iomem *ptr, u32 size)
  39. {
  40. iounmap(ptr);
  41. }
  42. static void __iomem *
  43. nvkm_client_map(void *priv, u64 handle, u32 size)
  44. {
  45. return ioremap(handle, size);
  46. }
  47. static int
  48. nvkm_client_ioctl(void *priv, bool super, void *data, u32 size, void **hack)
  49. {
  50. return nvkm_ioctl(priv, super, data, size, hack);
  51. }
  52. static int
  53. nvkm_client_resume(void *priv)
  54. {
  55. return nouveau_client_init(priv);
  56. }
  57. static int
  58. nvkm_client_suspend(void *priv)
  59. {
  60. return nouveau_client_fini(priv, true);
  61. }
  62. static void
  63. nvkm_client_fini(void *priv)
  64. {
  65. struct nouveau_object *client = priv;
  66. nouveau_client_fini(nv_client(client), false);
  67. atomic_set(&client->refcount, 1);
  68. nouveau_object_ref(NULL, &client);
  69. }
  70. static int
  71. nvkm_client_ntfy(const void *header, u32 length, const void *data, u32 size)
  72. {
  73. const union {
  74. struct nvif_notify_req_v0 v0;
  75. } *args = header;
  76. u8 route;
  77. if (length == sizeof(args->v0) && args->v0.version == 0) {
  78. route = args->v0.route;
  79. } else {
  80. WARN_ON(1);
  81. return NVKM_NOTIFY_DROP;
  82. }
  83. switch (route) {
  84. case NVDRM_NOTIFY_NVIF:
  85. return nvif_notify(header, length, data, size);
  86. case NVDRM_NOTIFY_USIF:
  87. return usif_notify(header, length, data, size);
  88. default:
  89. WARN_ON(1);
  90. break;
  91. }
  92. return NVKM_NOTIFY_DROP;
  93. }
  94. static int
  95. nvkm_client_init(const char *name, u64 device, const char *cfg,
  96. const char *dbg, void **ppriv)
  97. {
  98. struct nouveau_client *client;
  99. int ret;
  100. ret = nouveau_client_create(name, device, cfg, dbg, &client);
  101. *ppriv = client;
  102. if (ret)
  103. return ret;
  104. client->ntfy = nvkm_client_ntfy;
  105. return 0;
  106. }
  107. const struct nvif_driver
  108. nvif_driver_nvkm = {
  109. .name = "nvkm",
  110. .init = nvkm_client_init,
  111. .fini = nvkm_client_fini,
  112. .suspend = nvkm_client_suspend,
  113. .resume = nvkm_client_resume,
  114. .ioctl = nvkm_client_ioctl,
  115. .map = nvkm_client_map,
  116. .unmap = nvkm_client_unmap,
  117. .keep = false,
  118. };