diff options
author | Ji Soo Shin <jisshin@google.com> | 2023-05-24 13:24:25 +0200 |
---|---|---|
committer | Ji Soo Shin <jisshin@google.com> | 2023-05-26 18:30:55 +0200 |
commit | 2c29144d8fc90e33601e594b3c2b922b5fc34811 (patch) | |
tree | c060bbfcfae4ee6306ef30ebfab5733facbb3c39 | |
parent | c7e4bc6168648e93a5183b1d5b3e1f05c029f802 (diff) | |
download | trusty-2c29144d8fc90e33601e594b3c2b922b5fc34811.tar.gz |
ANDROID: trusty: remove cyclic dependency
Typically, other kernel modules depend on Trusty for claiming
reserving secure buffer. Usually that same module is also responsible
for providing dma buffer information through tipc. This results in
cyclic dependency - and this caused more headaches across platforms
than necessary to justify keeping current compile-time optimization.
Bug: 284002500
Change-Id: Ib60f14b6b3731c0a6d1124c2c22fc963db9518bf
Signed-off-by: Ji Soo Shin <jisshin@google.com>
-rw-r--r-- | drivers/trusty/trusty-ipc.c | 26 | ||||
-rw-r--r-- | include/linux/trusty/trusty.h | 39 |
2 files changed, 30 insertions, 35 deletions
diff --git a/drivers/trusty/trusty-ipc.c b/drivers/trusty/trusty-ipc.c index af0deda..26648c9 100644 --- a/drivers/trusty/trusty-ipc.c +++ b/drivers/trusty/trusty-ipc.c @@ -185,6 +185,22 @@ static struct virtio_device *default_vdev; static DEFINE_IDR(tipc_devices); static DEFINE_MUTEX(tipc_devices_lock); +static u64 (*dma_buf_get_ffa_tag)(struct dma_buf *dma_buf) = NULL; +static int (*dma_buf_get_shared_mem_id)(struct dma_buf *dma_buf, + trusty_shared_mem_id_t *id) = NULL; + +static inline u64 trusty_dma_buf_get_ffa_tag(struct dma_buf *dma_buf) +{ + return dma_buf_get_ffa_tag ? dma_buf_get_ffa_tag(dma_buf) : 0; +} + +static int trusty_dma_buf_get_shared_mem_id(struct dma_buf *dma_buf, + trusty_shared_mem_id_t *id) +{ + return dma_buf_get_shared_mem_id ? + dma_buf_get_shared_mem_id(dma_buf, id) : -ENODATA; +} + static int _match_any(int id, void *p, void *data) { return id; @@ -2282,6 +2298,16 @@ static void __exit tipc_exit(void) unregister_chrdev_region(MKDEV(tipc_major, 0), MAX_DEVICES); } +void trusty_register_func_for_dma_buf( + u64 (*get_ffa_tag)(struct dma_buf *dma_buf), + int (*get_shared_mem_id)(struct dma_buf *dma_buf, + trusty_shared_mem_id_t *id)) +{ + dma_buf_get_ffa_tag = get_ffa_tag; + dma_buf_get_shared_mem_id = get_shared_mem_id; +} +EXPORT_SYMBOL_GPL(trusty_register_func_for_dma_buf); + /* We need to init this early */ subsys_initcall(tipc_init); module_exit(tipc_exit); diff --git a/include/linux/trusty/trusty.h b/include/linux/trusty/trusty.h index 751e5c7..41680f9 100644 --- a/include/linux/trusty/trusty.h +++ b/include/linux/trusty/trusty.h @@ -83,41 +83,10 @@ int trusty_reclaim_memory(struct device *dev, trusty_shared_mem_id_t id, struct scatterlist *sglist, unsigned int nents); struct dma_buf; -#ifdef CONFIG_TRUSTY_DMA_BUF_FFA_TAG -u64 trusty_dma_buf_get_ffa_tag(struct dma_buf *dma_buf); -#else -static inline u64 trusty_dma_buf_get_ffa_tag(struct dma_buf *dma_buf) -{ - return 0; -} -#endif - -/* Invalid handle value is defined by FF-A spec */ -#ifdef CONFIG_TRUSTY_DMA_BUF_SHARED_MEM_ID -/** - * trusty_dma_buf_get_shared_mem_id() - Get memory ID corresponding to a dma_buf - * @dma_buf: DMA buffer - * @id: Pointer to output trusty_shared_mem_id_t - * - * Sets @id to trusty_shared_mem_id_t corresponding to the given @dma_buf. - * @dma_buf "owns" the ID, i.e. is responsible for allocating/releasing it. - * @dma_buf with an allocated @id must be in secure memory and should only be - * sent to Trusty using TRUSTY_SEND_SECURE. - * - * Return: - * * 0 - success - * * -ENODATA - @dma_buf does not own a trusty_shared_mem_id_t - * * ... - @dma_buf should not be lent or shared - */ -int trusty_dma_buf_get_shared_mem_id(struct dma_buf *dma_buf, - trusty_shared_mem_id_t *id); -#else -static inline int trusty_dma_buf_get_shared_mem_id(struct dma_buf *dma_buf, - trusty_shared_mem_id_t *id) -{ - return -ENODATA; -} -#endif +void trusty_register_func_for_dma_buf( + u64 (*get_ffa_tag)(struct dma_buf *dma_buf), + int (*get_shared_mem_id)(struct dma_buf *dma_buf, + trusty_shared_mem_id_t *id)); struct trusty_nop { struct list_head node; |