xref: /qemu/docs/specs/fw_cfg.rst (revision 381d2c36e1242f849a55f4622e50b9a69cb92842)
1701caa3dSSimon Sapin===========================================
26cec43e1SGabriel L. SomloQEMU Firmware Configuration (fw_cfg) Device
36cec43e1SGabriel L. Somlo===========================================
46cec43e1SGabriel L. Somlo
5701caa3dSSimon SapinGuest-side Hardware Interface
6701caa3dSSimon Sapin=============================
76cec43e1SGabriel L. Somlo
86cec43e1SGabriel L. SomloThis hardware interface allows the guest to retrieve various data items
96cec43e1SGabriel L. Somlo(blobs) that can influence how the firmware configures itself, or may
106cec43e1SGabriel L. Somlocontain tables to be installed for the guest OS. Examples include device
116cec43e1SGabriel L. Somloboot order, ACPI and SMBIOS tables, virtual machine UUID, SMP and NUMA
126cec43e1SGabriel L. Somloinformation, kernel/initrd images for direct (Linux) kernel booting, etc.
136cec43e1SGabriel L. Somlo
14701caa3dSSimon SapinSelector (Control) Register
15701caa3dSSimon Sapin---------------------------
166cec43e1SGabriel L. Somlo
176cec43e1SGabriel L. Somlo* Write only
186cec43e1SGabriel L. Somlo* Location: platform dependent (IOport or MMIO)
196cec43e1SGabriel L. Somlo* Width: 16-bit
206cec43e1SGabriel L. Somlo* Endianness: little-endian (if IOport), or big-endian (if MMIO)
216cec43e1SGabriel L. Somlo
226cec43e1SGabriel L. SomloA write to this register sets the index of a firmware configuration
236cec43e1SGabriel L. Somloitem which can subsequently be accessed via the data register.
246cec43e1SGabriel L. Somlo
256cec43e1SGabriel L. SomloSetting the selector register will cause the data offset to be set
266cec43e1SGabriel L. Somloto zero. The data offset impacts which data is accessed via the data
276cec43e1SGabriel L. Somloregister, and is explained below.
286cec43e1SGabriel L. Somlo
296cec43e1SGabriel L. SomloBit14 of the selector register indicates whether the configuration
306cec43e1SGabriel L. Somlosetting is being written. A value of 0 means the item is only being
316cec43e1SGabriel L. Somloread, and all write access to the data port will be ignored. A value
326cec43e1SGabriel L. Somloof 1 means the item's data can be overwritten by writes to the data
336cec43e1SGabriel L. Somloregister. In other words, configuration write mode is enabled when
346cec43e1SGabriel L. Somlothe selector value is between 0x4000-0x7fff or 0xc000-0xffff.
356cec43e1SGabriel L. Somlo
36701caa3dSSimon Sapin.. NOTE::
37701caa3dSSimon Sapin      As of QEMU v2.4, writes to the fw_cfg data register are no
386cec43e1SGabriel L. Somlo      longer supported, and will be ignored (treated as no-ops)!
396cec43e1SGabriel L. Somlo
40701caa3dSSimon Sapin.. NOTE::
41701caa3dSSimon Sapin      As of QEMU v2.9, writes are reinstated, but only through the DMA
42baf2d5bfSMichael S. Tsirkin      interface (see below). Furthermore, writeability of any specific item is
43baf2d5bfSMichael S. Tsirkin      governed independently of Bit14 in the selector key value.
44baf2d5bfSMichael S. Tsirkin
456cec43e1SGabriel L. SomloBit15 of the selector register indicates whether the configuration
466cec43e1SGabriel L. Somlosetting is architecture specific. A value of 0 means the item is a
476cec43e1SGabriel L. Somlogeneric configuration item. A value of 1 means the item is specific
486cec43e1SGabriel L. Somloto a particular architecture. In other words, generic configuration
496cec43e1SGabriel L. Somloitems are accessed with a selector value between 0x0000-0x7fff, and
506cec43e1SGabriel L. Somloarchitecture specific configuration items are accessed with a selector
516cec43e1SGabriel L. Somlovalue between 0x8000-0xffff.
526cec43e1SGabriel L. Somlo
53701caa3dSSimon SapinData Register
54701caa3dSSimon Sapin-------------
556cec43e1SGabriel L. Somlo
56baf2d5bfSMichael S. Tsirkin* Read/Write (writes ignored as of QEMU v2.4, but see the DMA interface)
57*381d2c36SPaolo Bonzini* Location: platform dependent (IOport\ [#placement]_ or MMIO)
586cec43e1SGabriel L. Somlo* Width: 8-bit (if IOport), 8/16/32/64-bit (if MMIO)
596cec43e1SGabriel L. Somlo* Endianness: string-preserving
606cec43e1SGabriel L. Somlo
61*381d2c36SPaolo Bonzini.. [#placement]
62701caa3dSSimon Sapin    On platforms where the data register is exposed as an IOport, its
636cec43e1SGabriel L. Somlo    port number will always be one greater than the port number of the
646cec43e1SGabriel L. Somlo    selector register. In other words, the two ports overlap, and can not
656cec43e1SGabriel L. Somlo    be mapped separately.
666cec43e1SGabriel L. Somlo
676cec43e1SGabriel L. SomloThe data register allows access to an array of bytes for each firmware
686cec43e1SGabriel L. Somloconfiguration data item. The specific item is selected by writing to
696cec43e1SGabriel L. Somlothe selector register, as described above.
706cec43e1SGabriel L. Somlo
716cec43e1SGabriel L. SomloInitially following a write to the selector register, the data offset
726cec43e1SGabriel L. Somlowill be set to zero. Each successful access to the data register will
736cec43e1SGabriel L. Somloincrement the data offset by the appropriate access width.
746cec43e1SGabriel L. Somlo
756cec43e1SGabriel L. SomloEach firmware configuration item has a maximum length of data
766cec43e1SGabriel L. Somloassociated with the item. After the data offset has passed the
776cec43e1SGabriel L. Somloend of this maximum data length, then any reads will return a data
786cec43e1SGabriel L. Somlovalue of 0x00, and all writes will be ignored.
796cec43e1SGabriel L. Somlo
806cec43e1SGabriel L. SomloAn N-byte wide read of the data register will return the next available
816cec43e1SGabriel L. SomloN bytes of the selected firmware configuration item, as a substring, in
826cec43e1SGabriel L. Somloincreasing address order, similar to memcpy().
836cec43e1SGabriel L. Somlo
84701caa3dSSimon SapinRegister Locations
85701caa3dSSimon Sapin------------------
866cec43e1SGabriel L. Somlo
87701caa3dSSimon Sapinx86, x86_64
88701caa3dSSimon Sapin    * Selector Register IOport: 0x510
89701caa3dSSimon Sapin    * Data Register IOport:     0x511
90701caa3dSSimon Sapin    * DMA Address IOport:       0x514
916cec43e1SGabriel L. Somlo
92701caa3dSSimon SapinArm
93701caa3dSSimon Sapin    * Selector Register address: Base + 8 (2 bytes)
94701caa3dSSimon Sapin    * Data Register address:     Base + 0 (8 bytes)
95701caa3dSSimon Sapin    * DMA Address address:       Base + 16 (8 bytes)
96c9eae1d4SMarc Marí
97701caa3dSSimon SapinACPI Interface
98701caa3dSSimon Sapin--------------
99c9eae1d4SMarc Marí
100701caa3dSSimon SapinThe fw_cfg device is defined with ACPI ID ``QEMU0002``. Since we expect
10136a43ea8SGabriel L. SomloACPI tables to be passed into the guest through the fw_cfg device itself,
10236a43ea8SGabriel L. Somlothe guest-side firmware can not use ACPI to find fw_cfg. However, once the
10336a43ea8SGabriel L. Somlofirmware is finished setting up ACPI tables and hands control over to the
10436a43ea8SGabriel L. Somloguest kernel, the latter can use the fw_cfg ACPI node for a more accurate
10536a43ea8SGabriel L. Somloinventory of in-use IOport or MMIO regions.
10636a43ea8SGabriel L. Somlo
107701caa3dSSimon SapinFirmware Configuration Items
108701caa3dSSimon Sapin----------------------------
1096cec43e1SGabriel L. Somlo
110701caa3dSSimon SapinSignature (Key 0x0000, ``FW_CFG_SIGNATURE``)
111701caa3dSSimon Sapin~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1126cec43e1SGabriel L. Somlo
1136cec43e1SGabriel L. SomloThe presence of the fw_cfg selector and data registers can be verified
114701caa3dSSimon Sapinby selecting the "signature" item using key 0x0000 (``FW_CFG_SIGNATURE``),
1156cec43e1SGabriel L. Somloand reading four bytes from the data register. If the fw_cfg device is
116701caa3dSSimon Sapinpresent, the four bytes read will contain the characters ``QEMU``.
1176cec43e1SGabriel L. Somlo
1182cc06a88SKevin O'ConnorIf the DMA interface is available, then reading the DMA Address
119701caa3dSSimon SapinRegister returns 0x51454d5520434647 (``QEMU CFG`` in big-endian format).
1202cc06a88SKevin O'Connor
121701caa3dSSimon SapinRevision / feature bitmap (Key 0x0001, ``FW_CFG_ID``)
122701caa3dSSimon Sapin~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1236cec43e1SGabriel L. Somlo
124c9eae1d4SMarc MaríA 32-bit little-endian unsigned int, this item is used to check for enabled
125c9eae1d4SMarc Marífeatures.
126701caa3dSSimon Sapin
127c9eae1d4SMarc Marí- Bit 0: traditional interface. Always set.
128c9eae1d4SMarc Marí- Bit 1: DMA interface.
1296cec43e1SGabriel L. Somlo
130701caa3dSSimon SapinFile Directory (Key 0x0019, ``FW_CFG_FILE_DIR``)
131701caa3dSSimon Sapin~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132701caa3dSSimon Sapin
133701caa3dSSimon Sapin.. highlight:: c
1346cec43e1SGabriel L. Somlo
1356cec43e1SGabriel L. SomloFirmware configuration items stored at selector keys 0x0020 or higher
136701caa3dSSimon Sapin(``FW_CFG_FILE_FIRST`` or higher) have an associated entry in a directory
1376cec43e1SGabriel L. Somlostructure, which makes it easier for guest-side firmware to identify
138701caa3dSSimon Sapinand retrieve them. The format of this file directory (from ``fw_cfg.h`` in
139701caa3dSSimon Sapinthe QEMU source tree) is shown here, slightly annotated for clarity::
1406cec43e1SGabriel L. Somlo
1416cec43e1SGabriel L. Somlo    struct FWCfgFiles {		/* the entire file directory fw_cfg item */
1426cec43e1SGabriel L. Somlo        uint32_t count;		/* number of entries, in big-endian format */
1436cec43e1SGabriel L. Somlo        struct FWCfgFile f[];	/* array of file entries, see below */
1446cec43e1SGabriel L. Somlo    };
1456cec43e1SGabriel L. Somlo
1466cec43e1SGabriel L. Somlo    struct FWCfgFile {		/* an individual file entry, 64 bytes total */
1476cec43e1SGabriel L. Somlo        uint32_t size;		/* size of referenced fw_cfg item, big-endian */
1486cec43e1SGabriel L. Somlo        uint16_t select;	/* selector key of fw_cfg item, big-endian */
1496cec43e1SGabriel L. Somlo        uint16_t reserved;
1506cec43e1SGabriel L. Somlo        char name[56];		/* fw_cfg item name, NUL-terminated ascii */
1516cec43e1SGabriel L. Somlo    };
1526cec43e1SGabriel L. Somlo
153701caa3dSSimon SapinAll Other Data Items
154701caa3dSSimon Sapin~~~~~~~~~~~~~~~~~~~~
1556cec43e1SGabriel L. Somlo
156baf2d5bfSMichael S. TsirkinPlease consult the QEMU source for the most up-to-date and authoritative list
157baf2d5bfSMichael S. Tsirkinof selector keys and their respective items' purpose, format and writeability.
1586cec43e1SGabriel L. Somlo
159701caa3dSSimon SapinRanges
160701caa3dSSimon Sapin~~~~~~
1616cec43e1SGabriel L. Somlo
1626cec43e1SGabriel L. SomloTheoretically, there may be up to 0x4000 generic firmware configuration
1636cec43e1SGabriel L. Somloitems, and up to 0x4000 architecturally specific ones.
1646cec43e1SGabriel L. Somlo
165701caa3dSSimon Sapin===============  ===========
1666cec43e1SGabriel L. SomloSelector Reg.    Range Usage
167701caa3dSSimon Sapin===============  ===========
168baf2d5bfSMichael S. Tsirkin0x0000 - 0x3fff  Generic (0x0000 - 0x3fff, generally RO, possibly RW through
169baf2d5bfSMichael S. Tsirkin                 the DMA interface in QEMU v2.9+)
1706cec43e1SGabriel L. Somlo0x4000 - 0x7fff  Generic (0x0000 - 0x3fff, RW, ignored in QEMU v2.4+)
171baf2d5bfSMichael S. Tsirkin0x8000 - 0xbfff  Arch. Specific (0x0000 - 0x3fff, generally RO, possibly RW
172baf2d5bfSMichael S. Tsirkin                 through the DMA interface in QEMU v2.9+)
1736cec43e1SGabriel L. Somlo0xc000 - 0xffff  Arch. Specific (0x0000 - 0x3fff, RW, ignored in v2.4+)
174701caa3dSSimon Sapin===============  ===========
1756cec43e1SGabriel L. Somlo
176a5b3ebfdSLaszlo ErsekIn practice, the number of allowed firmware configuration items depends on the
177a5b3ebfdSLaszlo Ersekmachine type/version.
1786cec43e1SGabriel L. Somlo
179701caa3dSSimon SapinGuest-side DMA Interface
180701caa3dSSimon Sapin========================
181c9eae1d4SMarc Marí
182c9eae1d4SMarc MaríIf bit 1 of the feature bitmap is set, the DMA interface is present. This does
183c9eae1d4SMarc Marínot replace the existing fw_cfg interface, it is an add-on. This interface
184c9eae1d4SMarc Marícan be used through the 64-bit wide address register.
185c9eae1d4SMarc Marí
186c9eae1d4SMarc MaríThe address register is in big-endian format. The value for the register is 0
187c9eae1d4SMarc Maríat startup and after an operation. A write to the least significant half (at
188c9eae1d4SMarc Maríoffset 4) triggers an operation. This means that operations with 32-bit
189c9eae1d4SMarc Maríaddresses can be triggered with just one write, whereas operations with
190c9eae1d4SMarc Marí64-bit addresses can be triggered with one 64-bit write or two 32-bit writes,
191c9eae1d4SMarc Marístarting with the most significant half (at offset 0).
192c9eae1d4SMarc Marí
193701caa3dSSimon SapinIn this register, the physical address of a ``FWCfgDmaAccess`` structure in RAM
194701caa3dSSimon Sapinshould be written. This is the format of the ``FWCfgDmaAccess`` structure::
195c9eae1d4SMarc Marí
196c9eae1d4SMarc Marí    typedef struct FWCfgDmaAccess {
197c9eae1d4SMarc Marí        uint32_t control;
198c9eae1d4SMarc Marí        uint32_t length;
199c9eae1d4SMarc Marí        uint64_t address;
200c9eae1d4SMarc Marí    } FWCfgDmaAccess;
201c9eae1d4SMarc Marí
202c9eae1d4SMarc MaríThe fields of the structure are in big endian mode, and the field at the lowest
203701caa3dSSimon Sapinaddress is the ``control`` field.
204c9eae1d4SMarc Marí
205701caa3dSSimon SapinThe ``control`` field has the following bits:
206701caa3dSSimon Sapin
207c9eae1d4SMarc Marí- Bit 0: Error
208c9eae1d4SMarc Marí- Bit 1: Read
209c9eae1d4SMarc Marí- Bit 2: Skip
210c9eae1d4SMarc Marí- Bit 3: Select. The upper 16 bits are the selected index.
211baf2d5bfSMichael S. Tsirkin- Bit 4: Write
212c9eae1d4SMarc Marí
213701caa3dSSimon SapinWhen an operation is triggered, if the ``control`` field has bit 3 set, the
214c9eae1d4SMarc Maríupper 16 bits are interpreted as an index of a firmware configuration item.
215c9eae1d4SMarc MaríThis has the same effect as writing the selector register.
216c9eae1d4SMarc Marí
217701caa3dSSimon SapinIf the ``control`` field has bit 1 set, a read operation will be performed.
218701caa3dSSimon Sapin``length`` bytes for the current selector and offset will be copied into the
219701caa3dSSimon Sapinphysical RAM address specified by the ``address`` field.
220c9eae1d4SMarc Marí
221701caa3dSSimon SapinIf the ``control`` field has bit 4 set (and not bit 1), a write operation will be
222701caa3dSSimon Sapinperformed. ``length`` bytes will be copied from the physical RAM address
223701caa3dSSimon Sapinspecified by the ``address`` field to the current selector and offset. QEMU
224baf2d5bfSMichael S. Tsirkinprevents starting or finishing the write beyond the end of the item associated
225baf2d5bfSMichael S. Tsirkinwith the current selector (i.e., the item cannot be resized). Truncated writes
226baf2d5bfSMichael S. Tsirkinare dropped entirely. Writes to read-only items are also rejected. All of these
227701caa3dSSimon Sapinwrite errors set bit 0 (the error bit) in the ``control`` field.
228baf2d5bfSMichael S. Tsirkin
229701caa3dSSimon SapinIf the ``control`` field has bit 2 set (and neither bit 1 nor bit 4), a skip
230baf2d5bfSMichael S. Tsirkinoperation will be performed. The offset for the current selector will be
231701caa3dSSimon Sapinadvanced ``length`` bytes.
232c9eae1d4SMarc Marí
233701caa3dSSimon SapinTo check the result, read the ``control`` field:
234701caa3dSSimon Sapin
235701caa3dSSimon SapinError bit set
236701caa3dSSimon Sapin    Something went wrong.
237701caa3dSSimon SapinAll bits cleared
238701caa3dSSimon Sapin    Transfer finished successfully.
239701caa3dSSimon SapinOtherwise
240701caa3dSSimon Sapin    Transfer still in progress
241701caa3dSSimon Sapin    (doesn't happen today due to implementation not being async,
242c9eae1d4SMarc Marí    but may in the future).
243c9eae1d4SMarc Marí
244701caa3dSSimon SapinExternally Provided Items
245701caa3dSSimon Sapin=========================
24681b2b810SGabriel L. Somlo
24732031489SPhilippe Mathieu-DaudéSince v2.4, "file" fw_cfg items (i.e., items with selector keys above
248701caa3dSSimon Sapin``FW_CFG_FILE_FIRST``, and with a corresponding entry in the fw_cfg file
24981b2b810SGabriel L. Somlodirectory structure) may be inserted via the QEMU command line, using
250701caa3dSSimon Sapinthe following syntax::
25181b2b810SGabriel L. Somlo
25281b2b810SGabriel L. Somlo    -fw_cfg [name=]<item_name>,file=<path>
25381b2b810SGabriel L. Somlo
254701caa3dSSimon SapinOr::
2556407d76eSGabriel L. Somlo
2566407d76eSGabriel L. Somlo    -fw_cfg [name=]<item_name>,string=<string>
2576407d76eSGabriel L. Somlo
25832031489SPhilippe Mathieu-DaudéSince v5.1, QEMU allows some objects to generate fw_cfg-specific content,
25932031489SPhilippe Mathieu-Daudéthe content is then associated with a "file" item using the 'gen_id' option
260701caa3dSSimon Sapinin the command line, using the following syntax::
26132031489SPhilippe Mathieu-Daudé
26232031489SPhilippe Mathieu-Daudé    -object <generator-type>,id=<generated_id>,[generator-specific-options] \
26332031489SPhilippe Mathieu-Daudé    -fw_cfg [name=]<item_name>,gen_id=<generated_id>
26432031489SPhilippe Mathieu-Daudé
26563d3145aSMarkus ArmbrusterSee QEMU man page for more documentation.
2666407d76eSGabriel L. Somlo
26763d3145aSMarkus ArmbrusterUsing item_name with plain ASCII characters only is recommended.
2686407d76eSGabriel L. Somlo
269701caa3dSSimon SapinItem names beginning with ``opt/`` are reserved for users.  QEMU will
27063d3145aSMarkus Armbrusternever create entries with such names unless explicitly ordered by the
27163d3145aSMarkus Armbrusteruser.
27281b2b810SGabriel L. Somlo
27363d3145aSMarkus ArmbrusterTo avoid clashes among different users, it is strongly recommended
274701caa3dSSimon Sapinthat you use names beginning with ``opt/RFQDN/``, where RFQDN is a reverse
27563d3145aSMarkus Armbrusterfully qualified domain name you control.  For instance, if SeaBIOS
276701caa3dSSimon Sapinwanted to define additional names, the prefix ``opt/org.seabios/`` would
27763d3145aSMarkus Armbrusterbe appropriate.
27881b2b810SGabriel L. Somlo
279701caa3dSSimon SapinFor historical reasons, ``opt/ovmf/`` is reserved for OVMF firmware.
28063d3145aSMarkus Armbruster
281701caa3dSSimon SapinPrefix ``opt/org.qemu/`` is reserved for QEMU itself.
28263d3145aSMarkus Armbruster
283701caa3dSSimon SapinUse of names not beginning with ``opt/`` is potentially dangerous and
28463d3145aSMarkus Armbrusterentirely unsupported.  QEMU will warn if you try.
285baf2d5bfSMichael S. Tsirkin
286701caa3dSSimon SapinUse of names not beginning with ``opt/`` is tolerated with 'gen_id' (that
287f7d8afb1SPhilippe Mathieu-Daudéis, the warning is suppressed), but you must know exactly what you're
288f7d8afb1SPhilippe Mathieu-Daudédoing.
289f7d8afb1SPhilippe Mathieu-Daudé
290baf2d5bfSMichael S. TsirkinAll externally provided fw_cfg items are read-only to the guest.
291