usergf119.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 gf119_dmaobj(p) container_of((p), struct gf119_dmaobj, base)
  25. #include "user.h"
  26. #include <core/client.h>
  27. #include <core/gpuobj.h>
  28. #include <subdev/fb.h>
  29. #include <nvif/cl0002.h>
  30. #include <nvif/unpack.h>
  31. struct gf119_dmaobj {
  32. struct nvkm_dmaobj base;
  33. u32 flags0;
  34. };
  35. static int
  36. gf119_dmaobj_bind(struct nvkm_dmaobj *base, struct nvkm_gpuobj *parent,
  37. int align, struct nvkm_gpuobj **pgpuobj)
  38. {
  39. struct gf119_dmaobj *dmaobj = gf119_dmaobj(base);
  40. struct nvkm_device *device = dmaobj->base.dma->engine.subdev.device;
  41. int ret;
  42. ret = nvkm_gpuobj_new(device, 24, align, false, parent, pgpuobj);
  43. if (ret == 0) {
  44. nvkm_kmap(*pgpuobj);
  45. nvkm_wo32(*pgpuobj, 0x00, dmaobj->flags0);
  46. nvkm_wo32(*pgpuobj, 0x04, dmaobj->base.start >> 8);
  47. nvkm_wo32(*pgpuobj, 0x08, dmaobj->base.limit >> 8);
  48. nvkm_wo32(*pgpuobj, 0x0c, 0x00000000);
  49. nvkm_wo32(*pgpuobj, 0x10, 0x00000000);
  50. nvkm_wo32(*pgpuobj, 0x14, 0x00000000);
  51. nvkm_done(*pgpuobj);
  52. }
  53. return ret;
  54. }
  55. static const struct nvkm_dmaobj_func
  56. gf119_dmaobj_func = {
  57. .bind = gf119_dmaobj_bind,
  58. };
  59. int
  60. gf119_dmaobj_new(struct nvkm_dma *dma, const struct nvkm_oclass *oclass,
  61. void *data, u32 size, struct nvkm_dmaobj **pdmaobj)
  62. {
  63. union {
  64. struct gf119_dma_v0 v0;
  65. } *args;
  66. struct nvkm_object *parent = oclass->parent;
  67. struct gf119_dmaobj *dmaobj;
  68. u32 kind, page;
  69. int ret;
  70. if (!(dmaobj = kzalloc(sizeof(*dmaobj), GFP_KERNEL)))
  71. return -ENOMEM;
  72. *pdmaobj = &dmaobj->base;
  73. ret = nvkm_dmaobj_ctor(&gf119_dmaobj_func, dma, oclass,
  74. &data, &size, &dmaobj->base);
  75. if (ret)
  76. return ret;
  77. ret = -ENOSYS;
  78. args = data;
  79. nvif_ioctl(parent, "create gf119 dma size %d\n", size);
  80. if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
  81. nvif_ioctl(parent,
  82. "create gf100 dma vers %d page %d kind %02x\n",
  83. args->v0.version, args->v0.page, args->v0.kind);
  84. kind = args->v0.kind;
  85. page = args->v0.page;
  86. } else
  87. if (size == 0) {
  88. if (dmaobj->base.target != NV_MEM_TARGET_VM) {
  89. kind = GF119_DMA_V0_KIND_PITCH;
  90. page = GF119_DMA_V0_PAGE_SP;
  91. } else {
  92. kind = GF119_DMA_V0_KIND_VM;
  93. page = GF119_DMA_V0_PAGE_LP;
  94. }
  95. } else
  96. return ret;
  97. if (page > 1)
  98. return -EINVAL;
  99. dmaobj->flags0 = (kind << 20) | (page << 6);
  100. switch (dmaobj->base.target) {
  101. case NV_MEM_TARGET_VRAM:
  102. dmaobj->flags0 |= 0x00000009;
  103. break;
  104. case NV_MEM_TARGET_VM:
  105. case NV_MEM_TARGET_PCI:
  106. case NV_MEM_TARGET_PCI_NOSNOOP:
  107. /* XXX: don't currently know how to construct a real one
  108. * of these. we only use them to represent pushbufs
  109. * on these chipsets, and the classes that use them
  110. * deal with the target themselves.
  111. */
  112. break;
  113. default:
  114. return -EINVAL;
  115. }
  116. return 0;
  117. }