coreboot_table-acpi.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * coreboot_table-acpi.c
  3. *
  4. * Using ACPI to locate Coreboot table and provide coreboot table access.
  5. *
  6. * Copyright 2017 Google Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License v2.0 as published by
  10. * the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/acpi.h>
  18. #include <linux/device.h>
  19. #include <linux/err.h>
  20. #include <linux/init.h>
  21. #include <linux/io.h>
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/platform_device.h>
  25. #include "coreboot_table.h"
  26. static int coreboot_table_acpi_probe(struct platform_device *pdev)
  27. {
  28. phys_addr_t phyaddr;
  29. resource_size_t len;
  30. struct coreboot_table_header __iomem *header = NULL;
  31. struct resource *res;
  32. void __iomem *ptr = NULL;
  33. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  34. if (!res)
  35. return -EINVAL;
  36. len = resource_size(res);
  37. if (!res->start || !len)
  38. return -EINVAL;
  39. phyaddr = res->start;
  40. header = ioremap_cache(phyaddr, sizeof(*header));
  41. if (header == NULL)
  42. return -ENOMEM;
  43. ptr = ioremap_cache(phyaddr,
  44. header->header_bytes + header->table_bytes);
  45. iounmap(header);
  46. if (!ptr)
  47. return -ENOMEM;
  48. return coreboot_table_init(&pdev->dev, ptr);
  49. }
  50. static int coreboot_table_acpi_remove(struct platform_device *pdev)
  51. {
  52. return coreboot_table_exit();
  53. }
  54. static const struct acpi_device_id cros_coreboot_acpi_match[] = {
  55. { "GOOGCB00", 0 },
  56. { "BOOT0000", 0 },
  57. { }
  58. };
  59. MODULE_DEVICE_TABLE(acpi, cros_coreboot_acpi_match);
  60. static struct platform_driver coreboot_table_acpi_driver = {
  61. .probe = coreboot_table_acpi_probe,
  62. .remove = coreboot_table_acpi_remove,
  63. .driver = {
  64. .name = "coreboot_table_acpi",
  65. .acpi_match_table = ACPI_PTR(cros_coreboot_acpi_match),
  66. },
  67. };
  68. static int __init coreboot_table_acpi_init(void)
  69. {
  70. return platform_driver_register(&coreboot_table_acpi_driver);
  71. }
  72. module_init(coreboot_table_acpi_init);
  73. MODULE_AUTHOR("Google, Inc.");
  74. MODULE_LICENSE("GPL");