Skip to content

Commit

Permalink
firmware: introduce sysfs driver for QEMU's fw_cfg device
Browse files Browse the repository at this point in the history
Make fw_cfg entries of type "file" available via sysfs. Entries
are listed under /sys/firmware/qemu_fw_cfg/by_key, in folders
named after each entry's selector key. Filename, selector value,
and size read-only attributes are included for each entry. Also,
a "raw" attribute allows retrieval of the full binary content of
each entry.

The fw_cfg device can be instantiated automatically from ACPI or
the Device Tree, or manually by using a kernel module (or command
line) parameter, with a syntax outlined in the documentation file.

Signed-off-by: Gabriel Somlo <somlo@cmu.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Gabriel Somlo authored and Greg Kroah-Hartman committed Feb 10, 2016
1 parent 2fe829a commit 75f3e8e
Show file tree
Hide file tree
Showing 4 changed files with 726 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Documentation/ABI/testing/sysfs-firmware-qemu_fw_cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
What: /sys/firmware/qemu_fw_cfg/
Date: August 2015
Contact: Gabriel Somlo <somlo@cmu.edu>
Description:
Several different architectures supported by QEMU (x86, arm,
sun4*, ppc/mac) are provisioned with a firmware configuration
(fw_cfg) device, originally intended as a way for the host to
provide configuration data to the guest firmware. Starting
with QEMU v2.4, arbitrary fw_cfg file entries may be specified
by the user on the command line, which makes fw_cfg additionally
useful as an out-of-band, asynchronous mechanism for providing
configuration data to the guest userspace.

The authoritative guest-side hardware interface documentation
to the fw_cfg device can be found in "docs/specs/fw_cfg.txt"
in the QEMU source tree.

=== SysFS fw_cfg Interface ===

The fw_cfg sysfs interface described in this document is only
intended to display discoverable blobs (i.e., those registered
with the file directory), as there is no way to determine the
presence or size of "legacy" blobs (with selector keys between
0x0002 and 0x0018) programmatically.

All fw_cfg information is shown under:

/sys/firmware/qemu_fw_cfg/

The only legacy blob displayed is the fw_cfg device revision:

/sys/firmware/qemu_fw_cfg/rev

--- Discoverable fw_cfg blobs by selector key ---

All discoverable blobs listed in the fw_cfg file directory are
displayed as entries named after their unique selector key
value, e.g.:

/sys/firmware/qemu_fw_cfg/by_key/32
/sys/firmware/qemu_fw_cfg/by_key/33
/sys/firmware/qemu_fw_cfg/by_key/34
...

Each such fw_cfg sysfs entry has the following values exported
as attributes:

name : The 56-byte nul-terminated ASCII string used as the
blob's 'file name' in the fw_cfg directory.
size : The length of the blob, as given in the fw_cfg
directory.
key : The value of the blob's selector key as given in the
fw_cfg directory. This value is the same as used in
the parent directory name.
raw : The raw bytes of the blob, obtained by selecting the
entry via the control register, and reading a number
of bytes equal to the blob size from the data
register.
19 changes: 19 additions & 0 deletions drivers/firmware/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,25 @@ config RASPBERRYPI_FIRMWARE
This option enables support for communicating with the firmware on the
Raspberry Pi.

config FW_CFG_SYSFS
tristate "QEMU fw_cfg device support in sysfs"
depends on SYSFS && (ARM || ARM64 || PPC_PMAC || SPARC || X86)
default n
help
Say Y or M here to enable the exporting of the QEMU firmware
configuration (fw_cfg) file entries via sysfs. Entries are
found under /sys/firmware/fw_cfg when this option is enabled
and loaded.

config FW_CFG_SYSFS_CMDLINE
bool "QEMU fw_cfg device parameter parsing"
depends on FW_CFG_SYSFS
help
Allow the qemu_fw_cfg device to be initialized via the kernel
command line or using a module parameter.
WARNING: Using incorrect parameters (base address in particular)
may crash your system.

config QCOM_SCM
bool
depends on ARM || ARM64
Expand Down
1 change: 1 addition & 0 deletions drivers/firmware/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ obj-$(CONFIG_ISCSI_IBFT_FIND) += iscsi_ibft_find.o
obj-$(CONFIG_ISCSI_IBFT) += iscsi_ibft.o
obj-$(CONFIG_FIRMWARE_MEMMAP) += memmap.o
obj-$(CONFIG_RASPBERRYPI_FIRMWARE) += raspberrypi.o
obj-$(CONFIG_FW_CFG_SYSFS) += qemu_fw_cfg.o
obj-$(CONFIG_QCOM_SCM) += qcom_scm.o
obj-$(CONFIG_QCOM_SCM_64) += qcom_scm-64.o
obj-$(CONFIG_QCOM_SCM_32) += qcom_scm-32.o
Expand Down
Loading

0 comments on commit 75f3e8e

Please sign in to comment.