The CBMEM area is a downward-growing memory region used by coreboot to dynamically allocate tagged data structures ("CBMEM entries") that remain resident during boot. This implements a driver which exports access to the CBMEM entries via sysfs under /sys/bus/coreboot/devices/cbmem-<id>. This implementation is quite versatile. Examples of how it could be used are given below: * Tools like util/cbmem from the coreboot tree could use this driver instead of finding CBMEM in /dev/mem directly. Alternatively, firmware developers debugging an issue may find the sysfs interface more ergonomic than the cbmem tool and choose to use it directly. * The crossystem tool, which exposes verified boot variables, can use this driver to read the vboot work buffer. * Tools which read the BIOS SPI flash (e.g., flashrom) can find the flash layout in CBMEM directly, which is significantly faster than searching the flash directly. Write access is provided to all CBMEM regions via /sys/bus/coreboot/devices/cbmem-<id>/mem, as the existing cbmem tooling updates this memory region, and envisioned use cases with crossystem can benefit from updating memory regions. Link: https://issuetracker.google.com/239604743 Cc: Stephen Boyd <swboyd@chromium.org> Cc: Tzung-Bi Shih <tzungbi@kernel.org> Reviewed-by: Guenter Roeck <groeck@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org> Tested-by: Jack Rosenthal <jrosenth@chromium.org> Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Link: https://lore.kernel.org/r/20221104161528.531248-1-jrosenth@chromium.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
113 lines
2.5 KiB
C
113 lines
2.5 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/*
|
|
* coreboot_table.h
|
|
*
|
|
* Internal header for coreboot table access.
|
|
*
|
|
* Copyright 2014 Gerd Hoffmann <kraxel@redhat.com>
|
|
* Copyright 2017 Google Inc.
|
|
* Copyright 2017 Samuel Holland <samuel@sholland.org>
|
|
*/
|
|
|
|
#ifndef __COREBOOT_TABLE_H
|
|
#define __COREBOOT_TABLE_H
|
|
|
|
#include <linux/device.h>
|
|
|
|
/* Coreboot table header structure */
|
|
struct coreboot_table_header {
|
|
char signature[4];
|
|
u32 header_bytes;
|
|
u32 header_checksum;
|
|
u32 table_bytes;
|
|
u32 table_checksum;
|
|
u32 table_entries;
|
|
};
|
|
|
|
/* List of coreboot entry structures that is used */
|
|
/* Generic */
|
|
struct coreboot_table_entry {
|
|
u32 tag;
|
|
u32 size;
|
|
};
|
|
|
|
/* Points to a CBMEM entry */
|
|
struct lb_cbmem_ref {
|
|
u32 tag;
|
|
u32 size;
|
|
|
|
u64 cbmem_addr;
|
|
};
|
|
|
|
#define LB_TAG_CBMEM_ENTRY 0x31
|
|
|
|
/* Corresponds to LB_TAG_CBMEM_ENTRY */
|
|
struct lb_cbmem_entry {
|
|
u32 tag;
|
|
u32 size;
|
|
|
|
u64 address;
|
|
u32 entry_size;
|
|
u32 id;
|
|
};
|
|
|
|
/* Describes framebuffer setup by coreboot */
|
|
struct lb_framebuffer {
|
|
u32 tag;
|
|
u32 size;
|
|
|
|
u64 physical_address;
|
|
u32 x_resolution;
|
|
u32 y_resolution;
|
|
u32 bytes_per_line;
|
|
u8 bits_per_pixel;
|
|
u8 red_mask_pos;
|
|
u8 red_mask_size;
|
|
u8 green_mask_pos;
|
|
u8 green_mask_size;
|
|
u8 blue_mask_pos;
|
|
u8 blue_mask_size;
|
|
u8 reserved_mask_pos;
|
|
u8 reserved_mask_size;
|
|
};
|
|
|
|
/* A device, additionally with information from coreboot. */
|
|
struct coreboot_device {
|
|
struct device dev;
|
|
union {
|
|
struct coreboot_table_entry entry;
|
|
struct lb_cbmem_ref cbmem_ref;
|
|
struct lb_cbmem_entry cbmem_entry;
|
|
struct lb_framebuffer framebuffer;
|
|
};
|
|
};
|
|
|
|
static inline struct coreboot_device *dev_to_coreboot_device(struct device *dev)
|
|
{
|
|
return container_of(dev, struct coreboot_device, dev);
|
|
}
|
|
|
|
/* A driver for handling devices described in coreboot tables. */
|
|
struct coreboot_driver {
|
|
int (*probe)(struct coreboot_device *);
|
|
void (*remove)(struct coreboot_device *);
|
|
struct device_driver drv;
|
|
u32 tag;
|
|
};
|
|
|
|
/* Register a driver that uses the data from a coreboot table. */
|
|
int coreboot_driver_register(struct coreboot_driver *driver);
|
|
|
|
/* Unregister a driver that uses the data from a coreboot table. */
|
|
void coreboot_driver_unregister(struct coreboot_driver *driver);
|
|
|
|
/* module_coreboot_driver() - Helper macro for drivers that don't do
|
|
* anything special in module init/exit. This eliminates a lot of
|
|
* boilerplate. Each module may only use this macro once, and
|
|
* calling it replaces module_init() and module_exit()
|
|
*/
|
|
#define module_coreboot_driver(__coreboot_driver) \
|
|
module_driver(__coreboot_driver, coreboot_driver_register, \
|
|
coreboot_driver_unregister)
|
|
|
|
#endif /* __COREBOOT_TABLE_H */
|