shadowacpi.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #if defined(CONFIG_ACPI) && defined(CONFIG_X86)
  25. int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len);
  26. bool nouveau_acpi_rom_supported(struct device *);
  27. #else
  28. static inline bool
  29. nouveau_acpi_rom_supported(struct device *dev)
  30. {
  31. return false;
  32. }
  33. static inline int
  34. nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len)
  35. {
  36. return -EINVAL;
  37. }
  38. #endif
  39. /* This version of the shadow function disobeys the ACPI spec and tries
  40. * to fetch in units of more than 4KiB at a time. This is a LOT faster
  41. * on some systems, such as Lenovo W530.
  42. */
  43. static u32
  44. acpi_read_fast(void *data, u32 offset, u32 length, struct nvkm_bios *bios)
  45. {
  46. u32 limit = (offset + length + 0xfff) & ~0xfff;
  47. u32 start = offset & ~0x00000fff;
  48. u32 fetch = limit - start;
  49. if (nvbios_extend(bios, limit) >= 0) {
  50. int ret = nouveau_acpi_get_bios_chunk(bios->data, start, fetch);
  51. if (ret == fetch)
  52. return fetch;
  53. }
  54. return 0;
  55. }
  56. /* Other systems, such as the one in fdo#55948, will report a success
  57. * but only return 4KiB of data. The common bios fetching logic will
  58. * detect an invalid image, and fall back to this version of the read
  59. * function.
  60. */
  61. static u32
  62. acpi_read_slow(void *data, u32 offset, u32 length, struct nvkm_bios *bios)
  63. {
  64. u32 limit = (offset + length + 0xfff) & ~0xfff;
  65. u32 start = offset & ~0xfff;
  66. u32 fetch = 0;
  67. if (nvbios_extend(bios, limit) >= 0) {
  68. while (start + fetch < limit) {
  69. int ret = nouveau_acpi_get_bios_chunk(bios->data,
  70. start + fetch,
  71. 0x1000);
  72. if (ret != 0x1000)
  73. break;
  74. fetch += 0x1000;
  75. }
  76. }
  77. return fetch;
  78. }
  79. static void *
  80. acpi_init(struct nvkm_bios *bios, const char *name)
  81. {
  82. if (!nouveau_acpi_rom_supported(bios->subdev.device->dev))
  83. return ERR_PTR(-ENODEV);
  84. return NULL;
  85. }
  86. const struct nvbios_source
  87. nvbios_acpi_fast = {
  88. .name = "ACPI",
  89. .init = acpi_init,
  90. .read = acpi_read_fast,
  91. .rw = false,
  92. .require_checksum = true,
  93. };
  94. const struct nvbios_source
  95. nvbios_acpi_slow = {
  96. .name = "ACPI",
  97. .init = acpi_init,
  98. .read = acpi_read_slow,
  99. .rw = false,
  100. };