efi-bgrt.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright 2012 Intel Corporation
  3. * Author: Josh Triplett <josh@joshtriplett.org>
  4. *
  5. * Based on the bgrt driver:
  6. * Copyright 2012 Red Hat, Inc <mjg@redhat.com>
  7. * Author: Matthew Garrett
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/acpi.h>
  15. #include <linux/efi.h>
  16. #include <linux/efi-bgrt.h>
  17. struct acpi_table_bgrt *bgrt_tab;
  18. void *bgrt_image;
  19. size_t bgrt_image_size;
  20. struct bmp_header {
  21. u16 id;
  22. u32 size;
  23. } __packed;
  24. void efi_bgrt_init(void)
  25. {
  26. acpi_status status;
  27. void __iomem *image;
  28. bool ioremapped = false;
  29. struct bmp_header bmp_header;
  30. if (acpi_disabled)
  31. return;
  32. status = acpi_get_table("BGRT", 0,
  33. (struct acpi_table_header **)&bgrt_tab);
  34. if (ACPI_FAILURE(status))
  35. return;
  36. if (bgrt_tab->header.length < sizeof(*bgrt_tab))
  37. return;
  38. if (bgrt_tab->version != 1)
  39. return;
  40. if (bgrt_tab->image_type != 0 || !bgrt_tab->image_address)
  41. return;
  42. image = efi_lookup_mapped_addr(bgrt_tab->image_address);
  43. if (!image) {
  44. image = ioremap(bgrt_tab->image_address, sizeof(bmp_header));
  45. ioremapped = true;
  46. if (!image)
  47. return;
  48. }
  49. memcpy_fromio(&bmp_header, image, sizeof(bmp_header));
  50. if (ioremapped)
  51. iounmap(image);
  52. bgrt_image_size = bmp_header.size;
  53. bgrt_image = kmalloc(bgrt_image_size, GFP_KERNEL);
  54. if (!bgrt_image)
  55. return;
  56. if (ioremapped) {
  57. image = ioremap(bgrt_tab->image_address, bmp_header.size);
  58. if (!image) {
  59. kfree(bgrt_image);
  60. bgrt_image = NULL;
  61. return;
  62. }
  63. }
  64. memcpy_fromio(bgrt_image, image, bgrt_image_size);
  65. if (ioremapped)
  66. iounmap(image);
  67. }