cdx: create sysfs bin files for cdx resources
PATCH v2 1/2 cdx: create sysfs bin files for cdx resources
Resource binary file contains the content of the memory regions. These resources<x> devices can be used to mmap the MMIO regions in the user-space.
---
Changes in v2:
- None
Documentation/ABI/testing/sysfs-bus-cdx | 7 ++ drivers/cdx/cdx.c | 118 +++++++++++++++++++++++- include/linux/cdx/cdx_bus.h | 10 ++ 3 files changed, 134 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-bus-cdx +7 -0
@@ -98,6 +98,13 @@ Description: # echo 1 > /sys/bus/cdx/devices/.../remove +What: /sys/bus/cdx/devices/.../resource<N> +Date: July 2023 +Contact: [email protected] +Description: + The resource binary file contains the content of the memory + regions. These files can be m'maped from userspace. + What: /sys/bus/cdx/devices/.../modalias Date: July 2023 Contact: [email protected]
drivers/cdx/cdx.c +117 -1
147 lines not on this page · raw message
include/linux/cdx/cdx_bus.h +10 -0
@@ -154,6 +154,7 @@ struct cdx_device {u8 bus_num;u8 dev_num;struct resource res[MAX_CDX_DEV_RESOURCES ]; +struct bin_attribute *res_attr[MAX_CDX_DEV_RESOURCES ];u8 res_count;u64 dma_mask;u16 flags;
@@ -170,6 +171,15 @@ struct cdx_device {#define to_cdx_device (_dev) \ container_of(_dev, struct cdx_device, dev) +#define cdx_resource_start (dev, num) ((dev)->res[(num)].start) +#define cdx_resource_end (dev, num) ((dev)->res[(num)].end) +#define cdx_resource_flags (dev, num) ((dev)->res[(num)].flags) +#define cdx_resource_len (dev, num) \ + ((cdx_resource_start((dev), (num)) == 0 && \ + cdx_resource_end((dev), (num)) == \ + cdx_resource_start((dev), (num))) ? 0 : \ + (cdx_resource_end((dev), (num)) - \ + cdx_resource_start((dev), (num)) + 1))/** * struct cdx_driver - CDX device driver * @driver: Generic device driver
Signature · 1 line
2.34.1
PATCH v2 2/2 cdx: Create resource debugfs file for cdx device
resource debugfs file contains host addresses of CDX device resources. Each line of the resource file describe type of resource, a region with start-end and flag fields.
---
Changes in v2:
- Use printk format %pr for Struct Resources
drivers/cdx/cdx.c | 39 ++++++++++++++++++++++++++++++++++++- include/linux/cdx/cdx_bus.h | 2 ++ 2 files changed, 40 insertions(+), 1 deletion(-)
drivers/cdx/cdx.c +38 -1
@@ -65,6 +65,7 @@#include <linux/cdx/cdx_bus.h> #include <linux/iommu.h> #include <linux/dma-map-ops.h> +#include <linux/debugfs.h> #include "cdx.h" /* Default DMA mask for devices on a CDX bus */
@@ -75,6 +76,8 @@static DEFINE_IDA (cdx_controller_ida);/* Lock to protect controller ops */ static DEFINE_MUTEX (cdx_controller_lock); +/* Debugfs dir for cdx bus */ +static struct dentry *cdx_debugfs_dir;static char *compat_node_name ="xlnx,versal-net-cdx" ;
@@ -149,6 +152,7 @@ static int cdx_unregister_device(struct device *dev, cdx->ops->bus_disable (cdx, cdx_dev->bus_num); }else {cdx_destroy_res_attr (cdx_dev,MAX_CDX_DEV_RESOURCES ); +debugfs_remove_recursive (cdx_dev->debugfs_dir);kfree (cdx_dev->driver_override); cdx_dev->driver_override =NULL ; }
@@ -552,6 +556,31 @@ static const struct attribute_group *cdx_dev_groups[] = { NULL, }; +static int cdx_debug_resource_show (struct seq_file *s,void *data) +{ +struct cdx_device *cdx_dev = s->private; +int i; + +for (i =0 ; i <MAX_CDX_DEV_RESOURCES ; i++) { +struct resource *res = &cdx_dev->res[i]; + +seq_printf (s,"%pr\n" , res); + } + +return 0 ; +} +DEFINE_SHOW_ATTRIBUTE (cdx_debug_resource); + +static void cdx_device_debugfs_init (struct cdx_device *cdx_dev) +{ + cdx_dev->debugfs_dir =debugfs_create_dir (dev_name (&cdx_dev->dev), cdx_debugfs_dir); +if (IS_ERR (cdx_dev->debugfs_dir)) +return ; + +debugfs_create_file ("resource" ,0444 , cdx_dev->debugfs_dir, cdx_dev, + &cdx_debug_resource_fops); +} +static ssize_t rescan_store (const struct bus_type *bus,const char *buf,size_t count) {
@@ -809,6 +838,8 @@ int cdx_device_add(struct cdx_dev_params *dev_params) } } +cdx_device_debugfs_init (cdx_dev); +return 0 ; resource_create_fail:cdx_destroy_res_attr (cdx_dev, i);
@@ -913,6 +944,12 @@ EXPORT_SYMBOL_NS_GPL(cdx_unregister_controller, CDX_BUS_CONTROLLER);static int __init cdx_bus_init (void ) { -return bus_register (&cdx_bus_type); +int ret; + + ret =bus_register (&cdx_bus_type); +if (!ret) + cdx_debugfs_dir =debugfs_create_dir (cdx_bus_type.name,NULL ); + +return ret; }postcore_initcall (cdx_bus_init);
include/linux/cdx/cdx_bus.h +2 -0
@@ -128,6 +128,7 @@ struct cdx_controller {* @dev_num: Device number for this device * @res: array of MMIO region entries * @res_attr: resource binary attribute +* @debugfs_dir: debugfs directory for this device * @res_count: number of valid MMIO regions * @dma_mask: Default DMA mask * @flags: CDX device flags
@@ -155,6 +156,7 @@ struct cdx_device {u8 dev_num;struct resource res[MAX_CDX_DEV_RESOURCES ];struct bin_attribute *res_attr[MAX_CDX_DEV_RESOURCES ]; +struct dentry *debugfs_dir;u8 res_count;u64 dma_mask;u16 flags;
Signature · 1 line
2.34.1
Quoted 10 lines
Subject: [PATCH v2 1/2] cdx: create sysfs bin files for cdx resources
Resource binary file contains the content of the memory regions. These resources<x> devices can be used to mmap the MMIO regions in the user-space.
Co-developed-by Puneet Gupta <[email protected]>Signed-off-by Puneet Gupta <[email protected]>Signed-off-by Abhijit Gangurde <[email protected]>---
Hi Greg,
Could you please review this patch series?
Thanks,
Abhijit
Quoted 6 lines · Abhijit
Quoted 6 lines
Subject: [PATCH v2 1/2] cdx: create sysfs bin files for cdx resources
Resource binary file contains the content of the memory regions. These resources<x> devices can be used to mmap the MMIO regions in the user-space.
Quoted 7 lines
Quoted 4 lines
Co-developed-by Puneet Gupta <[email protected]>Signed-off-by Puneet Gupta <[email protected]>Signed-off-by Abhijit Gangurde <[email protected]>---
Hi Greg,
Could you please review this patch series?
It's not in my review queue anymore at all, if it's still needed, please resend.
thanks,
greg k-hj