usernv50.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 nv50_dmaobj(p) container_of((p), struct nv50_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 nv50_dmaobj {
  32. struct nvkm_dmaobj base;
  33. u32 flags0;
  34. u32 flags5;
  35. };
  36. static int
  37. nv50_dmaobj_bind(struct nvkm_dmaobj *base, struct nvkm_gpuobj *parent,
  38. int align, struct nvkm_gpuobj **pgpuobj)
  39. {
  40. struct nv50_dmaobj *dmaobj = nv50_dmaobj(base);
  41. struct nvkm_device *device = dmaobj->base.dma->engine.subdev.device;
  42. int ret;
  43. ret = nvkm_gpuobj_new(device, 24, align, false, parent, pgpuobj);
  44. if (ret == 0) {
  45. nvkm_kmap(*pgpuobj);
  46. nvkm_wo32(*pgpuobj, 0x00, dmaobj->flags0);
  47. nvkm_wo32(*pgpuobj, 0x04, lower_32_bits(dmaobj->base.limit));
  48. nvkm_wo32(*pgpuobj, 0x08, lower_32_bits(dmaobj->base.start));
  49. nvkm_wo32(*pgpuobj, 0x0c, upper_32_bits(dmaobj->base.limit) << 24 |
  50. upper_32_bits(dmaobj->base.start));
  51. nvkm_wo32(*pgpuobj, 0x10, 0x00000000);
  52. nvkm_wo32(*pgpuobj, 0x14, dmaobj->flags5);
  53. nvkm_done(*pgpuobj);
  54. }
  55. return ret;
  56. }
  57. static const struct nvkm_dmaobj_func
  58. nv50_dmaobj_func = {
  59. .bind = nv50_dmaobj_bind,
  60. };
  61. int
  62. nv50_dmaobj_new(struct nvkm_dma *dma, const struct nvkm_oclass *oclass,
  63. void *data, u32 size, struct nvkm_dmaobj **pdmaobj)
  64. {
  65. union {
  66. struct nv50_dma_v0 v0;
  67. } *args;
  68. struct nvkm_object *parent = oclass->parent;
  69. struct nv50_dmaobj *dmaobj;
  70. u32 user, part, comp, kind;
  71. int ret;
  72. if (!(dmaobj = kzalloc(sizeof(*dmaobj), GFP_KERNEL)))
  73. return -ENOMEM;
  74. *pdmaobj = &dmaobj->base;
  75. ret = nvkm_dmaobj_ctor(&nv50_dmaobj_func, dma, oclass,
  76. &data, &size, &dmaobj->base);
  77. if (ret)
  78. return ret;
  79. ret = -ENOSYS;
  80. args = data;
  81. nvif_ioctl(parent, "create nv50 dma size %d\n", size);
  82. if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
  83. nvif_ioctl(parent, "create nv50 dma vers %d priv %d part %d "
  84. "comp %d kind %02x\n", args->v0.version,
  85. args->v0.priv, args->v0.part, args->v0.comp,
  86. args->v0.kind);
  87. user = args->v0.priv;
  88. part = args->v0.part;
  89. comp = args->v0.comp;
  90. kind = args->v0.kind;
  91. } else
  92. if (size == 0) {
  93. if (dmaobj->base.target != NV_MEM_TARGET_VM) {
  94. user = NV50_DMA_V0_PRIV_US;
  95. part = NV50_DMA_V0_PART_256;
  96. comp = NV50_DMA_V0_COMP_NONE;
  97. kind = NV50_DMA_V0_KIND_PITCH;
  98. } else {
  99. user = NV50_DMA_V0_PRIV_VM;
  100. part = NV50_DMA_V0_PART_VM;
  101. comp = NV50_DMA_V0_COMP_VM;
  102. kind = NV50_DMA_V0_KIND_VM;
  103. }
  104. } else
  105. return ret;
  106. if (user > 2 || part > 2 || comp > 3 || kind > 0x7f)
  107. return -EINVAL;
  108. dmaobj->flags0 = (comp << 29) | (kind << 22) | (user << 20) |
  109. oclass->base.oclass;
  110. dmaobj->flags5 = (part << 16);
  111. switch (dmaobj->base.target) {
  112. case NV_MEM_TARGET_VM:
  113. dmaobj->flags0 |= 0x00000000;
  114. break;
  115. case NV_MEM_TARGET_VRAM:
  116. dmaobj->flags0 |= 0x00010000;
  117. break;
  118. case NV_MEM_TARGET_PCI:
  119. dmaobj->flags0 |= 0x00020000;
  120. break;
  121. case NV_MEM_TARGET_PCI_NOSNOOP:
  122. dmaobj->flags0 |= 0x00030000;
  123. break;
  124. default:
  125. return -EINVAL;
  126. }
  127. switch (dmaobj->base.access) {
  128. case NV_MEM_ACCESS_VM:
  129. break;
  130. case NV_MEM_ACCESS_RO:
  131. dmaobj->flags0 |= 0x00040000;
  132. break;
  133. case NV_MEM_ACCESS_WO:
  134. case NV_MEM_ACCESS_RW:
  135. dmaobj->flags0 |= 0x00080000;
  136. break;
  137. default:
  138. return -EINVAL;
  139. }
  140. return 0;
  141. }