remoteproc_internal.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Remote processor framework
  4. *
  5. * Copyright (C) 2011 Texas Instruments, Inc.
  6. * Copyright (C) 2011 Google, Inc.
  7. *
  8. * Ohad Ben-Cohen <ohad@wizery.com>
  9. * Brian Swetland <swetland@google.com>
  10. */
  11. #ifndef REMOTEPROC_INTERNAL_H
  12. #define REMOTEPROC_INTERNAL_H
  13. #include <linux/irqreturn.h>
  14. #include <linux/firmware.h>
  15. struct rproc;
  16. struct rproc_debug_trace {
  17. struct rproc *rproc;
  18. struct dentry *tfile;
  19. struct list_head node;
  20. struct rproc_mem_entry trace_mem;
  21. };
  22. /**
  23. * struct rproc_vdev_data - remoteproc virtio device data
  24. * @rsc_offset: offset of the vdev's resource entry
  25. * @id: virtio device id (as in virtio_ids.h)
  26. * @index: vdev position versus other vdev declared in resource table
  27. * @rsc: pointer to the vdev resource entry. Valid only during vdev init as
  28. * the resource can be cached by rproc.
  29. */
  30. struct rproc_vdev_data {
  31. u32 rsc_offset;
  32. unsigned int id;
  33. u32 index;
  34. struct fw_rsc_vdev *rsc;
  35. };
  36. static inline bool rproc_has_feature(struct rproc *rproc, unsigned int feature)
  37. {
  38. return test_bit(feature, rproc->features);
  39. }
  40. static inline int rproc_set_feature(struct rproc *rproc, unsigned int feature)
  41. {
  42. if (feature >= RPROC_MAX_FEATURES)
  43. return -EINVAL;
  44. set_bit(feature, rproc->features);
  45. return 0;
  46. }
  47. /* from remoteproc_core.c */
  48. void rproc_release(struct kref *kref);
  49. int rproc_of_parse_firmware(struct device *dev, int index,
  50. const char **fw_name);
  51. /* from remoteproc_virtio.c */
  52. irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id);
  53. /* from remoteproc_debugfs.c */
  54. void rproc_remove_trace_file(struct dentry *tfile);
  55. struct dentry *rproc_create_trace_file(const char *name, struct rproc *rproc,
  56. struct rproc_debug_trace *trace);
  57. void rproc_delete_debug_dir(struct rproc *rproc);
  58. void rproc_create_debug_dir(struct rproc *rproc);
  59. void rproc_init_debugfs(void);
  60. void rproc_exit_debugfs(void);
  61. /* from remoteproc_sysfs.c */
  62. extern const struct class rproc_class;
  63. int rproc_init_sysfs(void);
  64. void rproc_exit_sysfs(void);
  65. #ifdef CONFIG_REMOTEPROC_CDEV
  66. void rproc_init_cdev(void);
  67. void rproc_exit_cdev(void);
  68. int rproc_char_device_add(struct rproc *rproc);
  69. void rproc_char_device_remove(struct rproc *rproc);
  70. #else
  71. static inline void rproc_init_cdev(void)
  72. {
  73. }
  74. static inline void rproc_exit_cdev(void)
  75. {
  76. }
  77. /*
  78. * The character device interface is an optional feature, if it is not enabled
  79. * the function should not return an error.
  80. */
  81. static inline int rproc_char_device_add(struct rproc *rproc)
  82. {
  83. return 0;
  84. }
  85. static inline void rproc_char_device_remove(struct rproc *rproc)
  86. {
  87. }
  88. #endif
  89. void rproc_free_vring(struct rproc_vring *rvring);
  90. int rproc_alloc_vring(struct rproc_vdev *rvdev, int i);
  91. int rproc_parse_vring(struct rproc_vdev *rvdev, struct fw_rsc_vdev *rsc, int i);
  92. phys_addr_t rproc_va_to_pa(void *cpu_addr);
  93. int rproc_trigger_recovery(struct rproc *rproc);
  94. int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw);
  95. u64 rproc_elf_get_boot_addr(struct rproc *rproc, const struct firmware *fw);
  96. int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw);
  97. int rproc_elf_load_rsc_table(struct rproc *rproc, const struct firmware *fw);
  98. struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,
  99. const struct firmware *fw);
  100. struct rproc_mem_entry *
  101. rproc_find_carveout_by_name(struct rproc *rproc, const char *name, ...);
  102. void rproc_add_rvdev(struct rproc *rproc, struct rproc_vdev *rvdev);
  103. void rproc_remove_rvdev(struct rproc_vdev *rvdev);
  104. static inline int rproc_prepare_device(struct rproc *rproc)
  105. {
  106. if (rproc->ops->prepare)
  107. return rproc->ops->prepare(rproc);
  108. return 0;
  109. }
  110. static inline int rproc_unprepare_device(struct rproc *rproc)
  111. {
  112. if (rproc->ops->unprepare)
  113. return rproc->ops->unprepare(rproc);
  114. return 0;
  115. }
  116. static inline int rproc_attach_device(struct rproc *rproc)
  117. {
  118. if (rproc->ops->attach)
  119. return rproc->ops->attach(rproc);
  120. return 0;
  121. }
  122. static inline
  123. int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
  124. {
  125. if (rproc->ops->sanity_check)
  126. return rproc->ops->sanity_check(rproc, fw);
  127. return 0;
  128. }
  129. static inline
  130. u64 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw)
  131. {
  132. if (rproc->ops->get_boot_addr)
  133. return rproc->ops->get_boot_addr(rproc, fw);
  134. return 0;
  135. }
  136. static inline
  137. int rproc_load_segments(struct rproc *rproc, const struct firmware *fw)
  138. {
  139. if (rproc->ops->load)
  140. return rproc->ops->load(rproc, fw);
  141. return -EINVAL;
  142. }
  143. static inline int rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
  144. {
  145. if (rproc->ops->parse_fw)
  146. return rproc->ops->parse_fw(rproc, fw);
  147. return 0;
  148. }
  149. static inline
  150. int rproc_handle_rsc(struct rproc *rproc, u32 rsc_type, void *rsc, int offset,
  151. int avail)
  152. {
  153. if (rproc->ops->handle_rsc)
  154. return rproc->ops->handle_rsc(rproc, rsc_type, rsc, offset,
  155. avail);
  156. return RSC_IGNORED;
  157. }
  158. static inline
  159. struct resource_table *rproc_find_loaded_rsc_table(struct rproc *rproc,
  160. const struct firmware *fw)
  161. {
  162. if (rproc->ops->find_loaded_rsc_table)
  163. return rproc->ops->find_loaded_rsc_table(rproc, fw);
  164. return NULL;
  165. }
  166. static inline
  167. struct resource_table *rproc_get_loaded_rsc_table(struct rproc *rproc,
  168. size_t *size)
  169. {
  170. if (rproc->ops->get_loaded_rsc_table)
  171. return rproc->ops->get_loaded_rsc_table(rproc, size);
  172. return NULL;
  173. }
  174. static inline
  175. bool rproc_u64_fit_in_size_t(u64 val)
  176. {
  177. if (sizeof(size_t) == sizeof(u64))
  178. return true;
  179. return (val <= (size_t) -1);
  180. }
  181. #endif /* REMOTEPROC_INTERNAL_H */