@@ -1715,7 +1715,7 @@ static int rproc_stop(struct rproc *rproc, bool crashed)
1715
1715
/*
1716
1716
* __rproc_detach(): Does the opposite of __rproc_attach()
1717
1717
*/
1718
- static int __maybe_unused __rproc_detach (struct rproc * rproc )
1718
+ static int __rproc_detach (struct rproc * rproc )
1719
1719
{
1720
1720
struct device * dev = & rproc -> dev ;
1721
1721
int ret ;
@@ -1954,6 +1954,62 @@ void rproc_shutdown(struct rproc *rproc)
1954
1954
}
1955
1955
EXPORT_SYMBOL (rproc_shutdown );
1956
1956
1957
+ /**
1958
+ * rproc_detach() - Detach the remote processor from the
1959
+ * remoteproc core
1960
+ *
1961
+ * @rproc: the remote processor
1962
+ *
1963
+ * Detach a remote processor (previously attached to with rproc_attach()).
1964
+ *
1965
+ * In case @rproc is still being used by an additional user(s), then
1966
+ * this function will just decrement the power refcount and exit,
1967
+ * without disconnecting the device.
1968
+ *
1969
+ * Function rproc_detach() calls __rproc_detach() in order to let a remote
1970
+ * processor know that services provided by the application processor are
1971
+ * no longer available. From there it should be possible to remove the
1972
+ * platform driver and even power cycle the application processor (if the HW
1973
+ * supports it) without needing to switch off the remote processor.
1974
+ */
1975
+ int rproc_detach (struct rproc * rproc )
1976
+ {
1977
+ struct device * dev = & rproc -> dev ;
1978
+ int ret ;
1979
+
1980
+ ret = mutex_lock_interruptible (& rproc -> lock );
1981
+ if (ret ) {
1982
+ dev_err (dev , "can't lock rproc %s: %d\n" , rproc -> name , ret );
1983
+ return ret ;
1984
+ }
1985
+
1986
+ /* if the remote proc is still needed, bail out */
1987
+ if (!atomic_dec_and_test (& rproc -> power )) {
1988
+ ret = 0 ;
1989
+ goto out ;
1990
+ }
1991
+
1992
+ ret = __rproc_detach (rproc );
1993
+ if (ret ) {
1994
+ atomic_inc (& rproc -> power );
1995
+ goto out ;
1996
+ }
1997
+
1998
+ /* clean up all acquired resources */
1999
+ rproc_resource_cleanup (rproc );
2000
+
2001
+ /* release HW resources if needed */
2002
+ rproc_unprepare_device (rproc );
2003
+
2004
+ rproc_disable_iommu (rproc );
2005
+
2006
+ rproc -> table_ptr = NULL ;
2007
+ out :
2008
+ mutex_unlock (& rproc -> lock );
2009
+ return ret ;
2010
+ }
2011
+ EXPORT_SYMBOL (rproc_detach );
2012
+
1957
2013
/**
1958
2014
* rproc_get_by_phandle() - find a remote processor by phandle
1959
2015
* @phandle: phandle to the rproc
0 commit comments