Add new debug infrastructure for configfs
Subsystems (2)
cover Add new debug infrastructure for configfs
Add a new configfs debug group. The intent of this structure is to allow us to separate ABI facing configfs entries from those which are purely for debug purposes. And it allows us more flexibility in how we define those parameters used for debug.
Add a new infrastructure to this debug configfs group that lets us easily define the parameters in a quick list. This is primarily useful for simple, single-type parameters such as enable/disable features or simple values passed. For more complex parameters, we will still need to define these separately.
Pull the GuC target related changes from [1] to fit within this new structure and add a new definition for guc_log_level on top of the existing module parameter (to ensure we aren't impacting existing users of the module parameter).
Note that the debug parameters here are all to be used "at your own risk". Without having in depth knowledge of how these impact the software and hardware, there could be unforeseen consequences of setting them. As such, they are all wrapped in a CONFIG_DRM_XE_DEBUG configfs option.
In terms of the patches here, I'm sorting the existing parameters by name/type. I know we have a few other module parameters that could migrate here, but I didn't want to overload this series too much, so the focus for now is on the existing configfs entries and demonstrating the new structures with the GuC log level and target parameters.
I used GitHub Copilot with Claude pretty extensively through the process here and attributed as such. Happy to answer any questions around this. Took a bit of time getting back to this series around other work, and in that time I was playing around with a few different models, hence some of the patches are showing multiple of them. I tried to attribute each as I was implementing the changes.
I also decided to drop John Harrison from the NPK patch. It has been modified quite a bit from the original, but more importantly John is no longer with Intel and that email address isn't available any more. If it makes a difference here, John and I had both separately implemented this same change at different occasions for debug. The one I used to start that initial series was cherry-picked from his latest variant.
v2:
- In this second revision I did confirm that the guc_log_level module parameter is taking precedence over the configfs parameter and ensured the other parameters seem to be autogenerating and working as expected.
- I tried to address all the review feedback from the first revision, [2].
- I also did another pass on the sorting since there were a few discrepancies I noticed in the first revision. I kept Gustavo's R-B on that one, but would like an ack before merging at least to confirm the patch is sane.
- And finally I moved the getter functions into the X-macro generators so we can autogenerate more of the similar functions between the different parameters in that debug param list.
v3:
- Address a couple of comments from Sashiko around GuC log level input checking and proper guard implementation.
v4:
- More review feedback from Sashiko addressed...
v5:
- Move the goto to a return (more Sashiko feedback) in the GuC log level setter before moving to the X-macro solution.
v6:
- Make the autogenerated X-macro function names more specific to avoid naming collisions (Sashiko again).
Stuart Summers (10):
drm/xe: Guard configfs attribute reads in getters drm/xe: Sort xe_config_device fields
drm/xe: Split out configfs data structures drm/xe: Add a new debug focused configfs group drm/xe: Move debug configfs entries to xe_configfs_debug.c drm/xe/guc: Add configfs support for guc_log_level drm/xe/guc: Add support for NPK as a GuC log target drm/xe: Add infrastructure for debug configfs parameters drm/xe: Migrate existing debug configfs entries to params
infrastructure
drm/xe: Taint kernel when debug configfs parameters are set
drivers/gpu/drm/xe/Makefile | 2 + drivers/gpu/drm/xe/abi/guc_log_abi.h | 8 + drivers/gpu/drm/xe/xe_configfs.c | 1017 +---------------- drivers/gpu/drm/xe/xe_configfs.h | 90 +- drivers/gpu/drm/xe/xe_configfs_debug.c | 872 ++++++++++++++ drivers/gpu/drm/xe/xe_configfs_debug.h | 48 + drivers/gpu/drm/xe/xe_configfs_debug_params.c | 158 +++ drivers/gpu/drm/xe/xe_configfs_debug_params.h | 194 ++++ drivers/gpu/drm/xe/xe_configfs_types.h | 59 + drivers/gpu/drm/xe/xe_defaults.h | 5 + drivers/gpu/drm/xe/xe_guc.c | 14 +- drivers/gpu/drm/xe/xe_guc_ads.c | 1 + drivers/gpu/drm/xe/xe_guc_log.c | 3 +- drivers/gpu/drm/xe/xe_hw_engine.c | 1 + drivers/gpu/drm/xe/xe_lrc.c | 1 + drivers/gpu/drm/xe/xe_pci.c | 1 + drivers/gpu/drm/xe/xe_psmi.c | 3 +- drivers/gpu/drm/xe/xe_rtp.c | 3 +- drivers/gpu/drm/xe/xe_survivability_mode.c | 1 + 19 files changed, 1495 insertions(+), 986 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_configfs_debug.c create mode 100644 drivers/gpu/drm/xe/xe_configfs_debug.h create mode 100644 drivers/gpu/drm/xe/xe_configfs_debug_params.c create mode 100644 drivers/gpu/drm/xe/xe_configfs_debug_params.h create mode 100644 drivers/gpu/drm/xe/xe_configfs_types.h
Signature · 1 line
2.43.0
PATCH 1/10 drm/xe: Guard configfs attribute reads in getters
The configfs getters read dev->config members without holding dev->lock, so a concurrent store can tear the value being returned. The store paths and a few of the getters already take the lock; make it consistent by wrapping every read of dev->config in the getters with a scoped_guard(), covering the surrounding checks that consume those values as well.
--- drivers/gpu/drm/xe/xe_configfs.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
drivers/gpu/drm/xe/xe_configfs.c +19 -10
@@ -1185,7 +1185,8 @@ bool xe_configfs_get_survivability_mode(struct pci_dev *pdev)if (!dev)return device_defaults.survivability_mode; - mode = dev->config.survivability_mode; +scoped_guard (mutex, &dev->lock) + mode = dev->config.survivability_mode;config_group_put (&dev->group);return mode;
@@ -1199,7 +1200,8 @@ static u64 get_gt_types_allowed(struct pci_dev *pdev)if (!dev)return device_defaults.gt_types_allowed; - mask = dev->config.gt_types_allowed; +scoped_guard (mutex, &dev->lock) + mask = dev->config.gt_types_allowed;config_group_put (&dev->group);return mask;
@@ -1243,7 +1245,8 @@ u64 xe_configfs_get_engines_allowed(struct pci_dev *pdev)if (!dev)return device_defaults.engines_allowed; - engines_allowed = dev->config.engines_allowed; + scoped_guard(mutex, &dev->lock) + engines_allowed = dev->config.engines_allowed;config_group_put (&dev->group);return engines_allowed;
@@ -1263,7 +1266,8 @@ bool xe_configfs_get_psmi_enabled(struct pci_dev *pdev)if (!dev)return false; - ret = dev->config.enable_psmi; +scoped_guard (mutex, &dev->lock) + ret = dev->config.enable_psmi;config_group_put (&dev->group);return ret;
@@ -1284,7 +1288,8 @@ bool xe_configfs_get_enable_multi_queue(struct pci_dev *pdev)if (!dev)return true; - ret = dev->config.enable_multi_queue; +scoped_guard (mutex, &dev->lock) + ret = dev->config.enable_multi_queue;config_group_put (&dev->group);return ret;
@@ -1308,10 +1313,12 @@ u32 xe_configfs_get_ctx_restore_mid_bb(struct pci_dev *pdev,if (!dev)return 0 ; -if (cs) - *cs = dev->config.ctx_restore_mid_bb[class].cs; + scoped_guard(mutex, &dev->lock) { +if (cs) + *cs = dev->config.ctx_restore_mid_bb[class].cs; - len = dev->config.ctx_restore_mid_bb[class].len; + len = dev->config.ctx_restore_mid_bb[class].len; + }config_group_put (&dev->group);return len;
@@ -1335,8 +1342,10 @@ u32 xe_configfs_get_ctx_restore_post_bb(struct pci_dev *pdev,if (!dev)return 0 ; - *cs = dev->config.ctx_restore_post_bb[class].cs; - len = dev->config.ctx_restore_post_bb[class].len; + scoped_guard(mutex, &dev->lock) { + *cs = dev->config.ctx_restore_post_bb[class].cs; + len = dev->config.ctx_restore_post_bb[class].len; + }config_group_put (&dev->group);return len;
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH 01/10] drm/xe: Guard configfs attribute reads in getters
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The getters for ctx_restore batch buffers return pointers to configfs-managed memory (cs), but drop the configfs reference via config_group_put before returning to the caller. This creates a race condition where a concurrent rmdir on the configfs directory can free the device configuration memory before the caller finishes using the pointer, leading to a Use-After-Free. --
--- Patch [1]: [PATCH 01/10] drm/xe: Guard configfs attribute reads in getters --- commit 8e7623fc58ac40897d93827d5632245e67750e49
Author: Stuart Summers <[email protected]>
drm/xe: Guard configfs attribute reads in getters
The commit wraps reads of dev->config in configfs getters with a scoped_guard() to prevent torn reads caused by concurrent stores.
Quoted 4 lines
drivers/gpu/drm/xe/xe_configfs.c +0
-0
[ ... ]
Quoted 6 lines
drivers/gpu/drm/xe/xe_configfs.c +0
-2@@ -1308,10 +1313,12 @@ u32 xe_configfs_get_ctx_restore_mid_bb(struct pci_dev *pdev,if (!dev)return 0 ; -if (cs) - *cs = dev->config.ctx_restore_mid_bb[class].cs;
drivers/gpu/drm/xe/xe_configfs.c u32 xe_configfs_get_ctx_restore_mid_bb(struct pci_dev *pdev, · line 1324
Quoted 10 lines
drivers/gpu/drm/xe/xe_configfs.c +5
-1+ scoped_guard(mutex, &dev->lock) { +if (cs) + *cs = dev->config.ctx_restore_mid_bb[class].cs; - len = dev->config.ctx_restore_mid_bb[class].len; + len = dev->config.ctx_restore_mid_bb[class].len; + }config_group_put (&dev->group);return len;
[Severity: High]
This is a pre-existing issue, but does dropping the configfs reference here allow the memory backing the returned pointer to be freed before the caller finishes using it?
If a concurrent rmdir on the configfs directory drops the group's reference count to 0, xe_config_device_release() could free the cs buffer via kfree(). The caller could then execute a memcpy() using the now-freed pointer, resulting in a use-after-free.
drivers/gpu/drm/xe/xe_configfs.c u32 xe_configfs_get_ctx_restore_post_bb(struct pci_dev *pdev, · line 1351
Quoted 13 lines
drivers/gpu/drm/xe/xe_configfs.c +4
-2@@ -1335,8 +1342,10 @@ u32 xe_configfs_get_ctx_restore_post_bb(struct pci_dev *pdev,if (!dev)return 0 ; - *cs = dev->config.ctx_restore_post_bb[class].cs; - len = dev->config.ctx_restore_post_bb[class].len; + scoped_guard(mutex, &dev->lock) { + *cs = dev->config.ctx_restore_post_bb[class].cs; + len = dev->config.ctx_restore_post_bb[class].len; + }config_group_put (&dev->group);return len;
[Severity: High]
This is also a pre-existing issue, but does the same use-after-free risk apply here in xe_configfs_get_ctx_restore_post_bb()? The memory backing cs could similarly be freed when config_group_put() drops the reference to the configfs group before returning the pointer to the caller.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH 01/10] drm/xe: Guard configfs attribute reads in getters
In reply to Stuart SummersQuoted 8 lines · Stuart Summers
The configfs getters read
dev->configmembers without holdingdev->lock, so a concurrent store can tear the value being returned. The store paths and a few of the getters already take the lock; make it consistent by wrapping every read ofdev->configin the getters with ascoped_guard(), covering the surrounding checks that consume those values as well.Signed-off-by Stuart Summers <[email protected]>Assisted-by Copilot:claude-opus-5
I don't think the locking is terribly important for most of these configfs interfaces, but it certainly doesn't hurt anything and is good for consistency.
Quoted 90 lines
--- drivers/gpu/drm/xe/xe_configfs.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)drivers/gpu/drm/xe/xe_configfs.c +19
-10@@ -1185,7 +1185,8 @@ bool xe_configfs_get_survivability_mode(struct pci_dev *pdev)if (!dev)return device_defaults.survivability_mode; - mode = dev->config.survivability_mode; +scoped_guard (mutex, &dev->lock) + mode = dev->config.survivability_mode;config_group_put (&dev->group);return mode;@@ -1199,7 +1200,8 @@ static u64 get_gt_types_allowed(struct pci_dev *pdev)if (!dev)return device_defaults.gt_types_allowed; - mask = dev->config.gt_types_allowed; +scoped_guard (mutex, &dev->lock) + mask = dev->config.gt_types_allowed;config_group_put (&dev->group);return mask;@@ -1243,7 +1245,8 @@ u64 xe_configfs_get_engines_allowed(struct pci_dev *pdev)if (!dev)return device_defaults.engines_allowed; - engines_allowed = dev->config.engines_allowed; + scoped_guard(mutex, &dev->lock) + engines_allowed = dev->config.engines_allowed;config_group_put (&dev->group);return engines_allowed;@@ -1263,7 +1266,8 @@ bool xe_configfs_get_psmi_enabled(struct pci_dev *pdev)if (!dev)return false; - ret = dev->config.enable_psmi; +scoped_guard (mutex, &dev->lock) + ret = dev->config.enable_psmi;config_group_put (&dev->group);return ret;@@ -1284,7 +1288,8 @@ bool xe_configfs_get_enable_multi_queue(struct pci_dev *pdev)if (!dev)return true; - ret = dev->config.enable_multi_queue; +scoped_guard (mutex, &dev->lock) + ret = dev->config.enable_multi_queue;config_group_put (&dev->group);return ret;@@ -1308,10 +1313,12 @@ u32 xe_configfs_get_ctx_restore_mid_bb(struct pci_dev *pdev,if (!dev)return 0 ; -if (cs) - *cs = dev->config.ctx_restore_mid_bb[class].cs; + scoped_guard(mutex, &dev->lock) { +if (cs) + *cs = dev->config.ctx_restore_mid_bb[class].cs; - len = dev->config.ctx_restore_mid_bb[class].len; + len = dev->config.ctx_restore_mid_bb[class].len; + }config_group_put (&dev->group);return len;@@ -1335,8 +1342,10 @@ u32 xe_configfs_get_ctx_restore_post_bb(struct pci_dev *pdev,if (!dev)return 0 ; - *cs = dev->config.ctx_restore_post_bb[class].cs; - len = dev->config.ctx_restore_post_bb[class].len; + scoped_guard(mutex, &dev->lock) { + *cs = dev->config.ctx_restore_post_bb[class].cs; + len = dev->config.ctx_restore_post_bb[class].len; + }config_group_put (&dev->group);return len;Signature · 1 line
2.43.0
Signature · 4 lines
Matt Roper Graphics Software Engineer Linux GPU Platform Enablement Intel Corporation
Re: [PATCH 01/10] drm/xe: Guard configfs attribute reads in getters
Quoted 14 lines · Matt Roper
Quoted 10 lines · Stuart Summers
The configfs getters read
dev->configmembers without holding dev-Quoted 1 line
lock,
so a concurrent store can tear the value being returned. The store paths
and a few of the getters already take the lock; make it consistent by
wrapping every read ofdev->configin the getters with ascoped_guard(),
covering the surrounding checks that consume those values as well.Quoted 2 lines
Signed-off-by Stuart Summers <[email protected]>Assisted-by Copilot:claude-opus-5
Quoted 6 lines
I don't think the locking is terribly important for most of these configfs interfaces, but it certainly doesn't hurt anything and is good
for consistency.Reviewed-by Matt Roper <[email protected]>
Thanks for the review!
-Stuart
Quoted 102 lines
Quoted 101 lines
---
drivers/gpu/drm/xe/xe_configfs.c | 29 +++++++++++++++++++--------- -1 file changed, 19 insertions(+), 10 deletions(-)drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1185,7 +1185,8 @@ bool xe_configfs_get_survivability_mode(struct pci_dev *pdev) if (!dev) return device_defaults.survivability_mode;
- mode =dev->config.survivability_mode; + scoped_guard(mutex,&dev->lock)
+ mode =dev->config.survivability_mode;config_group_put(&dev->group);
return mode;drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1199,7 +1200,8 @@ static u64 get_gt_types_allowed(struct pci_dev *pdev) if (!dev) return device_defaults.gt_types_allowed;
- mask =dev->config.gt_types_allowed; + scoped_guard(mutex,&dev->lock)
+ mask =dev->config.gt_types_allowed;config_group_put(&dev->group);
return mask;drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1243,7 +1245,8 @@ u64 xe_configfs_get_engines_allowed(struct pci_dev *pdev) if (!dev) return device_defaults.engines_allowed;
- engines_allowed =dev->config.engines_allowed; + scoped_guard(mutex,&dev->lock)
+ engines_allowed =dev->config.engines_allowed;config_group_put(&dev->group);
returnengines_allowed;drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1263,7 +1266,8 @@ bool xe_configfs_get_psmi_enabled(struct pci_dev *pdev) if (!dev) return false;
- ret =dev->config.enable_psmi;
+ scoped_guard(mutex,&dev->lock)
+ ret =dev->config.enable_psmi;
config_group_put(&dev->group);
return ret;drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1284,7 +1288,8 @@ bool xe_configfs_get_enable_multi_queue(struct pci_dev *pdev) if (!dev) return true;
- ret =dev->config.enable_multi_queue; + scoped_guard(mutex,&dev->lock)
+ ret =dev->config.enable_multi_queue;config_group_put(&dev->group);
return ret;drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1308,10 +1313,12 @@ u32 xe_configfs_get_ctx_restore_mid_bb(struct pci_dev *pdev, if (!dev) return 0;
- if (cs)
- *cs = dev->config.ctx_restore_mid_bb[class].cs; + scoped_guard(mutex,&dev->lock) {
+ if (cs)
+ *cs = dev-Quoted 1 line
config.ctx_restore_mid_bb[class].cs;
- len = dev->config.ctx_restore_mid_bb[class].len; + len = dev->config.ctx_restore_mid_bb[class].len; + }
config_group_put(&dev->group);
return len;drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1335,8 +1342,10 @@ u32 xe_configfs_get_ctx_restore_post_bb(struct pci_dev *pdev, if (!dev) return 0;
- *cs = dev->config.ctx_restore_post_bb[class].cs; - len = dev->config.ctx_restore_post_bb[class].len; + scoped_guard(mutex,&dev->lock) {
+ *cs = dev->config.ctx_restore_post_bb[class].cs; + len = dev->config.ctx_restore_post_bb[class].len; + }
config_group_put(&dev->group);
return len;Signature · 1 line
2.43.0
PATCH 2/10 drm/xe: Sort xe_config_device fields
In reply to Stuart SummersAs we're planning more configfs entries over time, let's add some sorting rules to make sure this stays clean and easy to manage. Sorting first by type and then name for readability.
--- drivers/gpu/drm/xe/xe_configfs.c | 1092 +++++++++++++++--------------- drivers/gpu/drm/xe/xe_configfs.h | 24 +- 2 files changed, 564 insertions(+), 552 deletions(-)
drivers/gpu/drm/xe/xe_configfs.c +552 -540
@@ -58,10 +58,11 @@* │ └── ... * : * └── 0000:03:00.0 -* ├── survivability_mode -* ├── gt_types_allowed * ├── engines_allowed -* └── enable_psmi +* ├── gt_types_allowed +* ├── enable_multi_queue +* ├── enable_psmi +* └── survivability_mode * * After configuring the attributes as per next section, the device can be * probed with::
@@ -73,13 +74,82 @@* Configure Attributes * ==================== * -* Survivability mode: -* ------------------- + +* Context restore BB +* ------------------ * -* Enable survivability mode on supported cards. This setting only takes -* effect when probing the device. Example to enable it:: +* Allow to execute a batch buffer during any context switches. When the +* GPU is restoring the context, it executes additional commands. It's useful +* for testing additional workarounds and validating certain HW behaviors: it's +* not intended for normal execution and will taint the kernel with TAINT_TEST +* when used. * -* # echo 1 > /sys/kernel/config/xe/0000:03:00.0/survivability_mode +* The syntax allows to pass straight instructions to be executed by the engine +* in a batch buffer or set specific registers. +* +* #. Generic instruction:: +* +* <engine-class> cmd <instr> [[dword0] [dword1] [...]] +* +* #. Simple register setting:: +* +* <engine-class> reg <address> <value> +* +* Commands are saved per engine class: all instances of that class will execute +* those commands during context switch. The instruction, dword arguments, +* addresses and values are in hex format like in the examples below. +* +* #. Execute a LRI command to write 0xDEADBEEF to register 0x4f10 after the +* normal context restore:: +* +* # echo 'rcs cmd 11000001 4F100 DEADBEEF' \ +* > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_post_bb +* +* #. Execute a LRI command to write 0xDEADBEEF to register 0x4f10 at the +* beginning of the context restore:: +* +* # echo 'rcs cmd 11000001 4F100 DEADBEEF' \ +* > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_mid_bb + +* #. Load certain values in a couple of registers (it can be used as a simpler +* alternative to the `cmd`) action:: +* +* # cat > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_post_bb <<EOF +* rcs reg 4F100 DEADBEEF +* rcs reg 4F104 FFFFFFFF +* EOF +* +* .. note:: +* +* When using multiple lines, make sure to use a command that is +* implemented with a single write syscall, like HEREDOC. +* +* Currently this is implemented only for post and mid context restore and +* these attributes can only be set before binding to the device. +* +* Allowed engines: +* ---------------- +* +* Allow only a set of engine(s) to be available, disabling the other engines +* even if they are available in hardware. This is applied after HW fuses are +* considered on each tile. Examples: +* +* Allow only one render and one copy engines, nothing else:: +* +* # echo 'rcs0,bcs0' > /sys/kernel/config/xe/0000:03:00.0/engines_allowed +* +* Allow only compute engines and first copy engine:: +* +* # echo 'ccs*,bcs0' > /sys/kernel/config/xe/0000:03:00.0/engines_allowed +* +* Note that the engine names are the per-GT hardware names. On multi-tile +* platforms, writing ``rcs0,bcs0`` to this file would allow the first render +* and copy engines on each tile. +* +* The requested configuration may not be supported by the platform and driver +* may fail to probe. For example: if at least one copy engine is expected to be +* available for migrations, but it's disabled. This is intended for debugging +* purposes only. * * This attribute can only be set before binding to the device. *
@@ -121,29 +191,15 @@* * # echo '' > /sys/kernel/config/xe/0000:03:00.0/gt_types_allowed * -* Allowed engines: -* ---------------- -* -* Allow only a set of engine(s) to be available, disabling the other engines -* even if they are available in hardware. This is applied after HW fuses are -* considered on each tile. Examples: -* -* Allow only one render and one copy engines, nothing else:: -* -* # echo 'rcs0,bcs0' > /sys/kernel/config/xe/0000:03:00.0/engines_allowed -* -* Allow only compute engines and first copy engine:: -* -* # echo 'ccs*,bcs0' > /sys/kernel/config/xe/0000:03:00.0/engines_allowed +* Enable multi-queue +* ------------------ * -* Note that the engine names are the per-GT hardware names. On multi-tile -* platforms, writing ``rcs0,bcs0`` to this file would allow the first render -* and copy engines on each tile. +* Multi-queue support on the device is enabled by default where the +* hardware supports it. Writing 0 force-disables multi-queue support: +* multi-queue exec-queue group creation via ioctl is refused, and the +* GuC feature is disabled:: * -* The requested configuration may not be supported by the platform and driver -* may fail to probe. For example: if at least one copy engine is expected to be -* available for migrations, but it's disabled. This is intended for debugging -* purposes only. +* # echo 0 > /sys/kernel/config/xe/0000:03:00.0/enable_multi_queue * * This attribute can only be set before binding to the device. *
@@ -159,57 +215,15 @@* * This attribute can only be set before binding to the device. * -* Context restore BB -* ------------------ -* -* Allow to execute a batch buffer during any context switches. When the -* GPU is restoring the context, it executes additional commands. It's useful -* for testing additional workarounds and validating certain HW behaviors: it's -* not intended for normal execution and will taint the kernel with TAINT_TEST -* when used. -* -* The syntax allows to pass straight instructions to be executed by the engine -* in a batch buffer or set specific registers. -* -* #. Generic instruction:: -* -* <engine-class> cmd <instr> [[dword0] [dword1] [...]] -* -* #. Simple register setting:: -* -* <engine-class> reg <address> <value> -* -* Commands are saved per engine class: all instances of that class will execute -* those commands during context switch. The instruction, dword arguments, -* addresses and values are in hex format like in the examples below. -* -* #. Execute a LRI command to write 0xDEADBEEF to register 0x4f10 after the -* normal context restore:: -* -* # echo 'rcs cmd 11000001 4F100 DEADBEEF' \ -* > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_post_bb -* -* #. Execute a LRI command to write 0xDEADBEEF to register 0x4f10 at the -* beginning of the context restore:: -* -* # echo 'rcs cmd 11000001 4F100 DEADBEEF' \ -* > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_mid_bb - -* #. Load certain values in a couple of registers (it can be used as a simpler -* alternative to the `cmd`) action:: -* -* # cat > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_post_bb <<EOF -* rcs reg 4F100 DEADBEEF -* rcs reg 4F104 FFFFFFFF -* EOF +* Survivability mode: +* ------------------- * -* .. note:: +* Enable survivability mode on supported cards. This setting only takes +* effect when probing the device. Example to enable it:: * -* When using multiple lines, make sure to use a command that is -* implemented with a single write syscall, like HEREDOC. +* # echo 1 > /sys/kernel/config/xe/0000:03:00.0/survivability_mode * -* Currently this is implemented only for post and mid context restore and -* these attributes can only be set before binding to the device. +* This attribute can only be set before binding to the device. * * Max SR-IOV Virtual Functions * ----------------------------
@@ -237,18 +251,6 @@* * This setting only takes effect when probing the device. * -* Enable multi-queue -* ------------------ -* -* Multi-queue support on the device is enabled by default where the -* hardware supports it. Writing 0 force-disables multi-queue support: -* multi-queue exec-queue group creation via ioctl is refused, and the -* GuC feature is disabled:: -* -* # echo 0 > /sys/kernel/config/xe/0000:03:00.0/enable_multi_queue -* -* This attribute can only be set before binding to the device. -* * Remove devices * ============== *
@@ -267,14 +269,19 @@ struct xe_config_group_device {struct config_group group;struct config_group sriov; +/* +* Fields sorted by type (largest first) then name: struct arrays, +* u64, u32/unsigned int, u8, bool, sub-structs last. Within each +* type, entries are sorted alphabetically. +*/ struct xe_config_device { -u64 gt_types_allowed; -u64 engines_allowed; -struct wa_bb ctx_restore_post_bb[XE_ENGINE_CLASS_MAX ];struct wa_bb ctx_restore_mid_bb[XE_ENGINE_CLASS_MAX ]; -bool survivability_mode; -bool enable_psmi; +struct wa_bb ctx_restore_post_bb[XE_ENGINE_CLASS_MAX ]; +u64 engines_allowed; +u64 gt_types_allowed;bool enable_multi_queue; +bool enable_psmi; +bool survivability_mode;struct {unsigned int max_vfs;bool admin_only_pf;
@@ -290,11 +297,11 @@ struct xe_config_group_device { };static const struct xe_config_device device_defaults = { - .gt_types_allowed =U64_MAX , .engines_allowed =U64_MAX , - .survivability_mode = false, - .enable_psmi = false, + .gt_types_allowed =U64_MAX , .enable_multi_queue = true, + .enable_psmi = false, + .survivability_mode = false, .sriov = { .max_vfs =XE_DEFAULT_MAX_VFS , .admin_only_pf =XE_DEFAULT_ADMIN_ONLY_PF ,
@@ -371,247 +378,60 @@ static bool is_bound(struct xe_config_group_device *dev)return ret; } -static ssize_t survivability_mode_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); - -return sprintf (page,"%d\n" , dev->survivability_mode); -} +static struct xe_config_group_device *find_xe_config_group_device (struct pci_dev *pdev); -static ssize_t survivability_mode_store (struct config_item *item,const char *page,size_t len) +/** +* xe_configfs_get_ctx_restore_mid_bb - get configfs ctx_restore_mid_bb setting +* @pdev: pci device +* @class: hw engine class +* @cs: pointer to the bb to use - only valid during probe +* +* Return: Number of dwords used in the mid_ctx_restore setting in configfs +*/ +u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, +enum xe_engine_class class, +const u32 **cs) { -struct xe_config_group_device *dev =to_xe_config_group_device (item); -bool survivability_mode; -int ret; +struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +u32 len; - ret =kstrtobool (page, &survivability_mode); -if (ret) -return ret; +if (!dev) +return 0 ; -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; + scoped_guard(mutex, &dev->lock) { +if (cs) + *cs = dev->config.ctx_restore_mid_bb[class].cs; - dev->config.survivability_mode = survivability_mode; + len = dev->config.ctx_restore_mid_bb[class].len; + } +config_group_put (&dev->group);return len; } -static ssize_t gt_types_allowed_show (struct config_item *item,char *page) +/** +* xe_configfs_get_ctx_restore_post_bb - get configfs ctx_restore_post_bb setting +* @pdev: pci device +* @class: hw engine class +* @cs: pointer to the bb to use - only valid during probe +* +* Return: Number of dwords used in the post_ctx_restore setting in configfs +*/ +u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, +enum xe_engine_class class, +const u32 **cs) { -struct xe_config_device *dev =to_xe_config_device (item); -char *p = page; - -for (size_t i =0 ; i <ARRAY_SIZE (gt_types); i++) -if (dev->gt_types_allowed &BIT_ULL (gt_types[i].type)) - p +=sprintf (p,"%s\n" , gt_types[i].name); +struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +u32 len; -return p - page; -} +if (!dev) +return 0 ; -static ssize_t gt_types_allowed_store (struct config_item *item,const char *page, -size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); - char *buf __free(kfree) = kstrdup(page, GFP_KERNEL); -char *p = buf; -u64 typemask =0 ; - -if (!buf) -return -ENOMEM ; - -while (p) { -char *typename =strsep (&p,",\n" ); -bool matched = false; - -if (typename[0 ] =='\0' ) -continue ; - -for (size_t i =0 ; i <ARRAY_SIZE (gt_types); i++) { -if (strcmp (typename, gt_types[i].name) ==0 ) { - typemask |=BIT (gt_types[i].type); - matched = true; -break ; - } - } - -if (!matched) -return -EINVAL ; - } - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.gt_types_allowed = typemask; - -return len; -} - -static ssize_t engines_allowed_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); -char *p = page; - -for (size_t i =0 ; i <ARRAY_SIZE (engine_info); i++) { -u64 mask = engine_info[i].mask; - -if ((dev->engines_allowed & mask) == mask) { - p +=sprintf (p,"%s*\n" , engine_info[i].cls); - }else if (mask & dev->engines_allowed) { -u16 bit0 =__ffs64 (mask), bit; - - mask &= dev->engines_allowed; - -for_each_set_bit (bit, (const unsigned long *)&mask,64 ) - p +=sprintf (p,"%s%u\n" , engine_info[i].cls, - bit - bit0); - } - } - -return p - page; -} - -/* -* Lookup engine_info. If @mask is not NULL, reduce the mask according to the -* instance in @pattern. -* -* Examples of inputs: -* - lookup_engine_info("rcs0", &mask): return "rcs" entry from @engine_info and -* mask == BIT_ULL(XE_HW_ENGINE_RCS0) -* - lookup_engine_info("rcs*", &mask): return "rcs" entry from @engine_info and -* mask == XE_HW_ENGINE_RCS_MASK -* - lookup_engine_info("rcs", NULL): return "rcs" entry from @engine_info -*/ -static const struct engine_info *lookup_engine_info (const char *pattern,u64 *mask) -{ -for (size_t i =0 ; i <ARRAY_SIZE (engine_info); i++) { -u8 instance; -u16 bit; - -if (!str_has_prefix (pattern, engine_info[i].cls)) -continue ; - - pattern +=strlen (engine_info[i].cls); -if (!mask) -return *pattern ?NULL : &engine_info[i]; - -if (!strcmp (pattern,"*" )) { - *mask = engine_info[i].mask; -return &engine_info[i]; - } - -if (kstrtou8 (pattern,10 , &instance)) -return NULL ; - - bit =__ffs64 (engine_info[i].mask) + instance; -if (bit >=fls64 (engine_info[i].mask)) -return NULL ; - - *mask =BIT_ULL (bit); -return &engine_info[i]; - } - -return NULL ; -} - -static int parse_engine (const char *s,const char *end_chars,u64 *mask, -const struct engine_info **pinfo) -{ -char buf[MAX_ENGINE_CLASS_CHARS +MAX_ENGINE_INSTANCE_CHARS +1 ]; -const struct engine_info *info; -size_t len; - - len =strcspn (s, end_chars); -if (len >=sizeof (buf)) -return -EINVAL ; - -memcpy (buf, s, len); - buf[len] ='\0' ; - - info =lookup_engine_info (buf, mask); -if (!info) -return -ENOENT ; - -if (pinfo) - *pinfo = info; - -return len; -} - -static ssize_t engines_allowed_store (struct config_item *item,const char *page, -size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); -ssize_t patternlen, p; -u64 mask, val =0 ; - -for (p =0 ; p < len; p += patternlen +1 ) { - patternlen =parse_engine (page + p,",\n" , &mask,NULL ); -if (patternlen <0 ) -return -EINVAL ; - - val |= mask; + scoped_guard(mutex, &dev->lock) { + *cs = dev->config.ctx_restore_post_bb[class].cs; + len = dev->config.ctx_restore_post_bb[class].len; } - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.engines_allowed = val; - -return len; -} - -static ssize_t enable_psmi_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); - -return sprintf (page,"%d\n" , dev->enable_psmi); -} - -static ssize_t enable_psmi_store (struct config_item *item,const char *page,size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); -bool val; -int ret; - - ret =kstrtobool (page, &val); -if (ret) -return ret; - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.enable_psmi = val; - -return len; -} - -static ssize_t enable_multi_queue_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); - -return sprintf (page,"%d\n" , dev->enable_multi_queue); -} - -static ssize_t enable_multi_queue_store (struct config_item *item,const char *page, -size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); -bool val; -int ret; - - ret =kstrtobool (page, &val); -if (ret) -return ret; - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.enable_multi_queue = val; +config_group_put (&dev->group);return len; }
@@ -718,6 +538,9 @@ static ssize_t parse_hex(const char *line, u32 *pval)return p - line; } +static int parse_engine (const char *s,const char *end_chars,u64 *mask, +const struct engine_info **pinfo); +/* * Parse lines with the format *
@@ -802,70 +625,439 @@ static ssize_t wa_bb_store(struct wa_bb wa_bb[static XE_ENGINE_CLASS_MAX],return count;guard (mutex)(&dev->lock); - + +if (is_bound (dev)) +return -EBUSY ; + +/* +* 2. Allocate a u32 array and set the pointers to the right positions +* according to the length of each class' wa_bb +*/ + tmp =krealloc (wa_bb[0 ].cs, count *sizeof (u32),GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + +if (!count) { +memset (wa_bb,0 ,sizeof (tmp_wa_bb)); +return len; + } + +for (class =0 , count =0 ; class <XE_ENGINE_CLASS_MAX ; ++class) { + tmp_wa_bb[class].cs = tmp + count; + count += tmp_wa_bb[class].len; + tmp_wa_bb[class].len =0 ; + } + +/* 3. Parse wa_bb lines again, this time saving the values */ + count =parse_wa_bb_lines (page, tmp_wa_bb); +if (count <0 ) +return count; + +memcpy (wa_bb, tmp_wa_bb,sizeof (tmp_wa_bb)); + +return len; +} + +static ssize_t ctx_restore_mid_bb_store (struct config_item *item, +const char *data,size_t sz) +{ +struct xe_config_group_device *dev =to_xe_config_group_device (item); + +return wa_bb_store (dev->config.ctx_restore_mid_bb, dev, data, sz); +} + +static ssize_t ctx_restore_post_bb_store (struct config_item *item, +const char *data,size_t sz) +{ +struct xe_config_group_device *dev =to_xe_config_group_device (item); + +return wa_bb_store (dev->config.ctx_restore_post_bb, dev, data, sz); +} + +/** +* xe_configfs_get_engines_allowed - get engine allowed mask from configfs +* @pdev: pci device +* +* Return: engine mask with allowed engines set in configfs +*/ +u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) +{ +struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +u64 engines_allowed; + +if (!dev) +return device_defaults.engines_allowed; + + scoped_guard(mutex, &dev->lock) + engines_allowed = dev->config.engines_allowed; +config_group_put (&dev->group); + +return engines_allowed; +} + +static ssize_t engines_allowed_show (struct config_item *item,char *page) +{ +struct xe_config_device *dev =to_xe_config_device (item); +char *p = page; + +for (size_t i =0 ; i <ARRAY_SIZE (engine_info); i++) { +u64 mask = engine_info[i].mask; + +if ((dev->engines_allowed & mask) == mask) { + p +=sprintf (p,"%s*\n" , engine_info[i].cls); + }else if (mask & dev->engines_allowed) { +u16 bit0 =__ffs64 (mask), bit; + + mask &= dev->engines_allowed; + +for_each_set_bit (bit, (const unsigned long *)&mask,64 ) + p +=sprintf (p,"%s%u\n" , engine_info[i].cls, + bit - bit0); + } + } + +return p - page; +} + +/* +* Lookup engine_info. If @mask is not NULL, reduce the mask according to the +* instance in @pattern. +* +* Examples of inputs: +* - lookup_engine_info("rcs0", &mask): return "rcs" entry from @engine_info and +* mask == BIT_ULL(XE_HW_ENGINE_RCS0) +* - lookup_engine_info("rcs*", &mask): return "rcs" entry from @engine_info and +* mask == XE_HW_ENGINE_RCS_MASK +* - lookup_engine_info("rcs", NULL): return "rcs" entry from @engine_info +*/ +static const struct engine_info *lookup_engine_info (const char *pattern,u64 *mask) +{ +for (size_t i =0 ; i <ARRAY_SIZE (engine_info); i++) { +u8 instance; +u16 bit; + +if (!str_has_prefix (pattern, engine_info[i].cls)) +continue ; + + pattern +=strlen (engine_info[i].cls); +if (!mask) +return *pattern ?NULL : &engine_info[i]; + +if (!strcmp (pattern,"*" )) { + *mask = engine_info[i].mask; +return &engine_info[i]; + } + +if (kstrtou8 (pattern,10 , &instance)) +return NULL ; + + bit =__ffs64 (engine_info[i].mask) + instance; +if (bit >=fls64 (engine_info[i].mask)) +return NULL ; + + *mask =BIT_ULL (bit); +return &engine_info[i]; + } + +return NULL ; +} + +static int parse_engine (const char *s,const char *end_chars,u64 *mask, +const struct engine_info **pinfo) +{ +char buf[MAX_ENGINE_CLASS_CHARS +MAX_ENGINE_INSTANCE_CHARS +1 ]; +const struct engine_info *info; +size_t len; + + len =strcspn (s, end_chars); +if (len >=sizeof (buf)) +return -EINVAL ; + +memcpy (buf, s, len); + buf[len] ='\0' ; + + info =lookup_engine_info (buf, mask); +if (!info) +return -ENOENT ; + +if (pinfo) + *pinfo = info; + +return len; +} + +static ssize_t engines_allowed_store (struct config_item *item,const char *page, +size_t len) +{ +struct xe_config_group_device *dev =to_xe_config_group_device (item); +ssize_t patternlen, p; +u64 mask, val =0 ; + +for (p =0 ; p < len; p += patternlen +1 ) { + patternlen =parse_engine (page + p,",\n" , &mask,NULL ); +if (patternlen <0 ) +return -EINVAL ; + + val |= mask; + } + +guard (mutex)(&dev->lock); +if (is_bound (dev)) +return -EBUSY ; + + dev->config.engines_allowed = val; + +return len; +} + +static u64 get_gt_types_allowed (struct pci_dev *pdev) +{ +struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +u64 mask; + +if (!dev) +return device_defaults.gt_types_allowed; + +scoped_guard (mutex, &dev->lock) + mask = dev->config.gt_types_allowed; +config_group_put (&dev->group); + +return mask; +} + +/** +* xe_configfs_primary_gt_allowed - determine whether primary GTs are supported +* @pdev: pci device +* +* Return: True if primary GTs are enabled, false if they have been disabled via +* configfs. +*/ +bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) +{ +return get_gt_types_allowed (pdev) &BIT_ULL (XE_GT_TYPE_MAIN ); +} + +/** +* xe_configfs_media_gt_allowed - determine whether media GTs are supported +* @pdev: pci device +* +* Return: True if the media GTs are enabled, false if they have been disabled +* via configfs. +*/ +bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) +{ +return get_gt_types_allowed (pdev) &BIT_ULL (XE_GT_TYPE_MEDIA ); +} + +static ssize_t gt_types_allowed_show (struct config_item *item,char *page) +{ +struct xe_config_device *dev =to_xe_config_device (item); +char *p = page; + +for (size_t i =0 ; i <ARRAY_SIZE (gt_types); i++) +if (dev->gt_types_allowed &BIT_ULL (gt_types[i].type)) + p +=sprintf (p,"%s\n" , gt_types[i].name); + +return p - page; +} + +static ssize_t gt_types_allowed_store (struct config_item *item,const char *page, +size_t len) +{ +struct xe_config_group_device *dev =to_xe_config_group_device (item); + char *buf __free(kfree) = kstrdup(page, GFP_KERNEL); +char *p = buf; +u64 typemask =0 ; + +if (!buf) +return -ENOMEM ; + +while (p) { +char *typename =strsep (&p,",\n" ); +bool matched = false; + +if (typename[0 ] =='\0' ) +continue ; + +for (size_t i =0 ; i <ARRAY_SIZE (gt_types); i++) { +if (strcmp (typename, gt_types[i].name) ==0 ) { + typemask |=BIT (gt_types[i].type); + matched = true; +break ; + } + } + +if (!matched) +return -EINVAL ; + } + +guard (mutex)(&dev->lock); +if (is_bound (dev)) +return -EBUSY ; + + dev->config.gt_types_allowed = typemask; + +return len; +} + +/** +* xe_configfs_get_enable_multi_queue - get configfs enable_multi_queue setting +* @pdev: pci device +* +* Return: true if multi-queue is enabled for this device (the default), +* false if it has been force-disabled via configfs. +*/ +bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) +{ +struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +bool ret; + +if (!dev) +return true; + +scoped_guard (mutex, &dev->lock) + ret = dev->config.enable_multi_queue; +config_group_put (&dev->group); + +return ret; +} + +static ssize_t enable_multi_queue_show (struct config_item *item,char *page) +{ +struct xe_config_device *dev =to_xe_config_device (item); + +return sprintf (page,"%d\n" , dev->enable_multi_queue); +} + +static ssize_t enable_multi_queue_store (struct config_item *item,const char *page, +size_t len) +{ +struct xe_config_group_device *dev =to_xe_config_group_device (item); +bool val; +int ret; + + ret =kstrtobool (page, &val); +if (ret) +return ret; + +guard (mutex)(&dev->lock); +if (is_bound (dev)) +return -EBUSY ; + + dev->config.enable_multi_queue = val; + +return len; +} + +/** +* xe_configfs_get_psmi_enabled - get configfs enable_psmi setting +* @pdev: pci device +* +* Return: enable_psmi setting in configfs +*/ +bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) +{ +struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +bool ret; + +if (!dev) +return false; + +scoped_guard (mutex, &dev->lock) + ret = dev->config.enable_psmi; +config_group_put (&dev->group); + +return ret; +} + +static ssize_t enable_psmi_show (struct config_item *item,char *page) +{ +struct xe_config_device *dev =to_xe_config_device (item); + +return sprintf (page,"%d\n" , dev->enable_psmi); +} + +static ssize_t enable_psmi_store (struct config_item *item,const char *page,size_t len) +{ +struct xe_config_group_device *dev =to_xe_config_group_device (item); +bool val; +int ret; + + ret =kstrtobool (page, &val); +if (ret) +return ret; + +guard (mutex)(&dev->lock);if (is_bound (dev))return -EBUSY ; -/* -* 2. Allocate a u32 array and set the pointers to the right positions -* according to the length of each class' wa_bb -*/ - tmp =krealloc (wa_bb[0 ].cs, count *sizeof (u32),GFP_KERNEL ); -if (!tmp) -return -ENOMEM ; + dev->config.enable_psmi = val; -if (!count) { -memset (wa_bb,0 ,sizeof (tmp_wa_bb)); -return len; - } +return len; +} -for (class =0 , count =0 ; class <XE_ENGINE_CLASS_MAX ; ++class) { - tmp_wa_bb[class].cs = tmp + count; - count += tmp_wa_bb[class].len; - tmp_wa_bb[class].len =0 ; - } +/** +* xe_configfs_get_survivability_mode - get configfs survivability mode attribute +* @pdev: pci device +* +* Return: survivability_mode attribute in configfs +*/ +bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) +{ +struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +bool mode; -/* 3. Parse wa_bb lines again, this time saving the values */ - count =parse_wa_bb_lines (page, tmp_wa_bb); -if (count <0 ) -return count; +if (!dev) +return device_defaults.survivability_mode; -memcpy (wa_bb, tmp_wa_bb,sizeof (tmp_wa_bb)); +scoped_guard (mutex, &dev->lock) + mode = dev->config.survivability_mode; +config_group_put (&dev->group); -return len; +return mode; } -static ssize_t ctx_restore_mid_bb_store (struct config_item *item, -const char *data,size_t sz) +static ssize_t survivability_mode_show (struct config_item *item,char *page) { -struct xe_config_group_device *dev =to_xe_config_group_device (item); +struct xe_config_device *dev =to_xe_config_device (item); -return wa_bb_store (dev->config.ctx_restore_mid_bb, dev, data, sz); +return sprintf (page,"%d\n" , dev->survivability_mode); } -static ssize_t ctx_restore_post_bb_store (struct config_item *item, -const char *data,size_t sz) +static ssize_t survivability_mode_store (struct config_item *item,const char *page,size_t len) {struct xe_config_group_device *dev =to_xe_config_group_device (item); +bool survivability_mode; +int ret; -return wa_bb_store (dev->config.ctx_restore_post_bb, dev, data, sz); + ret =kstrtobool (page, &survivability_mode); +if (ret) +return ret; + +guard (mutex)(&dev->lock); +if (is_bound (dev)) +return -EBUSY ; + + dev->config.survivability_mode = survivability_mode; + +return len; } CONFIGFS_ATTR(, ctx_restore_mid_bb); CONFIGFS_ATTR(, ctx_restore_post_bb); -CONFIGFS_ATTR(, enable_multi_queue); -CONFIGFS_ATTR(, enable_psmi); CONFIGFS_ATTR(, engines_allowed); CONFIGFS_ATTR(, gt_types_allowed); +CONFIGFS_ATTR(, enable_multi_queue); +CONFIGFS_ATTR(, enable_psmi); CONFIGFS_ATTR(, survivability_mode);static struct configfs_attribute *xe_config_device_attrs[] = { &attr_ctx_restore_mid_bb, &attr_ctx_restore_post_bb, - &attr_enable_multi_queue, - &attr_enable_psmi, &attr_engines_allowed, &attr_gt_types_allowed, + &attr_enable_multi_queue, + &attr_enable_psmi, &attr_survivability_mode,NULL , };
@@ -1138,8 +1330,8 @@ static void dump_custom_dev_config(struct pci_dev *pdev, dev->config.attr_); \ }while (0 ) -PRI_CUSTOM_ATTR ("%llx" , gt_types_allowed);PRI_CUSTOM_ATTR ("%llx" , engines_allowed); +PRI_CUSTOM_ATTR ("%llx" , gt_types_allowed);PRI_CUSTOM_ATTR ("%d" , enable_multi_queue);PRI_CUSTOM_ATTR ("%d" , enable_psmi);PRI_CUSTOM_ATTR ("%d" , survivability_mode);
@@ -1171,186 +1363,6 @@ void xe_configfs_check_device(struct pci_dev *pdev)config_group_put (&dev->group); } -/** -* xe_configfs_get_survivability_mode - get configfs survivability mode attribute -* @pdev: pci device -* -* Return: survivability_mode attribute in configfs -*/ -bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -bool mode; - -if (!dev) -return device_defaults.survivability_mode; - -scoped_guard (mutex, &dev->lock) - mode = dev->config.survivability_mode; -config_group_put (&dev->group); - -return mode; -} - -static u64 get_gt_types_allowed (struct pci_dev *pdev) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -u64 mask; - -if (!dev) -return device_defaults.gt_types_allowed; - -scoped_guard (mutex, &dev->lock) - mask = dev->config.gt_types_allowed; -config_group_put (&dev->group); - -return mask; -} - -/** -* xe_configfs_primary_gt_allowed - determine whether primary GTs are supported -* @pdev: pci device -* -* Return: True if primary GTs are enabled, false if they have been disabled via -* configfs. -*/ -bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) -{ -return get_gt_types_allowed (pdev) &BIT_ULL (XE_GT_TYPE_MAIN ); -} - -/** -* xe_configfs_media_gt_allowed - determine whether media GTs are supported -* @pdev: pci device -* -* Return: True if the media GTs are enabled, false if they have been disabled -* via configfs. -*/ -bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) -{ -return get_gt_types_allowed (pdev) &BIT_ULL (XE_GT_TYPE_MEDIA ); -} - -/** -* xe_configfs_get_engines_allowed - get engine allowed mask from configfs -* @pdev: pci device -* -* Return: engine mask with allowed engines set in configfs -*/ -u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -u64 engines_allowed; - -if (!dev) -return device_defaults.engines_allowed; - - scoped_guard(mutex, &dev->lock) - engines_allowed = dev->config.engines_allowed; -config_group_put (&dev->group); - -return engines_allowed; -} - -/** -* xe_configfs_get_psmi_enabled - get configfs enable_psmi setting -* @pdev: pci device -* -* Return: enable_psmi setting in configfs -*/ -bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -bool ret; - -if (!dev) -return false; - -scoped_guard (mutex, &dev->lock) - ret = dev->config.enable_psmi; -config_group_put (&dev->group); - -return ret; -} - -/** -* xe_configfs_get_enable_multi_queue - get configfs enable_multi_queue setting -* @pdev: pci device -* -* Return: true if multi-queue is enabled for this device (the default), -* false if it has been force-disabled via configfs. -*/ -bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -bool ret; - -if (!dev) -return true; - -scoped_guard (mutex, &dev->lock) - ret = dev->config.enable_multi_queue; -config_group_put (&dev->group); - -return ret; -} - -/** -* xe_configfs_get_ctx_restore_mid_bb - get configfs ctx_restore_mid_bb setting -* @pdev: pci device -* @class: hw engine class -* @cs: pointer to the bb to use - only valid during probe -* -* Return: Number of dwords used in the mid_ctx_restore setting in configfs -*/ -u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, -enum xe_engine_class class, -const u32 **cs) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -u32 len; - -if (!dev) -return 0 ; - - scoped_guard(mutex, &dev->lock) { -if (cs) - *cs = dev->config.ctx_restore_mid_bb[class].cs; - - len = dev->config.ctx_restore_mid_bb[class].len; - } -config_group_put (&dev->group); - -return len; -} - -/** -* xe_configfs_get_ctx_restore_post_bb - get configfs ctx_restore_post_bb setting -* @pdev: pci device -* @class: hw engine class -* @cs: pointer to the bb to use - only valid during probe -* -* Return: Number of dwords used in the post_ctx_restore setting in configfs -*/ -u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, -enum xe_engine_class class, -const u32 **cs) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -u32 len; - -if (!dev) -return 0 ; - - scoped_guard(mutex, &dev->lock) { - *cs = dev->config.ctx_restore_post_bb[class].cs; - len = dev->config.ctx_restore_post_bb[class].len; - } -config_group_put (&dev->group); - -return len; -} -#ifdef CONFIG_PCI_IOV /** * xe_configfs_admin_only_pf() - Get PF's operational mode.
drivers/gpu/drm/xe/xe_configfs.h +12 -12
@@ -18,18 +18,18 @@ struct pci_dev;int xe_configfs_init (void );void xe_configfs_exit (void );void xe_configfs_check_device (struct pci_dev *pdev); -bool xe_configfs_get_survivability_mode (struct pci_dev *pdev); -bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev); -bool xe_configfs_media_gt_allowed (struct pci_dev *pdev); -u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev); -bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev); -bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev);u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev,enum xe_engine_class class,const u32 **cs);u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev,enum xe_engine_class class,const u32 **cs); +u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev); +bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev); +bool xe_configfs_media_gt_allowed (struct pci_dev *pdev); +bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev); +bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev); +bool xe_configfs_get_survivability_mode (struct pci_dev *pdev);#ifdef CONFIG_PCI_IOV unsigned int xe_configfs_get_max_vfs (struct pci_dev *pdev);bool xe_configfs_admin_only_pf (struct pci_dev *pdev);
@@ -38,18 +38,18 @@ bool xe_configfs_admin_only_pf(struct pci_dev *pdev);static inline int xe_configfs_init (void ) {return 0 ; }static inline void xe_configfs_exit (void ) { }static inline void xe_configfs_check_device (struct pci_dev *pdev) { } -static inline bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) {return false; } -static inline bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) {return true; } -static inline bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) {return true; } -static inline u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) {return U64_MAX ; } -static inline bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) {return false; } -static inline bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) {return true; }static inline u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev,enum xe_engine_class class,const u32 **cs) {return 0 ; }static inline u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev,enum xe_engine_class class,const u32 **cs) {return 0 ; } +static inline u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) {return U64_MAX ; } +static inline bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) {return true; } +static inline bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) {return true; } +static inline bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) {return true; } +static inline bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) {return false; } +static inline bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) {return false; }#ifdef CONFIG_PCI_IOV static inline unsigned int xe_configfs_get_max_vfs (struct pci_dev *pdev) {
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH 02/10] drm/xe: Sort xe_config_device fields
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Use-After-Free due to dangling pointer returned by xe_configfs_get_ctx_restore_mid_bb and post_bb escaping the reference lifetime.
- [High] Out-of-bounds Read in parse_wa_bb_lines when input lacks a trailing newline.
--
--- Patch [2]: [PATCH 02/10] drm/xe: Sort xe_config_device fields --- commit 299f84549303f530b903f33ec9224a2a497c7599
Author: Stuart Summers <[email protected]>
drm/xe: Sort xe_config_device fields
As we're planning more configfs entries over time, let's add some sorting rules to make sure this stays clean and easy to manage. Sorting first by type and then name for readability.
Quoted 4 lines
drivers/gpu/drm/xe/xe_configfs.c +0
-0
[ ... ]
Quoted 258 lines
drivers/gpu/drm/xe/xe_configfs.c +31
-215+u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, +enum xe_engine_class class, +const u32 **cs) { -struct xe_config_group_device *dev =to_xe_config_group_device (item); -bool survivability_mode; -int ret; +struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +u32 len; - ret =kstrtobool (page, &survivability_mode); -if (ret) -return ret; +if (!dev) +return 0 ; -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; + scoped_guard(mutex, &dev->lock) { +if (cs) + *cs = dev->config.ctx_restore_mid_bb[class].cs; - dev->config.survivability_mode = survivability_mode; + len = dev->config.ctx_restore_mid_bb[class].len; + } +config_group_put (&dev->group);return len; } -static ssize_t gt_types_allowed_show (struct config_item *item,char *page) +/** +* xe_configfs_get_ctx_restore_post_bb - get configfs ctx_restore_post_bb setting +* @pdev: pci device +* @class: hw engine class +* @cs: pointer to the bb to use - only valid during probe +* +* Return: Number of dwords used in the post_ctx_restore setting in configfs +*/ +u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, +enum xe_engine_class class, +const u32 **cs) { -struct xe_config_device *dev =to_xe_config_device (item); -char *p = page; - -for (size_t i =0 ; i <ARRAY_SIZE (gt_types); i++) -if (dev->gt_types_allowed &BIT_ULL (gt_types[i].type)) - p +=sprintf (p,"%s\n" , gt_types[i].name); +struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +u32 len; -return p - page; -} +if (!dev) +return 0 ; -static ssize_t gt_types_allowed_store (struct config_item *item,const char *page, -size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); - char *buf __free(kfree) = kstrdup(page, GFP_KERNEL); -char *p = buf; -u64 typemask =0 ; - -if (!buf) -return -ENOMEM ; - -while (p) { -char *typename =strsep (&p,",\n" ); -bool matched = false; - -if (typename[0 ] =='\0' ) -continue ; - -for (size_t i =0 ; i <ARRAY_SIZE (gt_types); i++) { -if (strcmp (typename, gt_types[i].name) ==0 ) { - typemask |=BIT (gt_types[i].type); - matched = true; -break ; - } - } - -if (!matched) -return -EINVAL ; - } - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.gt_types_allowed = typemask; - -return len; -} - -static ssize_t engines_allowed_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); -char *p = page; - -for (size_t i =0 ; i <ARRAY_SIZE (engine_info); i++) { -u64 mask = engine_info[i].mask; - -if ((dev->engines_allowed & mask) == mask) { - p +=sprintf (p,"%s*\n" , engine_info[i].cls); - }else if (mask & dev->engines_allowed) { -u16 bit0 =__ffs64 (mask), bit; - - mask &= dev->engines_allowed; - -for_each_set_bit (bit, (const unsigned long *)&mask,64 ) - p +=sprintf (p,"%s%u\n" , engine_info[i].cls, - bit - bit0); - } - } - -return p - page; -} - -/* -* Lookup engine_info. If @mask is not NULL, reduce the mask according to the -* instance in @pattern. -* -* Examples of inputs: -* - lookup_engine_info("rcs0", &mask): return "rcs" entry from @engine_info and -* mask == BIT_ULL(XE_HW_ENGINE_RCS0) -* - lookup_engine_info("rcs*", &mask): return "rcs" entry from @engine_info and -* mask == XE_HW_ENGINE_RCS_MASK -* - lookup_engine_info("rcs", NULL): return "rcs" entry from @engine_info -*/ -static const struct engine_info *lookup_engine_info (const char *pattern,u64 *mask) -{ -for (size_t i =0 ; i <ARRAY_SIZE (engine_info); i++) { -u8 instance; -u16 bit; - -if (!str_has_prefix (pattern, engine_info[i].cls)) -continue ; - - pattern +=strlen (engine_info[i].cls); -if (!mask) -return *pattern ?NULL : &engine_info[i]; - -if (!strcmp (pattern,"*" )) { - *mask = engine_info[i].mask; -return &engine_info[i]; - } - -if (kstrtou8 (pattern,10 , &instance)) -return NULL ; - - bit =__ffs64 (engine_info[i].mask) + instance; -if (bit >=fls64 (engine_info[i].mask)) -return NULL ; - - *mask =BIT_ULL (bit); -return &engine_info[i]; - } - -return NULL ; -} - -static int parse_engine (const char *s,const char *end_chars,u64 *mask, -const struct engine_info **pinfo) -{ -char buf[MAX_ENGINE_CLASS_CHARS +MAX_ENGINE_INSTANCE_CHARS +1 ]; -const struct engine_info *info; -size_t len; - - len =strcspn (s, end_chars); -if (len >=sizeof (buf)) -return -EINVAL ; - -memcpy (buf, s, len); - buf[len] ='\0' ; - - info =lookup_engine_info (buf, mask); -if (!info) -return -ENOENT ; - -if (pinfo) - *pinfo = info; - -return len; -} - -static ssize_t engines_allowed_store (struct config_item *item,const char *page, -size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); -ssize_t patternlen, p; -u64 mask, val =0 ; - -for (p =0 ; p < len; p += patternlen +1 ) { - patternlen =parse_engine (page + p,",\n" , &mask,NULL ); -if (patternlen <0 ) -return -EINVAL ; - - val |= mask; + scoped_guard(mutex, &dev->lock) { + *cs = dev->config.ctx_restore_post_bb[class].cs; + len = dev->config.ctx_restore_post_bb[class].len; } - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.engines_allowed = val; - -return len; -} - -static ssize_t enable_psmi_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); - -return sprintf (page,"%d\n" , dev->enable_psmi); -} - -static ssize_t enable_psmi_store (struct config_item *item,const char *page,size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); -bool val; -int ret; - - ret =kstrtobool (page, &val); -if (ret) -return ret; - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.enable_psmi = val; - -return len; -} - -static ssize_t enable_multi_queue_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); - -return sprintf (page,"%d\n" , dev->enable_multi_queue); -} - -static ssize_t enable_multi_queue_store (struct config_item *item,const char *page, -size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); -bool val; -int ret; - - ret =kstrtobool (page, &val); -if (ret) -return ret;
drivers/gpu/drm/xe/xe_configfs.c static bool is_bound(struct xe_config_group_device *dev) · line 437
Quoted 10 lines
drivers/gpu/drm/xe/xe_configfs.c +1
-6- -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.enable_multi_queue = val; +config_group_put (&dev->group);return len; }
[Severity: High]
This is a pre-existing issue, but is it safe for xe_configfs_get_ctx_restore_mid_bb and xe_configfs_get_ctx_restore_post_bb to return internal pointers from the configfs context out to the caller while simultaneously dropping the reference with config_group_put()?
Because the pointer is returned directly and the group reference is dropped, the pointer escapes the reference lifetime. If userspace concurrently removes the configfs directory, xe_config_device_release() will free the internal buffer.
Could this lead to a use-after-free read during engine initialization if the freed memory is reused before the caller is finished with the batch buffer?
[ ... ]
Quoted 33 lines
drivers/gpu/drm/xe/xe_configfs.c +29
-1+static ssize_t wa_bb_store (struct wa_bb wa_bb[static XE_ENGINE_CLASS_MAX ], +struct xe_config_group_device *dev, +const char *page,size_t len) +{ +struct wa_bb tmp_wa_bb[XE_ENGINE_CLASS_MAX ] = {}; +enum xe_engine_class class; +ssize_t count; +u32 *tmp; + +/* 1. Ensure the inputs are valid and parseable */ + count =parse_wa_bb_lines (page, tmp_wa_bb); +if (count <0 )return count;guard (mutex)(&dev->lock); - + +if (is_bound (dev)) +return -EBUSY ; + +/* +* 2. Allocate a u32 array and set the pointers to the right positions +* according to the length of each class' wa_bb +*/ + tmp =krealloc (wa_bb[0 ].cs, count *sizeof (u32),GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + +if (!count) { +memset (wa_bb,0 ,sizeof (tmp_wa_bb)); +return len; + } +
drivers/gpu/drm/xe/xe_configfs.c static ssize_t wa_bb_store(struct wa_bb wa_bb[static XE_ENGINE_CLASS_MAX], · line 654
Quoted 10 lines
drivers/gpu/drm/xe/xe_configfs.c +10
-0+for (class =0 , count =0 ; class <XE_ENGINE_CLASS_MAX ; ++class) { + tmp_wa_bb[class].cs = tmp + count; + count += tmp_wa_bb[class].len; + tmp_wa_bb[class].len =0 ; + } + +/* 3. Parse wa_bb lines again, this time saving the values */ + count =parse_wa_bb_lines (page, tmp_wa_bb); +if (count <0 ) +return count;
[Severity: High]
This is a pre-existing issue, but does parse_wa_bb_lines() handle configfs inputs that lack a trailing newline safely?
If a user writes a batch buffer command to configfs without a trailing newline, parse_hex() parses the last parameter and leaves the pointer exactly at the null terminator.
At the end of the iteration, the outer for-loop in parse_wa_bb_lines():
for (p = lines; *p; p++) {unconditionally increments the pointer. This causes the pointer to jump past the null terminator and read into uninitialized memory on the next loop condition check.
Can this result in an out-of-bounds read and a potential kernel panic if the read crosses a page boundary into unmapped memory?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH 02/10] drm/xe: Sort xe_config_device fields
In reply to Stuart SummersQuoted 18 lines · Stuart Summers
As we're planning more configfs entries over time, let's add some sorting rules to make sure this stays clean and easy to manage. Sorting first by type and then name for readability.
Signed-off-by Stuart Summers <[email protected]>Assisted-by Copilot:claude-sonnet-4.6,claude-opus-4.7Reviewed-by Gustavo Sousa <[email protected]>--- drivers/gpu/drm/xe/xe_configfs.c | 1092 +++++++++++++++--------------- drivers/gpu/drm/xe/xe_configfs.h | 24 +- 2 files changed, 564 insertions(+), 552 deletions(-)drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -58,10 +58,11 @@* │ └── ...
drivers/gpu/drm/xe/xe_configfs.c line 65
Quoted 10 lines
drivers/gpu/drm/xe/xe_configfs.c +4
-3* : * └── 0000:03:00.0 -* ├── survivability_mode -* ├── gt_types_allowed * ├── engines_allowed -* └── enable_psmi +* ├── gt_types_allowed +* ├── enable_multi_queue +* ├── enable_psmi +* └── survivability_mode
Kind of a subjective nitpick, but I'd handle the structure sorting independently from the doc/function sorting. IMO, this tree structure should effectively be what the user expects to see when running "ls -l" and they won't be thinking about what datatype we're using internally to store the value (u64 vs bool vs ...). Same for the expanded descriptions below...if I want to find "enable_foo" documentation, I think just pure alphabetic sorting is easiest to search through. I'd only incorporate the datatype as a sorting factor for the structure itself.
BTW, should we add the ctx_restore_* entries and the SR-IOV subdirectory to this tree so that it accurately reflects where everything lists in the hierarchy?
Matt
Quoted 1,278 lines
drivers/gpu/drm/xe/xe_configfs.c +548
-537* * After configuring the attributes as per next section, the device can be * probed with:: @@ -73,13 +74,82 @@* Configure Attributes * ==================== * -* Survivability mode: -* ------------------- + +* Context restore BB +* ------------------ * -* Enable survivability mode on supported cards. This setting only takes -* effect when probing the device. Example to enable it:: +* Allow to execute a batch buffer during any context switches. When the +* GPU is restoring the context, it executes additional commands. It's useful +* for testing additional workarounds and validating certain HW behaviors: it's +* not intended for normal execution and will taint the kernel with TAINT_TEST +* when used. * -* # echo 1 > /sys/kernel/config/xe/0000:03:00.0/survivability_mode +* The syntax allows to pass straight instructions to be executed by the engine +* in a batch buffer or set specific registers. +* +* #. Generic instruction:: +* +* <engine-class> cmd <instr> [[dword0] [dword1] [...]] +* +* #. Simple register setting:: +* +* <engine-class> reg <address> <value> +* +* Commands are saved per engine class: all instances of that class will execute +* those commands during context switch. The instruction, dword arguments, +* addresses and values are in hex format like in the examples below. +* +* #. Execute a LRI command to write 0xDEADBEEF to register 0x4f10 after the +* normal context restore:: +* +* # echo 'rcs cmd 11000001 4F100 DEADBEEF' \ +* > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_post_bb +* +* #. Execute a LRI command to write 0xDEADBEEF to register 0x4f10 at the +* beginning of the context restore:: +* +* # echo 'rcs cmd 11000001 4F100 DEADBEEF' \ +* > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_mid_bb + +* #. Load certain values in a couple of registers (it can be used as a simpler +* alternative to the `cmd`) action:: +* +* # cat > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_post_bb <<EOF +* rcs reg 4F100 DEADBEEF +* rcs reg 4F104 FFFFFFFF +* EOF +* +* .. note:: +* +* When using multiple lines, make sure to use a command that is +* implemented with a single write syscall, like HEREDOC. +* +* Currently this is implemented only for post and mid context restore and +* these attributes can only be set before binding to the device. +* +* Allowed engines: +* ---------------- +* +* Allow only a set of engine(s) to be available, disabling the other engines +* even if they are available in hardware. This is applied after HW fuses are +* considered on each tile. Examples: +* +* Allow only one render and one copy engines, nothing else:: +* +* # echo 'rcs0,bcs0' > /sys/kernel/config/xe/0000:03:00.0/engines_allowed +* +* Allow only compute engines and first copy engine:: +* +* # echo 'ccs*,bcs0' > /sys/kernel/config/xe/0000:03:00.0/engines_allowed +* +* Note that the engine names are the per-GT hardware names. On multi-tile +* platforms, writing ``rcs0,bcs0`` to this file would allow the first render +* and copy engines on each tile. +* +* The requested configuration may not be supported by the platform and driver +* may fail to probe. For example: if at least one copy engine is expected to be +* available for migrations, but it's disabled. This is intended for debugging +* purposes only. * * This attribute can only be set before binding to the device. * @@ -121,29 +191,15 @@* * # echo '' > /sys/kernel/config/xe/0000:03:00.0/gt_types_allowed * -* Allowed engines: -* ---------------- -* -* Allow only a set of engine(s) to be available, disabling the other engines -* even if they are available in hardware. This is applied after HW fuses are -* considered on each tile. Examples: -* -* Allow only one render and one copy engines, nothing else:: -* -* # echo 'rcs0,bcs0' > /sys/kernel/config/xe/0000:03:00.0/engines_allowed -* -* Allow only compute engines and first copy engine:: -* -* # echo 'ccs*,bcs0' > /sys/kernel/config/xe/0000:03:00.0/engines_allowed +* Enable multi-queue +* ------------------ * -* Note that the engine names are the per-GT hardware names. On multi-tile -* platforms, writing ``rcs0,bcs0`` to this file would allow the first render -* and copy engines on each tile. +* Multi-queue support on the device is enabled by default where the +* hardware supports it. Writing 0 force-disables multi-queue support: +* multi-queue exec-queue group creation via ioctl is refused, and the +* GuC feature is disabled:: * -* The requested configuration may not be supported by the platform and driver -* may fail to probe. For example: if at least one copy engine is expected to be -* available for migrations, but it's disabled. This is intended for debugging -* purposes only. +* # echo 0 > /sys/kernel/config/xe/0000:03:00.0/enable_multi_queue * * This attribute can only be set before binding to the device. * @@ -159,57 +215,15 @@* * This attribute can only be set before binding to the device. * -* Context restore BB -* ------------------ -* -* Allow to execute a batch buffer during any context switches. When the -* GPU is restoring the context, it executes additional commands. It's useful -* for testing additional workarounds and validating certain HW behaviors: it's -* not intended for normal execution and will taint the kernel with TAINT_TEST -* when used. -* -* The syntax allows to pass straight instructions to be executed by the engine -* in a batch buffer or set specific registers. -* -* #. Generic instruction:: -* -* <engine-class> cmd <instr> [[dword0] [dword1] [...]] -* -* #. Simple register setting:: -* -* <engine-class> reg <address> <value> -* -* Commands are saved per engine class: all instances of that class will execute -* those commands during context switch. The instruction, dword arguments, -* addresses and values are in hex format like in the examples below. -* -* #. Execute a LRI command to write 0xDEADBEEF to register 0x4f10 after the -* normal context restore:: -* -* # echo 'rcs cmd 11000001 4F100 DEADBEEF' \ -* > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_post_bb -* -* #. Execute a LRI command to write 0xDEADBEEF to register 0x4f10 at the -* beginning of the context restore:: -* -* # echo 'rcs cmd 11000001 4F100 DEADBEEF' \ -* > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_mid_bb - -* #. Load certain values in a couple of registers (it can be used as a simpler -* alternative to the `cmd`) action:: -* -* # cat > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_post_bb <<EOF -* rcs reg 4F100 DEADBEEF -* rcs reg 4F104 FFFFFFFF -* EOF +* Survivability mode: +* ------------------- * -* .. note:: +* Enable survivability mode on supported cards. This setting only takes +* effect when probing the device. Example to enable it:: * -* When using multiple lines, make sure to use a command that is -* implemented with a single write syscall, like HEREDOC. +* # echo 1 > /sys/kernel/config/xe/0000:03:00.0/survivability_mode * -* Currently this is implemented only for post and mid context restore and -* these attributes can only be set before binding to the device. +* This attribute can only be set before binding to the device. * * Max SR-IOV Virtual Functions * ---------------------------- @@ -237,18 +251,6 @@* * This setting only takes effect when probing the device. * -* Enable multi-queue -* ------------------ -* -* Multi-queue support on the device is enabled by default where the -* hardware supports it. Writing 0 force-disables multi-queue support: -* multi-queue exec-queue group creation via ioctl is refused, and the -* GuC feature is disabled:: -* -* # echo 0 > /sys/kernel/config/xe/0000:03:00.0/enable_multi_queue -* -* This attribute can only be set before binding to the device. -* * Remove devices * ============== * @@ -267,14 +269,19 @@ struct xe_config_group_device {struct config_group group;struct config_group sriov; +/* +* Fields sorted by type (largest first) then name: struct arrays, +* u64, u32/unsigned int, u8, bool, sub-structs last. Within each +* type, entries are sorted alphabetically. +*/ struct xe_config_device { -u64 gt_types_allowed; -u64 engines_allowed; -struct wa_bb ctx_restore_post_bb[XE_ENGINE_CLASS_MAX ];struct wa_bb ctx_restore_mid_bb[XE_ENGINE_CLASS_MAX ]; -bool survivability_mode; -bool enable_psmi; +struct wa_bb ctx_restore_post_bb[XE_ENGINE_CLASS_MAX ]; +u64 engines_allowed; +u64 gt_types_allowed;bool enable_multi_queue; +bool enable_psmi; +bool survivability_mode;struct {unsigned int max_vfs;bool admin_only_pf;@@ -290,11 +297,11 @@ struct xe_config_group_device { };static const struct xe_config_device device_defaults = { - .gt_types_allowed =U64_MAX , .engines_allowed =U64_MAX , - .survivability_mode = false, - .enable_psmi = false, + .gt_types_allowed =U64_MAX , .enable_multi_queue = true, + .enable_psmi = false, + .survivability_mode = false, .sriov = { .max_vfs =XE_DEFAULT_MAX_VFS , .admin_only_pf =XE_DEFAULT_ADMIN_ONLY_PF ,@@ -371,247 +378,60 @@ static bool is_bound(struct xe_config_group_device *dev)return ret; } -static ssize_t survivability_mode_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); - -return sprintf (page,"%d\n" , dev->survivability_mode); -} +static struct xe_config_group_device *find_xe_config_group_device (struct pci_dev *pdev); -static ssize_t survivability_mode_store (struct config_item *item,const char *page,size_t len) +/** +* xe_configfs_get_ctx_restore_mid_bb - get configfs ctx_restore_mid_bb setting +* @pdev: pci device +* @class: hw engine class +* @cs: pointer to the bb to use - only valid during probe +* +* Return: Number of dwords used in the mid_ctx_restore setting in configfs +*/ +u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, +enum xe_engine_class class, +const u32 **cs) { -struct xe_config_group_device *dev =to_xe_config_group_device (item); -bool survivability_mode; -int ret; +struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +u32 len; - ret =kstrtobool (page, &survivability_mode); -if (ret) -return ret; +if (!dev) +return 0 ; -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; + scoped_guard(mutex, &dev->lock) { +if (cs) + *cs = dev->config.ctx_restore_mid_bb[class].cs; - dev->config.survivability_mode = survivability_mode; + len = dev->config.ctx_restore_mid_bb[class].len; + } +config_group_put (&dev->group);return len; } -static ssize_t gt_types_allowed_show (struct config_item *item,char *page) +/** +* xe_configfs_get_ctx_restore_post_bb - get configfs ctx_restore_post_bb setting +* @pdev: pci device +* @class: hw engine class +* @cs: pointer to the bb to use - only valid during probe +* +* Return: Number of dwords used in the post_ctx_restore setting in configfs +*/ +u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, +enum xe_engine_class class, +const u32 **cs) { -struct xe_config_device *dev =to_xe_config_device (item); -char *p = page; - -for (size_t i =0 ; i <ARRAY_SIZE (gt_types); i++) -if (dev->gt_types_allowed &BIT_ULL (gt_types[i].type)) - p +=sprintf (p,"%s\n" , gt_types[i].name); +struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +u32 len; -return p - page; -} +if (!dev) +return 0 ; -static ssize_t gt_types_allowed_store (struct config_item *item,const char *page, -size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); - char *buf __free(kfree) = kstrdup(page, GFP_KERNEL); -char *p = buf; -u64 typemask =0 ; - -if (!buf) -return -ENOMEM ; - -while (p) { -char *typename =strsep (&p,",\n" ); -bool matched = false; - -if (typename[0 ] =='\0' ) -continue ; - -for (size_t i =0 ; i <ARRAY_SIZE (gt_types); i++) { -if (strcmp (typename, gt_types[i].name) ==0 ) { - typemask |=BIT (gt_types[i].type); - matched = true; -break ; - } - } - -if (!matched) -return -EINVAL ; - } - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.gt_types_allowed = typemask; - -return len; -} - -static ssize_t engines_allowed_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); -char *p = page; - -for (size_t i =0 ; i <ARRAY_SIZE (engine_info); i++) { -u64 mask = engine_info[i].mask; - -if ((dev->engines_allowed & mask) == mask) { - p +=sprintf (p,"%s*\n" , engine_info[i].cls); - }else if (mask & dev->engines_allowed) { -u16 bit0 =__ffs64 (mask), bit; - - mask &= dev->engines_allowed; - -for_each_set_bit (bit, (const unsigned long *)&mask,64 ) - p +=sprintf (p,"%s%u\n" , engine_info[i].cls, - bit - bit0); - } - } - -return p - page; -} - -/* -* Lookup engine_info. If @mask is not NULL, reduce the mask according to the -* instance in @pattern. -* -* Examples of inputs: -* - lookup_engine_info("rcs0", &mask): return "rcs" entry from @engine_info and -* mask == BIT_ULL(XE_HW_ENGINE_RCS0) -* - lookup_engine_info("rcs*", &mask): return "rcs" entry from @engine_info and -* mask == XE_HW_ENGINE_RCS_MASK -* - lookup_engine_info("rcs", NULL): return "rcs" entry from @engine_info -*/ -static const struct engine_info *lookup_engine_info (const char *pattern,u64 *mask) -{ -for (size_t i =0 ; i <ARRAY_SIZE (engine_info); i++) { -u8 instance; -u16 bit; - -if (!str_has_prefix (pattern, engine_info[i].cls)) -continue ; - - pattern +=strlen (engine_info[i].cls); -if (!mask) -return *pattern ?NULL : &engine_info[i]; - -if (!strcmp (pattern,"*" )) { - *mask = engine_info[i].mask; -return &engine_info[i]; - } - -if (kstrtou8 (pattern,10 , &instance)) -return NULL ; - - bit =__ffs64 (engine_info[i].mask) + instance; -if (bit >=fls64 (engine_info[i].mask)) -return NULL ; - - *mask =BIT_ULL (bit); -return &engine_info[i]; - } - -return NULL ; -} - -static int parse_engine (const char *s,const char *end_chars,u64 *mask, -const struct engine_info **pinfo) -{ -char buf[MAX_ENGINE_CLASS_CHARS +MAX_ENGINE_INSTANCE_CHARS +1 ]; -const struct engine_info *info; -size_t len; - - len =strcspn (s, end_chars); -if (len >=sizeof (buf)) -return -EINVAL ; - -memcpy (buf, s, len); - buf[len] ='\0' ; - - info =lookup_engine_info (buf, mask); -if (!info) -return -ENOENT ; - -if (pinfo) - *pinfo = info; - -return len; -} - -static ssize_t engines_allowed_store (struct config_item *item,const char *page, -size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); -ssize_t patternlen, p; -u64 mask, val =0 ; - -for (p =0 ; p < len; p += patternlen +1 ) { - patternlen =parse_engine (page + p,",\n" , &mask,NULL ); -if (patternlen <0 ) -return -EINVAL ; - - val |= mask; + scoped_guard(mutex, &dev->lock) { + *cs = dev->config.ctx_restore_post_bb[class].cs; + len = dev->config.ctx_restore_post_bb[class].len; } - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.engines_allowed = val; - -return len; -} - -static ssize_t enable_psmi_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); - -return sprintf (page,"%d\n" , dev->enable_psmi); -} - -static ssize_t enable_psmi_store (struct config_item *item,const char *page,size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); -bool val; -int ret; - - ret =kstrtobool (page, &val); -if (ret) -return ret; - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.enable_psmi = val; - -return len; -} - -static ssize_t enable_multi_queue_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); - -return sprintf (page,"%d\n" , dev->enable_multi_queue); -} - -static ssize_t enable_multi_queue_store (struct config_item *item,const char *page, -size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); -bool val; -int ret; - - ret =kstrtobool (page, &val); -if (ret) -return ret; - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.enable_multi_queue = val; +config_group_put (&dev->group);return len; }@@ -718,6 +538,9 @@ static ssize_t parse_hex(const char *line, u32 *pval)return p - line; } +static int parse_engine (const char *s,const char *end_chars,u64 *mask, +const struct engine_info **pinfo); +/* * Parse lines with the format * @@ -802,70 +625,439 @@ static ssize_t wa_bb_store(struct wa_bb wa_bb[static XE_ENGINE_CLASS_MAX],return count;guard (mutex)(&dev->lock); - + +if (is_bound (dev)) +return -EBUSY ; + +/* +* 2. Allocate a u32 array and set the pointers to the right positions +* according to the length of each class' wa_bb +*/ + tmp =krealloc (wa_bb[0 ].cs, count *sizeof (u32),GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + +if (!count) { +memset (wa_bb,0 ,sizeof (tmp_wa_bb)); +return len; + } + +for (class =0 , count =0 ; class <XE_ENGINE_CLASS_MAX ; ++class) { + tmp_wa_bb[class].cs = tmp + count; + count += tmp_wa_bb[class].len; + tmp_wa_bb[class].len =0 ; + } + +/* 3. Parse wa_bb lines again, this time saving the values */ + count =parse_wa_bb_lines (page, tmp_wa_bb); +if (count <0 ) +return count; + +memcpy (wa_bb, tmp_wa_bb,sizeof (tmp_wa_bb)); + +return len; +} + +static ssize_t ctx_restore_mid_bb_store (struct config_item *item, +const char *data,size_t sz) +{ +struct xe_config_group_device *dev =to_xe_config_group_device (item); + +return wa_bb_store (dev->config.ctx_restore_mid_bb, dev, data, sz); +} + +static ssize_t ctx_restore_post_bb_store (struct config_item *item, +const char *data,size_t sz) +{ +struct xe_config_group_device *dev =to_xe_config_group_device (item); + +return wa_bb_store (dev->config.ctx_restore_post_bb, dev, data, sz); +} + +/** +* xe_configfs_get_engines_allowed - get engine allowed mask from configfs +* @pdev: pci device +* +* Return: engine mask with allowed engines set in configfs +*/ +u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) +{ +struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +u64 engines_allowed; + +if (!dev) +return device_defaults.engines_allowed; + + scoped_guard(mutex, &dev->lock) + engines_allowed = dev->config.engines_allowed; +config_group_put (&dev->group); + +return engines_allowed; +} + +static ssize_t engines_allowed_show (struct config_item *item,char *page) +{ +struct xe_config_device *dev =to_xe_config_device (item); +char *p = page; + +for (size_t i =0 ; i <ARRAY_SIZE (engine_info); i++) { +u64 mask = engine_info[i].mask; + +if ((dev->engines_allowed & mask) == mask) { + p +=sprintf (p,"%s*\n" , engine_info[i].cls); + }else if (mask & dev->engines_allowed) { +u16 bit0 =__ffs64 (mask), bit; + + mask &= dev->engines_allowed; + +for_each_set_bit (bit, (const unsigned long *)&mask,64 ) + p +=sprintf (p,"%s%u\n" , engine_info[i].cls, + bit - bit0); + } + } + +return p - page; +} + +/* +* Lookup engine_info. If @mask is not NULL, reduce the mask according to the +* instance in @pattern. +* +* Examples of inputs: +* - lookup_engine_info("rcs0", &mask): return "rcs" entry from @engine_info and +* mask == BIT_ULL(XE_HW_ENGINE_RCS0) +* - lookup_engine_info("rcs*", &mask): return "rcs" entry from @engine_info and +* mask == XE_HW_ENGINE_RCS_MASK +* - lookup_engine_info("rcs", NULL): return "rcs" entry from @engine_info +*/ +static const struct engine_info *lookup_engine_info (const char *pattern,u64 *mask) +{ +for (size_t i =0 ; i <ARRAY_SIZE (engine_info); i++) { +u8 instance; +u16 bit; + +if (!str_has_prefix (pattern, engine_info[i].cls)) +continue ; + + pattern +=strlen (engine_info[i].cls); +if (!mask) +return *pattern ?NULL : &engine_info[i]; + +if (!strcmp (pattern,"*" )) { + *mask = engine_info[i].mask; +return &engine_info[i]; + } + +if (kstrtou8 (pattern,10 , &instance)) +return NULL ; + + bit =__ffs64 (engine_info[i].mask) + instance; +if (bit >=fls64 (engine_info[i].mask)) +return NULL ; + + *mask =BIT_ULL (bit); +return &engine_info[i]; + } + +return NULL ; +} + +static int parse_engine (const char *s,const char *end_chars,u64 *mask, +const struct engine_info **pinfo) +{ +char buf[MAX_ENGINE_CLASS_CHARS +MAX_ENGINE_INSTANCE_CHARS +1 ]; +const struct engine_info *info; +size_t len; + + len =strcspn (s, end_chars); +if (len >=sizeof (buf)) +return -EINVAL ; + +memcpy (buf, s, len); + buf[len] ='\0' ; + + info =lookup_engine_info (buf, mask); +if (!info) +return -ENOENT ; + +if (pinfo) + *pinfo = info; + +return len; +} + +static ssize_t engines_allowed_store (struct config_item *item,const char *page, +size_t len) +{ +struct xe_config_group_device *dev =to_xe_config_group_device (item); +ssize_t patternlen, p; +u64 mask, val =0 ; + +for (p =0 ; p < len; p += patternlen +1 ) { + patternlen =parse_engine (page + p,",\n" , &mask,NULL ); +if (patternlen <0 ) +return -EINVAL ; + + val |= mask; + } + +guard (mutex)(&dev->lock); +if (is_bound (dev)) +return -EBUSY ; + + dev->config.engines_allowed = val; + +return len; +} + +static u64 get_gt_types_allowed (struct pci_dev *pdev) +{ +struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +u64 mask; + +if (!dev) +return device_defaults.gt_types_allowed; + +scoped_guard (mutex, &dev->lock) + mask = dev->config.gt_types_allowed; +config_group_put (&dev->group); + +return mask; +} + +/** +* xe_configfs_primary_gt_allowed - determine whether primary GTs are supported +* @pdev: pci device +* +* Return: True if primary GTs are enabled, false if they have been disabled via +* configfs. +*/ +bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) +{ +return get_gt_types_allowed (pdev) &BIT_ULL (XE_GT_TYPE_MAIN ); +} + +/** +* xe_configfs_media_gt_allowed - determine whether media GTs are supported +* @pdev: pci device +* +* Return: True if the media GTs are enabled, false if they have been disabled +* via configfs. +*/ +bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) +{ +return get_gt_types_allowed (pdev) &BIT_ULL (XE_GT_TYPE_MEDIA ); +} + +static ssize_t gt_types_allowed_show (struct config_item *item,char *page) +{ +struct xe_config_device *dev =to_xe_config_device (item); +char *p = page; + +for (size_t i =0 ; i <ARRAY_SIZE (gt_types); i++) +if (dev->gt_types_allowed &BIT_ULL (gt_types[i].type)) + p +=sprintf (p,"%s\n" , gt_types[i].name); + +return p - page; +} + +static ssize_t gt_types_allowed_store (struct config_item *item,const char *page, +size_t len) +{ +struct xe_config_group_device *dev =to_xe_config_group_device (item); + char *buf __free(kfree) = kstrdup(page, GFP_KERNEL); +char *p = buf; +u64 typemask =0 ; + +if (!buf) +return -ENOMEM ; + +while (p) { +char *typename =strsep (&p,",\n" ); +bool matched = false; + +if (typename[0 ] =='\0' ) +continue ; + +for (size_t i =0 ; i <ARRAY_SIZE (gt_types); i++) { +if (strcmp (typename, gt_types[i].name) ==0 ) { + typemask |=BIT (gt_types[i].type); + matched = true; +break ; + } + } + +if (!matched) +return -EINVAL ; + } + +guard (mutex)(&dev->lock); +if (is_bound (dev)) +return -EBUSY ; + + dev->config.gt_types_allowed = typemask; + +return len; +} + +/** +* xe_configfs_get_enable_multi_queue - get configfs enable_multi_queue setting +* @pdev: pci device +* +* Return: true if multi-queue is enabled for this device (the default), +* false if it has been force-disabled via configfs. +*/ +bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) +{ +struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +bool ret; + +if (!dev) +return true; + +scoped_guard (mutex, &dev->lock) + ret = dev->config.enable_multi_queue; +config_group_put (&dev->group); + +return ret; +} + +static ssize_t enable_multi_queue_show (struct config_item *item,char *page) +{ +struct xe_config_device *dev =to_xe_config_device (item); + +return sprintf (page,"%d\n" , dev->enable_multi_queue); +} + +static ssize_t enable_multi_queue_store (struct config_item *item,const char *page, +size_t len) +{ +struct xe_config_group_device *dev =to_xe_config_group_device (item); +bool val; +int ret; + + ret =kstrtobool (page, &val); +if (ret) +return ret; + +guard (mutex)(&dev->lock); +if (is_bound (dev)) +return -EBUSY ; + + dev->config.enable_multi_queue = val; + +return len; +} + +/** +* xe_configfs_get_psmi_enabled - get configfs enable_psmi setting +* @pdev: pci device +* +* Return: enable_psmi setting in configfs +*/ +bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) +{ +struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +bool ret; + +if (!dev) +return false; + +scoped_guard (mutex, &dev->lock) + ret = dev->config.enable_psmi; +config_group_put (&dev->group); + +return ret; +} + +static ssize_t enable_psmi_show (struct config_item *item,char *page) +{ +struct xe_config_device *dev =to_xe_config_device (item); + +return sprintf (page,"%d\n" , dev->enable_psmi); +} + +static ssize_t enable_psmi_store (struct config_item *item,const char *page,size_t len) +{ +struct xe_config_group_device *dev =to_xe_config_group_device (item); +bool val; +int ret; + + ret =kstrtobool (page, &val); +if (ret) +return ret; + +guard (mutex)(&dev->lock);if (is_bound (dev))return -EBUSY ; -/* -* 2. Allocate a u32 array and set the pointers to the right positions -* according to the length of each class' wa_bb -*/ - tmp =krealloc (wa_bb[0 ].cs, count *sizeof (u32),GFP_KERNEL ); -if (!tmp) -return -ENOMEM ; + dev->config.enable_psmi = val; -if (!count) { -memset (wa_bb,0 ,sizeof (tmp_wa_bb)); -return len; - } +return len; +} -for (class =0 , count =0 ; class <XE_ENGINE_CLASS_MAX ; ++class) { - tmp_wa_bb[class].cs = tmp + count; - count += tmp_wa_bb[class].len; - tmp_wa_bb[class].len =0 ; - } +/** +* xe_configfs_get_survivability_mode - get configfs survivability mode attribute +* @pdev: pci device +* +* Return: survivability_mode attribute in configfs +*/ +bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) +{ +struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +bool mode; -/* 3. Parse wa_bb lines again, this time saving the values */ - count =parse_wa_bb_lines (page, tmp_wa_bb); -if (count <0 ) -return count; +if (!dev) +return device_defaults.survivability_mode; -memcpy (wa_bb, tmp_wa_bb,sizeof (tmp_wa_bb)); +scoped_guard (mutex, &dev->lock) + mode = dev->config.survivability_mode; +config_group_put (&dev->group); -return len; +return mode; } -static ssize_t ctx_restore_mid_bb_store (struct config_item *item, -const char *data,size_t sz) +static ssize_t survivability_mode_show (struct config_item *item,char *page) { -struct xe_config_group_device *dev =to_xe_config_group_device (item); +struct xe_config_device *dev =to_xe_config_device (item); -return wa_bb_store (dev->config.ctx_restore_mid_bb, dev, data, sz); +return sprintf (page,"%d\n" , dev->survivability_mode); } -static ssize_t ctx_restore_post_bb_store (struct config_item *item, -const char *data,size_t sz) +static ssize_t survivability_mode_store (struct config_item *item,const char *page,size_t len) {struct xe_config_group_device *dev =to_xe_config_group_device (item); +bool survivability_mode; +int ret; -return wa_bb_store (dev->config.ctx_restore_post_bb, dev, data, sz); + ret =kstrtobool (page, &survivability_mode); +if (ret) +return ret; + +guard (mutex)(&dev->lock); +if (is_bound (dev)) +return -EBUSY ; + + dev->config.survivability_mode = survivability_mode; + +return len; } CONFIGFS_ATTR(, ctx_restore_mid_bb); CONFIGFS_ATTR(, ctx_restore_post_bb); -CONFIGFS_ATTR(, enable_multi_queue); -CONFIGFS_ATTR(, enable_psmi); CONFIGFS_ATTR(, engines_allowed); CONFIGFS_ATTR(, gt_types_allowed); +CONFIGFS_ATTR(, enable_multi_queue); +CONFIGFS_ATTR(, enable_psmi); CONFIGFS_ATTR(, survivability_mode);static struct configfs_attribute *xe_config_device_attrs[] = { &attr_ctx_restore_mid_bb, &attr_ctx_restore_post_bb, - &attr_enable_multi_queue, - &attr_enable_psmi, &attr_engines_allowed, &attr_gt_types_allowed, + &attr_enable_multi_queue, + &attr_enable_psmi, &attr_survivability_mode,NULL , };@@ -1138,8 +1330,8 @@ static void dump_custom_dev_config(struct pci_dev *pdev, dev->config.attr_); \ }while (0 ) -PRI_CUSTOM_ATTR ("%llx" , gt_types_allowed);PRI_CUSTOM_ATTR ("%llx" , engines_allowed); +PRI_CUSTOM_ATTR ("%llx" , gt_types_allowed);PRI_CUSTOM_ATTR ("%d" , enable_multi_queue);PRI_CUSTOM_ATTR ("%d" , enable_psmi);PRI_CUSTOM_ATTR ("%d" , survivability_mode);@@ -1171,186 +1363,6 @@ void xe_configfs_check_device(struct pci_dev *pdev)config_group_put (&dev->group); } -/** -* xe_configfs_get_survivability_mode - get configfs survivability mode attribute -* @pdev: pci device -* -* Return: survivability_mode attribute in configfs -*/ -bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -bool mode; - -if (!dev) -return device_defaults.survivability_mode; - -scoped_guard (mutex, &dev->lock) - mode = dev->config.survivability_mode; -config_group_put (&dev->group); - -return mode; -} - -static u64 get_gt_types_allowed (struct pci_dev *pdev) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -u64 mask; - -if (!dev) -return device_defaults.gt_types_allowed; - -scoped_guard (mutex, &dev->lock) - mask = dev->config.gt_types_allowed; -config_group_put (&dev->group); - -return mask; -} - -/** -* xe_configfs_primary_gt_allowed - determine whether primary GTs are supported -* @pdev: pci device -* -* Return: True if primary GTs are enabled, false if they have been disabled via -* configfs. -*/ -bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) -{ -return get_gt_types_allowed (pdev) &BIT_ULL (XE_GT_TYPE_MAIN ); -} - -/** -* xe_configfs_media_gt_allowed - determine whether media GTs are supported -* @pdev: pci device -* -* Return: True if the media GTs are enabled, false if they have been disabled -* via configfs. -*/ -bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) -{ -return get_gt_types_allowed (pdev) &BIT_ULL (XE_GT_TYPE_MEDIA ); -} - -/** -* xe_configfs_get_engines_allowed - get engine allowed mask from configfs -* @pdev: pci device -* -* Return: engine mask with allowed engines set in configfs -*/ -u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -u64 engines_allowed; - -if (!dev) -return device_defaults.engines_allowed; - - scoped_guard(mutex, &dev->lock) - engines_allowed = dev->config.engines_allowed; -config_group_put (&dev->group); - -return engines_allowed; -} - -/** -* xe_configfs_get_psmi_enabled - get configfs enable_psmi setting -* @pdev: pci device -* -* Return: enable_psmi setting in configfs -*/ -bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -bool ret; - -if (!dev) -return false; - -scoped_guard (mutex, &dev->lock) - ret = dev->config.enable_psmi; -config_group_put (&dev->group); - -return ret; -} - -/** -* xe_configfs_get_enable_multi_queue - get configfs enable_multi_queue setting -* @pdev: pci device -* -* Return: true if multi-queue is enabled for this device (the default), -* false if it has been force-disabled via configfs. -*/ -bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -bool ret; - -if (!dev) -return true; - -scoped_guard (mutex, &dev->lock) - ret = dev->config.enable_multi_queue; -config_group_put (&dev->group); - -return ret; -} - -/** -* xe_configfs_get_ctx_restore_mid_bb - get configfs ctx_restore_mid_bb setting -* @pdev: pci device -* @class: hw engine class -* @cs: pointer to the bb to use - only valid during probe -* -* Return: Number of dwords used in the mid_ctx_restore setting in configfs -*/ -u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, -enum xe_engine_class class, -const u32 **cs) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -u32 len; - -if (!dev) -return 0 ; - - scoped_guard(mutex, &dev->lock) { -if (cs) - *cs = dev->config.ctx_restore_mid_bb[class].cs; - - len = dev->config.ctx_restore_mid_bb[class].len; - } -config_group_put (&dev->group); - -return len; -} - -/** -* xe_configfs_get_ctx_restore_post_bb - get configfs ctx_restore_post_bb setting -* @pdev: pci device -* @class: hw engine class -* @cs: pointer to the bb to use - only valid during probe -* -* Return: Number of dwords used in the post_ctx_restore setting in configfs -*/ -u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, -enum xe_engine_class class, -const u32 **cs) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -u32 len; - -if (!dev) -return 0 ; - - scoped_guard(mutex, &dev->lock) { - *cs = dev->config.ctx_restore_post_bb[class].cs; - len = dev->config.ctx_restore_post_bb[class].len; - } -config_group_put (&dev->group); - -return len; -} -#ifdef CONFIG_PCI_IOV /** * xe_configfs_admin_only_pf() - Get PF's operational mode. drivers/gpu/drm/xe/xe_configfs.h +12
-12@@ -18,18 +18,18 @@ struct pci_dev;int xe_configfs_init (void );void xe_configfs_exit (void );void xe_configfs_check_device (struct pci_dev *pdev); -bool xe_configfs_get_survivability_mode (struct pci_dev *pdev); -bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev); -bool xe_configfs_media_gt_allowed (struct pci_dev *pdev); -u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev); -bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev); -bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev);u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev,enum xe_engine_class class,const u32 **cs);u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev,enum xe_engine_class class,const u32 **cs); +u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev); +bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev); +bool xe_configfs_media_gt_allowed (struct pci_dev *pdev); +bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev); +bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev); +bool xe_configfs_get_survivability_mode (struct pci_dev *pdev);#ifdef CONFIG_PCI_IOV unsigned int xe_configfs_get_max_vfs (struct pci_dev *pdev);bool xe_configfs_admin_only_pf (struct pci_dev *pdev);@@ -38,18 +38,18 @@ bool xe_configfs_admin_only_pf(struct pci_dev *pdev);static inline int xe_configfs_init (void ) {return 0 ; }static inline void xe_configfs_exit (void ) { }static inline void xe_configfs_check_device (struct pci_dev *pdev) { } -static inline bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) {return false; } -static inline bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) {return true; } -static inline bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) {return true; } -static inline u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) {return U64_MAX ; } -static inline bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) {return false; } -static inline bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) {return true; }static inline u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev,enum xe_engine_class class,const u32 **cs) {return 0 ; }static inline u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev,enum xe_engine_class class,const u32 **cs) {return 0 ; } +static inline u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) {return U64_MAX ; } +static inline bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) {return true; } +static inline bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) {return true; } +static inline bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) {return true; } +static inline bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) {return false; } +static inline bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) {return false; }#ifdef CONFIG_PCI_IOV static inline unsigned int xe_configfs_get_max_vfs (struct pci_dev *pdev) {Signature · 1 line
2.43.0
Signature · 4 lines
Matt Roper Graphics Software Engineer Linux GPU Platform Enablement Intel Corporation
Re: [PATCH 02/10] drm/xe: Sort xe_config_device fields
Quoted 36 lines · Matt Roper
Quoted 20 lines · Stuart Summers
As we're planning more configfs entries over time, let's add some sorting rules to make sure this stays clean and easy to manage. Sorting first by type and then name for readability.
Signed-off-by Stuart Summers <[email protected]>Assisted-by Copilot:claude-sonnet-4.6,claude-opus-4.7Reviewed-by Gustavo Sousa <[email protected]>---
drivers/gpu/drm/xe/xe_configfs.c | 1092 +++++++++++++++-----------
----
drivers/gpu/drm/xe/xe_configfs.h | 24 +-2 files changed, 564 insertions(+), 552 deletions(-)drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -58,10 +58,11 @@ * │ └── ...drivers/gpu/drm/xe/xe_configfs.c line 65
Quoted 10 lines
drivers/gpu/drm/xe/xe_configfs.c +4
-3* : * └── 0000:03:00.0 - * ├── survivability_mode - * ├── gt_types_allowed * ├── engines_allowed - * └── enable_psmi + * ├── gt_types_allowed + * ├── enable_multi_queue + * ├── enable_psmi + * └── survivability_modeKind of a subjective nitpick, but I'd handle the structure sorting independently from the doc/function sorting. IMO, this tree structure
should effectively be what the user expects to see when running "ls -
Quoted 8 lines
l"
and they won't be thinking about what datatype we're using internally to
store the value (u64 vs bool vs ...). Same for the expanded descriptions below...if I want to find "enable_foo" documentation, I think just pure alphabetic sorting is easiest to search through. I'd only incorporate the datatype as a sorting factor for the structure itself.
Yeah that makes sense. I was trying to have a consistent view all over the file, but maybe this is being a little too strict and not user- friendly...
I'll update to alphabetic in the documentation part.
Quoted 5 lines
BTW, should we add the ctx_restore_* entries and the SR-IOV subdirectory
to this tree so that it accurately reflects where everything lists in the hierarchy?
The SRIOV subdirectories should already be there, but I'll add everything so we have a full list. I agree from a documentation standpoint this would be better.
Thanks,
Stuart
Quoted 1,500 lines
Matt
Quoted 1,495 lines
drivers/gpu/drm/xe/xe_configfs.c +0
-0* * After configuring the attributes as per next section, thedevice can be
* probed with::drivers/gpu/drm/xe/xe_configfs.c +3
-3@@ -73,13 +74,82 @@ * Configure Attributes * ==================== * - * Survivability mode: - * ------------------- + + * Context restore BB + * ------------------ * - * Enable survivability mode on supported cards. This setting onlytakes
- * effect when probing the device. Example to enable it::
+ * Allow to execute a batch buffer during any context switches. When the
+ * GPU is restoring the context, it executes additional commands. It's useful
+ * for testing additional workarounds and validating certain HW
behaviors: it's
+ * not intended for normal execution and will taint the kernel withTAINT_TEST
+ * when used.
*
- * # echo 1 > /sys/kernel/config/xe/0000:03:00.0/survivability_mode
+ * The syntax allows to pass straight instructions to be executed by the engine
+ * in a batch buffer or set specific registers.
+ *
+ * #. Generic instruction::
+ *
+ * <engine-class> cmd <instr> [[dword0] [dword1] [...]]
+ *
+ * #. Simple register setting::
+ *
+ * <engine-class> reg <address> <value>
+ *
+ * Commands are saved per engine class: all instances of that class will execute
+ * those commands during context switch. The instruction, dword arguments,
+ * addresses and values are in hex format like in the examples below.
+ *
+ * #. Execute a LRI command to write0xDEADBEEFto register0x4f10after the
+ * normal context restore::
+ *
+ * # echo 'rcs cmd 11000001 4F100 DEADBEEF' \
+ * > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_post_bb
+ *
+ * #. Execute a LRI command to write0xDEADBEEFto register0x4f10at the
+ * beginning of the context restore::
+ *
+ * # echo 'rcs cmd 11000001 4F100 DEADBEEF' \
+ * > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_mid_bb
+
+ * #. Load certain values in a couple of registers (it can be used as a simpler
+ * alternative to thecmd) action::
+ *
+ * # cat > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_post_bb <<EOF
+ * rcs reg 4F100 DEADBEEF
+ * rcs reg 4F104 FFFFFFFF
+ * EOF
+ *
+ * .. note::
+ *
+ * When using multiple lines, make sure to use a command that is
+ * implemented with a single write syscall, like HEREDOC.
+ *
+ * Currently this is implemented only for post and mid context restore and
+ * these attributes can only be set before binding to the device.
+ *
+ * Allowed engines:
+ * ----------------
+ *
+ * Allow only a set of engine(s) to be available, disabling the other engines
+ * even if they are available in hardware. This is applied after HW fuses are
+ * considered on each tile. Examples:
+ *
+ * Allow only one render and one copy engines, nothing else::
+ *
+ * # echo 'rcs0,bcs0' > /sys/kernel/config/xe/0000:03:00.0/engines_allowed
+ *
+ * Allow only compute engines and first copy engine::
+ *
+ * # echo 'ccs*,bcs0' > /sys/kernel/config/xe/0000:03:00.0/engines_allowed
+ *
+ * Note that the engine names are the per-GT hardware names. On multi-tile
+ * platforms, writing ``rcs0,bcs0`` to this file would allow the first render
+ * and copy engines on each tile.
+ *
+ * The requested configuration may not be supported by the platform and driver
+ * may fail to probe. For example: if at least one copy engine is expected to be
+ * available for migrations, but it's disabled. This is intended for debugging
+ * purposes only.
*
* This attribute can only be set before binding to the device. *drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -121,29 +191,15 @@ * * # echo '' >/sys/kernel/config/xe/0000:03:00.0/gt_types_allowed
*
- * Allowed engines:
- * ----------------
- *
- * Allow only a set of engine(s) to be available, disabling the other engines
- * even if they are available in hardware. This is applied after HW fuses are
- * considered on each tile. Examples:
- *
- * Allow only one render and one copy engines, nothing else::
- *
- * # echo 'rcs0,bcs0' > /sys/kernel/config/xe/0000:03:00.0/engines_allowed
- *
- * Allow only compute engines and first copy engine::
- *
- * # echo 'ccs*,bcs0' > /sys/kernel/config/xe/0000:03:00.0/engines_allowed
+ * Enable multi-queue
+ * ------------------
*
- * Note that the engine names are the per-GT hardware names. On multi-tile
- * platforms, writing ``rcs0,bcs0`` to this file would allow the first render
- * and copy engines on each tile.
+ * Multi-queue support on the device is enabled by default where the
+ * hardware supports it. Writing 0 force-disables multi-queue support:
+ * multi-queue exec-queue group creation via ioctl is refused, and the
+ * GuC feature is disabled::
*
- * The requested configuration may not be supported by the platform and driver
- * may fail to probe. For example: if at least one copy engine is expected to be
- * available for migrations, but it's disabled. This is intended for debugging
- * purposes only.
+ * # echo 0 > /sys/kernel/config/xe/0000:03:00.0/enable_multi_queue
*
* This attribute can only be set before binding to the device. *drivers/gpu/drm/xe/xe_configfs.c +0
-4@@ -159,57 +215,15 @@ * * This attribute can only be set before binding to the device. * - * Context restore BB - * ------------------ - * - * Allow to execute a batch buffer during any context switches.When the
- * GPU is restoring the context, it executes additional commands. It's useful
- * for testing additional workarounds and validating certain HW
behaviors: it's
- * not intended for normal execution and will taint the kernel withTAINT_TEST
- * when used.
- *
- * The syntax allows to pass straight instructions to be executed by the engine
- * in a batch buffer or set specific registers.
- *
- * #. Generic instruction::
- *
- * <engine-class> cmd <instr> [[dword0] [dword1] [...]]
- *
- * #. Simple register setting::
- *
- * <engine-class> reg <address> <value>
- *
- * Commands are saved per engine class: all instances of that class will execute
- * those commands during context switch. The instruction, dword arguments,
- * addresses and values are in hex format like in the examples below.
- *
- * #. Execute a LRI command to write0xDEADBEEFto register0x4f10after the
- * normal context restore::
- *
- * # echo 'rcs cmd 11000001 4F100 DEADBEEF' \
- * > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_post_bb
- *
- * #. Execute a LRI command to write0xDEADBEEFto register0x4f10at the
- * beginning of the context restore::
- *
- * # echo 'rcs cmd 11000001 4F100 DEADBEEF' \
- * > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_mid_bb
-
- * #. Load certain values in a couple of registers (it can be used as a simpler
- * alternative to thecmd) action::
- *
- * # cat > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_post_bb <<EOF
- * rcs reg 4F100 DEADBEEF
- * rcs reg 4F104 FFFFFFFF
- * EOF
+ * Survivability mode:
+ * -------------------
*
- * .. note::
+ * Enable survivability mode on supported cards. This setting only takes
+ * effect when probing the device. Example to enable it::
*
- * When using multiple lines, make sure to use a command that is
- * implemented with a single write syscall, like HEREDOC.
+ * # echo 1 > /sys/kernel/config/xe/0000:03:00.0/survivability_mode
*
- * Currently this is implemented only for post and mid context restore and
- * these attributes can only be set before binding to the device.
+ * This attribute can only be set before binding to the device. *
* Max SR-IOV Virtual Functions
* ----------------------------drivers/gpu/drm/xe/xe_configfs.c +0
-4@@ -237,18 +251,6 @@ * * This setting only takes effect when probing the device. * - * Enable multi-queue - * ------------------ - * - * Multi-queue support on the device is enabled by default wherethe
- * hardware supports it. Writing 0 force-disables multi-queue support:
- * multi-queue exec-queue group creation via ioctl is refused, and the
- * GuC feature is disabled::
- *
- * # echo 0 > /sys/kernel/config/xe/0000:03:00.0/enable_multi_queue
- *
- * This attribute can only be set before binding to the device.
- *
* Remove devices
* ==============
*drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -267,14 +269,19 @@ struct xe_config_group_device { struct config_group group; struct config_group sriov;
+ /*
+ * Fields sorted by type (largest first) then name: struct arrays,
+ * u64, u32/unsigned int, u8, bool, sub-structs last. Within each
+ * type, entries are sorted alphabetically.
+ */
structxe_config_device{
- u64gt_types_allowed;
- u64engines_allowed;
- structwa_bbctx_restore_post_bb[XE_ENGINE_CLASS_MAX];
structwa_bbctx_restore_mid_bb[XE_ENGINE_CLASS_MAX];
- boolsurvivability_mode;
- boolenable_psmi;
+ structwa_bbctx_restore_post_bb[XE_ENGINE_CLASS_MAX];
+ u64engines_allowed;
+ u64gt_types_allowed;
boolenable_multi_queue;
+ boolenable_psmi;
+ boolsurvivability_mode;
struct {
unsigned intmax_vfs;
booladmin_only_pf;drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -290,11 +297,11 @@ struct xe_config_group_device { };
static const structxe_config_devicedevice_defaults= { - .gt_types_allowed =U64_MAX, .engines_allowed =U64_MAX,
- .survivability_mode = false,
- .enable_psmi = false,
+ .gt_types_allowed =U64_MAX, .enable_multi_queue = true,
+ .enable_psmi = false,
+ .survivability_mode = false,
.sriov = {
.max_vfs =XE_DEFAULT_MAX_VFS, .admin_only_pf =XE_DEFAULT_ADMIN_ONLY_PF,drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -371,247 +378,60 @@ static bool is_bound(struct xe_config_group_device *dev) return ret; }
-staticssize_tsurvivability_mode_show(struct config_item *item, char *page)drivers/gpu/drm/xe/xe_configfs.c +1
-5-{ - struct xe_config_device *dev = to_xe_config_device(item); - - return sprintf(page, "%d\n", dev->survivability_mode); -} +static struct xe_config_group_device*find_xe_config_group_device(struct
pci_dev*pdev);
-staticssize_tsurvivability_mode_store(struct config_item *item, const char *page, size_t len)
+/**
+ *xe_configfs_get_ctx_restore_mid_bb- get configfsctx_restore_mid_bbsetting
+ * @pdev: pci device
+ * @class: hw engine class
+ * @cs: pointer to the bb to use - only valid during probe
+ *
+ * Return: Number of dwords used in themid_ctx_restoresetting in configfs
+ */
+u32 xe_configfs_get_ctx_restore_mid_bb(structpci_dev*pdev, + enumxe_engine_classclass, + const u32 **cs)
{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
- boolsurvivability_mode;
- int ret;
+ structxe_config_group_device*dev =find_xe_config_group_device(pdev);
+ u32 len;
- ret =kstrtobool(page, &survivability_mode);
- if (ret)
- return ret;
+ if (!dev)
+ return 0;
- guard(mutex)(&dev->lock);
- if (is_bound(dev))
- return-EBUSY;
+ scoped_guard(mutex,&dev->lock) {
+ if (cs)
+ *cs = dev-Quoted 1 line
config.ctx_restore_mid_bb[class].cs;
- dev->config.survivability_mode =survivability_mode; + len = dev->config.ctx_restore_mid_bb[class].len; + }
+ config_group_put(&dev->group);
return len;
}
-staticssize_tgt_types_allowed_show(struct config_item *item, char *page)
+/**
+ *xe_configfs_get_ctx_restore_post_bb- get configfsctx_restore_post_bbsetting
+ * @pdev: pci device
+ * @class: hw engine class
+ * @cs: pointer to the bb to use - only valid during probe
+ *
+ * Return: Number of dwords used in thepost_ctx_restoresetting in configfs
+ */
+u32 xe_configfs_get_ctx_restore_post_bb(structpci_dev*pdev, + enumxe_engine_classclass, + const u32 **cs) {
- structxe_config_device*dev =to_xe_config_device(item); - char *p = page;
-
- for (size_ti = 0; i <ARRAY_SIZE(gt_types); i++) - if (dev->gt_types_allowed&BIT_ULL(gt_types[i].type))
- p +=sprintf(p, "%s\n", gt_types[i].name); + structxe_config_group_device*dev =find_xe_config_group_device(pdev);
+ u32 len;
- return p - page;
-}
+ if (!dev)
+ return 0;
-staticssize_tgt_types_allowed_store(structconfig_item*item, const char *page,
-size_tlen)
-{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
- char *buf__free(kfree)=kstrdup(page, GFP_KERNEL); - char *p = buf;
- u64 typemask = 0;drivers/gpu/drm/xe/xe_configfs.c +0
-13- - if (!buf) - return -ENOMEM; - - while (p) { - char *typename = strsep(&p, ",\n"); - bool matched = false; - - if (typename[0] == '\0') - continue; - - for (size_t i = 0; i < ARRAY_SIZE(gt_types); i++) { - if (strcmp(typename, gt_types[i].name) ==0) {
- typemask |=BIT(gt_types[i].type); - matched = true;
- break;
- }
- }drivers/gpu/drm/xe/xe_configfs.c +0
-15- - if (!matched) - return -EINVAL; - } - - guard(mutex)(&dev->lock); - if (is_bound(dev)) - return -EBUSY; - - dev->config.gt_types_allowed = typemask; - - return len; -} - -static ssize_t engines_allowed_show(struct config_item *item, char*page)
drivers/gpu/drm/xe/xe_configfs.c +0
-9-{ - struct xe_config_device *dev = to_xe_config_device(item); - char *p = page; - - for (size_t i = 0; i < ARRAY_SIZE(engine_info); i++) { - u64 mask = engine_info[i].mask; - - if ((dev->engines_allowed & mask) == mask) { - p += sprintf(p, "%s*\n",engine_info[i].cls);
- } else if (mask &dev->engines_allowed) { - u16 bit0 =__ffs64(mask), bit;drivers/gpu/drm/xe/xe_configfs.c +0
-4- - mask &= dev->engines_allowed; - - for_each_set_bit(bit, (const unsigned long*)&mask, 64)
- p += sprintf(p, "%s%u\n", engine_info[i].cls,
- bit - bit0); - }
- }drivers/gpu/drm/xe/xe_configfs.c +0
-6- - return p - page; -} - -/* -* Lookup engine_info. If @mask is not NULL, reduce the mask according to the
- * instance in @pattern.
- *
- * Examples of inputs:
- * -lookup_engine_info("rcs0", &mask): return "rcs" entry from @engine_info and
- * mask ==BIT_ULL(XE_HW_ENGINE_RCS0)
- * -lookup_engine_info("rcs*", &mask): return "rcs" entry from @engine_info and
- * mask ==XE_HW_ENGINE_RCS_MASK
- * -lookup_engine_info("rcs", NULL): return "rcs" entry from @engine_info
- */
-static const structengine_info*lookup_engine_info(const char *pattern, u64 *mask)drivers/gpu/drm/xe/xe_configfs.c +0
-32-{ - for (size_t i = 0; i < ARRAY_SIZE(engine_info); i++) { - u8 instance; - u16 bit; - - if (!str_has_prefix(pattern, engine_info[i].cls)) - continue; - - pattern += strlen(engine_info[i].cls); - if (!mask) - return *pattern ? NULL : &engine_info[i]; - - if (!strcmp(pattern, "*")) { - *mask = engine_info[i].mask; - return &engine_info[i]; - } - - if (kstrtou8(pattern, 10, &instance)) - return NULL; - - bit = __ffs64(engine_info[i].mask) + instance; - if (bit >= fls64(engine_info[i].mask)) - return NULL; - - *mask = BIT_ULL(bit); - return &engine_info[i]; - } - - return NULL; -} - -static int parse_engine(const char *s, const char *end_chars, u64*mask,
- const structengine_info**pinfo)drivers/gpu/drm/xe/xe_configfs.c +1
-23-{ - char buf[MAX_ENGINE_CLASS_CHARS + MAX_ENGINE_INSTANCE_CHARS + 1]; - const struct engine_info *info; - size_t len; - - len = strcspn(s, end_chars); - if (len >= sizeof(buf)) - return -EINVAL; - - memcpy(buf, s, len); - buf[len] = '\0'; - - info = lookup_engine_info(buf, mask); - if (!info) - return -ENOENT; - - if (pinfo) - *pinfo = info; - - return len; -} - -static ssize_t engines_allowed_store(struct config_item *item,const char *page,
-size_tlen)
-{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
- ssize_t patternlen, p;
- u64 mask, val = 0;
-
- for (p = 0; p < len; p += patternlen + 1) {
- patternlen =parse_engine(page + p, ",\n", &mask, NULL);
- if (patternlen < 0)
- return-EINVAL;
-
- val |= mask;
+ scoped_guard(mutex,&dev->lock) {
+ *cs = dev->config.ctx_restore_post_bb[class].cs; + len = dev->config.ctx_restore_post_bb[class].len; }drivers/gpu/drm/xe/xe_configfs.c +0
-11- - guard(mutex)(&dev->lock); - if (is_bound(dev)) - return -EBUSY; - - dev->config.engines_allowed = val; - - return len; -} - -static ssize_t enable_psmi_show(struct config_item *item, char*page)
drivers/gpu/drm/xe/xe_configfs.c +0
-7-{ - struct xe_config_device *dev = to_xe_config_device(item); - - return sprintf(page, "%d\n", dev->enable_psmi); -} - -static ssize_t enable_psmi_store(struct config_item *item, constchar *page,
size_tlen)
-{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
- bool val;
- int ret;drivers/gpu/drm/xe/xe_configfs.c +0
-15- - ret = kstrtobool(page, &val); - if (ret) - return ret; - - guard(mutex)(&dev->lock); - if (is_bound(dev)) - return -EBUSY; - - dev->config.enable_psmi = val; - - return len; -} - -static ssize_t enable_multi_queue_show(struct config_item *item,char *page)
drivers/gpu/drm/xe/xe_configfs.c +0
-7-{ - struct xe_config_device *dev = to_xe_config_device(item); - - return sprintf(page, "%d\n", dev->enable_multi_queue); -} - -static ssize_t enable_multi_queue_store(struct config_item *item,const char *page,
- size_t len) -{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
- bool val;
- int ret;drivers/gpu/drm/xe/xe_configfs.c +1
-10- - ret = kstrtobool(page, &val); - if (ret) - return ret; - - guard(mutex)(&dev->lock); - if (is_bound(dev)) - return -EBUSY; - - dev->config.enable_multi_queue = val; + config_group_put(&dev->group);
return len;
}drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -718,6 +538,9 @@ static ssize_t parse_hex(const char *line, u32 *pval) return p - line; }
+static int parse_engine(const char *s, const char*end_chars, u64 *mask,
+ const structengine_info**pinfo); +
/*
* Parse lines with the format
*drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -802,70 +625,439 @@ static ssize_t wa_bb_store(struct wa_bb wa_bb[static XE_ENGINE_CLASS_MAX], return count;
guard(mutex)(&dev->lock);drivers/gpu/drm/xe/xe_configfs.c +6
-1- + + if (is_bound(dev)) + return -EBUSY; + + /* +* 2. Allocate a u32 array and set the pointers to the right positions
+ * according to the length of each class'wa_bb+ */
+ tmp =krealloc(wa_bb[0].cs, count * sizeof(u32), GFP_KERNEL);
+ if (!tmp)
+ return-ENOMEM;drivers/gpu/drm/xe/xe_configfs.c +14
-0+ + if (!count) { + memset(wa_bb, 0, sizeof(tmp_wa_bb)); + return len; + } + + for (class = 0, count = 0; class < XE_ENGINE_CLASS_MAX; ++class) { + tmp_wa_bb[class].cs = tmp + count; + count += tmp_wa_bb[class].len; + tmp_wa_bb[class].len = 0; + } + + /* 3. Parse wa_bb lines again, this time saving the values*/
+ count =parse_wa_bb_lines(page, tmp_wa_bb); + if (count < 0)
+ return count;drivers/gpu/drm/xe/xe_configfs.c +8
-0+ + memcpy(wa_bb, tmp_wa_bb, sizeof(tmp_wa_bb)); + + return len; +} + +static ssize_t ctx_restore_mid_bb_store (struct config_item *item, + const char *data, size_tsz)
+{
+ structxe_config_group_device*dev =to_xe_config_group_device(item);
+
+ returnwa_bb_store(dev->config.ctx_restore_mid_bb, dev, data, sz);drivers/gpu/drm/xe/xe_configfs.c +4
-0+} + +static ssize_t ctx_restore_post_bb_store (struct config_item *item, + const char *data, size_tsz)
+{
+ structxe_config_group_device*dev =to_xe_config_group_device(item);
+
+ returnwa_bb_store(dev->config.ctx_restore_post_bb, dev, data, sz);drivers/gpu/drm/xe/xe_configfs.c +4
-0+} + +/** +* xe_configfs_get_engines_allowed - get engine allowed mask from configfs
+ * @pdev: pci device
+ *
+ * Return: engine mask with allowed engines set in configfs
+ */drivers/gpu/drm/xe/xe_configfs.c +3
-0+u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) +{ + struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
+ u64engines_allowed;drivers/gpu/drm/xe/xe_configfs.c +12
-0+ + if (!dev) + return device_defaults.engines_allowed; + + scoped_guard(mutex, &dev->lock) + engines_allowed = dev->config.engines_allowed; + config_group_put(&dev->group); + + return engines_allowed; +} + +static ssize_t engines_allowed_show(struct config_item *item, char*page)
drivers/gpu/drm/xe/xe_configfs.c +9
-0+{ + struct xe_config_device *dev = to_xe_config_device(item); + char *p = page; + + for (size_t i = 0; i < ARRAY_SIZE(engine_info); i++) { + u64 mask = engine_info[i].mask; + + if ((dev->engines_allowed & mask) == mask) { + p += sprintf(p, "%s*\n",engine_info[i].cls);
+ } else if (mask &dev->engines_allowed) { + u16 bit0 =__ffs64(mask), bit;drivers/gpu/drm/xe/xe_configfs.c +4
-0+ + mask &= dev->engines_allowed; + + for_each_set_bit(bit, (const unsigned long*)&mask, 64)
+ p += sprintf(p, "%s%u\n", engine_info[i].cls,
+ bit - bit0); + }
+ }drivers/gpu/drm/xe/xe_configfs.c +6
-0+ + return p - page; +} + +/* +* Lookup engine_info. If @mask is not NULL, reduce the mask according to the
+ * instance in @pattern.
+ *
+ * Examples of inputs:
+ * -lookup_engine_info("rcs0", &mask): return "rcs" entry from @engine_info and
+ * mask ==BIT_ULL(XE_HW_ENGINE_RCS0)
+ * -lookup_engine_info("rcs*", &mask): return "rcs" entry from @engine_info and
+ * mask ==XE_HW_ENGINE_RCS_MASK
+ * -lookup_engine_info("rcs", NULL): return "rcs" entry from @engine_info
+ */
+static const structengine_info*lookup_engine_info(const char *pattern, u64 *mask)drivers/gpu/drm/xe/xe_configfs.c +32
-0+{ + for (size_t i = 0; i < ARRAY_SIZE(engine_info); i++) { + u8 instance; + u16 bit; + + if (!str_has_prefix(pattern, engine_info[i].cls)) + continue; + + pattern += strlen(engine_info[i].cls); + if (!mask) + return *pattern ? NULL : &engine_info[i]; + + if (!strcmp(pattern, "*")) { + *mask = engine_info[i].mask; + return &engine_info[i]; + } + + if (kstrtou8(pattern, 10, &instance)) + return NULL; + + bit = __ffs64(engine_info[i].mask) + instance; + if (bit >= fls64(engine_info[i].mask)) + return NULL; + + *mask = BIT_ULL(bit); + return &engine_info[i]; + } + + return NULL; +} + +static int parse_engine(const char *s, const char *end_chars, u64*mask,
+ const structengine_info**pinfo)drivers/gpu/drm/xe/xe_configfs.c +24
-0+{ + char buf[MAX_ENGINE_CLASS_CHARS + MAX_ENGINE_INSTANCE_CHARS + 1]; + const struct engine_info *info; + size_t len; + + len = strcspn(s, end_chars); + if (len >= sizeof(buf)) + return -EINVAL; + + memcpy(buf, s, len); + buf[len] = '\0'; + + info = lookup_engine_info(buf, mask); + if (!info) + return -ENOENT; + + if (pinfo) + *pinfo = info; + + return len; +} + +static ssize_t engines_allowed_store(struct config_item *item,const char *page,
+size_tlen)
+{
+ structxe_config_group_device*dev =to_xe_config_group_device(item);
+ ssize_t patternlen, p;
+ u64 mask, val = 0;
+
+ for (p = 0; p < len; p += patternlen + 1) {
+ patternlen =parse_engine(page + p, ",\n", &mask, NULL);
+ if (patternlen < 0)
+ return-EINVAL;drivers/gpu/drm/xe/xe_configfs.c +16
-0+ + val |= mask; + } + + guard(mutex)(&dev->lock); + if (is_bound(dev)) + return -EBUSY; + + dev->config.engines_allowed = val; + + return len; +} + +static u64 get_gt_types_allowed (struct pci_dev *pdev) +{ + struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
+ u64 mask;drivers/gpu/drm/xe/xe_configfs.c +13
-0+ + if (!dev) + return device_defaults.gt_types_allowed; + + scoped_guard(mutex, &dev->lock) + mask = dev->config.gt_types_allowed; + config_group_put(&dev->group); + + return mask; +} + +/** +* xe_configfs_primary_gt_allowed - determine whether primary GTs are supported
+ * @pdev: pci device
+ *
+ * Return: True if primary GTs are enabled, false if they have been disabled via
+ * configfs.
+ */drivers/gpu/drm/xe/xe_configfs.c +3
-0+bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) +{ + return get_gt_types_allowed(pdev) &
BIT_ULL(XE_GT_TYPE_MAIN);drivers/gpu/drm/xe/xe_configfs.c +4
-0+} + +/** +* xe_configfs_media_gt_allowed - determine whether media GTs are supported
+ * @pdev: pci device
+ *
+ * Return: True if the media GTs are enabled, false if they have been disabled
+ * via configfs.
+ */drivers/gpu/drm/xe/xe_configfs.c +3
-0+bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) +{ + return get_gt_types_allowed(pdev) &
BIT_ULL(XE_GT_TYPE_MEDIA);drivers/gpu/drm/xe/xe_configfs.c +3
-0+} + +static ssize_t gt_types_allowed_show(struct config_item *item,char *page)
drivers/gpu/drm/xe/xe_configfs.c +6
-0+{ + struct xe_config_device *dev = to_xe_config_device(item); + char *p = page; + + for (size_t i = 0; i < ARRAY_SIZE(gt_types); i++) + if (dev->gt_types_allowed &
BIT_ULL(gt_types[i].type))
+ p +=sprintf(p, "%s\n", gt_types[i].name);drivers/gpu/drm/xe/xe_configfs.c +5
-0+ + return p - page; +} + +static ssize_t gt_types_allowed_store(struct config_item *item,const char *page,
+size_tlen) +{
+ structxe_config_group_device*dev =to_xe_config_group_device(item);
+ char *buf__free(kfree)=kstrdup(page, GFP_KERNEL); + char *p = buf;
+ u64 typemask = 0;drivers/gpu/drm/xe/xe_configfs.c +13
-0+ + if (!buf) + return -ENOMEM; + + while (p) { + char *typename = strsep(&p, ",\n"); + bool matched = false; + + if (typename[0] == '\0') + continue; + + for (size_t i = 0; i < ARRAY_SIZE(gt_types); i++) { + if (strcmp(typename, gt_types[i].name) ==0) {
+ typemask |=BIT(gt_types[i].type); + matched = true;
+ break;
+ }
+ }drivers/gpu/drm/xe/xe_configfs.c +16
-0+ + if (!matched) + return -EINVAL; + } + + guard(mutex)(&dev->lock); + if (is_bound(dev)) + return -EBUSY; + + dev->config.gt_types_allowed = typemask; + + return len; +} + +/** +* xe_configfs_get_enable_multi_queue - get configfs
enable_multi_queuesetting
+ * @pdev: pci device
+ *
+ * Return: true if multi-queue is enabled for this device (the default),
+ * false if it has been force-disabled via configfs.
+ */drivers/gpu/drm/xe/xe_configfs.c +3
-0+bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) +{ + struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
+ bool ret;drivers/gpu/drm/xe/xe_configfs.c +12
-0+ + if (!dev) + return true; + + scoped_guard(mutex, &dev->lock) + ret = dev->config.enable_multi_queue; + config_group_put(&dev->group); + + return ret; +} + +static ssize_t enable_multi_queue_show(struct config_item *item,char *page)
drivers/gpu/drm/xe/xe_configfs.c +7
-0+{ + struct xe_config_device *dev = to_xe_config_device(item); + + return sprintf(page, "%d\n", dev->enable_multi_queue); +} + +static ssize_t enable_multi_queue_store(struct config_item *item,const char *page,
+ size_t len) +{
+ structxe_config_group_device*dev =to_xe_config_group_device(item);
+ bool val;
+ int ret;drivers/gpu/drm/xe/xe_configfs.c +23
-0+ + ret = kstrtobool(page, &val); + if (ret) + return ret; + + guard(mutex)(&dev->lock); + if (is_bound(dev)) + return -EBUSY; + + dev->config.enable_multi_queue = val; + + return len; +} + +/** +* xe_configfs_get_psmi_enabled - get configfs enable_psmi setting +* @pdev: pci device +* +* Return: enable_psmi setting in configfs +*/ +bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) +{ + struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
+ bool ret;drivers/gpu/drm/xe/xe_configfs.c +12
-0+ + if (!dev) + return false; + + scoped_guard(mutex, &dev->lock) + ret = dev->config.enable_psmi; + config_group_put(&dev->group); + + return ret; +} + +static ssize_t enable_psmi_show(struct config_item *item, char*page)
drivers/gpu/drm/xe/xe_configfs.c +7
-0+{ + struct xe_config_device *dev = to_xe_config_device(item); + + return sprintf(page, "%d\n", dev->enable_psmi); +} + +static ssize_t enable_psmi_store(struct config_item *item, constchar *page,
size_tlen)
+{
+ structxe_config_group_device*dev =to_xe_config_group_device(item);
+ bool val;
+ int ret;drivers/gpu/drm/xe/xe_configfs.c +6
-0+ + ret = kstrtobool(page, &val); + if (ret) + return ret; + + guard(mutex)(&dev->lock);if (
is_bound(dev))
return-EBUSY;
- /*
- * 2. Allocate a u32 array and set the pointers to the right positions
- * according to the length of each class'wa_bb- */
- tmp =krealloc(wa_bb[0].cs, count * sizeof(u32), GFP_KERNEL);
- if (!tmp)
- return-ENOMEM;
+ dev->config.enable_psmi = val;
- if (!count) {
- memset(wa_bb, 0,sizeof(tmp_wa_bb));
- return len;
- }
+ return len;
+}
- for (class = 0, count = 0; class <XE_ENGINE_CLASS_MAX; ++class) {
- tmp_wa_bb[class].cs = tmp + count;
- count += tmp_wa_bb[class].len;
- tmp_wa_bb[class].len = 0;
- }
+/**
+ *xe_configfs_get_survivability_mode- get configfs survivability mode attribute
+ * @pdev: pci device
+ *
+ * Return:survivability_modeattribute in configfs
+ */drivers/gpu/drm/xe/xe_configfs.c +3
-0+bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) +{ + struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
+ bool mode;
- /* 3. Parsewa_bblines again, this time saving the values */
- count =parse_wa_bb_lines(page, tmp_wa_bb);
- if (count < 0)
- return count;
+ if (!dev)
+ return device_defaults.survivability_mode;
- memcpy(wa_bb,tmp_wa_bb,sizeof(tmp_wa_bb));
+ scoped_guard(mutex,&dev->lock)
+ mode =dev->config.survivability_mode;
+ config_group_put(&dev->group);
- return len;
+ return mode;
}
-staticssize_tctx_restore_mid_bb_store(structconfig_item*item, - const char *data,size_tsz)
+staticssize_tsurvivability_mode_show(struct config_item *item, char *page)
{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
+ structxe_config_device*dev =to_xe_config_device(item);
- returnwa_bb_store(dev->config.ctx_restore_mid_bb, dev, data, sz);
+ returnsprintf(page, "%d\n", dev->survivability_mode); }
-staticssize_tctx_restore_post_bb_store(structconfig_item*item, - const char *data,size_tsz)
+staticssize_tsurvivability_mode_store(struct config_item *item, const char *page, size_t len)
{
structxe_config_group_device*dev =to_xe_config_group_device(item);
+ boolsurvivability_mode;
+ int ret;
- returnwa_bb_store(dev->config.ctx_restore_post_bb, dev, data, sz);
+ ret =kstrtobool(page, &survivability_mode);
+ if (ret)
+ return ret;drivers/gpu/drm/xe/xe_configfs.c +8
-0+ + guard(mutex)(&dev->lock); + if (is_bound(dev)) + return -EBUSY; + + dev->config.survivability_mode = survivability_mode; + + return len;}
CONFIGFS_ATTR(,ctx_restore_mid_bb);
CONFIGFS_ATTR(,ctx_restore_post_bb);drivers/gpu/drm/xe/xe_configfs.c +0
-2-CONFIGFS_ATTR(, enable_multi_queue); -CONFIGFS_ATTR(, enable_psmi);CONFIGFS_ATTR(,
engines_allowed);
CONFIGFS_ATTR(,gt_types_allowed);drivers/gpu/drm/xe/xe_configfs.c +2
-0+CONFIGFS_ATTR(, enable_multi_queue); +CONFIGFS_ATTR(, enable_psmi);CONFIGFS_ATTR(,
survivability_mode);
static structconfigfs_attribute*xe_config_device_attrs[] = {&attr_ctx_restore_mid_bb,&attr_ctx_restore_post_bb,
- &attr_enable_multi_queue,
- &attr_enable_psmi,
&attr_engines_allowed,&attr_gt_types_allowed,
+ &attr_enable_multi_queue,
+ &attr_enable_psmi,
&attr_survivability_mode,
NULL,
};drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1138,8 +1330,8 @@ static void dump_custom_dev_config(structpci_dev *pdev, dev->config.attr_); \ } while (0)
- PRI_CUSTOM_ATTR("%llx",gt_types_allowed);PRI_CUSTOM_ATTR("%llx", engines_allowed); + PRI_CUSTOM_ATTR("%llx",gt_types_allowed);PRI_CUSTOM_ATTR("%d", enable_multi_queue);PRI_CUSTOM_ATTR("%d", enable_psmi);PRI_CUSTOM_ATTR("%d", survivability_mode);drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1171,186 +1363,6 @@ void xe_configfs_check_device(struct pci_dev *pdev) config_group_put(&dev->group); }
-/**
- *xe_configfs_get_survivability_mode- get configfs survivability mode attribute
- * @pdev: pci device
- *
- * Return:survivability_modeattribute in configfs
- */drivers/gpu/drm/xe/xe_configfs.c +0
-3-bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- bool mode;drivers/gpu/drm/xe/xe_configfs.c +0
-14- - if (!dev) - return device_defaults.survivability_mode; - - scoped_guard(mutex, &dev->lock) - mode = dev->config.survivability_mode; - config_group_put(&dev->group); - - return mode; -} - -static u64 get_gt_types_allowed (struct pci_dev *pdev) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- u64 mask;drivers/gpu/drm/xe/xe_configfs.c +0
-13- - if (!dev) - return device_defaults.gt_types_allowed; - - scoped_guard(mutex, &dev->lock) - mask = dev->config.gt_types_allowed; - config_group_put(&dev->group); - - return mask; -} - -/** -* xe_configfs_primary_gt_allowed - determine whether primary GTs are supported
- * @pdev: pci device
- *
- * Return: True if primary GTs are enabled, false if they have been disabled via
- * configfs.
- */drivers/gpu/drm/xe/xe_configfs.c +0
-3-bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) -{ - return get_gt_types_allowed(pdev) &
BIT_ULL(XE_GT_TYPE_MAIN);drivers/gpu/drm/xe/xe_configfs.c +0
-4-} - -/** -* xe_configfs_media_gt_allowed - determine whether media GTs are supported
- * @pdev: pci device
- *
- * Return: True if the media GTs are enabled, false if they have been disabled
- * via configfs.
- */drivers/gpu/drm/xe/xe_configfs.c +0
-3-bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) -{ - return get_gt_types_allowed(pdev) &
BIT_ULL(XE_GT_TYPE_MEDIA);drivers/gpu/drm/xe/xe_configfs.c +0
-4-} - -/** -* xe_configfs_get_engines_allowed - get engine allowed mask from configfs
- * @pdev: pci device
- *
- * Return: engine mask with allowed engines set in configfs
- */drivers/gpu/drm/xe/xe_configfs.c +0
-3-u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- u64engines_allowed;drivers/gpu/drm/xe/xe_configfs.c +0
-20- - if (!dev) - return device_defaults.engines_allowed; - - scoped_guard(mutex, &dev->lock) - engines_allowed = dev->config.engines_allowed; - config_group_put(&dev->group); - - return engines_allowed; -} - -/** -* xe_configfs_get_psmi_enabled - get configfs enable_psmi setting -* @pdev: pci device -* -* Return: enable_psmi setting in configfs -*/ -bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- bool ret;drivers/gpu/drm/xe/xe_configfs.c +0
-13- - if (!dev) - return false; - - scoped_guard(mutex, &dev->lock) - ret = dev->config.enable_psmi; - config_group_put(&dev->group); - - return ret; -} - -/** -* xe_configfs_get_enable_multi_queue - get configfs
enable_multi_queuesetting
- * @pdev: pci device
- *
- * Return: true if multi-queue is enabled for this device (the default),
- * false if it has been force-disabled via configfs.
- */drivers/gpu/drm/xe/xe_configfs.c +0
-3-bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- bool ret;drivers/gpu/drm/xe/xe_configfs.c +0
-13- - if (!dev) - return true; - - scoped_guard(mutex, &dev->lock) - ret = dev->config.enable_multi_queue; - config_group_put(&dev->group); - - return ret; -} - -/** -* xe_configfs_get_ctx_restore_mid_bb - get configfs
ctx_restore_mid_bbsetting
- * @pdev: pci device
- * @class: hw engine class
- * @cs: pointer to the bb to use - only valid during probe
- *
- * Return: Number of dwords used in themid_ctx_restoresetting in configfs
- */drivers/gpu/drm/xe/xe_configfs.c +0
-5-u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, - enum xe_engine_class class, - const u32 **cs) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- u32 len;drivers/gpu/drm/xe/xe_configfs.c +0
-7- - if (!dev) - return 0; - - scoped_guard(mutex, &dev->lock) { - if (cs) - *cs = dev-Quoted 1 line
config.ctx_restore_mid_bb[class].cs;
drivers/gpu/drm/xe/xe_configfs.c +0
-10- - len = dev->config.ctx_restore_mid_bb[class].len; - } - config_group_put(&dev->group); - - return len; -} - -/** -* xe_configfs_get_ctx_restore_post_bb - get configfs
ctx_restore_post_bbsetting
- * @pdev: pci device
- * @class: hw engine class
- * @cs: pointer to the bb to use - only valid during probe
- *
- * Return: Number of dwords used in thepost_ctx_restoresetting in configfs
- */drivers/gpu/drm/xe/xe_configfs.c +0
-5-u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, - enum xe_engine_class class, - const u32 **cs) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- u32 len;drivers/gpu/drm/xe/xe_configfs.c +0
-13- - if (!dev) - return 0; - - scoped_guard(mutex, &dev->lock) { - *cs = dev->config.ctx_restore_post_bb[class].cs; - len = dev->config.ctx_restore_post_bb[class].len; - } - config_group_put(&dev->group); - - return len; -} -#ifdef
CONFIG_PCI_IOV
/**
*xe_configfs_admin_only_pf()- Get PF's operational mode.drivers/gpu/drm/xe/xe_configfs.h +6
-12@@ -18,18 +18,18 @@ struct pci_dev; int xe_configfs_init(void); void xe_configfs_exit(void); void xe_configfs_check_device(struct pci_dev *pdev); -bool xe_configfs_get_survivability_mode (struct pci_dev *pdev); -bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev); -bool xe_configfs_media_gt_allowed (struct pci_dev *pdev); -u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev); -bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev); -bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev); u32 xe_configfs_get_ctx_restore_mid_bb(struct pci_dev *pdev, enum xe_engine_class class, const u32 **cs); u32 xe_configfs_get_ctx_restore_post_bb(struct pci_dev *pdev, enum xe_engine_class class, const u32 **cs); +u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev); +bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev); +bool xe_configfs_media_gt_allowed (struct pci_dev *pdev); +bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev); +bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev); +bool xe_configfs_get_survivability_mode (struct pci_dev *pdev); #ifdef CONFIG_PCI_IOV unsigned int xe_configfs_get_max_vfs(struct pci_dev *pdev); bool xe_configfs_admin_only_pf(struct pci_dev *pdev);@@ -38,18 +38,18 @@ bool xe_configfs_admin_only_pf(struct pci_dev *pdev); static inline int xe_configfs_init(void) { return 0; } static inline void xe_configfs_exit(void) { } static inline void xe_configfs_check_device(struct pci_dev *pdev) { } -static inline bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) { return false; } -static inline bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) { return true; } -static inline bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) { return true; } -static inline u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) { return U64_MAX; } -static inline bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) { return false; } -static inline bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) { return true; }static inline u32 xe_configfs_get_ctx_restore_mid_bb(struct
pci_dev*pdev,
enumxe_engine_classclass,
const u32 **cs) { return 0; }
static inline u32 xe_configfs_get_ctx_restore_post_bb(structpci_dev*pdev,
enumxe_engine_classclass,
const u32 **cs) { return 0; }
+static inline u64xe_configfs_get_engines_allowed(struct pci_dev *pdev){ returnU64_MAX; }
+static inline boolxe_configfs_primary_gt_allowed(struct pci_dev *pdev){ return true; }
+static inline boolxe_configfs_media_gt_allowed(struct pci_dev *pdev){ return true; }
+static inline boolxe_configfs_get_enable_multi_queue(struct pci_dev *pdev){ return true; }
+static inline boolxe_configfs_get_psmi_enabled(struct pci_dev *pdev){ return false; }
+static inline boolxe_configfs_get_survivability_mode(struct pci_dev *pdev){ return false; }
#ifdefCONFIG_PCI_IOV
static inline unsigned intxe_configfs_get_max_vfs(struct pci_dev *pdev)
{Signature · 1 line
2.43.0
PATCH 3/10 drm/xe: Split out configfs data structures
In reply to Stuart SummersPlanning on moving debug specific configfs parameters to their own file in a future patch. In preparation for that change, move the structures in xe_configfs.c to a new _types.h file so we can easily access them in the different configfs files.
Doing that separately here instead of combining with the patch that adds the debug file for ease of review.
--- drivers/gpu/drm/xe/xe_configfs.c | 41 -------------------- drivers/gpu/drm/xe/xe_configfs.h | 2 +- drivers/gpu/drm/xe/xe_configfs_types.h | 53 ++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 42 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_configfs_types.h
drivers/gpu/drm/xe/xe_configfs.c +0 -41
@@ -4,7 +4,6 @@*/ #include <linux/bitops.h> -#include <linux/ctype.h> #include <linux/configfs.h> #include <linux/cleanup.h> #include <linux/find.h>
@@ -17,10 +16,7 @@#include "xe_configfs.h" #include "xe_defaults.h" #include "xe_gt_types.h" -#include "xe_hw_engine_types.h" #include "xe_module.h" -#include "xe_pci_types.h" -#include "xe_sriov_types.h" /** * DOC: Xe Configfs
@@ -259,43 +255,6 @@* # rmdir /sys/kernel/config/xe/0000:03:00.0/ */ -/* Similar to struct xe_bb, but not tied to HW (yet) */ -struct wa_bb { -u32 *cs; -u32 len;/* in dwords */ -}; - -struct xe_config_group_device { -struct config_group group; -struct config_group sriov; - -/* -* Fields sorted by type (largest first) then name: struct arrays, -* u64, u32/unsigned int, u8, bool, sub-structs last. Within each -* type, entries are sorted alphabetically. -*/ -struct xe_config_device { -struct wa_bb ctx_restore_mid_bb[XE_ENGINE_CLASS_MAX ]; -struct wa_bb ctx_restore_post_bb[XE_ENGINE_CLASS_MAX ]; -u64 engines_allowed; -u64 gt_types_allowed; -bool enable_multi_queue; -bool enable_psmi; -bool survivability_mode; -struct { -unsigned int max_vfs; -bool admin_only_pf; - } sriov; - } config; - -/* protects attributes */ -struct mutex lock; -/* matching descriptor */ -const struct xe_device_desc *desc; -/* tentative SR-IOV mode */ -enum xe_sriov_mode mode; -}; -static const struct xe_config_device device_defaults = { .engines_allowed =U64_MAX , .gt_types_allowed =U64_MAX ,
drivers/gpu/drm/xe/xe_configfs.h +1 -1
@@ -8,8 +8,8 @@#include <linux/limits.h> #include <linux/types.h> +#include "xe_configfs_types.h" #include "xe_defaults.h" -#include "xe_hw_engine_types.h" #include "xe_module.h" struct pci_dev ;
drivers/gpu/drm/xe/xe_configfs_types.h new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH 03/10] drm/xe: Split out configfs data structures
Quoted 11 lines · Stuart Summers
Planning on moving debug specific configfs parameters to their own file in a future patch. In preparation for that change, move the structures in
xe_configfs.cto a new_types.hfile so we can easily access them in the different configfs files.Doing that separately here instead of combining with the patch that adds the debug file for ease of review.
Signed-off-by Stuart Summers <[email protected]>Assisted-by Copilot:claude-sonnet-4.6,claude-opus-4.7
Quoted 150 lines
--- drivers/gpu/drm/xe/xe_configfs.c | 41 -------------------- drivers/gpu/drm/xe/xe_configfs.h | 2 +- drivers/gpu/drm/xe/xe_configfs_types.h | 53 ++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 42 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_configfs_types.hdrivers/gpu/drm/xe/xe_configfs.c +0
-41@@ -4,7 +4,6 @@*/ #include <linux/bitops.h> -#include <linux/ctype.h> #include <linux/configfs.h> #include <linux/cleanup.h> #include <linux/find.h> @@ -17,10 +16,7 @@#include "xe_configfs.h" #include "xe_defaults.h" #include "xe_gt_types.h" -#include "xe_hw_engine_types.h" #include "xe_module.h" -#include "xe_pci_types.h" -#include "xe_sriov_types.h" /** * DOC: Xe Configfs @@ -259,43 +255,6 @@* # rmdir /sys/kernel/config/xe/0000:03:00.0/ */ -/* Similar to struct xe_bb, but not tied to HW (yet) */ -struct wa_bb { -u32 *cs; -u32 len;/* in dwords */ -}; - -struct xe_config_group_device { -struct config_group group; -struct config_group sriov; - -/* -* Fields sorted by type (largest first) then name: struct arrays, -* u64, u32/unsigned int, u8, bool, sub-structs last. Within each -* type, entries are sorted alphabetically. -*/ -struct xe_config_device { -struct wa_bb ctx_restore_mid_bb[XE_ENGINE_CLASS_MAX ]; -struct wa_bb ctx_restore_post_bb[XE_ENGINE_CLASS_MAX ]; -u64 engines_allowed; -u64 gt_types_allowed; -bool enable_multi_queue; -bool enable_psmi; -bool survivability_mode; -struct { -unsigned int max_vfs; -bool admin_only_pf; - } sriov; - } config; - -/* protects attributes */ -struct mutex lock; -/* matching descriptor */ -const struct xe_device_desc *desc; -/* tentative SR-IOV mode */ -enum xe_sriov_mode mode; -}; -static const struct xe_config_device device_defaults = { .engines_allowed =U64_MAX , .gt_types_allowed =U64_MAX ,drivers/gpu/drm/xe/xe_configfs.h +1
-1@@ -8,8 +8,8 @@#include <linux/limits.h> #include <linux/types.h> +#include "xe_configfs_types.h" #include "xe_defaults.h" -#include "xe_hw_engine_types.h" #include "xe_module.h" struct pci_dev ;drivers/gpu/drm/xe/xe_configfs_types.h new file +53
-0@@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2026 Intel Corporation +*/ +#ifndef _XE_CONFIGFS_TYPES_H_ +#define _XE_CONFIGFS_TYPES_H_ + +#include <linux/configfs.h> +#include <linux/mutex.h> +#include <linux/types.h> + +#include "xe_hw_engine_types.h" +#include "xe_pci_types.h" +#include "xe_sriov_types.h" + +/* Similar to struct xe_bb, but not tied to HW (yet) */ +struct wa_bb { +u32 *cs; +u32 len;/* in dwords */ +}; + +struct xe_config_group_device { +struct config_group group; +struct config_group sriov; + +/* +* Fields sorted by type (largest first) then name: struct arrays, +* u64, u32/unsigned int, u8, bool, sub-structs last. Within each +* type, entries are sorted alphabetically. +*/ +struct xe_config_device { +struct wa_bb ctx_restore_mid_bb[XE_ENGINE_CLASS_MAX ]; +struct wa_bb ctx_restore_post_bb[XE_ENGINE_CLASS_MAX ]; +u64 engines_allowed; +u64 gt_types_allowed; +bool enable_multi_queue; +bool enable_psmi; +bool survivability_mode; +struct { +unsigned int max_vfs; +bool admin_only_pf; + } sriov; + } config; + +/* protects attributes */ +struct mutex lock; +/* matching descriptor */ +const struct xe_device_desc *desc; +/* tentative SR-IOV mode */ +enum xe_sriov_mode mode; +}; + +#endif /* _XE_CONFIGFS_TYPES_H_ */ Signature · 1 line
2.43.0
Signature · 4 lines
Matt Roper Graphics Software Engineer Linux GPU Platform Enablement Intel Corporation
Re: [PATCH 03/10] drm/xe: Split out configfs data structures
Quoted 7 lines · Matt Roper
Quoted 6 lines · Stuart Summers
Planning on moving debug specific configfs parameters to their own file in a future patch. In preparation for that change, move the structures in
xe_configfs.cto a new_types.hfile so we can easily access them in the different configfs files.
Quoted 7 lines
Quoted 5 lines
Doing that separately here instead of combining with the patch that adds the debug file for ease of review.
Signed-off-by Stuart Summers <[email protected]>Assisted-by Copilot:claude-sonnet-4.6,claude-opus-4.7Reviewed-by Matt Roper <[email protected]>
Thanks for the review!
Quoted 164 lines
Quoted 163 lines
---
drivers/gpu/drm/xe/xe_configfs.c | 41 -------------------- drivers/gpu/drm/xe/xe_configfs.h | 2 +-drivers/gpu/drm/xe/xe_configfs_types.h| 53
++++++++++++++++++++++++++3 files changed, 54 insertions(+), 42 deletions(-)create mode 100644
drivers/gpu/drm/xe/xe_configfs_types.hdrivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -4,7 +4,6 @@*/
#include <linux/bitops.h>
-#include <linux/ctype.h>
#include <linux/configfs.h>
#include <linux/cleanup.h>
#include <linux/find.h>drivers/gpu/drm/xe/xe_configfs.c +0
-3@@ -17,10 +16,7 @@ #include "xe_configfs.h" #include "xe_defaults.h" #include "xe_gt_types.h" -#include "xe_hw_engine_types.h" #include "xe_module.h" -#include "xe_pci_types.h" -#include "xe_sriov_types.h"
/**
* DOC: Xe Configfsdrivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -259,43 +255,6 @@* # rmdir /sys/kernel/config/xe/0000:03:00.0/ */ drivers/gpu/drm/xe/xe_configfs.c +0
-12-/* Similar to struct xe_bb, but not tied to HW (yet) */ -struct wa_bb { - u32 *cs; - u32 len; /* in dwords */ -}; - -struct xe_config_group_device { - struct config_group group; - struct config_group sriov; - - /* - * Fields sorted by type (largest first) then name: structarrays,
- * u64, u32/unsigned int, u8, bool, sub-structs last. Within each
- * type, entries are sorted alphabetically. - */
- structxe_config_device{
- structwa_bbctx_restore_mid_bb[XE_ENGINE_CLASS_MAX];
- structwa_bbctx_restore_post_bb[XE_ENGINE_CLASS_MAX];
- u64engines_allowed;
- u64gt_types_allowed;
- boolenable_multi_queue;
- boolenable_psmi;
- boolsurvivability_mode;
- struct {
- unsigned intmax_vfs;
- booladmin_only_pf;
- } sriov;
- } config;drivers/gpu/drm/xe/xe_configfs.c +0
-9- - /* protects attributes */ - struct mutex lock; - /* matching descriptor */ - const struct xe_device_desc *desc; - /* tentative SR-IOV mode */ - enum xe_sriov_mode mode; -}; -static const struct
xe_config_devicedevice_defaults= { .engines_allowed =U64_MAX, .gt_types_allowed =U64_MAX,drivers/gpu/drm/xe/xe_configfs.h +0
-0@@ -8,8 +8,8 @@ #include <linux/limits.h> #include <linux/types.h>
+#include "xe_configfs_types.h"
#include "xe_defaults.h"
-#include "xe_hw_engine_types.h"
#include "xe_module.h"
structpci_dev;drivers/gpu/drm/xe/xe_configfs_types.h new file +27
-0@@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2026 Intel Corporation +*/ +#ifndef _XE_CONFIGFS_TYPES_H_ +#define _XE_CONFIGFS_TYPES_H_ + +#include <linux/configfs.h> +#include <linux/mutex.h> +#include <linux/types.h> + +#include "xe_hw_engine_types.h" +#include "xe_pci_types.h" +#include "xe_sriov_types.h" + +/* Similar to struct xe_bb, but not tied to HW (yet) */ +struct wa_bb { + u32 *cs; + u32 len; /* in dwords */ +}; + +struct xe_config_group_device { + struct config_group group; + struct config_group sriov; + + /* + * Fields sorted by type (largest first) then name: structarrays,
+ * u64, u32/unsigned int, u8, bool, sub-structs last. Within each
+ * type, entries are sorted alphabetically. + */
+ structxe_config_device{
+ structwa_bbctx_restore_mid_bb[XE_ENGINE_CLASS_MAX];
+ structwa_bbctx_restore_post_bb[XE_ENGINE_CLASS_MAX];
+ u64engines_allowed;
+ u64gt_types_allowed;
+ boolenable_multi_queue;
+ boolenable_psmi;
+ boolsurvivability_mode;
+ struct {
+ unsigned intmax_vfs;
+ booladmin_only_pf;
+ } sriov;
+ } config;drivers/gpu/drm/xe/xe_configfs_types.h new file +10
-0+ + /* protects attributes */ + struct mutex lock; + /* matching descriptor */ + const struct xe_device_desc *desc; + /* tentative SR-IOV mode */ + enum xe_sriov_mode mode; +}; + +#endif /* _XE_CONFIGFS_TYPES_H_ */ Signature · 1 line
2.43.0
PATCH 4/10 drm/xe: Add a new debug focused configfs group
In reply to Stuart SummersAdd the skeleton code for a new debug specific configfs group. Just add the structure for now. Actual debug content will be added in a subsequent patch.
--- drivers/gpu/drm/xe/Makefile | 2 ++ drivers/gpu/drm/xe/xe_configfs.c | 5 +++++ drivers/gpu/drm/xe/xe_configfs_debug.c | 14 ++++++++++++++ drivers/gpu/drm/xe/xe_configfs_debug.h | 13 +++++++++++++ drivers/gpu/drm/xe/xe_configfs_types.h | 3 +++ 5 files changed, 37 insertions(+) create mode 100644 drivers/gpu/drm/xe/xe_configfs_debug.c create mode 100644 drivers/gpu/drm/xe/xe_configfs_debug.h
drivers/gpu/drm/xe/Makefile +2 -0
@@ -163,6 +163,8 @@ xe-$(CONFIG_HWMON) += xe_hwmon.o xe-$(CONFIG_PERF_EVENTS) += xe_pmu.o xe-$(CONFIG_CONFIGFS_FS) += xe_configfs.o +xe_debug_configfs_obj-$(CONFIG_DRM_XE_DEBUG) := xe_configfs_debug.o +xe-$(CONFIG_CONFIGFS_FS) += $(xe_debug_configfs_obj-y) # graphics virtualization (SR-IOV) support xe-y += \
drivers/gpu/drm/xe/xe_configfs.c +5 -0
@@ -14,6 +14,7 @@#include "instructions/xe_mi_commands.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_defaults.h" #include "xe_gt_types.h" #include "xe_module.h"
@@ -1242,6 +1243,10 @@ static struct config_group *xe_config_make_device_group(struct config_group *groconfig_group_init_type_name (&dev->sriov,"sriov" , &xe_config_sriov_type);configfs_add_default_group (&dev->sriov, &dev->group); } +#if IS_ENABLED (CONFIG_DRM_XE_DEBUG ) +config_group_init_type_name (&dev->debug,"debug" , &xe_configfs_debug_type); +configfs_add_default_group (&dev->debug, &dev->group); +#endif mutex_init (&dev->lock);
drivers/gpu/drm/xe/xe_configfs_debug.c new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2026 Intel Corporation +*/ + +#include <linux/configfs.h> +#include <linux/module.h> + +#include "xe_configfs_debug.h" +#include "xe_configfs_types.h" + +const struct config_item_type xe_configfs_debug_type = { + .ct_owner =THIS_MODULE , +};
drivers/gpu/drm/xe/xe_configfs_debug.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2026 Intel Corporation +*/ +#ifndef _XE_CONFIGFS_DEBUG_H_ +#define _XE_CONFIGFS_DEBUG_H_ + +#if IS_ENABLED (CONFIG_DRM_XE_DEBUG ) &&IS_ENABLED (CONFIG_CONFIGFS_FS ) +struct config_item_type ; +extern const struct config_item_type xe_configfs_debug_type; +#endif + +#endif /* _XE_CONFIGFS_DEBUG_H_ */
drivers/gpu/drm/xe/xe_configfs_types.h +3 -0
@@ -22,6 +22,9 @@ struct wa_bb {struct xe_config_group_device {struct config_group group;struct config_group sriov; +#if IS_ENABLED (CONFIG_DRM_XE_DEBUG ) +struct config_group debug; +#endif /* * Fields sorted by type (largest first) then name: struct arrays,
Signature · 1 line
2.43.0
Re: [PATCH 04/10] drm/xe: Add a new debug focused configfs group
Quoted 22 lines · Stuart Summers
Add the skeleton code for a new debug specific configfs group. Just add the structure for now. Actual debug content will be added in a subsequent patch.
Signed-off-by Stuart Summers <[email protected]>Assisted-by Copilot:claude-sonnet-4.6,claude-opus-4.7Reviewed-by Rodrigo Vivi <[email protected]>--- drivers/gpu/drm/xe/Makefile | 2 ++ drivers/gpu/drm/xe/xe_configfs.c | 5 +++++ drivers/gpu/drm/xe/xe_configfs_debug.c | 14 ++++++++++++++ drivers/gpu/drm/xe/xe_configfs_debug.h | 13 +++++++++++++ drivers/gpu/drm/xe/xe_configfs_types.h | 3 +++ 5 files changed, 37 insertions(+) create mode 100644 drivers/gpu/drm/xe/xe_configfs_debug.c create mode 100644 drivers/gpu/drm/xe/xe_configfs_debug.hdrivers/gpu/drm/xe/Makefile +0
-0
drivers/gpu/drm/xe/Makefile xe-$(CONFIG_HWMON) += xe_hwmon.o · line 165
Quoted 3 lines
drivers/gpu/drm/xe/Makefile +0
-0@@ -163,6 +163,8 @@ xe-$(CONFIG_HWMON) += xe_hwmon.o xe-$(CONFIG_PERF_EVENTS) += xe_pmu.o xe-$(CONFIG_CONFIGFS_FS) += xe_configfs.o
Not really an issue with your patch here, but since we're messing with kconfig stuff it reminds me --- I'm not sure our pre-existing configfs kconfig handling is entirely correct (and I think I've seen kernel test robot warnings about that too). The concern is that our header file does a typical IS_ENABLED(CONFIG_CONFIGFS) type of check to decide between extern function declarations or noop stubs. But if Xe is built into the bzImage, but configfs is configured as a .ko, then Xe can't reach the configfs functions. I believe there's an IS_REACHABLE() that maybe we should be using instead, although I haven't got around to actually looking closer and trying it out myself.
Your actual changes in this patch look okay to me.
Matt
Quoted 84 lines
drivers/gpu/drm/xe/Makefile +2
-0+xe_debug_configfs_obj-$(CONFIG_DRM_XE_DEBUG) := xe_configfs_debug.o +xe-$(CONFIG_CONFIGFS_FS) += $(xe_debug_configfs_obj-y) # graphics virtualization (SR-IOV) support xe-y += \drivers/gpu/drm/xe/xe_configfs.c +5
-0@@ -14,6 +14,7 @@#include "instructions/xe_mi_commands.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_defaults.h" #include "xe_gt_types.h" #include "xe_module.h" @@ -1242,6 +1243,10 @@ static struct config_group *xe_config_make_device_group(struct config_group *groconfig_group_init_type_name (&dev->sriov,"sriov" , &xe_config_sriov_type);configfs_add_default_group (&dev->sriov, &dev->group); } +#if IS_ENABLED (CONFIG_DRM_XE_DEBUG ) +config_group_init_type_name (&dev->debug,"debug" , &xe_configfs_debug_type); +configfs_add_default_group (&dev->debug, &dev->group); +#endif mutex_init (&dev->lock);drivers/gpu/drm/xe/xe_configfs_debug.c new file +14
-0@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2026 Intel Corporation +*/ + +#include <linux/configfs.h> +#include <linux/module.h> + +#include "xe_configfs_debug.h" +#include "xe_configfs_types.h" + +const struct config_item_type xe_configfs_debug_type = { + .ct_owner =THIS_MODULE , +};drivers/gpu/drm/xe/xe_configfs_debug.h new file +13
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2026 Intel Corporation +*/ +#ifndef _XE_CONFIGFS_DEBUG_H_ +#define _XE_CONFIGFS_DEBUG_H_ + +#if IS_ENABLED (CONFIG_DRM_XE_DEBUG ) &&IS_ENABLED (CONFIG_CONFIGFS_FS ) +struct config_item_type ; +extern const struct config_item_type xe_configfs_debug_type; +#endif + +#endif /* _XE_CONFIGFS_DEBUG_H_ */ drivers/gpu/drm/xe/xe_configfs_types.h +3
-0@@ -22,6 +22,9 @@ struct wa_bb {struct xe_config_group_device {struct config_group group;struct config_group sriov; +#if IS_ENABLED (CONFIG_DRM_XE_DEBUG ) +struct config_group debug; +#endif /* * Fields sorted by type (largest first) then name: struct arrays, Signature · 1 line
2.43.0
Signature · 4 lines
Matt Roper Graphics Software Engineer Linux GPU Platform Enablement Intel Corporation
Re: [PATCH 04/10] drm/xe: Add a new debug focused configfs group
Quoted 24 lines · Matt Roper
Quoted 23 lines · Stuart Summers
Add the skeleton code for a new debug specific configfs group. Just add the structure for now. Actual debug content will be added in a subsequent patch.
Signed-off-by Stuart Summers <[email protected]>Assisted-by Copilot:claude-sonnet-4.6,claude-opus-4.7Reviewed-by Rodrigo Vivi <[email protected]>--- drivers/gpu/drm/xe/Makefile | 2 ++ drivers/gpu/drm/xe/xe_configfs.c | 5 +++++ drivers/gpu/drm/xe/xe_configfs_debug.c | 14 ++++++++++++++ drivers/gpu/drm/xe/xe_configfs_debug.h | 13 +++++++++++++ drivers/gpu/drm/xe/xe_configfs_types.h | 3 +++ 5 files changed, 37 insertions(+) create mode 100644 drivers/gpu/drm/xe/xe_configfs_debug.c create mode 100644 drivers/gpu/drm/xe/xe_configfs_debug.hdrivers/gpu/drm/xe/Makefile +0
-0@@ -163,6 +163,8 @@ xe-$(CONFIG_HWMON) += xe_hwmon.o
Quoted 13 lines
drivers/gpu/drm/xe/Makefile xe-$(CONFIG_HWMON) += xe_hwmon.o · line 165
Quoted 2 lines
drivers/gpu/drm/xe/Makefile +0
-0xe-$(CONFIG_PERF_EVENTS) += xe_pmu.o xe-$(CONFIG_CONFIGFS_FS) += xe_configfs.oNot really an issue with your patch here, but since we're messing with kconfig stuff it reminds me --- I'm not sure our pre-existing configfs kconfig handling is entirely correct (and I think I've seen kernel test robot warnings about that too). The concern is that our header file does a typical
IS_ENABLED(CONFIG_CONFIGFS)type of check to decide between extern function declarations or noop stubs. But if Xe is built into the bzImage, but configfs is configured as a .ko, then Xe can't reach the configfs functions. I believe there's anIS_REACHABLE()that maybe we should be using instead, although I haven't got around to actually looking closer and trying it out myself.
I was already trying to use IS_REACHABLE [1] but Jani is against it [2]
[1] https://patchwork.freedesktop.org/patch/696103/?series=159395&rev=1
[2] https://lore.kernel.org/intel-xe/[email protected]/
Quoted 93 lines
Your actual changes in this patch look okay to me.
Reviewed-by Matt Roper <[email protected]>Matt
Quoted 84 lines
drivers/gpu/drm/xe/Makefile +2
-0+xe_debug_configfs_obj-$(CONFIG_DRM_XE_DEBUG) := xe_configfs_debug.o +xe-$(CONFIG_CONFIGFS_FS) += $(xe_debug_configfs_obj-y) # graphics virtualization (SR-IOV) support xe-y += \drivers/gpu/drm/xe/xe_configfs.c +5
-0@@ -14,6 +14,7 @@#include "instructions/xe_mi_commands.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_defaults.h" #include "xe_gt_types.h" #include "xe_module.h" @@ -1242,6 +1243,10 @@ static struct config_group *xe_config_make_device_group(struct config_group *groconfig_group_init_type_name (&dev->sriov,"sriov" , &xe_config_sriov_type);configfs_add_default_group (&dev->sriov, &dev->group); } +#if IS_ENABLED (CONFIG_DRM_XE_DEBUG ) +config_group_init_type_name (&dev->debug,"debug" , &xe_configfs_debug_type); +configfs_add_default_group (&dev->debug, &dev->group); +#endif mutex_init (&dev->lock);drivers/gpu/drm/xe/xe_configfs_debug.c new file +14
-0@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2026 Intel Corporation +*/ + +#include <linux/configfs.h> +#include <linux/module.h> + +#include "xe_configfs_debug.h" +#include "xe_configfs_types.h" + +const struct config_item_type xe_configfs_debug_type = { + .ct_owner =THIS_MODULE , +};drivers/gpu/drm/xe/xe_configfs_debug.h new file +13
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2026 Intel Corporation +*/ +#ifndef _XE_CONFIGFS_DEBUG_H_ +#define _XE_CONFIGFS_DEBUG_H_ + +#if IS_ENABLED (CONFIG_DRM_XE_DEBUG ) &&IS_ENABLED (CONFIG_CONFIGFS_FS ) +struct config_item_type ; +extern const struct config_item_type xe_configfs_debug_type; +#endif + +#endif /* _XE_CONFIGFS_DEBUG_H_ */ drivers/gpu/drm/xe/xe_configfs_types.h +3
-0@@ -22,6 +22,9 @@ struct wa_bb {struct xe_config_group_device {struct config_group group;struct config_group sriov; +#if IS_ENABLED (CONFIG_DRM_XE_DEBUG ) +struct config_group debug; +#endif /* * Fields sorted by type (largest first) then name: struct arrays, Signature · 1 line
2.43.0
Re: [PATCH 04/10] drm/xe: Add a new debug focused configfs group
Quoted 49 lines · Michal Wajdeczko
Quoted 37 lines · Matt Roper
Quoted 23 lines · Stuart Summers
Add the skeleton code for a new debug specific configfs group. Just add the structure for now. Actual debug content will be added in a subsequent patch.
Signed-off-by Stuart Summers <[email protected]>Assisted-by Copilot:claude-sonnet-4.6,claude-opus-4.7Reviewed-by Rodrigo Vivi <[email protected]>---
drivers/gpu/drm/xe/Makefile | 2 ++ drivers/gpu/drm/xe/xe_configfs.c | 5 +++++drivers/gpu/drm/xe/xe_configfs_debug.c | 14 ++++++++++++++ drivers/gpu/drm/xe/xe_configfs_debug.h | 13 +++++++++++++ drivers/gpu/drm/xe/xe_configfs_types.h | 3 +++ 5 files changed, 37 insertions(+)create mode 100644
drivers/gpu/drm/xe/xe_configfs_debug.ccreate mode 100644drivers/gpu/drm/xe/xe_configfs_debug.hdrivers/gpu/drm/xe/Makefile +0
-0@@ -163,6 +163,8 @@ xe-$(CONFIG_HWMON) += xe_hwmon.oQuoted 3 lines
xe-$(CONFIG_PERF_EVENTS) += xe_pmu.o
xe-$(CONFIG_CONFIGFS_FS) += xe_configfs.oNot really an issue with your patch here, but since we're messing with
kconfig stuff it reminds me --- I'm not sure our pre-existing configfs
kconfig handling is entirely correct (and I think I've seen kernel test
robot warnings about that too). The concern is that our header file
does a typicalIS_ENABLED(CONFIG_CONFIGFS)type of check to decideQuoted 8 lines
between extern function declarations or noop stubs. But if Xe is built
into the bzImage, but configfs is configured as a .ko, then Xe can't
reach the configfs functions. I believe there's anIS_REACHABLE()that
maybe we should be using instead, although I haven't got around to actually looking closer and trying it out myself.
Quoted 7 lines
I was already trying to use
IS_REACHABLE[1] but Jani is against it
[2][1]
https://patchwork.freedesktop.org/patch/696103/?series=159395&rev=1
[2]
https://lore.kernel.org/intel-xe/[email protected]/
Maybe we just add CONFIG_CONFIGFS as a requirement of CONFIG_DRM_XE?
But also I'd rather have this discussion separate from the patch series here if possible. I didn't want to change anything fundamental here other than adding the debug-only pieces.
Let me know what you think here.
Thanks,
Stuart
Quoted 106 lines
Quoted 105 lines
Your actual changes in this patch look okay to me.
Reviewed-by Matt Roper <[email protected]>Matt
Quoted 95 lines
+xe_debug_configfs_obj-$(CONFIG_DRM_XE_DEBUG) := xe_configfs_debug.o
+xe-$(CONFIG_CONFIGFS_FS) += $(xe_debug_configfs_obj-y)# graphics virtualization (SR-IOV) support xe-y += \drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -14,6 +14,7 @@
#include "instructions/xe_mi_commands.h"
#include "xe_configfs.h"
+#include "xe_configfs_debug.h"
#include "xe_defaults.h"
#include "xe_gt_types.h"
#include "xe_module.h"drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1242,6 +1243,10 @@ static struct config_group *xe_config_make_device_group(struct config_group *gro config_group_init_type_name(&dev->sriov, "sriov", &xe_config_sriov_type);configfs_add_default_group(&dev->sriov, &dev-
Quoted 1 line
group);
}
+#ifIS_ENABLED(CONFIG_DRM_XE_DEBUG)
+ config_group_init_type_name(&dev->debug, "debug",&xe_configfs_debug_type);
+ configfs_add_default_group(&dev->debug,&dev->group); +#endif
mutex_init(&dev->lock);drivers/gpu/drm/xe/xe_configfs_debug.c new file +14
-0@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2026 Intel Corporation +*/ + +#include <linux/configfs.h> +#include <linux/module.h> + +#include "xe_configfs_debug.h" +#include "xe_configfs_types.h" + +const struct config_item_type xe_configfs_debug_type = { + .ct_owner = THIS_MODULE, +};drivers/gpu/drm/xe/xe_configfs_debug.h new file +8
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2026 Intel Corporation +*/ +#ifndef _XE_CONFIGFS_DEBUG_H_ +#define _XE_CONFIGFS_DEBUG_H_ + +#if IS_ENABLED(CONFIG_DRM_XE_DEBUG) &&
IS_ENABLED(CONFIG_CONFIGFS_FS)drivers/gpu/drm/xe/xe_configfs_debug.h new file +5
-0+struct config_item_type ; +extern const struct config_item_type xe_configfs_debug_type; +#endif + +#endif /* _XE_CONFIGFS_DEBUG_H_ */ drivers/gpu/drm/xe/xe_configfs_types.h +3
-0@@ -22,6 +22,9 @@ struct wa_bb { struct xe_config_group_device { struct config_group group; struct config_group sriov; +#if IS_ENABLED (CONFIG_DRM_XE_DEBUG ) + struct config_group debug; +#endif
/*
* Fields sorted by type (largest first) then name:
struct arrays,Signature · 1 line
2.43.0
PATCH 5/10 drm/xe: Move debug configfs entries to xe_configfs_debug.c
In reply to Stuart SummersMove the debug specific configfs attributes into the new xe_configfs_debug.c file under a new debug configfs subdirectory. Ensure these are wrapped in CONFIG_DRM_XE_DEBUG to allow finer grained debug changes outside of more ABI specific configfs entries.
--- drivers/gpu/drm/xe/xe_configfs.c | 991 ++------------------- drivers/gpu/drm/xe/xe_configfs.h | 88 +- drivers/gpu/drm/xe/xe_configfs_debug.c | 956 ++++++++++++++++++++ drivers/gpu/drm/xe/xe_configfs_debug.h | 39 +- drivers/gpu/drm/xe/xe_configfs_types.h | 18 +- drivers/gpu/drm/xe/xe_guc.c | 1 + drivers/gpu/drm/xe/xe_guc_ads.c | 1 + drivers/gpu/drm/xe/xe_hw_engine.c | 1 + drivers/gpu/drm/xe/xe_lrc.c | 1 + drivers/gpu/drm/xe/xe_pci.c | 1 + drivers/gpu/drm/xe/xe_psmi.c | 1 + drivers/gpu/drm/xe/xe_rtp.c | 1 + drivers/gpu/drm/xe/xe_survivability_mode.c | 1 + 13 files changed, 1134 insertions(+), 966 deletions(-)
drivers/gpu/drm/xe/xe_configfs.c +57 -934
@@ -6,17 +6,14 @@#include <linux/bitops.h> #include <linux/configfs.h> #include <linux/cleanup.h> -#include <linux/find.h> #include <linux/init.h> #include <linux/module.h> #include <linux/pci.h> #include <linux/string.h> -#include "instructions/xe_mi_commands.h" #include "xe_configfs.h" #include "xe_configfs_debug.h" #include "xe_defaults.h" -#include "xe_gt_types.h" #include "xe_module.h" /**
@@ -50,16 +47,9 @@* * /sys/kernel/config/xe/ * ├── 0000:00:02.0 -* │ └── ... -* ├── 0000:00:02.1 -* │ └── ... -* : -* └── 0000:03:00.0 -* ├── engines_allowed -* ├── gt_types_allowed -* ├── enable_multi_queue -* ├── enable_psmi -* └── survivability_mode +* │ └── ... +* └── 0000:00:02.1 +* └── ... * * After configuring the attributes as per next section, the device can be * probed with::
@@ -71,157 +61,6 @@* Configure Attributes * ==================== * - -* Context restore BB -* ------------------ -* -* Allow to execute a batch buffer during any context switches. When the -* GPU is restoring the context, it executes additional commands. It's useful -* for testing additional workarounds and validating certain HW behaviors: it's -* not intended for normal execution and will taint the kernel with TAINT_TEST -* when used. -* -* The syntax allows to pass straight instructions to be executed by the engine -* in a batch buffer or set specific registers. -* -* #. Generic instruction:: -* -* <engine-class> cmd <instr> [[dword0] [dword1] [...]] -* -* #. Simple register setting:: -* -* <engine-class> reg <address> <value> -* -* Commands are saved per engine class: all instances of that class will execute -* those commands during context switch. The instruction, dword arguments, -* addresses and values are in hex format like in the examples below. -* -* #. Execute a LRI command to write 0xDEADBEEF to register 0x4f10 after the -* normal context restore:: -* -* # echo 'rcs cmd 11000001 4F100 DEADBEEF' \ -* > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_post_bb -* -* #. Execute a LRI command to write 0xDEADBEEF to register 0x4f10 at the -* beginning of the context restore:: -* -* # echo 'rcs cmd 11000001 4F100 DEADBEEF' \ -* > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_mid_bb - -* #. Load certain values in a couple of registers (it can be used as a simpler -* alternative to the `cmd`) action:: -* -* # cat > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_post_bb <<EOF -* rcs reg 4F100 DEADBEEF -* rcs reg 4F104 FFFFFFFF -* EOF -* -* .. note:: -* -* When using multiple lines, make sure to use a command that is -* implemented with a single write syscall, like HEREDOC. -* -* Currently this is implemented only for post and mid context restore and -* these attributes can only be set before binding to the device. -* -* Allowed engines: -* ---------------- -* -* Allow only a set of engine(s) to be available, disabling the other engines -* even if they are available in hardware. This is applied after HW fuses are -* considered on each tile. Examples: -* -* Allow only one render and one copy engines, nothing else:: -* -* # echo 'rcs0,bcs0' > /sys/kernel/config/xe/0000:03:00.0/engines_allowed -* -* Allow only compute engines and first copy engine:: -* -* # echo 'ccs*,bcs0' > /sys/kernel/config/xe/0000:03:00.0/engines_allowed -* -* Note that the engine names are the per-GT hardware names. On multi-tile -* platforms, writing ``rcs0,bcs0`` to this file would allow the first render -* and copy engines on each tile. -* -* The requested configuration may not be supported by the platform and driver -* may fail to probe. For example: if at least one copy engine is expected to be -* available for migrations, but it's disabled. This is intended for debugging -* purposes only. -* -* This attribute can only be set before binding to the device. -* -* Allowed GT types: -* ----------------- -* -* Allow only specific types of GTs to be detected and initialized by the -* driver. Any combination of GT types can be enabled/disabled, although -* some settings will cause the device to fail to probe. -* -* Writes support both comma- and newline-separated input format. Reads -* will always return one GT type per line. "primary" and "media" are the -* GT type names supported by this interface. -* -* This attribute can only be set before binding to the device. -* -* Examples: -* -* Allow both primary and media GTs to be initialized and used. This matches -* the driver's default behavior:: -* -* # echo 'primary,media' > /sys/kernel/config/xe/0000:03:00.0/gt_types_allowed -* -* Allow only the primary GT of each tile to be initialized and used, -* effectively disabling the media GT if it exists on the platform:: -* -* # echo 'primary' > /sys/kernel/config/xe/0000:03:00.0/gt_types_allowed -* -* Allow only the media GT of each tile to be initialized and used, -* effectively disabling the primary GT. **This configuration will cause -* device probe failure on all current platforms, but may be allowed on -* igpu platforms in the future**:: -* -* # echo 'media' > /sys/kernel/config/xe/0000:03:00.0/gt_types_allowed -* -* Disable all GTs. Only other GPU IP (such as display) is potentially usable. -* **This configuration will cause device probe failure on all current -* platforms, but may be allowed on igpu platforms in the future**:: -* -* # echo '' > /sys/kernel/config/xe/0000:03:00.0/gt_types_allowed -* -* Enable multi-queue -* ------------------ -* -* Multi-queue support on the device is enabled by default where the -* hardware supports it. Writing 0 force-disables multi-queue support: -* multi-queue exec-queue group creation via ioctl is refused, and the -* GuC feature is disabled:: -* -* # echo 0 > /sys/kernel/config/xe/0000:03:00.0/enable_multi_queue -* -* This attribute can only be set before binding to the device. -* -* PSMI -* ---- -* -* Enable extra debugging capabilities to trace engine execution. Only useful -* during early platform enabling and requires additional hardware connected. -* Once it's enabled, additionals WAs are added and runtime configuration is -* done via debugfs. Example to enable it:: -* -* # echo 1 > /sys/kernel/config/xe/0000:03:00.0/enable_psmi -* -* This attribute can only be set before binding to the device. -* -* Survivability mode: -* ------------------- -* -* Enable survivability mode on supported cards. This setting only takes -* effect when probing the device. Example to enable it:: -* -* # echo 1 > /sys/kernel/config/xe/0000:03:00.0/survivability_mode -* -* This attribute can only be set before binding to the device. -* * Max SR-IOV Virtual Functions * ---------------------------- *
@@ -256,12 +95,16 @@* # rmdir /sys/kernel/config/xe/0000:03:00.0/ */ -static const struct xe_config_device device_defaults = { - .engines_allowed =U64_MAX , - .gt_types_allowed =U64_MAX , - .enable_multi_queue = true, - .enable_psmi = false, - .survivability_mode = false, +const struct xe_config_device xe_configfs_device_defaults = { +#if IS_ENABLED(CONFIG_DRM_XE_DEBUG) + .debug = { + .engines_allowed =U64_MAX , + .gt_types_allowed =U64_MAX , + .enable_multi_queue = true, + .enable_psmi = false, + .survivability_mode = false, + }, +#endif .sriov = { .max_vfs =XE_DEFAULT_MAX_VFS , .admin_only_pf =XE_DEFAULT_ADMIN_ONLY_PF ,
@@ -270,50 +113,22 @@ static const struct xe_config_device device_defaults = {static void set_device_defaults (struct xe_config_device *config) { - *config = device_defaults; + *config = xe_configfs_device_defaults;#ifdef CONFIG_PCI_IOV config->sriov.max_vfs = xe_modparam.max_vfs;#endif } -struct engine_info { -const char *cls; -u64 mask; -enum xe_engine_class engine_class; -}; - -/* Some helpful macros to aid on the sizing of buffer allocation when parsing */ -#define MAX_ENGINE_CLASS_CHARS 5 -#define MAX_ENGINE_INSTANCE_CHARS 2 - -static const struct engine_info engine_info[] = { - { .cls ="rcs" , .mask =XE_HW_ENGINE_RCS_MASK , .engine_class =XE_ENGINE_CLASS_RENDER }, - { .cls ="bcs" , .mask =XE_HW_ENGINE_BCS_MASK , .engine_class =XE_ENGINE_CLASS_COPY }, - { .cls ="vcs" , .mask =XE_HW_ENGINE_VCS_MASK , .engine_class =XE_ENGINE_CLASS_VIDEO_DECODE }, - { .cls ="vecs" , .mask =XE_HW_ENGINE_VECS_MASK , .engine_class =XE_ENGINE_CLASS_VIDEO_ENHANCE }, - { .cls ="ccs" , .mask =XE_HW_ENGINE_CCS_MASK , .engine_class =XE_ENGINE_CLASS_COMPUTE }, - { .cls ="gsccs" , .mask =XE_HW_ENGINE_GSCCS_MASK , .engine_class =XE_ENGINE_CLASS_OTHER }, -}; - -static const struct { -const char *name; -enum xe_gt_type type; -} gt_types[] = { - { .name ="primary" , .type =XE_GT_TYPE_MAIN }, - { .name ="media" , .type =XE_GT_TYPE_MEDIA }, -}; - -static struct xe_config_group_device *to_xe_config_group_device (struct config_item *item) -{ - return container_of(to_config_group(item), struct xe_config_group_device, group); -} - -static struct xe_config_device *to_xe_config_device (struct config_item *item) -{ -return &to_xe_config_group_device (item)->config; -} - -static bool is_bound (struct xe_config_group_device *dev) +/** +* xe_configfs_is_bound - check whether the matching pci device is bound +* @dev: configfs group device +* +* Caller must hold @dev->lock. +* +* Return: true if the matching pci_dev is already bound to a driver, +* false otherwise. +*/ +bool xe_configfs_is_bound (struct xe_config_group_device *dev) {unsigned int domain, bus, slot, function;struct pci_dev *pdev;
@@ -338,698 +153,13 @@ static bool is_bound(struct xe_config_group_device *dev)return ret; } -static struct xe_config_group_device *find_xe_config_group_device (struct pci_dev *pdev); - -/** -* xe_configfs_get_ctx_restore_mid_bb - get configfs ctx_restore_mid_bb setting -* @pdev: pci device -* @class: hw engine class -* @cs: pointer to the bb to use - only valid during probe -* -* Return: Number of dwords used in the mid_ctx_restore setting in configfs -*/ -u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, -enum xe_engine_class class, -const u32 **cs) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -u32 len; - -if (!dev) -return 0 ; - - scoped_guard(mutex, &dev->lock) { -if (cs) - *cs = dev->config.ctx_restore_mid_bb[class].cs; - - len = dev->config.ctx_restore_mid_bb[class].len; - } -config_group_put (&dev->group); - -return len; -} - -/** -* xe_configfs_get_ctx_restore_post_bb - get configfs ctx_restore_post_bb setting -* @pdev: pci device -* @class: hw engine class -* @cs: pointer to the bb to use - only valid during probe -* -* Return: Number of dwords used in the post_ctx_restore setting in configfs -*/ -u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, -enum xe_engine_class class, -const u32 **cs) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -u32 len; - -if (!dev) -return 0 ; - - scoped_guard(mutex, &dev->lock) { - *cs = dev->config.ctx_restore_post_bb[class].cs; - len = dev->config.ctx_restore_post_bb[class].len; - } -config_group_put (&dev->group); - -return len; -} - -static bool wa_bb_read_advance (bool dereference,char **p, -const char *append,size_t len, -size_t *max_size) -{ -if (dereference) { -if (len >= *max_size) -return false; - *max_size -= len; -if (append) -memcpy (*p, append, len); - } - - *p += len; - -return true; -} - -static ssize_t wa_bb_show (struct xe_config_group_device *dev, -struct wa_bb wa_bb[static XE_ENGINE_CLASS_MAX ], -char *data,size_t sz) -{ -char *p = data; - -guard (mutex)(&dev->lock); - -for (size_t i =0 ; i <ARRAY_SIZE (engine_info); i++) { -enum xe_engine_class ec = engine_info[i].engine_class; -size_t len; - -if (!wa_bb[ec].len) -continue ; - - len =snprintf (p, sz,"%s:" , engine_info[i].cls); -if (!wa_bb_read_advance (data, &p,NULL , len, &sz)) -return -ENOBUFS ; - -for (size_t j =0 ; j < wa_bb[ec].len; j++) { - len =snprintf (p, sz," %08x" , wa_bb[ec].cs[j]); -if (!wa_bb_read_advance (data, &p,NULL , len, &sz)) -return -ENOBUFS ; - } - -if (!wa_bb_read_advance (data, &p,"\n" ,1 , &sz)) -return -ENOBUFS ; - } - -if (!wa_bb_read_advance (data, &p,"" ,1 , &sz)) -return -ENOBUFS ; - -/* Reserve one more to match check for '\0' */ -if (!data) - p++; - -return p - data; -} - -static ssize_t ctx_restore_mid_bb_show (struct config_item *item,char *page) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); - -return wa_bb_show (dev, dev->config.ctx_restore_mid_bb, page,SZ_4K ); -} - -static ssize_t ctx_restore_post_bb_show (struct config_item *item,char *page) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); - -return wa_bb_show (dev, dev->config.ctx_restore_post_bb, page,SZ_4K ); -} - -static void wa_bb_append (struct wa_bb *wa_bb,u32 val) -{ -if (wa_bb->cs) - wa_bb->cs[wa_bb->len] = val; - - wa_bb->len++; -} - -static ssize_t parse_hex (const char *line,u32 *pval) -{ -char numstr[12 ]; -const char *p; -ssize_t numlen; - - p = line +strspn (line," \t" ); -if (!*p || *p =='\n' ) -return 0 ; - - numlen =strcspn (p," \t\n" ); -if (!numlen || numlen >=sizeof (numstr) -1 ) -return -EINVAL ; - -memcpy (numstr, p, numlen); - numstr[numlen] ='\0' ; - p += numlen; - -if (kstrtou32 (numstr,16 , pval)) -return -EINVAL ; - -return p - line; -} - -static int parse_engine (const char *s,const char *end_chars,u64 *mask, -const struct engine_info **pinfo); - -/* -* Parse lines with the format -* -* <engine-class> cmd <u32> <u32...> -* <engine-class> reg <u32_addr> <u32_val> -* -* and optionally save them in @wa_bb[i].cs is non-NULL. -* -* Return the number of dwords parsed. -*/ -static ssize_t parse_wa_bb_lines (const char *lines, -struct wa_bb wa_bb[static XE_ENGINE_CLASS_MAX ]) -{ -ssize_t dwords =0 , ret; -const char *p; - -for (p = lines; *p; p++) { -const struct engine_info *info =NULL ; -u32 val, val2; - -/* Also allow empty lines */ - p +=strspn (p," \t\n" ); -if (!*p) -break ; - - ret =parse_engine (p," \t\n" ,NULL , &info); -if (ret <0 ) -return ret; - - p += ret; - p +=strspn (p," \t" ); - -if (str_has_prefix (p,"cmd" )) { -for (p +=strlen ("cmd" ); *p;) { - ret =parse_hex (p, &val); -if (ret <0 ) -return -EINVAL ; -if (!ret) -break ; - - p += ret; - dwords++; -wa_bb_append (&wa_bb[info->engine_class], val); - } - }else if (str_has_prefix (p,"reg" )) { - p +=strlen ("reg" ); - ret =parse_hex (p, &val); -if (ret <=0 ) -return -EINVAL ; - - p += ret; - ret =parse_hex (p, &val2); -if (ret <=0 ) -return -EINVAL ; - - p += ret; - dwords +=3 ; -wa_bb_append (&wa_bb[info->engine_class], -MI_LOAD_REGISTER_IMM |MI_LRI_NUM_REGS (1 )); -wa_bb_append (&wa_bb[info->engine_class], val); -wa_bb_append (&wa_bb[info->engine_class], val2); - }else { -return -EINVAL ; - } - } - -return dwords; -} - -static ssize_t wa_bb_store (struct wa_bb wa_bb[static XE_ENGINE_CLASS_MAX ], -struct xe_config_group_device *dev, -const char *page,size_t len) -{ -/* tmp_wa_bb must match wa_bb's size */ -struct wa_bb tmp_wa_bb[XE_ENGINE_CLASS_MAX ] = { }; -ssize_t count, class; -u32 *tmp; - -/* 1. Count dwords - wa_bb[i].cs is NULL for all classes */ - count =parse_wa_bb_lines (page, tmp_wa_bb); -if (count <0 ) -return count; - -guard (mutex)(&dev->lock); - -if (is_bound (dev)) -return -EBUSY ; - -/* -* 2. Allocate a u32 array and set the pointers to the right positions -* according to the length of each class' wa_bb -*/ - tmp =krealloc (wa_bb[0 ].cs, count *sizeof (u32),GFP_KERNEL ); -if (!tmp) -return -ENOMEM ; - -if (!count) { -memset (wa_bb,0 ,sizeof (tmp_wa_bb)); -return len; - } - -for (class =0 , count =0 ; class <XE_ENGINE_CLASS_MAX ; ++class) { - tmp_wa_bb[class].cs = tmp + count; - count += tmp_wa_bb[class].len; - tmp_wa_bb[class].len =0 ; - } - -/* 3. Parse wa_bb lines again, this time saving the values */ - count =parse_wa_bb_lines (page, tmp_wa_bb); -if (count <0 ) -return count; - -memcpy (wa_bb, tmp_wa_bb,sizeof (tmp_wa_bb)); - -return len; -} - -static ssize_t ctx_restore_mid_bb_store (struct config_item *item, -const char *data,size_t sz) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); - -return wa_bb_store (dev->config.ctx_restore_mid_bb, dev, data, sz); -} - -static ssize_t ctx_restore_post_bb_store (struct config_item *item, -const char *data,size_t sz) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); - -return wa_bb_store (dev->config.ctx_restore_post_bb, dev, data, sz); -} - -/** -* xe_configfs_get_engines_allowed - get engine allowed mask from configfs -* @pdev: pci device -* -* Return: engine mask with allowed engines set in configfs -*/ -u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -u64 engines_allowed; - -if (!dev) -return device_defaults.engines_allowed; - - scoped_guard(mutex, &dev->lock) - engines_allowed = dev->config.engines_allowed; -config_group_put (&dev->group); - -return engines_allowed; -} - -static ssize_t engines_allowed_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); -char *p = page; - -for (size_t i =0 ; i <ARRAY_SIZE (engine_info); i++) { -u64 mask = engine_info[i].mask; - -if ((dev->engines_allowed & mask) == mask) { - p +=sprintf (p,"%s*\n" , engine_info[i].cls); - }else if (mask & dev->engines_allowed) { -u16 bit0 =__ffs64 (mask), bit; - - mask &= dev->engines_allowed; - -for_each_set_bit (bit, (const unsigned long *)&mask,64 ) - p +=sprintf (p,"%s%u\n" , engine_info[i].cls, - bit - bit0); - } - } - -return p - page; -} - -/* -* Lookup engine_info. If @mask is not NULL, reduce the mask according to the -* instance in @pattern. -* -* Examples of inputs: -* - lookup_engine_info("rcs0", &mask): return "rcs" entry from @engine_info and -* mask == BIT_ULL(XE_HW_ENGINE_RCS0) -* - lookup_engine_info("rcs*", &mask): return "rcs" entry from @engine_info and -* mask == XE_HW_ENGINE_RCS_MASK -* - lookup_engine_info("rcs", NULL): return "rcs" entry from @engine_info -*/ -static const struct engine_info *lookup_engine_info (const char *pattern,u64 *mask) -{ -for (size_t i =0 ; i <ARRAY_SIZE (engine_info); i++) { -u8 instance; -u16 bit; - -if (!str_has_prefix (pattern, engine_info[i].cls)) -continue ; - - pattern +=strlen (engine_info[i].cls); -if (!mask) -return *pattern ?NULL : &engine_info[i]; - -if (!strcmp (pattern,"*" )) { - *mask = engine_info[i].mask; -return &engine_info[i]; - } - -if (kstrtou8 (pattern,10 , &instance)) -return NULL ; - - bit =__ffs64 (engine_info[i].mask) + instance; -if (bit >=fls64 (engine_info[i].mask)) -return NULL ; - - *mask =BIT_ULL (bit); -return &engine_info[i]; - } - -return NULL ; -} - -static int parse_engine (const char *s,const char *end_chars,u64 *mask, -const struct engine_info **pinfo) -{ -char buf[MAX_ENGINE_CLASS_CHARS +MAX_ENGINE_INSTANCE_CHARS +1 ]; -const struct engine_info *info; -size_t len; - - len =strcspn (s, end_chars); -if (len >=sizeof (buf)) -return -EINVAL ; - -memcpy (buf, s, len); - buf[len] ='\0' ; - - info =lookup_engine_info (buf, mask); -if (!info) -return -ENOENT ; - -if (pinfo) - *pinfo = info; - -return len; -} - -static ssize_t engines_allowed_store (struct config_item *item,const char *page, -size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); -ssize_t patternlen, p; -u64 mask, val =0 ; - -for (p =0 ; p < len; p += patternlen +1 ) { - patternlen =parse_engine (page + p,",\n" , &mask,NULL ); -if (patternlen <0 ) -return -EINVAL ; - - val |= mask; - } - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.engines_allowed = val; - -return len; -} - -static u64 get_gt_types_allowed (struct pci_dev *pdev) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -u64 mask; - -if (!dev) -return device_defaults.gt_types_allowed; - -scoped_guard (mutex, &dev->lock) - mask = dev->config.gt_types_allowed; -config_group_put (&dev->group); - -return mask; -} - -/** -* xe_configfs_primary_gt_allowed - determine whether primary GTs are supported -* @pdev: pci device -* -* Return: True if primary GTs are enabled, false if they have been disabled via -* configfs. -*/ -bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) -{ -return get_gt_types_allowed (pdev) &BIT_ULL (XE_GT_TYPE_MAIN ); -} - -/** -* xe_configfs_media_gt_allowed - determine whether media GTs are supported -* @pdev: pci device -* -* Return: True if the media GTs are enabled, false if they have been disabled -* via configfs. -*/ -bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) -{ -return get_gt_types_allowed (pdev) &BIT_ULL (XE_GT_TYPE_MEDIA ); -} - -static ssize_t gt_types_allowed_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); -char *p = page; - -for (size_t i =0 ; i <ARRAY_SIZE (gt_types); i++) -if (dev->gt_types_allowed &BIT_ULL (gt_types[i].type)) - p +=sprintf (p,"%s\n" , gt_types[i].name); - -return p - page; -} - -static ssize_t gt_types_allowed_store (struct config_item *item,const char *page, -size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); - char *buf __free(kfree) = kstrdup(page, GFP_KERNEL); -char *p = buf; -u64 typemask =0 ; - -if (!buf) -return -ENOMEM ; - -while (p) { -char *typename =strsep (&p,",\n" ); -bool matched = false; - -if (typename[0 ] =='\0' ) -continue ; - -for (size_t i =0 ; i <ARRAY_SIZE (gt_types); i++) { -if (strcmp (typename, gt_types[i].name) ==0 ) { - typemask |=BIT (gt_types[i].type); - matched = true; -break ; - } - } - -if (!matched) -return -EINVAL ; - } - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.gt_types_allowed = typemask; - -return len; -} - -/** -* xe_configfs_get_enable_multi_queue - get configfs enable_multi_queue setting -* @pdev: pci device -* -* Return: true if multi-queue is enabled for this device (the default), -* false if it has been force-disabled via configfs. -*/ -bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -bool ret; - -if (!dev) -return true; - -scoped_guard (mutex, &dev->lock) - ret = dev->config.enable_multi_queue; -config_group_put (&dev->group); - -return ret; -} - -static ssize_t enable_multi_queue_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); - -return sprintf (page,"%d\n" , dev->enable_multi_queue); -} - -static ssize_t enable_multi_queue_store (struct config_item *item,const char *page, -size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); -bool val; -int ret; - - ret =kstrtobool (page, &val); -if (ret) -return ret; - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.enable_multi_queue = val; - -return len; -} - -/** -* xe_configfs_get_psmi_enabled - get configfs enable_psmi setting -* @pdev: pci device -* -* Return: enable_psmi setting in configfs -*/ -bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -bool ret; - -if (!dev) -return false; - -scoped_guard (mutex, &dev->lock) - ret = dev->config.enable_psmi; -config_group_put (&dev->group); - -return ret; -} - -static ssize_t enable_psmi_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); - -return sprintf (page,"%d\n" , dev->enable_psmi); -} - -static ssize_t enable_psmi_store (struct config_item *item,const char *page,size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); -bool val; -int ret; - - ret =kstrtobool (page, &val); -if (ret) -return ret; - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.enable_psmi = val; - -return len; -} - -/** -* xe_configfs_get_survivability_mode - get configfs survivability mode attribute -* @pdev: pci device -* -* Return: survivability_mode attribute in configfs -*/ -bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -bool mode; - -if (!dev) -return device_defaults.survivability_mode; - -scoped_guard (mutex, &dev->lock) - mode = dev->config.survivability_mode; -config_group_put (&dev->group); - -return mode; -} - -static ssize_t survivability_mode_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); - -return sprintf (page,"%d\n" , dev->survivability_mode); -} - -static ssize_t survivability_mode_store (struct config_item *item,const char *page,size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); -bool survivability_mode; -int ret; - - ret =kstrtobool (page, &survivability_mode); -if (ret) -return ret; - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.survivability_mode = survivability_mode; - -return len; -} - -CONFIGFS_ATTR(, ctx_restore_mid_bb); -CONFIGFS_ATTR(, ctx_restore_post_bb); -CONFIGFS_ATTR(, engines_allowed); -CONFIGFS_ATTR(, gt_types_allowed); -CONFIGFS_ATTR(, enable_multi_queue); -CONFIGFS_ATTR(, enable_psmi); -CONFIGFS_ATTR(, survivability_mode); - -static struct configfs_attribute *xe_config_device_attrs[] = { - &attr_ctx_restore_mid_bb, - &attr_ctx_restore_post_bb, - &attr_engines_allowed, - &attr_gt_types_allowed, - &attr_enable_multi_queue, - &attr_enable_psmi, - &attr_survivability_mode, -NULL , -}; -static void xe_config_device_release (struct config_item *item) { -struct xe_config_group_device *dev =to_xe_config_group_device (item); +struct xe_config_group_device *dev =xe_configfs_to_group_device (item);mutex_destroy (&dev->lock); -kfree (dev->config.ctx_restore_mid_bb[0 ].cs); -kfree (dev->config.ctx_restore_post_bb[0 ].cs); +xe_configfs_debug_release_config (&dev->config);kfree (dev); }
@@ -1037,33 +167,14 @@ static struct configfs_item_operations xe_config_device_ops = { .release = xe_config_device_release, }; -static bool xe_config_device_is_visible (struct config_item *item, -struct configfs_attribute *attr,int n) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); - -if (attr == &attr_survivability_mode) { -if (!dev->desc->is_dgfx || dev->desc->platform <XE_BATTLEMAGE ) -return false; - } - -return true; -} - -static struct configfs_group_operations xe_config_device_group_ops = { - .is_visible = xe_config_device_is_visible, -}; -static const struct config_item_type xe_config_device_type = { .ct_item_ops = &xe_config_device_ops, - .ct_group_ops = &xe_config_device_group_ops, - .ct_attrs = xe_config_device_attrs, .ct_owner =THIS_MODULE , };static ssize_t sriov_max_vfs_show (struct config_item *item,char *page) { -struct xe_config_group_device *dev =to_xe_config_group_device (item->ci_parent); +struct xe_config_group_device *dev =xe_configfs_subgroup_to_group_device (item);guard (mutex)(&dev->lock);
@@ -1075,13 +186,13 @@ static ssize_t sriov_max_vfs_show(struct config_item *item, char *page)static ssize_t sriov_max_vfs_store (struct config_item *item,const char *page,size_t len) { -struct xe_config_group_device *dev =to_xe_config_group_device (item->ci_parent); +struct xe_config_group_device *dev =xe_configfs_subgroup_to_group_device (item);unsigned int max_vfs;int ret;guard (mutex)(&dev->lock); -if (is_bound (dev)) +if (xe_configfs_is_bound (dev))return -EBUSY ; ret =kstrtouint (page,0 , &max_vfs);
@@ -1097,7 +208,7 @@ static ssize_t sriov_max_vfs_store(struct config_item *item, const char *page, sstatic ssize_t sriov_admin_only_pf_show (struct config_item *item,char *page) { -struct xe_config_group_device *dev =to_xe_config_group_device (item->ci_parent); +struct xe_config_group_device *dev =xe_configfs_subgroup_to_group_device (item);guard (mutex)(&dev->lock);
@@ -1106,13 +217,13 @@ static ssize_t sriov_admin_only_pf_show(struct config_item *item, char *page)static ssize_t sriov_admin_only_pf_store (struct config_item *item,const char *page,size_t len) { -struct xe_config_group_device *dev =to_xe_config_group_device (item->ci_parent); +struct xe_config_group_device *dev =xe_configfs_subgroup_to_group_device (item);bool admin_only_pf;int ret;guard (mutex)(&dev->lock); -if (is_bound (dev)) +if (xe_configfs_is_bound (dev))return -EBUSY ; ret =kstrtobool (page, &admin_only_pf);
@@ -1135,7 +246,7 @@ static struct configfs_attribute *xe_config_sriov_attrs[] = {static bool xe_config_sriov_is_visible (struct config_item *item,struct configfs_attribute *attr,int n) { -struct xe_config_group_device *dev =to_xe_config_group_device (item->ci_parent); +struct xe_config_group_device *dev =xe_configfs_subgroup_to_group_device (item);if (attr == &sriov_attr_max_vfs && dev->mode !=XE_SRIOV_MODE_PF )return false;
@@ -1271,7 +382,17 @@ static struct configfs_subsystem xe_configfs = { }, }; -static struct xe_config_group_device *find_xe_config_group_device (struct pci_dev *pdev) +/** +* xe_configfs_find_group_device() - Find a configfs group by PCI device. +* @pdev: the &pci_dev to look up +* +* Searches the configfs subsystem for a group whose name matches @pdev. +* If found, the returned group has an elevated reference count; the caller +* must call config_group_put() when done. +* +* Return: pointer to the matching &xe_config_group_device, or NULL. +*/ +struct xe_config_group_device *xe_configfs_find_group_device (struct pci_dev *pdev) {struct config_item *item;
@@ -1282,23 +403,25 @@ static struct xe_config_group_device *find_xe_config_group_device(struct pci_devif (!item)return NULL ; -return to_xe_config_group_device (item); +return xe_configfs_to_group_device (item); }static void dump_custom_dev_config (struct pci_dev *pdev,struct xe_config_group_device *dev) {#define PRI_CUSTOM_ATTR (fmt_, attr_) do { \ - if (dev->config.attr_ != device_defaults.attr_) \ + if (dev->config.attr_ != xe_configfs_device_defaults.attr_) \ pci_info(pdev, "configfs: " __stringify(attr_) " = " fmt_ "\n", \ dev->config.attr_); \ } while (0) -PRI_CUSTOM_ATTR ("%llx" , engines_allowed); -PRI_CUSTOM_ATTR ("%llx" , gt_types_allowed); -PRI_CUSTOM_ATTR ("%d" , enable_multi_queue); -PRI_CUSTOM_ATTR ("%d" , enable_psmi); -PRI_CUSTOM_ATTR ("%d" , survivability_mode); +#if IS_ENABLED (CONFIG_DRM_XE_DEBUG ) +PRI_CUSTOM_ATTR ("%llx" , debug.engines_allowed); +PRI_CUSTOM_ATTR ("%llx" , debug.gt_types_allowed); +PRI_CUSTOM_ATTR ("%d" , debug.enable_multi_queue); +PRI_CUSTOM_ATTR ("%d" , debug.enable_psmi); +PRI_CUSTOM_ATTR ("%d" , debug.survivability_mode); +#endif PRI_CUSTOM_ATTR ("%u" , sriov.admin_only_pf);#undef PRI_CUSTOM_ATTR
@@ -1313,13 +436,13 @@ static void dump_custom_dev_config(struct pci_dev *pdev,*/ void xe_configfs_check_device (struct pci_dev *pdev) { -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +struct xe_config_group_device *dev =xe_configfs_find_group_device (pdev);if (!dev)return ;/* memcmp here is safe as both are zero-initialized */ -if (memcmp (&dev->config, &device_defaults,sizeof (dev->config))) { +if (memcmp (&dev->config, &xe_configfs_device_defaults,sizeof (dev->config))) {pci_info (pdev,"Found custom settings in configfs\n" );dump_custom_dev_config (pdev, dev); }
@@ -1341,7 +464,7 @@ void xe_configfs_check_device(struct pci_dev *pdev)*/ bool xe_configfs_admin_only_pf (struct pci_dev *pdev) { -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +struct xe_config_group_device *dev =xe_configfs_find_group_device (pdev);bool admin_only_pf;if (!dev)
@@ -1366,7 +489,7 @@ bool xe_configfs_admin_only_pf(struct pci_dev *pdev)*/ unsigned int xe_configfs_get_max_vfs (struct pci_dev *pdev) { -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +struct xe_config_group_device *dev =xe_configfs_find_group_device (pdev);unsigned int max_vfs;if (!dev)
drivers/gpu/drm/xe/xe_configfs.h +64 -24
106 lines not on this page · raw message
drivers/gpu/drm/xe/xe_configfs_debug.c +956 -0
968 lines not on this page · raw message
drivers/gpu/drm/xe/xe_configfs_debug.h +38 -1
@@ -5,9 +5,46 @@#ifndef _XE_CONFIGFS_DEBUG_H_#define _XE_CONFIGFS_DEBUG_H_ +#include <linux/types.h> + +#include "xe_hw_engine_types.h" + +struct pci_dev ; +struct xe_config_device ; +#if IS_ENABLED (CONFIG_DRM_XE_DEBUG ) &&IS_ENABLED (CONFIG_CONFIGFS_FS ) -struct config_item_type ;extern const struct config_item_type xe_configfs_debug_type; +void xe_configfs_debug_release_config (struct xe_config_device *config); +u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, +enum xe_engine_class class, +const u32 **cs); +u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, +enum xe_engine_class class, +const u32 **cs); +u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev); +bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev); +bool xe_configfs_media_gt_allowed (struct pci_dev *pdev); +bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev); +bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev); +bool xe_configfs_get_survivability_mode (struct pci_dev *pdev); +#else +/* +* Dummy values here are not used since these function accesses are always +* wrapped in CONFIG_DRM_XE_DEBUG. +*/ +static inline void xe_configfs_debug_release_config (struct xe_config_device *config) { } +static inline u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, +enum xe_engine_class class, +const u32 **cs) {return 0 ; } +static inline u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, +enum xe_engine_class class, +const u32 **cs) {return 0 ; } +static inline u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) {return U64_MAX ; } +static inline bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) {return true; } +static inline bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) {return true; } +static inline bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) {return true; } +static inline bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) {return false; } +static inline bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) {return false; }#endif #endif /* _XE_CONFIGFS_DEBUG_H_ */
drivers/gpu/drm/xe/xe_configfs_types.h +11 -7
@@ -32,13 +32,17 @@ struct xe_config_group_device {* type, entries are sorted alphabetically. */ struct xe_config_device { -struct wa_bb ctx_restore_mid_bb[XE_ENGINE_CLASS_MAX ]; -struct wa_bb ctx_restore_post_bb[XE_ENGINE_CLASS_MAX ]; -u64 engines_allowed; -u64 gt_types_allowed; -bool enable_multi_queue; -bool enable_psmi; -bool survivability_mode; +#if IS_ENABLED (CONFIG_DRM_XE_DEBUG ) +struct { +struct wa_bb ctx_restore_mid_bb[XE_ENGINE_CLASS_MAX ]; +struct wa_bb ctx_restore_post_bb[XE_ENGINE_CLASS_MAX ]; +u64 engines_allowed; +u64 gt_types_allowed; +bool enable_multi_queue; +bool enable_psmi; +bool survivability_mode; + } debug; +#endif struct {unsigned int max_vfs;bool admin_only_pf;
drivers/gpu/drm/xe/xe_guc.c +1 -0
@@ -19,6 +19,7 @@#include "regs/xe_irq_regs.h" #include "xe_bo.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_device.h" #include "xe_force_wake.h" #include "xe_gt.h"
drivers/gpu/drm/xe/xe_guc_ads.c +1 -0
@@ -17,6 +17,7 @@#include "regs/xe_guc_regs.h" #include "xe_bo.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_gt.h" #include "xe_gt_ccs_mode.h" #include "xe_gt_mcr.h"
drivers/gpu/drm/xe/xe_hw_engine.c +1 -0
@@ -18,6 +18,7 @@#include "xe_assert.h" #include "xe_bo.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_device.h" #include "xe_execlist.h" #include "xe_force_wake.h"
drivers/gpu/drm/xe/xe_lrc.c +1 -0
@@ -19,6 +19,7 @@#include "xe_bb.h" #include "xe_bo.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_device.h" #include "xe_drm_client.h" #include "xe_exec_queue.h"
drivers/gpu/drm/xe/xe_pci.c +1 -0
@@ -19,6 +19,7 @@#include "regs/xe_gt_regs.h" #include "regs/xe_regs.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_device.h" #include "xe_drv.h" #include "xe_gt.h"
drivers/gpu/drm/xe/xe_psmi.c +1 -0
@@ -8,6 +8,7 @@#include "xe_bo.h" #include "xe_device_types.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_psmi.h" /*
drivers/gpu/drm/xe/xe_rtp.c +1 -0
@@ -10,6 +10,7 @@#include <uapi/drm/xe_drm.h> #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_device.h" #include "xe_gt.h" #include "xe_gt_topology.h"
drivers/gpu/drm/xe/xe_survivability_mode.c +1 -0
@@ -11,6 +11,7 @@#include <linux/sysfs.h> #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_device.h" #include "xe_heci_gsc.h" #include "xe_i2c.h"
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH 05/10] drm/xe: Move debug configfs entries to xe_configfs_debug.c
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Dangling pointer returned by xe_configfs_get_ctx_restore_mid_bb leads to Use-After-Free during probe.
- [High] Out-of-bounds read in parse_wa_bb_lines() when parsing input without trailing whitespace. --
--- Patch [5]: [PATCH 05/10] drm/xe: Move debug configfs entries to xe_configfs_debug.c --- commit 099241979e5a310cfae46aa5d3f9fe454fd151cd
Author: Stuart Summers <[email protected]>
drm/xe: Move debug configfs entries to xe_configfs_debug.c
Move the debug specific configfs attributes into the new xe_configfs_debug.c file under a new debug configfs subdirectory.
Quoted 3 lines
drivers/gpu/drm/xe/xe_configfs_debug.c new file +0
-0
[ ... ]
Quoted 10 lines
drivers/gpu/drm/xe/xe_configfs_debug.c new file +10
-0+u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, +enum xe_engine_class class, +const u32 **cs) +{ +struct xe_config_group_device *dev =find_device (pdev); +u32 len; + +if (!dev) +return 0 ; +
drivers/gpu/drm/xe/xe_configfs_debug.c line 265
Quoted 10 lines
drivers/gpu/drm/xe/xe_configfs_debug.c new file +10
-0+ scoped_guard(mutex, &dev->lock) { +if (cs) + *cs = dev->config.debug.ctx_restore_mid_bb[class].cs; + + len = dev->config.debug.ctx_restore_mid_bb[class].len; + } +config_group_put (&dev->group); + +return len; +}
[Severity: High]
This is a pre-existing issue, but can this lead to a use-after-free during driver probe? The pointer is read into the cs argument while holding dev->lock, but the lock and the config group reference are both released before the pointer is returned to the caller.
If a concurrent write to the configfs attribute executes ctx_restore_mid_bb_store() and krealloc() frees the old memory, or if the configfs directory is removed causing xe_config_device_release() to free the memory, the caller will be left with a dangling pointer.
For example, in xe_lrc.c:setup_configfs_mid_ctx_restore_bb():
count = xe_configfs_get_ctx_restore_mid_bb(to_pci_dev(xe->drm.dev),
hwe->class, &user_batch);
...memcpy(cmd, user_batch, count * sizeof(u32));
Can we safely dereference user_batch here without holding the lock?
[ ... ]
Quoted 24 lines
drivers/gpu/drm/xe/xe_configfs_debug.c new file +24
-0+static ssize_t parse_wa_bb_lines (const char *lines, +struct wa_bb wa_bb[static XE_ENGINE_CLASS_MAX ]) +{ +ssize_t dwords =0 , ret; +const char *p; + +for (p = lines; *p; p++) { +const struct engine_info *info =NULL ; +u32 val, val2; + +/* Also allow empty lines */ + p +=strspn (p," \t\n" ); +if (!*p) +break ; + + ret =parse_engine (p," \t\n" ,NULL , &info); +if (ret <0 ) +return ret; + + p += ret; + p +=strspn (p," \t" ); + +if (str_has_prefix (p,"cmd" )) { +for (p +=strlen ("cmd" ); *p;) {
drivers/gpu/drm/xe/xe_configfs_debug.c line 442
Quoted 10 lines
drivers/gpu/drm/xe/xe_configfs_debug.c new file +10
-0+ ret =parse_hex (p, &val); +if (ret <0 ) +return -EINVAL ; +if (!ret) +break ; + + p += ret; + dwords++; +wa_bb_append (&wa_bb[info->engine_class], val); + }
[Severity: High]
This isn't a bug introduced by this patch, but does this loop read past the end of the buffer if the input string does not end with a trailing space or newline?
In the outer loop, the pointer p is unconditionally incremented by p++ after each iteration. If parse_hex() processes a token without trailing whitespace (for example, echo -n 'rcs cmd 1'), it will advance p exactly to the null terminator. The inner loop terminates because *p is null, and execution falls through to the end of the outer loop body.
The outer loop then executes p++, advancing the pointer past the null terminator, and the loop condition *p evaluates out-of-bounds memory. Could this trigger a slab-out-of-bounds read?
Quoted 1 line
drivers/gpu/drm/xe/xe_configfs_debug.c new file +1
-0+ }else if (str_has_prefix (p,"reg" )) {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH 05/10] drm/xe: Move debug configfs entries to xe_configfs_debug.c
In reply to Stuart SummersQuoted 205 lines · Stuart Summers
Move the debug specific configfs attributes into the new
xe_configfs_debug.cfile under a new debug configfs subdirectory. Ensure these are wrapped inCONFIG_DRM_XE_DEBUGto allow finer grained debug changes outside of more ABI specific configfs entries.Signed-off-by Stuart Summers <[email protected]>Assisted-by Copilot:claude-sonnet-4.6,claude-sonnet-5,claude-opus-5--- drivers/gpu/drm/xe/xe_configfs.c | 991 ++------------------- drivers/gpu/drm/xe/xe_configfs.h | 88 +- drivers/gpu/drm/xe/xe_configfs_debug.c | 956 ++++++++++++++++++++ drivers/gpu/drm/xe/xe_configfs_debug.h | 39 +- drivers/gpu/drm/xe/xe_configfs_types.h | 18 +- drivers/gpu/drm/xe/xe_guc.c | 1 + drivers/gpu/drm/xe/xe_guc_ads.c | 1 + drivers/gpu/drm/xe/xe_hw_engine.c | 1 + drivers/gpu/drm/xe/xe_lrc.c | 1 + drivers/gpu/drm/xe/xe_pci.c | 1 + drivers/gpu/drm/xe/xe_psmi.c | 1 + drivers/gpu/drm/xe/xe_rtp.c | 1 + drivers/gpu/drm/xe/xe_survivability_mode.c | 1 + 13 files changed, 1134 insertions(+), 966 deletions(-)drivers/gpu/drm/xe/xe_configfs.c +3
-149@@ -6,17 +6,14 @@#include <linux/bitops.h> #include <linux/configfs.h> #include <linux/cleanup.h> -#include <linux/find.h> #include <linux/init.h> #include <linux/module.h> #include <linux/pci.h> #include <linux/string.h> -#include "instructions/xe_mi_commands.h" #include "xe_configfs.h" #include "xe_configfs_debug.h" #include "xe_defaults.h" -#include "xe_gt_types.h" #include "xe_module.h" /** @@ -50,16 +47,9 @@* * /sys/kernel/config/xe/ * ├── 0000:00:02.0 -* │ └── ... -* ├── 0000:00:02.1 -* │ └── ... -* : -* └── 0000:03:00.0 -* ├── engines_allowed -* ├── gt_types_allowed -* ├── enable_multi_queue -* ├── enable_psmi -* └── survivability_mode +* │ └── ... +* └── 0000:00:02.1 +* └── ... * * After configuring the attributes as per next section, the device can be * probed with:: @@ -71,157 +61,6 @@* Configure Attributes * ==================== * - -* Context restore BB -* ------------------ -* -* Allow to execute a batch buffer during any context switches. When the -* GPU is restoring the context, it executes additional commands. It's useful -* for testing additional workarounds and validating certain HW behaviors: it's -* not intended for normal execution and will taint the kernel with TAINT_TEST -* when used. -* -* The syntax allows to pass straight instructions to be executed by the engine -* in a batch buffer or set specific registers. -* -* #. Generic instruction:: -* -* <engine-class> cmd <instr> [[dword0] [dword1] [...]] -* -* #. Simple register setting:: -* -* <engine-class> reg <address> <value> -* -* Commands are saved per engine class: all instances of that class will execute -* those commands during context switch. The instruction, dword arguments, -* addresses and values are in hex format like in the examples below. -* -* #. Execute a LRI command to write 0xDEADBEEF to register 0x4f10 after the -* normal context restore:: -* -* # echo 'rcs cmd 11000001 4F100 DEADBEEF' \ -* > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_post_bb -* -* #. Execute a LRI command to write 0xDEADBEEF to register 0x4f10 at the -* beginning of the context restore:: -* -* # echo 'rcs cmd 11000001 4F100 DEADBEEF' \ -* > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_mid_bb - -* #. Load certain values in a couple of registers (it can be used as a simpler -* alternative to the `cmd`) action:: -* -* # cat > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_post_bb <<EOF -* rcs reg 4F100 DEADBEEF -* rcs reg 4F104 FFFFFFFF -* EOF -* -* .. note:: -* -* When using multiple lines, make sure to use a command that is -* implemented with a single write syscall, like HEREDOC. -* -* Currently this is implemented only for post and mid context restore and -* these attributes can only be set before binding to the device. -* -* Allowed engines: -* ---------------- -* -* Allow only a set of engine(s) to be available, disabling the other engines -* even if they are available in hardware. This is applied after HW fuses are -* considered on each tile. Examples: -* -* Allow only one render and one copy engines, nothing else:: -* -* # echo 'rcs0,bcs0' > /sys/kernel/config/xe/0000:03:00.0/engines_allowed -* -* Allow only compute engines and first copy engine:: -* -* # echo 'ccs*,bcs0' > /sys/kernel/config/xe/0000:03:00.0/engines_allowed -* -* Note that the engine names are the per-GT hardware names. On multi-tile -* platforms, writing ``rcs0,bcs0`` to this file would allow the first render -* and copy engines on each tile. -* -* The requested configuration may not be supported by the platform and driver -* may fail to probe. For example: if at least one copy engine is expected to be -* available for migrations, but it's disabled. This is intended for debugging -* purposes only. -* -* This attribute can only be set before binding to the device. -* -* Allowed GT types: -* ----------------- -* -* Allow only specific types of GTs to be detected and initialized by the -* driver. Any combination of GT types can be enabled/disabled, although -* some settings will cause the device to fail to probe. -* -* Writes support both comma- and newline-separated input format. Reads -* will always return one GT type per line. "primary" and "media" are the -* GT type names supported by this interface. -* -* This attribute can only be set before binding to the device. -* -* Examples: -* -* Allow both primary and media GTs to be initialized and used. This matches -* the driver's default behavior:: -* -* # echo 'primary,media' > /sys/kernel/config/xe/0000:03:00.0/gt_types_allowed -* -* Allow only the primary GT of each tile to be initialized and used, -* effectively disabling the media GT if it exists on the platform:: -* -* # echo 'primary' > /sys/kernel/config/xe/0000:03:00.0/gt_types_allowed -* -* Allow only the media GT of each tile to be initialized and used, -* effectively disabling the primary GT. **This configuration will cause -* device probe failure on all current platforms, but may be allowed on -* igpu platforms in the future**:: -* -* # echo 'media' > /sys/kernel/config/xe/0000:03:00.0/gt_types_allowed -* -* Disable all GTs. Only other GPU IP (such as display) is potentially usable. -* **This configuration will cause device probe failure on all current -* platforms, but may be allowed on igpu platforms in the future**:: -* -* # echo '' > /sys/kernel/config/xe/0000:03:00.0/gt_types_allowed -* -* Enable multi-queue -* ------------------ -* -* Multi-queue support on the device is enabled by default where the -* hardware supports it. Writing 0 force-disables multi-queue support: -* multi-queue exec-queue group creation via ioctl is refused, and the -* GuC feature is disabled:: -* -* # echo 0 > /sys/kernel/config/xe/0000:03:00.0/enable_multi_queue -* -* This attribute can only be set before binding to the device. -* -* PSMI -* ---- -* -* Enable extra debugging capabilities to trace engine execution. Only useful -* during early platform enabling and requires additional hardware connected. -* Once it's enabled, additionals WAs are added and runtime configuration is -* done via debugfs. Example to enable it::
drivers/gpu/drm/xe/xe_configfs.c line 219
Quoted 10 lines
drivers/gpu/drm/xe/xe_configfs.c +0
-10-* -* # echo 1 > /sys/kernel/config/xe/0000:03:00.0/enable_psmi -* -* This attribute can only be set before binding to the device. -* -* Survivability mode: -* ------------------- -* -* Enable survivability mode on supported cards. This setting only takes -* effect when probing the device. Example to enable it::
I didn't review the code movement in this patch in depth, but the one thing that I'm uncertain about is whether survivability mode should have been swept up in this move. My understanding is that unlike the other options which are meant for developers hacking on the driver, configurable survivability mode is a true production feature intended for end users to get the minimal driver support necessary to deal with a bad firmware flash, failing hardware, etc. I know there are cases where the driver can auto-detect the need to enter survivability mode without the configfs interface (i.e., various RAS error reports and such), but I thought manual entry through configfs was still something users may need in some cases? If so that would mean we should keep this available even when the debug options aren't compiled in.
+Cc Riana in case my understanding is off.
Matt
Quoted 2,230 lines
drivers/gpu/drm/xe/xe_configfs.c +54
-775-* -* # echo 1 > /sys/kernel/config/xe/0000:03:00.0/survivability_mode -* -* This attribute can only be set before binding to the device. -* * Max SR-IOV Virtual Functions * ---------------------------- * @@ -256,12 +95,16 @@* # rmdir /sys/kernel/config/xe/0000:03:00.0/ */ -static const struct xe_config_device device_defaults = { - .engines_allowed =U64_MAX , - .gt_types_allowed =U64_MAX , - .enable_multi_queue = true, - .enable_psmi = false, - .survivability_mode = false, +const struct xe_config_device xe_configfs_device_defaults = { +#if IS_ENABLED(CONFIG_DRM_XE_DEBUG) + .debug = { + .engines_allowed =U64_MAX , + .gt_types_allowed =U64_MAX , + .enable_multi_queue = true, + .enable_psmi = false, + .survivability_mode = false, + }, +#endif .sriov = { .max_vfs =XE_DEFAULT_MAX_VFS , .admin_only_pf =XE_DEFAULT_ADMIN_ONLY_PF ,@@ -270,50 +113,22 @@ static const struct xe_config_device device_defaults = {static void set_device_defaults (struct xe_config_device *config) { - *config = device_defaults; + *config = xe_configfs_device_defaults;#ifdef CONFIG_PCI_IOV config->sriov.max_vfs = xe_modparam.max_vfs;#endif } -struct engine_info { -const char *cls; -u64 mask; -enum xe_engine_class engine_class; -}; - -/* Some helpful macros to aid on the sizing of buffer allocation when parsing */ -#define MAX_ENGINE_CLASS_CHARS 5 -#define MAX_ENGINE_INSTANCE_CHARS 2 - -static const struct engine_info engine_info[] = { - { .cls ="rcs" , .mask =XE_HW_ENGINE_RCS_MASK , .engine_class =XE_ENGINE_CLASS_RENDER }, - { .cls ="bcs" , .mask =XE_HW_ENGINE_BCS_MASK , .engine_class =XE_ENGINE_CLASS_COPY }, - { .cls ="vcs" , .mask =XE_HW_ENGINE_VCS_MASK , .engine_class =XE_ENGINE_CLASS_VIDEO_DECODE }, - { .cls ="vecs" , .mask =XE_HW_ENGINE_VECS_MASK , .engine_class =XE_ENGINE_CLASS_VIDEO_ENHANCE }, - { .cls ="ccs" , .mask =XE_HW_ENGINE_CCS_MASK , .engine_class =XE_ENGINE_CLASS_COMPUTE }, - { .cls ="gsccs" , .mask =XE_HW_ENGINE_GSCCS_MASK , .engine_class =XE_ENGINE_CLASS_OTHER }, -}; - -static const struct { -const char *name; -enum xe_gt_type type; -} gt_types[] = { - { .name ="primary" , .type =XE_GT_TYPE_MAIN }, - { .name ="media" , .type =XE_GT_TYPE_MEDIA }, -}; - -static struct xe_config_group_device *to_xe_config_group_device (struct config_item *item) -{ - return container_of(to_config_group(item), struct xe_config_group_device, group); -} - -static struct xe_config_device *to_xe_config_device (struct config_item *item) -{ -return &to_xe_config_group_device (item)->config; -} - -static bool is_bound (struct xe_config_group_device *dev) +/** +* xe_configfs_is_bound - check whether the matching pci device is bound +* @dev: configfs group device +* +* Caller must hold @dev->lock. +* +* Return: true if the matching pci_dev is already bound to a driver, +* false otherwise. +*/ +bool xe_configfs_is_bound (struct xe_config_group_device *dev) {unsigned int domain, bus, slot, function;struct pci_dev *pdev;@@ -338,698 +153,13 @@ static bool is_bound(struct xe_config_group_device *dev)return ret; } -static struct xe_config_group_device *find_xe_config_group_device (struct pci_dev *pdev); - -/** -* xe_configfs_get_ctx_restore_mid_bb - get configfs ctx_restore_mid_bb setting -* @pdev: pci device -* @class: hw engine class -* @cs: pointer to the bb to use - only valid during probe -* -* Return: Number of dwords used in the mid_ctx_restore setting in configfs -*/ -u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, -enum xe_engine_class class, -const u32 **cs) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -u32 len; - -if (!dev) -return 0 ; - - scoped_guard(mutex, &dev->lock) { -if (cs) - *cs = dev->config.ctx_restore_mid_bb[class].cs; - - len = dev->config.ctx_restore_mid_bb[class].len; - } -config_group_put (&dev->group); - -return len; -} - -/** -* xe_configfs_get_ctx_restore_post_bb - get configfs ctx_restore_post_bb setting -* @pdev: pci device -* @class: hw engine class -* @cs: pointer to the bb to use - only valid during probe -* -* Return: Number of dwords used in the post_ctx_restore setting in configfs -*/ -u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, -enum xe_engine_class class, -const u32 **cs) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -u32 len; - -if (!dev) -return 0 ; - - scoped_guard(mutex, &dev->lock) { - *cs = dev->config.ctx_restore_post_bb[class].cs; - len = dev->config.ctx_restore_post_bb[class].len; - } -config_group_put (&dev->group); - -return len; -} - -static bool wa_bb_read_advance (bool dereference,char **p, -const char *append,size_t len, -size_t *max_size) -{ -if (dereference) { -if (len >= *max_size) -return false; - *max_size -= len; -if (append) -memcpy (*p, append, len); - } - - *p += len; - -return true; -} - -static ssize_t wa_bb_show (struct xe_config_group_device *dev, -struct wa_bb wa_bb[static XE_ENGINE_CLASS_MAX ], -char *data,size_t sz) -{ -char *p = data; - -guard (mutex)(&dev->lock); - -for (size_t i =0 ; i <ARRAY_SIZE (engine_info); i++) { -enum xe_engine_class ec = engine_info[i].engine_class; -size_t len; - -if (!wa_bb[ec].len) -continue ; - - len =snprintf (p, sz,"%s:" , engine_info[i].cls); -if (!wa_bb_read_advance (data, &p,NULL , len, &sz)) -return -ENOBUFS ; - -for (size_t j =0 ; j < wa_bb[ec].len; j++) { - len =snprintf (p, sz," %08x" , wa_bb[ec].cs[j]); -if (!wa_bb_read_advance (data, &p,NULL , len, &sz)) -return -ENOBUFS ; - } - -if (!wa_bb_read_advance (data, &p,"\n" ,1 , &sz)) -return -ENOBUFS ; - } - -if (!wa_bb_read_advance (data, &p,"" ,1 , &sz)) -return -ENOBUFS ; - -/* Reserve one more to match check for '\0' */ -if (!data) - p++; - -return p - data; -} - -static ssize_t ctx_restore_mid_bb_show (struct config_item *item,char *page) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); - -return wa_bb_show (dev, dev->config.ctx_restore_mid_bb, page,SZ_4K ); -} - -static ssize_t ctx_restore_post_bb_show (struct config_item *item,char *page) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); - -return wa_bb_show (dev, dev->config.ctx_restore_post_bb, page,SZ_4K ); -} - -static void wa_bb_append (struct wa_bb *wa_bb,u32 val) -{ -if (wa_bb->cs) - wa_bb->cs[wa_bb->len] = val; - - wa_bb->len++; -} - -static ssize_t parse_hex (const char *line,u32 *pval) -{ -char numstr[12 ]; -const char *p; -ssize_t numlen; - - p = line +strspn (line," \t" ); -if (!*p || *p =='\n' ) -return 0 ; - - numlen =strcspn (p," \t\n" ); -if (!numlen || numlen >=sizeof (numstr) -1 ) -return -EINVAL ; - -memcpy (numstr, p, numlen); - numstr[numlen] ='\0' ; - p += numlen; - -if (kstrtou32 (numstr,16 , pval)) -return -EINVAL ; - -return p - line; -} - -static int parse_engine (const char *s,const char *end_chars,u64 *mask, -const struct engine_info **pinfo); - -/* -* Parse lines with the format -* -* <engine-class> cmd <u32> <u32...> -* <engine-class> reg <u32_addr> <u32_val> -* -* and optionally save them in @wa_bb[i].cs is non-NULL. -* -* Return the number of dwords parsed. -*/ -static ssize_t parse_wa_bb_lines (const char *lines, -struct wa_bb wa_bb[static XE_ENGINE_CLASS_MAX ]) -{ -ssize_t dwords =0 , ret; -const char *p; - -for (p = lines; *p; p++) { -const struct engine_info *info =NULL ; -u32 val, val2; - -/* Also allow empty lines */ - p +=strspn (p," \t\n" ); -if (!*p) -break ; - - ret =parse_engine (p," \t\n" ,NULL , &info); -if (ret <0 ) -return ret; - - p += ret; - p +=strspn (p," \t" ); - -if (str_has_prefix (p,"cmd" )) { -for (p +=strlen ("cmd" ); *p;) { - ret =parse_hex (p, &val); -if (ret <0 ) -return -EINVAL ; -if (!ret) -break ; - - p += ret; - dwords++; -wa_bb_append (&wa_bb[info->engine_class], val); - } - }else if (str_has_prefix (p,"reg" )) { - p +=strlen ("reg" ); - ret =parse_hex (p, &val); -if (ret <=0 ) -return -EINVAL ; - - p += ret; - ret =parse_hex (p, &val2); -if (ret <=0 ) -return -EINVAL ; - - p += ret; - dwords +=3 ; -wa_bb_append (&wa_bb[info->engine_class], -MI_LOAD_REGISTER_IMM |MI_LRI_NUM_REGS (1 )); -wa_bb_append (&wa_bb[info->engine_class], val); -wa_bb_append (&wa_bb[info->engine_class], val2); - }else { -return -EINVAL ; - } - } - -return dwords; -} - -static ssize_t wa_bb_store (struct wa_bb wa_bb[static XE_ENGINE_CLASS_MAX ], -struct xe_config_group_device *dev, -const char *page,size_t len) -{ -/* tmp_wa_bb must match wa_bb's size */ -struct wa_bb tmp_wa_bb[XE_ENGINE_CLASS_MAX ] = { }; -ssize_t count, class; -u32 *tmp; - -/* 1. Count dwords - wa_bb[i].cs is NULL for all classes */ - count =parse_wa_bb_lines (page, tmp_wa_bb); -if (count <0 ) -return count; - -guard (mutex)(&dev->lock); - -if (is_bound (dev)) -return -EBUSY ; - -/* -* 2. Allocate a u32 array and set the pointers to the right positions -* according to the length of each class' wa_bb -*/ - tmp =krealloc (wa_bb[0 ].cs, count *sizeof (u32),GFP_KERNEL ); -if (!tmp) -return -ENOMEM ; - -if (!count) { -memset (wa_bb,0 ,sizeof (tmp_wa_bb)); -return len; - } - -for (class =0 , count =0 ; class <XE_ENGINE_CLASS_MAX ; ++class) { - tmp_wa_bb[class].cs = tmp + count; - count += tmp_wa_bb[class].len; - tmp_wa_bb[class].len =0 ; - } - -/* 3. Parse wa_bb lines again, this time saving the values */ - count =parse_wa_bb_lines (page, tmp_wa_bb); -if (count <0 ) -return count; - -memcpy (wa_bb, tmp_wa_bb,sizeof (tmp_wa_bb)); - -return len; -} - -static ssize_t ctx_restore_mid_bb_store (struct config_item *item, -const char *data,size_t sz) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); - -return wa_bb_store (dev->config.ctx_restore_mid_bb, dev, data, sz); -} - -static ssize_t ctx_restore_post_bb_store (struct config_item *item, -const char *data,size_t sz) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); - -return wa_bb_store (dev->config.ctx_restore_post_bb, dev, data, sz); -} - -/** -* xe_configfs_get_engines_allowed - get engine allowed mask from configfs -* @pdev: pci device -* -* Return: engine mask with allowed engines set in configfs -*/ -u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -u64 engines_allowed; - -if (!dev) -return device_defaults.engines_allowed; - - scoped_guard(mutex, &dev->lock) - engines_allowed = dev->config.engines_allowed; -config_group_put (&dev->group); - -return engines_allowed; -} - -static ssize_t engines_allowed_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); -char *p = page; - -for (size_t i =0 ; i <ARRAY_SIZE (engine_info); i++) { -u64 mask = engine_info[i].mask; - -if ((dev->engines_allowed & mask) == mask) { - p +=sprintf (p,"%s*\n" , engine_info[i].cls); - }else if (mask & dev->engines_allowed) { -u16 bit0 =__ffs64 (mask), bit; - - mask &= dev->engines_allowed; - -for_each_set_bit (bit, (const unsigned long *)&mask,64 ) - p +=sprintf (p,"%s%u\n" , engine_info[i].cls, - bit - bit0); - } - } - -return p - page; -} - -/* -* Lookup engine_info. If @mask is not NULL, reduce the mask according to the -* instance in @pattern. -* -* Examples of inputs: -* - lookup_engine_info("rcs0", &mask): return "rcs" entry from @engine_info and -* mask == BIT_ULL(XE_HW_ENGINE_RCS0) -* - lookup_engine_info("rcs*", &mask): return "rcs" entry from @engine_info and -* mask == XE_HW_ENGINE_RCS_MASK -* - lookup_engine_info("rcs", NULL): return "rcs" entry from @engine_info -*/ -static const struct engine_info *lookup_engine_info (const char *pattern,u64 *mask) -{ -for (size_t i =0 ; i <ARRAY_SIZE (engine_info); i++) { -u8 instance; -u16 bit; - -if (!str_has_prefix (pattern, engine_info[i].cls)) -continue ; - - pattern +=strlen (engine_info[i].cls); -if (!mask) -return *pattern ?NULL : &engine_info[i]; - -if (!strcmp (pattern,"*" )) { - *mask = engine_info[i].mask; -return &engine_info[i]; - } - -if (kstrtou8 (pattern,10 , &instance)) -return NULL ; - - bit =__ffs64 (engine_info[i].mask) + instance; -if (bit >=fls64 (engine_info[i].mask)) -return NULL ; - - *mask =BIT_ULL (bit); -return &engine_info[i]; - } - -return NULL ; -} - -static int parse_engine (const char *s,const char *end_chars,u64 *mask, -const struct engine_info **pinfo) -{ -char buf[MAX_ENGINE_CLASS_CHARS +MAX_ENGINE_INSTANCE_CHARS +1 ]; -const struct engine_info *info; -size_t len; - - len =strcspn (s, end_chars); -if (len >=sizeof (buf)) -return -EINVAL ; - -memcpy (buf, s, len); - buf[len] ='\0' ; - - info =lookup_engine_info (buf, mask); -if (!info) -return -ENOENT ; - -if (pinfo) - *pinfo = info; - -return len; -} - -static ssize_t engines_allowed_store (struct config_item *item,const char *page, -size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); -ssize_t patternlen, p; -u64 mask, val =0 ; - -for (p =0 ; p < len; p += patternlen +1 ) { - patternlen =parse_engine (page + p,",\n" , &mask,NULL ); -if (patternlen <0 ) -return -EINVAL ; - - val |= mask; - } - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.engines_allowed = val; - -return len; -} - -static u64 get_gt_types_allowed (struct pci_dev *pdev) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -u64 mask; - -if (!dev) -return device_defaults.gt_types_allowed; - -scoped_guard (mutex, &dev->lock) - mask = dev->config.gt_types_allowed; -config_group_put (&dev->group); - -return mask; -} - -/** -* xe_configfs_primary_gt_allowed - determine whether primary GTs are supported -* @pdev: pci device -* -* Return: True if primary GTs are enabled, false if they have been disabled via -* configfs. -*/ -bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) -{ -return get_gt_types_allowed (pdev) &BIT_ULL (XE_GT_TYPE_MAIN ); -} - -/** -* xe_configfs_media_gt_allowed - determine whether media GTs are supported -* @pdev: pci device -* -* Return: True if the media GTs are enabled, false if they have been disabled -* via configfs. -*/ -bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) -{ -return get_gt_types_allowed (pdev) &BIT_ULL (XE_GT_TYPE_MEDIA ); -} - -static ssize_t gt_types_allowed_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); -char *p = page; - -for (size_t i =0 ; i <ARRAY_SIZE (gt_types); i++) -if (dev->gt_types_allowed &BIT_ULL (gt_types[i].type)) - p +=sprintf (p,"%s\n" , gt_types[i].name); - -return p - page; -} - -static ssize_t gt_types_allowed_store (struct config_item *item,const char *page, -size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); - char *buf __free(kfree) = kstrdup(page, GFP_KERNEL); -char *p = buf; -u64 typemask =0 ; - -if (!buf) -return -ENOMEM ; - -while (p) { -char *typename =strsep (&p,",\n" ); -bool matched = false; - -if (typename[0 ] =='\0' ) -continue ; - -for (size_t i =0 ; i <ARRAY_SIZE (gt_types); i++) { -if (strcmp (typename, gt_types[i].name) ==0 ) { - typemask |=BIT (gt_types[i].type); - matched = true; -break ; - } - } - -if (!matched) -return -EINVAL ; - } - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.gt_types_allowed = typemask; - -return len; -} - -/** -* xe_configfs_get_enable_multi_queue - get configfs enable_multi_queue setting -* @pdev: pci device -* -* Return: true if multi-queue is enabled for this device (the default), -* false if it has been force-disabled via configfs. -*/ -bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -bool ret; - -if (!dev) -return true; - -scoped_guard (mutex, &dev->lock) - ret = dev->config.enable_multi_queue; -config_group_put (&dev->group); - -return ret; -} - -static ssize_t enable_multi_queue_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); - -return sprintf (page,"%d\n" , dev->enable_multi_queue); -} - -static ssize_t enable_multi_queue_store (struct config_item *item,const char *page, -size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); -bool val; -int ret; - - ret =kstrtobool (page, &val); -if (ret) -return ret; - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.enable_multi_queue = val; - -return len; -} - -/** -* xe_configfs_get_psmi_enabled - get configfs enable_psmi setting -* @pdev: pci device -* -* Return: enable_psmi setting in configfs -*/ -bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -bool ret; - -if (!dev) -return false; - -scoped_guard (mutex, &dev->lock) - ret = dev->config.enable_psmi; -config_group_put (&dev->group); - -return ret; -} - -static ssize_t enable_psmi_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); - -return sprintf (page,"%d\n" , dev->enable_psmi); -} - -static ssize_t enable_psmi_store (struct config_item *item,const char *page,size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); -bool val; -int ret; - - ret =kstrtobool (page, &val); -if (ret) -return ret; - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.enable_psmi = val; - -return len; -} - -/** -* xe_configfs_get_survivability_mode - get configfs survivability mode attribute -* @pdev: pci device -* -* Return: survivability_mode attribute in configfs -*/ -bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) -{ -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); -bool mode; - -if (!dev) -return device_defaults.survivability_mode; - -scoped_guard (mutex, &dev->lock) - mode = dev->config.survivability_mode; -config_group_put (&dev->group); - -return mode; -} - -static ssize_t survivability_mode_show (struct config_item *item,char *page) -{ -struct xe_config_device *dev =to_xe_config_device (item); - -return sprintf (page,"%d\n" , dev->survivability_mode); -} - -static ssize_t survivability_mode_store (struct config_item *item,const char *page,size_t len) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); -bool survivability_mode; -int ret; - - ret =kstrtobool (page, &survivability_mode); -if (ret) -return ret; - -guard (mutex)(&dev->lock); -if (is_bound (dev)) -return -EBUSY ; - - dev->config.survivability_mode = survivability_mode; - -return len; -} - -CONFIGFS_ATTR(, ctx_restore_mid_bb); -CONFIGFS_ATTR(, ctx_restore_post_bb); -CONFIGFS_ATTR(, engines_allowed); -CONFIGFS_ATTR(, gt_types_allowed); -CONFIGFS_ATTR(, enable_multi_queue); -CONFIGFS_ATTR(, enable_psmi); -CONFIGFS_ATTR(, survivability_mode); - -static struct configfs_attribute *xe_config_device_attrs[] = { - &attr_ctx_restore_mid_bb, - &attr_ctx_restore_post_bb, - &attr_engines_allowed, - &attr_gt_types_allowed, - &attr_enable_multi_queue, - &attr_enable_psmi, - &attr_survivability_mode, -NULL , -}; -static void xe_config_device_release (struct config_item *item) { -struct xe_config_group_device *dev =to_xe_config_group_device (item); +struct xe_config_group_device *dev =xe_configfs_to_group_device (item);mutex_destroy (&dev->lock); -kfree (dev->config.ctx_restore_mid_bb[0 ].cs); -kfree (dev->config.ctx_restore_post_bb[0 ].cs); +xe_configfs_debug_release_config (&dev->config);kfree (dev); }@@ -1037,33 +167,14 @@ static struct configfs_item_operations xe_config_device_ops = { .release = xe_config_device_release, }; -static bool xe_config_device_is_visible (struct config_item *item, -struct configfs_attribute *attr,int n) -{ -struct xe_config_group_device *dev =to_xe_config_group_device (item); - -if (attr == &attr_survivability_mode) { -if (!dev->desc->is_dgfx || dev->desc->platform <XE_BATTLEMAGE ) -return false; - } - -return true; -} - -static struct configfs_group_operations xe_config_device_group_ops = { - .is_visible = xe_config_device_is_visible, -}; -static const struct config_item_type xe_config_device_type = { .ct_item_ops = &xe_config_device_ops, - .ct_group_ops = &xe_config_device_group_ops, - .ct_attrs = xe_config_device_attrs, .ct_owner =THIS_MODULE , };static ssize_t sriov_max_vfs_show (struct config_item *item,char *page) { -struct xe_config_group_device *dev =to_xe_config_group_device (item->ci_parent); +struct xe_config_group_device *dev =xe_configfs_subgroup_to_group_device (item);guard (mutex)(&dev->lock);@@ -1075,13 +186,13 @@ static ssize_t sriov_max_vfs_show(struct config_item *item, char *page)static ssize_t sriov_max_vfs_store (struct config_item *item,const char *page,size_t len) { -struct xe_config_group_device *dev =to_xe_config_group_device (item->ci_parent); +struct xe_config_group_device *dev =xe_configfs_subgroup_to_group_device (item);unsigned int max_vfs;int ret;guard (mutex)(&dev->lock); -if (is_bound (dev)) +if (xe_configfs_is_bound (dev))return -EBUSY ; ret =kstrtouint (page,0 , &max_vfs);@@ -1097,7 +208,7 @@ static ssize_t sriov_max_vfs_store(struct config_item *item, const char *page, sstatic ssize_t sriov_admin_only_pf_show (struct config_item *item,char *page) { -struct xe_config_group_device *dev =to_xe_config_group_device (item->ci_parent); +struct xe_config_group_device *dev =xe_configfs_subgroup_to_group_device (item);guard (mutex)(&dev->lock);@@ -1106,13 +217,13 @@ static ssize_t sriov_admin_only_pf_show(struct config_item *item, char *page)static ssize_t sriov_admin_only_pf_store (struct config_item *item,const char *page,size_t len) { -struct xe_config_group_device *dev =to_xe_config_group_device (item->ci_parent); +struct xe_config_group_device *dev =xe_configfs_subgroup_to_group_device (item);bool admin_only_pf;int ret;guard (mutex)(&dev->lock); -if (is_bound (dev)) +if (xe_configfs_is_bound (dev))return -EBUSY ; ret =kstrtobool (page, &admin_only_pf);@@ -1135,7 +246,7 @@ static struct configfs_attribute *xe_config_sriov_attrs[] = {static bool xe_config_sriov_is_visible (struct config_item *item,struct configfs_attribute *attr,int n) { -struct xe_config_group_device *dev =to_xe_config_group_device (item->ci_parent); +struct xe_config_group_device *dev =xe_configfs_subgroup_to_group_device (item);if (attr == &sriov_attr_max_vfs && dev->mode !=XE_SRIOV_MODE_PF )return false;@@ -1271,7 +382,17 @@ static struct configfs_subsystem xe_configfs = { }, }; -static struct xe_config_group_device *find_xe_config_group_device (struct pci_dev *pdev) +/** +* xe_configfs_find_group_device() - Find a configfs group by PCI device. +* @pdev: the &pci_dev to look up +* +* Searches the configfs subsystem for a group whose name matches @pdev. +* If found, the returned group has an elevated reference count; the caller +* must call config_group_put() when done. +* +* Return: pointer to the matching &xe_config_group_device, or NULL. +*/ +struct xe_config_group_device *xe_configfs_find_group_device (struct pci_dev *pdev) {struct config_item *item;@@ -1282,23 +403,25 @@ static struct xe_config_group_device *find_xe_config_group_device(struct pci_devif (!item)return NULL ; -return to_xe_config_group_device (item); +return xe_configfs_to_group_device (item); }static void dump_custom_dev_config (struct pci_dev *pdev,struct xe_config_group_device *dev) {#define PRI_CUSTOM_ATTR (fmt_, attr_) do { \ - if (dev->config.attr_ != device_defaults.attr_) \ + if (dev->config.attr_ != xe_configfs_device_defaults.attr_) \ pci_info(pdev, "configfs: " __stringify(attr_) " = " fmt_ "\n", \ dev->config.attr_); \ } while (0) -PRI_CUSTOM_ATTR ("%llx" , engines_allowed); -PRI_CUSTOM_ATTR ("%llx" , gt_types_allowed); -PRI_CUSTOM_ATTR ("%d" , enable_multi_queue); -PRI_CUSTOM_ATTR ("%d" , enable_psmi); -PRI_CUSTOM_ATTR ("%d" , survivability_mode); +#if IS_ENABLED (CONFIG_DRM_XE_DEBUG ) +PRI_CUSTOM_ATTR ("%llx" , debug.engines_allowed); +PRI_CUSTOM_ATTR ("%llx" , debug.gt_types_allowed); +PRI_CUSTOM_ATTR ("%d" , debug.enable_multi_queue); +PRI_CUSTOM_ATTR ("%d" , debug.enable_psmi); +PRI_CUSTOM_ATTR ("%d" , debug.survivability_mode); +#endif PRI_CUSTOM_ATTR ("%u" , sriov.admin_only_pf);#undef PRI_CUSTOM_ATTR@@ -1313,13 +436,13 @@ static void dump_custom_dev_config(struct pci_dev *pdev,*/ void xe_configfs_check_device (struct pci_dev *pdev) { -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +struct xe_config_group_device *dev =xe_configfs_find_group_device (pdev);if (!dev)return ;/* memcmp here is safe as both are zero-initialized */ -if (memcmp (&dev->config, &device_defaults,sizeof (dev->config))) { +if (memcmp (&dev->config, &xe_configfs_device_defaults,sizeof (dev->config))) {pci_info (pdev,"Found custom settings in configfs\n" );dump_custom_dev_config (pdev, dev); }@@ -1341,7 +464,7 @@ void xe_configfs_check_device(struct pci_dev *pdev)*/ bool xe_configfs_admin_only_pf (struct pci_dev *pdev) { -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +struct xe_config_group_device *dev =xe_configfs_find_group_device (pdev);bool admin_only_pf;if (!dev)@@ -1366,7 +489,7 @@ bool xe_configfs_admin_only_pf(struct pci_dev *pdev)*/ unsigned int xe_configfs_get_max_vfs (struct pci_dev *pdev) { -struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +struct xe_config_group_device *dev =xe_configfs_find_group_device (pdev);unsigned int max_vfs;if (!dev)drivers/gpu/drm/xe/xe_configfs.h +64
-24@@ -12,24 +12,76 @@#include "xe_defaults.h" #include "xe_module.h" +struct config_item ;struct pci_dev ; +struct xe_config_group_device ; + +extern const struct xe_config_device xe_configfs_device_defaults;#if IS_ENABLED (CONFIG_CONFIGFS_FS ) +/** +* xe_configfs_to_group_device() - Cast a config_item to &xe_config_group_device. +* @item: the &config_item embedded in the device group +* +* The @item must be the top-level device group's cg_item, not a subgroup item. +* Use xe_configfs_subgroup_to_group_device() for subgroup show/store callbacks. +* +* Return: pointer to the enclosing &xe_config_group_device. +*/ +static inline struct xe_config_group_device * +xe_configfs_to_group_device (struct config_item *item) +{ + return container_of(to_config_group(item), struct xe_config_group_device, group); +} + +/** +* xe_configfs_to_device() - Cast a config_item to &xe_config_device. +* @item: the &config_item embedded in the device group +* +* Convenience wrapper around xe_configfs_to_group_device(). +* +* Return: pointer to the &xe_config_device nested in the group. +*/ +static inline struct xe_config_device *xe_configfs_to_device (struct config_item *item) +{ +return &xe_configfs_to_group_device (item)->config; +} + +/** +* xe_configfs_subgroup_to_group_device() - Cast a subgroup item to &xe_config_group_device. +* @item: the &config_item of a subgroup (e.g. sriov or debug) +* +* In configfs, show/store callbacks for a subgroup's attributes receive the +* subgroup's cg_item, whose parent is the device group's cg_item. +* This helper walks up one level to return the enclosing device group. +* +* Return: pointer to the enclosing &xe_config_group_device. +*/ +static inline struct xe_config_group_device * +xe_configfs_subgroup_to_group_device (struct config_item *item) +{ +return xe_configfs_to_group_device (item->ci_parent); +} + +/** +* xe_configfs_subgroup_to_device() - Cast a subgroup item to &xe_config_device. +* @item: the &config_item of a subgroup (e.g. sriov or debug) +* +* Convenience wrapper for a subgroup item to get the &xe_config_device. +* +* Return: pointer to the &xe_config_device nested in the parent device group. +*/ +static inline struct xe_config_device * +xe_configfs_subgroup_to_device (struct config_item *item) +{ +return xe_configfs_to_device (item->ci_parent); +} + +bool xe_configfs_is_bound (struct xe_config_group_device *dev); +struct xe_config_group_device *xe_configfs_find_group_device (struct pci_dev *pdev);int xe_configfs_init (void );void xe_configfs_exit (void );void xe_configfs_check_device (struct pci_dev *pdev); -u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, -enum xe_engine_class class, -const u32 **cs); -u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, -enum xe_engine_class class, -const u32 **cs); -u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev); -bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev); -bool xe_configfs_media_gt_allowed (struct pci_dev *pdev); -bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev); -bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev); -bool xe_configfs_get_survivability_mode (struct pci_dev *pdev);#ifdef CONFIG_PCI_IOV unsigned int xe_configfs_get_max_vfs (struct pci_dev *pdev);bool xe_configfs_admin_only_pf (struct pci_dev *pdev);@@ -38,18 +90,6 @@ bool xe_configfs_admin_only_pf(struct pci_dev *pdev);static inline int xe_configfs_init (void ) {return 0 ; }static inline void xe_configfs_exit (void ) { }static inline void xe_configfs_check_device (struct pci_dev *pdev) { } -static inline u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, -enum xe_engine_class class, -const u32 **cs) {return 0 ; } -static inline u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, -enum xe_engine_class class, -const u32 **cs) {return 0 ; } -static inline u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) {return U64_MAX ; } -static inline bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) {return true; } -static inline bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) {return true; } -static inline bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) {return true; } -static inline bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) {return false; } -static inline bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) {return false; }#ifdef CONFIG_PCI_IOV static inline unsigned int xe_configfs_get_max_vfs (struct pci_dev *pdev) {drivers/gpu/drm/xe/xe_configfs_debug.c +956
-0@@ -3,12 +3,968 @@* Copyright © 2026 Intel Corporation */ +#include <linux/bitops.h> #include <linux/configfs.h> #include <linux/module.h> +#include <linux/cleanup.h> +#include <linux/find.h> +#include <linux/pci.h> +#include <linux/string.h> +#include "abi/guc_log_abi.h" +#include "instructions/xe_mi_commands.h" +#include "xe_configfs.h" #include "xe_configfs_debug.h" #include "xe_configfs_types.h" +#include "xe_gt_types.h" +#include "xe_hw_engine_types.h" +#include "xe_pci_types.h" + +/** +* DOC: Xe Configfs Debug Attributes +* +* Overview +* ======== +* +* The following configfs attributes are only available when the kernel is +* built with ``CONFIG_DRM_XE_DEBUG=y``. They appear under the ``debug/`` +* subdirectory of each xe configfs device. They are intended for hardware +* and driver debugging and are not stable ABI. Using them is "at your own +* risk". +* +* See the top-level ``Xe Configfs`` documentation in ``xe_configfs.c`` +* for how to create, probe and remove configfs devices. Once a device +* directory exists, the driver populates it with a ``debug/`` subdirectory +* containing the entries described below:: +* +* /sys/kernel/config/xe/ +* └── 0000:03:00.0 +* └── debug/ +* ├── ctx_restore_mid_bb +* ├── ctx_restore_post_bb +* ├── engines_allowed +* ├── gt_types_allowed +* ├── enable_multi_queue +* ├── enable_psmi +* └── survivability_mode +* +* Configure Attributes +* ==================== +* +* Context restore BB +* ------------------ +* +* Allow to execute a batch buffer during any context switches. When the +* GPU is restoring the context, it executes additional commands. It's useful +* for testing additional workarounds and validating certain HW behaviors: it's +* not intended for normal execution and will taint the kernel with TAINT_TEST +* when used. +* +* The syntax allows to pass straight instructions to be executed by the engine +* in a batch buffer or set specific registers. +* +* #. Generic instruction:: +* +* <engine-class> cmd <instr> [[dword0] [dword1] [...]] +* +* #. Simple register setting:: +* +* <engine-class> reg <address> <value> +* +* Commands are saved per engine class: all instances of that class will execute +* those commands during context switch. The instruction, dword arguments, +* addresses and values are in hex format like in the examples below. +* +* #. Execute a LRI command to write 0xDEADBEEF to register 0x4f10 after the +* normal context restore:: +* +* # echo 'rcs cmd 11000001 4F100 DEADBEEF' \ +* > /sys/kernel/config/xe/0000:03:00.0/debug/ctx_restore_post_bb +* +* #. Execute a LRI command to write 0xDEADBEEF to register 0x4f10 at the +* beginning of the context restore:: +* +* # echo 'rcs cmd 11000001 4F100 DEADBEEF' \ +* > /sys/kernel/config/xe/0000:03:00.0/debug/ctx_restore_mid_bb +* +* #. Load certain values in a couple of registers (it can be used as a simpler +* alternative to the `cmd`) action:: +* +* # cat > /sys/kernel/config/xe/0000:03:00.0/debug/ctx_restore_post_bb <<EOF +* rcs reg 4F100 DEADBEEF +* rcs reg 4F104 FFFFFFFF +* EOF +* +* .. note:: +* +* When using multiple lines, make sure to use a command that is +* implemented with a single write syscall, like HEREDOC. +* +* Currently this is implemented only for post and mid context restore and +* these attributes can only be set before binding to the device. +* +* Allowed engines: +* ---------------- +* +* Allow only a set of engine(s) to be available, disabling the other engines +* even if they are available in hardware. This is applied after HW fuses are +* considered on each tile. Examples: +* +* Allow only one render and one copy engines, nothing else:: +* +* # echo 'rcs0,bcs0' > /sys/kernel/config/xe/0000:03:00.0/debug/engines_allowed +* +* Allow only compute engines and first copy engine:: +* +* # echo 'ccs*,bcs0' > /sys/kernel/config/xe/0000:03:00.0/debug/engines_allowed +* +* Note that the engine names are the per-GT hardware names. On multi-tile +* platforms, writing ``rcs0,bcs0`` to this file would allow the first render +* and copy engines on each tile. +* +* The requested configuration may not be supported by the platform and driver +* may fail to probe. For example: if at least one copy engine is expected to be +* available for migrations, but it's disabled. This is intended for debugging +* purposes only. +* +* This attribute can only be set before binding to the device. +* +* Allowed GT types: +* ----------------- +* +* Allow only specific types of GTs to be detected and initialized by the +* driver. Any combination of GT types can be enabled/disabled, although +* some settings will cause the device to fail to probe. +* +* Writes support both comma- and newline-separated input format. Reads +* will always return one GT type per line. "primary" and "media" are the +* GT type names supported by this interface. +* +* This attribute can only be set before binding to the device. +* +* Examples: +* +* Allow both primary and media GTs to be initialized and used. This matches +* the driver's default behavior:: +* +* # echo 'primary,media' > /sys/kernel/config/xe/0000:03:00.0/debug/gt_types_allowed +* +* Allow only the primary GT of each tile to be initialized and used, +* effectively disabling the media GT if it exists on the platform:: +* +* # echo 'primary' > /sys/kernel/config/xe/0000:03:00.0/debug/gt_types_allowed +* +* Allow only the media GT of each tile to be initialized and used, +* effectively disabling the primary GT. **This configuration will cause +* device probe failure on all current platforms, but may be allowed on +* igpu platforms in the future**:: +* +* # echo 'media' > /sys/kernel/config/xe/0000:03:00.0/debug/gt_types_allowed +* +* Disable all GTs. Only other GPU IP (such as display) is potentially usable. +* **This configuration will cause device probe failure on all current +* platforms, but may be allowed on igpu platforms in the future**:: +* +* # echo '' > /sys/kernel/config/xe/0000:03:00.0/debug/gt_types_allowed +* +* Enable multi-queue +* ------------------ +* +* Multi-queue support on the device is enabled by default where the +* hardware supports it. Writing 0 force-disables multi-queue support: +* multi-queue exec-queue group creation via ioctl is refused, and the +* GuC feature is disabled:: +* +* # echo 0 > /sys/kernel/config/xe/0000:03:00.0/debug/enable_multi_queue +* +* This attribute can only be set before binding to the device. +* +* PSMI +* ---- +* +* Enable extra debugging capabilities to trace engine execution. Only useful +* during early platform enabling and requires additional hardware connected. +* Once it's enabled, additionals WAs are added and runtime configuration is +* done via debugfs. Example to enable it:: +* +* # echo 1 > /sys/kernel/config/xe/0000:03:00.0/debug/enable_psmi +* +* This attribute can only be set before binding to the device. +* +* Survivability mode: +* ------------------- +* +* Enable survivability mode on supported cards. This setting only takes +* effect when probing the device. Example to enable it:: +* +* # echo 1 > /sys/kernel/config/xe/0000:03:00.0/debug/survivability_mode +* +* This attribute can only be set before binding to the device. +* +*/ + +struct engine_info { +const char *cls; +u64 mask; +enum xe_engine_class engine_class; +}; + +/* Some helpful macros to aid on the sizing of buffer allocation when parsing */ +#define MAX_ENGINE_CLASS_CHARS 5 +#define MAX_ENGINE_INSTANCE_CHARS 2 + +static const struct engine_info engine_info[] = { + { .cls ="rcs" , .mask =XE_HW_ENGINE_RCS_MASK , .engine_class =XE_ENGINE_CLASS_RENDER }, + { .cls ="bcs" , .mask =XE_HW_ENGINE_BCS_MASK , .engine_class =XE_ENGINE_CLASS_COPY }, + { .cls ="vcs" , .mask =XE_HW_ENGINE_VCS_MASK , .engine_class =XE_ENGINE_CLASS_VIDEO_DECODE }, + { .cls ="vecs" , .mask =XE_HW_ENGINE_VECS_MASK , .engine_class =XE_ENGINE_CLASS_VIDEO_ENHANCE }, + { .cls ="ccs" , .mask =XE_HW_ENGINE_CCS_MASK , .engine_class =XE_ENGINE_CLASS_COMPUTE }, + { .cls ="gsccs" , .mask =XE_HW_ENGINE_GSCCS_MASK , .engine_class =XE_ENGINE_CLASS_OTHER }, +}; + +static const struct { +const char *name; +enum xe_gt_type type; +} gt_types[] = { + { .name ="primary" , .type =XE_GT_TYPE_MAIN }, + { .name ="media" , .type =XE_GT_TYPE_MEDIA }, +}; + +static struct xe_config_group_device *find_device (struct pci_dev *pdev) +{ +return xe_configfs_find_group_device (pdev); +} + +/** +* xe_configfs_get_ctx_restore_mid_bb - get configfs ctx_restore_mid_bb setting +* @pdev: pci device +* @class: hw engine class +* @cs: pointer to the bb to use - only valid during probe +* +* Return: Number of dwords used in the mid_ctx_restore setting in configfs +*/ +u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, +enum xe_engine_class class, +const u32 **cs) +{ +struct xe_config_group_device *dev =find_device (pdev); +u32 len; + +if (!dev) +return 0 ; + + scoped_guard(mutex, &dev->lock) { +if (cs) + *cs = dev->config.debug.ctx_restore_mid_bb[class].cs; + + len = dev->config.debug.ctx_restore_mid_bb[class].len; + } +config_group_put (&dev->group); + +return len; +} + +/** +* xe_configfs_get_ctx_restore_post_bb - get configfs ctx_restore_post_bb setting +* @pdev: pci device +* @class: hw engine class +* @cs: pointer to the bb to use - only valid during probe +* +* Return: Number of dwords used in the post_ctx_restore setting in configfs +*/ +u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, +enum xe_engine_class class, +const u32 **cs) +{ +struct xe_config_group_device *dev =find_device (pdev); +u32 len; + +if (!dev) +return 0 ; + + scoped_guard(mutex, &dev->lock) { + *cs = dev->config.debug.ctx_restore_post_bb[class].cs; + len = dev->config.debug.ctx_restore_post_bb[class].len; + } +config_group_put (&dev->group); + +return len; +} + +static bool wa_bb_read_advance (bool dereference,char **p, +const char *append,size_t len, +size_t *max_size) +{ +if (dereference) { +if (len >= *max_size) +return false; + *max_size -= len; +if (append) +memcpy (*p, append, len); + } + + *p += len; + +return true; +} + +static ssize_t wa_bb_show (struct xe_config_group_device *dev, +struct wa_bb wa_bb[static XE_ENGINE_CLASS_MAX ], +char *data,size_t sz) +{ +char *p = data; + +guard (mutex)(&dev->lock); + +for (size_t i =0 ; i <ARRAY_SIZE (engine_info); i++) { +enum xe_engine_class ec = engine_info[i].engine_class; +size_t len; + +if (!wa_bb[ec].len) +continue ; + + len =snprintf (p, sz,"%s:" , engine_info[i].cls); +if (!wa_bb_read_advance (data, &p,NULL , len, &sz)) +return -ENOBUFS ; + +for (size_t j =0 ; j < wa_bb[ec].len; j++) { + len =snprintf (p, sz," %08x" , wa_bb[ec].cs[j]); +if (!wa_bb_read_advance (data, &p,NULL , len, &sz)) +return -ENOBUFS ; + } + +if (!wa_bb_read_advance (data, &p,"\n" ,1 , &sz)) +return -ENOBUFS ; + } + +if (!wa_bb_read_advance (data, &p,"" ,1 , &sz)) +return -ENOBUFS ; + +/* Reserve one more to match check for '\0' */ +if (!data) + p++; + +return p - data; +} + +static ssize_t ctx_restore_mid_bb_show (struct config_item *item,char *page) +{ +struct xe_config_group_device *dev =xe_configfs_subgroup_to_group_device (item); + +return wa_bb_show (dev, dev->config.debug.ctx_restore_mid_bb, page,SZ_4K ); +} + +static ssize_t ctx_restore_post_bb_show (struct config_item *item,char *page) +{ +struct xe_config_group_device *dev =xe_configfs_subgroup_to_group_device (item); + +return wa_bb_show (dev, dev->config.debug.ctx_restore_post_bb, page,SZ_4K ); +} + +static void wa_bb_append (struct wa_bb *wa_bb,u32 val) +{ +if (wa_bb->cs) + wa_bb->cs[wa_bb->len] = val; + + wa_bb->len++; +} + +static ssize_t parse_hex (const char *line,u32 *pval) +{ +char numstr[12 ]; +const char *p; +ssize_t numlen; + + p = line +strspn (line," \t" ); +if (!*p || *p =='\n' ) +return 0 ; + + numlen =strcspn (p," \t\n" ); +if (!numlen || numlen >=sizeof (numstr) -1 ) +return -EINVAL ; + +memcpy (numstr, p, numlen); + numstr[numlen] ='\0' ; + p += numlen; + +if (kstrtou32 (numstr,16 , pval)) +return -EINVAL ; + +return p - line; +} + +static int parse_engine (const char *s,const char *end_chars,u64 *mask, +const struct engine_info **pinfo); + +/* +* Parse lines with the format +* +* <engine-class> cmd <u32> <u32...> +* <engine-class> reg <u32_addr> <u32_val> +* +* and optionally save them in @wa_bb[i].cs is non-NULL. +* +* Return the number of dwords parsed. +*/ +static ssize_t parse_wa_bb_lines (const char *lines, +struct wa_bb wa_bb[static XE_ENGINE_CLASS_MAX ]) +{ +ssize_t dwords =0 , ret; +const char *p; + +for (p = lines; *p; p++) { +const struct engine_info *info =NULL ; +u32 val, val2; + +/* Also allow empty lines */ + p +=strspn (p," \t\n" ); +if (!*p) +break ; + + ret =parse_engine (p," \t\n" ,NULL , &info); +if (ret <0 ) +return ret; + + p += ret; + p +=strspn (p," \t" ); + +if (str_has_prefix (p,"cmd" )) { +for (p +=strlen ("cmd" ); *p;) { + ret =parse_hex (p, &val); +if (ret <0 ) +return -EINVAL ; +if (!ret) +break ; + + p += ret; + dwords++; +wa_bb_append (&wa_bb[info->engine_class], val); + } + }else if (str_has_prefix (p,"reg" )) { + p +=strlen ("reg" ); + ret =parse_hex (p, &val); +if (ret <=0 ) +return -EINVAL ; + + p += ret; + ret =parse_hex (p, &val2); +if (ret <=0 ) +return -EINVAL ; + + p += ret; + dwords +=3 ; +wa_bb_append (&wa_bb[info->engine_class], +MI_LOAD_REGISTER_IMM |MI_LRI_NUM_REGS (1 )); +wa_bb_append (&wa_bb[info->engine_class], val); +wa_bb_append (&wa_bb[info->engine_class], val2); + }else { +return -EINVAL ; + } + } + +return dwords; +} + +static ssize_t wa_bb_store (struct wa_bb wa_bb[static XE_ENGINE_CLASS_MAX ], +struct xe_config_group_device *dev, +const char *page,size_t len) +{ +/* tmp_wa_bb must match wa_bb's size */ +struct wa_bb tmp_wa_bb[XE_ENGINE_CLASS_MAX ] = { }; +ssize_t count, class; +u32 *tmp; + +/* 1. Count dwords - wa_bb[i].cs is NULL for all classes */ + count =parse_wa_bb_lines (page, tmp_wa_bb); +if (count <0 ) +return count; + +guard (mutex)(&dev->lock); + +if (xe_configfs_is_bound (dev)) +return -EBUSY ; + +/* +* 2. Allocate a u32 array and set the pointers to the right positions +* according to the length of each class' wa_bb +*/ + tmp =krealloc (wa_bb[0 ].cs, count *sizeof (u32),GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + +if (!count) { +memset (wa_bb,0 ,sizeof (tmp_wa_bb)); +return len; + } + +for (class =0 , count =0 ; class <XE_ENGINE_CLASS_MAX ; ++class) { + tmp_wa_bb[class].cs = tmp + count; + count += tmp_wa_bb[class].len; + tmp_wa_bb[class].len =0 ; + } + +/* 3. Parse wa_bb lines again, this time saving the values */ + count =parse_wa_bb_lines (page, tmp_wa_bb); +if (count <0 ) { +kfree (tmp); +memset (wa_bb,0 ,sizeof (tmp_wa_bb)); +return count; + } + +memcpy (wa_bb, tmp_wa_bb,sizeof (tmp_wa_bb)); + +return len; +} + +static ssize_t ctx_restore_mid_bb_store (struct config_item *item, +const char *data,size_t sz) +{ +struct xe_config_group_device *dev =xe_configfs_subgroup_to_group_device (item); + +return wa_bb_store (dev->config.debug.ctx_restore_mid_bb, dev, data, sz); +} + +static ssize_t ctx_restore_post_bb_store (struct config_item *item, +const char *data,size_t sz) +{ +struct xe_config_group_device *dev =xe_configfs_subgroup_to_group_device (item); + +return wa_bb_store (dev->config.debug.ctx_restore_post_bb, dev, data, sz); +} + +/** +* xe_configfs_get_engines_allowed - get engine allowed mask from configfs +* @pdev: pci device +* +* Return: engine mask with allowed engines set in configfs +*/ +u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) +{ +struct xe_config_group_device *dev =find_device (pdev); +u64 engines_allowed; + +if (!dev) +return xe_configfs_device_defaults.debug.engines_allowed; + + scoped_guard(mutex, &dev->lock) + engines_allowed = dev->config.debug.engines_allowed; +config_group_put (&dev->group); + +return engines_allowed; +} + +static ssize_t engines_allowed_show (struct config_item *item,char *page) +{ +struct xe_config_device *dev =xe_configfs_subgroup_to_device (item); +char *p = page; + +for (size_t i =0 ; i <ARRAY_SIZE (engine_info); i++) { +u64 mask = engine_info[i].mask; + +if ((dev->debug.engines_allowed & mask) == mask) { + p +=sprintf (p,"%s*\n" , engine_info[i].cls); + }else if (mask & dev->debug.engines_allowed) { +u16 bit0 =__ffs64 (mask), bit; + + mask &= dev->debug.engines_allowed; + +for_each_set_bit (bit, (const unsigned long *)&mask,64 ) + p +=sprintf (p,"%s%u\n" , engine_info[i].cls, + bit - bit0); + } + } + +return p - page; +} + +/* +* Lookup engine_info. If @mask is not NULL, reduce the mask according to the +* instance in @pattern. +* +* Examples of inputs: +* - lookup_engine_info("rcs0", &mask): return "rcs" entry from @engine_info and +* mask == BIT_ULL(XE_HW_ENGINE_RCS0) +* - lookup_engine_info("rcs*", &mask): return "rcs" entry from @engine_info and +* mask == XE_HW_ENGINE_RCS_MASK +* - lookup_engine_info("rcs", NULL): return "rcs" entry from @engine_info +*/ +static const struct engine_info *lookup_engine_info (const char *pattern,u64 *mask) +{ +for (size_t i =0 ; i <ARRAY_SIZE (engine_info); i++) { +u8 instance; +u16 bit; + +if (!str_has_prefix (pattern, engine_info[i].cls)) +continue ; + + pattern +=strlen (engine_info[i].cls); +if (!mask) +return *pattern ?NULL : &engine_info[i]; + +if (!strcmp (pattern,"*" )) { + *mask = engine_info[i].mask; +return &engine_info[i]; + } + +if (kstrtou8 (pattern,10 , &instance)) +return NULL ; + + bit =__ffs64 (engine_info[i].mask) + instance; +if (bit >=fls64 (engine_info[i].mask)) +return NULL ; + + *mask =BIT_ULL (bit); +return &engine_info[i]; + } + +return NULL ; +} + +static int parse_engine (const char *s,const char *end_chars,u64 *mask, +const struct engine_info **pinfo) +{ +char buf[MAX_ENGINE_CLASS_CHARS +MAX_ENGINE_INSTANCE_CHARS +1 ]; +const struct engine_info *info; +size_t len; + + len =strcspn (s, end_chars); +if (len >=sizeof (buf)) +return -EINVAL ; + +memcpy (buf, s, len); + buf[len] ='\0' ; + + info =lookup_engine_info (buf, mask); +if (!info) +return -ENOENT ; + +if (pinfo) + *pinfo = info; + +return len; +} + +static ssize_t engines_allowed_store (struct config_item *item,const char *page, +size_t len) +{ +struct xe_config_group_device *dev =xe_configfs_subgroup_to_group_device (item); +ssize_t patternlen, p; +u64 mask, val =0 ; + +for (p =0 ; p < len; p += patternlen +1 ) { + patternlen =parse_engine (page + p,",\n" , &mask,NULL ); +if (patternlen <0 ) +return -EINVAL ; + + val |= mask; + } + +guard (mutex)(&dev->lock); +if (xe_configfs_is_bound (dev)) +return -EBUSY ; + + dev->config.debug.engines_allowed = val; + +return len; +} + +static u64 get_gt_types_allowed (struct pci_dev *pdev) +{ +struct xe_config_group_device *dev =find_device (pdev); +u64 mask; + +if (!dev) +return xe_configfs_device_defaults.debug.gt_types_allowed; + +scoped_guard (mutex, &dev->lock) + mask = dev->config.debug.gt_types_allowed; +config_group_put (&dev->group); + +return mask; +} + +/** +* xe_configfs_primary_gt_allowed - determine whether primary GTs are supported +* @pdev: pci device +* +* Return: True if primary GTs are enabled, false if they have been disabled via +* configfs. +*/ +bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) +{ +return get_gt_types_allowed (pdev) &BIT_ULL (XE_GT_TYPE_MAIN ); +} + +/** +* xe_configfs_media_gt_allowed - determine whether media GTs are supported +* @pdev: pci device +* +* Return: True if the media GTs are enabled, false if they have been disabled +* via configfs. +*/ +bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) +{ +return get_gt_types_allowed (pdev) &BIT_ULL (XE_GT_TYPE_MEDIA ); +} + +static ssize_t gt_types_allowed_show (struct config_item *item,char *page) +{ +struct xe_config_device *dev =xe_configfs_subgroup_to_device (item); +char *p = page; + +for (size_t i =0 ; i <ARRAY_SIZE (gt_types); i++) +if (dev->debug.gt_types_allowed &BIT_ULL (gt_types[i].type)) + p +=sprintf (p,"%s\n" , gt_types[i].name); + +return p - page; +} + +static ssize_t gt_types_allowed_store (struct config_item *item,const char *page, +size_t len) +{ + char *buf __free(kfree) = kstrdup(page, GFP_KERNEL); +struct xe_config_group_device *dev =xe_configfs_subgroup_to_group_device (item); +u64 typemask =0 ; +char *p = buf; + +if (!buf) +return -ENOMEM ; + +while (p) { +char *typename =strsep (&p,",\n" ); +bool matched = false; + +if (typename[0 ] =='\0' ) +continue ; + +for (size_t i =0 ; i <ARRAY_SIZE (gt_types); i++) { +if (strcmp (typename, gt_types[i].name) ==0 ) { + typemask |=BIT (gt_types[i].type); + matched = true; +break ; + } + } + +if (!matched) +return -EINVAL ; + } + +guard (mutex)(&dev->lock); +if (xe_configfs_is_bound (dev)) +return -EBUSY ; + + dev->config.debug.gt_types_allowed = typemask; + +return len; +} + +/** +* xe_configfs_get_enable_multi_queue - get configfs enable_multi_queue setting +* @pdev: pci device +* +* Return: true if multi-queue is enabled for this device (the default), +* false if it has been force-disabled via configfs. +*/ +bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) +{ +struct xe_config_group_device *dev =find_device (pdev); +bool ret; + +if (!dev) +return xe_configfs_device_defaults.debug.enable_multi_queue; + +scoped_guard (mutex, &dev->lock) + ret = dev->config.debug.enable_multi_queue; +config_group_put (&dev->group); + +return ret; +} + +static ssize_t enable_multi_queue_show (struct config_item *item,char *page) +{ +struct xe_config_device *dev =xe_configfs_subgroup_to_device (item); + +return sprintf (page,"%d\n" , dev->debug.enable_multi_queue); +} + +static ssize_t enable_multi_queue_store (struct config_item *item,const char *page,size_t len) +{ +struct xe_config_group_device *dev =xe_configfs_subgroup_to_group_device (item); +bool val; +int ret; + + ret =kstrtobool (page, &val); +if (ret) +return ret; + +guard (mutex)(&dev->lock); +if (xe_configfs_is_bound (dev)) +return -EBUSY ; + + dev->config.debug.enable_multi_queue = val; + +return len; +} + +/** +* xe_configfs_get_psmi_enabled - get configfs enable_psmi setting +* @pdev: pci device +* +* Return: enable_psmi setting in configfs +*/ +bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) +{ +struct xe_config_group_device *dev =find_device (pdev); +bool ret; + +if (!dev) +return false; + +scoped_guard (mutex, &dev->lock) + ret = dev->config.debug.enable_psmi; +config_group_put (&dev->group); + +return ret; +} + +static ssize_t enable_psmi_show (struct config_item *item,char *page) +{ +struct xe_config_device *dev =xe_configfs_subgroup_to_device (item); + +return sprintf (page,"%d\n" , dev->debug.enable_psmi); +} + +static ssize_t enable_psmi_store (struct config_item *item,const char *page,size_t len) +{ +struct xe_config_group_device *dev =xe_configfs_subgroup_to_group_device (item); +bool val; +int ret; + + ret =kstrtobool (page, &val); +if (ret) +return ret; + +guard (mutex)(&dev->lock); +if (xe_configfs_is_bound (dev)) +return -EBUSY ; + + dev->config.debug.enable_psmi = val; + +return len; +} + +/** +* xe_configfs_get_survivability_mode - get configfs survivability mode attribute +* @pdev: pci device +* +* Return: survivability_mode attribute in configfs +*/ +bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) +{ +struct xe_config_group_device *dev =find_device (pdev); +bool mode; + +if (!dev) +return xe_configfs_device_defaults.debug.survivability_mode; + +scoped_guard (mutex, &dev->lock) + mode = dev->config.debug.survivability_mode; +config_group_put (&dev->group); + +return mode; +} + +static ssize_t survivability_mode_show (struct config_item *item,char *page) +{ +struct xe_config_device *dev =xe_configfs_subgroup_to_device (item); + +return sprintf (page,"%d\n" , dev->debug.survivability_mode); +} + +static ssize_t survivability_mode_store (struct config_item *item,const char *page,size_t len) +{ +struct xe_config_group_device *dev =xe_configfs_subgroup_to_group_device (item); +bool survivability_mode; +int ret; + + ret =kstrtobool (page, &survivability_mode); +if (ret) +return ret; + +guard (mutex)(&dev->lock); +if (xe_configfs_is_bound (dev)) +return -EBUSY ; + + dev->config.debug.survivability_mode = survivability_mode; + +return len; +} + +CONFIGFS_ATTR(, ctx_restore_mid_bb); +CONFIGFS_ATTR(, ctx_restore_post_bb); +CONFIGFS_ATTR(, engines_allowed); +CONFIGFS_ATTR(, gt_types_allowed); +CONFIGFS_ATTR(, enable_multi_queue); +CONFIGFS_ATTR(, enable_psmi); +CONFIGFS_ATTR(, survivability_mode); + +static struct configfs_attribute *xe_configfs_debug_attrs[] = { + &attr_ctx_restore_mid_bb, + &attr_ctx_restore_post_bb, + &attr_engines_allowed, + &attr_gt_types_allowed, + &attr_enable_multi_queue, + &attr_enable_psmi, + &attr_survivability_mode, +NULL , +}; + +/* +* Per-parameter visibility predicates. +* +* XE_PARAM_VISIBLE_ALWAYS - attribute is always shown. +* XE_PARAM_VISIBLE_SURVIVABILITY - only shown on dGFX platforms >= Battlemage. +* +* These macros are only evaluated here, where the platform descriptor is +* reachable. xe_configfs_debug_params.h treats them as opaque tokens. +*/ +#define XE_PARAM_VISIBLE_ALWAYS (_item) \ + (true) +#define XE_PARAM_VISIBLE_SURVIVABILITY (_item) \ + (xe_configfs_subgroup_to_group_device(_item)->desc->is_dgfx && \ + xe_configfs_subgroup_to_group_device(_item)->desc->platform >= XE_BATTLEMAGE) + +static bool xe_configfs_debug_is_visible (struct config_item *item, +struct configfs_attribute *attr,int n) +{ +if (attr == &attr_survivability_mode) { +struct xe_config_group_device *dev = +xe_configfs_to_group_device (item->ci_parent); + +return dev->desc->is_dgfx && dev->desc->platform >=XE_BATTLEMAGE ; + } + +return true; +} + +static struct configfs_group_operations xe_configfs_debug_group_ops = { + .is_visible = xe_configfs_debug_is_visible, +};const struct config_item_type xe_configfs_debug_type = { + .ct_attrs = xe_configfs_debug_attrs, + .ct_group_ops = &xe_configfs_debug_group_ops, .ct_owner =THIS_MODULE , }; + +/** +* xe_configfs_debug_release_config - release debug-specific config resources +* @config: xe config device structure +* +* Frees any memory allocated for debug configfs parameters. +*/ +void xe_configfs_debug_release_config (struct xe_config_device *config) +{ +kfree (config->debug.ctx_restore_mid_bb[0 ].cs); +kfree (config->debug.ctx_restore_post_bb[0 ].cs); +}drivers/gpu/drm/xe/xe_configfs_debug.h +38
-1@@ -5,9 +5,46 @@#ifndef _XE_CONFIGFS_DEBUG_H_#define _XE_CONFIGFS_DEBUG_H_ +#include <linux/types.h> + +#include "xe_hw_engine_types.h" + +struct pci_dev ; +struct xe_config_device ; +#if IS_ENABLED (CONFIG_DRM_XE_DEBUG ) &&IS_ENABLED (CONFIG_CONFIGFS_FS ) -struct config_item_type ;extern const struct config_item_type xe_configfs_debug_type; +void xe_configfs_debug_release_config (struct xe_config_device *config); +u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, +enum xe_engine_class class, +const u32 **cs); +u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, +enum xe_engine_class class, +const u32 **cs); +u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev); +bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev); +bool xe_configfs_media_gt_allowed (struct pci_dev *pdev); +bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev); +bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev); +bool xe_configfs_get_survivability_mode (struct pci_dev *pdev); +#else +/* +* Dummy values here are not used since these function accesses are always +* wrapped in CONFIG_DRM_XE_DEBUG. +*/ +static inline void xe_configfs_debug_release_config (struct xe_config_device *config) { } +static inline u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, +enum xe_engine_class class, +const u32 **cs) {return 0 ; } +static inline u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, +enum xe_engine_class class, +const u32 **cs) {return 0 ; } +static inline u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) {return U64_MAX ; } +static inline bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) {return true; } +static inline bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) {return true; } +static inline bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) {return true; } +static inline bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) {return false; } +static inline bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) {return false; }#endif #endif /* _XE_CONFIGFS_DEBUG_H_ */ drivers/gpu/drm/xe/xe_configfs_types.h +11
-7@@ -32,13 +32,17 @@ struct xe_config_group_device {* type, entries are sorted alphabetically. */ struct xe_config_device { -struct wa_bb ctx_restore_mid_bb[XE_ENGINE_CLASS_MAX ]; -struct wa_bb ctx_restore_post_bb[XE_ENGINE_CLASS_MAX ]; -u64 engines_allowed; -u64 gt_types_allowed; -bool enable_multi_queue; -bool enable_psmi; -bool survivability_mode; +#if IS_ENABLED (CONFIG_DRM_XE_DEBUG ) +struct { +struct wa_bb ctx_restore_mid_bb[XE_ENGINE_CLASS_MAX ]; +struct wa_bb ctx_restore_post_bb[XE_ENGINE_CLASS_MAX ]; +u64 engines_allowed; +u64 gt_types_allowed; +bool enable_multi_queue; +bool enable_psmi; +bool survivability_mode; + } debug; +#endif struct {unsigned int max_vfs;bool admin_only_pf;drivers/gpu/drm/xe/xe_guc.c +1
-0@@ -19,6 +19,7 @@#include "regs/xe_irq_regs.h" #include "xe_bo.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_device.h" #include "xe_force_wake.h" #include "xe_gt.h" drivers/gpu/drm/xe/xe_guc_ads.c +1
-0@@ -17,6 +17,7 @@#include "regs/xe_guc_regs.h" #include "xe_bo.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_gt.h" #include "xe_gt_ccs_mode.h" #include "xe_gt_mcr.h" drivers/gpu/drm/xe/xe_hw_engine.c +1
-0@@ -18,6 +18,7 @@#include "xe_assert.h" #include "xe_bo.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_device.h" #include "xe_execlist.h" #include "xe_force_wake.h" drivers/gpu/drm/xe/xe_lrc.c +1
-0@@ -19,6 +19,7 @@#include "xe_bb.h" #include "xe_bo.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_device.h" #include "xe_drm_client.h" #include "xe_exec_queue.h" drivers/gpu/drm/xe/xe_pci.c +1
-0@@ -19,6 +19,7 @@#include "regs/xe_gt_regs.h" #include "regs/xe_regs.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_device.h" #include "xe_drv.h" #include "xe_gt.h" drivers/gpu/drm/xe/xe_psmi.c +1
-0@@ -8,6 +8,7 @@#include "xe_bo.h" #include "xe_device_types.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_psmi.h" /* drivers/gpu/drm/xe/xe_rtp.c +1
-0@@ -10,6 +10,7 @@#include <uapi/drm/xe_drm.h> #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_device.h" #include "xe_gt.h" #include "xe_gt_topology.h" drivers/gpu/drm/xe/xe_survivability_mode.c +1
-0@@ -11,6 +11,7 @@#include <linux/sysfs.h> #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_device.h" #include "xe_heci_gsc.h" #include "xe_i2c.h" Signature · 1 line
2.43.0
Signature · 4 lines
Matt Roper Graphics Software Engineer Linux GPU Platform Enablement Intel Corporation
Re: [PATCH 05/10] drm/xe: Move debug configfs entries to xe_configfs_debug.c
Quoted 294 lines · Matt Roper
Quoted 263 lines · Stuart Summers
Move the debug specific configfs attributes into the new
xe_configfs_debug.cfile under a new debug configfs subdirectory. Ensure these are wrapped inCONFIG_DRM_XE_DEBUGto allow finer grained
debug changes outside of more ABI specific configfs entries.Signed-off-by Stuart Summers <[email protected]>Assisted-by Copilot:claude-sonnet-4.6,claude-sonnet-5,claude-opus-5
---
drivers/gpu/drm/xe/xe_configfs.c | 991 ++---------------
----
drivers/gpu/drm/xe/xe_configfs.h | 88 +- drivers/gpu/drm/xe/xe_configfs_debug.c | 956
++++++++++++++++++++
drivers/gpu/drm/xe/xe_configfs_debug.h | 39 +- drivers/gpu/drm/xe/xe_configfs_types.h | 18 +- drivers/gpu/drm/xe/xe_guc.c | 1 + drivers/gpu/drm/xe/xe_guc_ads.c | 1 + drivers/gpu/drm/xe/xe_hw_engine.c | 1 + drivers/gpu/drm/xe/xe_lrc.c | 1 + drivers/gpu/drm/xe/xe_pci.c | 1 + drivers/gpu/drm/xe/xe_psmi.c | 1 + drivers/gpu/drm/xe/xe_rtp.c | 1 +drivers/gpu/drm/xe/xe_survivability_mode.c| 1 +13 files changed, 1134 insertions(+), 966 deletions(-)drivers/gpu/drm/xe/xe_configfs.c +0
-1@@ -6,17 +6,14 @@ #include <linux/bitops.h> #include <linux/configfs.h> #include <linux/cleanup.h> -#include <linux/find.h> #include <linux/init.h> #include <linux/module.h> #include <linux/pci.h> #include <linux/string.h>
-#include "instructions/xe_mi_commands.h"
#include "xe_configfs.h"
#include "xe_configfs_debug.h"
#include "xe_defaults.h"
-#include "xe_gt_types.h"
#include "xe_module.h"
/**drivers/gpu/drm/xe/xe_configfs.c +3
-10@@ -50,16 +47,9 @@ * * /sys/kernel/config/xe/ * ├── 0000:00:02.0 - * │ └── ... - * ├── 0000:00:02.1 - * │ └── ... - * : - * └── 0000:03:00.0 - * ├── engines_allowed - * ├── gt_types_allowed - * ├── enable_multi_queue - * ├── enable_psmi - * └── survivability_mode + * │ └── ... + * └── 0000:00:02.1 + * └── ... * * After configuring the attributes as per next section, thedevice can be
* probed with::drivers/gpu/drm/xe/xe_configfs.c +0
-5@@ -71,157 +61,6 @@ * Configure Attributes * ==================== * - - * Context restore BB - * ------------------ - * - * Allow to execute a batch buffer during any context switches.When the
- * GPU is restoring the context, it executes additional commands. It's useful
- * for testing additional workarounds and validating certain HW
behaviors: it's
- * not intended for normal execution and will taint the kernel withTAINT_TEST
- * when used.
- *
- * The syntax allows to pass straight instructions to be executed by the engine
- * in a batch buffer or set specific registers.
- *
- * #. Generic instruction::
- *
- * <engine-class> cmd <instr> [[dword0] [dword1] [...]]
- *
- * #. Simple register setting::
- *
- * <engine-class> reg <address> <value>
- *
- * Commands are saved per engine class: all instances of that class will execute
- * those commands during context switch. The instruction, dword arguments,
- * addresses and values are in hex format like in the examples below.
- *
- * #. Execute a LRI command to write0xDEADBEEFto register0x4f10after the
- * normal context restore::
- *
- * # echo 'rcs cmd 11000001 4F100 DEADBEEF' \
- * > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_post_bb
- *
- * #. Execute a LRI command to write0xDEADBEEFto register0x4f10at the
- * beginning of the context restore::
- *
- * # echo 'rcs cmd 11000001 4F100 DEADBEEF' \
- * > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_mid_bb
-
- * #. Load certain values in a couple of registers (it can be used as a simpler
- * alternative to thecmd) action::
- *
- * # cat > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_post_bb <<EOF
- * rcs reg 4F100 DEADBEEF
- * rcs reg 4F104 FFFFFFFF
- * EOF
- *
- * .. note::
- *
- * When using multiple lines, make sure to use a command that is
- * implemented with a single write syscall, like HEREDOC.
- *
- * Currently this is implemented only for post and mid context restore and
- * these attributes can only be set before binding to the device.
- *
- * Allowed engines:
- * ----------------
- *
- * Allow only a set of engine(s) to be available, disabling the other engines
- * even if they are available in hardware. This is applied after HW fuses are
- * considered on each tile. Examples:
- *
- * Allow only one render and one copy engines, nothing else::
- *
- * # echo 'rcs0,bcs0' > /sys/kernel/config/xe/0000:03:00.0/engines_allowed
- *
- * Allow only compute engines and first copy engine::
- *
- * # echo 'ccs*,bcs0' > /sys/kernel/config/xe/0000:03:00.0/engines_allowed
- *
- * Note that the engine names are the per-GT hardware names. On multi-tile
- * platforms, writing ``rcs0,bcs0`` to this file would allow the first render
- * and copy engines on each tile.
- *
- * The requested configuration may not be supported by the platform and driver
- * may fail to probe. For example: if at least one copy engine is expected to be
- * available for migrations, but it's disabled. This is intended for debugging
- * purposes only.
- *
- * This attribute can only be set before binding to the device.
- *
- * Allowed GT types:
- * -----------------
- *
- * Allow only specific types of GTs to be detected and initialized by the
- * driver. Any combination of GT types can be enabled/disabled, although
- * some settings will cause the device to fail to probe.
- *
- * Writes support both comma- and newline-separated input format. Reads
- * will always return one GT type per line. "primary" and "media" are the
- * GT type names supported by this interface.
- *
- * This attribute can only be set before binding to the device.
- *
- * Examples:
- *
- * Allow both primary and media GTs to be initialized and used. This matches
- * the driver's default behavior::
- *
- * # echo 'primary,media' > /sys/kernel/config/xe/0000:03:00.0/gt_types_allowed
- *
- * Allow only the primary GT of each tile to be initialized and used,
- * effectively disabling the media GT if it exists on the platform::
- *
- * # echo 'primary' > /sys/kernel/config/xe/0000:03:00.0/gt_types_allowed
- *
- * Allow only the media GT of each tile to be initialized and used,
- * effectively disabling the primary GT. **This configuration will cause
- * device probe failure on all current platforms, but may be allowed on
- * igpu platforms in the future**::
- *
- * # echo 'media' > /sys/kernel/config/xe/0000:03:00.0/gt_types_allowed
- *
- * Disable all GTs. Only other GPU IP (such as display) is potentially usable.
- * **This configuration will cause device probe failure on all current
- * platforms, but may be allowed on igpu platforms in the future**::
- *
- * # echo '' > /sys/kernel/config/xe/0000:03:00.0/gt_types_allowed
- *
- * Enable multi-queue
- * ------------------
- *
- * Multi-queue support on the device is enabled by default where the
- * hardware supports it. Writing 0 force-disables multi-queue support:
- * multi-queue exec-queue group creation via ioctl is refused, and the
- * GuC feature is disabled::
- *
- * # echo 0 > /sys/kernel/config/xe/0000:03:00.0/enable_multi_queue
- *
- * This attribute can only be set before binding to the device.
- *
- * PSMI
- * ----
- *
- * Enable extra debugging capabilities to trace engine execution. Only useful
- * during early platform enabling and requires additional hardware connected.
- * Once it's enabled, additionals WAs are added and runtime configuration is
- * done via debugfs. Example to enable it::
- *
- * # echo 1 > /sys/kernel/config/xe/0000:03:00.0/enable_psmi
- *Quoted 8 lines
- * This attribute can only be set before binding to the device.
- *
- * Survivability mode:
- * -------------------
- *
- * Enable survivability mode on supported cards. This setting only takes
- * effect when probing the device. Example to enable it::I didn't review the code movement in this patch in depth, but the one thing that I'm uncertain about is whether survivability mode should have
been swept up in this move. My understanding is that unlike the other
options which are meant for developers hacking on the driver, configurable survivability mode is a true production feature intended for end users to get the minimal driver support necessary to deal with a
bad firmware flash, failing hardware, etc. I know there are cases where
the driver can auto-detect the need to enter survivability mode without
the configfs interface (i.e., various RAS error reports and such), but I
thought manual entry through configfs was still something users may need
in some cases? If so that would mean we should keep this available even
when the debug options aren't compiled in.
Quoted 1 line
+Cc Riana in case my understanding is off.
Yeah would appreciate feedback there Riana. My understanding of survivability mode is we want this to allow us to continue operation for a while to debug issues when the hardware is severely misbehaving. This isn't a normal customer use case.
My thought longer term here is we'd turn this into a bit map that allowed various hardware or software isolation configurations. We'll also have the per-feature configfs entries, but the survivability mode could be used to easily isolate based on a higher level isolation scheme that doesn't require the person debugging to fully understand all the different underlying features being disabled if that makes sense.
The flip side of this could be that we really want to require users to be more surgical about how they enable/disable different features. In that case, I'd argue we really should drop survivability mode completely and turn it into an "enable_punit" and various other related configurations.
Thanks,
Stuart
Quoted 2,601 lines
Matt
Quoted 2,596 lines
- *
- * # echo 1 > /sys/kernel/config/xe/0000:03:00.0/survivability_mode
- *
- * This attribute can only be set before binding to the device.
- *
* Max SR-IOV Virtual Functions
* ----------------------------
*drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -256,12 +95,16 @@* # rmdir /sys/kernel/config/xe/0000:03:00.0/ */ drivers/gpu/drm/xe/xe_configfs.c +10
-6-static const struct xe_config_device device_defaults = { - .engines_allowed = U64_MAX, - .gt_types_allowed = U64_MAX, - .enable_multi_queue = true, - .enable_psmi = false, - .survivability_mode = false, +const struct xe_config_device xe_configfs_device_defaults = { +#if IS_ENABLED(CONFIG_DRM_XE_DEBUG) + .debug = { + .engines_allowed = U64_MAX, + .gt_types_allowed = U64_MAX, + .enable_multi_queue = true, + .enable_psmi = false, + .survivability_mode = false, + }, +#endif.sriov = {
.max_vfs =XE_DEFAULT_MAX_VFS, .admin_only_pf =XE_DEFAULT_ADMIN_ONLY_PF,drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -270,50 +113,22 @@ static const struct xe_config_device device_defaults = {
static voidset_device_defaults(struct xe_config_device *config){
- *config =device_defaults;
+ *config =xe_configfs_device_defaults;
#ifdefCONFIG_PCI_IOV
config->sriov.max_vfs = xe_modparam.max_vfs; #endif
}drivers/gpu/drm/xe/xe_configfs.c +0
-7-struct engine_info { - const char *cls; - u64 mask; - enum xe_engine_class engine_class; -}; - -/* Some helpful macros to aid on the sizing of buffer allocation when parsing */
drivers/gpu/drm/xe/xe_configfs.c +0
-5-#define MAX_ENGINE_CLASS_CHARS 5 -#define MAX_ENGINE_INSTANCE_CHARS 2 - -static const struct engine_info engine_info[] = { - { .cls = "rcs", .mask = XE_HW_ENGINE_RCS_MASK,.engine_class =
XE_ENGINE_CLASS_RENDER},
- { .cls = "bcs", .mask =XE_HW_ENGINE_BCS_MASK, .engine_class =XE_ENGINE_CLASS_COPY},
- { .cls = "vcs", .mask =XE_HW_ENGINE_VCS_MASK, .engine_class =XE_ENGINE_CLASS_VIDEO_DECODE},
- { .cls = "vecs", .mask =XE_HW_ENGINE_VECS_MASK, .engine_class =XE_ENGINE_CLASS_VIDEO_ENHANCE}, - { .cls = "ccs", .mask =XE_HW_ENGINE_CCS_MASK, .engine_class =XE_ENGINE_CLASS_COMPUTE},
- { .cls = "gsccs", .mask =XE_HW_ENGINE_GSCCS_MASK, .engine_class =XE_ENGINE_CLASS_OTHER},drivers/gpu/drm/xe/xe_configfs.c +0
-11-}; - -static const struct { - const char *name; - enum xe_gt_type type; -} gt_types[] = { - { .name = "primary", .type = XE_GT_TYPE_MAIN }, - { .name = "media", .type = XE_GT_TYPE_MEDIA }, -}; - -static struct xe_config_group_device*to_xe_config_group_device(struct
config_item*item) -{
- returncontainer_of(to_config_group(item), struct xe_config_group_device, group);drivers/gpu/drm/xe/xe_configfs.c +0
-3-} - -static struct xe_config_device *to_xe_config_device(struct
config_item*item)drivers/gpu/drm/xe/xe_configfs.c +2
-5-{ - return &to_xe_config_group_device(item)->config; -} - -static bool is_bound (struct xe_config_group_device *dev) +/** +* xe_configfs_is_bound - check whether the matching pci device is bound
+ * @dev: configfs group device
+ *
+ * Caller must hold @dev->lock.
+ *
+ * Return: true if the matchingpci_devis already bound to a driver,
+ * false otherwise.
+ */
+boolxe_configfs_is_bound(struct xe_config_group_device *dev){
unsigned int domain, bus, slot, function; structpci_dev*pdev;drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -338,698 +153,13 @@ static bool is_bound(struct xe_config_group_device *dev) return ret; }
-static structxe_config_group_device*find_xe_config_group_device(structpci_dev*pdev);drivers/gpu/drm/xe/xe_configfs.c +0
-3- -/** -* xe_configfs_get_ctx_restore_mid_bb - get configfs
ctx_restore_mid_bbsetting
- * @pdev: pci device
- * @class: hw engine class
- * @cs: pointer to the bb to use - only valid during probe
- *
- * Return: Number of dwords used in themid_ctx_restoresetting in configfs
- */drivers/gpu/drm/xe/xe_configfs.c +0
-5-u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, - enum xe_engine_class class, - const u32 **cs) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- u32 len;drivers/gpu/drm/xe/xe_configfs.c +0
-7- - if (!dev) - return 0; - - scoped_guard(mutex, &dev->lock) { - if (cs) - *cs = dev-Quoted 1 line
config.ctx_restore_mid_bb[class].cs;
drivers/gpu/drm/xe/xe_configfs.c +0
-10- - len = dev->config.ctx_restore_mid_bb[class].len; - } - config_group_put(&dev->group); - - return len; -} - -/** -* xe_configfs_get_ctx_restore_post_bb - get configfs
ctx_restore_post_bbsetting
- * @pdev: pci device
- * @class: hw engine class
- * @cs: pointer to the bb to use - only valid during probe
- *
- * Return: Number of dwords used in thepost_ctx_restoresetting in configfs
- */drivers/gpu/drm/xe/xe_configfs.c +0
-5-u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, - enum xe_engine_class class, - const u32 **cs) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- u32 len;drivers/gpu/drm/xe/xe_configfs.c +0
-32- - if (!dev) - return 0; - - scoped_guard(mutex, &dev->lock) { - *cs = dev->config.ctx_restore_post_bb[class].cs; - len = dev->config.ctx_restore_post_bb[class].len; - } - config_group_put(&dev->group); - - return len; -} - -static bool wa_bb_read_advance (bool dereference,char **p, - const char *append, size_t len, - size_t *max_size) -{ - if (dereference) { - if (len >= *max_size) - return false; - *max_size -= len; - if (append) - memcpy(*p, append, len); - } - - *p += len; - - return true; -} - -static ssize_t wa_bb_show(struct xe_config_group_device *dev, - struct wa_bb wa_bb[static
XE_ENGINE_CLASS_MAX],
- char *data,size_tsz)drivers/gpu/drm/xe/xe_configfs.c +0
-7-{ - char *p = data; - - guard(mutex)(&dev->lock); - - for (size_t i = 0; i < ARRAY_SIZE(engine_info); i++) { - enum xe_engine_class ec =engine_info[i].engine_class;
- size_t len;drivers/gpu/drm/xe/xe_configfs.c +0
-10- - if (!wa_bb[ec].len) - continue; - - len = snprintf(p, sz, "%s:", engine_info[i].cls); - if (!wa_bb_read_advance(data, &p, NULL, len, &sz)) - return -ENOBUFS; - - for (size_t j = 0; j < wa_bb[ec].len; j++) { - len = snprintf(p, sz, " %08x",wa_bb[ec].cs[j]);
- if (!wa_bb_read_advance(data, &p, NULL, len, &sz))
- return-ENOBUFS;
- }drivers/gpu/drm/xe/xe_configfs.c +0
-16- - if (!wa_bb_read_advance(data, &p, "\n", 1, &sz)) - return -ENOBUFS; - } - - if (!wa_bb_read_advance(data, &p, "", 1, &sz)) - return -ENOBUFS; - - /* Reserve one more to match check for '\0' */ - if (!data) - p++; - - return p - data; -} - -static ssize_t ctx_restore_mid_bb_show(struct config_item *item,char *page)
-{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
-
- returnwa_bb_show(dev, dev->config.ctx_restore_mid_bb, page, SZ_4K);drivers/gpu/drm/xe/xe_configfs.c +0
-3-} - -static ssize_t ctx_restore_post_bb_show(struct config_item *item,char *page)
-{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
-
- returnwa_bb_show(dev, dev->config.ctx_restore_post_bb, page, SZ_4K);drivers/gpu/drm/xe/xe_configfs.c +0
-35-} - -static void wa_bb_append (struct wa_bb *wa_bb,u32 val) -{ - if (wa_bb->cs) - wa_bb->cs[wa_bb->len] = val; - - wa_bb->len++; -} - -static ssize_t parse_hex (const char *line,u32 *pval) -{ - char numstr[12]; - const char *p; - ssize_t numlen; - - p = line + strspn(line, " \t"); - if (!*p || *p == '\n') - return 0; - - numlen = strcspn(p, " \t\n"); - if (!numlen || numlen >= sizeof(numstr) - 1) - return -EINVAL; - - memcpy(numstr, p, numlen); - numstr[numlen] = '\0'; - p += numlen; - - if (kstrtou32(numstr, 16, pval)) - return -EINVAL; - - return p - line; -} - -static int parse_engine(const char *s, const char *end_chars, u64*mask,
- const structengine_info**pinfo);drivers/gpu/drm/xe/xe_configfs.c +0
-13- -/* -* Parse lines with the format -* -* <engine-class> cmd <u32> <u32...> -* <engine-class> reg <u32_addr> <u32_val> -* -* and optionally save them in @wa_bb[i].cs is non-NULL. -* -* Return the number of dwords parsed. -*/ -static ssize_t parse_wa_bb_lines(const char *lines, - struct wa_bb wa_bb[static
XE_ENGINE_CLASS_MAX])drivers/gpu/drm/xe/xe_configfs.c +0
-31-{ - ssize_t dwords = 0, ret; - const char *p; - - for (p = lines; *p; p++) { - const struct engine_info *info = NULL; - u32 val, val2; - - /* Also allow empty lines */ - p += strspn(p, " \t\n"); - if (!*p) - break; - - ret = parse_engine(p, " \t\n", NULL, &info); - if (ret < 0) - return ret; - - p += ret; - p += strspn(p, " \t"); - - if (str_has_prefix(p, "cmd")) { - for (p += strlen("cmd"); *p;) { - ret = parse_hex(p, &val); - if (ret < 0) - return -EINVAL; - if (!ret) - break; - - p += ret; - dwords++; - wa_bb_append(&wa_bb[info-Quoted 1 line
engine_class], val);- }
- } else if (str_has_prefix(p, "reg")) { - p +=strlen("reg");
- ret =parse_hex(p, &val); - if (ret <= 0)
- return-EINVAL;drivers/gpu/drm/xe/xe_configfs.c +0
-10- - p += ret; - ret = parse_hex(p, &val2); - if (ret <= 0) - return -EINVAL; - - p += ret; - dwords += 3; - wa_bb_append(&wa_bb[info->engine_class], - MI_LOAD_REGISTER_IMM |
MI_LRI_NUM_REGS(1));
- wa_bb_append(&wa_bb[info->engine_class], val);
- wa_bb_append(&wa_bb[info->engine_class], val2);
- } else {
- return-EINVAL;
- }
- }drivers/gpu/drm/xe/xe_configfs.c +0
-5- - return dwords; -} - -static ssize_t wa_bb_store(struct wa_bb wa_bb[static
XE_ENGINE_CLASS_MAX],
- structxe_config_group_device*dev, - const char *page,size_tlen)drivers/gpu/drm/xe/xe_configfs.c +0
-18-{ - /* tmp_wa_bb must match wa_bb's size */ - struct wa_bb tmp_wa_bb[XE_ENGINE_CLASS_MAX] = { }; - ssize_t count, class; - u32 *tmp; - - /* 1. Count dwords - wa_bb[i].cs is NULL for all classes */ - count = parse_wa_bb_lines(page, tmp_wa_bb); - if (count < 0) - return count; - - guard(mutex)(&dev->lock); - - if (is_bound(dev)) - return -EBUSY; - - /* -* 2. Allocate a u32 array and set the pointers to the right positions
- * according to the length of each class'wa_bb- */
- tmp =krealloc(wa_bb[0].cs, count * sizeof(u32), GFP_KERNEL);
- if (!tmp)
- return-ENOMEM;drivers/gpu/drm/xe/xe_configfs.c +1
-13- - if (!count) { - memset(wa_bb, 0, sizeof(tmp_wa_bb)); - return len; - } - - for (class = 0, count = 0; class < XE_ENGINE_CLASS_MAX; ++class) { - tmp_wa_bb[class].cs = tmp + count; - count += tmp_wa_bb[class].len; - tmp_wa_bb[class].len = 0; - } - - /* 3. Parse wa_bb lines again, this time saving the values*/
- count =parse_wa_bb_lines(page, tmp_wa_bb); - if (count < 0)
- return count;drivers/gpu/drm/xe/xe_configfs.c +0
-8- - memcpy(wa_bb, tmp_wa_bb, sizeof(tmp_wa_bb)); - - return len; -} - -static ssize_t ctx_restore_mid_bb_store (struct config_item *item, - const char *data, size_tsz)
-{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
-
- returnwa_bb_store(dev->config.ctx_restore_mid_bb, dev, data, sz);drivers/gpu/drm/xe/xe_configfs.c +0
-4-} - -static ssize_t ctx_restore_post_bb_store (struct config_item *item, - const char *data, size_tsz)
-{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
-
- returnwa_bb_store(dev->config.ctx_restore_post_bb, dev, data, sz);drivers/gpu/drm/xe/xe_configfs.c +0
-4-} - -/** -* xe_configfs_get_engines_allowed - get engine allowed mask from configfs
- * @pdev: pci device
- *
- * Return: engine mask with allowed engines set in configfs
- */drivers/gpu/drm/xe/xe_configfs.c +0
-3-u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- u64engines_allowed;drivers/gpu/drm/xe/xe_configfs.c +0
-12- - if (!dev) - return device_defaults.engines_allowed; - - scoped_guard(mutex, &dev->lock) - engines_allowed = dev->config.engines_allowed; - config_group_put(&dev->group); - - return engines_allowed; -} - -static ssize_t engines_allowed_show(struct config_item *item, char*page)
drivers/gpu/drm/xe/xe_configfs.c +0
-9-{ - struct xe_config_device *dev = to_xe_config_device(item); - char *p = page; - - for (size_t i = 0; i < ARRAY_SIZE(engine_info); i++) { - u64 mask = engine_info[i].mask; - - if ((dev->engines_allowed & mask) == mask) { - p += sprintf(p, "%s*\n",engine_info[i].cls);
- } else if (mask &dev->engines_allowed) { - u16 bit0 =__ffs64(mask), bit;drivers/gpu/drm/xe/xe_configfs.c +0
-4- - mask &= dev->engines_allowed; - - for_each_set_bit(bit, (const unsigned long*)&mask, 64)
- p += sprintf(p, "%s%u\n", engine_info[i].cls,
- bit - bit0); - }
- }drivers/gpu/drm/xe/xe_configfs.c +0
-6- - return p - page; -} - -/* -* Lookup engine_info. If @mask is not NULL, reduce the mask according to the
- * instance in @pattern.
- *
- * Examples of inputs:
- * -lookup_engine_info("rcs0", &mask): return "rcs" entry from @engine_info and
- * mask ==BIT_ULL(XE_HW_ENGINE_RCS0)
- * -lookup_engine_info("rcs*", &mask): return "rcs" entry from @engine_info and
- * mask ==XE_HW_ENGINE_RCS_MASK
- * -lookup_engine_info("rcs", NULL): return "rcs" entry from @engine_info
- */
-static const structengine_info*lookup_engine_info(const char *pattern, u64 *mask)drivers/gpu/drm/xe/xe_configfs.c +0
-32-{ - for (size_t i = 0; i < ARRAY_SIZE(engine_info); i++) { - u8 instance; - u16 bit; - - if (!str_has_prefix(pattern, engine_info[i].cls)) - continue; - - pattern += strlen(engine_info[i].cls); - if (!mask) - return *pattern ? NULL : &engine_info[i]; - - if (!strcmp(pattern, "*")) { - *mask = engine_info[i].mask; - return &engine_info[i]; - } - - if (kstrtou8(pattern, 10, &instance)) - return NULL; - - bit = __ffs64(engine_info[i].mask) + instance; - if (bit >= fls64(engine_info[i].mask)) - return NULL; - - *mask = BIT_ULL(bit); - return &engine_info[i]; - } - - return NULL; -} - -static int parse_engine(const char *s, const char *end_chars, u64*mask,
- const structengine_info**pinfo)drivers/gpu/drm/xe/xe_configfs.c +1
-23-{ - char buf[MAX_ENGINE_CLASS_CHARS + MAX_ENGINE_INSTANCE_CHARS + 1]; - const struct engine_info *info; - size_t len; - - len = strcspn(s, end_chars); - if (len >= sizeof(buf)) - return -EINVAL; - - memcpy(buf, s, len); - buf[len] = '\0'; - - info = lookup_engine_info(buf, mask); - if (!info) - return -ENOENT; - - if (pinfo) - *pinfo = info; - - return len; -} - -static ssize_t engines_allowed_store(struct config_item *item,const char *page,
-size_tlen)
-{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
- ssize_t patternlen, p;
- u64 mask, val = 0;
-
- for (p = 0; p < len; p += patternlen + 1) {
- patternlen =parse_engine(page + p, ",\n", &mask, NULL);
- if (patternlen < 0)
- return-EINVAL;drivers/gpu/drm/xe/xe_configfs.c +0
-16- - val |= mask; - } - - guard(mutex)(&dev->lock); - if (is_bound(dev)) - return -EBUSY; - - dev->config.engines_allowed = val; - - return len; -} - -static u64 get_gt_types_allowed (struct pci_dev *pdev) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- u64 mask;drivers/gpu/drm/xe/xe_configfs.c +0
-13- - if (!dev) - return device_defaults.gt_types_allowed; - - scoped_guard(mutex, &dev->lock) - mask = dev->config.gt_types_allowed; - config_group_put(&dev->group); - - return mask; -} - -/** -* xe_configfs_primary_gt_allowed - determine whether primary GTs are supported
- * @pdev: pci device
- *
- * Return: True if primary GTs are enabled, false if they have been disabled via
- * configfs.
- */drivers/gpu/drm/xe/xe_configfs.c +0
-3-bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) -{ - return get_gt_types_allowed(pdev) &
BIT_ULL(XE_GT_TYPE_MAIN);drivers/gpu/drm/xe/xe_configfs.c +0
-4-} - -/** -* xe_configfs_media_gt_allowed - determine whether media GTs are supported
- * @pdev: pci device
- *
- * Return: True if the media GTs are enabled, false if they have been disabled
- * via configfs.
- */drivers/gpu/drm/xe/xe_configfs.c +0
-3-bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) -{ - return get_gt_types_allowed(pdev) &
BIT_ULL(XE_GT_TYPE_MEDIA);drivers/gpu/drm/xe/xe_configfs.c +0
-3-} - -static ssize_t gt_types_allowed_show(struct config_item *item,char *page)
drivers/gpu/drm/xe/xe_configfs.c +0
-6-{ - struct xe_config_device *dev = to_xe_config_device(item); - char *p = page; - - for (size_t i = 0; i < ARRAY_SIZE(gt_types); i++) - if (dev->gt_types_allowed &
BIT_ULL(gt_types[i].type))
- p +=sprintf(p, "%s\n", gt_types[i].name);drivers/gpu/drm/xe/xe_configfs.c +0
-5- - return p - page; -} - -static ssize_t gt_types_allowed_store(struct config_item *item,const char *page,
-size_tlen) -{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
- char *buf__free(kfree)=kstrdup(page, GFP_KERNEL); - char *p = buf;
- u64 typemask = 0;drivers/gpu/drm/xe/xe_configfs.c +0
-13- - if (!buf) - return -ENOMEM; - - while (p) { - char *typename = strsep(&p, ",\n"); - bool matched = false; - - if (typename[0] == '\0') - continue; - - for (size_t i = 0; i < ARRAY_SIZE(gt_types); i++) { - if (strcmp(typename, gt_types[i].name) ==0) {
- typemask |=BIT(gt_types[i].type); - matched = true;
- break;
- }
- }drivers/gpu/drm/xe/xe_configfs.c +0
-16- - if (!matched) - return -EINVAL; - } - - guard(mutex)(&dev->lock); - if (is_bound(dev)) - return -EBUSY; - - dev->config.gt_types_allowed = typemask; - - return len; -} - -/** -* xe_configfs_get_enable_multi_queue - get configfs
enable_multi_queuesetting
- * @pdev: pci device
- *
- * Return: true if multi-queue is enabled for this device (the default),
- * false if it has been force-disabled via configfs.
- */drivers/gpu/drm/xe/xe_configfs.c +0
-3-bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- bool ret;drivers/gpu/drm/xe/xe_configfs.c +0
-12- - if (!dev) - return true; - - scoped_guard(mutex, &dev->lock) - ret = dev->config.enable_multi_queue; - config_group_put(&dev->group); - - return ret; -} - -static ssize_t enable_multi_queue_show(struct config_item *item,char *page)
drivers/gpu/drm/xe/xe_configfs.c +0
-7-{ - struct xe_config_device *dev = to_xe_config_device(item); - - return sprintf(page, "%d\n", dev->enable_multi_queue); -} - -static ssize_t enable_multi_queue_store(struct config_item *item,const char *page,
- size_t len) -{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
- bool val;
- int ret;drivers/gpu/drm/xe/xe_configfs.c +0
-23- - ret = kstrtobool(page, &val); - if (ret) - return ret; - - guard(mutex)(&dev->lock); - if (is_bound(dev)) - return -EBUSY; - - dev->config.enable_multi_queue = val; - - return len; -} - -/** -* xe_configfs_get_psmi_enabled - get configfs enable_psmi setting -* @pdev: pci device -* -* Return: enable_psmi setting in configfs -*/ -bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- bool ret;drivers/gpu/drm/xe/xe_configfs.c +0
-12- - if (!dev) - return false; - - scoped_guard(mutex, &dev->lock) - ret = dev->config.enable_psmi; - config_group_put(&dev->group); - - return ret; -} - -static ssize_t enable_psmi_show(struct config_item *item, char*page)
drivers/gpu/drm/xe/xe_configfs.c +0
-7-{ - struct xe_config_device *dev = to_xe_config_device(item); - - return sprintf(page, "%d\n", dev->enable_psmi); -} - -static ssize_t enable_psmi_store(struct config_item *item, constchar *page,
size_tlen)
-{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
- bool val;
- int ret;drivers/gpu/drm/xe/xe_configfs.c +0
-16- - ret = kstrtobool(page, &val); - if (ret) - return ret; - - guard(mutex)(&dev->lock); - if (is_bound(dev)) - return -EBUSY; - - dev->config.enable_psmi = val; - - return len; -} - -/** -* xe_configfs_get_survivability_mode - get configfs survivability mode attribute
- * @pdev: pci device
- *
- * Return:survivability_modeattribute in configfs
- */drivers/gpu/drm/xe/xe_configfs.c +0
-3-bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- bool mode;drivers/gpu/drm/xe/xe_configfs.c +0
-12- - if (!dev) - return device_defaults.survivability_mode; - - scoped_guard(mutex, &dev->lock) - mode = dev->config.survivability_mode; - config_group_put(&dev->group); - - return mode; -} - -static ssize_t survivability_mode_show(struct config_item *item,char *page)
drivers/gpu/drm/xe/xe_configfs.c +0
-7-{ - struct xe_config_device *dev = to_xe_config_device(item); - - return sprintf(page, "%d\n", dev->survivability_mode); -} - -static ssize_t survivability_mode_store(struct config_item *item,const char *page,
size_tlen)
-{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
- boolsurvivability_mode;
- int ret;drivers/gpu/drm/xe/xe_configfs.c +0
-33- - ret = kstrtobool(page, &survivability_mode); - if (ret) - return ret; - - guard(mutex)(&dev->lock); - if (is_bound(dev)) - return -EBUSY; - - dev->config.survivability_mode = survivability_mode; - - return len; -} - -CONFIGFS_ATTR(, ctx_restore_mid_bb); -CONFIGFS_ATTR(, ctx_restore_post_bb); -CONFIGFS_ATTR(, engines_allowed); -CONFIGFS_ATTR(, gt_types_allowed); -CONFIGFS_ATTR(, enable_multi_queue); -CONFIGFS_ATTR(, enable_psmi); -CONFIGFS_ATTR(, survivability_mode); - -static struct configfs_attribute *xe_config_device_attrs[] = { - &attr_ctx_restore_mid_bb, - &attr_ctx_restore_post_bb, - &attr_engines_allowed, - &attr_gt_types_allowed, - &attr_enable_multi_queue, - &attr_enable_psmi, - &attr_survivability_mode, - NULL, -}; -static void
xe_config_device_release(struct config_item *item){
- structxe_config_group_device*dev =to_xe_config_group_device(item);
+ structxe_config_group_device*dev =xe_configfs_to_group_device(item);
mutex_destroy(&dev->lock);
- kfree(dev->config.ctx_restore_mid_bb[0].cs); - kfree(dev->config.ctx_restore_post_bb[0].cs); + xe_configfs_debug_release_config(&dev->config); kfree(dev);
}drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1037,33 +167,14 @@ static struct configfs_item_operations xe_config_device_ops = { .release = xe_config_device_release, };
-static bool xe_config_device_is_visible(structconfig_item*item, - structconfigfs_attribute*attr, int n)
-{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
-
- if (attr ==&attr_survivability_mode) {
- if (!dev->desc->is_dgfx ||dev->desc->platform<XE_BATTLEMAGE)
- return false;
- }drivers/gpu/drm/xe/xe_configfs.c +0
-5- - return true; -} - -static struct configfs_group_operations xe_config_device_group_ops= {
- .is_visible =xe_config_device_is_visible,drivers/gpu/drm/xe/xe_configfs.c +0
-2-}; -static const struct
config_item_typexe_config_device_type= { .ct_item_ops =&xe_config_device_ops,
- .ct_group_ops =&xe_config_device_group_ops, - .ct_attrs =xe_config_device_attrs, .ct_owner =THIS_MODULE,
};
staticssize_tsriov_max_vfs_show(struct config_item *item, char *page)
{
- structxe_config_group_device*dev =to_xe_config_group_device(item->ci_parent);
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
guard(mutex)(&dev->lock);drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1075,13 +186,13 @@ static ssize_t sriov_max_vfs_show(struct config_item *item, char *page)
staticssize_tsriov_max_vfs_store(struct config_item *item, const char *page, size_t len)
{
- structxe_config_group_device*dev =to_xe_config_group_device(item->ci_parent);
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
unsigned intmax_vfs;
int ret;
guard(mutex)(&dev->lock);
- if (is_bound(dev))
+ if (xe_configfs_is_bound(dev))
return-EBUSY;
ret =kstrtouint(page, 0, &max_vfs);drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1097,7 +208,7 @@ static ssize_t sriov_max_vfs_store(struct
config_item*item, const char *page, s
staticssize_tsriov_admin_only_pf_show(struct config_item *item, char *page)
{
- structxe_config_group_device*dev =to_xe_config_group_device(item->ci_parent);
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
guard(mutex)(&dev->lock);drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1106,13 +217,13 @@ static ssize_t sriov_admin_only_pf_show(struct config_item *item, char *page)
staticssize_tsriov_admin_only_pf_store(struct config_item *item, const char *page, size_t len)
{
- structxe_config_group_device*dev =to_xe_config_group_device(item->ci_parent);
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
booladmin_only_pf;
int ret;
guard(mutex)(&dev->lock);
- if (is_bound(dev))
+ if (xe_configfs_is_bound(dev))
return-EBUSY;
ret =kstrtobool(page, &admin_only_pf);drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1135,7 +246,7 @@ static struct configfs_attribute *xe_config_sriov_attrs[] = { static bool xe_config_sriov_is_visible(struct config_item *item,struct
configfs_attribute*attr, int n)
{
- structxe_config_group_device*dev =to_xe_config_group_device(item->ci_parent);
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
if (attr ==&sriov_attr_max_vfs&&dev->mode!=XE_SRIOV_MODE_PF)
return false;drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1271,7 +382,17 @@ static struct configfs_subsystem xe_configfs = { }, };
-static structxe_config_group_device*find_xe_config_group_device(structpci_dev*pdev)
+/**
+ *xe_configfs_find_group_device()- Find a configfs group by PCI device.
+ * @pdev: the&pci_devto look up
+ *
+ * Searches the configfs subsystem for a group whose name matches @pdev.
+ * If found, the returned group has an elevated reference count; the caller
+ * must callconfig_group_put()when done.
+ *
+ * Return: pointer to the matching&xe_config_group_device, or NULL.
+ */
+structxe_config_group_device*xe_configfs_find_group_device(structpci_dev*pdev)
{
structconfig_item*item;drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1282,23 +403,25 @@ static struct xe_config_group_device *find_xe_config_group_device(struct pci_dev if (!item) return NULL;
- returnto_xe_config_group_device(item);
+ returnxe_configfs_to_group_device(item);
}
static voiddump_custom_dev_config(struct pci_dev *pdev, struct xe_config_group_device *dev)
{
#definePRI_CUSTOM_ATTR(fmt_, attr_)do { \
- if (dev->config.attr_!= device_defaults.attr_) \
+ if (dev->config.attr_!= xe_configfs_device_defaults.attr_) \
pci_info(pdev, "configfs: "__stringify(attr_)" = "fmt_"\n", \
dev->config.attr_); \
} while (0)
- PRI_CUSTOM_ATTR("%llx",engines_allowed);
- PRI_CUSTOM_ATTR("%llx",gt_types_allowed);
- PRI_CUSTOM_ATTR("%d",enable_multi_queue);
- PRI_CUSTOM_ATTR("%d",enable_psmi);
- PRI_CUSTOM_ATTR("%d",survivability_mode);drivers/gpu/drm/xe/xe_configfs.c +7
-0+#if IS_ENABLED (CONFIG_DRM_XE_DEBUG ) + PRI_CUSTOM_ATTR("%llx", debug.engines_allowed); + PRI_CUSTOM_ATTR("%llx", debug.gt_types_allowed); + PRI_CUSTOM_ATTR("%d", debug.enable_multi_queue); + PRI_CUSTOM_ATTR("%d", debug.enable_psmi); + PRI_CUSTOM_ATTR("%d", debug.survivability_mode); +#endif PRI_CUSTOM_ATTR("%u", sriov.admin_only_pf);
#undefPRI_CUSTOM_ATTRdrivers/gpu/drm/xe/xe_configfs.c +1
-1@@ -1313,13 +436,13 @@ static void dump_custom_dev_config(structpci_dev *pdev, */ void xe_configfs_check_device(struct pci_dev *pdev) { - struct xe_config_group_device *dev =find_xe_config_group_device (pdev); + struct xe_config_group_device *dev =xe_configfs_find_group_device (pdev);
if (!dev)
return;
/* memcmp here is safe as both are zero-initialized */ - if (memcmp(&dev->config,&device_defaults, sizeof(dev-Quoted 1 line
config))) {
+ if (
memcmp(&dev->config, &xe_configfs_device_defaults, sizeof(dev->config))) {
pci_info(pdev, "Found custom settings in configfs\n");
dump_custom_dev_config(pdev, dev);
}drivers/gpu/drm/xe/xe_configfs.c +1
-1@@ -1341,7 +464,7 @@ void xe_configfs_check_device(struct pci_dev*pdev) */ bool xe_configfs_admin_only_pf(struct pci_dev *pdev) { - struct xe_config_group_device *dev =find_xe_config_group_device (pdev); + struct xe_config_group_device *dev =xe_configfs_find_group_device (pdev);bool
admin_only_pf;
if (!dev)drivers/gpu/drm/xe/xe_configfs.c +1
-1@@ -1366,7 +489,7 @@ bool xe_configfs_admin_only_pf(struct pci_dev*pdev) */ unsigned int xe_configfs_get_max_vfs(struct pci_dev *pdev) { - struct xe_config_group_device *dev =find_xe_config_group_device (pdev); + struct xe_config_group_device *dev =xe_configfs_find_group_device (pdev);unsigned int
max_vfs;
if (!dev)drivers/gpu/drm/xe/xe_configfs.h +0
-0@@ -12,24 +12,76 @@ #include "xe_defaults.h" #include "xe_module.h"
+structconfig_item;
structpci_dev;drivers/gpu/drm/xe/xe_configfs.h +3
-0+struct xe_config_group_device ; + +extern const struct xe_config_device xe_configfs_device_defaults;
#ifIS_ENABLED(CONFIG_CONFIGFS_FS)
+/**
+ *xe_configfs_to_group_device()- Cast aconfig_itemto&xe_config_group_device.
+ * @item: the&config_itemembedded in the device group
+ *
+ * The @item must be the top-level device group'scg_item, not a subgroup item.
+ * Usexe_configfs_subgroup_to_group_device()for subgroup show/store callbacks.
+ *
+ * Return: pointer to the enclosing&xe_config_group_device.
+ */drivers/gpu/drm/xe/xe_configfs.h +4
-0+static inline struct xe_config_group_device * +xe_configfs_to_group_device (struct config_item *item) +{ + return container_of(to_config_group(item), struct
xe_config_group_device, group);drivers/gpu/drm/xe/xe_configfs.h +4
-0+} + +/** +* xe_configfs_to_device() - Cast a config_item to
&xe_config_device.
+ * @item: the&config_itemembedded in the device group
+ *
+ * Convenience wrapper aroundxe_configfs_to_group_device().
+ *
+ * Return: pointer to the&xe_config_devicenested in the group.
+ */
+static inline structxe_config_device*xe_configfs_to_device(structconfig_item*item)drivers/gpu/drm/xe/xe_configfs.h +6
-0+{ + return &xe_configfs_to_group_device(item)->config; +} + +/** +* xe_configfs_subgroup_to_group_device() - Cast a subgroup item to
&xe_config_group_device.
+ * @item: the&config_itemof a subgroup (e.g. sriov or debug)
+ *
+ * In configfs, show/store callbacks for a subgroup's attributes receive the
+ * subgroup'scg_item, whose parent is the device group'scg_item.
+ * This helper walks up one level to return the enclosing device group.
+ *
+ * Return: pointer to the enclosing&xe_config_group_device.
+ */drivers/gpu/drm/xe/xe_configfs.h +8
-0+static inline struct xe_config_group_device * +xe_configfs_subgroup_to_group_device (struct config_item *item) +{ + return xe_configfs_to_group_device(item->ci_parent); +} + +/** +* xe_configfs_subgroup_to_device() - Cast a subgroup item to
&xe_config_device.
+ * @item: the&config_itemof a subgroup (e.g. sriov or debug)
+ *
+ * Convenience wrapper for a subgroup item to get the&xe_config_device.
+ *
+ * Return: pointer to the&xe_config_devicenested in the parent device group.
+ */drivers/gpu/drm/xe/xe_configfs.h +8
-0+static inline struct xe_config_device * +xe_configfs_subgroup_to_device (struct config_item *item) +{ + return xe_configfs_to_device(item->ci_parent); +} + +bool xe_configfs_is_bound (struct xe_config_group_device *dev); +struct xe_config_group_device *xe_configfs_find_group_device(struct
pci_dev*pdev); intxe_configfs_init(void);
voidxe_configfs_exit(void);
voidxe_configfs_check_device(struct pci_dev *pdev);drivers/gpu/drm/xe/xe_configfs.h +0
-12-u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, - enum xe_engine_class class, - const u32 **cs); -u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, - enum xe_engine_class class, - const u32 **cs); -u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev); -bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev); -bool xe_configfs_media_gt_allowed (struct pci_dev *pdev); -bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev); -bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev); -bool xe_configfs_get_survivability_mode (struct pci_dev *pdev);#ifdef
CONFIG_PCI_IOV
unsigned intxe_configfs_get_max_vfs(struct pci_dev *pdev); boolxe_configfs_admin_only_pf(struct pci_dev *pdev);drivers/gpu/drm/xe/xe_configfs.h +0
-2@@ -38,18 +90,6 @@ bool xe_configfs_admin_only_pf(struct pci_dev *pdev); static inline int xe_configfs_init(void) { return 0; } static inline void xe_configfs_exit(void) { } static inline void xe_configfs_check_device(struct pci_dev *pdev) { } -static inline u32 xe_configfs_get_ctx_restore_mid_bb(struct pci_dev *pdev, - enum
xe_engine_classclass,
- const u32 **cs) { return 0; }
-static inline u32 xe_configfs_get_ctx_restore_post_bb(structpci_dev*pdev,
- enumxe_engine_classclass,
- const u32 **cs) { return 0; }
-static inline u64xe_configfs_get_engines_allowed(struct pci_dev *pdev){ returnU64_MAX; }
-static inline boolxe_configfs_primary_gt_allowed(struct pci_dev *pdev){ return true; }
-static inline boolxe_configfs_media_gt_allowed(struct pci_dev *pdev){ return true; }
-static inline boolxe_configfs_get_enable_multi_queue(struct pci_dev *pdev){ return true; }
-static inline boolxe_configfs_get_psmi_enabled(struct pci_dev *pdev){ return false; }
-static inline boolxe_configfs_get_survivability_mode(struct pci_dev *pdev){ return false; }
#ifdefCONFIG_PCI_IOV
static inline unsigned intxe_configfs_get_max_vfs(struct pci_dev *pdev)
{drivers/gpu/drm/xe/xe_configfs_debug.c +0
-0@@ -3,12 +3,968 @@* Copyright © 2026 Intel Corporation */
+#include <linux/bitops.h>
#include <linux/configfs.h>
#include <linux/module.h>drivers/gpu/drm/xe/xe_configfs_debug.c +4
-0+#include <linux/cleanup.h> +#include <linux/find.h> +#include <linux/pci.h> +#include <linux/string.h> drivers/gpu/drm/xe/xe_configfs_debug.c +3
-0+#include "abi/guc_log_abi.h" +#include "instructions/xe_mi_commands.h" +#include "xe_configfs.h" #include "
xe_configfs_debug.h"
#include "xe_configfs_types.h"drivers/gpu/drm/xe/xe_configfs_debug.c +11
-0+#include "xe_gt_types.h" +#include "xe_hw_engine_types.h" +#include "xe_pci_types.h" + +/** +* DOC: Xe Configfs Debug Attributes +* +* Overview +* ======== +* +* The following configfs attributes are only available when the kernel is
+ * built with ``CONFIG_DRM_XE_DEBUG=y``. They appear under the ``debug/``
+ * subdirectory of each xe configfs device. They are intended for hardware
+ * and driver debugging and are not stable ABI. Using them is "at your own
+ * risk".
+ *
+ * See the top-level ``Xe Configfs`` documentation in ``xe_configfs.c``
+ * for how to create, probe and remove configfs devices. Once a device
+ * directory exists, the driver populates it with a ``debug/`` subdirectory
+ * containing the entries described below::
+ *
+ * /sys/kernel/config/xe/+ * └── 0000:03:00.0 + * └── debug/ + * ├── ctx_restore_mid_bb + * ├── ctx_restore_post_bb + * ├── engines_allowed + * ├── gt_types_allowed + * ├── enable_multi_queue + * ├── enable_psmi + * └── survivability_mode+ *
+ * Configure Attributes
+ * ====================
+ *
+ * Context restore BB
+ * ------------------
+ *
+ * Allow to execute a batch buffer during any context switches. When the
+ * GPU is restoring the context, it executes additional commands. It's useful
+ * for testing additional workarounds and validating certain HW
behaviors: it's
+ * not intended for normal execution and will taint the kernel withTAINT_TEST
+ * when used.
+ *
+ * The syntax allows to pass straight instructions to be executed by the engine
+ * in a batch buffer or set specific registers.
+ *
+ * #. Generic instruction::
+ *
+ * <engine-class> cmd <instr> [[dword0] [dword1] [...]]
+ *
+ * #. Simple register setting::
+ *
+ * <engine-class> reg <address> <value>
+ *
+ * Commands are saved per engine class: all instances of that class will execute
+ * those commands during context switch. The instruction, dword arguments,
+ * addresses and values are in hex format like in the examples below.
+ *
+ * #. Execute a LRI command to write0xDEADBEEFto register0x4f10after the
+ * normal context restore::
+ *
+ * # echo 'rcs cmd 11000001 4F100 DEADBEEF' \
+ * > /sys/kernel/config/xe/0000:03:00.0/debug/ctx_restore_post_bb
+ *
+ * #. Execute a LRI command to write0xDEADBEEFto register0x4f10at the
+ * beginning of the context restore::
+ *
+ * # echo 'rcs cmd 11000001 4F100 DEADBEEF' \
+ * > /sys/kernel/config/xe/0000:03:00.0/debug/ctx_restore_mid_bb
+ *
+ * #. Load certain values in a couple of registers (it can be used as a simpler
+ * alternative to thecmd) action::
+ *
+ * # cat > /sys/kernel/config/xe/0000:03:00.0/debug/ctx_restore_post_bb <<EOF
+ * rcs reg 4F100 DEADBEEF
+ * rcs reg 4F104 FFFFFFFF
+ * EOF
+ *
+ * .. note::
+ *
+ * When using multiple lines, make sure to use a command that is
+ * implemented with a single write syscall, like HEREDOC.
+ *
+ * Currently this is implemented only for post and mid context restore and
+ * these attributes can only be set before binding to the device.
+ *
+ * Allowed engines:
+ * ----------------
+ *
+ * Allow only a set of engine(s) to be available, disabling the other engines
+ * even if they are available in hardware. This is applied after HW fuses are
+ * considered on each tile. Examples:
+ *
+ * Allow only one render and one copy engines, nothing else::
+ *
+ * # echo 'rcs0,bcs0' > /sys/kernel/config/xe/0000:03:00.0/debug/engines_allowed
+ *
+ * Allow only compute engines and first copy engine::
+ *
+ * # echo 'ccs*,bcs0' > /sys/kernel/config/xe/0000:03:00.0/debug/engines_allowed
+ *
+ * Note that the engine names are the per-GT hardware names. On multi-tile
+ * platforms, writing ``rcs0,bcs0`` to this file would allow the first render
+ * and copy engines on each tile.
+ *
+ * The requested configuration may not be supported by the platform and driver
+ * may fail to probe. For example: if at least one copy engine is expected to be
+ * available for migrations, but it's disabled. This is intended for debugging
+ * purposes only.
+ *
+ * This attribute can only be set before binding to the device.
+ *
+ * Allowed GT types:
+ * -----------------
+ *
+ * Allow only specific types of GTs to be detected and initialized by the
+ * driver. Any combination of GT types can be enabled/disabled, although
+ * some settings will cause the device to fail to probe.
+ *
+ * Writes support both comma- and newline-separated input format. Reads
+ * will always return one GT type per line. "primary" and "media" are the
+ * GT type names supported by this interface.
+ *
+ * This attribute can only be set before binding to the device.
+ *
+ * Examples:
+ *
+ * Allow both primary and media GTs to be initialized and used. This matches
+ * the driver's default behavior::
+ *
+ * # echo 'primary,media' > /sys/kernel/config/xe/0000:03:00.0/debug/gt_types_allowed
+ *
+ * Allow only the primary GT of each tile to be initialized and used,
+ * effectively disabling the media GT if it exists on the platform::
+ *
+ * # echo 'primary' > /sys/kernel/config/xe/0000:03:00.0/debug/gt_types_allowed
+ *
+ * Allow only the media GT of each tile to be initialized and used,
+ * effectively disabling the primary GT. **This configuration will cause
+ * device probe failure on all current platforms, but may be allowed on
+ * igpu platforms in the future**::
+ *
+ * # echo 'media' > /sys/kernel/config/xe/0000:03:00.0/debug/gt_types_allowed
+ *
+ * Disable all GTs. Only other GPU IP (such as display) is potentially usable.
+ * **This configuration will cause device probe failure on all current
+ * platforms, but may be allowed on igpu platforms in the future**::
+ *
+ * # echo '' > /sys/kernel/config/xe/0000:03:00.0/debug/gt_types_allowed
+ *
+ * Enable multi-queue
+ * ------------------
+ *
+ * Multi-queue support on the device is enabled by default where the
+ * hardware supports it. Writing 0 force-disables multi-queue support:
+ * multi-queue exec-queue group creation via ioctl is refused, and the
+ * GuC feature is disabled::
+ *
+ * # echo 0 > /sys/kernel/config/xe/0000:03:00.0/debug/enable_multi_queue
+ *
+ * This attribute can only be set before binding to the device.
+ *
+ * PSMI
+ * ----
+ *
+ * Enable extra debugging capabilities to trace engine execution. Only useful
+ * during early platform enabling and requires additional hardware connected.
+ * Once it's enabled, additionals WAs are added and runtime configuration is
+ * done via debugfs. Example to enable it::
+ *
+ * # echo 1 > /sys/kernel/config/xe/0000:03:00.0/debug/enable_psmi
+ *
+ * This attribute can only be set before binding to the device.
+ *
+ * Survivability mode:
+ * -------------------
+ *
+ * Enable survivability mode on supported cards. This setting only takes
+ * effect when probing the device. Example to enable it::
+ *
+ * # echo 1 > /sys/kernel/config/xe/0000:03:00.0/debug/survivability_mode
+ *
+ * This attribute can only be set before binding to the device.
+ *
+ */drivers/gpu/drm/xe/xe_configfs_debug.c +8
-0+ +struct engine_info { + const char *cls; + u64 mask; + enum xe_engine_class engine_class; +}; + +/* Some helpful macros to aid on the sizing of buffer allocation when parsing */
drivers/gpu/drm/xe/xe_configfs_debug.c +5
-0+#define MAX_ENGINE_CLASS_CHARS 5 +#define MAX_ENGINE_INSTANCE_CHARS 2 + +static const struct engine_info engine_info[] = { + { .cls = "rcs", .mask = XE_HW_ENGINE_RCS_MASK,.engine_class =
XE_ENGINE_CLASS_RENDER},
+ { .cls = "bcs", .mask =XE_HW_ENGINE_BCS_MASK, .engine_class =XE_ENGINE_CLASS_COPY},
+ { .cls = "vcs", .mask =XE_HW_ENGINE_VCS_MASK, .engine_class =XE_ENGINE_CLASS_VIDEO_DECODE},
+ { .cls = "vecs", .mask =XE_HW_ENGINE_VECS_MASK, .engine_class =XE_ENGINE_CLASS_VIDEO_ENHANCE}, + { .cls = "ccs", .mask =XE_HW_ENGINE_CCS_MASK, .engine_class =XE_ENGINE_CLASS_COMPUTE},
+ { .cls = "gsccs", .mask =XE_HW_ENGINE_GSCCS_MASK, .engine_class =XE_ENGINE_CLASS_OTHER},drivers/gpu/drm/xe/xe_configfs_debug.c +11
-0+}; + +static const struct { + const char *name; + enum xe_gt_type type; +} gt_types[] = { + { .name = "primary", .type = XE_GT_TYPE_MAIN }, + { .name = "media", .type = XE_GT_TYPE_MEDIA }, +}; + +static struct xe_config_group_device *find_device(struct pci_dev*pdev)
drivers/gpu/drm/xe/xe_configfs_debug.c +6
-0+{ + return xe_configfs_find_group_device(pdev); +} + +/** +* xe_configfs_get_ctx_restore_mid_bb - get configfs
ctx_restore_mid_bbsetting
+ * @pdev: pci device
+ * @class: hw engine class
+ * @cs: pointer to the bb to use - only valid during probe
+ *
+ * Return: Number of dwords used in themid_ctx_restoresetting in configfs
+ */drivers/gpu/drm/xe/xe_configfs_debug.c +13
-0+u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, + enum xe_engine_class class, + const u32 **cs) +{ + struct xe_config_group_device *dev = find_device(pdev); + u32 len; + + if (!dev) + return 0; + + scoped_guard(mutex, &dev->lock) { + if (cs) + *cs = dev-Quoted 1 line
config.debug.ctx_restore_mid_bb[class].cs;
+
+ len = dev-Quoted 1 line
config.debug.ctx_restore_mid_bb[class].len;
+ }
+ config_group_put(&dev->group);drivers/gpu/drm/xe/xe_configfs_debug.c +6
-0+ + return len; +} + +/** +* xe_configfs_get_ctx_restore_post_bb - get configfs
ctx_restore_post_bbsetting
+ * @pdev: pci device
+ * @class: hw engine class
+ * @cs: pointer to the bb to use - only valid during probe
+ *
+ * Return: Number of dwords used in thepost_ctx_restoresetting in configfs
+ */drivers/gpu/drm/xe/xe_configfs_debug.c +12
-0+u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, + enum xe_engine_class class, + const u32 **cs) +{ + struct xe_config_group_device *dev = find_device(pdev); + u32 len; + + if (!dev) + return 0; + + scoped_guard(mutex, &dev->lock) { + *cs = dev-Quoted 1 line
config.debug.ctx_restore_post_bb[class].cs;
+ len = dev-
Quoted 1 line
config.debug.ctx_restore_post_bb[class].len;
+ }
+ config_group_put(&dev->group);drivers/gpu/drm/xe/xe_configfs_debug.c +23
-0+ + return len; +} + +static bool wa_bb_read_advance (bool dereference,char **p, + const char *append, size_t len, + size_t *max_size) +{ + if (dereference) { + if (len >= *max_size) + return false; + *max_size -= len; + if (append) + memcpy(*p, append, len); + } + + *p += len; + + return true; +} + +static ssize_t wa_bb_show(struct xe_config_group_device *dev, + struct wa_bb wa_bb[static
XE_ENGINE_CLASS_MAX],
+ char *data,size_tsz)drivers/gpu/drm/xe/xe_configfs_debug.c +7
-0+{ + char *p = data; + + guard(mutex)(&dev->lock); + + for (size_t i = 0; i < ARRAY_SIZE(engine_info); i++) { + enum xe_engine_class ec =engine_info[i].engine_class;
+ size_t len;drivers/gpu/drm/xe/xe_configfs_debug.c +10
-0+ + if (!wa_bb[ec].len) + continue; + + len = snprintf(p, sz, "%s:", engine_info[i].cls); + if (!wa_bb_read_advance(data, &p, NULL, len, &sz)) + return -ENOBUFS; + + for (size_t j = 0; j < wa_bb[ec].len; j++) { + len = snprintf(p, sz, " %08x",wa_bb[ec].cs[j]);
+ if (!wa_bb_read_advance(data, &p, NULL, len, &sz))
+ return-ENOBUFS;
+ }drivers/gpu/drm/xe/xe_configfs_debug.c +16
-0+ + if (!wa_bb_read_advance(data, &p, "\n", 1, &sz)) + return -ENOBUFS; + } + + if (!wa_bb_read_advance(data, &p, "", 1, &sz)) + return -ENOBUFS; + + /* Reserve one more to match check for '\0' */ + if (!data) + p++; + + return p - data; +} + +static ssize_t ctx_restore_mid_bb_show(struct config_item *item,char *page)
+{
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
+
+ return wa_bb_show(dev, dev-Quoted 1 line
config.debug.ctx_restore_mid_bb, page,
SZ_4K);drivers/gpu/drm/xe/xe_configfs_debug.c +3
-0+} + +static ssize_t ctx_restore_post_bb_show(struct config_item *item,char *page)
+{
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
+
+ return wa_bb_show(dev, dev-Quoted 1 line
config.debug.ctx_restore_post_bb, page,
SZ_4K);drivers/gpu/drm/xe/xe_configfs_debug.c +35
-0+} + +static void wa_bb_append (struct wa_bb *wa_bb,u32 val) +{ + if (wa_bb->cs) + wa_bb->cs[wa_bb->len] = val; + + wa_bb->len++; +} + +static ssize_t parse_hex (const char *line,u32 *pval) +{ + char numstr[12]; + const char *p; + ssize_t numlen; + + p = line + strspn(line, " \t"); + if (!*p || *p == '\n') + return 0; + + numlen = strcspn(p, " \t\n"); + if (!numlen || numlen >= sizeof(numstr) - 1) + return -EINVAL; + + memcpy(numstr, p, numlen); + numstr[numlen] = '\0'; + p += numlen; + + if (kstrtou32(numstr, 16, pval)) + return -EINVAL; + + return p - line; +} + +static int parse_engine(const char *s, const char *end_chars, u64*mask,
+ const structengine_info**pinfo);drivers/gpu/drm/xe/xe_configfs_debug.c +13
-0+ +/* +* Parse lines with the format +* +* <engine-class> cmd <u32> <u32...> +* <engine-class> reg <u32_addr> <u32_val> +* +* and optionally save them in @wa_bb[i].cs is non-NULL. +* +* Return the number of dwords parsed. +*/ +static ssize_t parse_wa_bb_lines(const char *lines, + struct wa_bb wa_bb[static
XE_ENGINE_CLASS_MAX])drivers/gpu/drm/xe/xe_configfs_debug.c +31
-0+{ + ssize_t dwords = 0, ret; + const char *p; + + for (p = lines; *p; p++) { + const struct engine_info *info = NULL; + u32 val, val2; + + /* Also allow empty lines */ + p += strspn(p, " \t\n"); + if (!*p) + break; + + ret = parse_engine(p, " \t\n", NULL, &info); + if (ret < 0) + return ret; + + p += ret; + p += strspn(p, " \t"); + + if (str_has_prefix(p, "cmd")) { + for (p += strlen("cmd"); *p;) { + ret = parse_hex(p, &val); + if (ret < 0) + return -EINVAL; + if (!ret) + break; + + p += ret; + dwords++; + wa_bb_append(&wa_bb[info-Quoted 1 line
engine_class], val);+ }
+ } else if (str_has_prefix(p, "reg")) { + p +=strlen("reg");
+ ret =parse_hex(p, &val); + if (ret <= 0)
+ return-EINVAL;drivers/gpu/drm/xe/xe_configfs_debug.c +10
-0+ + p += ret; + ret = parse_hex(p, &val2); + if (ret <= 0) + return -EINVAL; + + p += ret; + dwords += 3; + wa_bb_append(&wa_bb[info->engine_class], + MI_LOAD_REGISTER_IMM |
MI_LRI_NUM_REGS(1));
+ wa_bb_append(&wa_bb[info->engine_class], val);
+ wa_bb_append(&wa_bb[info->engine_class], val2);
+ } else {
+ return-EINVAL;
+ }
+ }drivers/gpu/drm/xe/xe_configfs_debug.c +5
-0+ + return dwords; +} + +static ssize_t wa_bb_store(struct wa_bb wa_bb[static
XE_ENGINE_CLASS_MAX],
+ structxe_config_group_device*dev, + const char *page,size_tlen)drivers/gpu/drm/xe/xe_configfs_debug.c +18
-0+{ + /* tmp_wa_bb must match wa_bb's size */ + struct wa_bb tmp_wa_bb[XE_ENGINE_CLASS_MAX] = { }; + ssize_t count, class; + u32 *tmp; + + /* 1. Count dwords - wa_bb[i].cs is NULL for all classes */ + count = parse_wa_bb_lines(page, tmp_wa_bb); + if (count < 0) + return count; + + guard(mutex)(&dev->lock); + + if (xe_configfs_is_bound(dev)) + return -EBUSY; + + /* +* 2. Allocate a u32 array and set the pointers to the right positions
+ * according to the length of each class'wa_bb+ */
+ tmp =krealloc(wa_bb[0].cs, count * sizeof(u32), GFP_KERNEL);
+ if (!tmp)
+ return-ENOMEM;drivers/gpu/drm/xe/xe_configfs_debug.c +14
-0+ + if (!count) { + memset(wa_bb, 0, sizeof(tmp_wa_bb)); + return len; + } + + for (class = 0, count = 0; class < XE_ENGINE_CLASS_MAX; ++class) { + tmp_wa_bb[class].cs = tmp + count; + count += tmp_wa_bb[class].len; + tmp_wa_bb[class].len = 0; + } + + /* 3. Parse wa_bb lines again, this time saving the values*/
+ count =parse_wa_bb_lines(page, tmp_wa_bb); + if (count < 0) {
+ kfree(tmp);
+ memset(wa_bb, 0,sizeof(tmp_wa_bb)); + return count;
+ }drivers/gpu/drm/xe/xe_configfs_debug.c +8
-0+ + memcpy(wa_bb, tmp_wa_bb, sizeof(tmp_wa_bb)); + + return len; +} + +static ssize_t ctx_restore_mid_bb_store (struct config_item *item, + const char *data, size_tsz)
+{
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
+
+ returnwa_bb_store(dev->config.debug.ctx_restore_mid_bb, dev, data, sz);drivers/gpu/drm/xe/xe_configfs_debug.c +4
-0+} + +static ssize_t ctx_restore_post_bb_store (struct config_item *item, + const char *data, size_tsz)
+{
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
+
+ returnwa_bb_store(dev->config.debug.ctx_restore_post_bb, dev, data, sz);drivers/gpu/drm/xe/xe_configfs_debug.c +4
-0+} + +/** +* xe_configfs_get_engines_allowed - get engine allowed mask from configfs
+ * @pdev: pci device
+ *
+ * Return: engine mask with allowed engines set in configfs
+ */drivers/gpu/drm/xe/xe_configfs_debug.c +7
-0+u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) +{ + struct xe_config_group_device *dev = find_device(pdev); + u64 engines_allowed; + + if (!dev) + returnxe_configfs_device_defaults.debug.engines_allowed; +
+ scoped_guard(mutex,&dev->lock)
+ engines_allowed = dev-Quoted 1 line
config.debug.engines_allowed;
+ config_group_put(&dev->group);
drivers/gpu/drm/xe/xe_configfs_debug.c +5
-0+ + return engines_allowed; +} + +static ssize_t engines_allowed_show(struct config_item *item, char*page)
+{
+ structxe_config_device*dev =xe_configfs_subgroup_to_device(item);
+ char *p = page;drivers/gpu/drm/xe/xe_configfs_debug.c +6
-0+ + for (size_t i = 0; i < ARRAY_SIZE(engine_info); i++) { + u64 mask = engine_info[i].mask; + + if ((dev->debug.engines_allowed & mask) == mask) { + p += sprintf(p, "%s*\n",engine_info[i].cls);
+ } else if (mask &dev->debug.engines_allowed) { + u16 bit0 =__ffs64(mask), bit;drivers/gpu/drm/xe/xe_configfs_debug.c +4
-0+ + mask &= dev->debug.engines_allowed; + + for_each_set_bit(bit, (const unsigned long*)&mask, 64)
+ p += sprintf(p, "%s%u\n", engine_info[i].cls,
+ bit - bit0); + }
+ }drivers/gpu/drm/xe/xe_configfs_debug.c +6
-0+ + return p - page; +} + +/* +* Lookup engine_info. If @mask is not NULL, reduce the mask according to the
+ * instance in @pattern.
+ *
+ * Examples of inputs:
+ * -lookup_engine_info("rcs0", &mask): return "rcs" entry from @engine_info and
+ * mask ==BIT_ULL(XE_HW_ENGINE_RCS0)
+ * -lookup_engine_info("rcs*", &mask): return "rcs" entry from @engine_info and
+ * mask ==XE_HW_ENGINE_RCS_MASK
+ * -lookup_engine_info("rcs", NULL): return "rcs" entry from @engine_info
+ */
+static const structengine_info*lookup_engine_info(const char *pattern, u64 *mask)drivers/gpu/drm/xe/xe_configfs_debug.c +32
-0+{ + for (size_t i = 0; i < ARRAY_SIZE(engine_info); i++) { + u8 instance; + u16 bit; + + if (!str_has_prefix(pattern, engine_info[i].cls)) + continue; + + pattern += strlen(engine_info[i].cls); + if (!mask) + return *pattern ? NULL : &engine_info[i]; + + if (!strcmp(pattern, "*")) { + *mask = engine_info[i].mask; + return &engine_info[i]; + } + + if (kstrtou8(pattern, 10, &instance)) + return NULL; + + bit = __ffs64(engine_info[i].mask) + instance; + if (bit >= fls64(engine_info[i].mask)) + return NULL; + + *mask = BIT_ULL(bit); + return &engine_info[i]; + } + + return NULL; +} + +static int parse_engine(const char *s, const char *end_chars, u64*mask,
+ const structengine_info**pinfo)drivers/gpu/drm/xe/xe_configfs_debug.c +24
-0+{ + char buf[MAX_ENGINE_CLASS_CHARS + MAX_ENGINE_INSTANCE_CHARS + 1]; + const struct engine_info *info; + size_t len; + + len = strcspn(s, end_chars); + if (len >= sizeof(buf)) + return -EINVAL; + + memcpy(buf, s, len); + buf[len] = '\0'; + + info = lookup_engine_info(buf, mask); + if (!info) + return -ENOENT; + + if (pinfo) + *pinfo = info; + + return len; +} + +static ssize_t engines_allowed_store(struct config_item *item,const char *page,
+size_tlen)
+{
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
+ ssize_t patternlen, p;
+ u64 mask, val = 0;
+
+ for (p = 0; p < len; p += patternlen + 1) {
+ patternlen =parse_engine(page + p, ",\n", &mask, NULL);
+ if (patternlen < 0)
+ return-EINVAL;drivers/gpu/drm/xe/xe_configfs_debug.c +20
-0+ + val |= mask; + } + + guard(mutex)(&dev->lock); + if (xe_configfs_is_bound(dev)) + return -EBUSY; + + dev->config.debug.engines_allowed = val; + + return len; +} + +static u64 get_gt_types_allowed (struct pci_dev *pdev) +{ + struct xe_config_group_device *dev = find_device(pdev); + u64 mask; + + if (!dev) + returnxe_configfs_device_defaults.debug.gt_types_allowed;
drivers/gpu/drm/xe/xe_configfs_debug.c +10
-0+ + scoped_guard(mutex, &dev->lock) + mask = dev->config.debug.gt_types_allowed; + config_group_put(&dev->group); + + return mask; +} + +/** +* xe_configfs_primary_gt_allowed - determine whether primary GTs are supported
+ * @pdev: pci device
+ *
+ * Return: True if primary GTs are enabled, false if they have been disabled via
+ * configfs.
+ */drivers/gpu/drm/xe/xe_configfs_debug.c +3
-0+bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) +{ + return get_gt_types_allowed(pdev) &
BIT_ULL(XE_GT_TYPE_MAIN);drivers/gpu/drm/xe/xe_configfs_debug.c +4
-0+} + +/** +* xe_configfs_media_gt_allowed - determine whether media GTs are supported
+ * @pdev: pci device
+ *
+ * Return: True if the media GTs are enabled, false if they have been disabled
+ * via configfs.
+ */drivers/gpu/drm/xe/xe_configfs_debug.c +3
-0+bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) +{ + return get_gt_types_allowed(pdev) &
BIT_ULL(XE_GT_TYPE_MEDIA);drivers/gpu/drm/xe/xe_configfs_debug.c +3
-0+} + +static ssize_t gt_types_allowed_show(struct config_item *item,char *page)
+{
+ structxe_config_device*dev =xe_configfs_subgroup_to_device(item);
+ char *p = page;
+
+ for (size_ti = 0; i <ARRAY_SIZE(gt_types); i++) + if (dev->debug.gt_types_allowed&BIT_ULL(gt_types[i].type))
+ p +=sprintf(p, "%s\n", gt_types[i].name);drivers/gpu/drm/xe/xe_configfs_debug.c +5
-0+ + return p - page; +} + +static ssize_t gt_types_allowed_store(struct config_item *item,const char *page,
+size_tlen) +{
+ char *buf__free(kfree)=kstrdup(page, GFP_KERNEL); + structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
+ u64 typemask = 0;
+ char *p = buf;drivers/gpu/drm/xe/xe_configfs_debug.c +13
-0+ + if (!buf) + return -ENOMEM; + + while (p) { + char *typename = strsep(&p, ",\n"); + bool matched = false; + + if (typename[0] == '\0') + continue; + + for (size_t i = 0; i < ARRAY_SIZE(gt_types); i++) { + if (strcmp(typename, gt_types[i].name) ==0) {
+ typemask |=BIT(gt_types[i].type); + matched = true;
+ break;
+ }
+ }drivers/gpu/drm/xe/xe_configfs_debug.c +16
-0+ + if (!matched) + return -EINVAL; + } + + guard(mutex)(&dev->lock); + if (xe_configfs_is_bound(dev)) + return -EBUSY; + + dev->config.debug.gt_types_allowed = typemask; + + return len; +} + +/** +* xe_configfs_get_enable_multi_queue - get configfs
enable_multi_queuesetting
+ * @pdev: pci device
+ *
+ * Return: true if multi-queue is enabled for this device (the default),
+ * false if it has been force-disabled via configfs.
+ */drivers/gpu/drm/xe/xe_configfs_debug.c +7
-0+bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) +{ + struct xe_config_group_device *dev = find_device(pdev); + bool ret; + + if (!dev) + returnxe_configfs_device_defaults.debug.enable_multi_queue;
drivers/gpu/drm/xe/xe_configfs_debug.c +9
-0+ + scoped_guard(mutex, &dev->lock) + ret = dev->config.debug.enable_multi_queue; + config_group_put(&dev->group); + + return ret; +} + +static ssize_t enable_multi_queue_show(struct config_item *item,char *page)
+{
+ structxe_config_device*dev =xe_configfs_subgroup_to_device(item);
+
+ return sprintf(page, "%d\n", dev-Quoted 1 line
debug.enable_multi_queue);
drivers/gpu/drm/xe/xe_configfs_debug.c +3
-0+} + +static ssize_t enable_multi_queue_store(struct config_item *item,const char *page,
size_tlen)
+{
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
+ bool val;
+ int ret;drivers/gpu/drm/xe/xe_configfs_debug.c +36
-0+ + ret = kstrtobool(page, &val); + if (ret) + return ret; + + guard(mutex)(&dev->lock); + if (xe_configfs_is_bound(dev)) + return -EBUSY; + + dev->config.debug.enable_multi_queue = val; + + return len; +} + +/** +* xe_configfs_get_psmi_enabled - get configfs enable_psmi setting +* @pdev: pci device +* +* Return: enable_psmi setting in configfs +*/ +bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) +{ + struct xe_config_group_device *dev = find_device(pdev); + bool ret; + + if (!dev) + return false; + + scoped_guard(mutex, &dev->lock) + ret = dev->config.debug.enable_psmi; + config_group_put(&dev->group); + + return ret; +} + +static ssize_t enable_psmi_show(struct config_item *item, char*page)
+{
+ structxe_config_device*dev =xe_configfs_subgroup_to_device(item);drivers/gpu/drm/xe/xe_configfs_debug.c +5
-0+ + return sprintf(page, "%d\n", dev->debug.enable_psmi); +} + +static ssize_t enable_psmi_store(struct config_item *item, constchar *page,
size_tlen)
+{
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
+ bool val;
+ int ret;drivers/gpu/drm/xe/xe_configfs_debug.c +16
-0+ + ret = kstrtobool(page, &val); + if (ret) + return ret; + + guard(mutex)(&dev->lock); + if (xe_configfs_is_bound(dev)) + return -EBUSY; + + dev->config.debug.enable_psmi = val; + + return len; +} + +/** +* xe_configfs_get_survivability_mode - get configfs survivability mode attribute
+ * @pdev: pci device
+ *
+ * Return:survivability_modeattribute in configfs
+ */drivers/gpu/drm/xe/xe_configfs_debug.c +7
-0+bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) +{ + struct xe_config_group_device *dev = find_device(pdev); + bool mode; + + if (!dev) + returnxe_configfs_device_defaults.debug.survivability_mode;
drivers/gpu/drm/xe/xe_configfs_debug.c +9
-0+ + scoped_guard(mutex, &dev->lock) + mode = dev->config.debug.survivability_mode; + config_group_put(&dev->group); + + return mode; +} + +static ssize_t survivability_mode_show(struct config_item *item,char *page)
+{
+ structxe_config_device*dev =xe_configfs_subgroup_to_device(item);
+
+ return sprintf(page, "%d\n", dev-Quoted 1 line
debug.survivability_mode);
drivers/gpu/drm/xe/xe_configfs_debug.c +3
-0+} + +static ssize_t survivability_mode_store(struct config_item *item,const char *page,
size_tlen)
+{
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
+ boolsurvivability_mode;
+ int ret;drivers/gpu/drm/xe/xe_configfs_debug.c +38
-0+ + ret = kstrtobool(page, &survivability_mode); + if (ret) + return ret; + + guard(mutex)(&dev->lock); + if (xe_configfs_is_bound(dev)) + return -EBUSY; + + dev->config.debug.survivability_mode = survivability_mode; + + return len; +} + +CONFIGFS_ATTR(, ctx_restore_mid_bb); +CONFIGFS_ATTR(, ctx_restore_post_bb); +CONFIGFS_ATTR(, engines_allowed); +CONFIGFS_ATTR(, gt_types_allowed); +CONFIGFS_ATTR(, enable_multi_queue); +CONFIGFS_ATTR(, enable_psmi); +CONFIGFS_ATTR(, survivability_mode); + +static struct configfs_attribute *xe_configfs_debug_attrs[] = { + &attr_ctx_restore_mid_bb, + &attr_ctx_restore_post_bb, + &attr_engines_allowed, + &attr_gt_types_allowed, + &attr_enable_multi_queue, + &attr_enable_psmi, + &attr_survivability_mode, + NULL, +}; + +/* +* Per-parameter visibility predicates. +* +* XE_PARAM_VISIBLE_ALWAYS - attribute is always shown. +* XE_PARAM_VISIBLE_SURVIVABILITY - only shown on dGFX platforms Quoted 1 line
= Battlemage.
+ *
+ * These macros are only evaluated here, where the platform descriptor is
+ * reachable.xe_configfs_debug_params.htreats them as opaque tokens.
+ */drivers/gpu/drm/xe/xe_configfs_debug.c +4
-0+#define XE_PARAM_VISIBLE_ALWAYS (_item) \ + (true) +#define XE_PARAM_VISIBLE_SURVIVABILITY (_item) \ + (xe_configfs_subgroup_to_group_device(_item)->desc->is_dgfx&& \
+ xe_configfs_subgroup_to_group_device(_item)->desc-Quoted 1 line
platform >=
XE_BATTLEMAGE)drivers/gpu/drm/xe/xe_configfs_debug.c +3
-0+ +static bool xe_configfs_debug_is_visible (struct config_item *item, + struct configfs_attribute*attr, int n)
+{
+ if (attr ==&attr_survivability_mode) { + structxe_config_group_device*dev = + xe_configfs_to_group_device(item-Quoted 1 line
ci_parent);+
+ returndev->desc->is_dgfx&&dev->desc->platform>=XE_BATTLEMAGE;
+ }drivers/gpu/drm/xe/xe_configfs_debug.c +5
-0+ + return true; +} + +static struct configfs_group_operations
xe_configfs_debug_group_ops= {
+ .is_visible =xe_configfs_debug_is_visible, +};
const structconfig_item_typexe_configfs_debug_type= { + .ct_attrs =xe_configfs_debug_attrs, + .ct_group_ops =&xe_configfs_debug_group_ops, .ct_owner =THIS_MODULE,
};drivers/gpu/drm/xe/xe_configfs_debug.c +3
-0+ +/** +* xe_configfs_debug_release_config - release debug-specific config resources
+ * @config: xe config device structure
+ *
+ * Frees any memory allocated for debug configfs parameters.
+ */
+voidxe_configfs_debug_release_config(struct xe_config_device *config)drivers/gpu/drm/xe/xe_configfs_debug.c +4
-0+{ + kfree(config->debug.ctx_restore_mid_bb[0].cs); + kfree(config->debug.ctx_restore_post_bb[0].cs); +}drivers/gpu/drm/xe/xe_configfs_debug.h +0
-0@@ -5,9 +5,46 @@ #ifndef _XE_CONFIGFS_DEBUG_H_ #define _XE_CONFIGFS_DEBUG_H_drivers/gpu/drm/xe/xe_configfs_debug.h +7
-0+#include <linux/types.h> + +#include "xe_hw_engine_types.h" + +struct pci_dev ; +struct xe_config_device ; +#if
IS_ENABLED(CONFIG_DRM_XE_DEBUG)&&IS_ENABLED(CONFIG_CONFIGFS_FS)
-structconfig_item_type;
extern const structconfig_item_typexe_configfs_debug_type; +voidxe_configfs_debug_release_config(struct xe_config_device *config);drivers/gpu/drm/xe/xe_configfs_debug.h +15
-0+u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, + enum xe_engine_class class, + const u32 **cs); +u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, + enum xe_engine_class class, + const u32 **cs); +u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev); +bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev); +bool xe_configfs_media_gt_allowed (struct pci_dev *pdev); +bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev); +bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev); +bool xe_configfs_get_survivability_mode (struct pci_dev *pdev); +#else +/* +* Dummy values here are not used since these function accesses are always
+ * wrapped inCONFIG_DRM_XE_DEBUG.
+ */
+static inline voidxe_configfs_debug_release_config(struct xe_config_device *config){ }
+static inline u32 xe_configfs_get_ctx_restore_mid_bb(structpci_dev*pdev,
+ enumxe_engine_classclass,
+ const u32 **cs) { return 0; }
+static inline u32 xe_configfs_get_ctx_restore_post_bb(structpci_dev*pdev,
+ enumxe_engine_classclass,
+ const u32 **cs) { return 0; }
+static inline u64xe_configfs_get_engines_allowed(struct pci_dev *pdev){ returnU64_MAX; }
+static inline boolxe_configfs_primary_gt_allowed(struct pci_dev *pdev){ return true; }
+static inline boolxe_configfs_media_gt_allowed(struct pci_dev *pdev){ return true; }
+static inline boolxe_configfs_get_enable_multi_queue(struct pci_dev *pdev){ return true; }
+static inline boolxe_configfs_get_psmi_enabled(struct pci_dev *pdev){ return false; }
+static inline boolxe_configfs_get_survivability_mode(struct pci_dev *pdev){ return false; }
#endif
#endif /* _XE_CONFIGFS_DEBUG_H_ */drivers/gpu/drm/xe/xe_configfs_types.h +4
-7@@ -32,13 +32,17 @@ struct xe_config_group_device {* type, entries are sorted alphabetically. */ struct xe_config_device { - struct wa_bb ctx_restore_mid_bb[XE_ENGINE_CLASS_MAX]; - struct wa_bb ctx_restore_post_bb[XE_ENGINE_CLASS_MAX]; - u64 engines_allowed; - u64 gt_types_allowed; - bool enable_multi_queue; - bool enable_psmi; - bool survivability_mode; +#if IS_ENABLED(CONFIG_DRM_XE_DEBUG) + struct { + struct wa_bb ctx_restore_mid_bb[XE_ENGINE_CLASS_MAX]; + struct wa_bbctx_restore_post_bb[XE_ENGINE_CLASS_MAX];
+ u64engines_allowed;
+ u64gt_types_allowed;
+ boolenable_multi_queue;
+ boolenable_psmi;
+ boolsurvivability_mode;
+ } debug;
+#endif
struct {
unsigned intmax_vfs;
booladmin_only_pf;drivers/gpu/drm/xe/xe_guc.c +1
-0@@ -19,6 +19,7 @@ #include "regs/xe_irq_regs.h" #include "xe_bo.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_device.h" #include "xe_force_wake.h" #include "xe_gt.h"drivers/gpu/drm/xe/xe_guc_ads.c +1
-0@@ -17,6 +17,7 @@ #include "regs/xe_guc_regs.h" #include "xe_bo.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_gt.h" #include "xe_gt_ccs_mode.h" #include "xe_gt_mcr.h"drivers/gpu/drm/xe/xe_hw_engine.c +1
-0@@ -18,6 +18,7 @@ #include "xe_assert.h" #include "xe_bo.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_device.h" #include "xe_execlist.h" #include "xe_force_wake.h"drivers/gpu/drm/xe/xe_lrc.c +1
-0@@ -19,6 +19,7 @@ #include "xe_bb.h" #include "xe_bo.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_device.h" #include "xe_drm_client.h" #include "xe_exec_queue.h"drivers/gpu/drm/xe/xe_pci.c +1
-0@@ -19,6 +19,7 @@ #include "regs/xe_gt_regs.h" #include "regs/xe_regs.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_device.h" #include "xe_drv.h" #include "xe_gt.h"drivers/gpu/drm/xe/xe_psmi.c +1
-0@@ -8,6 +8,7 @@ #include "xe_bo.h" #include "xe_device_types.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_psmi.h"
/*drivers/gpu/drm/xe/xe_rtp.c +0
-0@@ -10,6 +10,7 @@ #include <uapi/drm/xe_drm.h>
#include "xe_configfs.h"
+#include "xe_configfs_debug.h"
#include "xe_device.h"
#include "xe_gt.h"
#include "xe_gt_topology.h"drivers/gpu/drm/xe/xe_survivability_mode.c +0
-0@@ -11,6 +11,7 @@ #include <linux/sysfs.h>
#include "xe_configfs.h"
+#include "xe_configfs_debug.h"
#include "xe_device.h"
#include "xe_heci_gsc.h"
#include "xe_i2c.h"Signature · 1 line
2.43.0
Rodrigo Vivi
maintainerRe: [PATCH 05/10] drm/xe: Move debug configfs entries to xe_configfs_debug.c
Quoted 295 lines · Stuart
Quoted 294 lines · Matt Roper
Quoted 263 lines · Stuart Summers
Move the debug specific configfs attributes into the new
xe_configfs_debug.cfile under a new debug configfs subdirectory. Ensure these are wrapped inCONFIG_DRM_XE_DEBUGto allow finer grained
debug changes outside of more ABI specific configfs entries.Signed-off-by Stuart Summers <[email protected]>Assisted-by Copilot:claude-sonnet-4.6,claude-sonnet-5,claude-opus-5
---
drivers/gpu/drm/xe/xe_configfs.c | 991 ++---------------
----
drivers/gpu/drm/xe/xe_configfs.h | 88 +- drivers/gpu/drm/xe/xe_configfs_debug.c | 956
++++++++++++++++++++
drivers/gpu/drm/xe/xe_configfs_debug.h | 39 +- drivers/gpu/drm/xe/xe_configfs_types.h | 18 +- drivers/gpu/drm/xe/xe_guc.c | 1 + drivers/gpu/drm/xe/xe_guc_ads.c | 1 + drivers/gpu/drm/xe/xe_hw_engine.c | 1 + drivers/gpu/drm/xe/xe_lrc.c | 1 + drivers/gpu/drm/xe/xe_pci.c | 1 + drivers/gpu/drm/xe/xe_psmi.c | 1 + drivers/gpu/drm/xe/xe_rtp.c | 1 +drivers/gpu/drm/xe/xe_survivability_mode.c| 1 +13 files changed, 1134 insertions(+), 966 deletions(-)drivers/gpu/drm/xe/xe_configfs.c +0
-1@@ -6,17 +6,14 @@ #include <linux/bitops.h> #include <linux/configfs.h> #include <linux/cleanup.h> -#include <linux/find.h> #include <linux/init.h> #include <linux/module.h> #include <linux/pci.h> #include <linux/string.h>
-#include "instructions/xe_mi_commands.h"
#include "xe_configfs.h"
#include "xe_configfs_debug.h"
#include "xe_defaults.h"
-#include "xe_gt_types.h"
#include "xe_module.h"
/**drivers/gpu/drm/xe/xe_configfs.c +3
-10@@ -50,16 +47,9 @@ * * /sys/kernel/config/xe/ * ├── 0000:00:02.0 - * │ └── ... - * ├── 0000:00:02.1 - * │ └── ... - * : - * └── 0000:03:00.0 - * ├── engines_allowed - * ├── gt_types_allowed - * ├── enable_multi_queue - * ├── enable_psmi - * └── survivability_mode + * │ └── ... + * └── 0000:00:02.1 + * └── ... * * After configuring the attributes as per next section, thedevice can be
* probed with::drivers/gpu/drm/xe/xe_configfs.c +0
-5@@ -71,157 +61,6 @@ * Configure Attributes * ==================== * - - * Context restore BB - * ------------------ - * - * Allow to execute a batch buffer during any context switches.When the
- * GPU is restoring the context, it executes additional commands. It's useful
- * for testing additional workarounds and validating certain HW
behaviors: it's
- * not intended for normal execution and will taint the kernel withTAINT_TEST
- * when used.
- *
- * The syntax allows to pass straight instructions to be executed by the engine
- * in a batch buffer or set specific registers.
- *
- * #. Generic instruction::
- *
- * <engine-class> cmd <instr> [[dword0] [dword1] [...]]
- *
- * #. Simple register setting::
- *
- * <engine-class> reg <address> <value>
- *
- * Commands are saved per engine class: all instances of that class will execute
- * those commands during context switch. The instruction, dword arguments,
- * addresses and values are in hex format like in the examples below.
- *
- * #. Execute a LRI command to write0xDEADBEEFto register0x4f10after the
- * normal context restore::
- *
- * # echo 'rcs cmd 11000001 4F100 DEADBEEF' \
- * > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_post_bb
- *
- * #. Execute a LRI command to write0xDEADBEEFto register0x4f10at the
- * beginning of the context restore::
- *
- * # echo 'rcs cmd 11000001 4F100 DEADBEEF' \
- * > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_mid_bb
-
- * #. Load certain values in a couple of registers (it can be used as a simpler
- * alternative to thecmd) action::
- *
- * # cat > /sys/kernel/config/xe/0000:03:00.0/ctx_restore_post_bb <<EOF
- * rcs reg 4F100 DEADBEEF
- * rcs reg 4F104 FFFFFFFF
- * EOF
- *
- * .. note::
- *
- * When using multiple lines, make sure to use a command that is
- * implemented with a single write syscall, like HEREDOC.
- *
- * Currently this is implemented only for post and mid context restore and
- * these attributes can only be set before binding to the device.
- *
- * Allowed engines:
- * ----------------
- *
- * Allow only a set of engine(s) to be available, disabling the other engines
- * even if they are available in hardware. This is applied after HW fuses are
- * considered on each tile. Examples:
- *
- * Allow only one render and one copy engines, nothing else::
- *
- * # echo 'rcs0,bcs0' > /sys/kernel/config/xe/0000:03:00.0/engines_allowed
- *
- * Allow only compute engines and first copy engine::
- *
- * # echo 'ccs*,bcs0' > /sys/kernel/config/xe/0000:03:00.0/engines_allowed
- *
- * Note that the engine names are the per-GT hardware names. On multi-tile
- * platforms, writing ``rcs0,bcs0`` to this file would allow the first render
- * and copy engines on each tile.
- *
- * The requested configuration may not be supported by the platform and driver
- * may fail to probe. For example: if at least one copy engine is expected to be
- * available for migrations, but it's disabled. This is intended for debugging
- * purposes only.
- *
- * This attribute can only be set before binding to the device.
- *
- * Allowed GT types:
- * -----------------
- *
- * Allow only specific types of GTs to be detected and initialized by the
- * driver. Any combination of GT types can be enabled/disabled, although
- * some settings will cause the device to fail to probe.
- *
- * Writes support both comma- and newline-separated input format. Reads
- * will always return one GT type per line. "primary" and "media" are the
- * GT type names supported by this interface.
- *
- * This attribute can only be set before binding to the device.
- *
- * Examples:
- *
- * Allow both primary and media GTs to be initialized and used. This matches
- * the driver's default behavior::
- *
- * # echo 'primary,media' > /sys/kernel/config/xe/0000:03:00.0/gt_types_allowed
- *
- * Allow only the primary GT of each tile to be initialized and used,
- * effectively disabling the media GT if it exists on the platform::
- *
- * # echo 'primary' > /sys/kernel/config/xe/0000:03:00.0/gt_types_allowed
- *
- * Allow only the media GT of each tile to be initialized and used,
- * effectively disabling the primary GT. **This configuration will cause
- * device probe failure on all current platforms, but may be allowed on
- * igpu platforms in the future**::
- *
- * # echo 'media' > /sys/kernel/config/xe/0000:03:00.0/gt_types_allowed
- *
- * Disable all GTs. Only other GPU IP (such as display) is potentially usable.
- * **This configuration will cause device probe failure on all current
- * platforms, but may be allowed on igpu platforms in the future**::
- *
- * # echo '' > /sys/kernel/config/xe/0000:03:00.0/gt_types_allowed
- *
- * Enable multi-queue
- * ------------------
- *
- * Multi-queue support on the device is enabled by default where the
- * hardware supports it. Writing 0 force-disables multi-queue support:
- * multi-queue exec-queue group creation via ioctl is refused, and the
- * GuC feature is disabled::
- *
- * # echo 0 > /sys/kernel/config/xe/0000:03:00.0/enable_multi_queue
- *
- * This attribute can only be set before binding to the device.
- *
- * PSMI
- * ----
- *
- * Enable extra debugging capabilities to trace engine execution. Only useful
- * during early platform enabling and requires additional hardware connected.
- * Once it's enabled, additionals WAs are added and runtime configuration is
- * done via debugfs. Example to enable it::
- *
- * # echo 1 > /sys/kernel/config/xe/0000:03:00.0/enable_psmi
- *Quoted 8 lines
- * This attribute can only be set before binding to the device.
- *
- * Survivability mode:
- * -------------------
- *
- * Enable survivability mode on supported cards. This setting only takes
- * effect when probing the device. Example to enable it::I didn't review the code movement in this patch in depth, but the one thing that I'm uncertain about is whether survivability mode should have
been swept up in this move. My understanding is that unlike the other
options which are meant for developers hacking on the driver, configurable survivability mode is a true production feature intended for end users to get the minimal driver support necessary to deal with a
bad firmware flash, failing hardware, etc. I know there are cases where
the driver can auto-detect the need to enter survivability mode without
the configfs interface (i.e., various RAS error reports and such), but I
thought manual entry through configfs was still something users may need
in some cases? If so that would mean we should keep this available even
when the debug options aren't compiled in.
Quoted 6 lines
Quoted 1 line
+Cc Riana in case my understanding is off.
Yeah would appreciate feedback there Riana. My understanding of survivability mode is we want this to allow us to continue operation for a while to debug issues when the hardware is severely misbehaving. This isn't a normal customer use case.
I'm not Riana, but I can answer to this! :)
Survivability is needed in final production builds.
We had cases in the field where any kind of probe (succeeded, failed, not-attempted) would put the device in a state where FW could not be flashed.
So this fallback option where user selects survivability and get a minimal probe where FW can be flashed is needed.
Also, another possible usage of this is around upcoming in-field test and in field repair cases.
So, survivability is one... But also I'm thinking about others as well in here. PSMI for instance, are we sure that PSMI folks don't plug PSMI in production builds at all when debugging some images that they cannot control?
Quoted 2,620 lines
My thought longer term here is we'd turn this into a bit map that allowed various hardware or software isolation configurations. We'll also have the per-feature configfs entries, but the survivability mode could be used to easily isolate based on a higher level isolation scheme that doesn't require the person debugging to fully understand all the different underlying features being disabled if that makes sense.
The flip side of this could be that we really want to require users to be more surgical about how they enable/disable different features. In that case, I'd argue we really should drop survivability mode completely and turn it into an "
enable_punit" and various other related configurations.Thanks,
StuartQuoted 2,601 lines
Matt
Quoted 2,596 lines
- *
- * # echo 1 > /sys/kernel/config/xe/0000:03:00.0/survivability_mode
- *
- * This attribute can only be set before binding to the device.
- *
* Max SR-IOV Virtual Functions
* ----------------------------
*drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -256,12 +95,16 @@* # rmdir /sys/kernel/config/xe/0000:03:00.0/ */ drivers/gpu/drm/xe/xe_configfs.c +10
-6-static const struct xe_config_device device_defaults = { - .engines_allowed = U64_MAX, - .gt_types_allowed = U64_MAX, - .enable_multi_queue = true, - .enable_psmi = false, - .survivability_mode = false, +const struct xe_config_device xe_configfs_device_defaults = { +#if IS_ENABLED(CONFIG_DRM_XE_DEBUG) + .debug = { + .engines_allowed = U64_MAX, + .gt_types_allowed = U64_MAX, + .enable_multi_queue = true, + .enable_psmi = false, + .survivability_mode = false, + }, +#endif.sriov = {
.max_vfs =XE_DEFAULT_MAX_VFS, .admin_only_pf =XE_DEFAULT_ADMIN_ONLY_PF,drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -270,50 +113,22 @@ static const struct xe_config_device device_defaults = {
static voidset_device_defaults(struct xe_config_device *config){
- *config =device_defaults;
+ *config =xe_configfs_device_defaults;
#ifdefCONFIG_PCI_IOV
config->sriov.max_vfs = xe_modparam.max_vfs; #endif
}drivers/gpu/drm/xe/xe_configfs.c +0
-7-struct engine_info { - const char *cls; - u64 mask; - enum xe_engine_class engine_class; -}; - -/* Some helpful macros to aid on the sizing of buffer allocation when parsing */
drivers/gpu/drm/xe/xe_configfs.c +0
-5-#define MAX_ENGINE_CLASS_CHARS 5 -#define MAX_ENGINE_INSTANCE_CHARS 2 - -static const struct engine_info engine_info[] = { - { .cls = "rcs", .mask = XE_HW_ENGINE_RCS_MASK,.engine_class =
XE_ENGINE_CLASS_RENDER},
- { .cls = "bcs", .mask =XE_HW_ENGINE_BCS_MASK, .engine_class =XE_ENGINE_CLASS_COPY},
- { .cls = "vcs", .mask =XE_HW_ENGINE_VCS_MASK, .engine_class =XE_ENGINE_CLASS_VIDEO_DECODE},
- { .cls = "vecs", .mask =XE_HW_ENGINE_VECS_MASK, .engine_class =XE_ENGINE_CLASS_VIDEO_ENHANCE}, - { .cls = "ccs", .mask =XE_HW_ENGINE_CCS_MASK, .engine_class =XE_ENGINE_CLASS_COMPUTE},
- { .cls = "gsccs", .mask =XE_HW_ENGINE_GSCCS_MASK, .engine_class =XE_ENGINE_CLASS_OTHER},drivers/gpu/drm/xe/xe_configfs.c +0
-11-}; - -static const struct { - const char *name; - enum xe_gt_type type; -} gt_types[] = { - { .name = "primary", .type = XE_GT_TYPE_MAIN }, - { .name = "media", .type = XE_GT_TYPE_MEDIA }, -}; - -static struct xe_config_group_device*to_xe_config_group_device(struct
config_item*item) -{
- returncontainer_of(to_config_group(item), struct xe_config_group_device, group);drivers/gpu/drm/xe/xe_configfs.c +0
-3-} - -static struct xe_config_device *to_xe_config_device(struct
config_item*item)drivers/gpu/drm/xe/xe_configfs.c +2
-5-{ - return &to_xe_config_group_device(item)->config; -} - -static bool is_bound (struct xe_config_group_device *dev) +/** +* xe_configfs_is_bound - check whether the matching pci device is bound
+ * @dev: configfs group device
+ *
+ * Caller must hold @dev->lock.
+ *
+ * Return: true if the matchingpci_devis already bound to a driver,
+ * false otherwise.
+ */
+boolxe_configfs_is_bound(struct xe_config_group_device *dev){
unsigned int domain, bus, slot, function; structpci_dev*pdev;drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -338,698 +153,13 @@ static bool is_bound(struct xe_config_group_device *dev) return ret; }
-static structxe_config_group_device*find_xe_config_group_device(structpci_dev*pdev);drivers/gpu/drm/xe/xe_configfs.c +0
-3- -/** -* xe_configfs_get_ctx_restore_mid_bb - get configfs
ctx_restore_mid_bbsetting
- * @pdev: pci device
- * @class: hw engine class
- * @cs: pointer to the bb to use - only valid during probe
- *
- * Return: Number of dwords used in themid_ctx_restoresetting in configfs
- */drivers/gpu/drm/xe/xe_configfs.c +0
-5-u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, - enum xe_engine_class class, - const u32 **cs) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- u32 len;drivers/gpu/drm/xe/xe_configfs.c +0
-7- - if (!dev) - return 0; - - scoped_guard(mutex, &dev->lock) { - if (cs) - *cs = dev-Quoted 1 line
config.ctx_restore_mid_bb[class].cs;
drivers/gpu/drm/xe/xe_configfs.c +0
-10- - len = dev->config.ctx_restore_mid_bb[class].len; - } - config_group_put(&dev->group); - - return len; -} - -/** -* xe_configfs_get_ctx_restore_post_bb - get configfs
ctx_restore_post_bbsetting
- * @pdev: pci device
- * @class: hw engine class
- * @cs: pointer to the bb to use - only valid during probe
- *
- * Return: Number of dwords used in thepost_ctx_restoresetting in configfs
- */drivers/gpu/drm/xe/xe_configfs.c +0
-5-u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, - enum xe_engine_class class, - const u32 **cs) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- u32 len;drivers/gpu/drm/xe/xe_configfs.c +0
-32- - if (!dev) - return 0; - - scoped_guard(mutex, &dev->lock) { - *cs = dev->config.ctx_restore_post_bb[class].cs; - len = dev->config.ctx_restore_post_bb[class].len; - } - config_group_put(&dev->group); - - return len; -} - -static bool wa_bb_read_advance (bool dereference,char **p, - const char *append, size_t len, - size_t *max_size) -{ - if (dereference) { - if (len >= *max_size) - return false; - *max_size -= len; - if (append) - memcpy(*p, append, len); - } - - *p += len; - - return true; -} - -static ssize_t wa_bb_show(struct xe_config_group_device *dev, - struct wa_bb wa_bb[static
XE_ENGINE_CLASS_MAX],
- char *data,size_tsz)drivers/gpu/drm/xe/xe_configfs.c +0
-7-{ - char *p = data; - - guard(mutex)(&dev->lock); - - for (size_t i = 0; i < ARRAY_SIZE(engine_info); i++) { - enum xe_engine_class ec =engine_info[i].engine_class;
- size_t len;drivers/gpu/drm/xe/xe_configfs.c +0
-10- - if (!wa_bb[ec].len) - continue; - - len = snprintf(p, sz, "%s:", engine_info[i].cls); - if (!wa_bb_read_advance(data, &p, NULL, len, &sz)) - return -ENOBUFS; - - for (size_t j = 0; j < wa_bb[ec].len; j++) { - len = snprintf(p, sz, " %08x",wa_bb[ec].cs[j]);
- if (!wa_bb_read_advance(data, &p, NULL, len, &sz))
- return-ENOBUFS;
- }drivers/gpu/drm/xe/xe_configfs.c +0
-16- - if (!wa_bb_read_advance(data, &p, "\n", 1, &sz)) - return -ENOBUFS; - } - - if (!wa_bb_read_advance(data, &p, "", 1, &sz)) - return -ENOBUFS; - - /* Reserve one more to match check for '\0' */ - if (!data) - p++; - - return p - data; -} - -static ssize_t ctx_restore_mid_bb_show(struct config_item *item,char *page)
-{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
-
- returnwa_bb_show(dev, dev->config.ctx_restore_mid_bb, page, SZ_4K);drivers/gpu/drm/xe/xe_configfs.c +0
-3-} - -static ssize_t ctx_restore_post_bb_show(struct config_item *item,char *page)
-{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
-
- returnwa_bb_show(dev, dev->config.ctx_restore_post_bb, page, SZ_4K);drivers/gpu/drm/xe/xe_configfs.c +0
-35-} - -static void wa_bb_append (struct wa_bb *wa_bb,u32 val) -{ - if (wa_bb->cs) - wa_bb->cs[wa_bb->len] = val; - - wa_bb->len++; -} - -static ssize_t parse_hex (const char *line,u32 *pval) -{ - char numstr[12]; - const char *p; - ssize_t numlen; - - p = line + strspn(line, " \t"); - if (!*p || *p == '\n') - return 0; - - numlen = strcspn(p, " \t\n"); - if (!numlen || numlen >= sizeof(numstr) - 1) - return -EINVAL; - - memcpy(numstr, p, numlen); - numstr[numlen] = '\0'; - p += numlen; - - if (kstrtou32(numstr, 16, pval)) - return -EINVAL; - - return p - line; -} - -static int parse_engine(const char *s, const char *end_chars, u64*mask,
- const structengine_info**pinfo);drivers/gpu/drm/xe/xe_configfs.c +0
-13- -/* -* Parse lines with the format -* -* <engine-class> cmd <u32> <u32...> -* <engine-class> reg <u32_addr> <u32_val> -* -* and optionally save them in @wa_bb[i].cs is non-NULL. -* -* Return the number of dwords parsed. -*/ -static ssize_t parse_wa_bb_lines(const char *lines, - struct wa_bb wa_bb[static
XE_ENGINE_CLASS_MAX])drivers/gpu/drm/xe/xe_configfs.c +0
-31-{ - ssize_t dwords = 0, ret; - const char *p; - - for (p = lines; *p; p++) { - const struct engine_info *info = NULL; - u32 val, val2; - - /* Also allow empty lines */ - p += strspn(p, " \t\n"); - if (!*p) - break; - - ret = parse_engine(p, " \t\n", NULL, &info); - if (ret < 0) - return ret; - - p += ret; - p += strspn(p, " \t"); - - if (str_has_prefix(p, "cmd")) { - for (p += strlen("cmd"); *p;) { - ret = parse_hex(p, &val); - if (ret < 0) - return -EINVAL; - if (!ret) - break; - - p += ret; - dwords++; - wa_bb_append(&wa_bb[info-Quoted 1 line
engine_class], val);- }
- } else if (str_has_prefix(p, "reg")) { - p +=strlen("reg");
- ret =parse_hex(p, &val); - if (ret <= 0)
- return-EINVAL;drivers/gpu/drm/xe/xe_configfs.c +0
-10- - p += ret; - ret = parse_hex(p, &val2); - if (ret <= 0) - return -EINVAL; - - p += ret; - dwords += 3; - wa_bb_append(&wa_bb[info->engine_class], - MI_LOAD_REGISTER_IMM |
MI_LRI_NUM_REGS(1));
- wa_bb_append(&wa_bb[info->engine_class], val);
- wa_bb_append(&wa_bb[info->engine_class], val2);
- } else {
- return-EINVAL;
- }
- }drivers/gpu/drm/xe/xe_configfs.c +0
-5- - return dwords; -} - -static ssize_t wa_bb_store(struct wa_bb wa_bb[static
XE_ENGINE_CLASS_MAX],
- structxe_config_group_device*dev, - const char *page,size_tlen)drivers/gpu/drm/xe/xe_configfs.c +0
-18-{ - /* tmp_wa_bb must match wa_bb's size */ - struct wa_bb tmp_wa_bb[XE_ENGINE_CLASS_MAX] = { }; - ssize_t count, class; - u32 *tmp; - - /* 1. Count dwords - wa_bb[i].cs is NULL for all classes */ - count = parse_wa_bb_lines(page, tmp_wa_bb); - if (count < 0) - return count; - - guard(mutex)(&dev->lock); - - if (is_bound(dev)) - return -EBUSY; - - /* -* 2. Allocate a u32 array and set the pointers to the right positions
- * according to the length of each class'wa_bb- */
- tmp =krealloc(wa_bb[0].cs, count * sizeof(u32), GFP_KERNEL);
- if (!tmp)
- return-ENOMEM;drivers/gpu/drm/xe/xe_configfs.c +1
-13- - if (!count) { - memset(wa_bb, 0, sizeof(tmp_wa_bb)); - return len; - } - - for (class = 0, count = 0; class < XE_ENGINE_CLASS_MAX; ++class) { - tmp_wa_bb[class].cs = tmp + count; - count += tmp_wa_bb[class].len; - tmp_wa_bb[class].len = 0; - } - - /* 3. Parse wa_bb lines again, this time saving the values*/
- count =parse_wa_bb_lines(page, tmp_wa_bb); - if (count < 0)
- return count;drivers/gpu/drm/xe/xe_configfs.c +0
-8- - memcpy(wa_bb, tmp_wa_bb, sizeof(tmp_wa_bb)); - - return len; -} - -static ssize_t ctx_restore_mid_bb_store (struct config_item *item, - const char *data, size_tsz)
-{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
-
- returnwa_bb_store(dev->config.ctx_restore_mid_bb, dev, data, sz);drivers/gpu/drm/xe/xe_configfs.c +0
-4-} - -static ssize_t ctx_restore_post_bb_store (struct config_item *item, - const char *data, size_tsz)
-{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
-
- returnwa_bb_store(dev->config.ctx_restore_post_bb, dev, data, sz);drivers/gpu/drm/xe/xe_configfs.c +0
-4-} - -/** -* xe_configfs_get_engines_allowed - get engine allowed mask from configfs
- * @pdev: pci device
- *
- * Return: engine mask with allowed engines set in configfs
- */drivers/gpu/drm/xe/xe_configfs.c +0
-3-u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- u64engines_allowed;drivers/gpu/drm/xe/xe_configfs.c +0
-12- - if (!dev) - return device_defaults.engines_allowed; - - scoped_guard(mutex, &dev->lock) - engines_allowed = dev->config.engines_allowed; - config_group_put(&dev->group); - - return engines_allowed; -} - -static ssize_t engines_allowed_show(struct config_item *item, char*page)
drivers/gpu/drm/xe/xe_configfs.c +0
-9-{ - struct xe_config_device *dev = to_xe_config_device(item); - char *p = page; - - for (size_t i = 0; i < ARRAY_SIZE(engine_info); i++) { - u64 mask = engine_info[i].mask; - - if ((dev->engines_allowed & mask) == mask) { - p += sprintf(p, "%s*\n",engine_info[i].cls);
- } else if (mask &dev->engines_allowed) { - u16 bit0 =__ffs64(mask), bit;drivers/gpu/drm/xe/xe_configfs.c +0
-4- - mask &= dev->engines_allowed; - - for_each_set_bit(bit, (const unsigned long*)&mask, 64)
- p += sprintf(p, "%s%u\n", engine_info[i].cls,
- bit - bit0); - }
- }drivers/gpu/drm/xe/xe_configfs.c +0
-6- - return p - page; -} - -/* -* Lookup engine_info. If @mask is not NULL, reduce the mask according to the
- * instance in @pattern.
- *
- * Examples of inputs:
- * -lookup_engine_info("rcs0", &mask): return "rcs" entry from @engine_info and
- * mask ==BIT_ULL(XE_HW_ENGINE_RCS0)
- * -lookup_engine_info("rcs*", &mask): return "rcs" entry from @engine_info and
- * mask ==XE_HW_ENGINE_RCS_MASK
- * -lookup_engine_info("rcs", NULL): return "rcs" entry from @engine_info
- */
-static const structengine_info*lookup_engine_info(const char *pattern, u64 *mask)drivers/gpu/drm/xe/xe_configfs.c +0
-32-{ - for (size_t i = 0; i < ARRAY_SIZE(engine_info); i++) { - u8 instance; - u16 bit; - - if (!str_has_prefix(pattern, engine_info[i].cls)) - continue; - - pattern += strlen(engine_info[i].cls); - if (!mask) - return *pattern ? NULL : &engine_info[i]; - - if (!strcmp(pattern, "*")) { - *mask = engine_info[i].mask; - return &engine_info[i]; - } - - if (kstrtou8(pattern, 10, &instance)) - return NULL; - - bit = __ffs64(engine_info[i].mask) + instance; - if (bit >= fls64(engine_info[i].mask)) - return NULL; - - *mask = BIT_ULL(bit); - return &engine_info[i]; - } - - return NULL; -} - -static int parse_engine(const char *s, const char *end_chars, u64*mask,
- const structengine_info**pinfo)drivers/gpu/drm/xe/xe_configfs.c +1
-23-{ - char buf[MAX_ENGINE_CLASS_CHARS + MAX_ENGINE_INSTANCE_CHARS + 1]; - const struct engine_info *info; - size_t len; - - len = strcspn(s, end_chars); - if (len >= sizeof(buf)) - return -EINVAL; - - memcpy(buf, s, len); - buf[len] = '\0'; - - info = lookup_engine_info(buf, mask); - if (!info) - return -ENOENT; - - if (pinfo) - *pinfo = info; - - return len; -} - -static ssize_t engines_allowed_store(struct config_item *item,const char *page,
-size_tlen)
-{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
- ssize_t patternlen, p;
- u64 mask, val = 0;
-
- for (p = 0; p < len; p += patternlen + 1) {
- patternlen =parse_engine(page + p, ",\n", &mask, NULL);
- if (patternlen < 0)
- return-EINVAL;drivers/gpu/drm/xe/xe_configfs.c +0
-16- - val |= mask; - } - - guard(mutex)(&dev->lock); - if (is_bound(dev)) - return -EBUSY; - - dev->config.engines_allowed = val; - - return len; -} - -static u64 get_gt_types_allowed (struct pci_dev *pdev) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- u64 mask;drivers/gpu/drm/xe/xe_configfs.c +0
-13- - if (!dev) - return device_defaults.gt_types_allowed; - - scoped_guard(mutex, &dev->lock) - mask = dev->config.gt_types_allowed; - config_group_put(&dev->group); - - return mask; -} - -/** -* xe_configfs_primary_gt_allowed - determine whether primary GTs are supported
- * @pdev: pci device
- *
- * Return: True if primary GTs are enabled, false if they have been disabled via
- * configfs.
- */drivers/gpu/drm/xe/xe_configfs.c +0
-3-bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) -{ - return get_gt_types_allowed(pdev) &
BIT_ULL(XE_GT_TYPE_MAIN);drivers/gpu/drm/xe/xe_configfs.c +0
-4-} - -/** -* xe_configfs_media_gt_allowed - determine whether media GTs are supported
- * @pdev: pci device
- *
- * Return: True if the media GTs are enabled, false if they have been disabled
- * via configfs.
- */drivers/gpu/drm/xe/xe_configfs.c +0
-3-bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) -{ - return get_gt_types_allowed(pdev) &
BIT_ULL(XE_GT_TYPE_MEDIA);drivers/gpu/drm/xe/xe_configfs.c +0
-3-} - -static ssize_t gt_types_allowed_show(struct config_item *item,char *page)
drivers/gpu/drm/xe/xe_configfs.c +0
-6-{ - struct xe_config_device *dev = to_xe_config_device(item); - char *p = page; - - for (size_t i = 0; i < ARRAY_SIZE(gt_types); i++) - if (dev->gt_types_allowed &
BIT_ULL(gt_types[i].type))
- p +=sprintf(p, "%s\n", gt_types[i].name);drivers/gpu/drm/xe/xe_configfs.c +0
-5- - return p - page; -} - -static ssize_t gt_types_allowed_store(struct config_item *item,const char *page,
-size_tlen) -{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
- char *buf__free(kfree)=kstrdup(page, GFP_KERNEL); - char *p = buf;
- u64 typemask = 0;drivers/gpu/drm/xe/xe_configfs.c +0
-13- - if (!buf) - return -ENOMEM; - - while (p) { - char *typename = strsep(&p, ",\n"); - bool matched = false; - - if (typename[0] == '\0') - continue; - - for (size_t i = 0; i < ARRAY_SIZE(gt_types); i++) { - if (strcmp(typename, gt_types[i].name) ==0) {
- typemask |=BIT(gt_types[i].type); - matched = true;
- break;
- }
- }drivers/gpu/drm/xe/xe_configfs.c +0
-16- - if (!matched) - return -EINVAL; - } - - guard(mutex)(&dev->lock); - if (is_bound(dev)) - return -EBUSY; - - dev->config.gt_types_allowed = typemask; - - return len; -} - -/** -* xe_configfs_get_enable_multi_queue - get configfs
enable_multi_queuesetting
- * @pdev: pci device
- *
- * Return: true if multi-queue is enabled for this device (the default),
- * false if it has been force-disabled via configfs.
- */drivers/gpu/drm/xe/xe_configfs.c +0
-3-bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- bool ret;drivers/gpu/drm/xe/xe_configfs.c +0
-12- - if (!dev) - return true; - - scoped_guard(mutex, &dev->lock) - ret = dev->config.enable_multi_queue; - config_group_put(&dev->group); - - return ret; -} - -static ssize_t enable_multi_queue_show(struct config_item *item,char *page)
drivers/gpu/drm/xe/xe_configfs.c +0
-7-{ - struct xe_config_device *dev = to_xe_config_device(item); - - return sprintf(page, "%d\n", dev->enable_multi_queue); -} - -static ssize_t enable_multi_queue_store(struct config_item *item,const char *page,
- size_t len) -{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
- bool val;
- int ret;drivers/gpu/drm/xe/xe_configfs.c +0
-23- - ret = kstrtobool(page, &val); - if (ret) - return ret; - - guard(mutex)(&dev->lock); - if (is_bound(dev)) - return -EBUSY; - - dev->config.enable_multi_queue = val; - - return len; -} - -/** -* xe_configfs_get_psmi_enabled - get configfs enable_psmi setting -* @pdev: pci device -* -* Return: enable_psmi setting in configfs -*/ -bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- bool ret;drivers/gpu/drm/xe/xe_configfs.c +0
-12- - if (!dev) - return false; - - scoped_guard(mutex, &dev->lock) - ret = dev->config.enable_psmi; - config_group_put(&dev->group); - - return ret; -} - -static ssize_t enable_psmi_show(struct config_item *item, char*page)
drivers/gpu/drm/xe/xe_configfs.c +0
-7-{ - struct xe_config_device *dev = to_xe_config_device(item); - - return sprintf(page, "%d\n", dev->enable_psmi); -} - -static ssize_t enable_psmi_store(struct config_item *item, constchar *page,
size_tlen)
-{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
- bool val;
- int ret;drivers/gpu/drm/xe/xe_configfs.c +0
-16- - ret = kstrtobool(page, &val); - if (ret) - return ret; - - guard(mutex)(&dev->lock); - if (is_bound(dev)) - return -EBUSY; - - dev->config.enable_psmi = val; - - return len; -} - -/** -* xe_configfs_get_survivability_mode - get configfs survivability mode attribute
- * @pdev: pci device
- *
- * Return:survivability_modeattribute in configfs
- */drivers/gpu/drm/xe/xe_configfs.c +0
-3-bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) -{ - struct xe_config_group_device *dev =
find_xe_config_group_device(pdev);
- bool mode;drivers/gpu/drm/xe/xe_configfs.c +0
-12- - if (!dev) - return device_defaults.survivability_mode; - - scoped_guard(mutex, &dev->lock) - mode = dev->config.survivability_mode; - config_group_put(&dev->group); - - return mode; -} - -static ssize_t survivability_mode_show(struct config_item *item,char *page)
drivers/gpu/drm/xe/xe_configfs.c +0
-7-{ - struct xe_config_device *dev = to_xe_config_device(item); - - return sprintf(page, "%d\n", dev->survivability_mode); -} - -static ssize_t survivability_mode_store(struct config_item *item,const char *page,
size_tlen)
-{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
- boolsurvivability_mode;
- int ret;drivers/gpu/drm/xe/xe_configfs.c +0
-33- - ret = kstrtobool(page, &survivability_mode); - if (ret) - return ret; - - guard(mutex)(&dev->lock); - if (is_bound(dev)) - return -EBUSY; - - dev->config.survivability_mode = survivability_mode; - - return len; -} - -CONFIGFS_ATTR(, ctx_restore_mid_bb); -CONFIGFS_ATTR(, ctx_restore_post_bb); -CONFIGFS_ATTR(, engines_allowed); -CONFIGFS_ATTR(, gt_types_allowed); -CONFIGFS_ATTR(, enable_multi_queue); -CONFIGFS_ATTR(, enable_psmi); -CONFIGFS_ATTR(, survivability_mode); - -static struct configfs_attribute *xe_config_device_attrs[] = { - &attr_ctx_restore_mid_bb, - &attr_ctx_restore_post_bb, - &attr_engines_allowed, - &attr_gt_types_allowed, - &attr_enable_multi_queue, - &attr_enable_psmi, - &attr_survivability_mode, - NULL, -}; -static void
xe_config_device_release(struct config_item *item){
- structxe_config_group_device*dev =to_xe_config_group_device(item);
+ structxe_config_group_device*dev =xe_configfs_to_group_device(item);
mutex_destroy(&dev->lock);
- kfree(dev->config.ctx_restore_mid_bb[0].cs); - kfree(dev->config.ctx_restore_post_bb[0].cs); + xe_configfs_debug_release_config(&dev->config); kfree(dev);
}drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1037,33 +167,14 @@ static struct configfs_item_operations xe_config_device_ops = { .release = xe_config_device_release, };
-static bool xe_config_device_is_visible(structconfig_item*item, - structconfigfs_attribute*attr, int n)
-{
- structxe_config_group_device*dev =to_xe_config_group_device(item);
-
- if (attr ==&attr_survivability_mode) {
- if (!dev->desc->is_dgfx ||dev->desc->platform<XE_BATTLEMAGE)
- return false;
- }drivers/gpu/drm/xe/xe_configfs.c +0
-5- - return true; -} - -static struct configfs_group_operations xe_config_device_group_ops= {
- .is_visible =xe_config_device_is_visible,drivers/gpu/drm/xe/xe_configfs.c +0
-2-}; -static const struct
config_item_typexe_config_device_type= { .ct_item_ops =&xe_config_device_ops,
- .ct_group_ops =&xe_config_device_group_ops, - .ct_attrs =xe_config_device_attrs, .ct_owner =THIS_MODULE,
};
staticssize_tsriov_max_vfs_show(struct config_item *item, char *page)
{
- structxe_config_group_device*dev =to_xe_config_group_device(item->ci_parent);
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
guard(mutex)(&dev->lock);drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1075,13 +186,13 @@ static ssize_t sriov_max_vfs_show(struct config_item *item, char *page)
staticssize_tsriov_max_vfs_store(struct config_item *item, const char *page, size_t len)
{
- structxe_config_group_device*dev =to_xe_config_group_device(item->ci_parent);
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
unsigned intmax_vfs;
int ret;
guard(mutex)(&dev->lock);
- if (is_bound(dev))
+ if (xe_configfs_is_bound(dev))
return-EBUSY;
ret =kstrtouint(page, 0, &max_vfs);drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1097,7 +208,7 @@ static ssize_t sriov_max_vfs_store(struct
config_item*item, const char *page, s
staticssize_tsriov_admin_only_pf_show(struct config_item *item, char *page)
{
- structxe_config_group_device*dev =to_xe_config_group_device(item->ci_parent);
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
guard(mutex)(&dev->lock);drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1106,13 +217,13 @@ static ssize_t sriov_admin_only_pf_show(struct config_item *item, char *page)
staticssize_tsriov_admin_only_pf_store(struct config_item *item, const char *page, size_t len)
{
- structxe_config_group_device*dev =to_xe_config_group_device(item->ci_parent);
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
booladmin_only_pf;
int ret;
guard(mutex)(&dev->lock);
- if (is_bound(dev))
+ if (xe_configfs_is_bound(dev))
return-EBUSY;
ret =kstrtobool(page, &admin_only_pf);drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1135,7 +246,7 @@ static struct configfs_attribute *xe_config_sriov_attrs[] = { static bool xe_config_sriov_is_visible(struct config_item *item,struct
configfs_attribute*attr, int n)
{
- structxe_config_group_device*dev =to_xe_config_group_device(item->ci_parent);
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
if (attr ==&sriov_attr_max_vfs&&dev->mode!=XE_SRIOV_MODE_PF)
return false;drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1271,7 +382,17 @@ static struct configfs_subsystem xe_configfs = { }, };
-static structxe_config_group_device*find_xe_config_group_device(structpci_dev*pdev)
+/**
+ *xe_configfs_find_group_device()- Find a configfs group by PCI device.
+ * @pdev: the&pci_devto look up
+ *
+ * Searches the configfs subsystem for a group whose name matches @pdev.
+ * If found, the returned group has an elevated reference count; the caller
+ * must callconfig_group_put()when done.
+ *
+ * Return: pointer to the matching&xe_config_group_device, or NULL.
+ */
+structxe_config_group_device*xe_configfs_find_group_device(structpci_dev*pdev)
{
structconfig_item*item;drivers/gpu/drm/xe/xe_configfs.c +0
-0@@ -1282,23 +403,25 @@ static struct xe_config_group_device *find_xe_config_group_device(struct pci_dev if (!item) return NULL;
- returnto_xe_config_group_device(item);
+ returnxe_configfs_to_group_device(item);
}
static voiddump_custom_dev_config(struct pci_dev *pdev, struct xe_config_group_device *dev)
{
#definePRI_CUSTOM_ATTR(fmt_, attr_)do { \
- if (dev->config.attr_!= device_defaults.attr_) \
+ if (dev->config.attr_!= xe_configfs_device_defaults.attr_) \
pci_info(pdev, "configfs: "__stringify(attr_)" = "fmt_"\n", \
dev->config.attr_); \
} while (0)
- PRI_CUSTOM_ATTR("%llx",engines_allowed);
- PRI_CUSTOM_ATTR("%llx",gt_types_allowed);
- PRI_CUSTOM_ATTR("%d",enable_multi_queue);
- PRI_CUSTOM_ATTR("%d",enable_psmi);
- PRI_CUSTOM_ATTR("%d",survivability_mode);drivers/gpu/drm/xe/xe_configfs.c +7
-0+#if IS_ENABLED (CONFIG_DRM_XE_DEBUG ) + PRI_CUSTOM_ATTR("%llx", debug.engines_allowed); + PRI_CUSTOM_ATTR("%llx", debug.gt_types_allowed); + PRI_CUSTOM_ATTR("%d", debug.enable_multi_queue); + PRI_CUSTOM_ATTR("%d", debug.enable_psmi); + PRI_CUSTOM_ATTR("%d", debug.survivability_mode); +#endif PRI_CUSTOM_ATTR("%u", sriov.admin_only_pf);
#undefPRI_CUSTOM_ATTRdrivers/gpu/drm/xe/xe_configfs.c +1
-1@@ -1313,13 +436,13 @@ static void dump_custom_dev_config(structpci_dev *pdev, */ void xe_configfs_check_device(struct pci_dev *pdev) { - struct xe_config_group_device *dev =find_xe_config_group_device (pdev); + struct xe_config_group_device *dev =xe_configfs_find_group_device (pdev);
if (!dev)
return;
/* memcmp here is safe as both are zero-initialized */ - if (memcmp(&dev->config,&device_defaults, sizeof(dev-Quoted 1 line
config))) {
+ if (
memcmp(&dev->config, &xe_configfs_device_defaults, sizeof(dev->config))) {
pci_info(pdev, "Found custom settings in configfs\n");
dump_custom_dev_config(pdev, dev);
}drivers/gpu/drm/xe/xe_configfs.c +1
-1@@ -1341,7 +464,7 @@ void xe_configfs_check_device(struct pci_dev*pdev) */ bool xe_configfs_admin_only_pf(struct pci_dev *pdev) { - struct xe_config_group_device *dev =find_xe_config_group_device (pdev); + struct xe_config_group_device *dev =xe_configfs_find_group_device (pdev);bool
admin_only_pf;
if (!dev)drivers/gpu/drm/xe/xe_configfs.c +1
-1@@ -1366,7 +489,7 @@ bool xe_configfs_admin_only_pf(struct pci_dev*pdev) */ unsigned int xe_configfs_get_max_vfs(struct pci_dev *pdev) { - struct xe_config_group_device *dev =find_xe_config_group_device (pdev); + struct xe_config_group_device *dev =xe_configfs_find_group_device (pdev);unsigned int
max_vfs;
if (!dev)drivers/gpu/drm/xe/xe_configfs.h +0
-0@@ -12,24 +12,76 @@ #include "xe_defaults.h" #include "xe_module.h"
+structconfig_item;
structpci_dev;drivers/gpu/drm/xe/xe_configfs.h +3
-0+struct xe_config_group_device ; + +extern const struct xe_config_device xe_configfs_device_defaults;
#ifIS_ENABLED(CONFIG_CONFIGFS_FS)
+/**
+ *xe_configfs_to_group_device()- Cast aconfig_itemto&xe_config_group_device.
+ * @item: the&config_itemembedded in the device group
+ *
+ * The @item must be the top-level device group'scg_item, not a subgroup item.
+ * Usexe_configfs_subgroup_to_group_device()for subgroup show/store callbacks.
+ *
+ * Return: pointer to the enclosing&xe_config_group_device.
+ */drivers/gpu/drm/xe/xe_configfs.h +4
-0+static inline struct xe_config_group_device * +xe_configfs_to_group_device (struct config_item *item) +{ + return container_of(to_config_group(item), struct
xe_config_group_device, group);drivers/gpu/drm/xe/xe_configfs.h +4
-0+} + +/** +* xe_configfs_to_device() - Cast a config_item to
&xe_config_device.
+ * @item: the&config_itemembedded in the device group
+ *
+ * Convenience wrapper aroundxe_configfs_to_group_device().
+ *
+ * Return: pointer to the&xe_config_devicenested in the group.
+ */
+static inline structxe_config_device*xe_configfs_to_device(structconfig_item*item)drivers/gpu/drm/xe/xe_configfs.h +6
-0+{ + return &xe_configfs_to_group_device(item)->config; +} + +/** +* xe_configfs_subgroup_to_group_device() - Cast a subgroup item to
&xe_config_group_device.
+ * @item: the&config_itemof a subgroup (e.g. sriov or debug)
+ *
+ * In configfs, show/store callbacks for a subgroup's attributes receive the
+ * subgroup'scg_item, whose parent is the device group'scg_item.
+ * This helper walks up one level to return the enclosing device group.
+ *
+ * Return: pointer to the enclosing&xe_config_group_device.
+ */drivers/gpu/drm/xe/xe_configfs.h +8
-0+static inline struct xe_config_group_device * +xe_configfs_subgroup_to_group_device (struct config_item *item) +{ + return xe_configfs_to_group_device(item->ci_parent); +} + +/** +* xe_configfs_subgroup_to_device() - Cast a subgroup item to
&xe_config_device.
+ * @item: the&config_itemof a subgroup (e.g. sriov or debug)
+ *
+ * Convenience wrapper for a subgroup item to get the&xe_config_device.
+ *
+ * Return: pointer to the&xe_config_devicenested in the parent device group.
+ */drivers/gpu/drm/xe/xe_configfs.h +8
-0+static inline struct xe_config_device * +xe_configfs_subgroup_to_device (struct config_item *item) +{ + return xe_configfs_to_device(item->ci_parent); +} + +bool xe_configfs_is_bound (struct xe_config_group_device *dev); +struct xe_config_group_device *xe_configfs_find_group_device(struct
pci_dev*pdev); intxe_configfs_init(void);
voidxe_configfs_exit(void);
voidxe_configfs_check_device(struct pci_dev *pdev);drivers/gpu/drm/xe/xe_configfs.h +0
-12-u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, - enum xe_engine_class class, - const u32 **cs); -u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, - enum xe_engine_class class, - const u32 **cs); -u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev); -bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev); -bool xe_configfs_media_gt_allowed (struct pci_dev *pdev); -bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev); -bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev); -bool xe_configfs_get_survivability_mode (struct pci_dev *pdev);#ifdef
CONFIG_PCI_IOV
unsigned intxe_configfs_get_max_vfs(struct pci_dev *pdev); boolxe_configfs_admin_only_pf(struct pci_dev *pdev);drivers/gpu/drm/xe/xe_configfs.h +0
-2@@ -38,18 +90,6 @@ bool xe_configfs_admin_only_pf(struct pci_dev *pdev); static inline int xe_configfs_init(void) { return 0; } static inline void xe_configfs_exit(void) { } static inline void xe_configfs_check_device(struct pci_dev *pdev) { } -static inline u32 xe_configfs_get_ctx_restore_mid_bb(struct pci_dev *pdev, - enum
xe_engine_classclass,
- const u32 **cs) { return 0; }
-static inline u32 xe_configfs_get_ctx_restore_post_bb(structpci_dev*pdev,
- enumxe_engine_classclass,
- const u32 **cs) { return 0; }
-static inline u64xe_configfs_get_engines_allowed(struct pci_dev *pdev){ returnU64_MAX; }
-static inline boolxe_configfs_primary_gt_allowed(struct pci_dev *pdev){ return true; }
-static inline boolxe_configfs_media_gt_allowed(struct pci_dev *pdev){ return true; }
-static inline boolxe_configfs_get_enable_multi_queue(struct pci_dev *pdev){ return true; }
-static inline boolxe_configfs_get_psmi_enabled(struct pci_dev *pdev){ return false; }
-static inline boolxe_configfs_get_survivability_mode(struct pci_dev *pdev){ return false; }
#ifdefCONFIG_PCI_IOV
static inline unsigned intxe_configfs_get_max_vfs(struct pci_dev *pdev)
{drivers/gpu/drm/xe/xe_configfs_debug.c +0
-0@@ -3,12 +3,968 @@* Copyright © 2026 Intel Corporation */
+#include <linux/bitops.h>
#include <linux/configfs.h>
#include <linux/module.h>drivers/gpu/drm/xe/xe_configfs_debug.c +4
-0+#include <linux/cleanup.h> +#include <linux/find.h> +#include <linux/pci.h> +#include <linux/string.h> drivers/gpu/drm/xe/xe_configfs_debug.c +3
-0+#include "abi/guc_log_abi.h" +#include "instructions/xe_mi_commands.h" +#include "xe_configfs.h" #include "
xe_configfs_debug.h"
#include "xe_configfs_types.h"drivers/gpu/drm/xe/xe_configfs_debug.c +11
-0+#include "xe_gt_types.h" +#include "xe_hw_engine_types.h" +#include "xe_pci_types.h" + +/** +* DOC: Xe Configfs Debug Attributes +* +* Overview +* ======== +* +* The following configfs attributes are only available when the kernel is
+ * built with ``CONFIG_DRM_XE_DEBUG=y``. They appear under the ``debug/``
+ * subdirectory of each xe configfs device. They are intended for hardware
+ * and driver debugging and are not stable ABI. Using them is "at your own
+ * risk".
+ *
+ * See the top-level ``Xe Configfs`` documentation in ``xe_configfs.c``
+ * for how to create, probe and remove configfs devices. Once a device
+ * directory exists, the driver populates it with a ``debug/`` subdirectory
+ * containing the entries described below::
+ *
+ * /sys/kernel/config/xe/+ * └── 0000:03:00.0 + * └── debug/ + * ├── ctx_restore_mid_bb + * ├── ctx_restore_post_bb + * ├── engines_allowed + * ├── gt_types_allowed + * ├── enable_multi_queue + * ├── enable_psmi + * └── survivability_mode+ *
+ * Configure Attributes
+ * ====================
+ *
+ * Context restore BB
+ * ------------------
+ *
+ * Allow to execute a batch buffer during any context switches. When the
+ * GPU is restoring the context, it executes additional commands. It's useful
+ * for testing additional workarounds and validating certain HW
behaviors: it's
+ * not intended for normal execution and will taint the kernel withTAINT_TEST
+ * when used.
+ *
+ * The syntax allows to pass straight instructions to be executed by the engine
+ * in a batch buffer or set specific registers.
+ *
+ * #. Generic instruction::
+ *
+ * <engine-class> cmd <instr> [[dword0] [dword1] [...]]
+ *
+ * #. Simple register setting::
+ *
+ * <engine-class> reg <address> <value>
+ *
+ * Commands are saved per engine class: all instances of that class will execute
+ * those commands during context switch. The instruction, dword arguments,
+ * addresses and values are in hex format like in the examples below.
+ *
+ * #. Execute a LRI command to write0xDEADBEEFto register0x4f10after the
+ * normal context restore::
+ *
+ * # echo 'rcs cmd 11000001 4F100 DEADBEEF' \
+ * > /sys/kernel/config/xe/0000:03:00.0/debug/ctx_restore_post_bb
+ *
+ * #. Execute a LRI command to write0xDEADBEEFto register0x4f10at the
+ * beginning of the context restore::
+ *
+ * # echo 'rcs cmd 11000001 4F100 DEADBEEF' \
+ * > /sys/kernel/config/xe/0000:03:00.0/debug/ctx_restore_mid_bb
+ *
+ * #. Load certain values in a couple of registers (it can be used as a simpler
+ * alternative to thecmd) action::
+ *
+ * # cat > /sys/kernel/config/xe/0000:03:00.0/debug/ctx_restore_post_bb <<EOF
+ * rcs reg 4F100 DEADBEEF
+ * rcs reg 4F104 FFFFFFFF
+ * EOF
+ *
+ * .. note::
+ *
+ * When using multiple lines, make sure to use a command that is
+ * implemented with a single write syscall, like HEREDOC.
+ *
+ * Currently this is implemented only for post and mid context restore and
+ * these attributes can only be set before binding to the device.
+ *
+ * Allowed engines:
+ * ----------------
+ *
+ * Allow only a set of engine(s) to be available, disabling the other engines
+ * even if they are available in hardware. This is applied after HW fuses are
+ * considered on each tile. Examples:
+ *
+ * Allow only one render and one copy engines, nothing else::
+ *
+ * # echo 'rcs0,bcs0' > /sys/kernel/config/xe/0000:03:00.0/debug/engines_allowed
+ *
+ * Allow only compute engines and first copy engine::
+ *
+ * # echo 'ccs*,bcs0' > /sys/kernel/config/xe/0000:03:00.0/debug/engines_allowed
+ *
+ * Note that the engine names are the per-GT hardware names. On multi-tile
+ * platforms, writing ``rcs0,bcs0`` to this file would allow the first render
+ * and copy engines on each tile.
+ *
+ * The requested configuration may not be supported by the platform and driver
+ * may fail to probe. For example: if at least one copy engine is expected to be
+ * available for migrations, but it's disabled. This is intended for debugging
+ * purposes only.
+ *
+ * This attribute can only be set before binding to the device.
+ *
+ * Allowed GT types:
+ * -----------------
+ *
+ * Allow only specific types of GTs to be detected and initialized by the
+ * driver. Any combination of GT types can be enabled/disabled, although
+ * some settings will cause the device to fail to probe.
+ *
+ * Writes support both comma- and newline-separated input format. Reads
+ * will always return one GT type per line. "primary" and "media" are the
+ * GT type names supported by this interface.
+ *
+ * This attribute can only be set before binding to the device.
+ *
+ * Examples:
+ *
+ * Allow both primary and media GTs to be initialized and used. This matches
+ * the driver's default behavior::
+ *
+ * # echo 'primary,media' > /sys/kernel/config/xe/0000:03:00.0/debug/gt_types_allowed
+ *
+ * Allow only the primary GT of each tile to be initialized and used,
+ * effectively disabling the media GT if it exists on the platform::
+ *
+ * # echo 'primary' > /sys/kernel/config/xe/0000:03:00.0/debug/gt_types_allowed
+ *
+ * Allow only the media GT of each tile to be initialized and used,
+ * effectively disabling the primary GT. **This configuration will cause
+ * device probe failure on all current platforms, but may be allowed on
+ * igpu platforms in the future**::
+ *
+ * # echo 'media' > /sys/kernel/config/xe/0000:03:00.0/debug/gt_types_allowed
+ *
+ * Disable all GTs. Only other GPU IP (such as display) is potentially usable.
+ * **This configuration will cause device probe failure on all current
+ * platforms, but may be allowed on igpu platforms in the future**::
+ *
+ * # echo '' > /sys/kernel/config/xe/0000:03:00.0/debug/gt_types_allowed
+ *
+ * Enable multi-queue
+ * ------------------
+ *
+ * Multi-queue support on the device is enabled by default where the
+ * hardware supports it. Writing 0 force-disables multi-queue support:
+ * multi-queue exec-queue group creation via ioctl is refused, and the
+ * GuC feature is disabled::
+ *
+ * # echo 0 > /sys/kernel/config/xe/0000:03:00.0/debug/enable_multi_queue
+ *
+ * This attribute can only be set before binding to the device.
+ *
+ * PSMI
+ * ----
+ *
+ * Enable extra debugging capabilities to trace engine execution. Only useful
+ * during early platform enabling and requires additional hardware connected.
+ * Once it's enabled, additionals WAs are added and runtime configuration is
+ * done via debugfs. Example to enable it::
+ *
+ * # echo 1 > /sys/kernel/config/xe/0000:03:00.0/debug/enable_psmi
+ *
+ * This attribute can only be set before binding to the device.
+ *
+ * Survivability mode:
+ * -------------------
+ *
+ * Enable survivability mode on supported cards. This setting only takes
+ * effect when probing the device. Example to enable it::
+ *
+ * # echo 1 > /sys/kernel/config/xe/0000:03:00.0/debug/survivability_mode
+ *
+ * This attribute can only be set before binding to the device.
+ *
+ */drivers/gpu/drm/xe/xe_configfs_debug.c +8
-0+ +struct engine_info { + const char *cls; + u64 mask; + enum xe_engine_class engine_class; +}; + +/* Some helpful macros to aid on the sizing of buffer allocation when parsing */
drivers/gpu/drm/xe/xe_configfs_debug.c +5
-0+#define MAX_ENGINE_CLASS_CHARS 5 +#define MAX_ENGINE_INSTANCE_CHARS 2 + +static const struct engine_info engine_info[] = { + { .cls = "rcs", .mask = XE_HW_ENGINE_RCS_MASK,.engine_class =
XE_ENGINE_CLASS_RENDER},
+ { .cls = "bcs", .mask =XE_HW_ENGINE_BCS_MASK, .engine_class =XE_ENGINE_CLASS_COPY},
+ { .cls = "vcs", .mask =XE_HW_ENGINE_VCS_MASK, .engine_class =XE_ENGINE_CLASS_VIDEO_DECODE},
+ { .cls = "vecs", .mask =XE_HW_ENGINE_VECS_MASK, .engine_class =XE_ENGINE_CLASS_VIDEO_ENHANCE}, + { .cls = "ccs", .mask =XE_HW_ENGINE_CCS_MASK, .engine_class =XE_ENGINE_CLASS_COMPUTE},
+ { .cls = "gsccs", .mask =XE_HW_ENGINE_GSCCS_MASK, .engine_class =XE_ENGINE_CLASS_OTHER},drivers/gpu/drm/xe/xe_configfs_debug.c +11
-0+}; + +static const struct { + const char *name; + enum xe_gt_type type; +} gt_types[] = { + { .name = "primary", .type = XE_GT_TYPE_MAIN }, + { .name = "media", .type = XE_GT_TYPE_MEDIA }, +}; + +static struct xe_config_group_device *find_device(struct pci_dev*pdev)
drivers/gpu/drm/xe/xe_configfs_debug.c +6
-0+{ + return xe_configfs_find_group_device(pdev); +} + +/** +* xe_configfs_get_ctx_restore_mid_bb - get configfs
ctx_restore_mid_bbsetting
+ * @pdev: pci device
+ * @class: hw engine class
+ * @cs: pointer to the bb to use - only valid during probe
+ *
+ * Return: Number of dwords used in themid_ctx_restoresetting in configfs
+ */drivers/gpu/drm/xe/xe_configfs_debug.c +13
-0+u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, + enum xe_engine_class class, + const u32 **cs) +{ + struct xe_config_group_device *dev = find_device(pdev); + u32 len; + + if (!dev) + return 0; + + scoped_guard(mutex, &dev->lock) { + if (cs) + *cs = dev-Quoted 1 line
config.debug.ctx_restore_mid_bb[class].cs;
+
+ len = dev-Quoted 1 line
config.debug.ctx_restore_mid_bb[class].len;
+ }
+ config_group_put(&dev->group);drivers/gpu/drm/xe/xe_configfs_debug.c +6
-0+ + return len; +} + +/** +* xe_configfs_get_ctx_restore_post_bb - get configfs
ctx_restore_post_bbsetting
+ * @pdev: pci device
+ * @class: hw engine class
+ * @cs: pointer to the bb to use - only valid during probe
+ *
+ * Return: Number of dwords used in thepost_ctx_restoresetting in configfs
+ */drivers/gpu/drm/xe/xe_configfs_debug.c +12
-0+u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, + enum xe_engine_class class, + const u32 **cs) +{ + struct xe_config_group_device *dev = find_device(pdev); + u32 len; + + if (!dev) + return 0; + + scoped_guard(mutex, &dev->lock) { + *cs = dev-Quoted 1 line
config.debug.ctx_restore_post_bb[class].cs;
+ len = dev-
Quoted 1 line
config.debug.ctx_restore_post_bb[class].len;
+ }
+ config_group_put(&dev->group);drivers/gpu/drm/xe/xe_configfs_debug.c +23
-0+ + return len; +} + +static bool wa_bb_read_advance (bool dereference,char **p, + const char *append, size_t len, + size_t *max_size) +{ + if (dereference) { + if (len >= *max_size) + return false; + *max_size -= len; + if (append) + memcpy(*p, append, len); + } + + *p += len; + + return true; +} + +static ssize_t wa_bb_show(struct xe_config_group_device *dev, + struct wa_bb wa_bb[static
XE_ENGINE_CLASS_MAX],
+ char *data,size_tsz)drivers/gpu/drm/xe/xe_configfs_debug.c +7
-0+{ + char *p = data; + + guard(mutex)(&dev->lock); + + for (size_t i = 0; i < ARRAY_SIZE(engine_info); i++) { + enum xe_engine_class ec =engine_info[i].engine_class;
+ size_t len;drivers/gpu/drm/xe/xe_configfs_debug.c +10
-0+ + if (!wa_bb[ec].len) + continue; + + len = snprintf(p, sz, "%s:", engine_info[i].cls); + if (!wa_bb_read_advance(data, &p, NULL, len, &sz)) + return -ENOBUFS; + + for (size_t j = 0; j < wa_bb[ec].len; j++) { + len = snprintf(p, sz, " %08x",wa_bb[ec].cs[j]);
+ if (!wa_bb_read_advance(data, &p, NULL, len, &sz))
+ return-ENOBUFS;
+ }drivers/gpu/drm/xe/xe_configfs_debug.c +16
-0+ + if (!wa_bb_read_advance(data, &p, "\n", 1, &sz)) + return -ENOBUFS; + } + + if (!wa_bb_read_advance(data, &p, "", 1, &sz)) + return -ENOBUFS; + + /* Reserve one more to match check for '\0' */ + if (!data) + p++; + + return p - data; +} + +static ssize_t ctx_restore_mid_bb_show(struct config_item *item,char *page)
+{
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
+
+ return wa_bb_show(dev, dev-Quoted 1 line
config.debug.ctx_restore_mid_bb, page,
SZ_4K);drivers/gpu/drm/xe/xe_configfs_debug.c +3
-0+} + +static ssize_t ctx_restore_post_bb_show(struct config_item *item,char *page)
+{
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
+
+ return wa_bb_show(dev, dev-Quoted 1 line
config.debug.ctx_restore_post_bb, page,
SZ_4K);drivers/gpu/drm/xe/xe_configfs_debug.c +35
-0+} + +static void wa_bb_append (struct wa_bb *wa_bb,u32 val) +{ + if (wa_bb->cs) + wa_bb->cs[wa_bb->len] = val; + + wa_bb->len++; +} + +static ssize_t parse_hex (const char *line,u32 *pval) +{ + char numstr[12]; + const char *p; + ssize_t numlen; + + p = line + strspn(line, " \t"); + if (!*p || *p == '\n') + return 0; + + numlen = strcspn(p, " \t\n"); + if (!numlen || numlen >= sizeof(numstr) - 1) + return -EINVAL; + + memcpy(numstr, p, numlen); + numstr[numlen] = '\0'; + p += numlen; + + if (kstrtou32(numstr, 16, pval)) + return -EINVAL; + + return p - line; +} + +static int parse_engine(const char *s, const char *end_chars, u64*mask,
+ const structengine_info**pinfo);drivers/gpu/drm/xe/xe_configfs_debug.c +13
-0+ +/* +* Parse lines with the format +* +* <engine-class> cmd <u32> <u32...> +* <engine-class> reg <u32_addr> <u32_val> +* +* and optionally save them in @wa_bb[i].cs is non-NULL. +* +* Return the number of dwords parsed. +*/ +static ssize_t parse_wa_bb_lines(const char *lines, + struct wa_bb wa_bb[static
XE_ENGINE_CLASS_MAX])drivers/gpu/drm/xe/xe_configfs_debug.c +31
-0+{ + ssize_t dwords = 0, ret; + const char *p; + + for (p = lines; *p; p++) { + const struct engine_info *info = NULL; + u32 val, val2; + + /* Also allow empty lines */ + p += strspn(p, " \t\n"); + if (!*p) + break; + + ret = parse_engine(p, " \t\n", NULL, &info); + if (ret < 0) + return ret; + + p += ret; + p += strspn(p, " \t"); + + if (str_has_prefix(p, "cmd")) { + for (p += strlen("cmd"); *p;) { + ret = parse_hex(p, &val); + if (ret < 0) + return -EINVAL; + if (!ret) + break; + + p += ret; + dwords++; + wa_bb_append(&wa_bb[info-Quoted 1 line
engine_class], val);+ }
+ } else if (str_has_prefix(p, "reg")) { + p +=strlen("reg");
+ ret =parse_hex(p, &val); + if (ret <= 0)
+ return-EINVAL;drivers/gpu/drm/xe/xe_configfs_debug.c +10
-0+ + p += ret; + ret = parse_hex(p, &val2); + if (ret <= 0) + return -EINVAL; + + p += ret; + dwords += 3; + wa_bb_append(&wa_bb[info->engine_class], + MI_LOAD_REGISTER_IMM |
MI_LRI_NUM_REGS(1));
+ wa_bb_append(&wa_bb[info->engine_class], val);
+ wa_bb_append(&wa_bb[info->engine_class], val2);
+ } else {
+ return-EINVAL;
+ }
+ }drivers/gpu/drm/xe/xe_configfs_debug.c +5
-0+ + return dwords; +} + +static ssize_t wa_bb_store(struct wa_bb wa_bb[static
XE_ENGINE_CLASS_MAX],
+ structxe_config_group_device*dev, + const char *page,size_tlen)drivers/gpu/drm/xe/xe_configfs_debug.c +18
-0+{ + /* tmp_wa_bb must match wa_bb's size */ + struct wa_bb tmp_wa_bb[XE_ENGINE_CLASS_MAX] = { }; + ssize_t count, class; + u32 *tmp; + + /* 1. Count dwords - wa_bb[i].cs is NULL for all classes */ + count = parse_wa_bb_lines(page, tmp_wa_bb); + if (count < 0) + return count; + + guard(mutex)(&dev->lock); + + if (xe_configfs_is_bound(dev)) + return -EBUSY; + + /* +* 2. Allocate a u32 array and set the pointers to the right positions
+ * according to the length of each class'wa_bb+ */
+ tmp =krealloc(wa_bb[0].cs, count * sizeof(u32), GFP_KERNEL);
+ if (!tmp)
+ return-ENOMEM;drivers/gpu/drm/xe/xe_configfs_debug.c +14
-0+ + if (!count) { + memset(wa_bb, 0, sizeof(tmp_wa_bb)); + return len; + } + + for (class = 0, count = 0; class < XE_ENGINE_CLASS_MAX; ++class) { + tmp_wa_bb[class].cs = tmp + count; + count += tmp_wa_bb[class].len; + tmp_wa_bb[class].len = 0; + } + + /* 3. Parse wa_bb lines again, this time saving the values*/
+ count =parse_wa_bb_lines(page, tmp_wa_bb); + if (count < 0) {
+ kfree(tmp);
+ memset(wa_bb, 0,sizeof(tmp_wa_bb)); + return count;
+ }drivers/gpu/drm/xe/xe_configfs_debug.c +8
-0+ + memcpy(wa_bb, tmp_wa_bb, sizeof(tmp_wa_bb)); + + return len; +} + +static ssize_t ctx_restore_mid_bb_store (struct config_item *item, + const char *data, size_tsz)
+{
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
+
+ returnwa_bb_store(dev->config.debug.ctx_restore_mid_bb, dev, data, sz);drivers/gpu/drm/xe/xe_configfs_debug.c +4
-0+} + +static ssize_t ctx_restore_post_bb_store (struct config_item *item, + const char *data, size_tsz)
+{
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
+
+ returnwa_bb_store(dev->config.debug.ctx_restore_post_bb, dev, data, sz);drivers/gpu/drm/xe/xe_configfs_debug.c +4
-0+} + +/** +* xe_configfs_get_engines_allowed - get engine allowed mask from configfs
+ * @pdev: pci device
+ *
+ * Return: engine mask with allowed engines set in configfs
+ */drivers/gpu/drm/xe/xe_configfs_debug.c +7
-0+u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) +{ + struct xe_config_group_device *dev = find_device(pdev); + u64 engines_allowed; + + if (!dev) + returnxe_configfs_device_defaults.debug.engines_allowed; +
+ scoped_guard(mutex,&dev->lock)
+ engines_allowed = dev-Quoted 1 line
config.debug.engines_allowed;
+ config_group_put(&dev->group);
drivers/gpu/drm/xe/xe_configfs_debug.c +5
-0+ + return engines_allowed; +} + +static ssize_t engines_allowed_show(struct config_item *item, char*page)
+{
+ structxe_config_device*dev =xe_configfs_subgroup_to_device(item);
+ char *p = page;drivers/gpu/drm/xe/xe_configfs_debug.c +6
-0+ + for (size_t i = 0; i < ARRAY_SIZE(engine_info); i++) { + u64 mask = engine_info[i].mask; + + if ((dev->debug.engines_allowed & mask) == mask) { + p += sprintf(p, "%s*\n",engine_info[i].cls);
+ } else if (mask &dev->debug.engines_allowed) { + u16 bit0 =__ffs64(mask), bit;drivers/gpu/drm/xe/xe_configfs_debug.c +4
-0+ + mask &= dev->debug.engines_allowed; + + for_each_set_bit(bit, (const unsigned long*)&mask, 64)
+ p += sprintf(p, "%s%u\n", engine_info[i].cls,
+ bit - bit0); + }
+ }drivers/gpu/drm/xe/xe_configfs_debug.c +6
-0+ + return p - page; +} + +/* +* Lookup engine_info. If @mask is not NULL, reduce the mask according to the
+ * instance in @pattern.
+ *
+ * Examples of inputs:
+ * -lookup_engine_info("rcs0", &mask): return "rcs" entry from @engine_info and
+ * mask ==BIT_ULL(XE_HW_ENGINE_RCS0)
+ * -lookup_engine_info("rcs*", &mask): return "rcs" entry from @engine_info and
+ * mask ==XE_HW_ENGINE_RCS_MASK
+ * -lookup_engine_info("rcs", NULL): return "rcs" entry from @engine_info
+ */
+static const structengine_info*lookup_engine_info(const char *pattern, u64 *mask)drivers/gpu/drm/xe/xe_configfs_debug.c +32
-0+{ + for (size_t i = 0; i < ARRAY_SIZE(engine_info); i++) { + u8 instance; + u16 bit; + + if (!str_has_prefix(pattern, engine_info[i].cls)) + continue; + + pattern += strlen(engine_info[i].cls); + if (!mask) + return *pattern ? NULL : &engine_info[i]; + + if (!strcmp(pattern, "*")) { + *mask = engine_info[i].mask; + return &engine_info[i]; + } + + if (kstrtou8(pattern, 10, &instance)) + return NULL; + + bit = __ffs64(engine_info[i].mask) + instance; + if (bit >= fls64(engine_info[i].mask)) + return NULL; + + *mask = BIT_ULL(bit); + return &engine_info[i]; + } + + return NULL; +} + +static int parse_engine(const char *s, const char *end_chars, u64*mask,
+ const structengine_info**pinfo)drivers/gpu/drm/xe/xe_configfs_debug.c +24
-0+{ + char buf[MAX_ENGINE_CLASS_CHARS + MAX_ENGINE_INSTANCE_CHARS + 1]; + const struct engine_info *info; + size_t len; + + len = strcspn(s, end_chars); + if (len >= sizeof(buf)) + return -EINVAL; + + memcpy(buf, s, len); + buf[len] = '\0'; + + info = lookup_engine_info(buf, mask); + if (!info) + return -ENOENT; + + if (pinfo) + *pinfo = info; + + return len; +} + +static ssize_t engines_allowed_store(struct config_item *item,const char *page,
+size_tlen)
+{
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
+ ssize_t patternlen, p;
+ u64 mask, val = 0;
+
+ for (p = 0; p < len; p += patternlen + 1) {
+ patternlen =parse_engine(page + p, ",\n", &mask, NULL);
+ if (patternlen < 0)
+ return-EINVAL;drivers/gpu/drm/xe/xe_configfs_debug.c +20
-0+ + val |= mask; + } + + guard(mutex)(&dev->lock); + if (xe_configfs_is_bound(dev)) + return -EBUSY; + + dev->config.debug.engines_allowed = val; + + return len; +} + +static u64 get_gt_types_allowed (struct pci_dev *pdev) +{ + struct xe_config_group_device *dev = find_device(pdev); + u64 mask; + + if (!dev) + returnxe_configfs_device_defaults.debug.gt_types_allowed;
drivers/gpu/drm/xe/xe_configfs_debug.c +10
-0+ + scoped_guard(mutex, &dev->lock) + mask = dev->config.debug.gt_types_allowed; + config_group_put(&dev->group); + + return mask; +} + +/** +* xe_configfs_primary_gt_allowed - determine whether primary GTs are supported
+ * @pdev: pci device
+ *
+ * Return: True if primary GTs are enabled, false if they have been disabled via
+ * configfs.
+ */drivers/gpu/drm/xe/xe_configfs_debug.c +3
-0+bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev) +{ + return get_gt_types_allowed(pdev) &
BIT_ULL(XE_GT_TYPE_MAIN);drivers/gpu/drm/xe/xe_configfs_debug.c +4
-0+} + +/** +* xe_configfs_media_gt_allowed - determine whether media GTs are supported
+ * @pdev: pci device
+ *
+ * Return: True if the media GTs are enabled, false if they have been disabled
+ * via configfs.
+ */drivers/gpu/drm/xe/xe_configfs_debug.c +3
-0+bool xe_configfs_media_gt_allowed (struct pci_dev *pdev) +{ + return get_gt_types_allowed(pdev) &
BIT_ULL(XE_GT_TYPE_MEDIA);drivers/gpu/drm/xe/xe_configfs_debug.c +3
-0+} + +static ssize_t gt_types_allowed_show(struct config_item *item,char *page)
+{
+ structxe_config_device*dev =xe_configfs_subgroup_to_device(item);
+ char *p = page;
+
+ for (size_ti = 0; i <ARRAY_SIZE(gt_types); i++) + if (dev->debug.gt_types_allowed&BIT_ULL(gt_types[i].type))
+ p +=sprintf(p, "%s\n", gt_types[i].name);drivers/gpu/drm/xe/xe_configfs_debug.c +5
-0+ + return p - page; +} + +static ssize_t gt_types_allowed_store(struct config_item *item,const char *page,
+size_tlen) +{
+ char *buf__free(kfree)=kstrdup(page, GFP_KERNEL); + structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
+ u64 typemask = 0;
+ char *p = buf;drivers/gpu/drm/xe/xe_configfs_debug.c +13
-0+ + if (!buf) + return -ENOMEM; + + while (p) { + char *typename = strsep(&p, ",\n"); + bool matched = false; + + if (typename[0] == '\0') + continue; + + for (size_t i = 0; i < ARRAY_SIZE(gt_types); i++) { + if (strcmp(typename, gt_types[i].name) ==0) {
+ typemask |=BIT(gt_types[i].type); + matched = true;
+ break;
+ }
+ }drivers/gpu/drm/xe/xe_configfs_debug.c +16
-0+ + if (!matched) + return -EINVAL; + } + + guard(mutex)(&dev->lock); + if (xe_configfs_is_bound(dev)) + return -EBUSY; + + dev->config.debug.gt_types_allowed = typemask; + + return len; +} + +/** +* xe_configfs_get_enable_multi_queue - get configfs
enable_multi_queuesetting
+ * @pdev: pci device
+ *
+ * Return: true if multi-queue is enabled for this device (the default),
+ * false if it has been force-disabled via configfs.
+ */drivers/gpu/drm/xe/xe_configfs_debug.c +7
-0+bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) +{ + struct xe_config_group_device *dev = find_device(pdev); + bool ret; + + if (!dev) + returnxe_configfs_device_defaults.debug.enable_multi_queue;
drivers/gpu/drm/xe/xe_configfs_debug.c +9
-0+ + scoped_guard(mutex, &dev->lock) + ret = dev->config.debug.enable_multi_queue; + config_group_put(&dev->group); + + return ret; +} + +static ssize_t enable_multi_queue_show(struct config_item *item,char *page)
+{
+ structxe_config_device*dev =xe_configfs_subgroup_to_device(item);
+
+ return sprintf(page, "%d\n", dev-Quoted 1 line
debug.enable_multi_queue);
drivers/gpu/drm/xe/xe_configfs_debug.c +3
-0+} + +static ssize_t enable_multi_queue_store(struct config_item *item,const char *page,
size_tlen)
+{
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
+ bool val;
+ int ret;drivers/gpu/drm/xe/xe_configfs_debug.c +36
-0+ + ret = kstrtobool(page, &val); + if (ret) + return ret; + + guard(mutex)(&dev->lock); + if (xe_configfs_is_bound(dev)) + return -EBUSY; + + dev->config.debug.enable_multi_queue = val; + + return len; +} + +/** +* xe_configfs_get_psmi_enabled - get configfs enable_psmi setting +* @pdev: pci device +* +* Return: enable_psmi setting in configfs +*/ +bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) +{ + struct xe_config_group_device *dev = find_device(pdev); + bool ret; + + if (!dev) + return false; + + scoped_guard(mutex, &dev->lock) + ret = dev->config.debug.enable_psmi; + config_group_put(&dev->group); + + return ret; +} + +static ssize_t enable_psmi_show(struct config_item *item, char*page)
+{
+ structxe_config_device*dev =xe_configfs_subgroup_to_device(item);drivers/gpu/drm/xe/xe_configfs_debug.c +5
-0+ + return sprintf(page, "%d\n", dev->debug.enable_psmi); +} + +static ssize_t enable_psmi_store(struct config_item *item, constchar *page,
size_tlen)
+{
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
+ bool val;
+ int ret;drivers/gpu/drm/xe/xe_configfs_debug.c +16
-0+ + ret = kstrtobool(page, &val); + if (ret) + return ret; + + guard(mutex)(&dev->lock); + if (xe_configfs_is_bound(dev)) + return -EBUSY; + + dev->config.debug.enable_psmi = val; + + return len; +} + +/** +* xe_configfs_get_survivability_mode - get configfs survivability mode attribute
+ * @pdev: pci device
+ *
+ * Return:survivability_modeattribute in configfs
+ */drivers/gpu/drm/xe/xe_configfs_debug.c +7
-0+bool xe_configfs_get_survivability_mode (struct pci_dev *pdev) +{ + struct xe_config_group_device *dev = find_device(pdev); + bool mode; + + if (!dev) + returnxe_configfs_device_defaults.debug.survivability_mode;
drivers/gpu/drm/xe/xe_configfs_debug.c +9
-0+ + scoped_guard(mutex, &dev->lock) + mode = dev->config.debug.survivability_mode; + config_group_put(&dev->group); + + return mode; +} + +static ssize_t survivability_mode_show(struct config_item *item,char *page)
+{
+ structxe_config_device*dev =xe_configfs_subgroup_to_device(item);
+
+ return sprintf(page, "%d\n", dev-Quoted 1 line
debug.survivability_mode);
drivers/gpu/drm/xe/xe_configfs_debug.c +3
-0+} + +static ssize_t survivability_mode_store(struct config_item *item,const char *page,
size_tlen)
+{
+ structxe_config_group_device*dev =xe_configfs_subgroup_to_group_device(item);
+ boolsurvivability_mode;
+ int ret;drivers/gpu/drm/xe/xe_configfs_debug.c +38
-0+ + ret = kstrtobool(page, &survivability_mode); + if (ret) + return ret; + + guard(mutex)(&dev->lock); + if (xe_configfs_is_bound(dev)) + return -EBUSY; + + dev->config.debug.survivability_mode = survivability_mode; + + return len; +} + +CONFIGFS_ATTR(, ctx_restore_mid_bb); +CONFIGFS_ATTR(, ctx_restore_post_bb); +CONFIGFS_ATTR(, engines_allowed); +CONFIGFS_ATTR(, gt_types_allowed); +CONFIGFS_ATTR(, enable_multi_queue); +CONFIGFS_ATTR(, enable_psmi); +CONFIGFS_ATTR(, survivability_mode); + +static struct configfs_attribute *xe_configfs_debug_attrs[] = { + &attr_ctx_restore_mid_bb, + &attr_ctx_restore_post_bb, + &attr_engines_allowed, + &attr_gt_types_allowed, + &attr_enable_multi_queue, + &attr_enable_psmi, + &attr_survivability_mode, + NULL, +}; + +/* +* Per-parameter visibility predicates. +* +* XE_PARAM_VISIBLE_ALWAYS - attribute is always shown. +* XE_PARAM_VISIBLE_SURVIVABILITY - only shown on dGFX platforms Quoted 1 line
= Battlemage.
+ *
+ * These macros are only evaluated here, where the platform descriptor is
+ * reachable.xe_configfs_debug_params.htreats them as opaque tokens.
+ */drivers/gpu/drm/xe/xe_configfs_debug.c +4
-0+#define XE_PARAM_VISIBLE_ALWAYS (_item) \ + (true) +#define XE_PARAM_VISIBLE_SURVIVABILITY (_item) \ + (xe_configfs_subgroup_to_group_device(_item)->desc->is_dgfx&& \
+ xe_configfs_subgroup_to_group_device(_item)->desc-Quoted 1 line
platform >=
XE_BATTLEMAGE)drivers/gpu/drm/xe/xe_configfs_debug.c +3
-0+ +static bool xe_configfs_debug_is_visible (struct config_item *item, + struct configfs_attribute*attr, int n)
+{
+ if (attr ==&attr_survivability_mode) { + structxe_config_group_device*dev = + xe_configfs_to_group_device(item-Quoted 1 line
ci_parent);+
+ returndev->desc->is_dgfx&&dev->desc->platform>=XE_BATTLEMAGE;
+ }drivers/gpu/drm/xe/xe_configfs_debug.c +5
-0+ + return true; +} + +static struct configfs_group_operations
xe_configfs_debug_group_ops= {
+ .is_visible =xe_configfs_debug_is_visible, +};
const structconfig_item_typexe_configfs_debug_type= { + .ct_attrs =xe_configfs_debug_attrs, + .ct_group_ops =&xe_configfs_debug_group_ops, .ct_owner =THIS_MODULE,
};drivers/gpu/drm/xe/xe_configfs_debug.c +3
-0+ +/** +* xe_configfs_debug_release_config - release debug-specific config resources
+ * @config: xe config device structure
+ *
+ * Frees any memory allocated for debug configfs parameters.
+ */
+voidxe_configfs_debug_release_config(struct xe_config_device *config)drivers/gpu/drm/xe/xe_configfs_debug.c +4
-0+{ + kfree(config->debug.ctx_restore_mid_bb[0].cs); + kfree(config->debug.ctx_restore_post_bb[0].cs); +}drivers/gpu/drm/xe/xe_configfs_debug.h +0
-0@@ -5,9 +5,46 @@ #ifndef _XE_CONFIGFS_DEBUG_H_ #define _XE_CONFIGFS_DEBUG_H_drivers/gpu/drm/xe/xe_configfs_debug.h +7
-0+#include <linux/types.h> + +#include "xe_hw_engine_types.h" + +struct pci_dev ; +struct xe_config_device ; +#if
IS_ENABLED(CONFIG_DRM_XE_DEBUG)&&IS_ENABLED(CONFIG_CONFIGFS_FS)
-structconfig_item_type;
extern const structconfig_item_typexe_configfs_debug_type; +voidxe_configfs_debug_release_config(struct xe_config_device *config);drivers/gpu/drm/xe/xe_configfs_debug.h +15
-0+u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev, + enum xe_engine_class class, + const u32 **cs); +u32 xe_configfs_get_ctx_restore_post_bb (struct pci_dev *pdev, + enum xe_engine_class class, + const u32 **cs); +u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev); +bool xe_configfs_primary_gt_allowed (struct pci_dev *pdev); +bool xe_configfs_media_gt_allowed (struct pci_dev *pdev); +bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev); +bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev); +bool xe_configfs_get_survivability_mode (struct pci_dev *pdev); +#else +/* +* Dummy values here are not used since these function accesses are always
+ * wrapped inCONFIG_DRM_XE_DEBUG.
+ */
+static inline voidxe_configfs_debug_release_config(struct xe_config_device *config){ }
+static inline u32 xe_configfs_get_ctx_restore_mid_bb(structpci_dev*pdev,
+ enumxe_engine_classclass,
+ const u32 **cs) { return 0; }
+static inline u32 xe_configfs_get_ctx_restore_post_bb(structpci_dev*pdev,
+ enumxe_engine_classclass,
+ const u32 **cs) { return 0; }
+static inline u64xe_configfs_get_engines_allowed(struct pci_dev *pdev){ returnU64_MAX; }
+static inline boolxe_configfs_primary_gt_allowed(struct pci_dev *pdev){ return true; }
+static inline boolxe_configfs_media_gt_allowed(struct pci_dev *pdev){ return true; }
+static inline boolxe_configfs_get_enable_multi_queue(struct pci_dev *pdev){ return true; }
+static inline boolxe_configfs_get_psmi_enabled(struct pci_dev *pdev){ return false; }
+static inline boolxe_configfs_get_survivability_mode(struct pci_dev *pdev){ return false; }
#endif
#endif /* _XE_CONFIGFS_DEBUG_H_ */drivers/gpu/drm/xe/xe_configfs_types.h +4
-7@@ -32,13 +32,17 @@ struct xe_config_group_device {* type, entries are sorted alphabetically. */ struct xe_config_device { - struct wa_bb ctx_restore_mid_bb[XE_ENGINE_CLASS_MAX]; - struct wa_bb ctx_restore_post_bb[XE_ENGINE_CLASS_MAX]; - u64 engines_allowed; - u64 gt_types_allowed; - bool enable_multi_queue; - bool enable_psmi; - bool survivability_mode; +#if IS_ENABLED(CONFIG_DRM_XE_DEBUG) + struct { + struct wa_bb ctx_restore_mid_bb[XE_ENGINE_CLASS_MAX]; + struct wa_bbctx_restore_post_bb[XE_ENGINE_CLASS_MAX];
+ u64engines_allowed;
+ u64gt_types_allowed;
+ boolenable_multi_queue;
+ boolenable_psmi;
+ boolsurvivability_mode;
+ } debug;
+#endif
struct {
unsigned intmax_vfs;
booladmin_only_pf;drivers/gpu/drm/xe/xe_guc.c +1
-0@@ -19,6 +19,7 @@ #include "regs/xe_irq_regs.h" #include "xe_bo.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_device.h" #include "xe_force_wake.h" #include "xe_gt.h"drivers/gpu/drm/xe/xe_guc_ads.c +1
-0@@ -17,6 +17,7 @@ #include "regs/xe_guc_regs.h" #include "xe_bo.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_gt.h" #include "xe_gt_ccs_mode.h" #include "xe_gt_mcr.h"drivers/gpu/drm/xe/xe_hw_engine.c +1
-0@@ -18,6 +18,7 @@ #include "xe_assert.h" #include "xe_bo.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_device.h" #include "xe_execlist.h" #include "xe_force_wake.h"drivers/gpu/drm/xe/xe_lrc.c +1
-0@@ -19,6 +19,7 @@ #include "xe_bb.h" #include "xe_bo.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_device.h" #include "xe_drm_client.h" #include "xe_exec_queue.h"drivers/gpu/drm/xe/xe_pci.c +1
-0@@ -19,6 +19,7 @@ #include "regs/xe_gt_regs.h" #include "regs/xe_regs.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_device.h" #include "xe_drv.h" #include "xe_gt.h"drivers/gpu/drm/xe/xe_psmi.c +1
-0@@ -8,6 +8,7 @@ #include "xe_bo.h" #include "xe_device_types.h" #include "xe_configfs.h" +#include "xe_configfs_debug.h" #include "xe_psmi.h"
/*drivers/gpu/drm/xe/xe_rtp.c +0
-0@@ -10,6 +10,7 @@ #include <uapi/drm/xe_drm.h>
#include "xe_configfs.h"
+#include "xe_configfs_debug.h"
#include "xe_device.h"
#include "xe_gt.h"
#include "xe_gt_topology.h"drivers/gpu/drm/xe/xe_survivability_mode.c +0
-0@@ -11,6 +11,7 @@ #include <linux/sysfs.h>
#include "xe_configfs.h"
+#include "xe_configfs_debug.h"
#include "xe_device.h"
#include "xe_heci_gsc.h"
#include "xe_i2c.h"Signature · 1 line
2.43.0