chromeos_pstore.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Driver to instantiate Chromebook ramoops device.
  3. //
  4. // Copyright (C) 2013 Google, Inc.
  5. #include <linux/acpi.h>
  6. #include <linux/dmi.h>
  7. #include <linux/module.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/pstore_ram.h>
  10. static const struct dmi_system_id chromeos_pstore_dmi_table[] __initconst = {
  11. {
  12. /*
  13. * Today all Chromebooks/boxes ship with Google_* as version and
  14. * coreboot as bios vendor. No other systems with this
  15. * combination are known to date.
  16. */
  17. .matches = {
  18. DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"),
  19. DMI_MATCH(DMI_BIOS_VERSION, "Google_"),
  20. },
  21. },
  22. {
  23. /* x86-alex, the first Samsung Chromebook. */
  24. .matches = {
  25. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  26. DMI_MATCH(DMI_PRODUCT_NAME, "Alex"),
  27. },
  28. },
  29. {
  30. /* x86-mario, the Cr-48 pilot device from Google. */
  31. .matches = {
  32. DMI_MATCH(DMI_SYS_VENDOR, "IEC"),
  33. DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
  34. },
  35. },
  36. {
  37. /* x86-zgb, the first Acer Chromebook. */
  38. .matches = {
  39. DMI_MATCH(DMI_SYS_VENDOR, "ACER"),
  40. DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"),
  41. },
  42. },
  43. { }
  44. };
  45. MODULE_DEVICE_TABLE(dmi, chromeos_pstore_dmi_table);
  46. /*
  47. * On x86 chromebooks/boxes, the firmware will keep the legacy VGA memory
  48. * range untouched across reboots, so we use that to store our pstore
  49. * contents for panic logs, etc.
  50. */
  51. static struct ramoops_platform_data chromeos_ramoops_data = {
  52. .mem_size = 0x100000,
  53. .mem_address = 0xf00000,
  54. .record_size = 0x40000,
  55. .console_size = 0x20000,
  56. .ftrace_size = 0x20000,
  57. .pmsg_size = 0x20000,
  58. .max_reason = KMSG_DUMP_OOPS,
  59. };
  60. static struct platform_device chromeos_ramoops = {
  61. .name = "ramoops",
  62. .dev = {
  63. .platform_data = &chromeos_ramoops_data,
  64. },
  65. };
  66. #ifdef CONFIG_ACPI
  67. static const struct acpi_device_id cros_ramoops_acpi_match[] = {
  68. { "GOOG9999", 0 },
  69. { }
  70. };
  71. MODULE_DEVICE_TABLE(acpi, cros_ramoops_acpi_match);
  72. static struct platform_driver chromeos_ramoops_acpi = {
  73. .driver = {
  74. .name = "chromeos_pstore",
  75. .acpi_match_table = ACPI_PTR(cros_ramoops_acpi_match),
  76. },
  77. };
  78. static int __init chromeos_probe_acpi(struct platform_device *pdev)
  79. {
  80. struct resource *res;
  81. resource_size_t len;
  82. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  83. if (!res)
  84. return -ENOMEM;
  85. len = resource_size(res);
  86. if (!res->start || !len)
  87. return -ENOMEM;
  88. pr_info("chromeos ramoops using acpi device.\n");
  89. chromeos_ramoops_data.mem_size = len;
  90. chromeos_ramoops_data.mem_address = res->start;
  91. return 0;
  92. }
  93. static bool __init chromeos_check_acpi(void)
  94. {
  95. if (!platform_driver_probe(&chromeos_ramoops_acpi, chromeos_probe_acpi))
  96. return true;
  97. return false;
  98. }
  99. #else
  100. static inline bool chromeos_check_acpi(void) { return false; }
  101. #endif
  102. static int __init chromeos_pstore_init(void)
  103. {
  104. bool acpi_dev_found;
  105. /* First check ACPI for non-hardcoded values from firmware. */
  106. acpi_dev_found = chromeos_check_acpi();
  107. if (acpi_dev_found || dmi_check_system(chromeos_pstore_dmi_table))
  108. return platform_device_register(&chromeos_ramoops);
  109. return -ENODEV;
  110. }
  111. static void __exit chromeos_pstore_exit(void)
  112. {
  113. platform_device_unregister(&chromeos_ramoops);
  114. }
  115. module_init(chromeos_pstore_init);
  116. module_exit(chromeos_pstore_exit);
  117. MODULE_DESCRIPTION("ChromeOS pstore module");
  118. MODULE_LICENSE("GPL v2");