1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * coreboot_table.h
4  *
5  * Internal header for coreboot table access.
6  *
7  * Copyright 2014 Gerd Hoffmann <kraxel@redhat.com>
8  * Copyright 2017 Google Inc.
9  * Copyright 2017 Samuel Holland <samuel@sholland.org>
10  */
11 
12 #ifndef __COREBOOT_TABLE_H
13 #define __COREBOOT_TABLE_H
14 
15 #include <linux/device.h>
16 
17 /* Coreboot table header structure */
18 struct coreboot_table_header {
19 	char signature[4];
20 	u32 header_bytes;
21 	u32 header_checksum;
22 	u32 table_bytes;
23 	u32 table_checksum;
24 	u32 table_entries;
25 };
26 
27 /* List of coreboot entry structures that is used */
28 /* Generic */
29 struct coreboot_table_entry {
30 	u32 tag;
31 	u32 size;
32 };
33 
34 /* Points to a CBMEM entry */
35 struct lb_cbmem_ref {
36 	u32 tag;
37 	u32 size;
38 
39 	u64 cbmem_addr;
40 };
41 
42 #define LB_TAG_CBMEM_ENTRY 0x31
43 
44 /* Corresponds to LB_TAG_CBMEM_ENTRY */
45 struct lb_cbmem_entry {
46 	u32 tag;
47 	u32 size;
48 
49 	u64 address;
50 	u32 entry_size;
51 	u32 id;
52 };
53 
54 /* Describes framebuffer setup by coreboot */
55 struct lb_framebuffer {
56 	u32 tag;
57 	u32 size;
58 
59 	u64 physical_address;
60 	u32 x_resolution;
61 	u32 y_resolution;
62 	u32 bytes_per_line;
63 	u8  bits_per_pixel;
64 	u8  red_mask_pos;
65 	u8  red_mask_size;
66 	u8  green_mask_pos;
67 	u8  green_mask_size;
68 	u8  blue_mask_pos;
69 	u8  blue_mask_size;
70 	u8  reserved_mask_pos;
71 	u8  reserved_mask_size;
72 };
73 
74 /* A device, additionally with information from coreboot. */
75 struct coreboot_device {
76 	struct device dev;
77 	union {
78 		struct coreboot_table_entry entry;
79 		struct lb_cbmem_ref cbmem_ref;
80 		struct lb_cbmem_entry cbmem_entry;
81 		struct lb_framebuffer framebuffer;
82 		DECLARE_FLEX_ARRAY(u8, raw);
83 	};
84 };
85 
dev_to_coreboot_device(struct device * dev)86 static inline struct coreboot_device *dev_to_coreboot_device(struct device *dev)
87 {
88 	return container_of(dev, struct coreboot_device, dev);
89 }
90 
91 /* A driver for handling devices described in coreboot tables. */
92 struct coreboot_driver {
93 	int (*probe)(struct coreboot_device *);
94 	void (*remove)(struct coreboot_device *);
95 	struct device_driver drv;
96 	u32 tag;
97 };
98 
99 /* Register a driver that uses the data from a coreboot table. */
100 int coreboot_driver_register(struct coreboot_driver *driver);
101 
102 /* Unregister a driver that uses the data from a coreboot table. */
103 void coreboot_driver_unregister(struct coreboot_driver *driver);
104 
105 /* module_coreboot_driver() - Helper macro for drivers that don't do
106  * anything special in module init/exit.  This eliminates a lot of
107  * boilerplate.  Each module may only use this macro once, and
108  * calling it replaces module_init() and module_exit()
109  */
110 #define module_coreboot_driver(__coreboot_driver) \
111 	module_driver(__coreboot_driver, coreboot_driver_register, \
112 			coreboot_driver_unregister)
113 
114 #endif /* __COREBOOT_TABLE_H */
115