@@ -66,10 +66,13 @@ static enum cpuhp_state hp_online;
66
66
67
67
struct etm4_init_arg {
68
68
unsigned int pid ;
69
- struct etmv4_drvdata * drvdata ;
69
+ struct device * dev ;
70
70
struct csdev_access * csa ;
71
71
};
72
72
73
+ static DEFINE_PER_CPU (struct etm4_init_arg * , delayed_probe ) ;
74
+ static int etm4_probe_cpu (unsigned int cpu );
75
+
73
76
/*
74
77
* Check if TRCSSPCICRn(i) is implemented for a given instance.
75
78
*
@@ -1085,7 +1088,7 @@ static void etm4_init_arch_data(void *info)
1085
1088
struct csdev_access * csa ;
1086
1089
int i ;
1087
1090
1088
- drvdata = init_arg -> drvdata ;
1091
+ drvdata = dev_get_drvdata ( init_arg -> dev ) ;
1089
1092
csa = init_arg -> csa ;
1090
1093
1091
1094
/*
@@ -1478,7 +1481,7 @@ static int etm4_set_event_filters(struct etmv4_drvdata *drvdata,
1478
1481
/*
1479
1482
* If filters::ssstatus == 1, trace acquisition was
1480
1483
* started but the process was yanked away before the
1481
- * the stop address was hit. As such the start/stop
1484
+ * stop address was hit. As such the start/stop
1482
1485
* logic needs to be re-started so that tracing can
1483
1486
* resume where it left.
1484
1487
*
@@ -1528,7 +1531,7 @@ void etm4_config_trace_mode(struct etmv4_config *config)
1528
1531
static int etm4_online_cpu (unsigned int cpu )
1529
1532
{
1530
1533
if (!etmdrvdata [cpu ])
1531
- return 0 ;
1534
+ return etm4_probe_cpu ( cpu ) ;
1532
1535
1533
1536
if (etmdrvdata [cpu ]-> boot_enable && !etmdrvdata [cpu ]-> sticky_enable )
1534
1537
coresight_enable (etmdrvdata [cpu ]-> csdev );
@@ -1904,48 +1907,20 @@ static void etm4_pm_clear(void)
1904
1907
}
1905
1908
}
1906
1909
1907
- static int etm4_probe (struct device * dev , void __iomem * base , u32 etm_pid )
1910
+ static int etm4_add_coresight_dev (struct etm4_init_arg * init_arg )
1908
1911
{
1909
1912
int ret ;
1910
1913
struct coresight_platform_data * pdata = NULL ;
1911
- struct etmv4_drvdata * drvdata ;
1914
+ struct device * dev = init_arg -> dev ;
1915
+ struct etmv4_drvdata * drvdata = dev_get_drvdata (dev );
1912
1916
struct coresight_desc desc = { 0 };
1913
- struct etm4_init_arg init_arg = { 0 };
1914
1917
u8 major , minor ;
1915
1918
char * type_name ;
1916
1919
1917
- drvdata = devm_kzalloc (dev , sizeof (* drvdata ), GFP_KERNEL );
1918
1920
if (!drvdata )
1919
- return - ENOMEM ;
1920
-
1921
- dev_set_drvdata (dev , drvdata );
1922
-
1923
- if (pm_save_enable == PARAM_PM_SAVE_FIRMWARE )
1924
- pm_save_enable = coresight_loses_context_with_cpu (dev ) ?
1925
- PARAM_PM_SAVE_SELF_HOSTED : PARAM_PM_SAVE_NEVER ;
1926
-
1927
- if (pm_save_enable != PARAM_PM_SAVE_NEVER ) {
1928
- drvdata -> save_state = devm_kmalloc (dev ,
1929
- sizeof (struct etmv4_save_state ), GFP_KERNEL );
1930
- if (!drvdata -> save_state )
1931
- return - ENOMEM ;
1932
- }
1933
-
1934
- drvdata -> base = base ;
1935
-
1936
- spin_lock_init (& drvdata -> spinlock );
1937
-
1938
- drvdata -> cpu = coresight_get_cpu (dev );
1939
- if (drvdata -> cpu < 0 )
1940
- return drvdata -> cpu ;
1941
-
1942
- init_arg .drvdata = drvdata ;
1943
- init_arg .csa = & desc .access ;
1944
- init_arg .pid = etm_pid ;
1921
+ return - EINVAL ;
1945
1922
1946
- if (smp_call_function_single (drvdata -> cpu ,
1947
- etm4_init_arch_data , & init_arg , 1 ))
1948
- dev_err (dev , "ETM arch init failed\n" );
1923
+ desc .access = * init_arg -> csa ;
1949
1924
1950
1925
if (!drvdata -> arch )
1951
1926
return - EINVAL ;
@@ -2016,6 +1991,68 @@ static int etm4_probe(struct device *dev, void __iomem *base, u32 etm_pid)
2016
1991
return 0 ;
2017
1992
}
2018
1993
1994
+ static int etm4_probe (struct device * dev , void __iomem * base , u32 etm_pid )
1995
+ {
1996
+ struct etmv4_drvdata * drvdata ;
1997
+ struct csdev_access access = { 0 };
1998
+ struct etm4_init_arg init_arg = { 0 };
1999
+ struct etm4_init_arg * delayed ;
2000
+
2001
+ drvdata = devm_kzalloc (dev , sizeof (* drvdata ), GFP_KERNEL );
2002
+ if (!drvdata )
2003
+ return - ENOMEM ;
2004
+
2005
+ dev_set_drvdata (dev , drvdata );
2006
+
2007
+ if (pm_save_enable == PARAM_PM_SAVE_FIRMWARE )
2008
+ pm_save_enable = coresight_loses_context_with_cpu (dev ) ?
2009
+ PARAM_PM_SAVE_SELF_HOSTED : PARAM_PM_SAVE_NEVER ;
2010
+
2011
+ if (pm_save_enable != PARAM_PM_SAVE_NEVER ) {
2012
+ drvdata -> save_state = devm_kmalloc (dev ,
2013
+ sizeof (struct etmv4_save_state ), GFP_KERNEL );
2014
+ if (!drvdata -> save_state )
2015
+ return - ENOMEM ;
2016
+ }
2017
+
2018
+ drvdata -> base = base ;
2019
+
2020
+ spin_lock_init (& drvdata -> spinlock );
2021
+
2022
+ drvdata -> cpu = coresight_get_cpu (dev );
2023
+ if (drvdata -> cpu < 0 )
2024
+ return drvdata -> cpu ;
2025
+
2026
+ init_arg .dev = dev ;
2027
+ init_arg .csa = & access ;
2028
+ init_arg .pid = etm_pid ;
2029
+
2030
+ /*
2031
+ * Serialize against CPUHP callbacks to avoid race condition
2032
+ * between the smp call and saving the delayed probe.
2033
+ */
2034
+ cpus_read_lock ();
2035
+ if (smp_call_function_single (drvdata -> cpu ,
2036
+ etm4_init_arch_data , & init_arg , 1 )) {
2037
+ /* The CPU was offline, try again once it comes online. */
2038
+ delayed = devm_kmalloc (dev , sizeof (* delayed ), GFP_KERNEL );
2039
+ if (!delayed ) {
2040
+ cpus_read_unlock ();
2041
+ return - ENOMEM ;
2042
+ }
2043
+
2044
+ * delayed = init_arg ;
2045
+
2046
+ per_cpu (delayed_probe , drvdata -> cpu ) = delayed ;
2047
+
2048
+ cpus_read_unlock ();
2049
+ return 0 ;
2050
+ }
2051
+ cpus_read_unlock ();
2052
+
2053
+ return etm4_add_coresight_dev (& init_arg );
2054
+ }
2055
+
2019
2056
static int etm4_probe_amba (struct amba_device * adev , const struct amba_id * id )
2020
2057
{
2021
2058
void __iomem * base ;
@@ -2054,6 +2091,35 @@ static int etm4_probe_platform_dev(struct platform_device *pdev)
2054
2091
return ret ;
2055
2092
}
2056
2093
2094
+ static int etm4_probe_cpu (unsigned int cpu )
2095
+ {
2096
+ int ret ;
2097
+ struct etm4_init_arg init_arg ;
2098
+ struct csdev_access access = { 0 };
2099
+ struct etm4_init_arg * iap = * this_cpu_ptr (& delayed_probe );
2100
+
2101
+ if (!iap )
2102
+ return 0 ;
2103
+
2104
+ init_arg = * iap ;
2105
+ devm_kfree (init_arg .dev , iap );
2106
+ * this_cpu_ptr (& delayed_probe ) = NULL ;
2107
+
2108
+ ret = pm_runtime_resume_and_get (init_arg .dev );
2109
+ if (ret < 0 ) {
2110
+ dev_err (init_arg .dev , "Failed to get PM runtime!\n" );
2111
+ return 0 ;
2112
+ }
2113
+
2114
+ init_arg .csa = & access ;
2115
+ etm4_init_arch_data (& init_arg );
2116
+
2117
+ etm4_add_coresight_dev (& init_arg );
2118
+
2119
+ pm_runtime_put (init_arg .dev );
2120
+ return 0 ;
2121
+ }
2122
+
2057
2123
static struct amba_cs_uci_id uci_id_etm4 [] = {
2058
2124
{
2059
2125
/* ETMv4 UCI data */
@@ -2068,29 +2134,36 @@ static void clear_etmdrvdata(void *info)
2068
2134
int cpu = * (int * )info ;
2069
2135
2070
2136
etmdrvdata [cpu ] = NULL ;
2137
+ per_cpu (delayed_probe , cpu ) = NULL ;
2071
2138
}
2072
2139
2073
2140
static int __exit etm4_remove_dev (struct etmv4_drvdata * drvdata )
2074
2141
{
2075
- etm_perf_symlink ( drvdata -> csdev , false) ;
2142
+ bool had_delayed_probe ;
2076
2143
/*
2077
2144
* Taking hotplug lock here to avoid racing between etm4_remove_dev()
2078
2145
* and CPU hotplug call backs.
2079
2146
*/
2080
2147
cpus_read_lock ();
2148
+
2149
+ had_delayed_probe = per_cpu (delayed_probe , drvdata -> cpu );
2150
+
2081
2151
/*
2082
2152
* The readers for etmdrvdata[] are CPU hotplug call backs
2083
2153
* and PM notification call backs. Change etmdrvdata[i] on
2084
2154
* CPU i ensures these call backs has consistent view
2085
2155
* inside one call back function.
2086
2156
*/
2087
2157
if (smp_call_function_single (drvdata -> cpu , clear_etmdrvdata , & drvdata -> cpu , 1 ))
2088
- etmdrvdata [ drvdata -> cpu ] = NULL ;
2158
+ clear_etmdrvdata ( & drvdata -> cpu ) ;
2089
2159
2090
2160
cpus_read_unlock ();
2091
2161
2092
- cscfg_unregister_csdev (drvdata -> csdev );
2093
- coresight_unregister (drvdata -> csdev );
2162
+ if (!had_delayed_probe ) {
2163
+ etm_perf_symlink (drvdata -> csdev , false);
2164
+ cscfg_unregister_csdev (drvdata -> csdev );
2165
+ coresight_unregister (drvdata -> csdev );
2166
+ }
2094
2167
2095
2168
return 0 ;
2096
2169
}
0 commit comments