blob: c34002888d2c3287f870b7a17803f137e84e0766 [file] [log] [blame]
Thomas Gleixner9c92ab62019-05-29 07:17:56 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +02002/*
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>
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +020010 */
11
12#ifndef REMOTEPROC_INTERNAL_H
13#define REMOTEPROC_INTERNAL_H
14
15#include <linux/irqreturn.h>
Sjur Brændeland72854fb2012-07-15 11:25:27 +030016#include <linux/firmware.h>
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +020017
18struct rproc;
19
Loic Pallardya987e6b92019-01-10 14:49:10 +010020struct 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
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +020027/* from remoteproc_core.c */
28void rproc_release(struct kref *kref);
29irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id);
Bjorn Anderssonaab8d802016-10-19 19:40:06 -070030void rproc_vdev_release(struct kref *ref);
Suman Annaa8aa5ee2020-07-21 17:36:13 -050031int rproc_of_parse_firmware(struct device *dev, int index,
32 const char **fw_name);
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +020033
Ohad Ben-Cohen7a186942012-02-13 22:30:39 +010034/* from remoteproc_virtio.c */
35int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id);
Loic Pallardyd4c036f2019-01-21 14:55:15 +010036int rproc_remove_virtio_dev(struct device *dev, void *data);
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +020037
38/* from remoteproc_debugfs.c */
39void rproc_remove_trace_file(struct dentry *tfile);
40struct dentry *rproc_create_trace_file(const char *name, struct rproc *rproc,
Loic Pallardya987e6b92019-01-10 14:49:10 +010041 struct rproc_debug_trace *trace);
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +020042void rproc_delete_debug_dir(struct rproc *rproc);
43void rproc_create_debug_dir(struct rproc *rproc);
44void rproc_init_debugfs(void);
45void rproc_exit_debugfs(void);
46
Matt Redfearn2aefbef2016-10-19 13:05:47 +010047/* from remoteproc_sysfs.c */
48extern struct class rproc_class;
49int rproc_init_sysfs(void);
50void rproc_exit_sysfs(void);
51
Rishabh Bhatnagar2c010cc2020-07-16 15:20:31 -070052/* from remoteproc_coredump.c */
53void rproc_coredump_cleanup(struct rproc *rproc);
54void rproc_coredump(struct rproc *rproc);
55
Siddharth Gupta44767702020-07-29 10:40:00 -070056#ifdef CONFIG_REMOTEPROC_CDEV
57void rproc_init_cdev(void);
58void rproc_exit_cdev(void);
59int rproc_char_device_add(struct rproc *rproc);
60void rproc_char_device_remove(struct rproc *rproc);
61#else
62static inline void rproc_init_cdev(void)
63{
64}
65
66static 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 */
74static inline int rproc_char_device_add(struct rproc *rproc)
75{
76 return 0;
77}
78
79static inline void rproc_char_device_remove(struct rproc *rproc)
80{
81}
82#endif
83
Ohad Ben-Cohen6db20ea2012-05-17 14:23:59 +030084void rproc_free_vring(struct rproc_vring *rvring);
85int rproc_alloc_vring(struct rproc_vdev *rvdev, int i);
Sjur Brændeland72854fb2012-07-15 11:25:27 +030086
Clement Leger9ce3bf22020-03-02 10:38:55 +010087void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len);
Loic Pallardy086d0872019-01-10 14:50:49 +010088phys_addr_t rproc_va_to_pa(void *cpu_addr);
Fernando Guzman Lugo70b85ef2012-08-30 13:26:13 -050089int rproc_trigger_recovery(struct rproc *rproc);
Sjur Brændeland72854fb2012-07-15 11:25:27 +030090
Clement Legerf31e3392020-03-02 10:39:00 +010091int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw);
Clement Legere4ae4b72020-03-02 10:38:57 +010092u64 rproc_elf_get_boot_addr(struct rproc *rproc, const struct firmware *fw);
Bjorn Andersson0f21f9c2018-01-05 15:58:01 -080093int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw);
Bjorn Andersson58b64092018-01-05 15:58:03 -080094int rproc_elf_load_rsc_table(struct rproc *rproc, const struct firmware *fw);
Bjorn Andersson0f21f9c2018-01-05 15:58:01 -080095struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,
96 const struct firmware *fw);
Loic Pallardyc6aed2382018-07-27 15:14:47 +020097struct rproc_mem_entry *
98rproc_find_carveout_by_name(struct rproc *rproc, const char *name, ...);
Bjorn Andersson0f21f9c2018-01-05 15:58:01 -080099
Loic Pallardy33467ac2020-04-16 19:20:35 -0500100static inline int rproc_prepare_device(struct rproc *rproc)
101{
102 if (rproc->ops->prepare)
103 return rproc->ops->prepare(rproc);
104
105 return 0;
106}
107
108static inline int rproc_unprepare_device(struct rproc *rproc)
109{
110 if (rproc->ops->unprepare)
111 return rproc->ops->unprepare(rproc);
112
113 return 0;
114}
115
Mathieu Poiriera6a4f282020-07-14 13:50:28 -0600116static inline int rproc_attach_device(struct rproc *rproc)
117{
118 if (rproc->ops->attach)
119 return rproc->ops->attach(rproc);
120
121 return 0;
122}
123
Sjur Brændeland4afc89d2012-06-19 10:08:18 +0300124static inline
125int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
126{
Bjorn Andersson0f21f9c2018-01-05 15:58:01 -0800127 if (rproc->ops->sanity_check)
128 return rproc->ops->sanity_check(rproc, fw);
Sjur Brændeland4afc89d2012-06-19 10:08:18 +0300129
130 return 0;
131}
132
133static inline
Clement Legere4ae4b72020-03-02 10:38:57 +0100134u64 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw)
Sjur Brændeland4afc89d2012-06-19 10:08:18 +0300135{
Bjorn Andersson0f21f9c2018-01-05 15:58:01 -0800136 if (rproc->ops->get_boot_addr)
137 return rproc->ops->get_boot_addr(rproc, fw);
Sjur Brændeland4afc89d2012-06-19 10:08:18 +0300138
139 return 0;
140}
141
142static inline
143int rproc_load_segments(struct rproc *rproc, const struct firmware *fw)
144{
Bjorn Andersson0f21f9c2018-01-05 15:58:01 -0800145 if (rproc->ops->load)
146 return rproc->ops->load(rproc, fw);
Sjur Brændeland4afc89d2012-06-19 10:08:18 +0300147
148 return -EINVAL;
149}
150
Bjorn Anderssonc1d35c12018-01-05 16:04:18 -0800151static inline int rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
Sjur Brændeland4afc89d2012-06-19 10:08:18 +0300152{
Bjorn Anderssonc1d35c12018-01-05 16:04:18 -0800153 if (rproc->ops->parse_fw)
154 return rproc->ops->parse_fw(rproc, fw);
Sjur Brændeland4afc89d2012-06-19 10:08:18 +0300155
Bjorn Andersson58b64092018-01-05 15:58:03 -0800156 return 0;
Sjur Brændeland4afc89d2012-06-19 10:08:18 +0300157}
158
Sjur Brændeland95f95782013-02-21 18:15:34 +0100159static inline
Clement Legerb1a17512019-06-17 14:57:30 +0200160int rproc_handle_rsc(struct rproc *rproc, u32 rsc_type, void *rsc, int offset,
161 int avail)
162{
163 if (rproc->ops->handle_rsc)
164 return rproc->ops->handle_rsc(rproc, rsc_type, rsc, offset,
165 avail);
166
167 return RSC_IGNORED;
168}
169
170static inline
Sjur Brændeland95f95782013-02-21 18:15:34 +0100171struct resource_table *rproc_find_loaded_rsc_table(struct rproc *rproc,
Anna, Suman730f84c2016-08-12 18:42:20 -0500172 const struct firmware *fw)
Sjur Brændeland95f95782013-02-21 18:15:34 +0100173{
Bjorn Andersson0f21f9c2018-01-05 15:58:01 -0800174 if (rproc->ops->find_loaded_rsc_table)
175 return rproc->ops->find_loaded_rsc_table(rproc, fw);
Sjur Brændeland95f95782013-02-21 18:15:34 +0100176
Suman Anna57971152013-06-30 11:33:05 +0300177 return NULL;
Sjur Brændeland95f95782013-02-21 18:15:34 +0100178}
179
Clement Legerf31e3392020-03-02 10:39:00 +0100180static inline
181bool rproc_u64_fit_in_size_t(u64 val)
182{
183 if (sizeof(size_t) == sizeof(u64))
184 return true;
185
186 return (val <= (size_t) -1);
187}
188
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200189#endif /* REMOTEPROC_INTERNAL_H */