Introducing firmware late binding
Subsystems (6)
Rodrigo Vivi
maintainercover Introducing firmware late binding
Introducing firmware late binding feature to enable firmware loading for the devices, such as the fan controller and voltage regulator, during the driver probe.
Typically, firmware for these devices are part of IFWI flash image but can be replaced at probe after OEM tuning.
This version (v8?): I'm covering for Badal's vacation since I'd like to take this as soon as possible to drm-xe-next.
The changes in this version are mostly to address the valid Greg's concerns on the mei patches. In summary:
- Proper commit messages
- 'Late Binding' documentation and explanation
- Proper code documentation, fixing word and style
- Bring consistency to the prefixes and naming
Previous revision history from Badal:
https://lore.kernel.org/intel-xe/[email protected]
Thanks,
Rodrigo.
Alexander Usyskin (2):
mei: bus: add mei_cldev_mtu interface
mei: late_bind: add late binding component driver
Badal Nilawar (7):
drm/xe/xe_late_bind_fw: Introducing xe_late_bind_fw drm/xe/xe_late_bind_fw: Initialize late binding firmware drm/xe/xe_late_bind_fw: Load late binding firmware drm/xe/xe_late_bind_fw: Reload late binding fw in rpm resume drm/xe/xe_late_bind_fw: Reload late binding fw during system resume drm/xe/xe_late_bind_fw: Introduce debug fs node to disable late
binding
drm/xe/xe_late_bind_fw: Extract and print version info
drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_debugfs.c | 41 ++ drivers/gpu/drm/xe/xe_device.c | 5 + drivers/gpu/drm/xe/xe_device_types.h | 6 + drivers/gpu/drm/xe/xe_late_bind_fw.c | 464 +++++++++++++++++++++ drivers/gpu/drm/xe/xe_late_bind_fw.h | 17 + drivers/gpu/drm/xe/xe_late_bind_fw_types.h | 75 ++++ drivers/gpu/drm/xe/xe_pci.c | 2 + drivers/gpu/drm/xe/xe_pci_types.h | 1 + drivers/gpu/drm/xe/xe_pm.c | 8 + drivers/gpu/drm/xe/xe_uc_fw_abi.h | 66 +++ drivers/misc/mei/Kconfig | 13 + drivers/misc/mei/Makefile | 1 + drivers/misc/mei/bus.c | 13 + drivers/misc/mei/mei_lb.c | 315 ++++++++++++++ include/drm/intel/i915_component.h | 1 + include/drm/intel/intel_lb_mei_interface.h | 70 ++++ include/linux/mei_cl_bus.h | 1 + 18 files changed, 1100 insertions(+) create mode 100644 drivers/gpu/drm/xe/xe_late_bind_fw.c create mode 100644 drivers/gpu/drm/xe/xe_late_bind_fw.h create mode 100644 drivers/gpu/drm/xe/xe_late_bind_fw_types.h create mode 100644 drivers/misc/mei/mei_lb.c create mode 100644 include/drm/intel/intel_lb_mei_interface.h
Signature · 1 line
2.49.0
Rodrigo Vivi
maintainerPATCH 1/9 mei: bus: add mei_cldev_mtu interface
From: Alexander Usyskin <[email protected]>
Add a new helper function that allows MEI client drivers to query the maximum transmission unit (MTU) for a connected MEI client.
This is useful for clients that need to transmit large payloads, such as firmware blobs, allowing them to determine the maximum message size that can be safely sent before starting transmission and size of the buffer to allocate when receiving data.
---
Change in this revision: Proper commit message.
drivers/misc/mei/bus.c | 13 +++++++++++++ include/linux/mei_cl_bus.h | 1 + 2 files changed, 14 insertions(+)
drivers/misc/mei/bus.c +13 -0
@@ -614,6 +614,19 @@ u8 mei_cldev_ver(const struct mei_cl_device *cldev) }EXPORT_SYMBOL_GPL (mei_cldev_ver); +/** +* mei_cldev_mtu - max message that client can send and receive +* +* @cldev: mei client device +* +* Return: mtu or 0 if client is not connected +*/ +size_t mei_cldev_mtu (const struct mei_cl_device *cldev) +{ +return mei_cl_mtu (cldev->cl); +} +EXPORT_SYMBOL_GPL (mei_cldev_mtu); +/** * mei_cldev_enabled - check whether the device is enabled *
include/linux/mei_cl_bus.h +1 -0
@@ -113,6 +113,7 @@ int mei_cldev_register_notif_cb(struct mei_cl_device *cldev, mei_cldev_cb_t notif_cb);u8 mei_cldev_ver (const struct mei_cl_device *cldev); +size_t mei_cldev_mtu (const struct mei_cl_device *cldev);void *mei_cldev_get_drvdata (const struct mei_cl_device *cldev);void mei_cldev_set_drvdata (struct mei_cl_device *cldev,void *data);
Signature · 1 line
2.49.0
Rodrigo Vivi
maintainerPATCH 2/9 mei: late_bind: add late binding component driver
In reply to Rodrigo ViviFrom: Alexander Usyskin <[email protected]>
Introduce a new MEI client driver to support Late Binding firmware upload/update for Intel discrete graphics platforms.
Late Binding is a runtime firmware upload/update mechanism that allows payloads, such as fan control and voltage regulator, to be securely delivered and applied without requiring SPI flash updates or system reboots. This driver enables the Xe graphics driver and other user-space tools to push such firmware blobs to the authentication firmware via the MEI interface.
The driver handles authentication, versioning, and communication with the authentication firmware, which in turn coordinates with the PUnit/PCODE to apply the payload.
This is a foundational component for enabling dynamic, secure, and re-entrant configuration updates on platforms like Battlemage.
---
Changes in this revision:
- Proper commit message
- Proper explanation of 'Late Binding' on Kconfig help and doc
- Consistency in naming:
+ mei_ prefix where it makes sense
+ use 'lb' for short of 'Late Binding' instead of 'late_bind' Including s/CONFIG_INTEL_MEI_LATE_BIND/CONFIG_INTEL_MEI_LB
+ remove stray 'struct module'
+ Fix structs and enum documentation style and fields
+ Remove 'CSC' to avoid yet another acronym. 'Authentication firmware' it is.
+ specify size unit
+ s/push_config/push_payload
drivers/misc/mei/Kconfig | 13 + drivers/misc/mei/Makefile | 1 + drivers/misc/mei/mei_lb.c | 315 +++++++++++++++++++++ include/drm/intel/i915_component.h | 1 + include/drm/intel/intel_lb_mei_interface.h | 70 +++++ 5 files changed, 400 insertions(+) create mode 100644 drivers/misc/mei/mei_lb.c create mode 100644 include/drm/intel/intel_lb_mei_interface.h
drivers/misc/mei/Kconfig +13 -0
@@ -81,6 +81,19 @@ config INTEL_MEI_VSC This driver can also be built as a module. If so, the module will be called mei-vsc. +config INTEL_MEI_LB + tristate "Intel Late Binding (LB) support on ME Interface" + depends on INTEL_MEI_ME + depends on DRM_XE + help + Enable support for Intel Late Binding (LB) via the MEI interface. + + Late Binding is a method for applying firmware updates at runtime, + allowing the Intel Xe driver to load firmware payloads such as + fan controller or voltage regulator. These firmware updates are + authenticated and versioned, and do not require firmware flashing + or system reboot. + source "drivers/misc/mei/hdcp/Kconfig" source "drivers/misc/mei/pxp/Kconfig" source "drivers/misc/mei/gsc_proxy/Kconfig"
drivers/misc/mei/Makefile +1 -0
@@ -31,6 +31,7 @@ CFLAGS_mei-trace.o = -I$(src) obj-$(CONFIG_INTEL_MEI_HDCP) += hdcp/ obj-$(CONFIG_INTEL_MEI_PXP) += pxp/ obj-$(CONFIG_INTEL_MEI_GSC_PROXY) += gsc_proxy/ +obj-$(CONFIG_INTEL_MEI_LB) += mei_lb.o obj-$(CONFIG_INTEL_MEI_VSC_HW) += mei-vsc-hw.o mei-vsc-hw-y := vsc-tp.o
drivers/misc/mei/mei_lb.c new file +315 -0
315 lines not on this page · raw message
include/drm/intel/i915_component.h +1 -0
@@ -31,6 +31,7 @@ enum i915_component_type {I915_COMPONENT_HDCP ,I915_COMPONENT_PXP ,I915_COMPONENT_GSC_PROXY , + INTEL_COMPONENT_LB, };/* MAX_PORT is the number of port
include/drm/intel/intel_lb_mei_interface.h new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
2.49.0
Greg KH
maintainerRe: [PATCH 2/9] mei: late_bind: add late binding component driver
Quoted 263 lines · Rodrigo Vivi
From: Alexander Usyskin <[email protected]>
Introduce a new MEI client driver to support Late Binding firmware upload/update for Intel discrete graphics platforms.
Late Binding is a runtime firmware upload/update mechanism that allows payloads, such as fan control and voltage regulator, to be securely delivered and applied without requiring SPI flash updates or system reboots. This driver enables the Xe graphics driver and other user-space tools to push such firmware blobs to the authentication firmware via the MEI interface.
The driver handles authentication, versioning, and communication with the authentication firmware, which in turn coordinates with the PUnit/PCODE to apply the payload.
This is a foundational component for enabling dynamic, secure, and re-entrant configuration updates on platforms like Battlemage.
Signed-off-by Alexander Usyskin <[email protected]>Signed-off-by Badal Nilawar <[email protected]>Reviewed-by Anshuman Gupta <[email protected]>Signed-off-by Rodrigo Vivi <[email protected]>---
Changes in this revision:
- Proper commit message
- Proper explanation of 'Late Binding' onKconfighelp and doc
- Consistency in naming:
+mei_prefix where it makes sense
+ use 'lb' for short of 'Late Binding' instead of 'late_bind' Including s/CONFIG_INTEL_MEI_LATE_BIND/CONFIG_INTEL_MEI_LB
+ remove stray 'struct module'
+ Fix structs and enum documentation style and fields
+ Remove 'CSC' to avoid yet another acronym. 'Authentication firmware' it is.
+ specify size unit
+ s/push_config/push_payloaddrivers/misc/mei/Kconfig | 13 + drivers/misc/mei/Makefile | 1 + drivers/misc/mei/mei_lb.c | 315 +++++++++++++++++++++ include/drm/intel/i915_component.h | 1 + include/drm/intel/intel_lb_mei_interface.h | 70 +++++ 5 files changed, 400 insertions(+) create mode 100644 drivers/misc/mei/mei_lb.c create mode 100644 include/drm/intel/intel_lb_mei_interface.hdrivers/misc/mei/Kconfig +13
-0@@ -81,6 +81,19 @@ config INTEL_MEI_VSC This driver can also be built as a module. If so, the module will be called mei-vsc. +config INTEL_MEI_LB + tristate "Intel Late Binding (LB) support on ME Interface" + depends on INTEL_MEI_ME + depends on DRM_XE + help + Enable support for Intel Late Binding (LB) via the MEI interface. + + Late Binding is a method for applying firmware updates at runtime, + allowing the Intel Xe driver to load firmware payloads such as + fan controller or voltage regulator. These firmware updates are + authenticated and versioned, and do not require firmware flashing + or system reboot. + source "drivers/misc/mei/hdcp/Kconfig" source "drivers/misc/mei/pxp/Kconfig" source "drivers/misc/mei/gsc_proxy/Kconfig"drivers/misc/mei/Makefile +1
-0@@ -31,6 +31,7 @@ CFLAGS_mei-trace.o = -I$(src) obj-$(CONFIG_INTEL_MEI_HDCP) += hdcp/ obj-$(CONFIG_INTEL_MEI_PXP) += pxp/ obj-$(CONFIG_INTEL_MEI_GSC_PROXY) += gsc_proxy/ +obj-$(CONFIG_INTEL_MEI_LB) += mei_lb.o obj-$(CONFIG_INTEL_MEI_VSC_HW) += mei-vsc-hw.o mei-vsc-hw-y := vsc-tp.odrivers/misc/mei/mei_lb.c new file +174
-0@@ -0,0 +1,315 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2025 Intel Corporation +*/ +#include <drm/intel/i915_component.h> +#include <drm/intel/intel_lb_mei_interface.h> +#include <linux/component.h> +#include <linux/pci.h> +#include <linux/mei_cl_bus.h> +#include <linux/module.h> +#include <linux/overflow.h> +#include <linux/slab.h> +#include <linux/uuid.h> + +#include "mkhi.h" + +/** +* DOC: Late Binding Firmware Update/Upload +* +* Late Binding is a firmware update/upload mechanism that allows configuration +* payloads to be securely delivered and applied at runtime, rather than +* being embedded in the system firmware image (e.g., IFWI or SPI flash). +* +* This mechanism is used to update device-level configuration such as: +* - Fan controller +* - Voltage regulator (VR) +* +* Key Characteristics: +* --------------------- +* - Runtime Delivery: +* Firmware blobs are loaded by the host driver (e.g., Xe KMD) +* after the GPU or SoC has booted. +* +* - Secure and Authenticated: +* All payloads are signed and verified by the authentication firmware. +* +* - No Firmware Flashing Required: +* Updates are applied in volatile memory and do not require SPI flash +* modification or system reboot. +* +* - Re-entrant: +* Multiple updates of the same or different types can be applied +* sequentially within a single boot session. +* +* - Version Controlled: +* Each payload includes version and security version number (SVN) +* metadata to support anti-rollback enforcement. +* +* Upload Flow: +* ------------ +* 1. Host driver (KMD or user-space tool) loads the late binding firmware. +* 2. Firmware is passed to the MEI interface and forwarded to +* authentication firmware. +* 3. Authentication firmware authenticates the payload and extracts +* command and data arrays. +* 4. Authentication firmware delivers the configuration to PUnit/PCODE. +* 5. Status is returned back to the host via MEI. +*/ + +#define INTEL_LB_CMD 0x12 +#define INTEL_LB_RSP (INTEL_LB_CMD | 0x80) + +#define INTEL_LB_SEND_TIMEOUT_MSEC 3000 +#define INTEL_LB_RECV_TIMEOUT_MSEC 3000 + +/** +* struct mei_lb_req - Late Binding request structure +* @header: MKHI message header (see struct mkhi_msg_hdr) +* @type: Type of the Late Binding payload +* @flags: Flags to be passed to the authentication firmware (e.g. %INTEL_LB_FLAGS_IS_PERSISTENT) +* @reserved: Reserved for future use by authentication firmware, must be set to 0 +* @payload_size: Size of the payload data in bytes +* @payload: Payload data to be sent to the authentication firmware +*/ +struct mei_lb_req { +struct mkhi_msg_hdr header; +__le32 type; +__le32 flags; +__le32 reserved[2 ]; +__le32 payload_size; + u8 payload[] __counted_by(payload_size); +} __packed; + +/** +* struct mei_lb_rsp - Late Binding response structure +* @header: MKHI message header (see struct mkhi_msg_hdr) +* @type: Type of the Late Binding payload +* @reserved: Reserved for future use by authentication firmware, must be set to 0 +* @status: Status returned by authentication firmware (see enum intel_lb_status) +*/ +struct mei_lb_rsp { +struct mkhi_msg_hdr header; +__le32 type; +__le32 reserved[2 ]; +__le32 status; +} __packed; + +static int mei_lb_check_response (const struct device *dev,const struct mkhi_msg_hdr *hdr) +{ +if (hdr->group_id !=MKHI_GROUP_ID_GFX ) { +dev_err (dev,"Mismatch group id: 0x%x instead of 0x%x\n" , + hdr->group_id,MKHI_GROUP_ID_GFX ); +return -EINVAL ; + } + +if (hdr->command !=INTEL_LB_RSP ) { +dev_err (dev,"Mismatch command: 0x%x instead of 0x%x\n" , + hdr->command,INTEL_LB_RSP ); +return -EINVAL ; + } + +if (hdr->result) { +dev_err (dev,"Error in result: 0x%x\n" , hdr->result); +return -EINVAL ; + } + +return 0 ; +} + +static int mei_lb_push_payload (struct device *dev, +enum intel_lb_type type,u32 flags, +const void *payload,size_t payload_size) +{ +struct mei_cl_device *cldev; +struct mei_lb_req *req =NULL ; +struct mei_lb_rsp rsp; +size_t req_size; +ssize_t bytes; +int ret; + + cldev =to_mei_cl_device (dev); + + ret =mei_cldev_enable (cldev); +if (ret) { +dev_dbg (dev,"mei_cldev_enable failed. %d\n" , ret); +return ret; + } + + req_size =struct_size (req, payload, payload_size); +if (req_size >mei_cldev_mtu (cldev)) { +dev_err (dev,"Payload is too big %zu\n" , payload_size); + ret = -EMSGSIZE ; + goto end; + } + + req =kmalloc (req_size,GFP_KERNEL ); +if (!req) { + ret = -ENOMEM ; + goto end; + } + + req->header.group_id =MKHI_GROUP_ID_GFX ; + req->header.command =INTEL_LB_CMD ; + req->type =cpu_to_le32 (type); + req->flags =cpu_to_le32 (flags); + req->reserved[0 ] =0 ; + req->reserved[1 ] =0 ; + req->payload_size =cpu_to_le32 (payload_size); +memcpy (req->payload, payload, payload_size); + + bytes =mei_cldev_send_timeout (cldev, + (void *)req, req_size,INTEL_LB_SEND_TIMEOUT_MSEC ); +if (bytes <0 ) { +dev_err (dev,"mei_cldev_send failed. %zd\n" , bytes); + ret = bytes; + goto end; + } + + bytes =mei_cldev_recv_timeout (cldev, + (void *)&rsp,sizeof (rsp),INTEL_LB_RECV_TIMEOUT_MSEC ); +if (bytes <0 ) { +dev_err (dev,"mei_cldev_recv failed. %zd\n" , bytes); + ret = bytes; + goto end;
drivers/misc/mei/mei_lb.c line 184
Quoted 10 lines
drivers/misc/mei/mei_lb.c new file +10
-0+ } +if (bytes <sizeof (rsp.header)) { +dev_err (dev,"bad response header from the firmware: size %zd < %zu\n" , + bytes,sizeof (rsp.header)); + ret = -EPROTO ; + goto end; + } +if (mei_lb_check_response (dev, &rsp.header)) { +dev_err (dev,"bad result response from the firmware: 0x%x\n" , + *(uint32_t *)&rsp.header);
What exactly are you printing out to userspace here? A pointer? Or a random value from the firmware? Why?
drivers/misc/mei/mei_lb.c line 181
Quoted 3 lines
drivers/misc/mei/mei_lb.c new file +3
-0+ ret = -EPROTO ; + goto end; + }
You forgot to check the type and reserved fields of the rsp structure :(
drivers/misc/mei/mei_lb.c line 193
Quoted 6 lines
drivers/misc/mei/mei_lb.c new file +6
-0+if (bytes <sizeof (rsp)) { +dev_err (dev,"bad response from the firmware: size %zd < %zu\n" , + bytes,sizeof (rsp)); + ret = -EPROTO ; + goto end; + }
Why not check this above when you check against the size of the header? You only need one size check, not 2.
thanks,
greg k-h
Usyskin, Alexander
maintainerRE: [PATCH 2/9] mei: late_bind: add late binding component driver
Quoted 286 lines
Subject: Re: [PATCH 2/9] mei:
late_bind: add late binding component driverQuoted 25 lines · Rodrigo Vivi
From: Alexander Usyskin <[email protected]>
Introduce a new MEI client driver to support Late Binding firmware upload/update for Intel discrete graphics platforms.
Late Binding is a runtime firmware upload/update mechanism that allows payloads, such as fan control and voltage regulator, to be securely delivered and applied without requiring SPI flash updates or system reboots. This driver enables the Xe graphics driver and other user-space tools to push such firmware blobs to the authentication firmware via the MEI interface.
The driver handles authentication, versioning, and communication with the authentication firmware, which in turn coordinates with the PUnit/PCODE to apply the payload.
This is a foundational component for enabling dynamic, secure, and re-entrant configuration updates on platforms like Battlemage.
Signed-off-by Alexander Usyskin <[email protected]>Signed-off-by Badal Nilawar <[email protected]>Reviewed-by Anshuman Gupta <[email protected]>Signed-off-by Rodrigo Vivi <[email protected]>---
Quoted 10 lines
Changes in this revision:
- Proper commit message
- Proper explanation of 'Late Binding' onKconfighelp and doc
- Consistency in naming:
+mei_prefix where it makes sense
+ use 'lb' for short of 'Late Binding' instead of 'late_bind' Including s/CONFIG_INTEL_MEI_LATE_BIND/CONFIG_INTEL_MEI_LB
+ remove stray 'struct module'
+ Fix structs and enum documentation style and fields
+ Remove 'CSC' to avoid yet another acronym. 'Authentication firmware' itis.
Quoted 64 lines
+ specify size unit
+ s/push_config/push_payloaddrivers/misc/mei/Kconfig | 13 + drivers/misc/mei/Makefile | 1 + drivers/misc/mei/mei_lb.c | 315 +++++++++++++++++++++ include/drm/intel/i915_component.h | 1 + include/drm/intel/intel_lb_mei_interface.h | 70 +++++ 5 files changed, 400 insertions(+) create mode 100644 drivers/misc/mei/mei_lb.c create mode 100644 include/drm/intel/intel_lb_mei_interface.hdrivers/misc/mei/Kconfig +13
-0@@ -81,6 +81,19 @@ config INTEL_MEI_VSC This driver can also be built as a module. If so, the module will be called mei-vsc. +config INTEL_MEI_LB + tristate "Intel Late Binding (LB) support on ME Interface" + depends on INTEL_MEI_ME + depends on DRM_XE + help + Enable support for Intel Late Binding (LB) via the MEI interface. + + Late Binding is a method for applying firmware updates at runtime, + allowing the Intel Xe driver to load firmware payloads such as + fan controller or voltage regulator. These firmware updates are + authenticated and versioned, and do not require firmware flashing + or system reboot. + source "drivers/misc/mei/hdcp/Kconfig" source "drivers/misc/mei/pxp/Kconfig" source "drivers/misc/mei/gsc_proxy/Kconfig"drivers/misc/mei/Makefile +1
-0@@ -31,6 +31,7 @@ CFLAGS_mei-trace.o = -I$(src) obj-$(CONFIG_INTEL_MEI_HDCP) += hdcp/ obj-$(CONFIG_INTEL_MEI_PXP) += pxp/ obj-$(CONFIG_INTEL_MEI_GSC_PROXY) += gsc_proxy/ +obj-$(CONFIG_INTEL_MEI_LB) += mei_lb.o obj-$(CONFIG_INTEL_MEI_VSC_HW) += mei-vsc-hw.o mei-vsc-hw-y := vsc-tp.odrivers/misc/mei/mei_lb.c new file +10
-0@@ -0,0 +1,315 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2025 Intel Corporation +*/ +#include <drm/intel/i915_component.h> +#include <drm/intel/intel_lb_mei_interface.h> +#include <linux/component.h> +#include <linux/pci.h> +#include <linux/mei_cl_bus.h> +#include <linux/module.h> drivers/misc/mei/mei_lb.c line 20
Quoted 10 lines
drivers/misc/mei/mei_lb.c new file +10
-0+#include <linux/overflow.h> +#include <linux/slab.h> +#include <linux/uuid.h> + +#include "mkhi.h" + +/** +* DOC: Late Binding Firmware Update/Upload +* +* Late Binding is a firmware update/upload mechanism that allows configuration
Quoted 40 lines
drivers/misc/mei/mei_lb.c new file +40
-0+* payloads to be securely delivered and applied at runtime, rather than +* being embedded in the system firmware image (e.g., IFWI or SPI flash). +* +* This mechanism is used to update device-level configuration such as: +* - Fan controller +* - Voltage regulator (VR) +* +* Key Characteristics: +* --------------------- +* - Runtime Delivery: +* Firmware blobs are loaded by the host driver (e.g., Xe KMD) +* after the GPU or SoC has booted. +* +* - Secure and Authenticated: +* All payloads are signed and verified by the authentication firmware. +* +* - No Firmware Flashing Required: +* Updates are applied in volatile memory and do not require SPI flash +* modification or system reboot. +* +* - Re-entrant: +* Multiple updates of the same or different types can be applied +* sequentially within a single boot session. +* +* - Version Controlled: +* Each payload includes version and security version number (SVN) +* metadata to support anti-rollback enforcement. +* +* Upload Flow: +* ------------ +* 1. Host driver (KMD or user-space tool) loads the late binding firmware. +* 2. Firmware is passed to the MEI interface and forwarded to +* authentication firmware. +* 3. Authentication firmware authenticates the payload and extracts +* command and data arrays. +* 4. Authentication firmware delivers the configuration to PUnit/PCODE. +* 5. Status is returned back to the host via MEI. +*/ + +#define INTEL_LB_CMD 0x12drivers/misc/mei/mei_lb.c
Quoted 10 lines
drivers/misc/mei/mei_lb.c new file +10
-0+#define INTEL_LB_RSP (INTEL_LB_CMD | 0x80) + +#define INTEL_LB_SEND_TIMEOUT_MSEC 3000 +#define INTEL_LB_RECV_TIMEOUT_MSEC 3000 + +/** +* struct mei_lb_req - Late Binding request structure +* @header: MKHI message header (see struct mkhi_msg_hdr) +* @type: Type of the Late Binding payload +* @flags: Flags to be passed to the authentication firmware (e.g. %INTEL_LB_FLAGS_IS_PERSISTENT)
drivers/misc/mei/mei_lb.c line 71
Quoted 1 line
drivers/misc/mei/mei_lb.c new file +1
-0+* @reserved: Reserved for future use by authentication firmware, must be set to 0
Quoted 7 lines
drivers/misc/mei/mei_lb.c new file +7
-0+* @payload_size: Size of the payload data in bytes +* @payload: Payload data to be sent to the authentication firmware +*/ +struct mei_lb_req { +struct mkhi_msg_hdr header; +__le32 type; +__le32 flags;drivers/misc/mei/mei_lb.c
Quoted 10 lines
drivers/misc/mei/mei_lb.c new file +10
-0+__le32 reserved[2 ]; +__le32 payload_size; + u8 payload[] __counted_by(payload_size); +} __packed; + +/** +* struct mei_lb_rsp - Late Binding response structure +* @header: MKHI message header (see struct mkhi_msg_hdr) +* @type: Type of the Late Binding payload +* @reserved: Reserved for future use by authentication firmware, must be set to 0
drivers/misc/mei/mei_lb.c line 89
Quoted 1 line
drivers/misc/mei/mei_lb.c new file +1
-0+* @status: Status returned by authentication firmware (see enum
intel_lb_status)drivers/misc/mei/mei_lb.c
Quoted 9 lines
drivers/misc/mei/mei_lb.c new file +9
-0+*/ +struct mei_lb_rsp { +struct mkhi_msg_hdr header; +__le32 type; +__le32 reserved[2 ]; +__le32 status; +} __packed; + +static int mei_lb_check_response(const struct device *dev, const struct
mkhi_msg_hdr*hdr)Quoted 54 lines
drivers/misc/mei/mei_lb.c new file +54
-0+{ +if (hdr->group_id !=MKHI_GROUP_ID_GFX ) { +dev_err (dev,"Mismatch group id: 0x%x instead of 0x%x\n" , + hdr->group_id,MKHI_GROUP_ID_GFX ); +return -EINVAL ; + } + +if (hdr->command !=INTEL_LB_RSP ) { +dev_err (dev,"Mismatch command: 0x%x instead of 0x%x\n" , + hdr->command,INTEL_LB_RSP ); +return -EINVAL ; + } + +if (hdr->result) { +dev_err (dev,"Error in result: 0x%x\n" , hdr->result); +return -EINVAL ; + } + +return 0 ; +} + +static int mei_lb_push_payload (struct device *dev, +enum intel_lb_type type,u32 flags, +const void *payload,size_t payload_size) +{ +struct mei_cl_device *cldev; +struct mei_lb_req *req =NULL ; +struct mei_lb_rsp rsp; +size_t req_size; +ssize_t bytes; +int ret; + + cldev =to_mei_cl_device (dev); + + ret =mei_cldev_enable (cldev); +if (ret) { +dev_dbg (dev,"mei_cldev_enable failed. %d\n" , ret); +return ret; + } + + req_size =struct_size (req, payload, payload_size); +if (req_size >mei_cldev_mtu (cldev)) { +dev_err (dev,"Payload is too big %zu\n" , payload_size); + ret = -EMSGSIZE ; + goto end; + } + + req =kmalloc (req_size,GFP_KERNEL ); +if (!req) { + ret = -ENOMEM ; + goto end; + } + + req->header.group_id =MKHI_GROUP_ID_GFX ;drivers/misc/mei/mei_lb.c
Quoted 10 lines
drivers/misc/mei/mei_lb.c new file +10
-0+ req->header.command =INTEL_LB_CMD ; + req->type =cpu_to_le32 (type); + req->flags =cpu_to_le32 (flags); + req->reserved[0 ] =0 ; + req->reserved[1 ] =0 ; + req->payload_size =cpu_to_le32 (payload_size); +memcpy (req->payload, payload, payload_size); + + bytes = mei_cldev_send_timeout(cldev, + (void *)req, req_size,
INTEL_LB_SEND_TIMEOUT_MSEC);drivers/misc/mei/mei_lb.c
Quoted 8 lines
drivers/misc/mei/mei_lb.c new file +8
-0+if (bytes <0 ) { +dev_err (dev,"mei_cldev_send failed. %zd\n" , bytes); + ret = bytes; + goto end; + } + + bytes = mei_cldev_recv_timeout(cldev, + (void *)&rsp, sizeof(rsp),
INTEL_LB_RECV_TIMEOUT_MSEC);drivers/misc/mei/mei_lb.c
Quoted 7 lines
drivers/misc/mei/mei_lb.c new file +7
-0+if (bytes <0 ) { +dev_err (dev,"mei_cldev_recv failed. %zd\n" , bytes); + ret = bytes; + goto end; + } +if (bytes <sizeof (rsp.header)) { + dev_err(dev, "bad response header from the firmware: size%zd < %zu\n",
drivers/misc/mei/mei_lb.c
Quoted 6 lines
drivers/misc/mei/mei_lb.c new file +6
-0+ bytes, sizeof(rsp.header)); + ret = -EPROTO ; + goto end; + } +if (mei_lb_check_response (dev, &rsp.header)) { + dev_err(dev, "bad result response from the firmware:0x%x\n",
Quoted 4 lines
drivers/misc/mei/mei_lb.c line 184
Quoted 1 line
drivers/misc/mei/mei_lb.c new file +1
-0+ *(uint32_t *)&rsp.header);What exactly are you printing out to userspace here? A pointer? Or a random value from the firmware? Why?
We've checked this data for validity and check is failed. Sometimes whole header needed to debug the issue, so we are printing it here.
Quoted 6 lines
drivers/misc/mei/mei_lb.c line 181
Quoted 4 lines
drivers/misc/mei/mei_lb.c new file +3
-0+ ret = -EPROTO ; + goto end; + }You forgot to check the type and reserved fields of the rsp structure :(
You are right, better to check type too.
Should reserved bits be checked for 0? Or it will be overkill?
Quoted 11 lines
drivers/misc/mei/mei_lb.c line 189
Quoted 3 lines
drivers/misc/mei/mei_lb.c new file +2
-0+if (bytes <sizeof (rsp)) { + dev_err(dev, "bad response from the firmware: size %zd <%zu\n",
drivers/misc/mei/mei_lb.c line 193
Quoted 4 lines
drivers/misc/mei/mei_lb.c new file +4
-0+ bytes, sizeof(rsp)); + ret = -EPROTO ; + goto end; + }Why not check this above when you check against the size of the header? You only need one size check, not 2.
Firmware may return only header with result field set without the data. We are parsing the header first and then starting to parse data. If we check for whole message size at the beginning we'll miss the result data.
- -
Thanks,
Sasha
Greg KH
maintainerRe: [PATCH 2/9] mei: late_bind: add late binding component driver
Quoted 294 lines · Alexander
Quoted 286 lines
Subject: Re: [PATCH 2/9] mei:
late_bind: add late binding component driverQuoted 25 lines · Rodrigo Vivi
From: Alexander Usyskin <[email protected]>
Introduce a new MEI client driver to support Late Binding firmware upload/update for Intel discrete graphics platforms.
Late Binding is a runtime firmware upload/update mechanism that allows payloads, such as fan control and voltage regulator, to be securely delivered and applied without requiring SPI flash updates or system reboots. This driver enables the Xe graphics driver and other user-space tools to push such firmware blobs to the authentication firmware via the MEI interface.
The driver handles authentication, versioning, and communication with the authentication firmware, which in turn coordinates with the PUnit/PCODE to apply the payload.
This is a foundational component for enabling dynamic, secure, and re-entrant configuration updates on platforms like Battlemage.
Signed-off-by Alexander Usyskin <[email protected]>Signed-off-by Badal Nilawar <[email protected]>Reviewed-by Anshuman Gupta <[email protected]>Signed-off-by Rodrigo Vivi <[email protected]>---
Quoted 10 lines
Changes in this revision:
- Proper commit message
- Proper explanation of 'Late Binding' onKconfighelp and doc
- Consistency in naming:
+mei_prefix where it makes sense
+ use 'lb' for short of 'Late Binding' instead of 'late_bind' Including s/CONFIG_INTEL_MEI_LATE_BIND/CONFIG_INTEL_MEI_LB
+ remove stray 'struct module'
+ Fix structs and enum documentation style and fields
+ Remove 'CSC' to avoid yet another acronym. 'Authentication firmware' itis.
Quoted 64 lines
+ specify size unit
+ s/push_config/push_payloaddrivers/misc/mei/Kconfig | 13 + drivers/misc/mei/Makefile | 1 + drivers/misc/mei/mei_lb.c | 315 +++++++++++++++++++++ include/drm/intel/i915_component.h | 1 + include/drm/intel/intel_lb_mei_interface.h | 70 +++++ 5 files changed, 400 insertions(+) create mode 100644 drivers/misc/mei/mei_lb.c create mode 100644 include/drm/intel/intel_lb_mei_interface.hdrivers/misc/mei/Kconfig +13
-0@@ -81,6 +81,19 @@ config INTEL_MEI_VSC This driver can also be built as a module. If so, the module will be called mei-vsc. +config INTEL_MEI_LB + tristate "Intel Late Binding (LB) support on ME Interface" + depends on INTEL_MEI_ME + depends on DRM_XE + help + Enable support for Intel Late Binding (LB) via the MEI interface. + + Late Binding is a method for applying firmware updates at runtime, + allowing the Intel Xe driver to load firmware payloads such as + fan controller or voltage regulator. These firmware updates are + authenticated and versioned, and do not require firmware flashing + or system reboot. + source "drivers/misc/mei/hdcp/Kconfig" source "drivers/misc/mei/pxp/Kconfig" source "drivers/misc/mei/gsc_proxy/Kconfig"drivers/misc/mei/Makefile +1
-0@@ -31,6 +31,7 @@ CFLAGS_mei-trace.o = -I$(src) obj-$(CONFIG_INTEL_MEI_HDCP) += hdcp/ obj-$(CONFIG_INTEL_MEI_PXP) += pxp/ obj-$(CONFIG_INTEL_MEI_GSC_PROXY) += gsc_proxy/ +obj-$(CONFIG_INTEL_MEI_LB) += mei_lb.o obj-$(CONFIG_INTEL_MEI_VSC_HW) += mei-vsc-hw.o mei-vsc-hw-y := vsc-tp.odrivers/misc/mei/mei_lb.c new file +10
-0@@ -0,0 +1,315 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2025 Intel Corporation +*/ +#include <drm/intel/i915_component.h> +#include <drm/intel/intel_lb_mei_interface.h> +#include <linux/component.h> +#include <linux/pci.h> +#include <linux/mei_cl_bus.h> +#include <linux/module.h> drivers/misc/mei/mei_lb.c line 20
Quoted 10 lines
drivers/misc/mei/mei_lb.c new file +10
-0+#include <linux/overflow.h> +#include <linux/slab.h> +#include <linux/uuid.h> + +#include "mkhi.h" + +/** +* DOC: Late Binding Firmware Update/Upload +* +* Late Binding is a firmware update/upload mechanism that allows configuration
Quoted 40 lines
drivers/misc/mei/mei_lb.c new file +40
-0+* payloads to be securely delivered and applied at runtime, rather than +* being embedded in the system firmware image (e.g., IFWI or SPI flash). +* +* This mechanism is used to update device-level configuration such as: +* - Fan controller +* - Voltage regulator (VR) +* +* Key Characteristics: +* --------------------- +* - Runtime Delivery: +* Firmware blobs are loaded by the host driver (e.g., Xe KMD) +* after the GPU or SoC has booted. +* +* - Secure and Authenticated: +* All payloads are signed and verified by the authentication firmware. +* +* - No Firmware Flashing Required: +* Updates are applied in volatile memory and do not require SPI flash +* modification or system reboot. +* +* - Re-entrant: +* Multiple updates of the same or different types can be applied +* sequentially within a single boot session. +* +* - Version Controlled: +* Each payload includes version and security version number (SVN) +* metadata to support anti-rollback enforcement. +* +* Upload Flow: +* ------------ +* 1. Host driver (KMD or user-space tool) loads the late binding firmware. +* 2. Firmware is passed to the MEI interface and forwarded to +* authentication firmware. +* 3. Authentication firmware authenticates the payload and extracts +* command and data arrays. +* 4. Authentication firmware delivers the configuration to PUnit/PCODE. +* 5. Status is returned back to the host via MEI. +*/ + +#define INTEL_LB_CMD 0x12drivers/misc/mei/mei_lb.c
Quoted 10 lines
drivers/misc/mei/mei_lb.c new file +10
-0+#define INTEL_LB_RSP (INTEL_LB_CMD | 0x80) + +#define INTEL_LB_SEND_TIMEOUT_MSEC 3000 +#define INTEL_LB_RECV_TIMEOUT_MSEC 3000 + +/** +* struct mei_lb_req - Late Binding request structure +* @header: MKHI message header (see struct mkhi_msg_hdr) +* @type: Type of the Late Binding payload +* @flags: Flags to be passed to the authentication firmware (e.g. %INTEL_LB_FLAGS_IS_PERSISTENT)
drivers/misc/mei/mei_lb.c line 71
Quoted 1 line
drivers/misc/mei/mei_lb.c new file +1
-0+* @reserved: Reserved for future use by authentication firmware, must be set to 0
Quoted 7 lines
drivers/misc/mei/mei_lb.c new file +7
-0+* @payload_size: Size of the payload data in bytes +* @payload: Payload data to be sent to the authentication firmware +*/ +struct mei_lb_req { +struct mkhi_msg_hdr header; +__le32 type; +__le32 flags;drivers/misc/mei/mei_lb.c
Quoted 10 lines
drivers/misc/mei/mei_lb.c new file +10
-0+__le32 reserved[2 ]; +__le32 payload_size; + u8 payload[] __counted_by(payload_size); +} __packed; + +/** +* struct mei_lb_rsp - Late Binding response structure +* @header: MKHI message header (see struct mkhi_msg_hdr) +* @type: Type of the Late Binding payload +* @reserved: Reserved for future use by authentication firmware, must be set to 0
drivers/misc/mei/mei_lb.c line 89
Quoted 1 line
drivers/misc/mei/mei_lb.c new file +1
-0+* @status: Status returned by authentication firmware (see enum
intel_lb_status)drivers/misc/mei/mei_lb.c
Quoted 9 lines
drivers/misc/mei/mei_lb.c new file +9
-0+*/ +struct mei_lb_rsp { +struct mkhi_msg_hdr header; +__le32 type; +__le32 reserved[2 ]; +__le32 status; +} __packed; + +static int mei_lb_check_response(const struct device *dev, const struct
mkhi_msg_hdr*hdr)Quoted 54 lines
drivers/misc/mei/mei_lb.c new file +54
-0+{ +if (hdr->group_id !=MKHI_GROUP_ID_GFX ) { +dev_err (dev,"Mismatch group id: 0x%x instead of 0x%x\n" , + hdr->group_id,MKHI_GROUP_ID_GFX ); +return -EINVAL ; + } + +if (hdr->command !=INTEL_LB_RSP ) { +dev_err (dev,"Mismatch command: 0x%x instead of 0x%x\n" , + hdr->command,INTEL_LB_RSP ); +return -EINVAL ; + } + +if (hdr->result) { +dev_err (dev,"Error in result: 0x%x\n" , hdr->result); +return -EINVAL ; + } + +return 0 ; +} + +static int mei_lb_push_payload (struct device *dev, +enum intel_lb_type type,u32 flags, +const void *payload,size_t payload_size) +{ +struct mei_cl_device *cldev; +struct mei_lb_req *req =NULL ; +struct mei_lb_rsp rsp; +size_t req_size; +ssize_t bytes; +int ret; + + cldev =to_mei_cl_device (dev); + + ret =mei_cldev_enable (cldev); +if (ret) { +dev_dbg (dev,"mei_cldev_enable failed. %d\n" , ret); +return ret; + } + + req_size =struct_size (req, payload, payload_size); +if (req_size >mei_cldev_mtu (cldev)) { +dev_err (dev,"Payload is too big %zu\n" , payload_size); + ret = -EMSGSIZE ; + goto end; + } + + req =kmalloc (req_size,GFP_KERNEL ); +if (!req) { + ret = -ENOMEM ; + goto end; + } + + req->header.group_id =MKHI_GROUP_ID_GFX ;drivers/misc/mei/mei_lb.c
Quoted 10 lines
drivers/misc/mei/mei_lb.c new file +10
-0+ req->header.command =INTEL_LB_CMD ; + req->type =cpu_to_le32 (type); + req->flags =cpu_to_le32 (flags); + req->reserved[0 ] =0 ; + req->reserved[1 ] =0 ; + req->payload_size =cpu_to_le32 (payload_size); +memcpy (req->payload, payload, payload_size); + + bytes = mei_cldev_send_timeout(cldev, + (void *)req, req_size,
INTEL_LB_SEND_TIMEOUT_MSEC);drivers/misc/mei/mei_lb.c
Quoted 8 lines
drivers/misc/mei/mei_lb.c new file +8
-0+if (bytes <0 ) { +dev_err (dev,"mei_cldev_send failed. %zd\n" , bytes); + ret = bytes; + goto end; + } + + bytes = mei_cldev_recv_timeout(cldev, + (void *)&rsp, sizeof(rsp),
INTEL_LB_RECV_TIMEOUT_MSEC);drivers/misc/mei/mei_lb.c
Quoted 7 lines
drivers/misc/mei/mei_lb.c new file +7
-0+if (bytes <0 ) { +dev_err (dev,"mei_cldev_recv failed. %zd\n" , bytes); + ret = bytes; + goto end; + } +if (bytes <sizeof (rsp.header)) { + dev_err(dev, "bad response header from the firmware: size%zd < %zu\n",
drivers/misc/mei/mei_lb.c
Quoted 6 lines
drivers/misc/mei/mei_lb.c new file +6
-0+ bytes, sizeof(rsp.header)); + ret = -EPROTO ; + goto end; + } +if (mei_lb_check_response (dev, &rsp.header)) { + dev_err(dev, "bad result response from the firmware:0x%x\n",
Quoted 4 lines
drivers/misc/mei/mei_lb.c line 184
Quoted 1 line
drivers/misc/mei/mei_lb.c new file +1
-0+ *(uint32_t *)&rsp.header);What exactly are you printing out to userspace here? A pointer? Or a random value from the firmware? Why?
We've checked this data for validity and check is failed. Sometimes whole header needed to debug the issue, so we are printing it here.
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
drivers/misc/mei/mei_lb.c line 181
Quoted 3 lines
drivers/misc/mei/mei_lb.c new file +3
-0+ ret = -EPROTO ; + goto end; + }You forgot to check the type and reserved fields of the rsp structure :(
You are right, better to check type too.
Should reserved bits be checked for 0? Or it will be overkill?
The reserved bytes HAVE TO BE CHECKED, otherwise you can NEVER use them in the future. You say so in your documentation for the structure :)
Quoted 11 lines
Quoted 10 lines
drivers/misc/mei/mei_lb.c line 189
Quoted 2 lines
drivers/misc/mei/mei_lb.c new file +2
-0+if (bytes <sizeof (rsp)) { + dev_err(dev, "bad response from the firmware: size %zd <%zu\n",
drivers/misc/mei/mei_lb.c line 193
Quoted 4 lines
drivers/misc/mei/mei_lb.c new file +4
-0+ bytes, sizeof(rsp)); + ret = -EPROTO ; + goto end; + }Why not check this above when you check against the size of the header? You only need one size check, not 2.
Firmware may return only header with result field set without the data.
Then the firmware is broken :)
Quoted 2 lines
We are parsing the header first and then starting to parse data. If we check for whole message size at the beginning we'll miss the result data.
You mean you will make it harder to debug the firmware, as you will not be printing out the header information? Or something else? The bytes variable HAS to match the full structure size, not just the header size, according to this code. So just test for that and be done with it!
thanks,
greg k-h
Usyskin, Alexander
maintainerRE: [PATCH 2/9] mei: late_bind: add late binding component driver
Quoted 331 lines
Subject: Re: [PATCH 2/9] mei:
late_bind: add late binding component driverQuoted 28 lines · Alexander
Quoted 28 lines
Subject: Re: [PATCH 2/9] mei:
late_bind: add late binding component driverQuoted 25 lines · Rodrigo Vivi
From: Alexander Usyskin <[email protected]>
Introduce a new MEI client driver to support Late Binding firmware upload/update for Intel discrete graphics platforms.
Late Binding is a runtime firmware upload/update mechanism that allows payloads, such as fan control and voltage regulator, to be securely delivered and applied without requiring SPI flash updates or system reboots. This driver enables the Xe graphics driver and other user-space tools to push such firmware blobs to the authentication firmware via the MEI interface.
The driver handles authentication, versioning, and communication with the authentication firmware, which in turn coordinates with the PUnit/PCODE to apply the payload.
This is a foundational component for enabling dynamic, secure, and re-entrant configuration updates on platforms like Battlemage.
Signed-off-by Alexander Usyskin <[email protected]>Signed-off-by Badal Nilawar <[email protected]>Reviewed-by Anshuman Gupta <[email protected]>Signed-off-by Rodrigo Vivi <[email protected]>---
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Changes in this revision:
- Proper commit message
- Proper explanation of 'Late Binding' onKconfighelp and doc
- Consistency in naming:
+mei_prefix where it makes sense
+ use 'lb' for short of 'Late Binding' instead of 'late_bind' Including s/CONFIG_INTEL_MEI_LATE_BIND/CONFIG_INTEL_MEI_LB
+ remove stray 'struct module'
+ Fix structs and enum documentation style and fields
+ Remove 'CSC' to avoid yet another acronym. 'Authentication firmware'it
Quoted 76 lines
Quoted 76 lines
is.
Quoted 64 lines
+ specify size unit
+ s/push_config/push_payloaddrivers/misc/mei/Kconfig | 13 + drivers/misc/mei/Makefile | 1 + drivers/misc/mei/mei_lb.c | 315 +++++++++++++++++++++ include/drm/intel/i915_component.h | 1 + include/drm/intel/intel_lb_mei_interface.h | 70 +++++ 5 files changed, 400 insertions(+) create mode 100644 drivers/misc/mei/mei_lb.c create mode 100644 include/drm/intel/intel_lb_mei_interface.hdrivers/misc/mei/Kconfig +13
-0@@ -81,6 +81,19 @@ config INTEL_MEI_VSC This driver can also be built as a module. If so, the module will be called mei-vsc. +config INTEL_MEI_LB + tristate "Intel Late Binding (LB) support on ME Interface" + depends on INTEL_MEI_ME + depends on DRM_XE + help + Enable support for Intel Late Binding (LB) via the MEI interface. + + Late Binding is a method for applying firmware updates at runtime, + allowing the Intel Xe driver to load firmware payloads such as + fan controller or voltage regulator. These firmware updates are + authenticated and versioned, and do not require firmware flashing + or system reboot. + source "drivers/misc/mei/hdcp/Kconfig" source "drivers/misc/mei/pxp/Kconfig" source "drivers/misc/mei/gsc_proxy/Kconfig"drivers/misc/mei/Makefile +1
-0@@ -31,6 +31,7 @@ CFLAGS_mei-trace.o = -I$(src) obj-$(CONFIG_INTEL_MEI_HDCP) += hdcp/ obj-$(CONFIG_INTEL_MEI_PXP) += pxp/ obj-$(CONFIG_INTEL_MEI_GSC_PROXY) += gsc_proxy/ +obj-$(CONFIG_INTEL_MEI_LB) += mei_lb.o obj-$(CONFIG_INTEL_MEI_VSC_HW) += mei-vsc-hw.o mei-vsc-hw-y := vsc-tp.odrivers/misc/mei/mei_lb.c new file +10
-0@@ -0,0 +1,315 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2025 Intel Corporation +*/ +#include <drm/intel/i915_component.h> +#include <drm/intel/intel_lb_mei_interface.h> +#include <linux/component.h> +#include <linux/pci.h> +#include <linux/mei_cl_bus.h> +#include <linux/module.h> drivers/misc/mei/mei_lb.c line 20
Quoted 10 lines
drivers/misc/mei/mei_lb.c new file +10
-0+#include <linux/overflow.h> +#include <linux/slab.h> +#include <linux/uuid.h> + +#include "mkhi.h" + +/** +* DOC: Late Binding Firmware Update/Upload +* +* Late Binding is a firmware update/upload mechanism that allows configuration
Quoted 2 lines
Quoted 2 lines
drivers/misc/mei/mei_lb.c line 22
Quoted 2 lines
drivers/misc/mei/mei_lb.c new file +2
-0+* payloads to be securely delivered and applied at runtime, rather than +* being embedded in the system firmware image (e.g., IFWI or SPI flash).
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
drivers/misc/mei/mei_lb.c new file +21
-0+* +* This mechanism is used to update device-level configuration such as: +* - Fan controller +* - Voltage regulator (VR) +* +* Key Characteristics: +* --------------------- +* - Runtime Delivery: +* Firmware blobs are loaded by the host driver (e.g., Xe KMD) +* after the GPU or SoC has booted. +* +* - Secure and Authenticated: +* All payloads are signed and verified by the authentication firmware. +* +* - No Firmware Flashing Required: +* Updates are applied in volatile memory and do not require SPI flash +* modification or system reboot. +* +* - Re-entrant: +* Multiple updates of the same or different types can be applied +* sequentially within a single boot session. Quoted 8 lines
Quoted 8 lines
drivers/misc/mei/mei_lb.c
Quoted 8 lines
drivers/misc/mei/mei_lb.c new file +8
-0+* +* - Version Controlled: +* Each payload includes version and security version number (SVN) +* metadata to support anti-rollback enforcement. +* +* Upload Flow: +* ------------ +* 1. Host driver (KMD or user-space tool) loads the late binding firmware.
Quoted 5 lines
Quoted 5 lines
drivers/misc/mei/mei_lb.c
Quoted 5 lines
drivers/misc/mei/mei_lb.c new file +5
-0+* 2. Firmware is passed to the MEI interface and forwarded to +* authentication firmware. +* 3. Authentication firmware authenticates the payload and extracts +* command and data arrays. +* 4. Authentication firmware delivers the configuration to PUnit/PCODE.
Quoted 15 lines
Quoted 15 lines
Quoted 4 lines
drivers/misc/mei/mei_lb.c new file +4
-0+* 5. Status is returned back to the host via MEI. +*/ + +#define INTEL_LB_CMD 0x12drivers/misc/mei/mei_lb.c
Quoted 10 lines
drivers/misc/mei/mei_lb.c new file +10
-0+#define INTEL_LB_RSP (INTEL_LB_CMD | 0x80) + +#define INTEL_LB_SEND_TIMEOUT_MSEC 3000 +#define INTEL_LB_RECV_TIMEOUT_MSEC 3000 + +/** +* struct mei_lb_req - Late Binding request structure +* @header: MKHI message header (see struct mkhi_msg_hdr) +* @type: Type of the Late Binding payload +* @flags: Flags to be passed to the authentication firmware (e.g. %INTEL_LB_FLAGS_IS_PERSISTENT)
Quoted 1 line
Quoted 1 line
drivers/misc/mei/mei_lb.c line 71
Quoted 1 line
drivers/misc/mei/mei_lb.c new file +1
-0+* @reserved: Reserved for future use by authentication firmware, must be
Quoted 10 lines
Quoted 10 lines
set to 0
Quoted 9 lines
drivers/misc/mei/mei_lb.c new file +9
-0+* @payload_size: Size of the payload data in bytes +* @payload: Payload data to be sent to the authentication firmware +*/ +struct mei_lb_req { +struct mkhi_msg_hdr header; +__le32 type; +__le32 flags; +__le32 reserved[2 ]; +__le32 payload_size;Quoted 8 lines
Quoted 8 lines
drivers/misc/mei/mei_lb.c
Quoted 8 lines
drivers/misc/mei/mei_lb.c new file +8
-0+ u8 payload[] __counted_by(payload_size); +} __packed; + +/** +* struct mei_lb_rsp - Late Binding response structure +* @header: MKHI message header (see struct mkhi_msg_hdr) +* @type: Type of the Late Binding payload +* @reserved: Reserved for future use by authentication firmware, must be
Quoted 102 lines
Quoted 102 lines
set to 0
drivers/misc/mei/mei_lb.c line 89
Quoted 1 line
drivers/misc/mei/mei_lb.c new file +1
-0+* @status: Status returned by authentication firmware (see enum
intel_lb_status)drivers/misc/mei/mei_lb.c
Quoted 9 lines
drivers/misc/mei/mei_lb.c new file +9
-0+*/ +struct mei_lb_rsp { +struct mkhi_msg_hdr header; +__le32 type; +__le32 reserved[2 ]; +__le32 status; +} __packed; + +static int mei_lb_check_response(const struct device *dev, const struct
mkhi_msg_hdr*hdr)Quoted 54 lines
drivers/misc/mei/mei_lb.c new file +54
-0+{ +if (hdr->group_id !=MKHI_GROUP_ID_GFX ) { +dev_err (dev,"Mismatch group id: 0x%x instead of 0x%x\n" , + hdr->group_id,MKHI_GROUP_ID_GFX ); +return -EINVAL ; + } + +if (hdr->command !=INTEL_LB_RSP ) { +dev_err (dev,"Mismatch command: 0x%x instead of 0x%x\n" , + hdr->command,INTEL_LB_RSP ); +return -EINVAL ; + } + +if (hdr->result) { +dev_err (dev,"Error in result: 0x%x\n" , hdr->result); +return -EINVAL ; + } + +return 0 ; +} + +static int mei_lb_push_payload (struct device *dev, +enum intel_lb_type type,u32 flags, +const void *payload,size_t payload_size) +{ +struct mei_cl_device *cldev; +struct mei_lb_req *req =NULL ; +struct mei_lb_rsp rsp; +size_t req_size; +ssize_t bytes; +int ret; + + cldev =to_mei_cl_device (dev); + + ret =mei_cldev_enable (cldev); +if (ret) { +dev_dbg (dev,"mei_cldev_enable failed. %d\n" , ret); +return ret; + } + + req_size =struct_size (req, payload, payload_size); +if (req_size >mei_cldev_mtu (cldev)) { +dev_err (dev,"Payload is too big %zu\n" , payload_size); + ret = -EMSGSIZE ; + goto end; + } + + req =kmalloc (req_size,GFP_KERNEL ); +if (!req) { + ret = -ENOMEM ; + goto end; + } + + req->header.group_id =MKHI_GROUP_ID_GFX ;drivers/misc/mei/mei_lb.c
Quoted 10 lines
drivers/misc/mei/mei_lb.c new file +10
-0+ req->header.command =INTEL_LB_CMD ; + req->type =cpu_to_le32 (type); + req->flags =cpu_to_le32 (flags); + req->reserved[0 ] =0 ; + req->reserved[1 ] =0 ; + req->payload_size =cpu_to_le32 (payload_size); +memcpy (req->payload, payload, payload_size); + + bytes = mei_cldev_send_timeout(cldev, + (void *)req, req_size,
INTEL_LB_SEND_TIMEOUT_MSEC);drivers/misc/mei/mei_lb.c
Quoted 8 lines
drivers/misc/mei/mei_lb.c new file +8
-0+if (bytes <0 ) { +dev_err (dev,"mei_cldev_send failed. %zd\n" , bytes); + ret = bytes; + goto end; + } + + bytes = mei_cldev_recv_timeout(cldev, + (void *)&rsp, sizeof(rsp),
INTEL_LB_RECV_TIMEOUT_MSEC);drivers/misc/mei/mei_lb.c
Quoted 7 lines
drivers/misc/mei/mei_lb.c new file +7
-0+if (bytes <0 ) { +dev_err (dev,"mei_cldev_recv failed. %zd\n" , bytes); + ret = bytes; + goto end; + } +if (bytes <sizeof (rsp.header)) { + dev_err(dev, "bad response header from the firmware: size%zd < %zu\n",
drivers/misc/mei/mei_lb.c
Quoted 6 lines
drivers/misc/mei/mei_lb.c new file +6
-0+ bytes, sizeof(rsp.header)); + ret = -EPROTO ; + goto end; + } +if (mei_lb_check_response (dev, &rsp.header)) { + dev_err(dev, "bad result response from the firmware:0x%x\n",
Quoted 6 lines
Quoted 4 lines
drivers/misc/mei/mei_lb.c line 184
Quoted 1 line
drivers/misc/mei/mei_lb.c new file +1
-0+ *(uint32_t *)&rsp.header);What exactly are you printing out to userspace here? A pointer? Or a random value from the firmware? Why?
We've checked this data for validity and check is failed. Sometimes whole header needed to debug the issue, so we are printing it
here.
Quoted 9 lines
Quoted 7 lines
drivers/misc/mei/mei_lb.c line 181
Quoted 5 lines
drivers/misc/mei/mei_lb.c new file +3
-0+ ret = -EPROTO ; + goto end; + }You forgot to check the type and reserved fields of the rsp structure :(
You are right, better to check type too.
Should reserved bits be checked for 0? Or it will be overkill?The reserved bytes HAVE TO BE CHECKED, otherwise you can NEVER use them in the future. You say so in your documentation for the structure :)
Quoted 11 lines
Quoted 10 lines
drivers/misc/mei/mei_lb.c line 189
Quoted 2 lines
drivers/misc/mei/mei_lb.c new file +2
-0+if (bytes <sizeof (rsp)) { + dev_err(dev, "bad response from the firmware: size %zd <%zu\n",
drivers/misc/mei/mei_lb.c line 193
Quoted 4 lines
drivers/misc/mei/mei_lb.c new file +4
-0+ bytes, sizeof(rsp)); + ret = -EPROTO ; + goto end; + }Why not check this above when you check against the size of the header? You only need one size check, not 2.
Firmware may return only header with result field set without the data.
Then the firmware is broken :)
Quoted 2 lines
We are parsing the header first and then starting to parse data. If we check for whole message size at the beginning we'll miss the result
Quoted 7 lines
data.
You mean you will make it harder to debug the firmware, as you will not be printing out the header information? Or something else? The bytes variable HAS to match the full structure size, not just the header size, according to this code. So just test for that and be done with it!
The CSME firmware returns only command header if, like, command is not recognised. This may happen because of firmware bug or for firmware is configured/compiled that way.
This seems reasonable for the complex protocols where firmware may not be aware of this particular command at all and have no idea what the data size it should send in reply.
Printing result from the header will allow us to understand either this is the firmware problem or driver sent something wrong.
- -
Thanks,
Sasha
Greg KH
maintainerRe: [PATCH 2/9] mei: late_bind: add late binding component driver
Quoted 24 lines · Alexander
Quoted 16 lines
Quoted 11 lines
Quoted 10 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (bytes < sizeof(rsp)) { + dev_err(dev, "bad response from the firmware: size %zd <%zu\n",
drivers/misc/mei/mei_lb.c line 193
Quoted 4 lines
drivers/misc/mei/mei_lb.c new file +4
-0+ bytes, sizeof(rsp)); + ret = -EPROTO ; + goto end; + }Why not check this above when you check against the size of the header? You only need one size check, not 2.
Firmware may return only header with result field set without the data.
Then the firmware is broken :)
Quoted 2 lines
We are parsing the header first and then starting to parse data. If we check for whole message size at the beginning we'll miss the result
Quoted 7 lines
data.
You mean you will make it harder to debug the firmware, as you will not be printing out the header information? Or something else? The bytes variable HAS to match the full structure size, not just the header size, according to this code. So just test for that and be done with it!
Quoted 8 lines
The CSME firmware returns only command header if, like, command is not recognised. This may happen because of firmware bug or for firmware is configured/compiled that way.
This seems reasonable for the complex protocols where firmware may not be aware of this particular command at all and have no idea what the data size it should send in reply.
Printing result from the header will allow us to understand either this is the firmware problem or driver sent something wrong.
Then make it obvious in your checking and in your error messages as to what you are doing here. Checking the size of the buffer in two different places, with different values is very odd, and deserves a lot of explaination.
thanks,
greg k-h
Usyskin, Alexander
maintainerRE: [PATCH 2/9] mei: late_bind: add late binding component driver
Quoted 39 lines
Subject: Re: [PATCH 2/9] mei:
late_bind: add late binding component driverQuoted 2 lines · Alexander
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (bytes < sizeof(rsp)) { + dev_err(dev, "bad response from the firmware: size%zd <
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
%zu\n",
drivers/misc/mei/mei_lb.c line 193
Quoted 4 lines
drivers/misc/mei/mei_lb.c new file +4
-0+ bytes, sizeof(rsp)); + ret = -EPROTO ; + goto end; + }Why not check this above when you check against the size of the
header?
Quoted 9 lines
Quoted 9 lines
Quoted 2 lines
Quoted 1 line
You only need one size check, not 2.
Firmware may return only header with result field set without the data.
Then the firmware is broken :)
Quoted 2 lines
We are parsing the header first and then starting to parse data. If we check for whole message size at the beginning we'll miss the result
data.
Quoted 7 lines
Quoted 5 lines
You mean you will make it harder to debug the firmware, as you will not be printing out the header information? Or something else? The bytes variable HAS to match the full structure size, not just the header size, according to this code. So just test for that and be done with it!
The CSME firmware returns only command header if, like, command is not
recognised.
Quoted 1 line
This may happen because of firmware bug or for firmware is
configured/compiled
Quoted 3 lines
that way.
This seems reasonable for the complex protocols where firmware may not be aware of this particular command at all and have no idea what the data sizeit
Quoted 2 lines
should send in reply.
Printing result from the header will allow us to understand either this is the
Quoted 8 lines
firmware
Quoted 1 line
problem or driver sent something wrong.
Then make it obvious in your checking and in your error messages as to what you are doing here. Checking the size of the buffer in two different places, with different values is very odd, and deserves a lot of explaination.
Is this addition
/*
* Received message size may be smaller than the full message size when
* reply contains only MKHI header with result field set to the error code.
* Check the header size and content first to output exact error, if needed,
* and then process to the whole message.
*/
and remodelling error messages like "received less then header size from the firmware" made it clean for people not involved with our firmware?
I'm too deep in this to judge the wording.
- -
Thanks,
Sasha
Re: [PATCH 2/9] mei: late_bind: add late binding component driver
Hi Greg,
Quoted 51 lines · Alexander
Quoted 34 lines
Subject: Re: [PATCH 2/9] mei:
late_bind: add late binding component driverQuoted 2 lines · Alexander
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (bytes < sizeof(rsp)) { + dev_err(dev, "bad response from the firmware: size%zd <
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
%zu\n",
Review
Quoted 4 lines
(quoted diff) +4
-0+ bytes, sizeof(rsp)); + ret = -EPROTO; + goto end; + }Why not check this above when you check against the size of the
header?
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
You only need one size check, not 2.
Firmware may return only header with result field set without the data.
Then the firmware is broken :)
Quoted 2 lines
We are parsing the header first and then starting to parse data. If we check for whole message size at the beginning we'll miss the result
Quoted 8 lines
Quoted 7 lines
data.
You mean you will make it harder to debug the firmware, as you will not be printing out the header information? Or something else? The bytes variable HAS to match the full structure size, not just the header size, according to this code. So just test for that and be done with it!
The CSME firmware returns only command header if, like, command is not
recognised.
Quoted 1 line
This may happen because of firmware bug or for firmware is
configured/compiled
Quoted 3 lines
that way.
This seems reasonable for the complex protocols where firmware may not be aware of this particular command at all and have no idea what the data sizeit
Quoted 9 lines
Quoted 2 lines
should send in reply.
Printing result from the header will allow us to understand either this is thefirmware
Quoted 1 line
problem or driver sent something wrong.
Then make it obvious in your checking and in your error messages as to what you are doing here. Checking the size of the buffer in two different places, with different values is very odd, and deserves a lot of explaination.
Is this addition
/*
* Received message size may be smaller than the full message size when
* reply contains only MKHI header with result field set to the error code.
* Check the header size and content first to output exact error, if needed,
* and then process to the whole message.
*/
Quoted 3 lines
and remodelling error messages like "received less then header size from the firmware" made it clean for people not involved with our firmware?
I'm too deep in this to judge the wording.
I'm planning to include the following code in the next revision. Does this change align with your recommendation?
+ /*
+ * Received message size may be smaller than the full message size when
+ * reply contains only MKHI header with result field set to the error code.
+ * Check the header size and content first to output exact error, if needed,
+ * and then process to the whole message.
+ */
if (bytes < sizeof(rsp.header)) {
- dev_err(dev, "bad response header from the firmware:
size %zd < %zu\n",
+ dev_err(dev, "received less than header size from
the firmware: %zd < %zu\n",
bytes, sizeof(rsp.header));
ret = -EPROTO;
goto end;
}
if (mei_lb_check_response(dev, &rsp.header)) {
- dev_err(dev, "bad result response from the firmware:
0x%x\n",
+ dev_err(dev, "bad response from the firmware:
header: 0x%x\n",
*(uint32_t *)&rsp.header);
ret = -EPROTO;
goto end;
}
if (bytes < sizeof(rsp)) {
- dev_err(dev, "bad response from the firmware: size
%zd < %zu\n",
+ dev_err(dev, "received less than message size from
the firmware: %zd < %zu\n",
bytes, sizeof(rsp));
ret = -EPROTO;
goto end;Thanks,
Badal
Quoted 6 lines
- -
Thanks,
Sasha
Greg KH
maintainerRe: [PATCH 2/9] mei: late_bind: add late binding component driver
Quoted 1 line · Badal
Hi Greg,
<snip>
For some reason this was in html format :(
Also, please follow the rules that Intel kernel developers must follow, which means not using me as your first-line of review. Please work with your internal developers on this first, before resubmitting.
thanks,
greg k-h
Rodrigo Vivi
maintainerPATCH 3/9 drm/xe/xe_late_bind_fw: Introducing xe_late_bind_fw
In reply to Rodrigo ViviFrom: Badal Nilawar <[email protected]>
Introducing xe_late_bind_fw to enable firmware loading for the devices, such as the fan controller, during the driver probe. Typically, firmware for such devices are part of IFWI flash image but can be replaced at probe after OEM tuning.
This patch binds mei late binding component to enable firmware loading.
v2:
- Add devm_add_action_or_reset to remove the component (Daniele)
- Add INTEL_MEI_GSC check in xe_late_bind_init() (Daniele)
v3:
- Fail driver probe if late bind initialization fails, add has_late_bind flag (Daniele)
v4:
- %S/I915_COMPONENT_LATE_BIND/INTEL_COMPONENT_LATE_BIND/
v6:
- rebased
--- drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_device.c | 5 ++ drivers/gpu/drm/xe/xe_device_types.h | 6 ++ drivers/gpu/drm/xe/xe_late_bind_fw.c | 84 ++++++++++++++++++++++ drivers/gpu/drm/xe/xe_late_bind_fw.h | 15 ++++ drivers/gpu/drm/xe/xe_late_bind_fw_types.h | 33 +++++++++ drivers/gpu/drm/xe/xe_pci.c | 2 + drivers/gpu/drm/xe/xe_pci_types.h | 1 + 8 files changed, 147 insertions(+) create mode 100644 drivers/gpu/drm/xe/xe_late_bind_fw.c create mode 100644 drivers/gpu/drm/xe/xe_late_bind_fw.h create mode 100644 drivers/gpu/drm/xe/xe_late_bind_fw_types.h
drivers/gpu/drm/xe/Makefile +1 -0
@@ -76,6 +76,7 @@ xe-y += xe_bb.o \ xe_hw_fence.o \ xe_irq.o \ xe_lrc.o \ + xe_late_bind_fw.o \ xe_migrate.o \ xe_mmio.o \ xe_mocs.o \
drivers/gpu/drm/xe/xe_device.c +5 -0
@@ -44,6 +44,7 @@#include "xe_hw_engine_group.h" #include "xe_hwmon.h" #include "xe_irq.h" +#include "xe_late_bind_fw.h" #include "xe_mmio.h" #include "xe_module.h" #include "xe_nvm.h"
@@ -866,6 +867,10 @@ int xe_device_probe(struct xe_device *xe)if (err)return err; + err =xe_late_bind_init (&xe->late_bind); +if (err && err != -ENODEV ) +return err; + err =xe_oa_init (xe);if (err)return err;
drivers/gpu/drm/xe/xe_device_types.h +6 -0
@@ -16,6 +16,7 @@#include "xe_devcoredump_types.h" #include "xe_heci_gsc.h" #include "xe_lmtt_types.h" +#include "xe_late_bind_fw_types.h" #include "xe_memirq_types.h" #include "xe_oa_types.h" #include "xe_platform_types.h"
@@ -325,6 +326,8 @@ struct xe_device { u8 has_heci_cscfi:1;/** @info.has_heci_gscfi: device has heci gscfi */ u8 has_heci_gscfi:1; +/** @info.has_late_bind: Device has firmware late binding support */ + u8 has_late_bind:1;/** @info.has_llc: Device has a shared CPU+GPU last level cache */ u8 has_llc:1;/** @info.has_mbx_power_limits: Device has support to manage power limits using
@@ -557,6 +560,9 @@ struct xe_device {/** @nvm: discrete graphics non-volatile memory */ struct intel_dg_nvm_dev *nvm; +/** @late_bind: xe mei late bind interface */ +struct xe_late_bind late_bind; +/** @oa: oa observation subsystem */ struct xe_oa oa;
drivers/gpu/drm/xe/xe_late_bind_fw.c new file +84 -0
84 lines not on this page · raw message
drivers/gpu/drm/xe/xe_late_bind_fw.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_LATE_BIND_FW_H_ +#define _XE_LATE_BIND_FW_H_ + +#include <linux/types.h> + +struct xe_late_bind ; + +int xe_late_bind_init (struct xe_late_bind *late_bind); + +#endif
drivers/gpu/drm/xe/xe_late_bind_fw_types.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_LATE_BIND_TYPES_H_ +#define _XE_LATE_BIND_TYPES_H_ + +#include <linux/iosys-map.h> +#include <linux/mutex.h> +#include <linux/types.h> + +/** +* struct xe_late_bind_component - Late Binding services component +* @mei_dev: device that provide Late Binding service. +* @ops: Ops implemented by Late Binding driver, used by Xe driver. +* +* Communication between Xe and MEI drivers for Late Binding services +*/ +struct xe_late_bind_component { +struct device *mei_dev; +const struct late_bind_component_ops *ops; +}; + +/** +* struct xe_late_bind +*/ +struct xe_late_bind { +/** @component: struct for communication with mei component */ +struct xe_late_bind_component component; +}; + +#endif
drivers/gpu/drm/xe/xe_pci.c +2 -0
@@ -332,6 +332,7 @@ static const struct xe_device_desc bmg_desc = { .has_gsc_nvm = 1, .has_heci_cscfi = 1, .max_gt_per_tile = 2, + .has_late_bind = true, .needs_scratch = true, };
@@ -578,6 +579,7 @@ static int xe_info_init_early(struct xe_device *xe, xe->info.has_gsc_nvm = desc->has_gsc_nvm; xe->info.has_heci_gscfi = desc->has_heci_gscfi; xe->info.has_heci_cscfi = desc->has_heci_cscfi; + xe->info.has_late_bind = desc->has_late_bind; xe->info.has_llc = desc->has_llc; xe->info.has_pxp = desc->has_pxp; xe->info.has_sriov = desc->has_sriov;
drivers/gpu/drm/xe/xe_pci_types.h +1 -0
@@ -39,6 +39,7 @@ struct xe_device_desc { u8 has_gsc_nvm:1; u8 has_heci_gscfi:1; u8 has_heci_cscfi:1; + u8 has_late_bind:1; u8 has_llc:1; u8 has_mbx_power_limits:1; u8 has_pxp:1;
Signature · 1 line
2.49.0
Re: [PATCH 3/9] drm/xe/xe_late_bind_fw: Introducing xe_late_bind_fw
Quoted 3 lines · Rodrigo Vivi
From: Badal Nilawar <[email protected]>
Introducing
xe_late_bind_fwto enable firmware loading for the devices,
here and in the subject: no gerund, please.
Quoted 38 lines
such as the fan controller, during the driver probe. Typically, firmware for such devices are part of IFWI flash image but can be replaced at probe after OEM tuning.
This patch binds mei late binding component to enable firmware loading.v2:
- Adddevm_add_action_or_resetto remove the component (Daniele)
- AddINTEL_MEI_GSCcheck inxe_late_bind_init()(Daniele) v3:
- Fail driver probe if late bind initialization fails, addhas_late_bindflag (Daniele)
v4:
- %S/I915_COMPONENT_LATE_BIND/INTEL_COMPONENT_LATE_BIND/ v6:
- rebasedSigned-off-by Badal Nilawar <[email protected]>Reviewed-by Daniele Ceraolo Spurio <[email protected]>Signed-off-by Rodrigo Vivi <[email protected]>---
drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_device.c | 5 ++ drivers/gpu/drm/xe/xe_device_types.h | 6 ++ drivers/gpu/drm/xe/xe_late_bind_fw.c | 84 ++++++++++++++++++++++ drivers/gpu/drm/xe/xe_late_bind_fw.h | 15 ++++ drivers/gpu/drm/xe/xe_late_bind_fw_types.h | 33 +++++++++ drivers/gpu/drm/xe/xe_pci.c | 2 + drivers/gpu/drm/xe/xe_pci_types.h | 1 + 8 files changed, 147 insertions(+)create mode 100644
drivers/gpu/drm/xe/xe_late_bind_fw.ccreate mode 100644drivers/gpu/drm/xe/xe_late_bind_fw.hcreate mode 100644drivers/gpu/drm/xe/xe_late_bind_fw_types.hdrivers/gpu/drm/xe/Makefile +0
-0
drivers/gpu/drm/xe/Makefile xe-y += xe_bb.o \ · line 79
Quoted 4 lines
drivers/gpu/drm/xe/Makefile +1
-0@@ -76,6 +76,7 @@ xe-y += xe_bb.o \ xe_hw_fence.o \ xe_irq.o \ xe_lrc.o \ + xe_late_bind_fw.o \
almost there, but still not sorted as it should be
Quoted 16 lines
drivers/gpu/drm/xe/Makefile +0
-0xe_migrate.o \ xe_mmio.o \ xe_mocs.o \drivers/gpu/drm/xe/xe_device.c +1
-0@@ -44,6 +44,7 @@#include "xe_hw_engine_group.h" #include "xe_hwmon.h" #include "xe_irq.h" +#include "xe_late_bind_fw.h" #include "xe_mmio.h" #include "xe_module.h" #include "xe_nvm.h"
drivers/gpu/drm/xe/xe_device.c int xe_device_probe(struct xe_device *xe) · line 871
Quoted 5 lines
drivers/gpu/drm/xe/xe_device.c +2
-0@@ -866,6 +867,10 @@ int xe_device_probe(struct xe_device *xe)if (err)return err; + err =xe_late_bind_init (&xe->late_bind); +if (err && err != -ENODEV )
let's not be creative in xe_device_probe(). Boring is good.
All the other parts in this function handle ENODEV internally. It's up to them to decide if ENODEV -> return 0, not here.
Quoted 10 lines
drivers/gpu/drm/xe/xe_device.c +2
-0+return err; + err =xe_oa_init (xe);if (err)return err;drivers/gpu/drm/xe/xe_device_types.h +0
-0
drivers/gpu/drm/xe/xe_device_types.h line 19
Quoted 4 lines
drivers/gpu/drm/xe/xe_device_types.h +1
-0@@ -16,6 +16,7 @@#include "xe_devcoredump_types.h" #include "xe_heci_gsc.h" #include "xe_lmtt_types.h" +#include "xe_late_bind_fw_types.h"
should be sorted
Quoted 98 lines
drivers/gpu/drm/xe/xe_device_types.h +5
-0#include "xe_memirq_types.h" #include "xe_oa_types.h" #include "xe_platform_types.h" @@ -325,6 +326,8 @@ struct xe_device { u8 has_heci_cscfi:1;/** @info.has_heci_gscfi: device has heci gscfi */ u8 has_heci_gscfi:1; +/** @info.has_late_bind: Device has firmware late binding support */ + u8 has_late_bind:1;/** @info.has_llc: Device has a shared CPU+GPU last level cache */ u8 has_llc:1;/** @info.has_mbx_power_limits: Device has support to manage power limits using @@ -557,6 +560,9 @@ struct xe_device {/** @nvm: discrete graphics non-volatile memory */ struct intel_dg_nvm_dev *nvm; +/** @late_bind: xe mei late bind interface */ +struct xe_late_bind late_bind; +/** @oa: oa observation subsystem */ struct xe_oa oa;drivers/gpu/drm/xe/xe_late_bind_fw.c new file +70
-0@@ -0,0 +1,84 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2025 Intel Corporation +*/ + +#include <linux/component.h> +#include <linux/delay.h> + +#include <drm/drm_managed.h> +#include <drm/intel/i915_component.h> +#include <drm/intel/intel_lb_mei_interface.h> +#include <drm/drm_print.h> + +#include "xe_device.h" +#include "xe_late_bind_fw.h" + +static struct xe_device * +late_bind_to_xe (struct xe_late_bind *late_bind) +{ + return container_of(late_bind, struct xe_device, late_bind); +} + +static int xe_late_bind_component_bind (struct device *xe_kdev, +struct device *mei_kdev,void *data) +{ +struct xe_device *xe =kdev_to_xe_device (xe_kdev); +struct xe_late_bind *late_bind = &xe->late_bind; + + late_bind->component.ops = data; + late_bind->component.mei_dev = mei_kdev; + +return 0 ; +} + +static void xe_late_bind_component_unbind (struct device *xe_kdev, +struct device *mei_kdev,void *data) +{ +struct xe_device *xe =kdev_to_xe_device (xe_kdev); +struct xe_late_bind *late_bind = &xe->late_bind; + + late_bind->component.ops =NULL ; +} + +static const struct component_ops xe_late_bind_component_ops = { + .bind = xe_late_bind_component_bind, + .unbind = xe_late_bind_component_unbind, +}; + +static void xe_late_bind_remove (void *arg) +{ +struct xe_late_bind *late_bind = arg; +struct xe_device *xe =late_bind_to_xe (late_bind); + +component_del (xe->drm.dev, &xe_late_bind_component_ops); +} + +/** +* xe_late_bind_init() - add xe mei late binding component +* @late_bind: pointer to late bind structure. +* +* Return: 0 if the initialization was successful, a negative errno otherwise. +*/ +int xe_late_bind_init (struct xe_late_bind *late_bind) +{ +struct xe_device *xe =late_bind_to_xe (late_bind); +int err; + +if (!xe->info.has_late_bind) +return 0 ; +
drivers/gpu/drm/xe/xe_late_bind_fw.c line 80
Quoted 10 lines
drivers/gpu/drm/xe/xe_late_bind_fw.c new file +10
-0+if (!IS_ENABLED (CONFIG_INTEL_MEI_LATE_BIND ) || !IS_ENABLED (CONFIG_INTEL_MEI_GSC )) { +drm_info (&xe->drm,"Can't init xe mei late bind missing mei component\n" ); +return -ENODEV ; + } + + err =component_add_typed (xe->drm.dev, &xe_late_bind_component_ops, +INTEL_COMPONENT_LB ); +if (err <0 ) { +drm_info (&xe->drm,"Failed to add mei late bind component (%pe)\n" ,ERR_PTR (err)); +return err;
if you are going to return an error to stop the probe, then make this a drm_err()
Quoted 69 lines
drivers/gpu/drm/xe/xe_late_bind_fw.c new file +4
-0+ } + +return devm_add_action_or_reset (xe->drm.dev, xe_late_bind_remove, late_bind); +}drivers/gpu/drm/xe/xe_late_bind_fw.h new file +15
-0@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_LATE_BIND_FW_H_ +#define _XE_LATE_BIND_FW_H_ + +#include <linux/types.h> + +struct xe_late_bind ; + +int xe_late_bind_init (struct xe_late_bind *late_bind); + +#endif drivers/gpu/drm/xe/xe_late_bind_fw_types.h new file +33
-0@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_LATE_BIND_TYPES_H_ +#define _XE_LATE_BIND_TYPES_H_ + +#include <linux/iosys-map.h> +#include <linux/mutex.h> +#include <linux/types.h> + +/** +* struct xe_late_bind_component - Late Binding services component +* @mei_dev: device that provide Late Binding service. +* @ops: Ops implemented by Late Binding driver, used by Xe driver. +* +* Communication between Xe and MEI drivers for Late Binding services +*/ +struct xe_late_bind_component { +struct device *mei_dev; +const struct late_bind_component_ops *ops; +}; + +/** +* struct xe_late_bind +*/ +struct xe_late_bind { +/** @component: struct for communication with mei component */ +struct xe_late_bind_component component; +}; + +#endif drivers/gpu/drm/xe/xe_pci.c +0
-0
drivers/gpu/drm/xe/xe_pci.c static const struct xe_device_desc bmg_desc = { · line 335
Quoted 4 lines
drivers/gpu/drm/xe/xe_pci.c +1
-0@@ -332,6 +332,7 @@ static const struct xe_device_desc bmg_desc = { .has_gsc_nvm = 1, .has_heci_cscfi = 1, .max_gt_per_tile = 2, + .has_late_bind = true,
again, boring is good: all the has_xxxx flags should be sorted together.
Lucas De Marchi
Quoted 26 lines
drivers/gpu/drm/xe/xe_pci.c +1
-0.needs_scratch = true, };@@ -578,6 +579,7 @@ static int xe_info_init_early(struct xe_device *xe, xe->info.has_gsc_nvm = desc->has_gsc_nvm; xe->info.has_heci_gscfi = desc->has_heci_gscfi; xe->info.has_heci_cscfi = desc->has_heci_cscfi; + xe->info.has_late_bind = desc->has_late_bind; xe->info.has_llc = desc->has_llc; xe->info.has_pxp = desc->has_pxp; xe->info.has_sriov = desc->has_sriov;drivers/gpu/drm/xe/xe_pci_types.h +1
-0@@ -39,6 +39,7 @@ struct xe_device_desc { u8 has_gsc_nvm:1; u8 has_heci_gscfi:1; u8 has_heci_cscfi:1; + u8 has_late_bind:1; u8 has_llc:1; u8 has_mbx_power_limits:1; u8 has_pxp:1;Signature · 1 line
2.49.0
Re: [PATCH 3/9] drm/xe/xe_late_bind_fw: Introducing xe_late_bind_fw
Quoted 6 lines · Lucas De Marchi
Quoted 3 lines · Rodrigo Vivi
From: Badal Nilawar <[email protected]>
Introducing
xe_late_bind_fwto enable firmware loading for the devices,here and in the subject: no gerund, please.
Sure.
Quoted 34 lines
Quoted 34 lines
such as the fan controller, during the driver probe. Typically, firmware for such devices are part of IFWI flash image but can be replaced at probe after OEM tuning.
This patch binds mei late binding component to enable firmware loading.v2:
- Adddevm_add_action_or_resetto remove the component (Daniele)
- AddINTEL_MEI_GSCcheck inxe_late_bind_init()(Daniele) v3:
- Fail driver probe if late bind initialization fails, addhas_late_bindflag (Daniele)
v4:
- %S/I915_COMPONENT_LATE_BIND/INTEL_COMPONENT_LATE_BIND/ v6:
- rebasedSigned-off-by Badal Nilawar <[email protected]>Reviewed-by Daniele Ceraolo Spurio <[email protected]>Signed-off-by Rodrigo Vivi <[email protected]>---
drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_device.c | 5 ++drivers/gpu/drm/xe/xe_device_types.h | 6 ++ drivers/gpu/drm/xe/xe_late_bind_fw.c | 84 ++++++++++++++++++++++ drivers/gpu/drm/xe/xe_late_bind_fw.h | 15 ++++ drivers/gpu/drm/xe/xe_late_bind_fw_types.h | 33 +++++++++ drivers/gpu/drm/xe/xe_pci.c | 2 + drivers/gpu/drm/xe/xe_pci_types.h | 1 + 8 files changed, 147 insertions(+)create mode 100644
drivers/gpu/drm/xe/xe_late_bind_fw.ccreate mode 100644drivers/gpu/drm/xe/xe_late_bind_fw.hcreate mode 100644drivers/gpu/drm/xe/xe_late_bind_fw_types.h
Quoted 11 lines
drivers/gpu/drm/xe/Makefile xe-y += xe_bb.o \ · line 79
Quoted 9 lines
drivers/gpu/drm/xe/Makefile +1
-0@@ -76,6 +76,7 @@ xe-y += xe_bb.o \ xe_hw_fence.o \ xe_irq.o \ xe_lrc.o \ + xe_late_bind_fw.o \almost there, but still not sorted as it should be
It seems the rebase messed up the order—it was correctly placed in the previous revision. I’ll fix it.
Quoted 20 lines
Quoted 20 lines
drivers/gpu/drm/xe/Makefile +0
-0xe_migrate.o \ xe_mmio.o \ xe_mocs.o \drivers/gpu/drm/xe/xe_device.c +1
-0@@ -44,6 +44,7 @@#include "xe_hw_engine_group.h" #include "xe_hwmon.h" #include "xe_irq.h" +#include "xe_late_bind_fw.h" #include "xe_mmio.h" #include "xe_module.h" #include "xe_nvm.h" @@ -866,6 +867,10 @@ int xe_device_probe(struct xe_device *xe) if (err) return err;
Quoted 7 lines
drivers/gpu/drm/xe/xe_device.c int xe_device_probe(struct xe_device *xe) · line 871
Quoted 2 lines
drivers/gpu/drm/xe/xe_device.c +2
-0+ err = xe_late_bind_init(&xe->late_bind); + if (err && err != -ENODEV)let's not be creative in
xe_device_probe(). Boring is good.All the other parts in this function handle ENODEV internally. It's up to them to decide if ENODEV -> return 0, not here.
sure, will update accordingly.
Quoted 18 lines
Quoted 12 lines
drivers/gpu/drm/xe/xe_device.c +2
-0+ return err; + err = xe_oa_init(xe); if (err) return err;drivers/gpu/drm/xe/xe_device_types.h +0
-0drivers/gpu/drm/xe/xe_device_types.h line 19
Quoted 4 lines
drivers/gpu/drm/xe/xe_device_types.h +1
-0@@ -16,6 +16,7 @@#include "xe_devcoredump_types.h" #include "xe_heci_gsc.h" #include "xe_lmtt_types.h" +#include "xe_late_bind_fw_types.h" should be sorted
Sure.
Quoted 109 lines
Quoted 109 lines
drivers/gpu/drm/xe/xe_device_types.h +1
-0#include "xe_memirq_types.h" #include "xe_oa_types.h" #include "xe_platform_types.h" @@ -325,6 +326,8 @@ struct xe_device { u8 has_heci_cscfi:1; /** @info.has_heci_gscfi: device has heci gscfi */ u8 has_heci_gscfi:1; + /** @info.has_late_bind: Device has firmware late bindingsupport */
+ u8 has_late_bind:1;
/** @info.has_llc: Device has a shared CPU+GPU last level cache */ u8 has_llc:1;
/** @info.has_mbx_power_limits: Device has support to manage power limits usingdrivers/gpu/drm/xe/xe_device_types.h +3
-0@@ -557,6 +560,9 @@ struct xe_device { /** @nvm: discrete graphics non-volatile memory */ struct intel_dg_nvm_dev *nvm; + /** @late_bind: xe mei late bind interface */ + struct xe_late_bind late_bind; + /** @oa: oa observation subsystem */ struct xe_oa oa;drivers/gpu/drm/xe/xe_late_bind_fw.c new file +61
-0@@ -0,0 +1,84 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2025 Intel Corporation +*/ + +#include <linux/component.h> +#include <linux/delay.h> + +#include <drm/drm_managed.h> +#include <drm/intel/i915_component.h> +#include <drm/intel/intel_lb_mei_interface.h> +#include <drm/drm_print.h> + +#include "xe_device.h" +#include "xe_late_bind_fw.h" + +static struct xe_device * +late_bind_to_xe (struct xe_late_bind *late_bind) +{ + return container_of(late_bind, struct xe_device, late_bind); +} + +static int xe_late_bind_component_bind (struct device *xe_kdev, + struct device *mei_kdev, void *data) +{ + struct xe_device *xe = kdev_to_xe_device(xe_kdev); + struct xe_late_bind *late_bind = &xe->late_bind; + + late_bind->component.ops = data; + late_bind->component.mei_dev = mei_kdev; + + return 0; +} + +static void xe_late_bind_component_unbind (struct device *xe_kdev, + struct device *mei_kdev, void *data) +{ + struct xe_device *xe = kdev_to_xe_device(xe_kdev); + struct xe_late_bind *late_bind = &xe->late_bind; + + late_bind->component.ops = NULL; +} + +static const struct component_ops xe_late_bind_component_ops = { + .bind = xe_late_bind_component_bind, + .unbind = xe_late_bind_component_unbind, +}; + +static void xe_late_bind_remove (void *arg) +{ + struct xe_late_bind *late_bind = arg; + struct xe_device *xe = late_bind_to_xe(late_bind); + + component_del(xe->drm.dev, &xe_late_bind_component_ops); +} + +/** +* xe_late_bind_init() - add xe mei late binding component +* @late_bind: pointer to late bind structure. +* +* Return: 0 if the initialization was successful, a negative errno otherwise.
+ */drivers/gpu/drm/xe/xe_late_bind_fw.c new file +9
-0+int xe_late_bind_init (struct xe_late_bind *late_bind) +{ + struct xe_device *xe = late_bind_to_xe(late_bind); + int err; + + if (!xe->info.has_late_bind) + return 0; + + if (!IS_ENABLED(CONFIG_INTEL_MEI_LATE_BIND) ||!IS_ENABLED(CONFIG_INTEL_MEI_GSC)) {
+drm_info(&xe->drm, "Can't init xe mei late bind missing mei component\n");
+ return-ENODEV;
+ }
+
+ err = component_add_typed(xe->drm.dev,&xe_late_bind_component_ops,
Quoted 8 lines
Quoted 5 lines
+
INTEL_COMPONENT_LB);
+ if (err < 0) {
+drm_info(&xe->drm, "Failed to add mei late bind component (%pe)\n", ERR_PTR(err));
+ return err;if you are going to return an error to stop the probe, then make this a
drm_err()
Sure.
Quoted 70 lines
Quoted 70 lines
+ }
+
+ return devm_add_action_or_reset(xe->drm.dev,xe_late_bind_remove,late_bind);drivers/gpu/drm/xe/xe_late_bind_fw.c new file +1
-0+}drivers/gpu/drm/xe/xe_late_bind_fw.h new file +15
-0@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_LATE_BIND_FW_H_ +#define _XE_LATE_BIND_FW_H_ + +#include <linux/types.h> + +struct xe_late_bind ; + +int xe_late_bind_init (struct xe_late_bind *late_bind); + +#endif drivers/gpu/drm/xe/xe_late_bind_fw_types.h new file +33
-0@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_LATE_BIND_TYPES_H_ +#define _XE_LATE_BIND_TYPES_H_ + +#include <linux/iosys-map.h> +#include <linux/mutex.h> +#include <linux/types.h> + +/** +* struct xe_late_bind_component - Late Binding services component +* @mei_dev: device that provide Late Binding service. +* @ops: Ops implemented by Late Binding driver, used by Xe driver. +* +* Communication between Xe and MEI drivers for Late Binding services +*/ +struct xe_late_bind_component { + struct device *mei_dev; + const struct late_bind_component_ops *ops; +}; + +/** +* struct xe_late_bind +*/ +struct xe_late_bind { + /** @component: struct for communication with mei component */ + struct xe_late_bind_component component; +}; + +#endif drivers/gpu/drm/xe/xe_pci.c +0
-0
Quoted 8 lines
drivers/gpu/drm/xe/xe_pci.c static const struct xe_device_desc bmg_desc = { · line 335
Quoted 5 lines
drivers/gpu/drm/xe/xe_pci.c +1
-0@@ -332,6 +332,7 @@ static const struct xe_device_desc bmg_desc = { .has_gsc_nvm = 1, .has_heci_cscfi = 1, .max_gt_per_tile = 2, + .has_late_bind = true,again, boring is good: all the
has_xxxxflags should be sorted together.
Looks like the re-base affected this part as well. It was correctly grouped in the previous revision — I’ll fix this.
Thanks,
Badal
Quoted 29 lines
Lucas De Marchi
Quoted 26 lines
drivers/gpu/drm/xe/xe_pci.c +1
-0.needs_scratch = true, };@@ -578,6 +579,7 @@ static int xe_info_init_early(struct xe_device *xe, xe->info.has_gsc_nvm = desc->has_gsc_nvm; xe->info.has_heci_gscfi = desc->has_heci_gscfi; xe->info.has_heci_cscfi = desc->has_heci_cscfi; + xe->info.has_late_bind = desc->has_late_bind; xe->info.has_llc = desc->has_llc; xe->info.has_pxp = desc->has_pxp; xe->info.has_sriov = desc->has_sriov;drivers/gpu/drm/xe/xe_pci_types.h +1
-0@@ -39,6 +39,7 @@ struct xe_device_desc { u8 has_gsc_nvm:1; u8 has_heci_gscfi:1; u8 has_heci_cscfi:1; + u8 has_late_bind:1; u8 has_llc:1; u8 has_mbx_power_limits:1; u8 has_pxp:1;Signature · 1 line
2.49.0
Rodrigo Vivi
maintainerPATCH 4/9 drm/xe/xe_late_bind_fw: Initialize late binding firmware
In reply to Rodrigo ViviFrom: Badal Nilawar <[email protected]>
Search for late binding firmware binaries and populate the meta data of firmware structures.
v2 (Daniele):
- drm_err if firmware size is more than max pay load size
- s/request_firmware/firmware_request_nowarn/ as firmware will not be available for all possible cards
v3 (Daniele):
- init firmware from within xe_late_bind_init, propagate error
- switch late_bind_fw to array to handle multiple firmware types
v4 (Daniele):
- Alloc payload dynamically, fix nits
v6 (Daniele)
- %s/MAX_PAYLOAD_SIZE/XE_LB_MAX_PAYLOAD_SIZE/
--- drivers/gpu/drm/xe/xe_late_bind_fw.c | 100 ++++++++++++++++++++- drivers/gpu/drm/xe/xe_late_bind_fw_types.h | 30 +++++++ 2 files changed, 129 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_late_bind_fw.c +99 -1
@@ -5,6 +5,7 @@#include <linux/component.h> #include <linux/delay.h> +#include <linux/firmware.h> #include <drm/drm_managed.h> #include <drm/intel/i915_component.h>
@@ -13,6 +14,16 @@#include "xe_device.h" #include "xe_late_bind_fw.h" +#include "xe_pcode.h" +#include "xe_pcode_api.h" + +static const u32 fw_id_to_type[] = { + [XE_LB_FW_FAN_CONTROL ] =INTEL_LB_TYPE_FAN_CONTROL , + }; + +static const char *const fw_id_to_name[] = { + [XE_LB_FW_FAN_CONTROL ] ="fan_control" , + };static struct xe_device *late_bind_to_xe (struct xe_late_bind *late_bind)
@@ -20,6 +31,89 @@ late_bind_to_xe(struct xe_late_bind *late_bind) return container_of(late_bind, struct xe_device, late_bind); } +static int xe_late_bind_fw_num_fans (struct xe_late_bind *late_bind) +{ +struct xe_device *xe =late_bind_to_xe (late_bind); +struct xe_tile *root_tile =xe_device_get_root_tile (xe); +u32 uval; + +if (!xe_pcode_read (root_tile, +PCODE_MBOX (FAN_SPEED_CONTROL ,FSC_READ_NUM_FANS ,0 ), &uval,NULL )) +return uval; +else +return 0 ; +} + +static int __xe_late_bind_fw_init (struct xe_late_bind *late_bind,u32 fw_id) +{ +struct xe_device *xe =late_bind_to_xe (late_bind); +struct pci_dev *pdev =to_pci_dev (xe->drm.dev); +struct xe_late_bind_fw *lb_fw; +const struct firmware *fw; +u32 num_fans; +int ret; + +if (fw_id >=XE_LB_FW_MAX_ID ) +return -EINVAL ; + + lb_fw = &late_bind->late_bind_fw[fw_id]; + + lb_fw->id = fw_id; + lb_fw->type = fw_id_to_type[lb_fw->id]; + lb_fw->flags &= ~INTEL_LB_FLAGS_IS_PERSISTENT ; + +if (lb_fw->type ==INTEL_LB_TYPE_FAN_CONTROL ) { + num_fans =xe_late_bind_fw_num_fans (late_bind); +drm_dbg (&xe->drm,"Number of Fans: %d\n" , num_fans); +if (!num_fans) +return 0 ; + } + +snprintf (lb_fw->blob_path,sizeof (lb_fw->blob_path),"xe/%s_8086_%04x_%04x_%04x.bin" , + fw_id_to_name[lb_fw->id], pdev->device, + pdev->subsystem_vendor, pdev->subsystem_device); + +drm_dbg (&xe->drm,"Request late binding firmware %s\n" , lb_fw->blob_path); + ret =firmware_request_nowarn (&fw, lb_fw->blob_path, xe->drm.dev); +if (ret) { +drm_dbg (&xe->drm,"%s late binding fw not available for current device" , + fw_id_to_name[lb_fw->id]); +return 0 ; + } + +if (fw->size >XE_LB_MAX_PAYLOAD_SIZE ) { +drm_err (&xe->drm,"Firmware %s size %zu is larger than max pay load size %u\n" , + lb_fw->blob_path, fw->size,XE_LB_MAX_PAYLOAD_SIZE ); +release_firmware (fw); +return -ENODATA ; + } + + lb_fw->payload_size = fw->size; + lb_fw->payload =drmm_kzalloc (&xe->drm, lb_fw->payload_size,GFP_KERNEL ); +if (!lb_fw->payload) { +release_firmware (fw); +return -ENOMEM ; + } + +memcpy ((void *)lb_fw->payload, fw->data, lb_fw->payload_size); +release_firmware (fw); + +return 0 ; +} + +static int xe_late_bind_fw_init (struct xe_late_bind *late_bind) +{ +int ret; +int fw_id; + +for (fw_id =0 ; fw_id <XE_LB_FW_MAX_ID ; fw_id++) { + ret =__xe_late_bind_fw_init (late_bind, fw_id); +if (ret) +return ret; + } +return 0 ; +} +static int xe_late_bind_component_bind (struct device *xe_kdev,struct device *mei_kdev,void *data) {
@@ -80,5 +174,9 @@ int xe_late_bind_init(struct xe_late_bind *late_bind)return err; } -return devm_add_action_or_reset (xe->drm.dev, xe_late_bind_remove, late_bind); + err =devm_add_action_or_reset (xe->drm.dev, xe_late_bind_remove, late_bind); +if (err) +return err; + +return xe_late_bind_fw_init (late_bind); }
drivers/gpu/drm/xe/xe_late_bind_fw_types.h +30 -0
@@ -10,6 +10,34 @@#include <linux/mutex.h> #include <linux/types.h> +#define XE_LB_MAX_PAYLOAD_SIZE SZ_4K + +/** +* xe_late_bind_fw_id - enum to determine late binding fw index +*/ +enum xe_late_bind_fw_id { +XE_LB_FW_FAN_CONTROL =0 , +XE_LB_FW_MAX_ID +}; + +/** +* struct xe_late_bind_fw +*/ +struct xe_late_bind_fw { +/** @id: firmware index */ +u32 id; +/** @blob_path: firmware binary path */ +char blob_path[PATH_MAX ]; +/** @type: firmware type */ +u32 type; +/** @flags: firmware flags */ +u32 flags; +/** @payload: to store the late binding blob */ +const u8 *payload; +/** @payload_size: late binding blob payload_size */ +size_t payload_size; +}; +/** * struct xe_late_bind_component - Late Binding services component * @mei_dev: device that provide Late Binding service.
@@ -28,6 +56,8 @@ struct xe_late_bind_component {struct xe_late_bind {/** @component: struct for communication with mei component */ struct xe_late_bind_component component; +/** @late_bind_fw: late binding firmware array */ +struct xe_late_bind_fw late_bind_fw[XE_LB_FW_MAX_ID ]; };#endif
Signature · 1 line
2.49.0
Rodrigo Vivi
maintainerPATCH 5/9 drm/xe/xe_late_bind_fw: Load late binding firmware
In reply to Rodrigo ViviFrom: Badal Nilawar <[email protected]>
Load late binding firmware
v2:
- s/EAGAIN/EBUSY/
- Flush worker in suspend and driver unload (Daniele)
v3:
- Use retry interval of 6s, in steps of 200ms, to allow other OS components release MEI CL handle (Sasha)
v4:
- return -ENODEV if component not added (Daniele)
- parse and print status returned by csc
v5:
- Use payload to check firmware valid (Daniele)
- Obtain the RPM reference before scheduling the worker to ensure the device remains awake until the worker completes firmware loading (Rodrigo)
v6:
- In case of error donot re-attempt fw download (Daniele)
v7 (Rodrigo):
- Rename of mei structs and callback.
--- drivers/gpu/drm/xe/xe_late_bind_fw.c | 157 ++++++++++++++++++++- drivers/gpu/drm/xe/xe_late_bind_fw.h | 1 + drivers/gpu/drm/xe/xe_late_bind_fw_types.h | 9 +- 3 files changed, 165 insertions(+), 2 deletions(-)
drivers/gpu/drm/xe/xe_late_bind_fw.c +156 -1
@@ -16,6 +16,20 @@#include "xe_late_bind_fw.h" #include "xe_pcode.h" #include "xe_pcode_api.h" +#include "xe_pm.h" + +/* +* The component should load quite quickly in most cases, but it could take +* a bit. Using a very big timeout just to cover the worst case scenario +*/ +#define LB_INIT_TIMEOUT_MS 20000 + +/* +* Retry interval set to 6 seconds, in steps of 200 ms, to allow time for +* other OS components to release the MEI CL handle +*/ +#define LB_FW_LOAD_RETRY_MAXCOUNT 30 +#define LB_FW_LOAD_RETRY_PAUSE_MS 200static const u32 fw_id_to_type[] = { [XE_LB_FW_FAN_CONTROL ] =INTEL_LB_TYPE_FAN_CONTROL ,
@@ -31,6 +45,30 @@ late_bind_to_xe(struct xe_late_bind *late_bind) return container_of(late_bind, struct xe_device, late_bind); } +static const char *xe_late_bind_parse_status (uint32_t status) +{ +switch (status) { +case INTEL_LB_STATUS_SUCCESS : +return "success" ; +case INTEL_LB_STATUS_4ID_MISMATCH : +return "4Id Mismatch" ; +case INTEL_LB_STATUS_ARB_FAILURE : +return "ARB Failure" ; +case INTEL_LB_STATUS_GENERAL_ERROR : +return "General Error" ; +case INTEL_LB_STATUS_INVALID_PARAMS : +return "Invalid Params" ; +case INTEL_LB_STATUS_INVALID_SIGNATURE : +return "Invalid Signature" ; +case INTEL_LB_STATUS_INVALID_PAYLOAD : +return "Invalid Payload" ; +case INTEL_LB_STATUS_TIMEOUT : +return "Timeout" ; +default : +return "Unknown error" ; + } +} +static int xe_late_bind_fw_num_fans (struct xe_late_bind *late_bind) {struct xe_device *xe =late_bind_to_xe (late_bind);
@@ -44,6 +82,101 @@ static int xe_late_bind_fw_num_fans(struct xe_late_bind *late_bind)return 0 ; } +static void xe_late_bind_wait_for_worker_completion (struct xe_late_bind *late_bind) +{ +struct xe_device *xe =late_bind_to_xe (late_bind); +struct xe_late_bind_fw *lbfw; +int fw_id; + +for (fw_id =0 ; fw_id <XE_LB_FW_MAX_ID ; fw_id++) { + lbfw = &late_bind->late_bind_fw[fw_id]; +if (lbfw->payload && late_bind->wq) { +drm_dbg (&xe->drm,"Flush work: load %s firmware\n" , + fw_id_to_name[lbfw->id]); +flush_work (&lbfw->work); + } + } +} + +static void xe_late_bind_work (struct work_struct *work) +{ + struct xe_late_bind_fw *lbfw = container_of(work, struct xe_late_bind_fw, work); + struct xe_late_bind *late_bind = container_of(lbfw, struct xe_late_bind, + late_bind_fw[lbfw->id]); +struct xe_device *xe =late_bind_to_xe (late_bind); +int retry =LB_FW_LOAD_RETRY_MAXCOUNT ; +int ret; +int slept; + +xe_device_assert_mem_access (xe); + +/* we can queue this before the component is bound */ +for (slept =0 ; slept <LB_INIT_TIMEOUT_MS ; slept +=100 ) { +if (late_bind->component.ops) +break ; +msleep (100 ); + } + +if (!late_bind->component.ops) { +drm_err (&xe->drm,"Late bind component not bound\n" ); +/* Do not re-attempt fw load */ +drmm_kfree (&xe->drm, (void *)lbfw->payload); + lbfw->payload =NULL ; + goto out; + } + +drm_dbg (&xe->drm,"Load %s firmware\n" , fw_id_to_name[lbfw->id]); + +do { + ret = late_bind->component.ops->push_payload (late_bind->component.mei_dev, + lbfw->type, + lbfw->flags, + lbfw->payload, + lbfw->payload_size); +if (!ret) +break ; +msleep (LB_FW_LOAD_RETRY_PAUSE_MS ); + }while (--retry && ret == -EBUSY ); + +if (!ret) { +drm_dbg (&xe->drm,"Load %s firmware successful\n" , + fw_id_to_name[lbfw->id]); + goto out; + } + +if (ret >0 ) +drm_err (&xe->drm,"Load %s firmware failed with err %d, %s\n" , + fw_id_to_name[lbfw->id], ret,xe_late_bind_parse_status (ret)); +else +drm_err (&xe->drm,"Load %s firmware failed with err %d" , + fw_id_to_name[lbfw->id], ret); +/* Do not re-attempt fw load */ +drmm_kfree (&xe->drm, (void *)lbfw->payload); + lbfw->payload =NULL ; + +out: +xe_pm_runtime_put (xe); +} + +int xe_late_bind_fw_load (struct xe_late_bind *late_bind) +{ +struct xe_device *xe =late_bind_to_xe (late_bind); +struct xe_late_bind_fw *lbfw; +int fw_id; + +if (!late_bind->component_added) +return -ENODEV ; + +for (fw_id =0 ; fw_id <XE_LB_FW_MAX_ID ; fw_id++) { + lbfw = &late_bind->late_bind_fw[fw_id]; +if (lbfw->payload) { +xe_pm_runtime_get_noresume (xe); +queue_work (late_bind->wq, &lbfw->work); + } + } +return 0 ; +} +static int __xe_late_bind_fw_init (struct xe_late_bind *late_bind,u32 fw_id) {struct xe_device *xe =late_bind_to_xe (late_bind);
@@ -97,6 +230,7 @@ static int __xe_late_bind_fw_init(struct xe_late_bind *late_bind, u32 fw_id)memcpy ((void *)lb_fw->payload, fw->data, lb_fw->payload_size);release_firmware (fw); +INIT_WORK (&lb_fw->work, xe_late_bind_work);return 0 ; }
@@ -106,11 +240,16 @@ static int xe_late_bind_fw_init(struct xe_late_bind *late_bind)int ret;int fw_id; + late_bind->wq =alloc_ordered_workqueue ("late-bind-ordered-wq" ,0 ); +if (!late_bind->wq) +return -ENOMEM ; +for (fw_id =0 ; fw_id <XE_LB_FW_MAX_ID ; fw_id++) { ret =__xe_late_bind_fw_init (late_bind, fw_id);if (ret)return ret; } +return 0 ; }
@@ -132,6 +271,8 @@ static void xe_late_bind_component_unbind(struct device *xe_kdev,struct xe_device *xe =kdev_to_xe_device (xe_kdev);struct xe_late_bind *late_bind = &xe->late_bind; +xe_late_bind_wait_for_worker_completion (late_bind); + late_bind->component.ops =NULL ; }
@@ -145,7 +286,15 @@ static void xe_late_bind_remove(void *arg)struct xe_late_bind *late_bind = arg;struct xe_device *xe =late_bind_to_xe (late_bind); +xe_late_bind_wait_for_worker_completion (late_bind); + + late_bind->component_added = false; +component_del (xe->drm.dev, &xe_late_bind_component_ops); +if (late_bind->wq) { +destroy_workqueue (late_bind->wq); + late_bind->wq =NULL ; + } }/**
@@ -174,9 +323,15 @@ int xe_late_bind_init(struct xe_late_bind *late_bind)return err; } + late_bind->component_added = true; + err =devm_add_action_or_reset (xe->drm.dev, xe_late_bind_remove, late_bind);if (err)return err; -return xe_late_bind_fw_init (late_bind); + err =xe_late_bind_fw_init (late_bind); +if (err) +return err; + +return xe_late_bind_fw_load (late_bind); }
drivers/gpu/drm/xe/xe_late_bind_fw.h +1 -0
@@ -11,5 +11,6 @@struct xe_late_bind ;int xe_late_bind_init (struct xe_late_bind *late_bind); +int xe_late_bind_fw_load (struct xe_late_bind *late_bind);#endif
drivers/gpu/drm/xe/xe_late_bind_fw_types.h +8 -1
@@ -9,6 +9,7 @@#include <linux/iosys-map.h> #include <linux/mutex.h> #include <linux/types.h> +#include <linux/workqueue.h> #define XE_LB_MAX_PAYLOAD_SIZE SZ_4K
@@ -36,6 +37,8 @@ struct xe_late_bind_fw {const u8 *payload;/** @payload_size: late binding blob payload_size */ size_t payload_size; +/** @work: worker to upload latebind blob */ +struct work_struct work; };/**
@@ -47,7 +50,7 @@ struct xe_late_bind_fw {*/ struct xe_late_bind_component {struct device *mei_dev; -const struct late_bind_component_ops *ops; +const struct intel_lb_component_ops *ops; };/**
@@ -58,6 +61,10 @@ struct xe_late_bind {struct xe_late_bind_component component;/** @late_bind_fw: late binding firmware array */ struct xe_late_bind_fw late_bind_fw[XE_LB_FW_MAX_ID ]; +/** @wq: workqueue to submit request to download late bind blob */ +struct workqueue_struct *wq; +/** @component_added: whether the component has been added */ + bool component_added; };#endif
Signature · 1 line
2.49.0
Rodrigo Vivi
maintainerPATCH 6/9 drm/xe/xe_late_bind_fw: Reload late binding fw in rpm resume
In reply to Rodrigo ViviFrom: Badal Nilawar <[email protected]>
Reload late binding fw during runtime resume.
--- drivers/gpu/drm/xe/xe_late_bind_fw.c | 2 +- drivers/gpu/drm/xe/xe_late_bind_fw.h | 1 + drivers/gpu/drm/xe/xe_pm.c | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_late_bind_fw.c +1 -1
@@ -82,7 +82,7 @@ static int xe_late_bind_fw_num_fans(struct xe_late_bind *late_bind)return 0 ; } -static void xe_late_bind_wait_for_worker_completion (struct xe_late_bind *late_bind) +void xe_late_bind_wait_for_worker_completion (struct xe_late_bind *late_bind) {struct xe_device *xe =late_bind_to_xe (late_bind);struct xe_late_bind_fw *lbfw;
drivers/gpu/drm/xe/xe_late_bind_fw.h +1 -0
@@ -12,5 +12,6 @@ struct xe_late_bind;int xe_late_bind_init (struct xe_late_bind *late_bind);int xe_late_bind_fw_load (struct xe_late_bind *late_bind); +void xe_late_bind_wait_for_worker_completion (struct xe_late_bind *late_bind);#endif
drivers/gpu/drm/xe/xe_pm.c +4 -0
@@ -20,6 +20,7 @@#include "xe_gt.h" #include "xe_guc.h" #include "xe_irq.h" +#include "xe_late_bind_fw.h" #include "xe_pcode.h" #include "xe_pxp.h" #include "xe_trace.h"
@@ -545,6 +546,9 @@ int xe_pm_runtime_resume(struct xe_device *xe)xe_pxp_pm_resume (xe->pxp); +if (xe->d3cold.allowed) +xe_late_bind_fw_load (&xe->late_bind); + out:xe_rpm_lockmap_release (xe);xe_pm_write_callback_task (xe,NULL );
Signature · 1 line
2.49.0
Rodrigo Vivi
maintainerPATCH 7/9 drm/xe/xe_late_bind_fw: Reload late binding fw during system resume
In reply to Rodrigo ViviFrom: Badal Nilawar <[email protected]>
Reload late binding fw during resume from system suspend
v2:
- Unconditionally reload late binding fw (Rodrigo)
- Flush worker during system suspend
--- drivers/gpu/drm/xe/xe_pm.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/xe/xe_pm.c +4 -0
@@ -127,6 +127,8 @@ int xe_pm_suspend(struct xe_device *xe)if (err) goto err; +xe_late_bind_wait_for_worker_completion (&xe->late_bind); +for_each_gt (gt, xe, id)xe_gt_suspend_prepare (gt);
@@ -204,6 +206,8 @@ int xe_pm_resume(struct xe_device *xe)xe_pxp_pm_resume (xe->pxp); +xe_late_bind_fw_load (&xe->late_bind); +drm_dbg (&xe->drm,"Device resumed\n" );return 0 ; err:
Signature · 1 line
2.49.0
Rodrigo Vivi
maintainerPATCH 8/9 drm/xe/xe_late_bind_fw: Introduce debug fs node to disable late binding
In reply to Rodrigo ViviFrom: Badal Nilawar <[email protected]>
Introduce a debug filesystem node to disable late binding fw reload during the system or runtime resume. This is intended for situations where the late binding fw needs to be loaded from user mode, perticularly for validation purpose.
Note that xe kmd doesn't participate in late binding flow from user space. Binary loaded from the userspace will be lost upon entering to D3 cold hence user space app need to handle this situation.
v2:
- s/(uval == 1) ? true : false/!!uval/ (Daniele)
v3:
- Refine the commit message (Daniele)
--- drivers/gpu/drm/xe/xe_debugfs.c | 41 ++++++++++++++++++++++ drivers/gpu/drm/xe/xe_late_bind_fw.c | 3 ++ drivers/gpu/drm/xe/xe_late_bind_fw_types.h | 2 ++ 3 files changed, 46 insertions(+)
drivers/gpu/drm/xe/xe_debugfs.c +41 -0
@@ -226,6 +226,44 @@ static const struct file_operations atomic_svm_timeslice_ms_fops = { .write = atomic_svm_timeslice_ms_set, }; +static ssize_t disable_late_binding_show (struct file *f,char __user *ubuf, +size_t size,loff_t *pos) +{ +struct xe_device *xe =file_inode (f)->i_private; +struct xe_late_bind *late_bind = &xe->late_bind; +char buf[32 ]; +int len; + + len =scnprintf (buf,sizeof (buf),"%d\n" , late_bind->disable); + +return simple_read_from_buffer (ubuf, size, pos, buf, len); +} + +static ssize_t disable_late_binding_set (struct file *f,const char __user *ubuf, +size_t size,loff_t *pos) +{ +struct xe_device *xe =file_inode (f)->i_private; +struct xe_late_bind *late_bind = &xe->late_bind; +u32 uval; +ssize_t ret; + + ret =kstrtouint_from_user (ubuf, size,sizeof (uval), &uval); +if (ret) +return ret; + +if (uval >1 ) +return -EINVAL ; + + late_bind->disable = !!uval; +return size; +} + +static const struct file_operations disable_late_binding_fops = { + .owner =THIS_MODULE , + .read = disable_late_binding_show, + .write = disable_late_binding_set, +}; +void xe_debugfs_register (struct xe_device *xe) {struct ttm_device *bdev = &xe->ttm;
@@ -249,6 +287,9 @@ void xe_debugfs_register(struct xe_device *xe)debugfs_create_file ("atomic_svm_timeslice_ms" ,0600 , root, xe, &atomic_svm_timeslice_ms_fops); +debugfs_create_file ("disable_late_binding" ,0600 , root, xe, + &disable_late_binding_fops); +for (mem_type =XE_PL_VRAM0 ; mem_type <=XE_PL_VRAM1 ; ++mem_type) { man =ttm_manager_type (bdev, mem_type);
drivers/gpu/drm/xe/xe_late_bind_fw.c +3 -0
@@ -167,6 +167,9 @@ int xe_late_bind_fw_load(struct xe_late_bind *late_bind)if (!late_bind->component_added)return -ENODEV ; +if (late_bind->disable) +return 0 ; +for (fw_id =0 ; fw_id <XE_LB_FW_MAX_ID ; fw_id++) { lbfw = &late_bind->late_bind_fw[fw_id];if (lbfw->payload) {
drivers/gpu/drm/xe/xe_late_bind_fw_types.h +2 -0
@@ -65,6 +65,8 @@ struct xe_late_bind {struct workqueue_struct *wq;/** @component_added: whether the component has been added */ bool component_added; +/** @disable: to block late binding reload during pm resume flow*/ + bool disable; };#endif
Signature · 1 line
2.49.0
Re: [PATCH 8/9] drm/xe/xe_late_bind_fw: Introduce debug fs node to disable late binding
Quoted 15 lines · Rodrigo Vivi
From: Badal Nilawar <[email protected]>
Introduce a debug filesystem node to disable late binding fw reload during the system or runtime resume. This is intended for situations where the late binding fw needs to be loaded from user mode, perticularly for validation purpose.
Note that xe kmd doesn't participate in late binding flow from user space. Binary loaded from the userspace will be lost upon entering to D3 cold hence user space app need to handle this situation.v2:
- s/(uval == 1) ? true : false/!!uval/ (Daniele) v3:
- Refine the commit message (Daniele)
Quoted 4 lines
Acked-by Rodrigo Vivi <[email protected]>Signed-off-by Badal Nilawar <[email protected]>Reviewed-by Daniele Ceraolo Spurio <[email protected]>Signed-off-by Rodrigo Vivi <[email protected]>
Bit of a flyby comment here, but would it be better if this was configfs rather than debugfs in case we wanted to skip this on the first probe?
Thanks,
Stuart
Quoted 104 lines
---
drivers/gpu/drm/xe/xe_debugfs.c | 41
++++++++++++++++++++++
drivers/gpu/drm/xe/xe_late_bind_fw.c | 3 ++drivers/gpu/drm/xe/xe_late_bind_fw_types.h| 2 ++3 files changed, 46 insertions(+)drivers/gpu/drm/xe/xe_debugfs.c +0
-0@@ -226,6 +226,44 @@ static const struct file_operations atomic_svm_timeslice_ms_fops = { .write = atomic_svm_timeslice_ms_set, };
+staticssize_tdisable_late_binding_show(struct file *f, char__user*ubuf,
+size_tsize,loff_t*pos)drivers/gpu/drm/xe/xe_debugfs.c +7
-0+{ + struct xe_device *xe = file_inode(f)->i_private; + struct xe_late_bind *late_bind = &xe->late_bind; + char buf[32]; + int len; + + len = scnprintf(buf, sizeof(buf), "%d\n", late_bind-Quoted 1 line
disable);
drivers/gpu/drm/xe/xe_debugfs.c +5
-0+ + return simple_read_from_buffer(ubuf, size, pos, buf, len); +} + +static ssize_t disable_late_binding_set(struct file *f, const char
__user*ubuf,
+ size_t size,loff_t*pos)drivers/gpu/drm/xe/xe_debugfs.c +23
-0+{ + struct xe_device *xe = file_inode(f)->i_private; + struct xe_late_bind *late_bind = &xe->late_bind; + u32 uval; + ssize_t ret; + + ret = kstrtouint_from_user(ubuf, size, sizeof(uval), &uval); + if (ret) + return ret; + + if (uval > 1) + return -EINVAL; + + late_bind->disable = !!uval; + return size; +} + +static const struct file_operations disable_late_binding_fops = { + .owner = THIS_MODULE, + .read = disable_late_binding_show, + .write = disable_late_binding_set, +}; +void
xe_debugfs_register(struct xe_device *xe)
{
structttm_device*bdev =&xe->ttm;drivers/gpu/drm/xe/xe_debugfs.c +0
-0@@ -249,6 +287,9 @@ void xe_debugfs_register(struct xe_device *xe) debugfs_create_file("atomic_svm_timeslice_ms", 0600, root, xe, &atomic_svm_timeslice_ms_fops);
+ debugfs_create_file("disable_late_binding", 0600, root, xe, +&disable_late_binding_fops); +
for (mem_type=XE_PL_VRAM0;mem_type<=XE_PL_VRAM1; ++mem_type) {
man =ttm_manager_type(bdev, mem_type);drivers/gpu/drm/xe/xe_late_bind_fw.c +0
-0@@ -167,6 +167,9 @@ int xe_late_bind_fw_load(struct xe_late_bind *late_bind) if (!late_bind->component_added) return -ENODEV;
+ if (late_bind->disable)
+ return 0;
+
for (fw_id= 0;fw_id<XE_LB_FW_MAX_ID; fw_id++) { lbfw = &late_bind->late_bind_fw[fw_id]; if (lbfw->payload) {drivers/gpu/drm/xe/xe_late_bind_fw_types.h +1
-0@@ -65,6 +65,8 @@ struct xe_late_bind { struct workqueue_struct *wq; /** @component_added: whether the component has been added */ bool component_added; + /** @disable: to block late binding reload during pm resumeflow*/
+ bool disable;
};
#endif
Rodrigo Vivi
maintainerRe: [PATCH 8/9] drm/xe/xe_late_bind_fw: Introduce debug fs node to disable late binding
Quoted 16 lines · Stuart
Quoted 15 lines · Rodrigo Vivi
From: Badal Nilawar <[email protected]>
Introduce a debug filesystem node to disable late binding fw reload during the system or runtime resume. This is intended for situations where the late binding fw needs to be loaded from user mode, perticularly for validation purpose.
Note that xe kmd doesn't participate in late binding flow from user space. Binary loaded from the userspace will be lost upon entering to D3 cold hence user space app need to handle this situation.v2:
- s/(uval == 1) ? true : false/!!uval/ (Daniele) v3:
- Refine the commit message (Daniele)
Quoted 8 lines
Quoted 4 lines
Acked-by Rodrigo Vivi <[email protected]>Signed-off-by Badal Nilawar <[email protected]>Reviewed-by Daniele Ceraolo Spurio <[email protected]>Signed-off-by Rodrigo Vivi <[email protected]>Bit of a flyby comment here, but would it be better if this was configfs rather than debugfs in case we wanted to skip this on the first probe?
Indeed. Configfs seems the best alternative for this. Otherwise by the time we get to have the debugfs, the fw was already attempted to get loaded at least once.
Quoted 109 lines
Thanks,
StuartQuoted 104 lines
---
drivers/gpu/drm/xe/xe_debugfs.c | 41
++++++++++++++++++++++
drivers/gpu/drm/xe/xe_late_bind_fw.c | 3 ++drivers/gpu/drm/xe/xe_late_bind_fw_types.h| 2 ++3 files changed, 46 insertions(+)drivers/gpu/drm/xe/xe_debugfs.c +0
-0@@ -226,6 +226,44 @@ static const struct file_operations atomic_svm_timeslice_ms_fops = { .write = atomic_svm_timeslice_ms_set, };
+staticssize_tdisable_late_binding_show(struct file *f, char__user*ubuf,
+size_tsize,loff_t*pos)drivers/gpu/drm/xe/xe_debugfs.c +7
-0+{ + struct xe_device *xe = file_inode(f)->i_private; + struct xe_late_bind *late_bind = &xe->late_bind; + char buf[32]; + int len; + + len = scnprintf(buf, sizeof(buf), "%d\n", late_bind-Quoted 1 line
disable);
drivers/gpu/drm/xe/xe_debugfs.c +5
-0+ + return simple_read_from_buffer(ubuf, size, pos, buf, len); +} + +static ssize_t disable_late_binding_set(struct file *f, const char
__user*ubuf,
+ size_t size,loff_t*pos)drivers/gpu/drm/xe/xe_debugfs.c +23
-0+{ + struct xe_device *xe = file_inode(f)->i_private; + struct xe_late_bind *late_bind = &xe->late_bind; + u32 uval; + ssize_t ret; + + ret = kstrtouint_from_user(ubuf, size, sizeof(uval), &uval); + if (ret) + return ret; + + if (uval > 1) + return -EINVAL; + + late_bind->disable = !!uval; + return size; +} + +static const struct file_operations disable_late_binding_fops = { + .owner = THIS_MODULE, + .read = disable_late_binding_show, + .write = disable_late_binding_set, +}; +void
xe_debugfs_register(struct xe_device *xe)
{
structttm_device*bdev =&xe->ttm;drivers/gpu/drm/xe/xe_debugfs.c +0
-0@@ -249,6 +287,9 @@ void xe_debugfs_register(struct xe_device *xe) debugfs_create_file("atomic_svm_timeslice_ms", 0600, root, xe, &atomic_svm_timeslice_ms_fops);
+ debugfs_create_file("disable_late_binding", 0600, root, xe, +&disable_late_binding_fops); +
for (mem_type=XE_PL_VRAM0;mem_type<=XE_PL_VRAM1; ++mem_type) {
man =ttm_manager_type(bdev, mem_type);drivers/gpu/drm/xe/xe_late_bind_fw.c +0
-0@@ -167,6 +167,9 @@ int xe_late_bind_fw_load(struct xe_late_bind *late_bind) if (!late_bind->component_added) return -ENODEV;
+ if (late_bind->disable)
+ return 0;
+
for (fw_id= 0;fw_id<XE_LB_FW_MAX_ID; fw_id++) { lbfw = &late_bind->late_bind_fw[fw_id]; if (lbfw->payload) {drivers/gpu/drm/xe/xe_late_bind_fw_types.h +1
-0@@ -65,6 +65,8 @@ struct xe_late_bind { struct workqueue_struct *wq; /** @component_added: whether the component has been added */ bool component_added; + /** @disable: to block late binding reload during pm resumeflow*/
+ bool disable;
};
#endif
Re: [PATCH 8/9] drm/xe/xe_late_bind_fw: Introduce debug fs node to disable late binding
Quoted 21 lines · Rodrigo Vivi
Quoted 20 lines · Stuart
Quoted 19 lines · Rodrigo Vivi
From: Badal Nilawar <[email protected]>
Introduce a debug filesystem node to disable late binding fw reload during the system or runtime resume. This is intended for situations where the late binding fw needs to be loaded from user mode, perticularly for validation purpose.
Note that xe kmd doesn't participate in late binding flow from user space. Binary loaded from the userspace will be lost upon entering to D3 cold hence user space app need to handle this situation.v2:
- s/(uval == 1) ? true : false/!!uval/ (Daniele)
v3:
- Refine the commit message (Daniele)Acked-by Rodrigo Vivi <[email protected]>Signed-off-by Badal Nilawar <[email protected]>Reviewed-by Daniele Ceraolo Spurio <[email protected]>Signed-off-by Rodrigo Vivi <[email protected]>
Quoted 6 lines
Quoted 3 lines
Bit of a flyby comment here, but would it be better if this was configfs rather than debugfs in case we wanted to skip this on the first probe?
Indeed. Configfs seems the best alternative for this. Otherwise by the time we get to have the debugfs, the fw was already attempted to get loaded at least once.
Don't want to skip fw load during probe, that's why used debugfs.
Regards,
Badal
Quoted 108 lines
Quoted 108 lines
Thanks,
StuartQuoted 104 lines
--- drivers/gpu/drm/xe/xe_debugfs.c | 41 ++++++++++++++++++++++ drivers/gpu/drm/xe/xe_late_bind_fw.c | 3 ++ drivers/gpu/drm/xe/xe_late_bind_fw_types.h | 2 ++ 3 files changed, 46 insertions(+)drivers/gpu/drm/xe/xe_debugfs.c +14
-0@@ -226,6 +226,44 @@ static const struct file_operations atomic_svm_timeslice_ms_fops = { .write = atomic_svm_timeslice_ms_set, }; +static ssize_t disable_late_binding_show (struct file *f,char __user *ubuf, + size_t size, loff_t *pos) +{ + struct xe_device *xe = file_inode(f)->i_private; + struct xe_late_bind *late_bind = &xe->late_bind; + char buf[32]; + int len; + + len = scnprintf(buf, sizeof(buf), "%d\n", late_bind- > disable); + + return simple_read_from_buffer(ubuf, size, pos, buf, len); +} + +static ssize_t disable_late_binding_set(struct file *f, const char
__user*ubuf,
+ size_t size,loff_t*pos)drivers/gpu/drm/xe/xe_debugfs.c +27
-0+{ + struct xe_device *xe = file_inode(f)->i_private; + struct xe_late_bind *late_bind = &xe->late_bind; + u32 uval; + ssize_t ret; + + ret = kstrtouint_from_user(ubuf, size, sizeof(uval), &uval); + if (ret) + return ret; + + if (uval > 1) + return -EINVAL; + + late_bind->disable = !!uval; + return size; +} + +static const struct file_operations disable_late_binding_fops = { + .owner = THIS_MODULE, + .read = disable_late_binding_show, + .write = disable_late_binding_set, +}; + void xe_debugfs_register(struct xe_device *xe) { struct ttm_device *bdev = &xe->ttm;@@ -249,6 +287,9 @@ void xe_debugfs_register(struct xe_device *xe) debugfs_create_file("atomic_svm_timeslice_ms", 0600, root, xe, &atomic_svm_timeslice_ms_fops); + debugfs_create_file("disable_late_binding", 0600, root, xe, + &disable_late_binding_fops); + for (mem_type = XE_PL_VRAM0; mem_type <= XE_PL_VRAM1; ++mem_type) { man = ttm_manager_type(bdev, mem_type);drivers/gpu/drm/xe/xe_late_bind_fw.c +3
-0@@ -167,6 +167,9 @@ int xe_late_bind_fw_load(struct xe_late_bind *late_bind) if (!late_bind->component_added) return -ENODEV; + if (late_bind->disable) + return 0; + for (fw_id = 0; fw_id < XE_LB_FW_MAX_ID; fw_id++) { lbfw = &late_bind->late_bind_fw[fw_id];if (
lbfw->payload) {drivers/gpu/drm/xe/xe_late_bind_fw_types.h +1
-0@@ -65,6 +65,8 @@ struct xe_late_bind { struct workqueue_struct *wq; /** @component_added: whether the component has been added */ bool component_added; + /** @disable: to block late binding reload during pm resumeflow*/
+ bool disable;
};#endif
Rodrigo Vivi
maintainerPATCH 9/9 drm/xe/xe_late_bind_fw: Extract and print version info
In reply to Rodrigo ViviFrom: Badal Nilawar <[email protected]>
Extract and print version info of the late binding binary.
v2: Some refinements (Daniele)
--- drivers/gpu/drm/xe/xe_late_bind_fw.c | 124 +++++++++++++++++++++ drivers/gpu/drm/xe/xe_late_bind_fw_types.h | 3 + drivers/gpu/drm/xe/xe_uc_fw_abi.h | 66 +++++++++++ 3 files changed, 193 insertions(+)
drivers/gpu/drm/xe/xe_late_bind_fw.c +124 -0
@@ -45,6 +45,121 @@ late_bind_to_xe(struct xe_late_bind *late_bind) return container_of(late_bind, struct xe_device, late_bind); } +static struct xe_device * +late_bind_fw_to_xe (struct xe_late_bind_fw *lb_fw) +{ + return container_of(lb_fw, struct xe_device, late_bind.late_bind_fw[lb_fw->id]); +} + +/* Refer to the "Late Bind based Firmware Layout" documentation entry for details */ +static int parse_cpd_header (struct xe_late_bind_fw *lb_fw, +const void *data,size_t size,const char *manifest_entry) +{ +struct xe_device *xe =late_bind_fw_to_xe (lb_fw); +const struct gsc_cpd_header_v2 *header = data; +const struct gsc_manifest_header *manifest; +const struct gsc_cpd_entry *entry; +size_t min_size =sizeof (*header); +u32 offset; +int i; + +/* manifest_entry is mandatory */ +xe_assert (xe, manifest_entry); + +if (size < min_size || header->header_marker !=GSC_CPD_HEADER_MARKER ) +return -ENOENT ; + +if (header->header_length <sizeof (struct gsc_cpd_header_v2 )) { +drm_err (&xe->drm,"%s late binding fw: Invalid CPD header length %u!\n" , + fw_id_to_name[lb_fw->id], header->header_length); +return -EINVAL ; + } + + min_size = header->header_length +sizeof (struct gsc_cpd_entry ) * header->num_of_entries; +if (size < min_size) { +drm_err (&xe->drm,"%s late binding fw: too small! %zu < %zu\n" , + fw_id_to_name[lb_fw->id], size, min_size); +return -ENODATA ; + } + +/* Look for the manifest first */ + entry = (void *)header + header->header_length; +for (i =0 ; i < header->num_of_entries; i++, entry++) +if (strcmp (entry->name, manifest_entry) ==0 ) + offset = entry->offset &GSC_CPD_ENTRY_OFFSET_MASK ; + +if (!offset) { +drm_err (&xe->drm,"%s late binding fw: Failed to find manifest_entry\n" , + fw_id_to_name[lb_fw->id]); +return -ENODATA ; + } + + min_size = offset +sizeof (struct gsc_manifest_header ); +if (size < min_size) { +drm_err (&xe->drm,"%s late binding fw: too small! %zu < %zu\n" , + fw_id_to_name[lb_fw->id], size, min_size); +return -ENODATA ; + } + + manifest = data + offset; + + lb_fw->version = manifest->fw_version; + +return 0 ; +} + +/* Refer to the "Late Bind based Firmware Layout" documentation entry for details */ +static int parse_lb_layout (struct xe_late_bind_fw *lb_fw, +const void *data,size_t size,const char *fpt_entry) +{ +struct xe_device *xe =late_bind_fw_to_xe (lb_fw); +const struct csc_fpt_header *header = data; +const struct csc_fpt_entry *entry; +size_t min_size =sizeof (*header); +u32 offset; +int i; + +/* fpt_entry is mandatory */ +xe_assert (xe, fpt_entry); + +if (size < min_size || header->header_marker !=CSC_FPT_HEADER_MARKER ) +return -ENOENT ; + +if (header->header_length <sizeof (struct csc_fpt_header )) { +drm_err (&xe->drm,"%s late binding fw: Invalid FPT header length %u!\n" , + fw_id_to_name[lb_fw->id], header->header_length); +return -EINVAL ; + } + + min_size = header->header_length +sizeof (struct csc_fpt_entry ) * header->num_of_entries; +if (size < min_size) { +drm_err (&xe->drm,"%s late binding fw: too small! %zu < %zu\n" , + fw_id_to_name[lb_fw->id], size, min_size); +return -ENODATA ; + } + +/* Look for the cpd header first */ + entry = (void *)header + header->header_length; +for (i =0 ; i < header->num_of_entries; i++, entry++) +if (strcmp (entry->name, fpt_entry) ==0 ) + offset = entry->offset; + +if (!offset) { +drm_err (&xe->drm,"%s late binding fw: Failed to find fpt_entry\n" , + fw_id_to_name[lb_fw->id]); +return -ENODATA ; + } + + min_size = offset +sizeof (struct gsc_cpd_header_v2 ); +if (size < min_size) { +drm_err (&xe->drm,"%s late binding fw: too small! %zu < %zu\n" , + fw_id_to_name[lb_fw->id], size, min_size); +return -ENODATA ; + } + +return parse_cpd_header (lb_fw, data + offset, size - offset,"LTES.man" ); +} +static const char *xe_late_bind_parse_status (uint32_t status) {switch (status) {
@@ -224,6 +339,10 @@ static int __xe_late_bind_fw_init(struct xe_late_bind *late_bind, u32 fw_id)return -ENODATA ; } + ret =parse_lb_layout (lb_fw, fw->data, fw->size,"LTES" ); +if (ret) +return ret; + lb_fw->payload_size = fw->size; lb_fw->payload =drmm_kzalloc (&xe->drm, lb_fw->payload_size,GFP_KERNEL );if (!lb_fw->payload) {
@@ -231,6 +350,11 @@ static int __xe_late_bind_fw_init(struct xe_late_bind *late_bind, u32 fw_id)return -ENOMEM ; } +drm_info (&xe->drm,"Using %s firmware from %s version %u.%u.%u.%u\n" , + fw_id_to_name[lb_fw->id], lb_fw->blob_path, + lb_fw->version.major, lb_fw->version.minor, + lb_fw->version.hotfix, lb_fw->version.build); +memcpy ((void *)lb_fw->payload, fw->data, lb_fw->payload_size);release_firmware (fw);INIT_WORK (&lb_fw->work, xe_late_bind_work);
drivers/gpu/drm/xe/xe_late_bind_fw_types.h +3 -0
@@ -10,6 +10,7 @@#include <linux/mutex.h> #include <linux/types.h> #include <linux/workqueue.h> +#include "xe_uc_fw_abi.h" #define XE_LB_MAX_PAYLOAD_SIZE SZ_4K
@@ -39,6 +40,8 @@ struct xe_late_bind_fw {size_t payload_size;/** @work: worker to upload latebind blob */ struct work_struct work; +/** @version: late binding blob manifest version */ +struct gsc_version version; };/**
drivers/gpu/drm/xe/xe_uc_fw_abi.h +66 -0
70 lines not on this page · raw message
Signature · 1 line
2.49.0