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