xref: /qemu/docs/specs/fw_cfg.rst (revision 63d3145aadbecaa7e8be1e74b5d6b5cbbeb4e153)
16cec43e1SGabriel L. SomloQEMU Firmware Configuration (fw_cfg) Device
26cec43e1SGabriel L. Somlo===========================================
36cec43e1SGabriel L. Somlo
46cec43e1SGabriel L. Somlo= Guest-side Hardware Interface =
56cec43e1SGabriel L. Somlo
66cec43e1SGabriel L. SomloThis hardware interface allows the guest to retrieve various data items
76cec43e1SGabriel L. Somlo(blobs) that can influence how the firmware configures itself, or may
86cec43e1SGabriel L. Somlocontain tables to be installed for the guest OS. Examples include device
96cec43e1SGabriel L. Somloboot order, ACPI and SMBIOS tables, virtual machine UUID, SMP and NUMA
106cec43e1SGabriel L. Somloinformation, kernel/initrd images for direct (Linux) kernel booting, etc.
116cec43e1SGabriel L. Somlo
126cec43e1SGabriel L. Somlo== Selector (Control) Register ==
136cec43e1SGabriel L. Somlo
146cec43e1SGabriel L. Somlo* Write only
156cec43e1SGabriel L. Somlo* Location: platform dependent (IOport or MMIO)
166cec43e1SGabriel L. Somlo* Width: 16-bit
176cec43e1SGabriel L. Somlo* Endianness: little-endian (if IOport), or big-endian (if MMIO)
186cec43e1SGabriel L. Somlo
196cec43e1SGabriel L. SomloA write to this register sets the index of a firmware configuration
206cec43e1SGabriel L. Somloitem which can subsequently be accessed via the data register.
216cec43e1SGabriel L. Somlo
226cec43e1SGabriel L. SomloSetting the selector register will cause the data offset to be set
236cec43e1SGabriel L. Somloto zero. The data offset impacts which data is accessed via the data
246cec43e1SGabriel L. Somloregister, and is explained below.
256cec43e1SGabriel L. Somlo
266cec43e1SGabriel L. SomloBit14 of the selector register indicates whether the configuration
276cec43e1SGabriel L. Somlosetting is being written. A value of 0 means the item is only being
286cec43e1SGabriel L. Somloread, and all write access to the data port will be ignored. A value
296cec43e1SGabriel L. Somloof 1 means the item's data can be overwritten by writes to the data
306cec43e1SGabriel L. Somloregister. In other words, configuration write mode is enabled when
316cec43e1SGabriel L. Somlothe selector value is between 0x4000-0x7fff or 0xc000-0xffff.
326cec43e1SGabriel L. Somlo
336cec43e1SGabriel L. SomloNOTE: As of QEMU v2.4, writes to the fw_cfg data register are no
346cec43e1SGabriel L. Somlo      longer supported, and will be ignored (treated as no-ops)!
356cec43e1SGabriel L. Somlo
366cec43e1SGabriel L. SomloBit15 of the selector register indicates whether the configuration
376cec43e1SGabriel L. Somlosetting is architecture specific. A value of 0 means the item is a
386cec43e1SGabriel L. Somlogeneric configuration item. A value of 1 means the item is specific
396cec43e1SGabriel L. Somloto a particular architecture. In other words, generic configuration
406cec43e1SGabriel L. Somloitems are accessed with a selector value between 0x0000-0x7fff, and
416cec43e1SGabriel L. Somloarchitecture specific configuration items are accessed with a selector
426cec43e1SGabriel L. Somlovalue between 0x8000-0xffff.
436cec43e1SGabriel L. Somlo
446cec43e1SGabriel L. Somlo== Data Register ==
456cec43e1SGabriel L. Somlo
466cec43e1SGabriel L. Somlo* Read/Write (writes ignored as of QEMU v2.4)
476cec43e1SGabriel L. Somlo* Location: platform dependent (IOport [*] or MMIO)
486cec43e1SGabriel L. Somlo* Width: 8-bit (if IOport), 8/16/32/64-bit (if MMIO)
496cec43e1SGabriel L. Somlo* Endianness: string-preserving
506cec43e1SGabriel L. Somlo
516cec43e1SGabriel L. Somlo[*] On platforms where the data register is exposed as an IOport, its
526cec43e1SGabriel L. Somloport number will always be one greater than the port number of the
536cec43e1SGabriel L. Somloselector register. In other words, the two ports overlap, and can not
546cec43e1SGabriel L. Somlobe mapped separately.
556cec43e1SGabriel L. Somlo
566cec43e1SGabriel L. SomloThe data register allows access to an array of bytes for each firmware
576cec43e1SGabriel L. Somloconfiguration data item. The specific item is selected by writing to
586cec43e1SGabriel L. Somlothe selector register, as described above.
596cec43e1SGabriel L. Somlo
606cec43e1SGabriel L. SomloInitially following a write to the selector register, the data offset
616cec43e1SGabriel L. Somlowill be set to zero. Each successful access to the data register will
626cec43e1SGabriel L. Somloincrement the data offset by the appropriate access width.
636cec43e1SGabriel L. Somlo
646cec43e1SGabriel L. SomloEach firmware configuration item has a maximum length of data
656cec43e1SGabriel L. Somloassociated with the item. After the data offset has passed the
666cec43e1SGabriel L. Somloend of this maximum data length, then any reads will return a data
676cec43e1SGabriel L. Somlovalue of 0x00, and all writes will be ignored.
686cec43e1SGabriel L. Somlo
696cec43e1SGabriel L. SomloAn N-byte wide read of the data register will return the next available
706cec43e1SGabriel L. SomloN bytes of the selected firmware configuration item, as a substring, in
716cec43e1SGabriel L. Somloincreasing address order, similar to memcpy().
726cec43e1SGabriel L. Somlo
736cec43e1SGabriel L. Somlo== Register Locations ==
746cec43e1SGabriel L. Somlo
756cec43e1SGabriel L. Somlo=== x86, x86_64 Register Locations ===
766cec43e1SGabriel L. Somlo
776cec43e1SGabriel L. SomloSelector Register IOport: 0x510
786cec43e1SGabriel L. SomloData Register IOport:     0x511
79c9eae1d4SMarc MaríDMA Address IOport:       0x514
80c9eae1d4SMarc Marí
81c9eae1d4SMarc Marí=== ARM Register Locations ===
82c9eae1d4SMarc Marí
83c9eae1d4SMarc MaríSelector Register address: Base + 8 (2 bytes)
84c9eae1d4SMarc MaríData Register address:     Base + 0 (8 bytes)
85c9eae1d4SMarc MaríDMA Address address:       Base + 16 (8 bytes)
866cec43e1SGabriel L. Somlo
8736a43ea8SGabriel L. Somlo== ACPI Interface ==
8836a43ea8SGabriel L. Somlo
8936a43ea8SGabriel L. SomloThe fw_cfg device is defined with ACPI ID "QEMU0002". Since we expect
9036a43ea8SGabriel L. SomloACPI tables to be passed into the guest through the fw_cfg device itself,
9136a43ea8SGabriel L. Somlothe guest-side firmware can not use ACPI to find fw_cfg. However, once the
9236a43ea8SGabriel L. Somlofirmware is finished setting up ACPI tables and hands control over to the
9336a43ea8SGabriel L. Somloguest kernel, the latter can use the fw_cfg ACPI node for a more accurate
9436a43ea8SGabriel L. Somloinventory of in-use IOport or MMIO regions.
9536a43ea8SGabriel L. Somlo
966cec43e1SGabriel L. Somlo== Firmware Configuration Items ==
976cec43e1SGabriel L. Somlo
986cec43e1SGabriel L. Somlo=== Signature (Key 0x0000, FW_CFG_SIGNATURE) ===
996cec43e1SGabriel L. Somlo
1006cec43e1SGabriel L. SomloThe presence of the fw_cfg selector and data registers can be verified
1016cec43e1SGabriel L. Somloby selecting the "signature" item using key 0x0000 (FW_CFG_SIGNATURE),
1026cec43e1SGabriel L. Somloand reading four bytes from the data register. If the fw_cfg device is
1036cec43e1SGabriel L. Somlopresent, the four bytes read will contain the characters "QEMU".
1046cec43e1SGabriel L. Somlo
1052cc06a88SKevin O'ConnorIf the DMA interface is available, then reading the DMA Address
1062cc06a88SKevin O'ConnorRegister returns 0x51454d5520434647 ("QEMU CFG" in big-endian format).
1072cc06a88SKevin O'Connor
108c9eae1d4SMarc Marí=== Revision / feature bitmap (Key 0x0001, FW_CFG_ID) ===
1096cec43e1SGabriel L. Somlo
110c9eae1d4SMarc MaríA 32-bit little-endian unsigned int, this item is used to check for enabled
111c9eae1d4SMarc Marífeatures.
112c9eae1d4SMarc Marí - Bit 0: traditional interface. Always set.
113c9eae1d4SMarc Marí - Bit 1: DMA interface.
1146cec43e1SGabriel L. Somlo
1156cec43e1SGabriel L. Somlo=== File Directory (Key 0x0019, FW_CFG_FILE_DIR) ===
1166cec43e1SGabriel L. Somlo
1176cec43e1SGabriel L. SomloFirmware configuration items stored at selector keys 0x0020 or higher
1186cec43e1SGabriel L. Somlo(FW_CFG_FILE_FIRST or higher) have an associated entry in a directory
1196cec43e1SGabriel L. Somlostructure, which makes it easier for guest-side firmware to identify
1206cec43e1SGabriel L. Somloand retrieve them. The format of this file directory (from fw_cfg.h in
1216cec43e1SGabriel L. Somlothe QEMU source tree) is shown here, slightly annotated for clarity:
1226cec43e1SGabriel L. Somlo
1236cec43e1SGabriel L. Somlostruct FWCfgFiles {		/* the entire file directory fw_cfg item */
1246cec43e1SGabriel L. Somlo    uint32_t count;		/* number of entries, in big-endian format */
1256cec43e1SGabriel L. Somlo    struct FWCfgFile f[];	/* array of file entries, see below */
1266cec43e1SGabriel L. Somlo};
1276cec43e1SGabriel L. Somlo
1286cec43e1SGabriel L. Somlostruct FWCfgFile {		/* an individual file entry, 64 bytes total */
1296cec43e1SGabriel L. Somlo    uint32_t size;		/* size of referenced fw_cfg item, big-endian */
1306cec43e1SGabriel L. Somlo    uint16_t select;		/* selector key of fw_cfg item, big-endian */
1316cec43e1SGabriel L. Somlo    uint16_t reserved;
1326cec43e1SGabriel L. Somlo    char name[56];		/* fw_cfg item name, NUL-terminated ascii */
1336cec43e1SGabriel L. Somlo};
1346cec43e1SGabriel L. Somlo
1356cec43e1SGabriel L. Somlo=== All Other Data Items ===
1366cec43e1SGabriel L. Somlo
1376cec43e1SGabriel L. SomloPlease consult the QEMU source for the most up-to-date and authoritative
1386cec43e1SGabriel L. Somlolist of selector keys and their respective items' purpose and format.
1396cec43e1SGabriel L. Somlo
1406cec43e1SGabriel L. Somlo=== Ranges ===
1416cec43e1SGabriel L. Somlo
1426cec43e1SGabriel L. SomloTheoretically, there may be up to 0x4000 generic firmware configuration
1436cec43e1SGabriel L. Somloitems, and up to 0x4000 architecturally specific ones.
1446cec43e1SGabriel L. Somlo
1456cec43e1SGabriel L. SomloSelector Reg.    Range Usage
1466cec43e1SGabriel L. Somlo---------------  -----------
1476cec43e1SGabriel L. Somlo0x0000 - 0x3fff  Generic (0x0000 - 0x3fff, RO)
1486cec43e1SGabriel L. Somlo0x4000 - 0x7fff  Generic (0x0000 - 0x3fff, RW, ignored in QEMU v2.4+)
1496cec43e1SGabriel L. Somlo0x8000 - 0xbfff  Arch. Specific (0x0000 - 0x3fff, RO)
1506cec43e1SGabriel L. Somlo0xc000 - 0xffff  Arch. Specific (0x0000 - 0x3fff, RW, ignored in v2.4+)
1516cec43e1SGabriel L. Somlo
1526cec43e1SGabriel L. SomloIn practice, the number of allowed firmware configuration items is given
1536cec43e1SGabriel L. Somloby the value of FW_CFG_MAX_ENTRY (see fw_cfg.h).
1546cec43e1SGabriel L. Somlo
155c9eae1d4SMarc Marí= Guest-side DMA Interface =
156c9eae1d4SMarc Marí
157c9eae1d4SMarc MaríIf bit 1 of the feature bitmap is set, the DMA interface is present. This does
158c9eae1d4SMarc Marínot replace the existing fw_cfg interface, it is an add-on. This interface
159c9eae1d4SMarc Marícan be used through the 64-bit wide address register.
160c9eae1d4SMarc Marí
161c9eae1d4SMarc MaríThe address register is in big-endian format. The value for the register is 0
162c9eae1d4SMarc Maríat startup and after an operation. A write to the least significant half (at
163c9eae1d4SMarc Maríoffset 4) triggers an operation. This means that operations with 32-bit
164c9eae1d4SMarc Maríaddresses can be triggered with just one write, whereas operations with
165c9eae1d4SMarc Marí64-bit addresses can be triggered with one 64-bit write or two 32-bit writes,
166c9eae1d4SMarc Marístarting with the most significant half (at offset 0).
167c9eae1d4SMarc Marí
168c9eae1d4SMarc MaríIn this register, the physical address of a FWCfgDmaAccess structure in RAM
169c9eae1d4SMarc Maríshould be written. This is the format of the FWCfgDmaAccess structure:
170c9eae1d4SMarc Marí
171c9eae1d4SMarc Marítypedef struct FWCfgDmaAccess {
172c9eae1d4SMarc Marí    uint32_t control;
173c9eae1d4SMarc Marí    uint32_t length;
174c9eae1d4SMarc Marí    uint64_t address;
175c9eae1d4SMarc Marí} FWCfgDmaAccess;
176c9eae1d4SMarc Marí
177c9eae1d4SMarc MaríThe fields of the structure are in big endian mode, and the field at the lowest
178c9eae1d4SMarc Maríaddress is the "control" field.
179c9eae1d4SMarc Marí
180c9eae1d4SMarc MaríThe "control" field has the following bits:
181c9eae1d4SMarc Marí - Bit 0: Error
182c9eae1d4SMarc Marí - Bit 1: Read
183c9eae1d4SMarc Marí - Bit 2: Skip
184c9eae1d4SMarc Marí - Bit 3: Select. The upper 16 bits are the selected index.
185c9eae1d4SMarc Marí
186c9eae1d4SMarc MaríWhen an operation is triggered, if the "control" field has bit 3 set, the
187c9eae1d4SMarc Maríupper 16 bits are interpreted as an index of a firmware configuration item.
188c9eae1d4SMarc MaríThis has the same effect as writing the selector register.
189c9eae1d4SMarc Marí
190c9eae1d4SMarc MaríIf the "control" field has bit 1 set, a read operation will be performed.
191c9eae1d4SMarc Marí"length" bytes for the current selector and offset will be copied into the
192c9eae1d4SMarc Maríphysical RAM address specified by the "address" field.
193c9eae1d4SMarc Marí
194c9eae1d4SMarc MaríIf the "control" field has bit 2 set (and not bit 1), a skip operation will be
195c9eae1d4SMarc Maríperformed. The offset for the current selector will be advanced "length" bytes.
196c9eae1d4SMarc Marí
197c9eae1d4SMarc MaríTo check the result, read the "control" field:
198c9eae1d4SMarc Marí   error bit set        ->  something went wrong.
199c9eae1d4SMarc Marí   all bits cleared     ->  transfer finished successfully.
200c9eae1d4SMarc Marí   otherwise            ->  transfer still in progress (doesn't happen
201c9eae1d4SMarc Marí                            today due to implementation not being async,
202c9eae1d4SMarc Marí                            but may in the future).
203c9eae1d4SMarc Marí
2049c4a5c55SGabriel L. Somlo= Externally Provided Items =
20581b2b810SGabriel L. Somlo
20681b2b810SGabriel L. SomloAs of v2.4, "file" fw_cfg items (i.e., items with selector keys above
20781b2b810SGabriel L. SomloFW_CFG_FILE_FIRST, and with a corresponding entry in the fw_cfg file
20881b2b810SGabriel L. Somlodirectory structure) may be inserted via the QEMU command line, using
20981b2b810SGabriel L. Somlothe following syntax:
21081b2b810SGabriel L. Somlo
21181b2b810SGabriel L. Somlo    -fw_cfg [name=]<item_name>,file=<path>
21281b2b810SGabriel L. Somlo
213*63d3145aSMarkus ArmbrusterOr
2146407d76eSGabriel L. Somlo
2156407d76eSGabriel L. Somlo    -fw_cfg [name=]<item_name>,string=<string>
2166407d76eSGabriel L. Somlo
217*63d3145aSMarkus ArmbrusterSee QEMU man page for more documentation.
2186407d76eSGabriel L. Somlo
219*63d3145aSMarkus ArmbrusterUsing item_name with plain ASCII characters only is recommended.
2206407d76eSGabriel L. Somlo
221*63d3145aSMarkus ArmbrusterItem names beginning with "opt/" are reserved for users.  QEMU will
222*63d3145aSMarkus Armbrusternever create entries with such names unless explicitly ordered by the
223*63d3145aSMarkus Armbrusteruser.
22481b2b810SGabriel L. Somlo
225*63d3145aSMarkus ArmbrusterTo avoid clashes among different users, it is strongly recommended
226*63d3145aSMarkus Armbrusterthat you use names beginning with opt/RFQDN/, where RFQDN is a reverse
227*63d3145aSMarkus Armbrusterfully qualified domain name you control.  For instance, if SeaBIOS
228*63d3145aSMarkus Armbrusterwanted to define additional names, the prefix "opt/org.seabios/" would
229*63d3145aSMarkus Armbrusterbe appropriate.
23081b2b810SGabriel L. Somlo
231*63d3145aSMarkus ArmbrusterFor historical reasons, "opt/ovmf/" is reserved for OVMF firmware.
232*63d3145aSMarkus Armbruster
233*63d3145aSMarkus ArmbrusterPrefix "opt/org.qemu/" is reserved for QEMU itself.
234*63d3145aSMarkus Armbruster
235*63d3145aSMarkus ArmbrusterUse of names not beginning with "opt/" is potentially dangerous and
236*63d3145aSMarkus Armbrusterentirely unsupported.  QEMU will warn if you try.
237