1 #ifndef FW_CFG_H 2 #define FW_CFG_H 3 4 #include "exec/hwaddr.h" 5 #include "hw/nvram/fw_cfg_keys.h" 6 #include "hw/sysbus.h" 7 #include "sysemu/dma.h" 8 9 #define TYPE_FW_CFG "fw_cfg" 10 #define TYPE_FW_CFG_IO "fw_cfg_io" 11 #define TYPE_FW_CFG_MEM "fw_cfg_mem" 12 13 #define FW_CFG(obj) OBJECT_CHECK(FWCfgState, (obj), TYPE_FW_CFG) 14 #define FW_CFG_IO(obj) OBJECT_CHECK(FWCfgIoState, (obj), TYPE_FW_CFG_IO) 15 #define FW_CFG_MEM(obj) OBJECT_CHECK(FWCfgMemState, (obj), TYPE_FW_CFG_MEM) 16 17 typedef struct FWCfgFile { 18 uint32_t size; /* file size */ 19 uint16_t select; /* write this to 0x510 to read it */ 20 uint16_t reserved; 21 char name[FW_CFG_MAX_FILE_PATH]; 22 } FWCfgFile; 23 24 #define FW_CFG_ORDER_OVERRIDE_VGA 70 25 #define FW_CFG_ORDER_OVERRIDE_NIC 80 26 #define FW_CFG_ORDER_OVERRIDE_USER 100 27 #define FW_CFG_ORDER_OVERRIDE_DEVICE 110 28 29 void fw_cfg_set_order_override(FWCfgState *fw_cfg, int order); 30 void fw_cfg_reset_order_override(FWCfgState *fw_cfg); 31 32 typedef struct FWCfgFiles { 33 uint32_t count; 34 FWCfgFile f[]; 35 } FWCfgFiles; 36 37 /* Control as first field allows for different structures selected by this 38 * field, which might be useful in the future 39 */ 40 typedef struct FWCfgDmaAccess { 41 uint32_t control; 42 uint32_t length; 43 uint64_t address; 44 } QEMU_PACKED FWCfgDmaAccess; 45 46 typedef void (*FWCfgCallback)(void *opaque); 47 typedef void (*FWCfgWriteCallback)(void *opaque, off_t start, size_t len); 48 49 struct FWCfgState { 50 /*< private >*/ 51 SysBusDevice parent_obj; 52 /*< public >*/ 53 54 uint16_t file_slots; 55 FWCfgEntry *entries[2]; 56 int *entry_order; 57 FWCfgFiles *files; 58 uint16_t cur_entry; 59 uint32_t cur_offset; 60 Notifier machine_ready; 61 62 int fw_cfg_order_override; 63 64 bool dma_enabled; 65 dma_addr_t dma_addr; 66 AddressSpace *dma_as; 67 MemoryRegion dma_iomem; 68 }; 69 70 struct FWCfgIoState { 71 /*< private >*/ 72 FWCfgState parent_obj; 73 /*< public >*/ 74 75 MemoryRegion comb_iomem; 76 }; 77 78 struct FWCfgMemState { 79 /*< private >*/ 80 FWCfgState parent_obj; 81 /*< public >*/ 82 83 MemoryRegion ctl_iomem, data_iomem; 84 uint32_t data_width; 85 MemoryRegionOps wide_data_ops; 86 }; 87 88 /** 89 * fw_cfg_add_bytes: 90 * @s: fw_cfg device being modified 91 * @key: selector key value for new fw_cfg item 92 * @data: pointer to start of item data 93 * @len: size of item data 94 * 95 * Add a new fw_cfg item, available by selecting the given key, as a raw 96 * "blob" of the given size. The data referenced by the starting pointer 97 * is only linked, NOT copied, into the data structure of the fw_cfg device. 98 */ 99 void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len); 100 101 /** 102 * fw_cfg_add_string: 103 * @s: fw_cfg device being modified 104 * @key: selector key value for new fw_cfg item 105 * @value: NUL-terminated ascii string 106 * 107 * Add a new fw_cfg item, available by selecting the given key. The item 108 * data will consist of a dynamically allocated copy of the provided string, 109 * including its NUL terminator. 110 */ 111 void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value); 112 113 /** 114 * fw_cfg_add_i16: 115 * @s: fw_cfg device being modified 116 * @key: selector key value for new fw_cfg item 117 * @value: 16-bit integer 118 * 119 * Add a new fw_cfg item, available by selecting the given key. The item 120 * data will consist of a dynamically allocated copy of the given 16-bit 121 * value, converted to little-endian representation. 122 */ 123 void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value); 124 125 /** 126 * fw_cfg_modify_i16: 127 * @s: fw_cfg device being modified 128 * @key: selector key value for new fw_cfg item 129 * @value: 16-bit integer 130 * 131 * Replace the fw_cfg item available by selecting the given key. The new 132 * data will consist of a dynamically allocated copy of the given 16-bit 133 * value, converted to little-endian representation. The data being replaced, 134 * assumed to have been dynamically allocated during an earlier call to 135 * either fw_cfg_add_i16() or fw_cfg_modify_i16(), is freed before returning. 136 */ 137 void fw_cfg_modify_i16(FWCfgState *s, uint16_t key, uint16_t value); 138 139 /** 140 * fw_cfg_add_i32: 141 * @s: fw_cfg device being modified 142 * @key: selector key value for new fw_cfg item 143 * @value: 32-bit integer 144 * 145 * Add a new fw_cfg item, available by selecting the given key. The item 146 * data will consist of a dynamically allocated copy of the given 32-bit 147 * value, converted to little-endian representation. 148 */ 149 void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value); 150 151 /** 152 * fw_cfg_add_i64: 153 * @s: fw_cfg device being modified 154 * @key: selector key value for new fw_cfg item 155 * @value: 64-bit integer 156 * 157 * Add a new fw_cfg item, available by selecting the given key. The item 158 * data will consist of a dynamically allocated copy of the given 64-bit 159 * value, converted to little-endian representation. 160 */ 161 void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value); 162 163 /** 164 * fw_cfg_add_file: 165 * @s: fw_cfg device being modified 166 * @filename: name of new fw_cfg file item 167 * @data: pointer to start of item data 168 * @len: size of item data 169 * 170 * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data 171 * referenced by the starting pointer is only linked, NOT copied, into the 172 * data structure of the fw_cfg device. 173 * The next available (unused) selector key starting at FW_CFG_FILE_FIRST 174 * will be used; also, a new entry will be added to the file directory 175 * structure residing at key value FW_CFG_FILE_DIR, containing the item name, 176 * data size, and assigned selector key value. 177 */ 178 void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data, 179 size_t len); 180 181 /** 182 * fw_cfg_add_file_callback: 183 * @s: fw_cfg device being modified 184 * @filename: name of new fw_cfg file item 185 * @select_cb: callback function when selecting 186 * @write_cb: callback function after a write 187 * @callback_opaque: argument to be passed into callback function 188 * @data: pointer to start of item data 189 * @len: size of item data 190 * @read_only: is file read only 191 * 192 * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data 193 * referenced by the starting pointer is only linked, NOT copied, into the 194 * data structure of the fw_cfg device. 195 * The next available (unused) selector key starting at FW_CFG_FILE_FIRST 196 * will be used; also, a new entry will be added to the file directory 197 * structure residing at key value FW_CFG_FILE_DIR, containing the item name, 198 * data size, and assigned selector key value. 199 * Additionally, set a callback function (and argument) to be called each 200 * time this item is selected (by having its selector key either written to 201 * the fw_cfg control register, or passed to QEMU in FWCfgDmaAccess.control 202 * with FW_CFG_DMA_CTL_SELECT). 203 */ 204 void fw_cfg_add_file_callback(FWCfgState *s, const char *filename, 205 FWCfgCallback select_cb, 206 FWCfgWriteCallback write_cb, 207 void *callback_opaque, 208 void *data, size_t len, bool read_only); 209 210 /** 211 * fw_cfg_modify_file: 212 * @s: fw_cfg device being modified 213 * @filename: name of new fw_cfg file item 214 * @data: pointer to start of item data 215 * @len: size of item data 216 * 217 * Replace a NAMED fw_cfg item. If an existing item is found, its callback 218 * information will be cleared, and a pointer to its data will be returned 219 * to the caller, so that it may be freed if necessary. If an existing item 220 * is not found, this call defaults to fw_cfg_add_file(), and NULL is 221 * returned to the caller. 222 * In either case, the new item data is only linked, NOT copied, into the 223 * data structure of the fw_cfg device. 224 * 225 * Returns: pointer to old item's data, or NULL if old item does not exist. 226 */ 227 void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data, 228 size_t len); 229 230 FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase, 231 AddressSpace *dma_as); 232 FWCfgState *fw_cfg_init_io(uint32_t iobase); 233 FWCfgState *fw_cfg_init_mem(hwaddr ctl_addr, hwaddr data_addr); 234 FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr, 235 hwaddr data_addr, uint32_t data_width, 236 hwaddr dma_addr, AddressSpace *dma_as); 237 238 FWCfgState *fw_cfg_find(void); 239 bool fw_cfg_dma_enabled(void *opaque); 240 241 #endif 242