hw/nvram/fw_cfg: Add the FW_CFG_DATA_GENERATOR interface

The FW_CFG_DATA_GENERATOR allows any object to produce
blob of data consumable by the fw_cfg device.

Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20200623172726.21040-3-philmd@redhat.com>
This commit is contained in:
Philippe Mathieu-Daudé 2020-05-14 15:15:38 +02:00
parent 993aec27aa
commit 3203148917
3 changed files with 86 additions and 1 deletions

View file

@ -9,11 +9,36 @@
#define TYPE_FW_CFG "fw_cfg"
#define TYPE_FW_CFG_IO "fw_cfg_io"
#define TYPE_FW_CFG_MEM "fw_cfg_mem"
#define TYPE_FW_CFG_DATA_GENERATOR_INTERFACE "fw_cfg-data-generator"
#define FW_CFG(obj) OBJECT_CHECK(FWCfgState, (obj), TYPE_FW_CFG)
#define FW_CFG_IO(obj) OBJECT_CHECK(FWCfgIoState, (obj), TYPE_FW_CFG_IO)
#define FW_CFG_MEM(obj) OBJECT_CHECK(FWCfgMemState, (obj), TYPE_FW_CFG_MEM)
#define FW_CFG_DATA_GENERATOR_CLASS(class) \
OBJECT_CLASS_CHECK(FWCfgDataGeneratorClass, (class), \
TYPE_FW_CFG_DATA_GENERATOR_INTERFACE)
#define FW_CFG_DATA_GENERATOR_GET_CLASS(obj) \
OBJECT_GET_CLASS(FWCfgDataGeneratorClass, (obj), \
TYPE_FW_CFG_DATA_GENERATOR_INTERFACE)
typedef struct FWCfgDataGeneratorClass {
/*< private >*/
InterfaceClass parent_class;
/*< public >*/
/**
* get_data:
* @obj: the object implementing this interface
* @errp: pointer to a NULL-initialized error object
*
* Returns: reference to a byte array containing the data.
* The caller should release the reference when no longer
* required.
*/
GByteArray *(*get_data)(Object *obj, Error **errp);
} FWCfgDataGeneratorClass;
typedef struct fw_cfg_file FWCfgFile;
#define FW_CFG_ORDER_OVERRIDE_VGA 70
@ -263,6 +288,24 @@ void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data,
size_t len);
/**
* fw_cfg_add_from_generator:
* @s: fw_cfg device being modified
* @filename: name of new fw_cfg file item
* @gen_id: name of object implementing FW_CFG_DATA_GENERATOR interface
* @errp: pointer to a NULL initialized error object
*
* Add a new NAMED fw_cfg item with the content generated from the
* @gen_id object. The data generated by the @gen_id object is copied
* into the data structure of the fw_cfg device.
* The next available (unused) selector key starting at FW_CFG_FILE_FIRST
* will be used; also, a new entry will be added to the file directory
* structure residing at key value FW_CFG_FILE_DIR, containing the item name,
* data size, and assigned selector key value.
*/
void fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
const char *gen_id, Error **errp);
FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase,
AddressSpace *dma_as);
FWCfgState *fw_cfg_init_io(uint32_t iobase);