base.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. fb->func->tile.prog(fb, region, tile);
  51. if (likely(device->gr))
  52. device->gr->engine.tile_prog(&device->gr->engine, region);
  53. if (likely(device->mpeg))
  54. device->mpeg->tile_prog(device->mpeg, region);
  55. }
  56. int
  57. nvkm_fb_bios_memtype(struct nvkm_bios *bios)
  58. {
  59. struct nvkm_subdev *subdev = &bios->subdev;
  60. struct nvkm_device *device = subdev->device;
  61. const u8 ramcfg = (nvkm_rd32(device, 0x101000) & 0x0000003c) >> 2;
  62. struct nvbios_M0203E M0203E;
  63. u8 ver, hdr;
  64. if (nvbios_M0203Em(bios, ramcfg, &ver, &hdr, &M0203E)) {
  65. switch (M0203E.type) {
  66. case M0203E_TYPE_DDR2 : return NVKM_RAM_TYPE_DDR2;
  67. case M0203E_TYPE_DDR3 : return NVKM_RAM_TYPE_DDR3;
  68. case M0203E_TYPE_GDDR3: return NVKM_RAM_TYPE_GDDR3;
  69. case M0203E_TYPE_GDDR5: return NVKM_RAM_TYPE_GDDR5;
  70. default:
  71. nvkm_warn(subdev, "M0203E type %02x\n", M0203E.type);
  72. return NVKM_RAM_TYPE_UNKNOWN;
  73. }
  74. }
  75. nvkm_warn(subdev, "M0203E not matched!\n");
  76. return NVKM_RAM_TYPE_UNKNOWN;
  77. }
  78. static void
  79. nvkm_fb_intr(struct nvkm_subdev *subdev)
  80. {
  81. struct nvkm_fb *fb = nvkm_fb(subdev);
  82. if (fb->func->intr)
  83. fb->func->intr(fb);
  84. }
  85. static int
  86. nvkm_fb_oneinit(struct nvkm_subdev *subdev)
  87. {
  88. struct nvkm_fb *fb = nvkm_fb(subdev);
  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. return 0;
  97. }
  98. static int
  99. nvkm_fb_init(struct nvkm_subdev *subdev)
  100. {
  101. struct nvkm_fb *fb = nvkm_fb(subdev);
  102. int ret, i;
  103. if (fb->ram) {
  104. ret = nvkm_ram_init(fb->ram);
  105. if (ret)
  106. return ret;
  107. }
  108. for (i = 0; i < fb->tile.regions; i++)
  109. fb->func->tile.prog(fb, i, &fb->tile.region[i]);
  110. if (fb->func->init)
  111. fb->func->init(fb);
  112. return 0;
  113. }
  114. static void *
  115. nvkm_fb_dtor(struct nvkm_subdev *subdev)
  116. {
  117. struct nvkm_fb *fb = nvkm_fb(subdev);
  118. int i;
  119. for (i = 0; i < fb->tile.regions; i++)
  120. fb->func->tile.fini(fb, i, &fb->tile.region[i]);
  121. nvkm_ram_del(&fb->ram);
  122. if (fb->func->dtor)
  123. return fb->func->dtor(fb);
  124. return fb;
  125. }
  126. static const struct nvkm_subdev_func
  127. nvkm_fb = {
  128. .dtor = nvkm_fb_dtor,
  129. .oneinit = nvkm_fb_oneinit,
  130. .init = nvkm_fb_init,
  131. .intr = nvkm_fb_intr,
  132. };
  133. void
  134. nvkm_fb_ctor(const struct nvkm_fb_func *func, struct nvkm_device *device,
  135. int index, struct nvkm_fb *fb)
  136. {
  137. nvkm_subdev_ctor(&nvkm_fb, device, index, 0, &fb->subdev);
  138. fb->func = func;
  139. fb->tile.regions = fb->func->tile.regions;
  140. }
  141. int
  142. nvkm_fb_new_(const struct nvkm_fb_func *func, struct nvkm_device *device,
  143. int index, struct nvkm_fb **pfb)
  144. {
  145. if (!(*pfb = kzalloc(sizeof(**pfb), GFP_KERNEL)))
  146. return -ENOMEM;
  147. nvkm_fb_ctor(func, device, index, *pfb);
  148. return 0;
  149. }