1 #ifndef FW_CFG_H 2 #define FW_CFG_H 3 4 #include "exec/hwaddr.h" 5 #include "standard-headers/linux/qemu_fw_cfg.h" 6 #include "hw/sysbus.h" 7 #include "sysemu/dma.h" 8 #include "qom/object.h" 9 10 #define TYPE_FW_CFG "fw_cfg" 11 #define TYPE_FW_CFG_IO "fw_cfg_io" 12 #define TYPE_FW_CFG_MEM "fw_cfg_mem" 13 #define TYPE_FW_CFG_DATA_GENERATOR_INTERFACE "fw_cfg-data-generator" 14 15 #define FW_CFG(obj) OBJECT_CHECK(FWCfgState, (obj), TYPE_FW_CFG) 16 #define FW_CFG_IO(obj) OBJECT_CHECK(FWCfgIoState, (obj), TYPE_FW_CFG_IO) 17 #define FW_CFG_MEM(obj) OBJECT_CHECK(FWCfgMemState, (obj), TYPE_FW_CFG_MEM) 18 19 typedef struct FWCfgDataGeneratorClass FWCfgDataGeneratorClass; 20 #define FW_CFG_DATA_GENERATOR_CLASS(class) \ 21 OBJECT_CLASS_CHECK(FWCfgDataGeneratorClass, (class), \ 22 TYPE_FW_CFG_DATA_GENERATOR_INTERFACE) 23 #define FW_CFG_DATA_GENERATOR_GET_CLASS(obj) \ 24 OBJECT_GET_CLASS(FWCfgDataGeneratorClass, (obj), \ 25 TYPE_FW_CFG_DATA_GENERATOR_INTERFACE) 26 27 struct FWCfgDataGeneratorClass { 28 /*< private >*/ 29 InterfaceClass parent_class; 30 /*< public >*/ 31 32 /** 33 * get_data: 34 * @obj: the object implementing this interface 35 * @errp: pointer to a NULL-initialized error object 36 * 37 * Returns: reference to a byte array containing the data on success, 38 * or NULL on error. 39 * 40 * The caller should release the reference when no longer 41 * required. 42 */ 43 GByteArray *(*get_data)(Object *obj, Error **errp); 44 }; 45 46 typedef struct fw_cfg_file FWCfgFile; 47 48 #define FW_CFG_ORDER_OVERRIDE_VGA 70 49 #define FW_CFG_ORDER_OVERRIDE_NIC 80 50 #define FW_CFG_ORDER_OVERRIDE_USER 100 51 #define FW_CFG_ORDER_OVERRIDE_DEVICE 110 52 53 void fw_cfg_set_order_override(FWCfgState *fw_cfg, int order); 54 void fw_cfg_reset_order_override(FWCfgState *fw_cfg); 55 56 typedef struct FWCfgFiles { 57 uint32_t count; 58 FWCfgFile f[]; 59 } FWCfgFiles; 60 61 typedef struct fw_cfg_dma_access FWCfgDmaAccess; 62 63 typedef void (*FWCfgCallback)(void *opaque); 64 typedef void (*FWCfgWriteCallback)(void *opaque, off_t start, size_t len); 65 66 struct FWCfgState { 67 /*< private >*/ 68 SysBusDevice parent_obj; 69 /*< public >*/ 70 71 uint16_t file_slots; 72 FWCfgEntry *entries[2]; 73 int *entry_order; 74 FWCfgFiles *files; 75 uint16_t cur_entry; 76 uint32_t cur_offset; 77 Notifier machine_ready; 78 79 int fw_cfg_order_override; 80 81 bool dma_enabled; 82 dma_addr_t dma_addr; 83 AddressSpace *dma_as; 84 MemoryRegion dma_iomem; 85 86 /* restore during migration */ 87 bool acpi_mr_restore; 88 uint64_t table_mr_size; 89 uint64_t linker_mr_size; 90 uint64_t rsdp_mr_size; 91 }; 92 93 struct FWCfgIoState { 94 /*< private >*/ 95 FWCfgState parent_obj; 96 /*< public >*/ 97 98 MemoryRegion comb_iomem; 99 }; 100 101 struct FWCfgMemState { 102 /*< private >*/ 103 FWCfgState parent_obj; 104 /*< public >*/ 105 106 MemoryRegion ctl_iomem, data_iomem; 107 uint32_t data_width; 108 MemoryRegionOps wide_data_ops; 109 }; 110 111 /** 112 * fw_cfg_add_bytes: 113 * @s: fw_cfg device being modified 114 * @key: selector key value for new fw_cfg item 115 * @data: pointer to start of item data 116 * @len: size of item data 117 * 118 * Add a new fw_cfg item, available by selecting the given key, as a raw 119 * "blob" of the given size. The data referenced by the starting pointer 120 * is only linked, NOT copied, into the data structure of the fw_cfg device. 121 */ 122 void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len); 123 124 /** 125 * fw_cfg_add_string: 126 * @s: fw_cfg device being modified 127 * @key: selector key value for new fw_cfg item 128 * @value: NUL-terminated ascii string 129 * 130 * Add a new fw_cfg item, available by selecting the given key. The item 131 * data will consist of a dynamically allocated copy of the provided string, 132 * including its NUL terminator. 133 */ 134 void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value); 135 136 /** 137 * fw_cfg_modify_string: 138 * @s: fw_cfg device being modified 139 * @key: selector key value for new fw_cfg item 140 * @value: NUL-terminated ascii string 141 * 142 * Replace the fw_cfg item available by selecting the given key. The new 143 * data will consist of a dynamically allocated copy of the provided string, 144 * including its NUL terminator. The data being replaced, assumed to have 145 * been dynamically allocated during an earlier call to either 146 * fw_cfg_add_string() or fw_cfg_modify_string(), is freed before returning. 147 */ 148 void fw_cfg_modify_string(FWCfgState *s, uint16_t key, const char *value); 149 150 /** 151 * fw_cfg_add_i16: 152 * @s: fw_cfg device being modified 153 * @key: selector key value for new fw_cfg item 154 * @value: 16-bit integer 155 * 156 * Add a new fw_cfg item, available by selecting the given key. The item 157 * data will consist of a dynamically allocated copy of the given 16-bit 158 * value, converted to little-endian representation. 159 */ 160 void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value); 161 162 /** 163 * fw_cfg_modify_i16: 164 * @s: fw_cfg device being modified 165 * @key: selector key value for new fw_cfg item 166 * @value: 16-bit integer 167 * 168 * Replace the fw_cfg item available by selecting the given key. The new 169 * data will consist of a dynamically allocated copy of the given 16-bit 170 * value, converted to little-endian representation. The data being replaced, 171 * assumed to have been dynamically allocated during an earlier call to 172 * either fw_cfg_add_i16() or fw_cfg_modify_i16(), is freed before returning. 173 */ 174 void fw_cfg_modify_i16(FWCfgState *s, uint16_t key, uint16_t value); 175 176 /** 177 * fw_cfg_add_i32: 178 * @s: fw_cfg device being modified 179 * @key: selector key value for new fw_cfg item 180 * @value: 32-bit integer 181 * 182 * Add a new fw_cfg item, available by selecting the given key. The item 183 * data will consist of a dynamically allocated copy of the given 32-bit 184 * value, converted to little-endian representation. 185 */ 186 void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value); 187 188 /** 189 * fw_cfg_modify_i32: 190 * @s: fw_cfg device being modified 191 * @key: selector key value for new fw_cfg item 192 * @value: 32-bit integer 193 * 194 * Replace the fw_cfg item available by selecting the given key. The new 195 * data will consist of a dynamically allocated copy of the given 32-bit 196 * value, converted to little-endian representation. The data being replaced, 197 * assumed to have been dynamically allocated during an earlier call to 198 * either fw_cfg_add_i32() or fw_cfg_modify_i32(), is freed before returning. 199 */ 200 void fw_cfg_modify_i32(FWCfgState *s, uint16_t key, uint32_t value); 201 202 /** 203 * fw_cfg_add_i64: 204 * @s: fw_cfg device being modified 205 * @key: selector key value for new fw_cfg item 206 * @value: 64-bit integer 207 * 208 * Add a new fw_cfg item, available by selecting the given key. The item 209 * data will consist of a dynamically allocated copy of the given 64-bit 210 * value, converted to little-endian representation. 211 */ 212 void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value); 213 214 /** 215 * fw_cfg_modify_i64: 216 * @s: fw_cfg device being modified 217 * @key: selector key value for new fw_cfg item 218 * @value: 64-bit integer 219 * 220 * Replace the fw_cfg item available by selecting the given key. The new 221 * data will consist of a dynamically allocated copy of the given 64-bit 222 * value, converted to little-endian representation. The data being replaced, 223 * assumed to have been dynamically allocated during an earlier call to 224 * either fw_cfg_add_i64() or fw_cfg_modify_i64(), is freed before returning. 225 */ 226 void fw_cfg_modify_i64(FWCfgState *s, uint16_t key, uint64_t value); 227 228 /** 229 * fw_cfg_add_file: 230 * @s: fw_cfg device being modified 231 * @filename: name of new fw_cfg file item 232 * @data: pointer to start of item data 233 * @len: size of item data 234 * 235 * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data 236 * referenced by the starting pointer is only linked, NOT copied, into the 237 * data structure of the fw_cfg device. 238 * The next available (unused) selector key starting at FW_CFG_FILE_FIRST 239 * will be used; also, a new entry will be added to the file directory 240 * structure residing at key value FW_CFG_FILE_DIR, containing the item name, 241 * data size, and assigned selector key value. 242 */ 243 void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data, 244 size_t len); 245 246 /** 247 * fw_cfg_add_file_callback: 248 * @s: fw_cfg device being modified 249 * @filename: name of new fw_cfg file item 250 * @select_cb: callback function when selecting 251 * @write_cb: callback function after a write 252 * @callback_opaque: argument to be passed into callback function 253 * @data: pointer to start of item data 254 * @len: size of item data 255 * @read_only: is file read only 256 * 257 * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data 258 * referenced by the starting pointer is only linked, NOT copied, into the 259 * data structure of the fw_cfg device. 260 * The next available (unused) selector key starting at FW_CFG_FILE_FIRST 261 * will be used; also, a new entry will be added to the file directory 262 * structure residing at key value FW_CFG_FILE_DIR, containing the item name, 263 * data size, and assigned selector key value. 264 * Additionally, set a callback function (and argument) to be called each 265 * time this item is selected (by having its selector key either written to 266 * the fw_cfg control register, or passed to QEMU in FWCfgDmaAccess.control 267 * with FW_CFG_DMA_CTL_SELECT). 268 */ 269 void fw_cfg_add_file_callback(FWCfgState *s, const char *filename, 270 FWCfgCallback select_cb, 271 FWCfgWriteCallback write_cb, 272 void *callback_opaque, 273 void *data, size_t len, bool read_only); 274 275 /** 276 * fw_cfg_modify_file: 277 * @s: fw_cfg device being modified 278 * @filename: name of new fw_cfg file item 279 * @data: pointer to start of item data 280 * @len: size of item data 281 * 282 * Replace a NAMED fw_cfg item. If an existing item is found, its callback 283 * information will be cleared, and a pointer to its data will be returned 284 * to the caller, so that it may be freed if necessary. If an existing item 285 * is not found, this call defaults to fw_cfg_add_file(), and NULL is 286 * returned to the caller. 287 * In either case, the new item data is only linked, NOT copied, into the 288 * data structure of the fw_cfg device. 289 * 290 * Returns: pointer to old item's data, or NULL if old item does not exist. 291 */ 292 void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data, 293 size_t len); 294 295 /** 296 * fw_cfg_add_from_generator: 297 * @s: fw_cfg device being modified 298 * @filename: name of new fw_cfg file item 299 * @gen_id: name of object implementing FW_CFG_DATA_GENERATOR interface 300 * @errp: pointer to a NULL initialized error object 301 * 302 * Add a new NAMED fw_cfg item with the content generated from the 303 * @gen_id object. The data generated by the @gen_id object is copied 304 * into the data structure of the fw_cfg device. 305 * The next available (unused) selector key starting at FW_CFG_FILE_FIRST 306 * will be used; also, a new entry will be added to the file directory 307 * structure residing at key value FW_CFG_FILE_DIR, containing the item name, 308 * data size, and assigned selector key value. 309 * 310 * Returns: %true on success, %false on error. 311 */ 312 bool fw_cfg_add_from_generator(FWCfgState *s, const char *filename, 313 const char *gen_id, Error **errp); 314 315 FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase, 316 AddressSpace *dma_as); 317 FWCfgState *fw_cfg_init_io(uint32_t iobase); 318 FWCfgState *fw_cfg_init_mem(hwaddr ctl_addr, hwaddr data_addr); 319 FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr, 320 hwaddr data_addr, uint32_t data_width, 321 hwaddr dma_addr, AddressSpace *dma_as); 322 323 FWCfgState *fw_cfg_find(void); 324 bool fw_cfg_dma_enabled(void *opaque); 325 326 /** 327 * fw_cfg_arch_key_name: 328 * 329 * @key: The uint16 selector key. 330 * 331 * The key is architecture-specific (the FW_CFG_ARCH_LOCAL mask is expected 332 * to be set in the key). 333 * 334 * Returns: The stringified architecture-specific name if the selector 335 * refers to a well-known numerically defined item, or NULL on 336 * key lookup failure. 337 */ 338 const char *fw_cfg_arch_key_name(uint16_t key); 339 340 #endif 341