nv04.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 nv04_instmem(p) container_of((p), struct nv04_instmem, base)
  25. #include "priv.h"
  26. #include <core/memory.h>
  27. #include <core/ramht.h>
  28. struct nv04_instmem {
  29. struct nvkm_instmem base;
  30. struct nvkm_mm heap;
  31. };
  32. /******************************************************************************
  33. * instmem object implementation
  34. *****************************************************************************/
  35. #define nv04_instobj(p) container_of((p), struct nv04_instobj, memory)
  36. struct nv04_instobj {
  37. struct nvkm_memory memory;
  38. struct nv04_instmem *imem;
  39. struct nvkm_mm_node *node;
  40. };
  41. static enum nvkm_memory_target
  42. nv04_instobj_target(struct nvkm_memory *memory)
  43. {
  44. return NVKM_MEM_TARGET_INST;
  45. }
  46. static u64
  47. nv04_instobj_addr(struct nvkm_memory *memory)
  48. {
  49. return nv04_instobj(memory)->node->offset;
  50. }
  51. static u64
  52. nv04_instobj_size(struct nvkm_memory *memory)
  53. {
  54. return nv04_instobj(memory)->node->length;
  55. }
  56. static void __iomem *
  57. nv04_instobj_acquire(struct nvkm_memory *memory)
  58. {
  59. struct nv04_instobj *iobj = nv04_instobj(memory);
  60. struct nvkm_device *device = iobj->imem->base.subdev.device;
  61. return device->pri + 0x700000 + iobj->node->offset;
  62. }
  63. static void
  64. nv04_instobj_release(struct nvkm_memory *memory)
  65. {
  66. }
  67. static u32
  68. nv04_instobj_rd32(struct nvkm_memory *memory, u64 offset)
  69. {
  70. struct nv04_instobj *iobj = nv04_instobj(memory);
  71. struct nvkm_device *device = iobj->imem->base.subdev.device;
  72. return nvkm_rd32(device, 0x700000 + iobj->node->offset + offset);
  73. }
  74. static void
  75. nv04_instobj_wr32(struct nvkm_memory *memory, u64 offset, u32 data)
  76. {
  77. struct nv04_instobj *iobj = nv04_instobj(memory);
  78. struct nvkm_device *device = iobj->imem->base.subdev.device;
  79. nvkm_wr32(device, 0x700000 + iobj->node->offset + offset, data);
  80. }
  81. static void *
  82. nv04_instobj_dtor(struct nvkm_memory *memory)
  83. {
  84. struct nv04_instobj *iobj = nv04_instobj(memory);
  85. mutex_lock(&iobj->imem->base.subdev.mutex);
  86. nvkm_mm_free(&iobj->imem->heap, &iobj->node);
  87. mutex_unlock(&iobj->imem->base.subdev.mutex);
  88. return iobj;
  89. }
  90. static const struct nvkm_memory_func
  91. nv04_instobj_func = {
  92. .dtor = nv04_instobj_dtor,
  93. .target = nv04_instobj_target,
  94. .size = nv04_instobj_size,
  95. .addr = nv04_instobj_addr,
  96. .acquire = nv04_instobj_acquire,
  97. .release = nv04_instobj_release,
  98. .rd32 = nv04_instobj_rd32,
  99. .wr32 = nv04_instobj_wr32,
  100. };
  101. static int
  102. nv04_instobj_new(struct nvkm_instmem *base, u32 size, u32 align, bool zero,
  103. struct nvkm_memory **pmemory)
  104. {
  105. struct nv04_instmem *imem = nv04_instmem(base);
  106. struct nv04_instobj *iobj;
  107. int ret;
  108. if (!(iobj = kzalloc(sizeof(*iobj), GFP_KERNEL)))
  109. return -ENOMEM;
  110. *pmemory = &iobj->memory;
  111. nvkm_memory_ctor(&nv04_instobj_func, &iobj->memory);
  112. iobj->imem = imem;
  113. mutex_lock(&imem->base.subdev.mutex);
  114. ret = nvkm_mm_head(&imem->heap, 0, 1, size, size,
  115. align ? align : 1, &iobj->node);
  116. mutex_unlock(&imem->base.subdev.mutex);
  117. return ret;
  118. }
  119. /******************************************************************************
  120. * instmem subdev implementation
  121. *****************************************************************************/
  122. static u32
  123. nv04_instmem_rd32(struct nvkm_instmem *imem, u32 addr)
  124. {
  125. return nvkm_rd32(imem->subdev.device, 0x700000 + addr);
  126. }
  127. static void
  128. nv04_instmem_wr32(struct nvkm_instmem *imem, u32 addr, u32 data)
  129. {
  130. nvkm_wr32(imem->subdev.device, 0x700000 + addr, data);
  131. }
  132. static int
  133. nv04_instmem_oneinit(struct nvkm_instmem *base)
  134. {
  135. struct nv04_instmem *imem = nv04_instmem(base);
  136. struct nvkm_device *device = imem->base.subdev.device;
  137. int ret;
  138. /* PRAMIN aperture maps over the end of VRAM, reserve it */
  139. imem->base.reserved = 512 * 1024;
  140. ret = nvkm_mm_init(&imem->heap, 0, imem->base.reserved, 1);
  141. if (ret)
  142. return ret;
  143. /* 0x00000-0x10000: reserve for probable vbios image */
  144. ret = nvkm_memory_new(device, NVKM_MEM_TARGET_INST, 0x10000, 0, false,
  145. &imem->base.vbios);
  146. if (ret)
  147. return ret;
  148. /* 0x10000-0x18000: reserve for RAMHT */
  149. ret = nvkm_ramht_new(device, 0x08000, 0, NULL, &imem->base.ramht);
  150. if (ret)
  151. return ret;
  152. /* 0x18000-0x18800: reserve for RAMFC (enough for 32 nv30 channels) */
  153. ret = nvkm_memory_new(device, NVKM_MEM_TARGET_INST, 0x00800, 0, true,
  154. &imem->base.ramfc);
  155. if (ret)
  156. return ret;
  157. /* 0x18800-0x18a00: reserve for RAMRO */
  158. ret = nvkm_memory_new(device, NVKM_MEM_TARGET_INST, 0x00200, 0, false,
  159. &imem->base.ramro);
  160. if (ret)
  161. return ret;
  162. return 0;
  163. }
  164. static void *
  165. nv04_instmem_dtor(struct nvkm_instmem *base)
  166. {
  167. struct nv04_instmem *imem = nv04_instmem(base);
  168. nvkm_memory_del(&imem->base.ramfc);
  169. nvkm_memory_del(&imem->base.ramro);
  170. nvkm_ramht_del(&imem->base.ramht);
  171. nvkm_memory_del(&imem->base.vbios);
  172. nvkm_mm_fini(&imem->heap);
  173. return imem;
  174. }
  175. static const struct nvkm_instmem_func
  176. nv04_instmem = {
  177. .dtor = nv04_instmem_dtor,
  178. .oneinit = nv04_instmem_oneinit,
  179. .rd32 = nv04_instmem_rd32,
  180. .wr32 = nv04_instmem_wr32,
  181. .memory_new = nv04_instobj_new,
  182. .persistent = false,
  183. .zero = false,
  184. };
  185. int
  186. nv04_instmem_new(struct nvkm_device *device, int index,
  187. struct nvkm_instmem **pimem)
  188. {
  189. struct nv04_instmem *imem;
  190. if (!(imem = kzalloc(sizeof(*imem), GFP_KERNEL)))
  191. return -ENOMEM;
  192. nvkm_instmem_ctor(&nv04_instmem, device, index, &imem->base);
  193. *pimem = &imem->base;
  194. return 0;
  195. }