coreboot_table-of.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * coreboot_table-of.c
  3. *
  4. * Coreboot table access through open firmware.
  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/device.h>
  18. #include <linux/io.h>
  19. #include <linux/module.h>
  20. #include <linux/of_address.h>
  21. #include <linux/of_platform.h>
  22. #include <linux/platform_device.h>
  23. #include "coreboot_table.h"
  24. static int coreboot_table_of_probe(struct platform_device *pdev)
  25. {
  26. struct device_node *fw_dn = pdev->dev.of_node;
  27. void __iomem *ptr;
  28. ptr = of_iomap(fw_dn, 0);
  29. of_node_put(fw_dn);
  30. if (!ptr)
  31. return -ENOMEM;
  32. return coreboot_table_init(&pdev->dev, ptr);
  33. }
  34. static int coreboot_table_of_remove(struct platform_device *pdev)
  35. {
  36. return coreboot_table_exit();
  37. }
  38. static const struct of_device_id coreboot_of_match[] = {
  39. { .compatible = "coreboot" },
  40. {},
  41. };
  42. static struct platform_driver coreboot_table_of_driver = {
  43. .probe = coreboot_table_of_probe,
  44. .remove = coreboot_table_of_remove,
  45. .driver = {
  46. .name = "coreboot_table_of",
  47. .of_match_table = coreboot_of_match,
  48. },
  49. };
  50. static int __init platform_coreboot_table_of_init(void)
  51. {
  52. struct platform_device *pdev;
  53. struct device_node *of_node;
  54. /* Limit device creation to the presence of /firmware/coreboot node */
  55. of_node = of_find_node_by_path("/firmware/coreboot");
  56. if (!of_node)
  57. return -ENODEV;
  58. if (!of_match_node(coreboot_of_match, of_node))
  59. return -ENODEV;
  60. pdev = of_platform_device_create(of_node, "coreboot_table_of", NULL);
  61. if (!pdev)
  62. return -ENODEV;
  63. return platform_driver_register(&coreboot_table_of_driver);
  64. }
  65. module_init(platform_coreboot_table_of_init);
  66. MODULE_AUTHOR("Google, Inc.");
  67. MODULE_LICENSE("GPL");