nv10.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (C) 2010 Francisco Jerez.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the
  14. * next paragraph) shall be included in all copies or substantial
  15. * portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. */
  26. #include "nv04.h"
  27. #include "fbmem.h"
  28. #include <subdev/bios.h>
  29. #include <subdev/bios/init.h>
  30. static void
  31. nv10_devinit_meminit(struct nvkm_devinit *init)
  32. {
  33. struct nvkm_subdev *subdev = &init->subdev;
  34. struct nvkm_device *device = subdev->device;
  35. static const int mem_width[] = { 0x10, 0x00, 0x20 };
  36. int mem_width_count;
  37. uint32_t patt = 0xdeadbeef;
  38. struct io_mapping *fb;
  39. int i, j, k;
  40. if (device->card_type >= NV_11 && device->chipset >= 0x17)
  41. mem_width_count = 3;
  42. else
  43. mem_width_count = 2;
  44. /* Map the framebuffer aperture */
  45. fb = fbmem_init(device);
  46. if (!fb) {
  47. nvkm_error(subdev, "failed to map fb\n");
  48. return;
  49. }
  50. nvkm_wr32(device, NV10_PFB_REFCTRL, NV10_PFB_REFCTRL_VALID_1);
  51. /* Probe memory bus width */
  52. for (i = 0; i < mem_width_count; i++) {
  53. nvkm_mask(device, NV04_PFB_CFG0, 0x30, mem_width[i]);
  54. for (j = 0; j < 4; j++) {
  55. for (k = 0; k < 4; k++)
  56. fbmem_poke(fb, 0x1c, 0);
  57. fbmem_poke(fb, 0x1c, patt);
  58. fbmem_poke(fb, 0x3c, 0);
  59. if (fbmem_peek(fb, 0x1c) == patt)
  60. goto mem_width_found;
  61. }
  62. }
  63. mem_width_found:
  64. patt <<= 1;
  65. /* Probe amount of installed memory */
  66. for (i = 0; i < 4; i++) {
  67. int off = nvkm_rd32(device, 0x10020c) - 0x100000;
  68. fbmem_poke(fb, off, patt);
  69. fbmem_poke(fb, 0, 0);
  70. fbmem_peek(fb, 0);
  71. fbmem_peek(fb, 0);
  72. fbmem_peek(fb, 0);
  73. fbmem_peek(fb, 0);
  74. if (fbmem_peek(fb, off) == patt)
  75. goto amount_found;
  76. }
  77. /* IC missing - disable the upper half memory space. */
  78. nvkm_mask(device, NV04_PFB_CFG0, 0x1000, 0);
  79. amount_found:
  80. fbmem_fini(fb);
  81. }
  82. static const struct nvkm_devinit_func
  83. nv10_devinit = {
  84. .dtor = nv04_devinit_dtor,
  85. .preinit = nv04_devinit_preinit,
  86. .post = nv04_devinit_post,
  87. .meminit = nv10_devinit_meminit,
  88. .pll_set = nv04_devinit_pll_set,
  89. };
  90. int
  91. nv10_devinit_new(struct nvkm_device *device, int index,
  92. struct nvkm_devinit **pinit)
  93. {
  94. return nv04_devinit_new_(&nv10_devinit, device, index, pinit);
  95. }