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