On 4/7/20 3:29 AM, patrick.rudo...@9elements.com wrote:
> From: Patrick Rudolph
>
> Make all CBMEM buffers available to userland. This is useful for tools
> that are currently using /dev/mem.
>
> Make the id, size and address available, as well as the raw table data.
>
> Tools can easily scan the right CBMEM buffer by reading
> /sys/bus/coreboot/drivers/cbmem/coreboot*/cbmem_attributes/id
> or
> /sys/bus/coreboot/devices/coreboot*/cbmem_attributes/id
>
> The binary table data can then be read from
> /sys/bus/coreboot/drivers/cbmem/coreboot*/cbmem_attributes/data
> or
> /sys/bus/coreboot/devices/coreboot*/cbmem_attributes/data
>
> Signed-off-by: Patrick Rudolph
> ---
> -v2:
> - Add ABI documentation
> - Add 0x prefix on hex values
> -v3:
> - Use BIN_ATTR_RO
> -v4:
> - Use temporary memremap instead of persistent ioremap
> - Constify a struct
> - Get rid of unused headers
> - Use dev_{get|set}_drvdata
> - Use dev_groups to automatically handle attributes
> - Updated file description
> - Updated ABI documentation
> ---
> Documentation/ABI/stable/sysfs-bus-coreboot | 44 +++
> drivers/firmware/google/Kconfig | 9 ++
> drivers/firmware/google/Makefile| 1 +
> drivers/firmware/google/cbmem-coreboot.c| 128
> drivers/firmware/google/coreboot_table.h| 14 +++
> 5 files changed, 196 insertions(+)
> create mode 100644 Documentation/ABI/stable/sysfs-bus-coreboot
> create mode 100644 drivers/firmware/google/cbmem-coreboot.c
>
> diff --git a/Documentation/ABI/stable/sysfs-bus-coreboot
> b/Documentation/ABI/stable/sysfs-bus-coreboot
> new file mode 100644
> index ..6055906f41f2
> --- /dev/null
> +++ b/Documentation/ABI/stable/sysfs-bus-coreboot
> @@ -0,0 +1,44 @@
> +What:/sys/bus/coreboot/devices/.../cbmem_attributes/id
> +Date:Apr 2020
> +KernelVersion: 5.6
I guess these will be 5.8 now.
> +Contact: Patrick Rudolph
> +Description:
> + coreboot device directory can contain a file named
> + cbmem_attributes/id if the device corresponds to a CBMEM
> + buffer.
> + The file holds an ASCII representation of the CBMEM ID in hex
> + (e.g. 0xdeadbeef).
> +
> +What:/sys/bus/coreboot/devices/.../cbmem_attributes/size
> +Date:Apr 2020
> +KernelVersion: 5.6
> +Contact: Patrick Rudolph
> +Description:
> + coreboot device directory can contain a file named
> + cbmem_attributes/size if the device corresponds to a CBMEM
> + buffer.
> + The file holds an representation as decimal number of the
nit: "a representation" (maybe "a decimal representation"?)
> + CBMEM buffer size (e.g. 64).
> +
> +What:/sys/bus/coreboot/devices/.../cbmem_attributes/address
> +Date:Apr 2020
> +KernelVersion: 5.6
> +Contact: Patrick Rudolph
> +Description:
> + coreboot device directory can contain a file named
> + cbmem_attributes/address if the device corresponds to a CBMEM
> + buffer.
> + The file holds an ASCII representation of the physical address
> + of the CBMEM buffer in hex (e.g. 0x8000d000) and should
> + be used for debugging only.
> +
> +What:/sys/bus/coreboot/devices/.../cbmem_attributes/data
> +Date:Apr 2020
> +KernelVersion: 5.6
> +Contact: Patrick Rudolph
> +Description:
> + coreboot device directory can contain a file named
> + cbmem_attributes/data if the device corresponds to a CBMEM
> + buffer.
> + The file holds a read-only binary representation of the CBMEM
> + buffer.
> diff --git a/drivers/firmware/google/Kconfig b/drivers/firmware/google/Kconfig
> index a3a6ca659ffa..11a67c397ab3 100644
> --- a/drivers/firmware/google/Kconfig
> +++ b/drivers/firmware/google/Kconfig
> @@ -58,6 +58,15 @@ config GOOGLE_FRAMEBUFFER_COREBOOT
> This option enables the kernel to search for a framebuffer in
> the coreboot table. If found, it is registered with simplefb.
>
> +config GOOGLE_CBMEM_COREBOOT
> + tristate "Coreboot CBMEM access"
> + depends on GOOGLE_COREBOOT_TABLE
> + help
> + This option exposes all available CBMEM buffers to userland.
> + The CBMEM id, size and address as well as the raw table data
> + are exported as sysfs attributes of the corresponding coreboot
> + table.
> +
> config GOOGLE_MEMCONSOLE_COREBOOT
> tristate "Firmware Memory Console"
> depends on GOOGLE_COREBOOT_TABLE
> diff --git a/drivers/firmware/google/Makefile
> b/drivers/firmware/google/Makefile
> index d17caded5d88..62053cd6d058 100644
> --- a/drivers/firmware/google/Makefile
> +++