1 #ifndef FW_CFG_H 2 #define FW_CFG_H 3 4 #ifndef NO_QEMU_PROTOS 5 #include <stdint.h> 6 #include <stddef.h> 7 8 #include "exec/hwaddr.h" 9 #include "qemu/typedefs.h" 10 #endif 11 12 #define FW_CFG_SIGNATURE 0x00 13 #define FW_CFG_ID 0x01 14 #define FW_CFG_UUID 0x02 15 #define FW_CFG_RAM_SIZE 0x03 16 #define FW_CFG_NOGRAPHIC 0x04 17 #define FW_CFG_NB_CPUS 0x05 18 #define FW_CFG_MACHINE_ID 0x06 19 #define FW_CFG_KERNEL_ADDR 0x07 20 #define FW_CFG_KERNEL_SIZE 0x08 21 #define FW_CFG_KERNEL_CMDLINE 0x09 22 #define FW_CFG_INITRD_ADDR 0x0a 23 #define FW_CFG_INITRD_SIZE 0x0b 24 #define FW_CFG_BOOT_DEVICE 0x0c 25 #define FW_CFG_NUMA 0x0d 26 #define FW_CFG_BOOT_MENU 0x0e 27 #define FW_CFG_MAX_CPUS 0x0f 28 #define FW_CFG_KERNEL_ENTRY 0x10 29 #define FW_CFG_KERNEL_DATA 0x11 30 #define FW_CFG_INITRD_DATA 0x12 31 #define FW_CFG_CMDLINE_ADDR 0x13 32 #define FW_CFG_CMDLINE_SIZE 0x14 33 #define FW_CFG_CMDLINE_DATA 0x15 34 #define FW_CFG_SETUP_ADDR 0x16 35 #define FW_CFG_SETUP_SIZE 0x17 36 #define FW_CFG_SETUP_DATA 0x18 37 #define FW_CFG_FILE_DIR 0x19 38 39 #define FW_CFG_FILE_FIRST 0x20 40 #define FW_CFG_FILE_SLOTS 0x10 41 #define FW_CFG_MAX_ENTRY (FW_CFG_FILE_FIRST+FW_CFG_FILE_SLOTS) 42 43 #define FW_CFG_WRITE_CHANNEL 0x4000 44 #define FW_CFG_ARCH_LOCAL 0x8000 45 #define FW_CFG_ENTRY_MASK ~(FW_CFG_WRITE_CHANNEL | FW_CFG_ARCH_LOCAL) 46 47 #define FW_CFG_INVALID 0xffff 48 49 #define FW_CFG_MAX_FILE_PATH 56 50 51 #ifndef NO_QEMU_PROTOS 52 typedef struct FWCfgFile { 53 uint32_t size; /* file size */ 54 uint16_t select; /* write this to 0x510 to read it */ 55 uint16_t reserved; 56 char name[FW_CFG_MAX_FILE_PATH]; 57 } FWCfgFile; 58 59 typedef struct FWCfgFiles { 60 uint32_t count; 61 FWCfgFile f[]; 62 } FWCfgFiles; 63 64 /* Control as first field allows for different structures selected by this 65 * field, which might be useful in the future 66 */ 67 typedef struct FWCfgDmaAccess { 68 uint32_t control; 69 uint32_t length; 70 uint64_t address; 71 } QEMU_PACKED FWCfgDmaAccess; 72 73 typedef void (*FWCfgReadCallback)(void *opaque); 74 75 /** 76 * fw_cfg_add_bytes: 77 * @s: fw_cfg device being modified 78 * @key: selector key value for new fw_cfg item 79 * @data: pointer to start of item data 80 * @len: size of item data 81 * 82 * Add a new fw_cfg item, available by selecting the given key, as a raw 83 * "blob" of the given size. The data referenced by the starting pointer 84 * is only linked, NOT copied, into the data structure of the fw_cfg device. 85 */ 86 void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len); 87 88 /** 89 * fw_cfg_add_string: 90 * @s: fw_cfg device being modified 91 * @key: selector key value for new fw_cfg item 92 * @value: NUL-terminated ascii string 93 * 94 * Add a new fw_cfg item, available by selecting the given key. The item 95 * data will consist of a dynamically allocated copy of the provided string, 96 * including its NUL terminator. 97 */ 98 void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value); 99 100 /** 101 * fw_cfg_add_i16: 102 * @s: fw_cfg device being modified 103 * @key: selector key value for new fw_cfg item 104 * @value: 16-bit integer 105 * 106 * Add a new fw_cfg item, available by selecting the given key. The item 107 * data will consist of a dynamically allocated copy of the given 16-bit 108 * value, converted to little-endian representation. 109 */ 110 void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value); 111 112 /** 113 * fw_cfg_modify_i16: 114 * @s: fw_cfg device being modified 115 * @key: selector key value for new fw_cfg item 116 * @value: 16-bit integer 117 * 118 * Replace the fw_cfg item available by selecting the given key. The new 119 * data will consist of a dynamically allocated copy of the given 16-bit 120 * value, converted to little-endian representation. The data being replaced, 121 * assumed to have been dynamically allocated during an earlier call to 122 * either fw_cfg_add_i16() or fw_cfg_modify_i16(), is freed before returning. 123 */ 124 void fw_cfg_modify_i16(FWCfgState *s, uint16_t key, uint16_t value); 125 126 /** 127 * fw_cfg_add_i32: 128 * @s: fw_cfg device being modified 129 * @key: selector key value for new fw_cfg item 130 * @value: 32-bit integer 131 * 132 * Add a new fw_cfg item, available by selecting the given key. The item 133 * data will consist of a dynamically allocated copy of the given 32-bit 134 * value, converted to little-endian representation. 135 */ 136 void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value); 137 138 /** 139 * fw_cfg_add_i64: 140 * @s: fw_cfg device being modified 141 * @key: selector key value for new fw_cfg item 142 * @value: 64-bit integer 143 * 144 * Add a new fw_cfg item, available by selecting the given key. The item 145 * data will consist of a dynamically allocated copy of the given 64-bit 146 * value, converted to little-endian representation. 147 */ 148 void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value); 149 150 /** 151 * fw_cfg_add_file: 152 * @s: fw_cfg device being modified 153 * @filename: name of new fw_cfg file item 154 * @data: pointer to start of item data 155 * @len: size of item data 156 * 157 * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data 158 * referenced by the starting pointer is only linked, NOT copied, into the 159 * data structure of the fw_cfg device. 160 * The next available (unused) selector key starting at FW_CFG_FILE_FIRST 161 * will be used; also, a new entry will be added to the file directory 162 * structure residing at key value FW_CFG_FILE_DIR, containing the item name, 163 * data size, and assigned selector key value. 164 */ 165 void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data, 166 size_t len); 167 168 /** 169 * fw_cfg_add_file_callback: 170 * @s: fw_cfg device being modified 171 * @filename: name of new fw_cfg file item 172 * @callback: callback function 173 * @callback_opaque: argument to be passed into callback function 174 * @data: pointer to start of item data 175 * @len: size of item data 176 * 177 * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data 178 * referenced by the starting pointer is only linked, NOT copied, into the 179 * data structure of the fw_cfg device. 180 * The next available (unused) selector key starting at FW_CFG_FILE_FIRST 181 * will be used; also, a new entry will be added to the file directory 182 * structure residing at key value FW_CFG_FILE_DIR, containing the item name, 183 * data size, and assigned selector key value. 184 * Additionally, set a callback function (and argument) to be called each 185 * time this item is selected (by having its selector key either written to 186 * the fw_cfg control register, or passed to QEMU in FWCfgDmaAccess.control 187 * with FW_CFG_DMA_CTL_SELECT). 188 */ 189 void fw_cfg_add_file_callback(FWCfgState *s, const char *filename, 190 FWCfgReadCallback callback, void *callback_opaque, 191 void *data, size_t len); 192 193 /** 194 * fw_cfg_modify_file: 195 * @s: fw_cfg device being modified 196 * @filename: name of new fw_cfg file item 197 * @data: pointer to start of item data 198 * @len: size of item data 199 * 200 * Replace a NAMED fw_cfg item. If an existing item is found, its callback 201 * information will be cleared, and a pointer to its data will be returned 202 * to the caller, so that it may be freed if necessary. If an existing item 203 * is not found, this call defaults to fw_cfg_add_file(), and NULL is 204 * returned to the caller. 205 * In either case, the new item data is only linked, NOT copied, into the 206 * data structure of the fw_cfg device. 207 * 208 * Returns: pointer to old item's data, or NULL if old item does not exist. 209 */ 210 void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data, 211 size_t len); 212 213 FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase, 214 AddressSpace *dma_as); 215 FWCfgState *fw_cfg_init_io(uint32_t iobase); 216 FWCfgState *fw_cfg_init_mem(hwaddr ctl_addr, hwaddr data_addr); 217 FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr, 218 hwaddr data_addr, uint32_t data_width, 219 hwaddr dma_addr, AddressSpace *dma_as); 220 221 FWCfgState *fw_cfg_find(void); 222 223 #endif /* NO_QEMU_PROTOS */ 224 225 #endif 226