ramcfg.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright 2013 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 <bskeggs@redhat.com>
  23. */
  24. #include <subdev/bios.h>
  25. #include <subdev/bios/bit.h>
  26. #include <subdev/bios/ramcfg.h>
  27. #include <subdev/bios/M0203.h>
  28. static u8
  29. nvbios_ramcfg_strap(struct nvkm_subdev *subdev)
  30. {
  31. return (nvkm_rd32(subdev->device, 0x101000) & 0x0000003c) >> 2;
  32. }
  33. u8
  34. nvbios_ramcfg_count(struct nvkm_bios *bios)
  35. {
  36. struct bit_entry bit_M;
  37. if (!bit_entry(bios, 'M', &bit_M)) {
  38. if (bit_M.version == 1 && bit_M.length >= 5)
  39. return nvbios_rd08(bios, bit_M.offset + 2);
  40. if (bit_M.version == 2 && bit_M.length >= 3)
  41. return nvbios_rd08(bios, bit_M.offset + 0);
  42. }
  43. return 0x00;
  44. }
  45. u8
  46. nvbios_ramcfg_index(struct nvkm_subdev *subdev)
  47. {
  48. struct nvkm_bios *bios = subdev->device->bios;
  49. u8 strap = nvbios_ramcfg_strap(subdev);
  50. u32 xlat = 0x00000000;
  51. struct bit_entry bit_M;
  52. struct nvbios_M0203E M0203E;
  53. u8 ver, hdr;
  54. if (!bit_entry(bios, 'M', &bit_M)) {
  55. if (bit_M.version == 1 && bit_M.length >= 5)
  56. xlat = nvbios_rd16(bios, bit_M.offset + 3);
  57. if (bit_M.version == 2 && bit_M.length >= 3) {
  58. /*XXX: is M ever shorter than this?
  59. * if not - what is xlat used for now?
  60. * also - sigh..
  61. */
  62. if (bit_M.length >= 7 &&
  63. nvbios_M0203Em(bios, strap, &ver, &hdr, &M0203E))
  64. return M0203E.group;
  65. xlat = nvbios_rd16(bios, bit_M.offset + 1);
  66. }
  67. }
  68. if (xlat)
  69. strap = nvbios_rd08(bios, xlat + strap);
  70. return strap;
  71. }