blob: b389dc79da81176baeab7fdcb4c3db12aa0cc7e5 [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);
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +020031
Ohad Ben-Cohen7a186942012-02-13 22:30:39 +010032/* from remoteproc_virtio.c */
33int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id);
Loic Pallardyd4c036f2019-01-21 14:55:15 +010034int rproc_remove_virtio_dev(struct device *dev, void *data);
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +020035
36/* from remoteproc_debugfs.c */
37void rproc_remove_trace_file(struct dentry *tfile);
38struct dentry *rproc_create_trace_file(const char *name, struct rproc *rproc,
Loic Pallardya987e6b92019-01-10 14:49:10 +010039 struct rproc_debug_trace *trace);
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +020040void rproc_delete_debug_dir(struct rproc *rproc);
41void rproc_create_debug_dir(struct rproc *rproc);
42void rproc_init_debugfs(void);
43void rproc_exit_debugfs(void);
44
Matt Redfearn2aefbef2016-10-19 13:05:47 +010045/* from remoteproc_sysfs.c */
46extern struct class rproc_class;
47int rproc_init_sysfs(void);
48void rproc_exit_sysfs(void);
49
Ohad Ben-Cohen6db20ea2012-05-17 14:23:59 +030050void rproc_free_vring(struct rproc_vring *rvring);
51int rproc_alloc_vring(struct rproc_vdev *rvdev, int i);
Sjur Brændeland72854fb2012-07-15 11:25:27 +030052
Clement Leger9ce3bf22020-03-02 10:38:55 +010053void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len);
Loic Pallardy086d0872019-01-10 14:50:49 +010054phys_addr_t rproc_va_to_pa(void *cpu_addr);
Fernando Guzman Lugo70b85ef2012-08-30 13:26:13 -050055int rproc_trigger_recovery(struct rproc *rproc);
Sjur Brændeland72854fb2012-07-15 11:25:27 +030056
Clement Leger826c3392020-03-02 10:38:59 +010057int rproc_elf32_sanity_check(struct rproc *rproc, const struct firmware *fw);
Clement Legerf31e3392020-03-02 10:39:00 +010058int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw);
Clement Legere4ae4b72020-03-02 10:38:57 +010059u64 rproc_elf_get_boot_addr(struct rproc *rproc, const struct firmware *fw);
Bjorn Andersson0f21f9c2018-01-05 15:58:01 -080060int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw);
Bjorn Andersson58b64092018-01-05 15:58:03 -080061int rproc_elf_load_rsc_table(struct rproc *rproc, const struct firmware *fw);
Bjorn Andersson0f21f9c2018-01-05 15:58:01 -080062struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,
63 const struct firmware *fw);
Loic Pallardyc6aed2382018-07-27 15:14:47 +020064struct rproc_mem_entry *
65rproc_find_carveout_by_name(struct rproc *rproc, const char *name, ...);
Bjorn Andersson0f21f9c2018-01-05 15:58:01 -080066
Sjur Brændeland4afc89d2012-06-19 10:08:18 +030067static inline
68int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
69{
Bjorn Andersson0f21f9c2018-01-05 15:58:01 -080070 if (rproc->ops->sanity_check)
71 return rproc->ops->sanity_check(rproc, fw);
Sjur Brændeland4afc89d2012-06-19 10:08:18 +030072
73 return 0;
74}
75
76static inline
Clement Legere4ae4b72020-03-02 10:38:57 +010077u64 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw)
Sjur Brændeland4afc89d2012-06-19 10:08:18 +030078{
Bjorn Andersson0f21f9c2018-01-05 15:58:01 -080079 if (rproc->ops->get_boot_addr)
80 return rproc->ops->get_boot_addr(rproc, fw);
Sjur Brændeland4afc89d2012-06-19 10:08:18 +030081
82 return 0;
83}
84
85static inline
86int rproc_load_segments(struct rproc *rproc, const struct firmware *fw)
87{
Bjorn Andersson0f21f9c2018-01-05 15:58:01 -080088 if (rproc->ops->load)
89 return rproc->ops->load(rproc, fw);
Sjur Brændeland4afc89d2012-06-19 10:08:18 +030090
91 return -EINVAL;
92}
93
Bjorn Anderssonc1d35c12018-01-05 16:04:18 -080094static inline int rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
Sjur Brændeland4afc89d2012-06-19 10:08:18 +030095{
Bjorn Anderssonc1d35c12018-01-05 16:04:18 -080096 if (rproc->ops->parse_fw)
97 return rproc->ops->parse_fw(rproc, fw);
Sjur Brændeland4afc89d2012-06-19 10:08:18 +030098
Bjorn Andersson58b64092018-01-05 15:58:03 -080099 return 0;
Sjur Brændeland4afc89d2012-06-19 10:08:18 +0300100}
101
Sjur Brændeland95f95782013-02-21 18:15:34 +0100102static inline
Clement Legerb1a17512019-06-17 14:57:30 +0200103int rproc_handle_rsc(struct rproc *rproc, u32 rsc_type, void *rsc, int offset,
104 int avail)
105{
106 if (rproc->ops->handle_rsc)
107 return rproc->ops->handle_rsc(rproc, rsc_type, rsc, offset,
108 avail);
109
110 return RSC_IGNORED;
111}
112
113static inline
Sjur Brændeland95f95782013-02-21 18:15:34 +0100114struct resource_table *rproc_find_loaded_rsc_table(struct rproc *rproc,
Anna, Suman730f84c2016-08-12 18:42:20 -0500115 const struct firmware *fw)
Sjur Brændeland95f95782013-02-21 18:15:34 +0100116{
Bjorn Andersson0f21f9c2018-01-05 15:58:01 -0800117 if (rproc->ops->find_loaded_rsc_table)
118 return rproc->ops->find_loaded_rsc_table(rproc, fw);
Sjur Brændeland95f95782013-02-21 18:15:34 +0100119
Suman Anna57971152013-06-30 11:33:05 +0300120 return NULL;
Sjur Brændeland95f95782013-02-21 18:15:34 +0100121}
122
Clement Legerf31e3392020-03-02 10:39:00 +0100123static inline
124bool rproc_u64_fit_in_size_t(u64 val)
125{
126 if (sizeof(size_t) == sizeof(u64))
127 return true;
128
129 return (val <= (size_t) -1);
130}
131
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200132#endif /* REMOTEPROC_INTERNAL_H */