1*44e33a5aSSean Rhodes /* SPDX-License-Identifier: GPL-2.0-only */ 2*44e33a5aSSean Rhodes /* 3*44e33a5aSSean Rhodes * coreboot_table.h 4*44e33a5aSSean Rhodes * 5*44e33a5aSSean Rhodes * Internal header for coreboot table access. 6*44e33a5aSSean Rhodes * 7*44e33a5aSSean Rhodes * Copyright 2014 Gerd Hoffmann <kraxel@redhat.com> 8*44e33a5aSSean Rhodes * Copyright 2017 Google Inc. 9*44e33a5aSSean Rhodes * Copyright 2017 Samuel Holland <samuel@sholland.org> 10*44e33a5aSSean Rhodes */ 11*44e33a5aSSean Rhodes 12*44e33a5aSSean Rhodes #ifndef __COREBOOT_TABLE_H 13*44e33a5aSSean Rhodes #define __COREBOOT_TABLE_H 14*44e33a5aSSean Rhodes 15*44e33a5aSSean Rhodes #include <linux/coreboot.h> 16*44e33a5aSSean Rhodes #include <linux/device.h> 17*44e33a5aSSean Rhodes 18*44e33a5aSSean Rhodes /* A device, additionally with information from coreboot. */ 19*44e33a5aSSean Rhodes struct coreboot_device { 20*44e33a5aSSean Rhodes struct device dev; 21*44e33a5aSSean Rhodes union { 22*44e33a5aSSean Rhodes struct coreboot_table_entry entry; 23*44e33a5aSSean Rhodes struct lb_cbmem_ref cbmem_ref; 24*44e33a5aSSean Rhodes struct lb_cbmem_entry cbmem_entry; 25*44e33a5aSSean Rhodes struct lb_framebuffer framebuffer; 26*44e33a5aSSean Rhodes DECLARE_FLEX_ARRAY(u8, raw); 27*44e33a5aSSean Rhodes }; 28*44e33a5aSSean Rhodes }; 29*44e33a5aSSean Rhodes dev_to_coreboot_device(struct device * dev)30*44e33a5aSSean Rhodesstatic inline struct coreboot_device *dev_to_coreboot_device(struct device *dev) 31*44e33a5aSSean Rhodes { 32*44e33a5aSSean Rhodes return container_of(dev, struct coreboot_device, dev); 33*44e33a5aSSean Rhodes } 34*44e33a5aSSean Rhodes 35*44e33a5aSSean Rhodes /* A driver for handling devices described in coreboot tables. */ 36*44e33a5aSSean Rhodes struct coreboot_driver { 37*44e33a5aSSean Rhodes int (*probe)(struct coreboot_device *); 38*44e33a5aSSean Rhodes void (*remove)(struct coreboot_device *); 39*44e33a5aSSean Rhodes struct device_driver drv; 40*44e33a5aSSean Rhodes const struct coreboot_device_id *id_table; 41*44e33a5aSSean Rhodes }; 42*44e33a5aSSean Rhodes 43*44e33a5aSSean Rhodes /* use a macro to avoid include chaining to get THIS_MODULE */ 44*44e33a5aSSean Rhodes #define coreboot_driver_register(driver) \ 45*44e33a5aSSean Rhodes __coreboot_driver_register(driver, THIS_MODULE) 46*44e33a5aSSean Rhodes /* Register a driver that uses the data from a coreboot table. */ 47*44e33a5aSSean Rhodes int __coreboot_driver_register(struct coreboot_driver *driver, 48*44e33a5aSSean Rhodes struct module *owner); 49*44e33a5aSSean Rhodes 50*44e33a5aSSean Rhodes /* Unregister a driver that uses the data from a coreboot table. */ 51*44e33a5aSSean Rhodes void coreboot_driver_unregister(struct coreboot_driver *driver); 52*44e33a5aSSean Rhodes 53*44e33a5aSSean Rhodes /* module_coreboot_driver() - Helper macro for drivers that don't do 54*44e33a5aSSean Rhodes * anything special in module init/exit. This eliminates a lot of 55*44e33a5aSSean Rhodes * boilerplate. Each module may only use this macro once, and 56*44e33a5aSSean Rhodes * calling it replaces module_init() and module_exit() 57*44e33a5aSSean Rhodes */ 58*44e33a5aSSean Rhodes #define module_coreboot_driver(__coreboot_driver) \ 59*44e33a5aSSean Rhodes module_driver(__coreboot_driver, coreboot_driver_register, \ 60*44e33a5aSSean Rhodes coreboot_driver_unregister) 61*44e33a5aSSean Rhodes 62*44e33a5aSSean Rhodes #endif /* __COREBOOT_TABLE_H */ 63