base.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. #include "priv.h"
  25. #include "ram.h"
  26. #include <core/memory.h>
  27. #include <core/option.h>
  28. #include <subdev/bios.h>
  29. #include <subdev/bios/M0203.h>
  30. #include <engine/gr.h>
  31. #include <engine/mpeg.h>
  32. void
  33. nvkm_fb_tile_fini(struct nvkm_fb *fb, int region, struct nvkm_fb_tile *tile)
  34. {
  35. fb->func->tile.fini(fb, region, tile);
  36. }
  37. void
  38. nvkm_fb_tile_init(struct nvkm_fb *fb, int region, u32 addr, u32 size,
  39. u32 pitch, u32 flags, struct nvkm_fb_tile *tile)
  40. {
  41. fb->func->tile.init(fb, region, addr, size, pitch, flags, tile);
  42. }
  43. void
  44. nvkm_fb_tile_prog(struct nvkm_fb *fb, int region, struct nvkm_fb_tile *tile)
  45. {
  46. struct nvkm_device *device = fb->subdev.device;
  47. if (fb->func->tile.prog) {
  48. fb->func->tile.prog(fb, region, tile);
  49. if (device->gr)
  50. nvkm_engine_tile(&device->gr->engine, region);
  51. if (device->mpeg)
  52. nvkm_engine_tile(device->mpeg, region);
  53. }
  54. }
  55. int
  56. nvkm_fb_bios_memtype(struct nvkm_bios *bios)
  57. {
  58. struct nvkm_subdev *subdev = &bios->subdev;
  59. struct nvkm_device *device = subdev->device;
  60. const u8 ramcfg = (nvkm_rd32(device, 0x101000) & 0x0000003c) >> 2;
  61. struct nvbios_M0203E M0203E;
  62. u8 ver, hdr;
  63. if (nvbios_M0203Em(bios, ramcfg, &ver, &hdr, &M0203E)) {
  64. switch (M0203E.type) {
  65. case M0203E_TYPE_DDR2 : return NVKM_RAM_TYPE_DDR2;
  66. case M0203E_TYPE_DDR3 : return NVKM_RAM_TYPE_DDR3;
  67. case M0203E_TYPE_GDDR3: return NVKM_RAM_TYPE_GDDR3;
  68. case M0203E_TYPE_GDDR5: return NVKM_RAM_TYPE_GDDR5;
  69. default:
  70. nvkm_warn(subdev, "M0203E type %02x\n", M0203E.type);
  71. return NVKM_RAM_TYPE_UNKNOWN;
  72. }
  73. }
  74. nvkm_warn(subdev, "M0203E not matched!\n");
  75. return NVKM_RAM_TYPE_UNKNOWN;
  76. }
  77. static void
  78. nvkm_fb_intr(struct nvkm_subdev *subdev)
  79. {
  80. struct nvkm_fb *fb = nvkm_fb(subdev);
  81. if (fb->func->intr)
  82. fb->func->intr(fb);
  83. }
  84. static int
  85. nvkm_fb_oneinit(struct nvkm_subdev *subdev)
  86. {
  87. struct nvkm_fb *fb = nvkm_fb(subdev);
  88. u32 tags = 0;
  89. if (fb->func->ram_new) {
  90. int ret = fb->func->ram_new(fb, &fb->ram);
  91. if (ret) {
  92. nvkm_error(subdev, "vram setup failed, %d\n", ret);
  93. return ret;
  94. }
  95. }
  96. if (fb->func->oneinit) {
  97. int ret = fb->func->oneinit(fb);
  98. if (ret)
  99. return ret;
  100. }
  101. /* Initialise compression tag allocator.
  102. *
  103. * LTC oneinit() will override this on Fermi and newer.
  104. */
  105. if (fb->func->tags) {
  106. tags = fb->func->tags(fb);
  107. nvkm_debug(subdev, "%d comptags\n", tags);
  108. }
  109. return nvkm_mm_init(&fb->tags, 0, 0, tags, 1);
  110. }
  111. static int
  112. nvkm_fb_init(struct nvkm_subdev *subdev)
  113. {
  114. struct nvkm_fb *fb = nvkm_fb(subdev);
  115. int ret, i;
  116. if (fb->ram) {
  117. ret = nvkm_ram_init(fb->ram);
  118. if (ret)
  119. return ret;
  120. }
  121. for (i = 0; i < fb->tile.regions; i++)
  122. fb->func->tile.prog(fb, i, &fb->tile.region[i]);
  123. if (fb->func->init)
  124. fb->func->init(fb);
  125. if (fb->func->init_remapper)
  126. fb->func->init_remapper(fb);
  127. if (fb->func->init_page) {
  128. ret = fb->func->init_page(fb);
  129. if (WARN_ON(ret))
  130. return ret;
  131. }
  132. if (fb->func->init_unkn)
  133. fb->func->init_unkn(fb);
  134. return 0;
  135. }
  136. static void *
  137. nvkm_fb_dtor(struct nvkm_subdev *subdev)
  138. {
  139. struct nvkm_fb *fb = nvkm_fb(subdev);
  140. int i;
  141. nvkm_memory_unref(&fb->mmu_wr);
  142. nvkm_memory_unref(&fb->mmu_rd);
  143. for (i = 0; i < fb->tile.regions; i++)
  144. fb->func->tile.fini(fb, i, &fb->tile.region[i]);
  145. nvkm_mm_fini(&fb->tags);
  146. nvkm_ram_del(&fb->ram);
  147. if (fb->func->dtor)
  148. return fb->func->dtor(fb);
  149. return fb;
  150. }
  151. static const struct nvkm_subdev_func
  152. nvkm_fb = {
  153. .dtor = nvkm_fb_dtor,
  154. .oneinit = nvkm_fb_oneinit,
  155. .init = nvkm_fb_init,
  156. .intr = nvkm_fb_intr,
  157. };
  158. void
  159. nvkm_fb_ctor(const struct nvkm_fb_func *func, struct nvkm_device *device,
  160. int index, struct nvkm_fb *fb)
  161. {
  162. nvkm_subdev_ctor(&nvkm_fb, device, index, &fb->subdev);
  163. fb->func = func;
  164. fb->tile.regions = fb->func->tile.regions;
  165. fb->page = nvkm_longopt(device->cfgopt, "NvFbBigPage",
  166. fb->func->default_bigpage);
  167. }
  168. int
  169. nvkm_fb_new_(const struct nvkm_fb_func *func, struct nvkm_device *device,
  170. int index, struct nvkm_fb **pfb)
  171. {
  172. if (!(*pfb = kzalloc(sizeof(**pfb), GFP_KERNEL)))
  173. return -ENOMEM;
  174. nvkm_fb_ctor(func, device, index, *pfb);
  175. return 0;
  176. }