xref: /openbmc/qemu/include/hw/nvram/fw_cfg.h (revision d9d3aaea)
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 
7 typedef struct FWCfgFile {
8     uint32_t  size;        /* file size */
9     uint16_t  select;      /* write this to 0x510 to read it */
10     uint16_t  reserved;
11     char      name[FW_CFG_MAX_FILE_PATH];
12 } FWCfgFile;
13 
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 
19 void fw_cfg_set_order_override(FWCfgState *fw_cfg, int order);
20 void fw_cfg_reset_order_override(FWCfgState *fw_cfg);
21 
22 typedef struct FWCfgFiles {
23     uint32_t  count;
24     FWCfgFile f[];
25 } FWCfgFiles;
26 
27 /* Control as first field allows for different structures selected by this
28  * field, which might be useful in the future
29  */
30 typedef struct FWCfgDmaAccess {
31     uint32_t control;
32     uint32_t length;
33     uint64_t address;
34 } QEMU_PACKED FWCfgDmaAccess;
35 
36 typedef void (*FWCfgReadCallback)(void *opaque);
37 
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  */
49 void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len);
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  */
61 void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value);
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  */
73 void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value);
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  */
87 void fw_cfg_modify_i16(FWCfgState *s, uint16_t key, uint16_t value);
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  */
99 void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value);
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  */
111 void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value);
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  */
128 void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data,
129                      size_t len);
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
139  *
140  * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
141  * referenced by the starting pointer is only linked, NOT copied, into the
142  * data structure of the fw_cfg device.
143  * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
144  * will be used; also, a new entry will be added to the file directory
145  * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
146  * data size, and assigned selector key value.
147  * Additionally, set a callback function (and argument) to be called each
148  * time this item is selected (by having its selector key either written to
149  * the fw_cfg control register, or passed to QEMU in FWCfgDmaAccess.control
150  * with FW_CFG_DMA_CTL_SELECT).
151  */
152 void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
153                               FWCfgReadCallback callback, void *callback_opaque,
154                               void *data, size_t len);
155 
156 /**
157  * fw_cfg_modify_file:
158  * @s: fw_cfg device being modified
159  * @filename: name of new fw_cfg file item
160  * @data: pointer to start of item data
161  * @len: size of item data
162  *
163  * Replace a NAMED fw_cfg item. If an existing item is found, its callback
164  * information will be cleared, and a pointer to its data will be returned
165  * to the caller, so that it may be freed if necessary. If an existing item
166  * is not found, this call defaults to fw_cfg_add_file(), and NULL is
167  * returned to the caller.
168  * In either case, the new item data is only linked, NOT copied, into the
169  * data structure of the fw_cfg device.
170  *
171  * Returns: pointer to old item's data, or NULL if old item does not exist.
172  */
173 void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data,
174                          size_t len);
175 
176 FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase,
177                                 AddressSpace *dma_as);
178 FWCfgState *fw_cfg_init_io(uint32_t iobase);
179 FWCfgState *fw_cfg_init_mem(hwaddr ctl_addr, hwaddr data_addr);
180 FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,
181                                  hwaddr data_addr, uint32_t data_width,
182                                  hwaddr dma_addr, AddressSpace *dma_as);
183 
184 FWCfgState *fw_cfg_find(void);
185 
186 #endif
187