xref: /qemu/docs/specs/fw_cfg.rst (revision 6cec43e178cde38a3eac43a2cd741ce741b10f36)
1*6cec43e1SGabriel L. SomloQEMU Firmware Configuration (fw_cfg) Device
2*6cec43e1SGabriel L. Somlo===========================================
3*6cec43e1SGabriel L. Somlo
4*6cec43e1SGabriel L. Somlo= Guest-side Hardware Interface =
5*6cec43e1SGabriel L. Somlo
6*6cec43e1SGabriel L. SomloThis hardware interface allows the guest to retrieve various data items
7*6cec43e1SGabriel L. Somlo(blobs) that can influence how the firmware configures itself, or may
8*6cec43e1SGabriel L. Somlocontain tables to be installed for the guest OS. Examples include device
9*6cec43e1SGabriel L. Somloboot order, ACPI and SMBIOS tables, virtual machine UUID, SMP and NUMA
10*6cec43e1SGabriel L. Somloinformation, kernel/initrd images for direct (Linux) kernel booting, etc.
11*6cec43e1SGabriel L. Somlo
12*6cec43e1SGabriel L. Somlo== Selector (Control) Register ==
13*6cec43e1SGabriel L. Somlo
14*6cec43e1SGabriel L. Somlo* Write only
15*6cec43e1SGabriel L. Somlo* Location: platform dependent (IOport or MMIO)
16*6cec43e1SGabriel L. Somlo* Width: 16-bit
17*6cec43e1SGabriel L. Somlo* Endianness: little-endian (if IOport), or big-endian (if MMIO)
18*6cec43e1SGabriel L. Somlo
19*6cec43e1SGabriel L. SomloA write to this register sets the index of a firmware configuration
20*6cec43e1SGabriel L. Somloitem which can subsequently be accessed via the data register.
21*6cec43e1SGabriel L. Somlo
22*6cec43e1SGabriel L. SomloSetting the selector register will cause the data offset to be set
23*6cec43e1SGabriel L. Somloto zero. The data offset impacts which data is accessed via the data
24*6cec43e1SGabriel L. Somloregister, and is explained below.
25*6cec43e1SGabriel L. Somlo
26*6cec43e1SGabriel L. SomloBit14 of the selector register indicates whether the configuration
27*6cec43e1SGabriel L. Somlosetting is being written. A value of 0 means the item is only being
28*6cec43e1SGabriel L. Somloread, and all write access to the data port will be ignored. A value
29*6cec43e1SGabriel L. Somloof 1 means the item's data can be overwritten by writes to the data
30*6cec43e1SGabriel L. Somloregister. In other words, configuration write mode is enabled when
31*6cec43e1SGabriel L. Somlothe selector value is between 0x4000-0x7fff or 0xc000-0xffff.
32*6cec43e1SGabriel L. Somlo
33*6cec43e1SGabriel L. SomloNOTE: As of QEMU v2.4, writes to the fw_cfg data register are no
34*6cec43e1SGabriel L. Somlo      longer supported, and will be ignored (treated as no-ops)!
35*6cec43e1SGabriel L. Somlo
36*6cec43e1SGabriel L. SomloBit15 of the selector register indicates whether the configuration
37*6cec43e1SGabriel L. Somlosetting is architecture specific. A value of 0 means the item is a
38*6cec43e1SGabriel L. Somlogeneric configuration item. A value of 1 means the item is specific
39*6cec43e1SGabriel L. Somloto a particular architecture. In other words, generic configuration
40*6cec43e1SGabriel L. Somloitems are accessed with a selector value between 0x0000-0x7fff, and
41*6cec43e1SGabriel L. Somloarchitecture specific configuration items are accessed with a selector
42*6cec43e1SGabriel L. Somlovalue between 0x8000-0xffff.
43*6cec43e1SGabriel L. Somlo
44*6cec43e1SGabriel L. Somlo== Data Register ==
45*6cec43e1SGabriel L. Somlo
46*6cec43e1SGabriel L. Somlo* Read/Write (writes ignored as of QEMU v2.4)
47*6cec43e1SGabriel L. Somlo* Location: platform dependent (IOport [*] or MMIO)
48*6cec43e1SGabriel L. Somlo* Width: 8-bit (if IOport), 8/16/32/64-bit (if MMIO)
49*6cec43e1SGabriel L. Somlo* Endianness: string-preserving
50*6cec43e1SGabriel L. Somlo
51*6cec43e1SGabriel L. Somlo[*] On platforms where the data register is exposed as an IOport, its
52*6cec43e1SGabriel L. Somloport number will always be one greater than the port number of the
53*6cec43e1SGabriel L. Somloselector register. In other words, the two ports overlap, and can not
54*6cec43e1SGabriel L. Somlobe mapped separately.
55*6cec43e1SGabriel L. Somlo
56*6cec43e1SGabriel L. SomloThe data register allows access to an array of bytes for each firmware
57*6cec43e1SGabriel L. Somloconfiguration data item. The specific item is selected by writing to
58*6cec43e1SGabriel L. Somlothe selector register, as described above.
59*6cec43e1SGabriel L. Somlo
60*6cec43e1SGabriel L. SomloInitially following a write to the selector register, the data offset
61*6cec43e1SGabriel L. Somlowill be set to zero. Each successful access to the data register will
62*6cec43e1SGabriel L. Somloincrement the data offset by the appropriate access width.
63*6cec43e1SGabriel L. Somlo
64*6cec43e1SGabriel L. SomloEach firmware configuration item has a maximum length of data
65*6cec43e1SGabriel L. Somloassociated with the item. After the data offset has passed the
66*6cec43e1SGabriel L. Somloend of this maximum data length, then any reads will return a data
67*6cec43e1SGabriel L. Somlovalue of 0x00, and all writes will be ignored.
68*6cec43e1SGabriel L. Somlo
69*6cec43e1SGabriel L. SomloAn N-byte wide read of the data register will return the next available
70*6cec43e1SGabriel L. SomloN bytes of the selected firmware configuration item, as a substring, in
71*6cec43e1SGabriel L. Somloincreasing address order, similar to memcpy().
72*6cec43e1SGabriel L. Somlo
73*6cec43e1SGabriel L. Somlo== Register Locations ==
74*6cec43e1SGabriel L. Somlo
75*6cec43e1SGabriel L. Somlo=== x86, x86_64 Register Locations ===
76*6cec43e1SGabriel L. Somlo
77*6cec43e1SGabriel L. SomloSelector Register IOport: 0x510
78*6cec43e1SGabriel L. SomloData Register IOport:     0x511
79*6cec43e1SGabriel L. Somlo
80*6cec43e1SGabriel L. Somlo== Firmware Configuration Items ==
81*6cec43e1SGabriel L. Somlo
82*6cec43e1SGabriel L. Somlo=== Signature (Key 0x0000, FW_CFG_SIGNATURE) ===
83*6cec43e1SGabriel L. Somlo
84*6cec43e1SGabriel L. SomloThe presence of the fw_cfg selector and data registers can be verified
85*6cec43e1SGabriel L. Somloby selecting the "signature" item using key 0x0000 (FW_CFG_SIGNATURE),
86*6cec43e1SGabriel L. Somloand reading four bytes from the data register. If the fw_cfg device is
87*6cec43e1SGabriel L. Somlopresent, the four bytes read will contain the characters "QEMU".
88*6cec43e1SGabriel L. Somlo
89*6cec43e1SGabriel L. Somlo=== Revision (Key 0x0001, FW_CFG_ID) ===
90*6cec43e1SGabriel L. Somlo
91*6cec43e1SGabriel L. SomloA 32-bit little-endian unsigned int, this item is used as an interface
92*6cec43e1SGabriel L. Somlorevision number, and is currently set to 1 by QEMU when fw_cfg is
93*6cec43e1SGabriel L. Somloinitialized.
94*6cec43e1SGabriel L. Somlo
95*6cec43e1SGabriel L. Somlo=== File Directory (Key 0x0019, FW_CFG_FILE_DIR) ===
96*6cec43e1SGabriel L. Somlo
97*6cec43e1SGabriel L. SomloFirmware configuration items stored at selector keys 0x0020 or higher
98*6cec43e1SGabriel L. Somlo(FW_CFG_FILE_FIRST or higher) have an associated entry in a directory
99*6cec43e1SGabriel L. Somlostructure, which makes it easier for guest-side firmware to identify
100*6cec43e1SGabriel L. Somloand retrieve them. The format of this file directory (from fw_cfg.h in
101*6cec43e1SGabriel L. Somlothe QEMU source tree) is shown here, slightly annotated for clarity:
102*6cec43e1SGabriel L. Somlo
103*6cec43e1SGabriel L. Somlostruct FWCfgFiles {		/* the entire file directory fw_cfg item */
104*6cec43e1SGabriel L. Somlo    uint32_t count;		/* number of entries, in big-endian format */
105*6cec43e1SGabriel L. Somlo    struct FWCfgFile f[];	/* array of file entries, see below */
106*6cec43e1SGabriel L. Somlo};
107*6cec43e1SGabriel L. Somlo
108*6cec43e1SGabriel L. Somlostruct FWCfgFile {		/* an individual file entry, 64 bytes total */
109*6cec43e1SGabriel L. Somlo    uint32_t size;		/* size of referenced fw_cfg item, big-endian */
110*6cec43e1SGabriel L. Somlo    uint16_t select;		/* selector key of fw_cfg item, big-endian */
111*6cec43e1SGabriel L. Somlo    uint16_t reserved;
112*6cec43e1SGabriel L. Somlo    char name[56];		/* fw_cfg item name, NUL-terminated ascii */
113*6cec43e1SGabriel L. Somlo};
114*6cec43e1SGabriel L. Somlo
115*6cec43e1SGabriel L. Somlo=== All Other Data Items ===
116*6cec43e1SGabriel L. Somlo
117*6cec43e1SGabriel L. SomloPlease consult the QEMU source for the most up-to-date and authoritative
118*6cec43e1SGabriel L. Somlolist of selector keys and their respective items' purpose and format.
119*6cec43e1SGabriel L. Somlo
120*6cec43e1SGabriel L. Somlo=== Ranges ===
121*6cec43e1SGabriel L. Somlo
122*6cec43e1SGabriel L. SomloTheoretically, there may be up to 0x4000 generic firmware configuration
123*6cec43e1SGabriel L. Somloitems, and up to 0x4000 architecturally specific ones.
124*6cec43e1SGabriel L. Somlo
125*6cec43e1SGabriel L. SomloSelector Reg.    Range Usage
126*6cec43e1SGabriel L. Somlo---------------  -----------
127*6cec43e1SGabriel L. Somlo0x0000 - 0x3fff  Generic (0x0000 - 0x3fff, RO)
128*6cec43e1SGabriel L. Somlo0x4000 - 0x7fff  Generic (0x0000 - 0x3fff, RW, ignored in QEMU v2.4+)
129*6cec43e1SGabriel L. Somlo0x8000 - 0xbfff  Arch. Specific (0x0000 - 0x3fff, RO)
130*6cec43e1SGabriel L. Somlo0xc000 - 0xffff  Arch. Specific (0x0000 - 0x3fff, RW, ignored in v2.4+)
131*6cec43e1SGabriel L. Somlo
132*6cec43e1SGabriel L. SomloIn practice, the number of allowed firmware configuration items is given
133*6cec43e1SGabriel L. Somloby the value of FW_CFG_MAX_ENTRY (see fw_cfg.h).
134*6cec43e1SGabriel L. Somlo
135*6cec43e1SGabriel L. Somlo= Host-side API =
136*6cec43e1SGabriel L. Somlo
137*6cec43e1SGabriel L. SomloThe following functions are available to the QEMU programmer for adding
138*6cec43e1SGabriel L. Somlodata to a fw_cfg device during guest initialization (see fw_cfg.h for
139*6cec43e1SGabriel L. Somloeach function's complete prototype):
140*6cec43e1SGabriel L. Somlo
141*6cec43e1SGabriel L. Somlo== fw_cfg_add_bytes() ==
142*6cec43e1SGabriel L. Somlo
143*6cec43e1SGabriel L. SomloGiven a selector key value, starting pointer, and size, create an item
144*6cec43e1SGabriel L. Somloas a raw "blob" of the given size, available by selecting the given key.
145*6cec43e1SGabriel L. SomloThe data referenced by the starting pointer is only linked, NOT copied,
146*6cec43e1SGabriel L. Somlointo the data structure of the fw_cfg device.
147*6cec43e1SGabriel L. Somlo
148*6cec43e1SGabriel L. Somlo== fw_cfg_add_string() ==
149*6cec43e1SGabriel L. Somlo
150*6cec43e1SGabriel L. SomloInstead of a starting pointer and size, this function accepts a pointer
151*6cec43e1SGabriel L. Somloto a NUL-terminated ascii string, and inserts a newly allocated copy of
152*6cec43e1SGabriel L. Somlothe string (including the NUL terminator) into the fw_cfg device data
153*6cec43e1SGabriel L. Somlostructure.
154*6cec43e1SGabriel L. Somlo
155*6cec43e1SGabriel L. Somlo== fw_cfg_add_iXX() ==
156*6cec43e1SGabriel L. Somlo
157*6cec43e1SGabriel L. SomloInsert an XX-bit item, where XX may be 16, 32, or 64. These functions
158*6cec43e1SGabriel L. Somlowill convert a 16-, 32-, or 64-bit integer to little-endian, then add
159*6cec43e1SGabriel L. Somloa dynamically allocated copy of the appropriately sized item to fw_cfg
160*6cec43e1SGabriel L. Somlounder the given selector key value.
161*6cec43e1SGabriel L. Somlo
162*6cec43e1SGabriel L. Somlo== fw_cfg_add_file() ==
163*6cec43e1SGabriel L. Somlo
164*6cec43e1SGabriel L. SomloGiven a filename (i.e., fw_cfg item name), starting pointer, and size,
165*6cec43e1SGabriel L. Somlocreate an item as a raw "blob" of the given size. Unlike fw_cfg_add_bytes()
166*6cec43e1SGabriel L. Somloabove, the next available selector key (above 0x0020, FW_CFG_FILE_FIRST)
167*6cec43e1SGabriel L. Somlowill be used, and a new entry will be added to the file directory structure
168*6cec43e1SGabriel L. Somlo(at key 0x0019), containing the item name, blob size, and automatically
169*6cec43e1SGabriel L. Somloassigned selector key value. The data referenced by the starting pointer
170*6cec43e1SGabriel L. Somlois only linked, NOT copied, into the fw_cfg data structure.
171*6cec43e1SGabriel L. Somlo
172*6cec43e1SGabriel L. Somlo== fw_cfg_add_file_callback() ==
173*6cec43e1SGabriel L. Somlo
174*6cec43e1SGabriel L. SomloLike fw_cfg_add_file(), but additionally sets pointers to a callback
175*6cec43e1SGabriel L. Somlofunction (and opaque argument), which will be executed host-side by
176*6cec43e1SGabriel L. SomloQEMU each time a byte is read by the guest from this particular item.
177*6cec43e1SGabriel L. Somlo
178*6cec43e1SGabriel L. SomloNOTE: The callback function is given the opaque argument set by
179*6cec43e1SGabriel L. Somlofw_cfg_add_file_callback(), but also the current data offset,
180*6cec43e1SGabriel L. Somloallowing it the option of only acting upon specific offset values
181*6cec43e1SGabriel L. Somlo(e.g., 0, before the first data byte of the selected item is
182*6cec43e1SGabriel L. Somloreturned to the guest).
183*6cec43e1SGabriel L. Somlo
184*6cec43e1SGabriel L. Somlo== fw_cfg_modify_file() ==
185*6cec43e1SGabriel L. Somlo
186*6cec43e1SGabriel L. SomloGiven a filename (i.e., fw_cfg item name), starting pointer, and size,
187*6cec43e1SGabriel L. Somlocompletely replace the configuration item referenced by the given item
188*6cec43e1SGabriel L. Somloname with the new given blob. If an existing blob is found, its
189*6cec43e1SGabriel L. Somlocallback information is removed, and a pointer to the old data is
190*6cec43e1SGabriel L. Somloreturned to allow the caller to free it, helping avoid memory leaks.
191*6cec43e1SGabriel L. SomloIf a configuration item does not already exist under the given item
192*6cec43e1SGabriel L. Somloname, a new item will be created as with fw_cfg_add_file(), and NULL
193*6cec43e1SGabriel L. Somlois returned to the caller. In any case, the data referenced by the
194*6cec43e1SGabriel L. Somlostarting pointer is only linked, NOT copied, into the fw_cfg data
195*6cec43e1SGabriel L. Somlostructure.
196*6cec43e1SGabriel L. Somlo
197*6cec43e1SGabriel L. Somlo== fw_cfg_add_callback() ==
198*6cec43e1SGabriel L. Somlo
199*6cec43e1SGabriel L. SomloLike fw_cfg_add_bytes(), but additionally sets pointers to a callback
200*6cec43e1SGabriel L. Somlofunction (and opaque argument), which will be executed host-side by
201*6cec43e1SGabriel L. SomloQEMU each time a guest-side write operation to this particular item
202*6cec43e1SGabriel L. Somlocompletes fully overwriting the item's data.
203*6cec43e1SGabriel L. Somlo
204*6cec43e1SGabriel L. SomloNOTE: This function is deprecated, and will be completely removed
205*6cec43e1SGabriel L. Somlostarting with QEMU v2.4.
206