Merge tag 'sound-fix-5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai...
[linux-2.6-microblaze.git] / drivers / remoteproc / remoteproc_internal.h
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 /* from remoteproc_core.c */
28 void rproc_release(struct kref *kref);
29 irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id);
30 void rproc_vdev_release(struct kref *ref);
31 int rproc_of_parse_firmware(struct device *dev, int index,
32                             const char **fw_name);
33
34 /* from remoteproc_virtio.c */
35 int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id);
36 int rproc_remove_virtio_dev(struct device *dev, void *data);
37
38 /* from remoteproc_debugfs.c */
39 void rproc_remove_trace_file(struct dentry *tfile);
40 struct dentry *rproc_create_trace_file(const char *name, struct rproc *rproc,
41                                        struct rproc_debug_trace *trace);
42 void rproc_delete_debug_dir(struct rproc *rproc);
43 void rproc_create_debug_dir(struct rproc *rproc);
44 void rproc_init_debugfs(void);
45 void rproc_exit_debugfs(void);
46
47 /* from remoteproc_sysfs.c */
48 extern struct class rproc_class;
49 int rproc_init_sysfs(void);
50 void rproc_exit_sysfs(void);
51
52 /* from remoteproc_coredump.c */
53 void rproc_coredump_cleanup(struct rproc *rproc);
54 void rproc_coredump(struct rproc *rproc);
55
56 #ifdef CONFIG_REMOTEPROC_CDEV
57 void rproc_init_cdev(void);
58 void rproc_exit_cdev(void);
59 int rproc_char_device_add(struct rproc *rproc);
60 void rproc_char_device_remove(struct rproc *rproc);
61 #else
62 static inline void rproc_init_cdev(void)
63 {
64 }
65
66 static inline void rproc_exit_cdev(void)
67 {
68 }
69
70 /*
71  * The character device interface is an optional feature, if it is not enabled
72  * the function should not return an error.
73  */
74 static inline int rproc_char_device_add(struct rproc *rproc)
75 {
76         return 0;
77 }
78
79 static inline void  rproc_char_device_remove(struct rproc *rproc)
80 {
81 }
82 #endif
83
84 void rproc_free_vring(struct rproc_vring *rvring);
85 int rproc_alloc_vring(struct rproc_vdev *rvdev, int i);
86
87 phys_addr_t rproc_va_to_pa(void *cpu_addr);
88 int rproc_trigger_recovery(struct rproc *rproc);
89
90 int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw);
91 u64 rproc_elf_get_boot_addr(struct rproc *rproc, const struct firmware *fw);
92 int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw);
93 int rproc_elf_load_rsc_table(struct rproc *rproc, const struct firmware *fw);
94 struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,
95                                                        const struct firmware *fw);
96 struct rproc_mem_entry *
97 rproc_find_carveout_by_name(struct rproc *rproc, const char *name, ...);
98
99 static inline int rproc_prepare_device(struct rproc *rproc)
100 {
101         if (rproc->ops->prepare)
102                 return rproc->ops->prepare(rproc);
103
104         return 0;
105 }
106
107 static inline int rproc_unprepare_device(struct rproc *rproc)
108 {
109         if (rproc->ops->unprepare)
110                 return rproc->ops->unprepare(rproc);
111
112         return 0;
113 }
114
115 static inline int rproc_attach_device(struct rproc *rproc)
116 {
117         if (rproc->ops->attach)
118                 return rproc->ops->attach(rproc);
119
120         return 0;
121 }
122
123 static inline
124 int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
125 {
126         if (rproc->ops->sanity_check)
127                 return rproc->ops->sanity_check(rproc, fw);
128
129         return 0;
130 }
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
138         return 0;
139 }
140
141 static inline
142 int rproc_load_segments(struct rproc *rproc, const struct firmware *fw)
143 {
144         if (rproc->ops->load)
145                 return rproc->ops->load(rproc, fw);
146
147         return -EINVAL;
148 }
149
150 static inline int rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
151 {
152         if (rproc->ops->parse_fw)
153                 return rproc->ops->parse_fw(rproc, fw);
154
155         return 0;
156 }
157
158 static inline
159 int rproc_handle_rsc(struct rproc *rproc, u32 rsc_type, void *rsc, int offset,
160                      int avail)
161 {
162         if (rproc->ops->handle_rsc)
163                 return rproc->ops->handle_rsc(rproc, rsc_type, rsc, offset,
164                                               avail);
165
166         return RSC_IGNORED;
167 }
168
169 static inline
170 struct resource_table *rproc_find_loaded_rsc_table(struct rproc *rproc,
171                                                    const struct firmware *fw)
172 {
173         if (rproc->ops->find_loaded_rsc_table)
174                 return rproc->ops->find_loaded_rsc_table(rproc, fw);
175
176         return NULL;
177 }
178
179 static inline
180 struct resource_table *rproc_get_loaded_rsc_table(struct rproc *rproc,
181                                                   size_t *size)
182 {
183         if (rproc->ops->get_loaded_rsc_table)
184                 return rproc->ops->get_loaded_rsc_table(rproc, size);
185
186         return NULL;
187 }
188
189 static inline
190 bool rproc_u64_fit_in_size_t(u64 val)
191 {
192         if (sizeof(size_t) == sizeof(u64))
193                 return true;
194
195         return (val <= (size_t) -1);
196 }
197
198 #endif /* REMOTEPROC_INTERNAL_H */