xref: /openbmc/linux/drivers/remoteproc/remoteproc_internal.h (revision fd28f879e6274d477378362d848b42747ecb27eb)
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 /* from remoteproc_core.c */
43 void rproc_release(struct kref *kref);
44 irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id);
45 void rproc_vdev_release(struct kref *ref);
46 int rproc_of_parse_firmware(struct device *dev, int index,
47 			    const char **fw_name);
48 
49 /* from remoteproc_virtio.c */
50 int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id);
51 int rproc_remove_virtio_dev(struct device *dev, void *data);
52 
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 
62 /* from remoteproc_sysfs.c */
63 extern struct class rproc_class;
64 int rproc_init_sysfs(void);
65 void rproc_exit_sysfs(void);
66 
67 /* from remoteproc_coredump.c */
68 void rproc_coredump_cleanup(struct rproc *rproc);
69 void rproc_coredump(struct rproc *rproc);
70 
71 #ifdef CONFIG_REMOTEPROC_CDEV
72 void rproc_init_cdev(void);
73 void rproc_exit_cdev(void);
74 int rproc_char_device_add(struct rproc *rproc);
75 void rproc_char_device_remove(struct rproc *rproc);
76 #else
77 static inline void rproc_init_cdev(void)
78 {
79 }
80 
81 static inline void rproc_exit_cdev(void)
82 {
83 }
84 
85 /*
86  * The character device interface is an optional feature, if it is not enabled
87  * the function should not return an error.
88  */
89 static inline int rproc_char_device_add(struct rproc *rproc)
90 {
91 	return 0;
92 }
93 
94 static inline void  rproc_char_device_remove(struct rproc *rproc)
95 {
96 }
97 #endif
98 
99 void rproc_free_vring(struct rproc_vring *rvring);
100 int rproc_alloc_vring(struct rproc_vdev *rvdev, int i);
101 
102 phys_addr_t rproc_va_to_pa(void *cpu_addr);
103 int rproc_trigger_recovery(struct rproc *rproc);
104 
105 int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw);
106 u64 rproc_elf_get_boot_addr(struct rproc *rproc, const struct firmware *fw);
107 int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw);
108 int rproc_elf_load_rsc_table(struct rproc *rproc, const struct firmware *fw);
109 struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,
110 						       const struct firmware *fw);
111 struct rproc_mem_entry *
112 rproc_find_carveout_by_name(struct rproc *rproc, const char *name, ...);
113 
114 static inline int rproc_prepare_device(struct rproc *rproc)
115 {
116 	if (rproc->ops->prepare)
117 		return rproc->ops->prepare(rproc);
118 
119 	return 0;
120 }
121 
122 static inline int rproc_unprepare_device(struct rproc *rproc)
123 {
124 	if (rproc->ops->unprepare)
125 		return rproc->ops->unprepare(rproc);
126 
127 	return 0;
128 }
129 
130 static inline int rproc_attach_device(struct rproc *rproc)
131 {
132 	if (rproc->ops->attach)
133 		return rproc->ops->attach(rproc);
134 
135 	return 0;
136 }
137 
138 static inline
139 int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
140 {
141 	if (rproc->ops->sanity_check)
142 		return rproc->ops->sanity_check(rproc, fw);
143 
144 	return 0;
145 }
146 
147 static inline
148 u64 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw)
149 {
150 	if (rproc->ops->get_boot_addr)
151 		return rproc->ops->get_boot_addr(rproc, fw);
152 
153 	return 0;
154 }
155 
156 static inline
157 int rproc_load_segments(struct rproc *rproc, const struct firmware *fw)
158 {
159 	if (rproc->ops->load)
160 		return rproc->ops->load(rproc, fw);
161 
162 	return -EINVAL;
163 }
164 
165 static inline int rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
166 {
167 	if (rproc->ops->parse_fw)
168 		return rproc->ops->parse_fw(rproc, fw);
169 
170 	return 0;
171 }
172 
173 static inline
174 int rproc_handle_rsc(struct rproc *rproc, u32 rsc_type, void *rsc, int offset,
175 		     int avail)
176 {
177 	if (rproc->ops->handle_rsc)
178 		return rproc->ops->handle_rsc(rproc, rsc_type, rsc, offset,
179 					      avail);
180 
181 	return RSC_IGNORED;
182 }
183 
184 static inline
185 struct resource_table *rproc_find_loaded_rsc_table(struct rproc *rproc,
186 						   const struct firmware *fw)
187 {
188 	if (rproc->ops->find_loaded_rsc_table)
189 		return rproc->ops->find_loaded_rsc_table(rproc, fw);
190 
191 	return NULL;
192 }
193 
194 static inline
195 struct resource_table *rproc_get_loaded_rsc_table(struct rproc *rproc,
196 						  size_t *size)
197 {
198 	if (rproc->ops->get_loaded_rsc_table)
199 		return rproc->ops->get_loaded_rsc_table(rproc, size);
200 
201 	return NULL;
202 }
203 
204 static inline
205 bool rproc_u64_fit_in_size_t(u64 val)
206 {
207 	if (sizeof(size_t) == sizeof(u64))
208 		return true;
209 
210 	return (val <= (size_t) -1);
211 }
212 
213 #endif /* REMOTEPROC_INTERNAL_H */
214