Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

firmware: coreboot: Collapse platform drivers into bus core

The DT based and ACPI based platform drivers here do the same thing; map
some memory and hand it over to the coreboot bus to populate devices.
The only major difference is that the DT based driver doesn't map the
coreboot table header to figure out how large of a region to map for the
whole coreboot table and it uses of_iomap() instead of ioremap_cache().
A cached or non-cached mapping shouldn't matter here and mapping some
smaller region first before mapping the whole table is just more work
but should be OK. In the end, we can remove two files and combine the
code all in one place making it easier to reason about things.

We leave the old Kconfigs in place for a little while longer but make
them hidden and select the previously hidden config option. This way
users can upgrade without having to know to reselect this config in the
future. Later on we can remove the old hidden configs.

Cc: Wei-Ning Huang <wnhuang@chromium.org>
Cc: Julius Werner <jwerner@chromium.org>
Cc: Brian Norris <briannorris@chromium.org>
Cc: Samuel Holland <samuel@sholland.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Stephen Boyd and committed by
Greg Kroah-Hartman
a28aad66 b81e3140

+73 -177
+11 -17
drivers/firmware/google/Kconfig
··· 19 19 variables. 20 20 21 21 config GOOGLE_COREBOOT_TABLE 22 - tristate 23 - depends on GOOGLE_COREBOOT_TABLE_ACPI || GOOGLE_COREBOOT_TABLE_OF 24 - 25 - config GOOGLE_COREBOOT_TABLE_ACPI 26 - tristate "Coreboot Table Access - ACPI" 27 - depends on ACPI 28 - select GOOGLE_COREBOOT_TABLE 22 + tristate "Coreboot Table Access" 23 + depends on ACPI || OF 29 24 help 30 25 This option enables the coreboot_table module, which provides other 31 - firmware modules to access to the coreboot table. The coreboot table 32 - pointer is accessed through the ACPI "GOOGCB00" object. 26 + firmware modules access to the coreboot table. The coreboot table 27 + pointer is accessed through the ACPI "GOOGCB00" object or the 28 + device tree node /firmware/coreboot. 33 29 If unsure say N. 34 30 35 - config GOOGLE_COREBOOT_TABLE_OF 36 - tristate "Coreboot Table Access - Device Tree" 37 - depends on OF 31 + config GOOGLE_COREBOOT_TABLE_ACPI 32 + tristate 38 33 select GOOGLE_COREBOOT_TABLE 39 - help 40 - This option enable the coreboot_table module, which provide other 41 - firmware modules to access coreboot table. The coreboot table pointer 42 - is accessed through the device tree node /firmware/coreboot. 43 - If unsure say N. 34 + 35 + config GOOGLE_COREBOOT_TABLE_OF 36 + tristate 37 + select GOOGLE_COREBOOT_TABLE 44 38 45 39 config GOOGLE_MEMCONSOLE 46 40 tristate
-2
drivers/firmware/google/Makefile
··· 2 2 3 3 obj-$(CONFIG_GOOGLE_SMI) += gsmi.o 4 4 obj-$(CONFIG_GOOGLE_COREBOOT_TABLE) += coreboot_table.o 5 - obj-$(CONFIG_GOOGLE_COREBOOT_TABLE_ACPI) += coreboot_table-acpi.o 6 - obj-$(CONFIG_GOOGLE_COREBOOT_TABLE_OF) += coreboot_table-of.o 7 5 obj-$(CONFIG_GOOGLE_FRAMEBUFFER_COREBOOT) += framebuffer-coreboot.o 8 6 obj-$(CONFIG_GOOGLE_MEMCONSOLE) += memconsole.o 9 7 obj-$(CONFIG_GOOGLE_MEMCONSOLE_COREBOOT) += memconsole-coreboot.o
-88
drivers/firmware/google/coreboot_table-acpi.c
··· 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 - 18 - #include <linux/acpi.h> 19 - #include <linux/device.h> 20 - #include <linux/err.h> 21 - #include <linux/init.h> 22 - #include <linux/io.h> 23 - #include <linux/kernel.h> 24 - #include <linux/module.h> 25 - #include <linux/platform_device.h> 26 - 27 - #include "coreboot_table.h" 28 - 29 - static int coreboot_table_acpi_probe(struct platform_device *pdev) 30 - { 31 - phys_addr_t phyaddr; 32 - resource_size_t len; 33 - struct coreboot_table_header __iomem *header = NULL; 34 - struct resource *res; 35 - void __iomem *ptr = NULL; 36 - 37 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 38 - if (!res) 39 - return -EINVAL; 40 - 41 - len = resource_size(res); 42 - if (!res->start || !len) 43 - return -EINVAL; 44 - 45 - phyaddr = res->start; 46 - header = ioremap_cache(phyaddr, sizeof(*header)); 47 - if (header == NULL) 48 - return -ENOMEM; 49 - 50 - ptr = ioremap_cache(phyaddr, 51 - header->header_bytes + header->table_bytes); 52 - iounmap(header); 53 - if (!ptr) 54 - return -ENOMEM; 55 - 56 - return coreboot_table_init(&pdev->dev, ptr); 57 - } 58 - 59 - static int coreboot_table_acpi_remove(struct platform_device *pdev) 60 - { 61 - return coreboot_table_exit(); 62 - } 63 - 64 - static const struct acpi_device_id cros_coreboot_acpi_match[] = { 65 - { "GOOGCB00", 0 }, 66 - { "BOOT0000", 0 }, 67 - { } 68 - }; 69 - MODULE_DEVICE_TABLE(acpi, cros_coreboot_acpi_match); 70 - 71 - static struct platform_driver coreboot_table_acpi_driver = { 72 - .probe = coreboot_table_acpi_probe, 73 - .remove = coreboot_table_acpi_remove, 74 - .driver = { 75 - .name = "coreboot_table_acpi", 76 - .acpi_match_table = ACPI_PTR(cros_coreboot_acpi_match), 77 - }, 78 - }; 79 - 80 - static int __init coreboot_table_acpi_init(void) 81 - { 82 - return platform_driver_register(&coreboot_table_acpi_driver); 83 - } 84 - 85 - module_init(coreboot_table_acpi_init); 86 - 87 - MODULE_AUTHOR("Google, Inc."); 88 - MODULE_LICENSE("GPL");
-60
drivers/firmware/google/coreboot_table-of.c
··· 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 - 18 - #include <linux/device.h> 19 - #include <linux/io.h> 20 - #include <linux/module.h> 21 - #include <linux/of_address.h> 22 - #include <linux/platform_device.h> 23 - 24 - #include "coreboot_table.h" 25 - 26 - static int coreboot_table_of_probe(struct platform_device *pdev) 27 - { 28 - struct device_node *fw_dn = pdev->dev.of_node; 29 - void __iomem *ptr; 30 - 31 - ptr = of_iomap(fw_dn, 0); 32 - if (!ptr) 33 - return -ENOMEM; 34 - 35 - return coreboot_table_init(&pdev->dev, ptr); 36 - } 37 - 38 - static int coreboot_table_of_remove(struct platform_device *pdev) 39 - { 40 - return coreboot_table_exit(); 41 - } 42 - 43 - static const struct of_device_id coreboot_of_match[] = { 44 - { .compatible = "coreboot" }, 45 - {} 46 - }; 47 - MODULE_DEVICE_TABLE(of, coreboot_of_match); 48 - 49 - static struct platform_driver coreboot_table_of_driver = { 50 - .probe = coreboot_table_of_probe, 51 - .remove = coreboot_table_of_remove, 52 - .driver = { 53 - .name = "coreboot_table_of", 54 - .of_match_table = coreboot_of_match, 55 - }, 56 - }; 57 - module_platform_driver(coreboot_table_of_driver); 58 - 59 - MODULE_AUTHOR("Google, Inc."); 60 - MODULE_LICENSE("GPL");
+62 -4
drivers/firmware/google/coreboot_table.c
··· 16 16 * GNU General Public License for more details. 17 17 */ 18 18 19 + #include <linux/acpi.h> 19 20 #include <linux/device.h> 20 21 #include <linux/err.h> 21 22 #include <linux/init.h> 22 23 #include <linux/io.h> 23 24 #include <linux/kernel.h> 24 25 #include <linux/module.h> 26 + #include <linux/of.h> 27 + #include <linux/platform_device.h> 25 28 #include <linux/slab.h> 26 29 27 30 #include "coreboot_table.h" ··· 94 91 } 95 92 EXPORT_SYMBOL(coreboot_driver_unregister); 96 93 97 - int coreboot_table_init(struct device *dev, void __iomem *ptr) 94 + static int coreboot_table_init(struct device *dev, void __iomem *ptr) 98 95 { 99 96 int i, ret; 100 97 void *ptr_entry; ··· 147 144 iounmap(ptr); 148 145 return ret; 149 146 } 150 - EXPORT_SYMBOL(coreboot_table_init); 151 147 152 - int coreboot_table_exit(void) 148 + static int coreboot_table_probe(struct platform_device *pdev) 149 + { 150 + phys_addr_t phyaddr; 151 + resource_size_t len; 152 + struct coreboot_table_header __iomem *header = NULL; 153 + struct resource *res; 154 + void __iomem *ptr = NULL; 155 + 156 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 157 + if (!res) 158 + return -EINVAL; 159 + 160 + len = resource_size(res); 161 + if (!res->start || !len) 162 + return -EINVAL; 163 + 164 + phyaddr = res->start; 165 + header = ioremap_cache(phyaddr, sizeof(*header)); 166 + if (header == NULL) 167 + return -ENOMEM; 168 + 169 + ptr = ioremap_cache(phyaddr, 170 + header->header_bytes + header->table_bytes); 171 + iounmap(header); 172 + if (!ptr) 173 + return -ENOMEM; 174 + 175 + return coreboot_table_init(&pdev->dev, ptr); 176 + } 177 + 178 + static int coreboot_table_remove(struct platform_device *pdev) 153 179 { 154 180 if (ptr_header) { 155 181 bus_unregister(&coreboot_bus_type); ··· 187 155 188 156 return 0; 189 157 } 190 - EXPORT_SYMBOL(coreboot_table_exit); 191 158 159 + #ifdef CONFIG_ACPI 160 + static const struct acpi_device_id cros_coreboot_acpi_match[] = { 161 + { "GOOGCB00", 0 }, 162 + { "BOOT0000", 0 }, 163 + { } 164 + }; 165 + MODULE_DEVICE_TABLE(acpi, cros_coreboot_acpi_match); 166 + #endif 167 + 168 + #ifdef CONFIG_OF 169 + static const struct of_device_id coreboot_of_match[] = { 170 + { .compatible = "coreboot" }, 171 + {} 172 + }; 173 + MODULE_DEVICE_TABLE(of, coreboot_of_match); 174 + #endif 175 + 176 + static struct platform_driver coreboot_table_driver = { 177 + .probe = coreboot_table_probe, 178 + .remove = coreboot_table_remove, 179 + .driver = { 180 + .name = "coreboot_table", 181 + .acpi_match_table = ACPI_PTR(cros_coreboot_acpi_match), 182 + .of_match_table = of_match_ptr(coreboot_of_match), 183 + }, 184 + }; 185 + module_platform_driver(coreboot_table_driver); 192 186 MODULE_AUTHOR("Google, Inc."); 193 187 MODULE_LICENSE("GPL");
-6
drivers/firmware/google/coreboot_table.h
··· 91 91 /* Unregister a driver that uses the data from a coreboot table. */ 92 92 void coreboot_driver_unregister(struct coreboot_driver *driver); 93 93 94 - /* Initialize coreboot table module given a pointer to iomem */ 95 - int coreboot_table_init(struct device *dev, void __iomem *ptr); 96 - 97 - /* Cleanup coreboot table module */ 98 - int coreboot_table_exit(void); 99 - 100 94 #endif /* __COREBOOT_TABLE_H */