0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef REMOTEPROC_INTERNAL_H
0013 #define REMOTEPROC_INTERNAL_H
0014
0015 #include <linux/irqreturn.h>
0016 #include <linux/firmware.h>
0017
0018 struct rproc;
0019
0020 struct rproc_debug_trace {
0021 struct rproc *rproc;
0022 struct dentry *tfile;
0023 struct list_head node;
0024 struct rproc_mem_entry trace_mem;
0025 };
0026
0027
0028 void rproc_release(struct kref *kref);
0029 irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id);
0030 void rproc_vdev_release(struct kref *ref);
0031 int rproc_of_parse_firmware(struct device *dev, int index,
0032 const char **fw_name);
0033
0034
0035 int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id);
0036 int rproc_remove_virtio_dev(struct device *dev, void *data);
0037
0038
0039 void rproc_remove_trace_file(struct dentry *tfile);
0040 struct dentry *rproc_create_trace_file(const char *name, struct rproc *rproc,
0041 struct rproc_debug_trace *trace);
0042 void rproc_delete_debug_dir(struct rproc *rproc);
0043 void rproc_create_debug_dir(struct rproc *rproc);
0044 void rproc_init_debugfs(void);
0045 void rproc_exit_debugfs(void);
0046
0047
0048 extern struct class rproc_class;
0049 int rproc_init_sysfs(void);
0050 void rproc_exit_sysfs(void);
0051
0052
0053 void rproc_coredump_cleanup(struct rproc *rproc);
0054 void rproc_coredump(struct rproc *rproc);
0055
0056 #ifdef CONFIG_REMOTEPROC_CDEV
0057 void rproc_init_cdev(void);
0058 void rproc_exit_cdev(void);
0059 int rproc_char_device_add(struct rproc *rproc);
0060 void rproc_char_device_remove(struct rproc *rproc);
0061 #else
0062 static inline void rproc_init_cdev(void)
0063 {
0064 }
0065
0066 static inline void rproc_exit_cdev(void)
0067 {
0068 }
0069
0070
0071
0072
0073
0074 static inline int rproc_char_device_add(struct rproc *rproc)
0075 {
0076 return 0;
0077 }
0078
0079 static inline void rproc_char_device_remove(struct rproc *rproc)
0080 {
0081 }
0082 #endif
0083
0084 void rproc_free_vring(struct rproc_vring *rvring);
0085 int rproc_alloc_vring(struct rproc_vdev *rvdev, int i);
0086
0087 phys_addr_t rproc_va_to_pa(void *cpu_addr);
0088 int rproc_trigger_recovery(struct rproc *rproc);
0089
0090 int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw);
0091 u64 rproc_elf_get_boot_addr(struct rproc *rproc, const struct firmware *fw);
0092 int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw);
0093 int rproc_elf_load_rsc_table(struct rproc *rproc, const struct firmware *fw);
0094 struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,
0095 const struct firmware *fw);
0096 struct rproc_mem_entry *
0097 rproc_find_carveout_by_name(struct rproc *rproc, const char *name, ...);
0098
0099 static inline int rproc_prepare_device(struct rproc *rproc)
0100 {
0101 if (rproc->ops->prepare)
0102 return rproc->ops->prepare(rproc);
0103
0104 return 0;
0105 }
0106
0107 static inline int rproc_unprepare_device(struct rproc *rproc)
0108 {
0109 if (rproc->ops->unprepare)
0110 return rproc->ops->unprepare(rproc);
0111
0112 return 0;
0113 }
0114
0115 static inline int rproc_attach_device(struct rproc *rproc)
0116 {
0117 if (rproc->ops->attach)
0118 return rproc->ops->attach(rproc);
0119
0120 return 0;
0121 }
0122
0123 static inline
0124 int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
0125 {
0126 if (rproc->ops->sanity_check)
0127 return rproc->ops->sanity_check(rproc, fw);
0128
0129 return 0;
0130 }
0131
0132 static inline
0133 u64 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw)
0134 {
0135 if (rproc->ops->get_boot_addr)
0136 return rproc->ops->get_boot_addr(rproc, fw);
0137
0138 return 0;
0139 }
0140
0141 static inline
0142 int rproc_load_segments(struct rproc *rproc, const struct firmware *fw)
0143 {
0144 if (rproc->ops->load)
0145 return rproc->ops->load(rproc, fw);
0146
0147 return -EINVAL;
0148 }
0149
0150 static inline int rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
0151 {
0152 if (rproc->ops->parse_fw)
0153 return rproc->ops->parse_fw(rproc, fw);
0154
0155 return 0;
0156 }
0157
0158 static inline
0159 int rproc_handle_rsc(struct rproc *rproc, u32 rsc_type, void *rsc, int offset,
0160 int avail)
0161 {
0162 if (rproc->ops->handle_rsc)
0163 return rproc->ops->handle_rsc(rproc, rsc_type, rsc, offset,
0164 avail);
0165
0166 return RSC_IGNORED;
0167 }
0168
0169 static inline
0170 struct resource_table *rproc_find_loaded_rsc_table(struct rproc *rproc,
0171 const struct firmware *fw)
0172 {
0173 if (rproc->ops->find_loaded_rsc_table)
0174 return rproc->ops->find_loaded_rsc_table(rproc, fw);
0175
0176 return NULL;
0177 }
0178
0179 static inline
0180 struct resource_table *rproc_get_loaded_rsc_table(struct rproc *rproc,
0181 size_t *size)
0182 {
0183 if (rproc->ops->get_loaded_rsc_table)
0184 return rproc->ops->get_loaded_rsc_table(rproc, size);
0185
0186 return NULL;
0187 }
0188
0189 static inline
0190 bool rproc_u64_fit_in_size_t(u64 val)
0191 {
0192 if (sizeof(size_t) == sizeof(u64))
0193 return true;
0194
0195 return (val <= (size_t) -1);
0196 }
0197
0198 #endif