60
60
#include <linux/of_device.h>
61
61
#include <linux/slab.h>
62
62
#include <linux/mm.h>
63
- #include <linux/xarray .h>
63
+ #include <linux/idr .h>
64
64
#include <linux/cdx/cdx_bus.h>
65
65
#include <linux/iommu.h>
66
66
#include <linux/dma-map-ops.h>
70
70
#define CDX_DEFAULT_DMA_MASK (~0ULL)
71
71
#define MAX_CDX_CONTROLLERS 16
72
72
73
- /* CDX controllers registered with the CDX bus */
74
- static DEFINE_XARRAY_ALLOC (cdx_controllers );
73
+ /* IDA for CDX controllers registered with the CDX bus */
74
+ static DEFINE_IDA (cdx_controller_ida );
75
+
76
+ static char * compat_node_name = "xlnx,versal-net-cdx" ;
75
77
76
78
/**
77
79
* cdx_dev_reset - Reset a CDX device
@@ -384,7 +386,8 @@ static ssize_t rescan_store(const struct bus_type *bus,
384
386
const char * buf , size_t count )
385
387
{
386
388
struct cdx_controller * cdx ;
387
- unsigned long index ;
389
+ struct platform_device * pd ;
390
+ struct device_node * np ;
388
391
bool val ;
389
392
390
393
if (kstrtobool (buf , & val ) < 0 )
@@ -397,12 +400,19 @@ static ssize_t rescan_store(const struct bus_type *bus,
397
400
cdx_unregister_devices (& cdx_bus_type );
398
401
399
402
/* Rescan all the devices */
400
- xa_for_each (& cdx_controllers , index , cdx ) {
401
- int ret ;
403
+ for_each_compatible_node (np , NULL , compat_node_name ) {
404
+ if (!np )
405
+ return - EINVAL ;
402
406
403
- ret = cdx -> ops -> scan (cdx );
404
- if (ret )
405
- dev_err (cdx -> dev , "cdx bus scanning failed\n" );
407
+ pd = of_find_device_by_node (np );
408
+ if (!pd )
409
+ return - EINVAL ;
410
+
411
+ cdx = platform_get_drvdata (pd );
412
+ if (cdx && cdx -> controller_registered && cdx -> ops -> scan )
413
+ cdx -> ops -> scan (cdx );
414
+
415
+ put_device (& pd -> dev );
406
416
}
407
417
408
418
return count ;
@@ -520,17 +530,20 @@ int cdx_register_controller(struct cdx_controller *cdx)
520
530
{
521
531
int ret ;
522
532
523
- ret = xa_alloc (& cdx_controllers , & cdx -> id , cdx ,
524
- XA_LIMIT (0 , MAX_CDX_CONTROLLERS - 1 ), GFP_KERNEL );
525
- if (ret ) {
533
+ ret = ida_alloc_range (& cdx_controller_ida , 0 , MAX_CDX_CONTROLLERS - 1 , GFP_KERNEL );
534
+ if (ret < 0 ) {
526
535
dev_err (cdx -> dev ,
527
536
"No free index available. Maximum controllers already registered\n" );
528
537
cdx -> id = (u8 )MAX_CDX_CONTROLLERS ;
529
538
return ret ;
530
539
}
531
540
541
+ cdx -> id = ret ;
542
+
532
543
/* Scan all the devices */
533
- cdx -> ops -> scan (cdx );
544
+ if (cdx -> ops -> scan )
545
+ cdx -> ops -> scan (cdx );
546
+ cdx -> controller_registered = true;
534
547
535
548
return 0 ;
536
549
}
@@ -541,8 +554,9 @@ void cdx_unregister_controller(struct cdx_controller *cdx)
541
554
if (cdx -> id >= MAX_CDX_CONTROLLERS )
542
555
return ;
543
556
557
+ cdx -> controller_registered = false;
544
558
device_for_each_child (cdx -> dev , NULL , cdx_unregister_device );
545
- xa_erase ( & cdx_controllers , cdx -> id );
559
+ ida_free ( & cdx_controller_ida , cdx -> id );
546
560
}
547
561
EXPORT_SYMBOL_GPL (cdx_unregister_controller );
548
562
0 commit comments