linux/drivers/remoteproc/remoteproc_internal.h
<<
>>
Prefs
   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
  18struct rproc;
  19
  20struct 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 */
  28void rproc_release(struct kref *kref);
  29irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id);
  30void rproc_vdev_release(struct kref *ref);
  31int rproc_of_parse_firmware(struct device *dev, int index,
  32                            const char **fw_name);
  33
  34/* from remoteproc_virtio.c */
  35int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id);
  36int rproc_remove_virtio_dev(struct device *dev, void *data);
  37
  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,
  41                                       struct rproc_debug_trace *trace);
  42void 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
  47/* from remoteproc_sysfs.c */
  48extern struct class rproc_class;
  49int rproc_init_sysfs(void);
  50void rproc_exit_sysfs(void);
  51
  52/* from remoteproc_coredump.c */
  53void rproc_coredump_cleanup(struct rproc *rproc);
  54void rproc_coredump(struct rproc *rproc);
  55
  56#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
  84void rproc_free_vring(struct rproc_vring *rvring);
  85int rproc_alloc_vring(struct rproc_vdev *rvdev, int i);
  86
  87void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem);
  88phys_addr_t rproc_va_to_pa(void *cpu_addr);
  89int rproc_trigger_recovery(struct rproc *rproc);
  90
  91int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw);
  92u64 rproc_elf_get_boot_addr(struct rproc *rproc, const struct firmware *fw);
  93int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw);
  94int rproc_elf_load_rsc_table(struct rproc *rproc, const struct firmware *fw);
  95struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,
  96                                                       const struct firmware *fw);
  97struct rproc_mem_entry *
  98rproc_find_carveout_by_name(struct rproc *rproc, const char *name, ...);
  99
 100static 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
 116static 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
 124static inline
 125int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
 126{
 127        if (rproc->ops->sanity_check)
 128                return rproc->ops->sanity_check(rproc, fw);
 129
 130        return 0;
 131}
 132
 133static inline
 134u64 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw)
 135{
 136        if (rproc->ops->get_boot_addr)
 137                return rproc->ops->get_boot_addr(rproc, fw);
 138
 139        return 0;
 140}
 141
 142static inline
 143int rproc_load_segments(struct rproc *rproc, const struct firmware *fw)
 144{
 145        if (rproc->ops->load)
 146                return rproc->ops->load(rproc, fw);
 147
 148        return -EINVAL;
 149}
 150
 151static inline int rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
 152{
 153        if (rproc->ops->parse_fw)
 154                return rproc->ops->parse_fw(rproc, fw);
 155
 156        return 0;
 157}
 158
 159static inline
 160int 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
 171struct resource_table *rproc_find_loaded_rsc_table(struct rproc *rproc,
 172                                                   const struct firmware *fw)
 173{
 174        if (rproc->ops->find_loaded_rsc_table)
 175                return rproc->ops->find_loaded_rsc_table(rproc, fw);
 176
 177        return NULL;
 178}
 179
 180static inline
 181struct resource_table *rproc_get_loaded_rsc_table(struct rproc *rproc,
 182                                                  size_t *size)
 183{
 184        if (rproc->ops->get_loaded_rsc_table)
 185                return rproc->ops->get_loaded_rsc_table(rproc, size);
 186
 187        return NULL;
 188}
 189
 190static inline
 191bool rproc_u64_fit_in_size_t(u64 val)
 192{
 193        if (sizeof(size_t) == sizeof(u64))
 194                return true;
 195
 196        return (val <= (size_t) -1);
 197}
 198
 199#endif /* REMOTEPROC_INTERNAL_H */
 200