ti_sci_proc.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Texas Instruments TI-SCI Processor Controller Helper Functions
  4. *
  5. * Copyright (C) 2018-2019 Texas Instruments Incorporated - http://www.ti.com/
  6. * Lokesh Vutla <lokeshvutla@ti.com>
  7. * Suman Anna <s-anna@ti.com>
  8. */
  9. #ifndef REMOTEPROC_TI_SCI_PROC_H
  10. #define REMOTEPROC_TI_SCI_PROC_H
  11. #define TISCI_INVALID_HOST 0xff
  12. /**
  13. * struct ti_sci_proc - structure representing a processor control client
  14. * @sci: cached TI-SCI protocol handle
  15. * @ops: cached TI-SCI proc ops
  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. * @dev_id: Device ID as identified by system controller.
  20. */
  21. struct ti_sci_proc {
  22. const struct ti_sci_handle *sci;
  23. const struct ti_sci_proc_ops *ops;
  24. u8 proc_id;
  25. u8 host_id;
  26. u16 dev_id;
  27. };
  28. static inline int ti_sci_proc_request(struct ti_sci_proc *tsp)
  29. {
  30. int ret;
  31. debug("%s: proc_id = %d\n", __func__, tsp->proc_id);
  32. ret = tsp->ops->proc_request(tsp->sci, tsp->proc_id);
  33. if (ret)
  34. pr_err("ti-sci processor request failed: %d\n", ret);
  35. return ret;
  36. }
  37. static inline int ti_sci_proc_release(struct ti_sci_proc *tsp)
  38. {
  39. int ret;
  40. debug("%s: proc_id = %d\n", __func__, tsp->proc_id);
  41. if (tsp->host_id != TISCI_INVALID_HOST)
  42. ret = tsp->ops->proc_handover(tsp->sci, tsp->proc_id,
  43. tsp->host_id);
  44. else
  45. ret = tsp->ops->proc_release(tsp->sci, tsp->proc_id);
  46. if (ret)
  47. pr_err("ti-sci processor release failed: %d\n", ret);
  48. return ret;
  49. }
  50. static inline int ti_sci_proc_handover(struct ti_sci_proc *tsp)
  51. {
  52. int ret;
  53. debug("%s: proc_id = %d\n", __func__, tsp->proc_id);
  54. ret = tsp->ops->proc_handover(tsp->sci, tsp->proc_id, tsp->host_id);
  55. if (ret)
  56. pr_err("ti-sci processor handover of %d to %d failed: %d\n",
  57. tsp->proc_id, tsp->host_id, ret);
  58. return ret;
  59. }
  60. static inline int ti_sci_proc_get_status(struct ti_sci_proc *tsp,
  61. u64 *boot_vector, u32 *cfg_flags,
  62. u32 *ctrl_flags, u32 *status_flags)
  63. {
  64. int ret;
  65. ret = tsp->ops->get_proc_boot_status(tsp->sci, tsp->proc_id,
  66. boot_vector, cfg_flags, ctrl_flags,
  67. status_flags);
  68. if (ret)
  69. pr_err("ti-sci processor get_status failed: %d\n", ret);
  70. debug("%s: proc_id = %d, boot_vector = 0x%llx, cfg_flags = 0x%x, ctrl_flags = 0x%x, sts = 0x%x\n",
  71. __func__, tsp->proc_id, *boot_vector, *cfg_flags, *ctrl_flags,
  72. *status_flags);
  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. debug("%s: proc_id = %d, boot_vector = 0x%llx, cfg_set = 0x%x, cfg_clr = 0x%x\n",
  81. __func__, tsp->proc_id, boot_vector, cfg_set, cfg_clr);
  82. ret = tsp->ops->set_proc_boot_cfg(tsp->sci, tsp->proc_id, boot_vector,
  83. cfg_set, cfg_clr);
  84. if (ret)
  85. pr_err("ti-sci processor set_config failed: %d\n", ret);
  86. return ret;
  87. }
  88. static inline int ti_sci_proc_set_control(struct ti_sci_proc *tsp,
  89. u32 ctrl_set, u32 ctrl_clr)
  90. {
  91. int ret;
  92. debug("%s: proc_id = %d, ctrl_set = 0x%x, ctrl_clr = 0x%x\n", __func__,
  93. tsp->proc_id, ctrl_set, ctrl_clr);
  94. ret = tsp->ops->set_proc_boot_ctrl(tsp->sci, tsp->proc_id, ctrl_set,
  95. ctrl_clr);
  96. if (ret)
  97. pr_err("ti-sci processor set_control failed: %d\n", ret);
  98. return ret;
  99. }
  100. static inline int ti_sci_proc_power_domain_on(struct ti_sci_proc *tsp)
  101. {
  102. int ret;
  103. debug("%s: dev_id = %d\n", __func__, tsp->dev_id);
  104. ret = tsp->sci->ops.dev_ops.get_device_exclusive(tsp->sci, tsp->dev_id);
  105. if (ret)
  106. pr_err("Power-domain on failed for dev = %d\n", tsp->dev_id);
  107. return ret;
  108. }
  109. static inline int ti_sci_proc_power_domain_off(struct ti_sci_proc *tsp)
  110. {
  111. int ret;
  112. debug("%s: dev_id = %d\n", __func__, tsp->dev_id);
  113. ret = tsp->sci->ops.dev_ops.put_device(tsp->sci, tsp->dev_id);
  114. if (ret)
  115. pr_err("Power-domain off failed for dev = %d\n", tsp->dev_id);
  116. return ret;
  117. }
  118. #endif /* REMOTEPROC_TI_SCI_PROC_H */