2019-05-29 17:17:56 +03:00
/* SPDX-License-Identifier: GPL-2.0-only */
2011-10-20 18:52:46 +04:00
/*
* Remote processor framework
*
* Copyright ( C ) 2011 Texas Instruments , Inc .
* Copyright ( C ) 2011 Google , Inc .
*
* Ohad Ben - Cohen < ohad @ wizery . com >
* Brian Swetland < swetland @ google . com >
*/
# ifndef REMOTEPROC_INTERNAL_H
# define REMOTEPROC_INTERNAL_H
# include <linux/irqreturn.h>
2012-07-15 12:25:27 +04:00
# include <linux/firmware.h>
2011-10-20 18:52:46 +04:00
struct rproc ;
2019-01-10 16:49:10 +03:00
struct rproc_debug_trace {
struct rproc * rproc ;
struct dentry * tfile ;
struct list_head node ;
struct rproc_mem_entry trace_mem ;
} ;
2022-09-21 16:50:41 +03:00
/**
* struct rproc_vdev_data - remoteproc virtio device data
* @ rsc_offset : offset of the vdev ' s resource entry
* @ id : virtio device id ( as in virtio_ids . h )
* @ index : vdev position versus other vdev declared in resource table
* @ rsc : pointer to the vdev resource entry . Valid only during vdev init as
* the resource can be cached by rproc .
*/
struct rproc_vdev_data {
u32 rsc_offset ;
unsigned int id ;
u32 index ;
struct fw_rsc_vdev * rsc ;
} ;
2022-09-28 09:47:55 +03:00
static inline bool rproc_has_feature ( struct rproc * rproc , unsigned int feature )
{
return test_bit ( feature , rproc - > features ) ;
}
static inline int rproc_set_feature ( struct rproc * rproc , unsigned int feature )
{
if ( feature > = RPROC_MAX_FEATURES )
return - EINVAL ;
set_bit ( feature , rproc - > features ) ;
return 0 ;
}
2011-10-20 18:52:46 +04:00
/* from remoteproc_core.c */
void rproc_release ( struct kref * kref ) ;
2020-07-22 01:36:13 +03:00
int rproc_of_parse_firmware ( struct device * dev , int index ,
const char * * fw_name ) ;
2011-10-20 18:52:46 +04:00
2012-02-14 01:30:39 +04:00
/* from remoteproc_virtio.c */
2022-09-21 16:50:43 +03:00
irqreturn_t rproc_vq_interrupt ( struct rproc * rproc , int vq_id ) ;
2011-10-20 18:52:46 +04:00
/* from remoteproc_debugfs.c */
void rproc_remove_trace_file ( struct dentry * tfile ) ;
struct dentry * rproc_create_trace_file ( const char * name , struct rproc * rproc ,
2019-01-10 16:49:10 +03:00
struct rproc_debug_trace * trace ) ;
2011-10-20 18:52:46 +04:00
void rproc_delete_debug_dir ( struct rproc * rproc ) ;
void rproc_create_debug_dir ( struct rproc * rproc ) ;
void rproc_init_debugfs ( void ) ;
void rproc_exit_debugfs ( void ) ;
2016-10-19 15:05:47 +03:00
/* from remoteproc_sysfs.c */
extern struct class rproc_class ;
int rproc_init_sysfs ( void ) ;
void rproc_exit_sysfs ( void ) ;
2020-07-29 20:40:00 +03:00
# ifdef CONFIG_REMOTEPROC_CDEV
void rproc_init_cdev ( void ) ;
void rproc_exit_cdev ( void ) ;
int rproc_char_device_add ( struct rproc * rproc ) ;
void rproc_char_device_remove ( struct rproc * rproc ) ;
# else
static inline void rproc_init_cdev ( void )
{
}
static inline void rproc_exit_cdev ( void )
{
}
/*
* The character device interface is an optional feature , if it is not enabled
* the function should not return an error .
*/
static inline int rproc_char_device_add ( struct rproc * rproc )
{
return 0 ;
}
static inline void rproc_char_device_remove ( struct rproc * rproc )
{
}
# endif
2012-05-17 15:23:59 +04:00
void rproc_free_vring ( struct rproc_vring * rvring ) ;
int rproc_alloc_vring ( struct rproc_vdev * rvdev , int i ) ;
2022-09-21 16:50:43 +03:00
int rproc_parse_vring ( struct rproc_vdev * rvdev , struct fw_rsc_vdev * rsc , int i ) ;
2012-07-15 12:25:27 +04:00
2019-01-10 16:50:49 +03:00
phys_addr_t rproc_va_to_pa ( void * cpu_addr ) ;
2012-08-30 22:26:13 +04:00
int rproc_trigger_recovery ( struct rproc * rproc ) ;
2012-07-15 12:25:27 +04:00
2020-03-02 12:39:00 +03:00
int rproc_elf_sanity_check ( struct rproc * rproc , const struct firmware * fw ) ;
2020-03-02 12:38:57 +03:00
u64 rproc_elf_get_boot_addr ( struct rproc * rproc , const struct firmware * fw ) ;
2018-01-06 02:58:01 +03:00
int rproc_elf_load_segments ( struct rproc * rproc , const struct firmware * fw ) ;
2018-01-06 02:58:03 +03:00
int rproc_elf_load_rsc_table ( struct rproc * rproc , const struct firmware * fw ) ;
2018-01-06 02:58:01 +03:00
struct resource_table * rproc_elf_find_loaded_rsc_table ( struct rproc * rproc ,
const struct firmware * fw ) ;
2018-07-27 16:14:47 +03:00
struct rproc_mem_entry *
rproc_find_carveout_by_name ( struct rproc * rproc , const char * name , . . . ) ;
2022-09-21 16:50:43 +03:00
void rproc_add_rvdev ( struct rproc * rproc , struct rproc_vdev * rvdev ) ;
void rproc_remove_rvdev ( struct rproc_vdev * rvdev ) ;
2018-01-06 02:58:01 +03:00
2020-04-17 03:20:35 +03:00
static inline int rproc_prepare_device ( struct rproc * rproc )
{
if ( rproc - > ops - > prepare )
return rproc - > ops - > prepare ( rproc ) ;
return 0 ;
}
static inline int rproc_unprepare_device ( struct rproc * rproc )
{
if ( rproc - > ops - > unprepare )
return rproc - > ops - > unprepare ( rproc ) ;
return 0 ;
}
2020-07-14 22:50:28 +03:00
static inline int rproc_attach_device ( struct rproc * rproc )
{
if ( rproc - > ops - > attach )
return rproc - > ops - > attach ( rproc ) ;
return 0 ;
}
2012-06-19 11:08:18 +04:00
static inline
int rproc_fw_sanity_check ( struct rproc * rproc , const struct firmware * fw )
{
2018-01-06 02:58:01 +03:00
if ( rproc - > ops - > sanity_check )
return rproc - > ops - > sanity_check ( rproc , fw ) ;
2012-06-19 11:08:18 +04:00
return 0 ;
}
static inline
2020-03-02 12:38:57 +03:00
u64 rproc_get_boot_addr ( struct rproc * rproc , const struct firmware * fw )
2012-06-19 11:08:18 +04:00
{
2018-01-06 02:58:01 +03:00
if ( rproc - > ops - > get_boot_addr )
return rproc - > ops - > get_boot_addr ( rproc , fw ) ;
2012-06-19 11:08:18 +04:00
return 0 ;
}
static inline
int rproc_load_segments ( struct rproc * rproc , const struct firmware * fw )
{
2018-01-06 02:58:01 +03:00
if ( rproc - > ops - > load )
return rproc - > ops - > load ( rproc , fw ) ;
2012-06-19 11:08:18 +04:00
return - EINVAL ;
}
2018-01-06 03:04:18 +03:00
static inline int rproc_parse_fw ( struct rproc * rproc , const struct firmware * fw )
2012-06-19 11:08:18 +04:00
{
2018-01-06 03:04:18 +03:00
if ( rproc - > ops - > parse_fw )
return rproc - > ops - > parse_fw ( rproc , fw ) ;
2012-06-19 11:08:18 +04:00
2018-01-06 02:58:03 +03:00
return 0 ;
2012-06-19 11:08:18 +04:00
}
2019-06-17 15:57:30 +03:00
static inline
int rproc_handle_rsc ( struct rproc * rproc , u32 rsc_type , void * rsc , int offset ,
int avail )
{
if ( rproc - > ops - > handle_rsc )
return rproc - > ops - > handle_rsc ( rproc , rsc_type , rsc , offset ,
avail ) ;
return RSC_IGNORED ;
}
2013-02-21 21:15:34 +04:00
static inline
struct resource_table * rproc_find_loaded_rsc_table ( struct rproc * rproc ,
2016-08-13 02:42:20 +03:00
const struct firmware * fw )
2013-02-21 21:15:34 +04:00
{
2018-01-06 02:58:01 +03:00
if ( rproc - > ops - > find_loaded_rsc_table )
return rproc - > ops - > find_loaded_rsc_table ( rproc , fw ) ;
2013-02-21 21:15:34 +04:00
2013-06-30 12:33:05 +04:00
return NULL ;
2013-02-21 21:15:34 +04:00
}
2021-03-12 19:24:41 +03:00
static inline
struct resource_table * rproc_get_loaded_rsc_table ( struct rproc * rproc ,
size_t * size )
{
if ( rproc - > ops - > get_loaded_rsc_table )
return rproc - > ops - > get_loaded_rsc_table ( rproc , size ) ;
return NULL ;
}
2020-03-02 12:39:00 +03:00
static inline
bool rproc_u64_fit_in_size_t ( u64 val )
{
if ( sizeof ( size_t ) = = sizeof ( u64 ) )
return true ;
return ( val < = ( size_t ) - 1 ) ;
}
2011-10-20 18:52:46 +04:00
# endif /* REMOTEPROC_INTERNAL_H */