base.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 <subdev/bios.h>
  27. #include <subdev/bios/M0203.h>
  28. #include <engine/gr.h>
  29. #include <engine/mpeg.h>
  30. bool
  31. nvkm_fb_memtype_valid(struct nvkm_fb *fb, u32 memtype)
  32. {
  33. return fb->func->memtype_valid(fb, memtype);
  34. }
  35. void
  36. nvkm_fb_tile_fini(struct nvkm_fb *fb, int region, struct nvkm_fb_tile *tile)
  37. {
  38. fb->func->tile.fini(fb, region, tile);
  39. }
  40. void
  41. nvkm_fb_tile_init(struct nvkm_fb *fb, int region, u32 addr, u32 size,
  42. u32 pitch, u32 flags, struct nvkm_fb_tile *tile)
  43. {
  44. fb->func->tile.init(fb, region, addr, size, pitch, flags, tile);
  45. }
  46. void
  47. nvkm_fb_tile_prog(struct nvkm_fb *fb, int region, struct nvkm_fb_tile *tile)
  48. {
  49. struct nvkm_device *device = fb->subdev.device;
  50. if (fb->func->tile.prog) {
  51. fb->func->tile.prog(fb, region, tile);
  52. if (device->gr)
  53. nvkm_engine_tile(&device->gr->engine, region);
  54. if (device->mpeg)
  55. nvkm_engine_tile(device->mpeg, region);
  56. }
  57. }
  58. int
  59. nvkm_fb_bios_memtype(struct nvkm_bios *bios)
  60. {
  61. struct nvkm_subdev *subdev = &bios->subdev;
  62. struct nvkm_device *device = subdev->device;
  63. const u8 ramcfg = (nvkm_rd32(device, 0x101000) & 0x0000003c) >> 2;
  64. struct nvbios_M0203E M0203E;
  65. u8 ver, hdr;
  66. if (nvbios_M0203Em(bios, ramcfg, &ver, &hdr, &M0203E)) {
  67. switch (M0203E.type) {
  68. case M0203E_TYPE_DDR2 : return NVKM_RAM_TYPE_DDR2;
  69. case M0203E_TYPE_DDR3 : return NVKM_RAM_TYPE_DDR3;
  70. case M0203E_TYPE_GDDR3: return NVKM_RAM_TYPE_GDDR3;
  71. case M0203E_TYPE_GDDR5: return NVKM_RAM_TYPE_GDDR5;
  72. default:
  73. nvkm_warn(subdev, "M0203E type %02x\n", M0203E.type);
  74. return NVKM_RAM_TYPE_UNKNOWN;
  75. }
  76. }
  77. nvkm_warn(subdev, "M0203E not matched!\n");
  78. return NVKM_RAM_TYPE_UNKNOWN;
  79. }
  80. static void
  81. nvkm_fb_intr(struct nvkm_subdev *subdev)
  82. {
  83. struct nvkm_fb *fb = nvkm_fb(subdev);
  84. if (fb->func->intr)
  85. fb->func->intr(fb);
  86. }
  87. static int
  88. nvkm_fb_oneinit(struct nvkm_subdev *subdev)
  89. {
  90. struct nvkm_fb *fb = nvkm_fb(subdev);
  91. if (fb->func->ram_new) {
  92. int ret = fb->func->ram_new(fb, &fb->ram);
  93. if (ret) {
  94. nvkm_error(subdev, "vram setup failed, %d\n", ret);
  95. return ret;
  96. }
  97. }
  98. return 0;
  99. }
  100. static int
  101. nvkm_fb_init(struct nvkm_subdev *subdev)
  102. {
  103. struct nvkm_fb *fb = nvkm_fb(subdev);
  104. int ret, i;
  105. if (fb->ram) {
  106. ret = nvkm_ram_init(fb->ram);
  107. if (ret)
  108. return ret;
  109. }
  110. for (i = 0; i < fb->tile.regions; i++)
  111. fb->func->tile.prog(fb, i, &fb->tile.region[i]);
  112. if (fb->func->init)
  113. fb->func->init(fb);
  114. return 0;
  115. }
  116. static void *
  117. nvkm_fb_dtor(struct nvkm_subdev *subdev)
  118. {
  119. struct nvkm_fb *fb = nvkm_fb(subdev);
  120. int i;
  121. for (i = 0; i < fb->tile.regions; i++)
  122. fb->func->tile.fini(fb, i, &fb->tile.region[i]);
  123. nvkm_ram_del(&fb->ram);
  124. if (fb->func->dtor)
  125. return fb->func->dtor(fb);
  126. return fb;
  127. }
  128. static const struct nvkm_subdev_func
  129. nvkm_fb = {
  130. .dtor = nvkm_fb_dtor,
  131. .oneinit = nvkm_fb_oneinit,
  132. .init = nvkm_fb_init,
  133. .intr = nvkm_fb_intr,
  134. };
  135. void
  136. nvkm_fb_ctor(const struct nvkm_fb_func *func, struct nvkm_device *device,
  137. int index, struct nvkm_fb *fb)
  138. {
  139. nvkm_subdev_ctor(&nvkm_fb, device, index, 0, &fb->subdev);
  140. fb->func = func;
  141. fb->tile.regions = fb->func->tile.regions;
  142. }
  143. int
  144. nvkm_fb_new_(const struct nvkm_fb_func *func, struct nvkm_device *device,
  145. int index, struct nvkm_fb **pfb)
  146. {
  147. if (!(*pfb = kzalloc(sizeof(**pfb), GFP_KERNEL)))
  148. return -ENOMEM;
  149. nvkm_fb_ctor(func, device, index, *pfb);
  150. return 0;
  151. }