• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
coreboot_table_acpi_probe(struct platform_device * pdev)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(ptr);
57 }
58 
coreboot_table_acpi_remove(struct platform_device * pdev)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 
coreboot_table_acpi_init(void)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");
89