fifo.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 <nvif/fifo.h>
  23. static int
  24. nvif_fifo_runlists(struct nvif_device *device)
  25. {
  26. struct nvif_object *object = &device->object;
  27. struct {
  28. struct nv_device_info_v1 m;
  29. struct {
  30. struct nv_device_info_v1_data runlists;
  31. struct nv_device_info_v1_data runlist[64];
  32. } v;
  33. } *a;
  34. int ret, i;
  35. if (device->runlist)
  36. return 0;
  37. if (!(a = kmalloc(sizeof(*a), GFP_KERNEL)))
  38. return -ENOMEM;
  39. a->m.version = 1;
  40. a->m.count = sizeof(a->v) / sizeof(a->v.runlists);
  41. a->v.runlists.mthd = NV_DEVICE_FIFO_RUNLISTS;
  42. for (i = 0; i < ARRAY_SIZE(a->v.runlist); i++)
  43. a->v.runlist[i].mthd = NV_DEVICE_FIFO_RUNLIST_ENGINES(i);
  44. ret = nvif_object_mthd(object, NV_DEVICE_V0_INFO, a, sizeof(*a));
  45. if (ret)
  46. goto done;
  47. device->runlists = fls64(a->v.runlists.data);
  48. device->runlist = kcalloc(device->runlists, sizeof(*device->runlist),
  49. GFP_KERNEL);
  50. if (!device->runlist) {
  51. ret = -ENOMEM;
  52. goto done;
  53. }
  54. for (i = 0; i < device->runlists; i++) {
  55. if (a->v.runlists.data & BIT_ULL(i))
  56. device->runlist[i].engines = a->v.runlist[i].data;
  57. }
  58. done:
  59. kfree(a);
  60. return ret;
  61. }
  62. u64
  63. nvif_fifo_runlist(struct nvif_device *device, u64 engine)
  64. {
  65. struct nvif_object *object = &device->object;
  66. struct {
  67. struct nv_device_info_v1 m;
  68. struct {
  69. struct nv_device_info_v1_data engine;
  70. } v;
  71. } a = {
  72. .m.version = 1,
  73. .m.count = sizeof(a.v) / sizeof(a.v.engine),
  74. .v.engine.mthd = engine,
  75. };
  76. u64 runm = 0;
  77. int ret, i;
  78. if ((ret = nvif_fifo_runlists(device)))
  79. return runm;
  80. ret = nvif_object_mthd(object, NV_DEVICE_V0_INFO, &a, sizeof(a));
  81. if (ret == 0) {
  82. for (i = 0; i < device->runlists; i++) {
  83. if (device->runlist[i].engines & a.v.engine.data)
  84. runm |= BIT_ULL(i);
  85. }
  86. }
  87. return runm;
  88. }