remoteproc_internal.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 <[email protected]>
  9. * Brian Swetland <[email protected]>
  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 struct class rproc_class;
  63. int rproc_init_sysfs(void);
  64. void rproc_exit_sysfs(void);
  65. /* from remoteproc_coredump.c */
  66. void rproc_coredump_cleanup(struct rproc *rproc);
  67. void rproc_coredump(struct rproc *rproc);
  68. #ifdef CONFIG_REMOTEPROC_CDEV
  69. void rproc_init_cdev(void);
  70. void rproc_exit_cdev(void);
  71. int rproc_char_device_add(struct rproc *rproc);
  72. void rproc_char_device_remove(struct rproc *rproc);
  73. #else
  74. static inline void rproc_init_cdev(void)
  75. {
  76. }
  77. static inline void rproc_exit_cdev(void)
  78. {
  79. }
  80. /*
  81. * The character device interface is an optional feature, if it is not enabled
  82. * the function should not return an error.
  83. */
  84. static inline int rproc_char_device_add(struct rproc *rproc)
  85. {
  86. return 0;
  87. }
  88. static inline void rproc_char_device_remove(struct rproc *rproc)
  89. {
  90. }
  91. #endif
  92. void rproc_free_vring(struct rproc_vring *rvring);
  93. int rproc_alloc_vring(struct rproc_vdev *rvdev, int i);
  94. int rproc_parse_vring(struct rproc_vdev *rvdev, struct fw_rsc_vdev *rsc, int i);
  95. phys_addr_t rproc_va_to_pa(void *cpu_addr);
  96. int rproc_trigger_recovery(struct rproc *rproc);
  97. int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw);
  98. u64 rproc_elf_get_boot_addr(struct rproc *rproc, const struct firmware *fw);
  99. int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw);
  100. int rproc_elf_load_rsc_table(struct rproc *rproc, const struct firmware *fw);
  101. struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,
  102. const struct firmware *fw);
  103. struct rproc_mem_entry *
  104. rproc_find_carveout_by_name(struct rproc *rproc, const char *name, ...);
  105. void rproc_add_rvdev(struct rproc *rproc, struct rproc_vdev *rvdev);
  106. void rproc_remove_rvdev(struct rproc_vdev *rvdev);
  107. static inline int rproc_prepare_device(struct rproc *rproc)
  108. {
  109. if (rproc->ops->prepare)
  110. return rproc->ops->prepare(rproc);
  111. return 0;
  112. }
  113. static inline int rproc_unprepare_device(struct rproc *rproc)
  114. {
  115. if (rproc->ops->unprepare)
  116. return rproc->ops->unprepare(rproc);
  117. return 0;
  118. }
  119. static inline int rproc_attach_device(struct rproc *rproc)
  120. {
  121. if (rproc->ops->attach)
  122. return rproc->ops->attach(rproc);
  123. return 0;
  124. }
  125. static inline
  126. int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
  127. {
  128. if (rproc->ops->sanity_check)
  129. return rproc->ops->sanity_check(rproc, fw);
  130. return 0;
  131. }
  132. static inline
  133. u64 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw)
  134. {
  135. if (rproc->ops->get_boot_addr)
  136. return rproc->ops->get_boot_addr(rproc, fw);
  137. return 0;
  138. }
  139. static inline
  140. int rproc_load_segments(struct rproc *rproc, const struct firmware *fw)
  141. {
  142. if (rproc->ops->load)
  143. return rproc->ops->load(rproc, fw);
  144. return -EINVAL;
  145. }
  146. static inline int rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
  147. {
  148. if (rproc->ops->parse_fw)
  149. return rproc->ops->parse_fw(rproc, fw);
  150. return 0;
  151. }
  152. static inline
  153. int rproc_handle_rsc(struct rproc *rproc, u32 rsc_type, void *rsc, int offset,
  154. int avail)
  155. {
  156. if (rproc->ops->handle_rsc)
  157. return rproc->ops->handle_rsc(rproc, rsc_type, rsc, offset,
  158. avail);
  159. return RSC_IGNORED;
  160. }
  161. static inline
  162. struct resource_table *rproc_find_loaded_rsc_table(struct rproc *rproc,
  163. const struct firmware *fw)
  164. {
  165. if (rproc->ops->find_loaded_rsc_table)
  166. return rproc->ops->find_loaded_rsc_table(rproc, fw);
  167. return NULL;
  168. }
  169. static inline
  170. struct resource_table *rproc_get_loaded_rsc_table(struct rproc *rproc,
  171. size_t *size)
  172. {
  173. if (rproc->ops->get_loaded_rsc_table)
  174. return rproc->ops->get_loaded_rsc_table(rproc, size);
  175. return NULL;
  176. }
  177. static inline
  178. bool rproc_u64_fit_in_size_t(u64 val)
  179. {
  180. if (sizeof(size_t) == sizeof(u64))
  181. return true;
  182. return (val <= (size_t) -1);
  183. }
  184. #endif /* REMOTEPROC_INTERNAL_H */