1 /* SPDX-License-Identifier: GPL-2.0-or-later * 1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 2 /* 3 * Driver for Qualcomm Secure Execution Enviro 3 * Driver for Qualcomm Secure Execution Environment (SEE) interface (QSEECOM). 4 * Responsible for setting up and managing QSE 4 * Responsible for setting up and managing QSEECOM client devices. 5 * 5 * 6 * Copyright (C) 2023 Maximilian Luz <luzmaxim 6 * Copyright (C) 2023 Maximilian Luz <luzmaximilian@gmail.com> 7 */ 7 */ 8 8 9 #ifndef __QCOM_QSEECOM_H 9 #ifndef __QCOM_QSEECOM_H 10 #define __QCOM_QSEECOM_H 10 #define __QCOM_QSEECOM_H 11 11 12 #include <linux/auxiliary_bus.h> 12 #include <linux/auxiliary_bus.h> 13 #include <linux/dma-mapping.h> 13 #include <linux/dma-mapping.h> 14 #include <linux/types.h> 14 #include <linux/types.h> 15 15 16 #include <linux/firmware/qcom/qcom_scm.h> 16 #include <linux/firmware/qcom/qcom_scm.h> 17 17 18 /** 18 /** 19 * struct qseecom_client - QSEECOM client devi 19 * struct qseecom_client - QSEECOM client device. 20 * @aux_dev: Underlying auxiliary device. 20 * @aux_dev: Underlying auxiliary device. 21 * @app_id: ID of the loaded application. 21 * @app_id: ID of the loaded application. 22 */ 22 */ 23 struct qseecom_client { 23 struct qseecom_client { 24 struct auxiliary_device aux_dev; 24 struct auxiliary_device aux_dev; 25 u32 app_id; 25 u32 app_id; 26 }; 26 }; 27 27 28 /** 28 /** >> 29 * qseecom_scm_dev() - Get the SCM device associated with the QSEECOM client. >> 30 * @client: The QSEECOM client device. >> 31 * >> 32 * Returns the SCM device under which the provided QSEECOM client device >> 33 * operates. This function is intended to be used for DMA allocations. >> 34 */ >> 35 static inline struct device *qseecom_scm_dev(struct qseecom_client *client) >> 36 { >> 37 return client->aux_dev.dev.parent->parent; >> 38 } >> 39 >> 40 /** >> 41 * qseecom_dma_alloc() - Allocate DMA memory for a QSEECOM client. >> 42 * @client: The QSEECOM client to allocate the memory for. >> 43 * @size: The number of bytes to allocate. >> 44 * @dma_handle: Pointer to where the DMA address should be stored. >> 45 * @gfp: Allocation flags. >> 46 * >> 47 * Wrapper function for dma_alloc_coherent(), allocating DMA memory usable for >> 48 * TZ/QSEECOM communication. Refer to dma_alloc_coherent() for details. >> 49 */ >> 50 static inline void *qseecom_dma_alloc(struct qseecom_client *client, size_t size, >> 51 dma_addr_t *dma_handle, gfp_t gfp) >> 52 { >> 53 return dma_alloc_coherent(qseecom_scm_dev(client), size, dma_handle, gfp); >> 54 } >> 55 >> 56 /** >> 57 * dma_free_coherent() - Free QSEECOM DMA memory. >> 58 * @client: The QSEECOM client for which the memory has been allocated. >> 59 * @size: The number of bytes allocated. >> 60 * @cpu_addr: Virtual memory address to free. >> 61 * @dma_handle: DMA memory address to free. >> 62 * >> 63 * Wrapper function for dma_free_coherent(), freeing memory previously >> 64 * allocated with qseecom_dma_alloc(). Refer to dma_free_coherent() for >> 65 * details. >> 66 */ >> 67 static inline void qseecom_dma_free(struct qseecom_client *client, size_t size, >> 68 void *cpu_addr, dma_addr_t dma_handle) >> 69 { >> 70 return dma_free_coherent(qseecom_scm_dev(client), size, cpu_addr, dma_handle); >> 71 } >> 72 >> 73 /** 29 * qcom_qseecom_app_send() - Send to and recei 74 * qcom_qseecom_app_send() - Send to and receive data from a given QSEE app. 30 * @client: The QSEECOM client associated wi 75 * @client: The QSEECOM client associated with the target app. 31 * @req: Request buffer sent to the app ( !! 76 * @req: DMA address of the request buffer sent to the app. 32 * @req_size: Size of the request buffer. 77 * @req_size: Size of the request buffer. 33 * @rsp: Response buffer, written to by t !! 78 * @rsp: DMA address of the response buffer, written to by the app. 34 * @rsp_size: Size of the response buffer. 79 * @rsp_size: Size of the response buffer. 35 * 80 * 36 * Sends a request to the QSEE app associated 81 * Sends a request to the QSEE app associated with the given client and read 37 * back its response. The caller must provide 82 * back its response. The caller must provide two DMA memory regions, one for 38 * the request and one for the response, and f 83 * the request and one for the response, and fill out the @req region with the 39 * respective (app-specific) request data. The 84 * respective (app-specific) request data. The QSEE app reads this and returns 40 * its response in the @rsp region. 85 * its response in the @rsp region. 41 * 86 * 42 * Note: This is a convenience wrapper around 87 * Note: This is a convenience wrapper around qcom_scm_qseecom_app_send(). 43 * Clients should prefer to use this wrapper. 88 * Clients should prefer to use this wrapper. 44 * 89 * 45 * Return: Zero on success, nonzero on failure 90 * Return: Zero on success, nonzero on failure. 46 */ 91 */ 47 static inline int qcom_qseecom_app_send(struct 92 static inline int qcom_qseecom_app_send(struct qseecom_client *client, 48 void * !! 93 dma_addr_t req, size_t req_size, 49 void * !! 94 dma_addr_t rsp, size_t rsp_size) 50 { 95 { 51 return qcom_scm_qseecom_app_send(clien 96 return qcom_scm_qseecom_app_send(client->app_id, req, req_size, rsp, rsp_size); 52 } 97 } 53 98 54 #endif /* __QCOM_QSEECOM_H */ 99 #endif /* __QCOM_QSEECOM_H */ 55 100
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.