Skip to content

Commit dbd43f4

Browse files
edimoldovanclaude
andcommitted
iommu: apple-dart: probe a manual-availability DART after its client
A DART marked apple,manual-availability defers its probe until its client calls apple_dart_make_available() for its node. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8805d27 commit dbd43f4

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

‎drivers/iommu/apple-dart.c‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2850,6 +2850,43 @@ apple_dart_platform_ioremap_np_resource(struct platform_device *pdev,
28502850
return regs;
28512851
}
28522852

2853+
struct apple_dart_available {
2854+
struct list_head list;
2855+
struct device_node *np;
2856+
};
2857+
2858+
static DEFINE_MUTEX(apple_dart_available_lock);
2859+
static LIST_HEAD(apple_dart_available_list);
2860+
2861+
void apple_dart_make_available(struct device_node *np)
2862+
{
2863+
struct apple_dart_available *a;
2864+
2865+
guard(mutex)(&apple_dart_available_lock);
2866+
list_for_each_entry(a, &apple_dart_available_list, list)
2867+
if (a->np == np)
2868+
return;
2869+
a = kzalloc(sizeof(*a), GFP_KERNEL);
2870+
if (!a)
2871+
return;
2872+
a->np = of_node_get(np);
2873+
list_add(&a->list, &apple_dart_available_list);
2874+
}
2875+
EXPORT_SYMBOL_GPL(apple_dart_make_available);
2876+
2877+
static bool apple_dart_is_available(struct device_node *np)
2878+
{
2879+
struct apple_dart_available *a;
2880+
2881+
if (!of_property_read_bool(np, "apple,manual-availability"))
2882+
return true;
2883+
guard(mutex)(&apple_dart_available_lock);
2884+
list_for_each_entry(a, &apple_dart_available_list, list)
2885+
if (a->np == np)
2886+
return true;
2887+
return false;
2888+
}
2889+
28532890
static int apple_dart_probe(struct platform_device *pdev)
28542891
{
28552892
int ret, sid;
@@ -2863,6 +2900,10 @@ static int apple_dart_probe(struct platform_device *pdev)
28632900
of_node_name_prefix(dev->of_node->parent,
28642901
"usb4-pcie-tunnel-");
28652902

2903+
/* Its registers answer only once its client is up */
2904+
if (!apple_dart_is_available(dev->of_node))
2905+
return dev_err_probe(dev, -EPROBE_DEFER, "waiting for its client\n");
2906+
28662907
dart = devm_kzalloc(dev, sizeof(*dart), GFP_KERNEL);
28672908
if (!dart)
28682909
return -ENOMEM;

‎include/linux/soc/apple/dart.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/errno.h>
77

88
struct device;
9+
struct device_node;
910

1011
/*
1112
* The tunneled PCIe IOMMU shares the port clock. Stop issuing commands
@@ -23,4 +24,14 @@ static inline int apple_dart_save_tunnel_state(struct device *dev) { return -EOP
2324
static inline int apple_dart_restore_tunnel_state(struct device *dev) { return -EOPNOTSUPP; }
2425
#endif
2526

27+
/*
28+
* A DART marked apple,manual-availability answers only once its client (a
29+
* PCIe root complex) is up. The client makes it available, and it probes then.
30+
*/
31+
#if IS_ENABLED(CONFIG_APPLE_DART)
32+
void apple_dart_make_available(struct device_node *np);
33+
#else
34+
static inline void apple_dart_make_available(struct device_node *np) { }
35+
#endif
36+
2637
#endif

0 commit comments

Comments
 (0)