4 * Module providing coreboot table access.
6 * Copyright 2017 Google Inc.
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.
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.
18 #include <linux/err.h>
19 #include <linux/init.h>
21 #include <linux/kernel.h>
22 #include <linux/module.h>
24 #include "coreboot_table.h"
26 struct coreboot_table_entry
{
31 static struct coreboot_table_header __iomem
*ptr_header
;
34 * This function parses the coreboot table for an entry that contains the base
35 * address of the given entry tag. The coreboot table consists of a header
36 * directly followed by a number of small, variable-sized entries, which each
37 * contain an identifying tag and their length as the first two fields.
39 int coreboot_table_find(int tag
, void *data
, size_t data_size
)
41 struct coreboot_table_header header
;
42 struct coreboot_table_entry entry
;
49 memcpy_fromio(&header
, ptr_header
, sizeof(header
));
51 if (strncmp(header
.signature
, "LBIO", sizeof(header
.signature
))) {
52 pr_warn("coreboot_table: coreboot table missing or corrupt!\n");
56 ptr_entry
= (void *)ptr_header
+ header
.header_bytes
;
58 for (i
= 0; i
< header
.table_entries
; i
++) {
59 memcpy_fromio(&entry
, ptr_entry
, sizeof(entry
));
60 if (entry
.tag
== tag
) {
61 if (data_size
< entry
.size
)
64 memcpy_fromio(data
, ptr_entry
, entry
.size
);
69 ptr_entry
+= entry
.size
;
74 EXPORT_SYMBOL(coreboot_table_find
);
76 int coreboot_table_init(void __iomem
*ptr
)
82 EXPORT_SYMBOL(coreboot_table_init
);
84 int coreboot_table_exit(void)
91 EXPORT_SYMBOL(coreboot_table_exit
);
93 MODULE_AUTHOR("Google, Inc.");
94 MODULE_LICENSE("GPL");