]> Git Repo - qemu.git/blame - include/hw/nvram/fw_cfg.h
fw-cfg: support writeable blobs
[qemu.git] / include / hw / nvram / fw_cfg.h
CommitLineData
3cce6243
BS
1#ifndef FW_CFG_H
2#define FW_CFG_H
3
1dfe5057 4#include "exec/hwaddr.h"
6f061ea1 5#include "hw/nvram/fw_cfg_keys.h"
1dfe5057 6
abe147e0
GH
7typedef struct FWCfgFile {
8 uint32_t size; /* file size */
9 uint16_t select; /* write this to 0x510 to read it */
10 uint16_t reserved;
35c12e60 11 char name[FW_CFG_MAX_FILE_PATH];
abe147e0
GH
12} FWCfgFile;
13
bab47d9a
GH
14#define FW_CFG_ORDER_OVERRIDE_VGA 70
15#define FW_CFG_ORDER_OVERRIDE_NIC 80
16#define FW_CFG_ORDER_OVERRIDE_USER 100
17#define FW_CFG_ORDER_OVERRIDE_DEVICE 110
18
19void fw_cfg_set_order_override(FWCfgState *fw_cfg, int order);
20void fw_cfg_reset_order_override(FWCfgState *fw_cfg);
21
abe147e0
GH
22typedef struct FWCfgFiles {
23 uint32_t count;
24 FWCfgFile f[];
25} FWCfgFiles;
26
a4c0d1de
MM
27/* Control as first field allows for different structures selected by this
28 * field, which might be useful in the future
29 */
30typedef struct FWCfgDmaAccess {
31 uint32_t control;
32 uint32_t length;
33 uint64_t address;
34} QEMU_PACKED FWCfgDmaAccess;
35
3f8752b4 36typedef void (*FWCfgReadCallback)(void *opaque);
3cce6243 37
9c4a5c55
GS
38/**
39 * fw_cfg_add_bytes:
40 * @s: fw_cfg device being modified
41 * @key: selector key value for new fw_cfg item
42 * @data: pointer to start of item data
43 * @len: size of item data
44 *
45 * Add a new fw_cfg item, available by selecting the given key, as a raw
46 * "blob" of the given size. The data referenced by the starting pointer
47 * is only linked, NOT copied, into the data structure of the fw_cfg device.
48 */
089da572 49void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len);
9c4a5c55
GS
50
51/**
52 * fw_cfg_add_string:
53 * @s: fw_cfg device being modified
54 * @key: selector key value for new fw_cfg item
55 * @value: NUL-terminated ascii string
56 *
57 * Add a new fw_cfg item, available by selecting the given key. The item
58 * data will consist of a dynamically allocated copy of the provided string,
59 * including its NUL terminator.
60 */
44687f75 61void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value);
9c4a5c55
GS
62
63/**
64 * fw_cfg_add_i16:
65 * @s: fw_cfg device being modified
66 * @key: selector key value for new fw_cfg item
67 * @value: 16-bit integer
68 *
69 * Add a new fw_cfg item, available by selecting the given key. The item
70 * data will consist of a dynamically allocated copy of the given 16-bit
71 * value, converted to little-endian representation.
72 */
4cad3867 73void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value);
9c4a5c55
GS
74
75/**
76 * fw_cfg_modify_i16:
77 * @s: fw_cfg device being modified
78 * @key: selector key value for new fw_cfg item
79 * @value: 16-bit integer
80 *
81 * Replace the fw_cfg item available by selecting the given key. The new
82 * data will consist of a dynamically allocated copy of the given 16-bit
83 * value, converted to little-endian representation. The data being replaced,
84 * assumed to have been dynamically allocated during an earlier call to
85 * either fw_cfg_add_i16() or fw_cfg_modify_i16(), is freed before returning.
86 */
1edd34b6 87void fw_cfg_modify_i16(FWCfgState *s, uint16_t key, uint16_t value);
9c4a5c55
GS
88
89/**
90 * fw_cfg_add_i32:
91 * @s: fw_cfg device being modified
92 * @key: selector key value for new fw_cfg item
93 * @value: 32-bit integer
94 *
95 * Add a new fw_cfg item, available by selecting the given key. The item
96 * data will consist of a dynamically allocated copy of the given 32-bit
97 * value, converted to little-endian representation.
98 */
4cad3867 99void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value);
9c4a5c55
GS
100
101/**
102 * fw_cfg_add_i64:
103 * @s: fw_cfg device being modified
104 * @key: selector key value for new fw_cfg item
105 * @value: 64-bit integer
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 given 64-bit
109 * value, converted to little-endian representation.
110 */
4cad3867 111void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value);
9c4a5c55
GS
112
113/**
114 * fw_cfg_add_file:
115 * @s: fw_cfg device being modified
116 * @filename: name of new fw_cfg file item
117 * @data: pointer to start of item data
118 * @len: size of item data
119 *
120 * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
121 * referenced by the starting pointer is only linked, NOT copied, into the
122 * data structure of the fw_cfg device.
123 * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
124 * will be used; also, a new entry will be added to the file directory
125 * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
126 * data size, and assigned selector key value.
127 */
089da572
MA
128void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data,
129 size_t len);
9c4a5c55
GS
130
131/**
132 * fw_cfg_add_file_callback:
133 * @s: fw_cfg device being modified
134 * @filename: name of new fw_cfg file item
135 * @callback: callback function
136 * @callback_opaque: argument to be passed into callback function
137 * @data: pointer to start of item data
138 * @len: size of item data
baf2d5bf 139 * @read_only: is file read only
9c4a5c55
GS
140 *
141 * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
142 * referenced by the starting pointer is only linked, NOT copied, into the
143 * data structure of the fw_cfg device.
144 * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
145 * will be used; also, a new entry will be added to the file directory
146 * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
147 * data size, and assigned selector key value.
148 * Additionally, set a callback function (and argument) to be called each
3bef7e8a
GS
149 * time this item is selected (by having its selector key either written to
150 * the fw_cfg control register, or passed to QEMU in FWCfgDmaAccess.control
151 * with FW_CFG_DMA_CTL_SELECT).
9c4a5c55 152 */
d87072ce
MT
153void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
154 FWCfgReadCallback callback, void *callback_opaque,
baf2d5bf 155 void *data, size_t len, bool read_only);
9c4a5c55
GS
156
157/**
158 * fw_cfg_modify_file:
159 * @s: fw_cfg device being modified
160 * @filename: name of new fw_cfg file item
161 * @data: pointer to start of item data
162 * @len: size of item data
163 *
164 * Replace a NAMED fw_cfg item. If an existing item is found, its callback
165 * information will be cleared, and a pointer to its data will be returned
166 * to the caller, so that it may be freed if necessary. If an existing item
167 * is not found, this call defaults to fw_cfg_add_file(), and NULL is
168 * returned to the caller.
169 * In either case, the new item data is only linked, NOT copied, into the
170 * data structure of the fw_cfg device.
171 *
172 * Returns: pointer to old item's data, or NULL if old item does not exist.
173 */
bdbb5b17
GA
174void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data,
175 size_t len);
9c4a5c55 176
a4c0d1de
MM
177FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase,
178 AddressSpace *dma_as);
5712db6a
LE
179FWCfgState *fw_cfg_init_io(uint32_t iobase);
180FWCfgState *fw_cfg_init_mem(hwaddr ctl_addr, hwaddr data_addr);
a4c0d1de
MM
181FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,
182 hwaddr data_addr, uint32_t data_width,
183 hwaddr dma_addr, AddressSpace *dma_as);
3cce6243 184
600c60b7 185FWCfgState *fw_cfg_find(void);
b2a575a1 186bool fw_cfg_dma_enabled(void *opaque);
600c60b7 187
3cce6243 188#endif
This page took 0.679711 seconds and 4 git commands to generate.