Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 // Driver to instantiate Chromebook ramoops device.
0003 //
0004 // Copyright (C) 2013 Google, Inc.
0005 
0006 #include <linux/acpi.h>
0007 #include <linux/dmi.h>
0008 #include <linux/module.h>
0009 #include <linux/platform_device.h>
0010 #include <linux/pstore_ram.h>
0011 
0012 static const struct dmi_system_id chromeos_pstore_dmi_table[] __initconst = {
0013     {
0014         /*
0015          * Today all Chromebooks/boxes ship with Google_* as version and
0016          * coreboot as bios vendor. No other systems with this
0017          * combination are known to date.
0018          */
0019         .matches = {
0020             DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"),
0021             DMI_MATCH(DMI_BIOS_VERSION, "Google_"),
0022         },
0023     },
0024     {
0025         /* x86-alex, the first Samsung Chromebook. */
0026         .matches = {
0027             DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
0028             DMI_MATCH(DMI_PRODUCT_NAME, "Alex"),
0029         },
0030     },
0031     {
0032         /* x86-mario, the Cr-48 pilot device from Google. */
0033         .matches = {
0034             DMI_MATCH(DMI_SYS_VENDOR, "IEC"),
0035             DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
0036         },
0037     },
0038     {
0039         /* x86-zgb, the first Acer Chromebook. */
0040         .matches = {
0041             DMI_MATCH(DMI_SYS_VENDOR, "ACER"),
0042             DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"),
0043         },
0044     },
0045     { }
0046 };
0047 MODULE_DEVICE_TABLE(dmi, chromeos_pstore_dmi_table);
0048 
0049 /*
0050  * On x86 chromebooks/boxes, the firmware will keep the legacy VGA memory
0051  * range untouched across reboots, so we use that to store our pstore
0052  * contents for panic logs, etc.
0053  */
0054 static struct ramoops_platform_data chromeos_ramoops_data = {
0055     .mem_size   = 0x100000,
0056     .mem_address    = 0xf00000,
0057     .record_size    = 0x40000,
0058     .console_size   = 0x20000,
0059     .ftrace_size    = 0x20000,
0060     .pmsg_size  = 0x20000,
0061     .max_reason = KMSG_DUMP_OOPS,
0062 };
0063 
0064 static struct platform_device chromeos_ramoops = {
0065     .name = "ramoops",
0066     .dev = {
0067         .platform_data = &chromeos_ramoops_data,
0068     },
0069 };
0070 
0071 #ifdef CONFIG_ACPI
0072 static const struct acpi_device_id cros_ramoops_acpi_match[] = {
0073     { "GOOG9999", 0 },
0074     { }
0075 };
0076 MODULE_DEVICE_TABLE(acpi, cros_ramoops_acpi_match);
0077 
0078 static struct platform_driver chromeos_ramoops_acpi = {
0079     .driver     = {
0080         .name   = "chromeos_pstore",
0081         .acpi_match_table = ACPI_PTR(cros_ramoops_acpi_match),
0082     },
0083 };
0084 
0085 static int __init chromeos_probe_acpi(struct platform_device *pdev)
0086 {
0087     struct resource *res;
0088     resource_size_t len;
0089 
0090     res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
0091     if (!res)
0092         return -ENOMEM;
0093 
0094     len = resource_size(res);
0095     if (!res->start || !len)
0096         return -ENOMEM;
0097 
0098     pr_info("chromeos ramoops using acpi device.\n");
0099 
0100     chromeos_ramoops_data.mem_size = len;
0101     chromeos_ramoops_data.mem_address = res->start;
0102 
0103     return 0;
0104 }
0105 
0106 static bool __init chromeos_check_acpi(void)
0107 {
0108     if (!platform_driver_probe(&chromeos_ramoops_acpi, chromeos_probe_acpi))
0109         return true;
0110     return false;
0111 }
0112 #else
0113 static inline bool chromeos_check_acpi(void) { return false; }
0114 #endif
0115 
0116 static int __init chromeos_pstore_init(void)
0117 {
0118     bool acpi_dev_found;
0119 
0120     /* First check ACPI for non-hardcoded values from firmware. */
0121     acpi_dev_found = chromeos_check_acpi();
0122 
0123     if (acpi_dev_found || dmi_check_system(chromeos_pstore_dmi_table))
0124         return platform_device_register(&chromeos_ramoops);
0125 
0126     return -ENODEV;
0127 }
0128 
0129 static void __exit chromeos_pstore_exit(void)
0130 {
0131     platform_device_unregister(&chromeos_ramoops);
0132 }
0133 
0134 module_init(chromeos_pstore_init);
0135 module_exit(chromeos_pstore_exit);
0136 
0137 MODULE_DESCRIPTION("ChromeOS pstore module");
0138 MODULE_LICENSE("GPL v2");