qcom_common.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * Qualcomm Peripheral Image Loader helpers
  3. *
  4. * Copyright (C) 2016 Linaro Ltd
  5. * Copyright (C) 2015 Sony Mobile Communications Inc
  6. * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/firmware.h>
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/notifier.h>
  21. #include <linux/remoteproc.h>
  22. #include <linux/rpmsg/qcom_glink.h>
  23. #include <linux/rpmsg/qcom_smd.h>
  24. #include "remoteproc_internal.h"
  25. #include "qcom_common.h"
  26. #define to_glink_subdev(d) container_of(d, struct qcom_rproc_glink, subdev)
  27. #define to_smd_subdev(d) container_of(d, struct qcom_rproc_subdev, subdev)
  28. #define to_ssr_subdev(d) container_of(d, struct qcom_rproc_ssr, subdev)
  29. static BLOCKING_NOTIFIER_HEAD(ssr_notifiers);
  30. /**
  31. * qcom_mdt_find_rsc_table() - provide dummy resource table for remoteproc
  32. * @rproc: remoteproc handle
  33. * @fw: firmware header
  34. * @tablesz: outgoing size of the table
  35. *
  36. * Returns a dummy table.
  37. */
  38. struct resource_table *qcom_mdt_find_rsc_table(struct rproc *rproc,
  39. const struct firmware *fw,
  40. int *tablesz)
  41. {
  42. static struct resource_table table = { .ver = 1, };
  43. *tablesz = sizeof(table);
  44. return &table;
  45. }
  46. EXPORT_SYMBOL_GPL(qcom_mdt_find_rsc_table);
  47. static int glink_subdev_probe(struct rproc_subdev *subdev)
  48. {
  49. struct qcom_rproc_glink *glink = to_glink_subdev(subdev);
  50. glink->edge = qcom_glink_smem_register(glink->dev, glink->node);
  51. return IS_ERR(glink->edge) ? PTR_ERR(glink->edge) : 0;
  52. }
  53. static void glink_subdev_remove(struct rproc_subdev *subdev)
  54. {
  55. struct qcom_rproc_glink *glink = to_glink_subdev(subdev);
  56. qcom_glink_smem_unregister(glink->edge);
  57. glink->edge = NULL;
  58. }
  59. /**
  60. * qcom_add_glink_subdev() - try to add a GLINK subdevice to rproc
  61. * @rproc: rproc handle to parent the subdevice
  62. * @glink: reference to a GLINK subdev context
  63. */
  64. void qcom_add_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink)
  65. {
  66. struct device *dev = &rproc->dev;
  67. glink->node = of_get_child_by_name(dev->parent->of_node, "glink-edge");
  68. if (!glink->node)
  69. return;
  70. glink->dev = dev;
  71. rproc_add_subdev(rproc, &glink->subdev, glink_subdev_probe, glink_subdev_remove);
  72. }
  73. EXPORT_SYMBOL_GPL(qcom_add_glink_subdev);
  74. /**
  75. * qcom_remove_glink_subdev() - remove a GLINK subdevice from rproc
  76. * @rproc: rproc handle
  77. * @glink: reference to a GLINK subdev context
  78. */
  79. void qcom_remove_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink)
  80. {
  81. rproc_remove_subdev(rproc, &glink->subdev);
  82. of_node_put(glink->node);
  83. }
  84. EXPORT_SYMBOL_GPL(qcom_remove_glink_subdev);
  85. static int smd_subdev_probe(struct rproc_subdev *subdev)
  86. {
  87. struct qcom_rproc_subdev *smd = to_smd_subdev(subdev);
  88. smd->edge = qcom_smd_register_edge(smd->dev, smd->node);
  89. return PTR_ERR_OR_ZERO(smd->edge);
  90. }
  91. static void smd_subdev_remove(struct rproc_subdev *subdev)
  92. {
  93. struct qcom_rproc_subdev *smd = to_smd_subdev(subdev);
  94. qcom_smd_unregister_edge(smd->edge);
  95. smd->edge = NULL;
  96. }
  97. /**
  98. * qcom_add_smd_subdev() - try to add a SMD subdevice to rproc
  99. * @rproc: rproc handle to parent the subdevice
  100. * @smd: reference to a Qualcomm subdev context
  101. */
  102. void qcom_add_smd_subdev(struct rproc *rproc, struct qcom_rproc_subdev *smd)
  103. {
  104. struct device *dev = &rproc->dev;
  105. smd->node = of_get_child_by_name(dev->parent->of_node, "smd-edge");
  106. if (!smd->node)
  107. return;
  108. smd->dev = dev;
  109. rproc_add_subdev(rproc, &smd->subdev, smd_subdev_probe, smd_subdev_remove);
  110. }
  111. EXPORT_SYMBOL_GPL(qcom_add_smd_subdev);
  112. /**
  113. * qcom_remove_smd_subdev() - remove the smd subdevice from rproc
  114. * @rproc: rproc handle
  115. * @smd: the SMD subdevice to remove
  116. */
  117. void qcom_remove_smd_subdev(struct rproc *rproc, struct qcom_rproc_subdev *smd)
  118. {
  119. rproc_remove_subdev(rproc, &smd->subdev);
  120. of_node_put(smd->node);
  121. }
  122. EXPORT_SYMBOL_GPL(qcom_remove_smd_subdev);
  123. /**
  124. * qcom_register_ssr_notifier() - register SSR notification handler
  125. * @nb: notifier_block to notify for restart notifications
  126. *
  127. * Returns 0 on success, negative errno on failure.
  128. *
  129. * This register the @notify function as handler for restart notifications. As
  130. * remote processors are stopped this function will be called, with the SSR
  131. * name passed as a parameter.
  132. */
  133. int qcom_register_ssr_notifier(struct notifier_block *nb)
  134. {
  135. return blocking_notifier_chain_register(&ssr_notifiers, nb);
  136. }
  137. EXPORT_SYMBOL_GPL(qcom_register_ssr_notifier);
  138. /**
  139. * qcom_unregister_ssr_notifier() - unregister SSR notification handler
  140. * @nb: notifier_block to unregister
  141. */
  142. void qcom_unregister_ssr_notifier(struct notifier_block *nb)
  143. {
  144. blocking_notifier_chain_unregister(&ssr_notifiers, nb);
  145. }
  146. EXPORT_SYMBOL_GPL(qcom_unregister_ssr_notifier);
  147. static int ssr_notify_start(struct rproc_subdev *subdev)
  148. {
  149. return 0;
  150. }
  151. static void ssr_notify_stop(struct rproc_subdev *subdev)
  152. {
  153. struct qcom_rproc_ssr *ssr = to_ssr_subdev(subdev);
  154. blocking_notifier_call_chain(&ssr_notifiers, 0, (void *)ssr->name);
  155. }
  156. /**
  157. * qcom_add_ssr_subdev() - register subdevice as restart notification source
  158. * @rproc: rproc handle
  159. * @ssr: SSR subdevice handle
  160. * @ssr_name: identifier to use for notifications originating from @rproc
  161. *
  162. * As the @ssr is registered with the @rproc SSR events will be sent to all
  163. * registered listeners in the system as the remoteproc is shut down.
  164. */
  165. void qcom_add_ssr_subdev(struct rproc *rproc, struct qcom_rproc_ssr *ssr,
  166. const char *ssr_name)
  167. {
  168. ssr->name = ssr_name;
  169. rproc_add_subdev(rproc, &ssr->subdev, ssr_notify_start, ssr_notify_stop);
  170. }
  171. EXPORT_SYMBOL_GPL(qcom_add_ssr_subdev);
  172. /**
  173. * qcom_remove_ssr_subdev() - remove subdevice as restart notification source
  174. * @rproc: rproc handle
  175. * @ssr: SSR subdevice handle
  176. */
  177. void qcom_remove_ssr_subdev(struct rproc *rproc, struct qcom_rproc_ssr *ssr)
  178. {
  179. rproc_remove_subdev(rproc, &ssr->subdev);
  180. }
  181. EXPORT_SYMBOL_GPL(qcom_remove_ssr_subdev);
  182. MODULE_DESCRIPTION("Qualcomm Remoteproc helper driver");
  183. MODULE_LICENSE("GPL v2");