remoteproc_internal.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. /* from remoteproc_core.c */
  23. void rproc_release(struct kref *kref);
  24. irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id);
  25. void rproc_vdev_release(struct kref *ref);
  26. int rproc_of_parse_firmware(struct device *dev, int index,
  27. const char **fw_name);
  28. /* from remoteproc_virtio.c */
  29. int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id);
  30. int rproc_remove_virtio_dev(struct device *dev, void *data);
  31. /* from remoteproc_debugfs.c */
  32. void rproc_remove_trace_file(struct dentry *tfile);
  33. struct dentry *rproc_create_trace_file(const char *name, struct rproc *rproc,
  34. struct rproc_debug_trace *trace);
  35. void rproc_delete_debug_dir(struct rproc *rproc);
  36. void rproc_create_debug_dir(struct rproc *rproc);
  37. void rproc_init_debugfs(void);
  38. void rproc_exit_debugfs(void);
  39. /* from remoteproc_sysfs.c */
  40. extern struct class rproc_class;
  41. int rproc_init_sysfs(void);
  42. void rproc_exit_sysfs(void);
  43. #ifdef CONFIG_REMOTEPROC_CDEV
  44. void rproc_init_cdev(void);
  45. void rproc_exit_cdev(void);
  46. int rproc_char_device_add(struct rproc *rproc);
  47. void rproc_char_device_remove(struct rproc *rproc);
  48. #else
  49. static inline void rproc_init_cdev(void)
  50. {
  51. }
  52. static inline void rproc_exit_cdev(void)
  53. {
  54. }
  55. /*
  56. * The character device interface is an optional feature, if it is not enabled
  57. * the function should not return an error.
  58. */
  59. static inline int rproc_char_device_add(struct rproc *rproc)
  60. {
  61. return 0;
  62. }
  63. static inline void rproc_char_device_remove(struct rproc *rproc)
  64. {
  65. }
  66. #endif
  67. void rproc_free_vring(struct rproc_vring *rvring);
  68. int rproc_alloc_vring(struct rproc_vdev *rvdev, int i);
  69. void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem);
  70. phys_addr_t rproc_va_to_pa(void *cpu_addr);
  71. int rproc_trigger_recovery(struct rproc *rproc);
  72. int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw);
  73. u64 rproc_elf_get_boot_addr(struct rproc *rproc, const struct firmware *fw);
  74. int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw);
  75. int rproc_elf_load_rsc_table(struct rproc *rproc, const struct firmware *fw);
  76. struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,
  77. const struct firmware *fw);
  78. struct rproc_mem_entry *
  79. rproc_find_carveout_by_name(struct rproc *rproc, const char *name, ...);
  80. static inline int rproc_prepare_device(struct rproc *rproc)
  81. {
  82. if (rproc->ops->prepare)
  83. return rproc->ops->prepare(rproc);
  84. return 0;
  85. }
  86. static inline int rproc_unprepare_device(struct rproc *rproc)
  87. {
  88. if (rproc->ops->unprepare)
  89. return rproc->ops->unprepare(rproc);
  90. return 0;
  91. }
  92. static inline int rproc_attach_device(struct rproc *rproc)
  93. {
  94. if (rproc->ops->attach)
  95. return rproc->ops->attach(rproc);
  96. return 0;
  97. }
  98. static inline
  99. int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
  100. {
  101. if (rproc->ops->sanity_check)
  102. return rproc->ops->sanity_check(rproc, fw);
  103. return 0;
  104. }
  105. static inline
  106. u64 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw)
  107. {
  108. if (rproc->ops->get_boot_addr)
  109. return rproc->ops->get_boot_addr(rproc, fw);
  110. return 0;
  111. }
  112. static inline
  113. int rproc_load_segments(struct rproc *rproc, const struct firmware *fw)
  114. {
  115. if (rproc->ops->load)
  116. return rproc->ops->load(rproc, fw);
  117. return -EINVAL;
  118. }
  119. static inline int rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
  120. {
  121. if (rproc->ops->parse_fw)
  122. return rproc->ops->parse_fw(rproc, fw);
  123. return 0;
  124. }
  125. static inline
  126. int rproc_handle_rsc(struct rproc *rproc, u32 rsc_type, void *rsc, int offset,
  127. int avail)
  128. {
  129. if (rproc->ops->handle_rsc)
  130. return rproc->ops->handle_rsc(rproc, rsc_type, rsc, offset,
  131. avail);
  132. return RSC_IGNORED;
  133. }
  134. static inline
  135. struct resource_table *rproc_find_loaded_rsc_table(struct rproc *rproc,
  136. const struct firmware *fw)
  137. {
  138. if (rproc->ops->find_loaded_rsc_table)
  139. return rproc->ops->find_loaded_rsc_table(rproc, fw);
  140. return NULL;
  141. }
  142. static inline
  143. bool rproc_u64_fit_in_size_t(u64 val)
  144. {
  145. if (sizeof(size_t) == sizeof(u64))
  146. return true;
  147. return (val <= (size_t) -1);
  148. }
  149. #endif /* REMOTEPROC_INTERNAL_H */