pmu.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright 2014 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/image.h>
  27. #include <subdev/bios/pmu.h>
  28. u32
  29. nvbios_pmuTe(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
  30. {
  31. struct bit_entry bit_p;
  32. u32 data = 0;
  33. if (!bit_entry(bios, 'p', &bit_p)) {
  34. if (bit_p.version == 2 && bit_p.length >= 4)
  35. data = nvbios_rd32(bios, bit_p.offset + 0x00);
  36. if (data) {
  37. *ver = nvbios_rd08(bios, data + 0x00); /* maybe? */
  38. *hdr = nvbios_rd08(bios, data + 0x01);
  39. *len = nvbios_rd08(bios, data + 0x02);
  40. *cnt = nvbios_rd08(bios, data + 0x03);
  41. }
  42. }
  43. return data;
  44. }
  45. u32
  46. nvbios_pmuEe(struct nvkm_bios *bios, int idx, u8 *ver, u8 *hdr)
  47. {
  48. u8 cnt, len;
  49. u32 data = nvbios_pmuTe(bios, ver, hdr, &cnt, &len);
  50. if (data && idx < cnt) {
  51. data = data + *hdr + (idx * len);
  52. *hdr = len;
  53. return data;
  54. }
  55. return 0;
  56. }
  57. u32
  58. nvbios_pmuEp(struct nvkm_bios *bios, int idx, u8 *ver, u8 *hdr,
  59. struct nvbios_pmuE *info)
  60. {
  61. u32 data = nvbios_pmuEe(bios, idx, ver, hdr);
  62. memset(info, 0x00, sizeof(*info));
  63. switch (!!data * *ver) {
  64. default:
  65. info->type = nvbios_rd08(bios, data + 0x00);
  66. info->data = nvbios_rd32(bios, data + 0x02);
  67. break;
  68. }
  69. return data;
  70. }
  71. bool
  72. nvbios_pmuRm(struct nvkm_bios *bios, u8 type, struct nvbios_pmuR *info)
  73. {
  74. struct nvbios_pmuE pmuE;
  75. u8 ver, hdr, idx = 0;
  76. u32 data;
  77. memset(info, 0x00, sizeof(*info));
  78. while ((data = nvbios_pmuEp(bios, idx++, &ver, &hdr, &pmuE))) {
  79. if (pmuE.type == type && (data = pmuE.data)) {
  80. info->init_addr_pmu = nvbios_rd32(bios, data + 0x08);
  81. info->args_addr_pmu = nvbios_rd32(bios, data + 0x0c);
  82. info->boot_addr = data + 0x30;
  83. info->boot_addr_pmu = nvbios_rd32(bios, data + 0x10) +
  84. nvbios_rd32(bios, data + 0x18);
  85. info->boot_size = nvbios_rd32(bios, data + 0x1c) -
  86. nvbios_rd32(bios, data + 0x18);
  87. info->code_addr = info->boot_addr + info->boot_size;
  88. info->code_addr_pmu = info->boot_addr_pmu +
  89. info->boot_size;
  90. info->code_size = nvbios_rd32(bios, data + 0x20);
  91. info->data_addr = data + 0x30 +
  92. nvbios_rd32(bios, data + 0x24);
  93. info->data_addr_pmu = nvbios_rd32(bios, data + 0x28);
  94. info->data_size = nvbios_rd32(bios, data + 0x2c);
  95. return true;
  96. }
  97. }
  98. return false;
  99. }