xref: /openbmc/qemu/include/hw/nvram/fw_cfg.h (revision 63785678)
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 typedef struct FWCfgFiles {
15     uint32_t  count;
16     FWCfgFile f[];
17 } FWCfgFiles;
18 
19 /* Control as first field allows for different structures selected by this
20  * field, which might be useful in the future
21  */
22 typedef struct FWCfgDmaAccess {
23     uint32_t control;
24     uint32_t length;
25     uint64_t address;
26 } QEMU_PACKED FWCfgDmaAccess;
27 
28 typedef void (*FWCfgReadCallback)(void *opaque);
29 
30 /**
31  * fw_cfg_add_bytes:
32  * @s: fw_cfg device being modified
33  * @key: selector key value for new fw_cfg item
34  * @data: pointer to start of item data
35  * @len: size of item data
36  *
37  * Add a new fw_cfg item, available by selecting the given key, as a raw
38  * "blob" of the given size. The data referenced by the starting pointer
39  * is only linked, NOT copied, into the data structure of the fw_cfg device.
40  */
41 void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len);
42 
43 /**
44  * fw_cfg_add_string:
45  * @s: fw_cfg device being modified
46  * @key: selector key value for new fw_cfg item
47  * @value: NUL-terminated ascii string
48  *
49  * Add a new fw_cfg item, available by selecting the given key. The item
50  * data will consist of a dynamically allocated copy of the provided string,
51  * including its NUL terminator.
52  */
53 void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value);
54 
55 /**
56  * fw_cfg_add_i16:
57  * @s: fw_cfg device being modified
58  * @key: selector key value for new fw_cfg item
59  * @value: 16-bit integer
60  *
61  * Add a new fw_cfg item, available by selecting the given key. The item
62  * data will consist of a dynamically allocated copy of the given 16-bit
63  * value, converted to little-endian representation.
64  */
65 void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value);
66 
67 /**
68  * fw_cfg_modify_i16:
69  * @s: fw_cfg device being modified
70  * @key: selector key value for new fw_cfg item
71  * @value: 16-bit integer
72  *
73  * Replace the fw_cfg item available by selecting the given key. The new
74  * data will consist of a dynamically allocated copy of the given 16-bit
75  * value, converted to little-endian representation. The data being replaced,
76  * assumed to have been dynamically allocated during an earlier call to
77  * either fw_cfg_add_i16() or fw_cfg_modify_i16(), is freed before returning.
78  */
79 void fw_cfg_modify_i16(FWCfgState *s, uint16_t key, uint16_t value);
80 
81 /**
82  * fw_cfg_add_i32:
83  * @s: fw_cfg device being modified
84  * @key: selector key value for new fw_cfg item
85  * @value: 32-bit integer
86  *
87  * Add a new fw_cfg item, available by selecting the given key. The item
88  * data will consist of a dynamically allocated copy of the given 32-bit
89  * value, converted to little-endian representation.
90  */
91 void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value);
92 
93 /**
94  * fw_cfg_add_i64:
95  * @s: fw_cfg device being modified
96  * @key: selector key value for new fw_cfg item
97  * @value: 64-bit integer
98  *
99  * Add a new fw_cfg item, available by selecting the given key. The item
100  * data will consist of a dynamically allocated copy of the given 64-bit
101  * value, converted to little-endian representation.
102  */
103 void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value);
104 
105 /**
106  * fw_cfg_add_file:
107  * @s: fw_cfg device being modified
108  * @filename: name of new fw_cfg file item
109  * @data: pointer to start of item data
110  * @len: size of item data
111  *
112  * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
113  * referenced by the starting pointer is only linked, NOT copied, into the
114  * data structure of the fw_cfg device.
115  * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
116  * will be used; also, a new entry will be added to the file directory
117  * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
118  * data size, and assigned selector key value.
119  */
120 void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data,
121                      size_t len);
122 
123 /**
124  * fw_cfg_add_file_callback:
125  * @s: fw_cfg device being modified
126  * @filename: name of new fw_cfg file item
127  * @callback: callback function
128  * @callback_opaque: argument to be passed into callback function
129  * @data: pointer to start of item data
130  * @len: size of item data
131  *
132  * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
133  * referenced by the starting pointer is only linked, NOT copied, into the
134  * data structure of the fw_cfg device.
135  * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
136  * will be used; also, a new entry will be added to the file directory
137  * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
138  * data size, and assigned selector key value.
139  * Additionally, set a callback function (and argument) to be called each
140  * time this item is selected (by having its selector key either written to
141  * the fw_cfg control register, or passed to QEMU in FWCfgDmaAccess.control
142  * with FW_CFG_DMA_CTL_SELECT).
143  */
144 void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
145                               FWCfgReadCallback callback, void *callback_opaque,
146                               void *data, size_t len);
147 
148 /**
149  * fw_cfg_modify_file:
150  * @s: fw_cfg device being modified
151  * @filename: name of new fw_cfg file item
152  * @data: pointer to start of item data
153  * @len: size of item data
154  *
155  * Replace a NAMED fw_cfg item. If an existing item is found, its callback
156  * information will be cleared, and a pointer to its data will be returned
157  * to the caller, so that it may be freed if necessary. If an existing item
158  * is not found, this call defaults to fw_cfg_add_file(), and NULL is
159  * returned to the caller.
160  * In either case, the new item data is only linked, NOT copied, into the
161  * data structure of the fw_cfg device.
162  *
163  * Returns: pointer to old item's data, or NULL if old item does not exist.
164  */
165 void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data,
166                          size_t len);
167 
168 FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase,
169                                 AddressSpace *dma_as);
170 FWCfgState *fw_cfg_init_io(uint32_t iobase);
171 FWCfgState *fw_cfg_init_mem(hwaddr ctl_addr, hwaddr data_addr);
172 FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,
173                                  hwaddr data_addr, uint32_t data_width,
174                                  hwaddr dma_addr, AddressSpace *dma_as);
175 
176 FWCfgState *fw_cfg_find(void);
177 
178 #endif
179