ti_sci_proc.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Texas Instruments TI-SCI Processor Controller Helper Functions
  4. *
  5. * Copyright (C) 2018-2020 Texas Instruments Incorporated - https://www.ti.com/
  6. * Suman Anna <s-anna@ti.com>
  7. */
  8. #ifndef REMOTEPROC_TI_SCI_PROC_H
  9. #define REMOTEPROC_TI_SCI_PROC_H
  10. #include <linux/soc/ti/ti_sci_protocol.h>
  11. /**
  12. * struct ti_sci_proc - structure representing a processor control client
  13. * @sci: cached TI-SCI protocol handle
  14. * @ops: cached TI-SCI proc ops
  15. * @dev: cached client device pointer
  16. * @proc_id: processor id for the consumer remoteproc device
  17. * @host_id: host id to pass the control over for this consumer remoteproc
  18. * device
  19. */
  20. struct ti_sci_proc {
  21. const struct ti_sci_handle *sci;
  22. const struct ti_sci_proc_ops *ops;
  23. struct device *dev;
  24. u8 proc_id;
  25. u8 host_id;
  26. };
  27. static inline
  28. struct ti_sci_proc *ti_sci_proc_of_get_tsp(struct device *dev,
  29. const struct ti_sci_handle *sci)
  30. {
  31. struct ti_sci_proc *tsp;
  32. u32 temp[2];
  33. int ret;
  34. ret = of_property_read_u32_array(dev_of_node(dev), "ti,sci-proc-ids",
  35. temp, 2);
  36. if (ret < 0)
  37. return ERR_PTR(ret);
  38. tsp = devm_kzalloc(dev, sizeof(*tsp), GFP_KERNEL);
  39. if (!tsp)
  40. return ERR_PTR(-ENOMEM);
  41. tsp->dev = dev;
  42. tsp->sci = sci;
  43. tsp->ops = &sci->ops.proc_ops;
  44. tsp->proc_id = temp[0];
  45. tsp->host_id = temp[1];
  46. return tsp;
  47. }
  48. static inline int ti_sci_proc_request(struct ti_sci_proc *tsp)
  49. {
  50. int ret;
  51. ret = tsp->ops->request(tsp->sci, tsp->proc_id);
  52. if (ret)
  53. dev_err(tsp->dev, "ti-sci processor request failed: %d\n",
  54. ret);
  55. return ret;
  56. }
  57. static inline int ti_sci_proc_release(struct ti_sci_proc *tsp)
  58. {
  59. int ret;
  60. ret = tsp->ops->release(tsp->sci, tsp->proc_id);
  61. if (ret)
  62. dev_err(tsp->dev, "ti-sci processor release failed: %d\n",
  63. ret);
  64. return ret;
  65. }
  66. static inline int ti_sci_proc_handover(struct ti_sci_proc *tsp)
  67. {
  68. int ret;
  69. ret = tsp->ops->handover(tsp->sci, tsp->proc_id, tsp->host_id);
  70. if (ret)
  71. dev_err(tsp->dev, "ti-sci processor handover of %d to %d failed: %d\n",
  72. tsp->proc_id, tsp->host_id, ret);
  73. return ret;
  74. }
  75. static inline int ti_sci_proc_set_config(struct ti_sci_proc *tsp,
  76. u64 boot_vector,
  77. u32 cfg_set, u32 cfg_clr)
  78. {
  79. int ret;
  80. ret = tsp->ops->set_config(tsp->sci, tsp->proc_id, boot_vector,
  81. cfg_set, cfg_clr);
  82. if (ret)
  83. dev_err(tsp->dev, "ti-sci processor set_config failed: %d\n",
  84. ret);
  85. return ret;
  86. }
  87. static inline int ti_sci_proc_set_control(struct ti_sci_proc *tsp,
  88. u32 ctrl_set, u32 ctrl_clr)
  89. {
  90. int ret;
  91. ret = tsp->ops->set_control(tsp->sci, tsp->proc_id, ctrl_set, ctrl_clr);
  92. if (ret)
  93. dev_err(tsp->dev, "ti-sci processor set_control failed: %d\n",
  94. ret);
  95. return ret;
  96. }
  97. static inline int ti_sci_proc_get_status(struct ti_sci_proc *tsp,
  98. u64 *boot_vector, u32 *cfg_flags,
  99. u32 *ctrl_flags, u32 *status_flags)
  100. {
  101. int ret;
  102. ret = tsp->ops->get_status(tsp->sci, tsp->proc_id, boot_vector,
  103. cfg_flags, ctrl_flags, status_flags);
  104. if (ret)
  105. dev_err(tsp->dev, "ti-sci processor get_status failed: %d\n",
  106. ret);
  107. return ret;
  108. }
  109. #endif /* REMOTEPROC_TI_SCI_PROC_H */