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