shadowramin.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. */
  23. #include "priv.h"
  24. struct priv {
  25. struct nvkm_bios *bios;
  26. u32 bar0;
  27. };
  28. static u32
  29. pramin_read(void *data, u32 offset, u32 length, struct nvkm_bios *bios)
  30. {
  31. struct nvkm_device *device = bios->subdev.device;
  32. u32 i;
  33. if (offset + length <= 0x00100000) {
  34. for (i = offset; i < offset + length; i += 4)
  35. *(u32 *)&bios->data[i] = nvkm_rd32(device, 0x700000 + i);
  36. return length;
  37. }
  38. return 0;
  39. }
  40. static void
  41. pramin_fini(void *data)
  42. {
  43. struct priv *priv = data;
  44. if (priv) {
  45. struct nvkm_device *device = priv->bios->subdev.device;
  46. nvkm_wr32(device, 0x001700, priv->bar0);
  47. kfree(priv);
  48. }
  49. }
  50. static void *
  51. pramin_init(struct nvkm_bios *bios, const char *name)
  52. {
  53. struct nvkm_subdev *subdev = &bios->subdev;
  54. struct nvkm_device *device = subdev->device;
  55. struct priv *priv = NULL;
  56. u64 addr = 0;
  57. /* PRAMIN always potentially available prior to nv50 */
  58. if (device->card_type < NV_50)
  59. return NULL;
  60. /* we can't get the bios image pointer without PDISP */
  61. if (device->card_type >= GM100)
  62. addr = nvkm_rd32(device, 0x021c04);
  63. else
  64. if (device->card_type >= NV_C0)
  65. addr = nvkm_rd32(device, 0x022500);
  66. if (addr & 0x00000001) {
  67. nvkm_debug(subdev, "... display disabled\n");
  68. return ERR_PTR(-ENODEV);
  69. }
  70. /* check that the window is enabled and in vram, particularly
  71. * important as we don't want to be touching vram on an
  72. * uninitialised board
  73. */
  74. addr = nvkm_rd32(device, 0x619f04);
  75. if (!(addr & 0x00000008)) {
  76. nvkm_debug(subdev, "... not enabled\n");
  77. return ERR_PTR(-ENODEV);
  78. }
  79. if ( (addr & 0x00000003) != 1) {
  80. nvkm_debug(subdev, "... not in vram\n");
  81. return ERR_PTR(-ENODEV);
  82. }
  83. /* some alternate method inherited from xf86-video-nv... */
  84. addr = (addr & 0xffffff00) << 8;
  85. if (!addr) {
  86. addr = (u64)nvkm_rd32(device, 0x001700) << 16;
  87. addr += 0xf0000;
  88. }
  89. /* modify bar0 PRAMIN window to cover the bios image */
  90. if (!(priv = kmalloc(sizeof(*priv), GFP_KERNEL))) {
  91. nvkm_error(subdev, "... out of memory\n");
  92. return ERR_PTR(-ENOMEM);
  93. }
  94. priv->bios = bios;
  95. priv->bar0 = nvkm_rd32(device, 0x001700);
  96. nvkm_wr32(device, 0x001700, addr >> 16);
  97. return priv;
  98. }
  99. const struct nvbios_source
  100. nvbios_ramin = {
  101. .name = "PRAMIN",
  102. .init = pramin_init,
  103. .fini = pramin_fini,
  104. .read = pramin_read,
  105. .rw = true,
  106. };