mirror of
https://github.com/lkl/linux.git
synced 2025-12-19 16:13:19 +09:00
firmware: arm_ffa: Split up ffa_ops into info, message and memory operations
In preparation to make memory operations accessible for a non ffa_driver/device, it is better to split the ffa_ops into different categories of operations: info, message and memory. The info and memory are ffa_device independent and can be used without any associated ffa_device from a non ffa_driver. However, we don't export these info and memory APIs yet without the user. The first users of these APIs can export them. Link: https://lore.kernel.org/r/20220907145240.1683088-11-sudeep.holla@arm.com Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
This commit is contained in:
@@ -691,16 +691,28 @@ static int ffa_memory_lend(struct ffa_mem_ops_args *args)
|
|||||||
return ffa_memory_ops(FFA_MEM_LEND, args);
|
return ffa_memory_ops(FFA_MEM_LEND, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct ffa_ops ffa_ops = {
|
static const struct ffa_info_ops ffa_drv_info_ops = {
|
||||||
.api_version_get = ffa_api_version_get,
|
.api_version_get = ffa_api_version_get,
|
||||||
.partition_info_get = ffa_partition_info_get,
|
.partition_info_get = ffa_partition_info_get,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct ffa_msg_ops ffa_drv_msg_ops = {
|
||||||
.mode_32bit_set = ffa_mode_32bit_set,
|
.mode_32bit_set = ffa_mode_32bit_set,
|
||||||
.sync_send_receive = ffa_sync_send_receive,
|
.sync_send_receive = ffa_sync_send_receive,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct ffa_mem_ops ffa_drv_mem_ops = {
|
||||||
.memory_reclaim = ffa_memory_reclaim,
|
.memory_reclaim = ffa_memory_reclaim,
|
||||||
.memory_share = ffa_memory_share,
|
.memory_share = ffa_memory_share,
|
||||||
.memory_lend = ffa_memory_lend,
|
.memory_lend = ffa_memory_lend,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const struct ffa_ops ffa_drv_ops = {
|
||||||
|
.info_ops = &ffa_drv_info_ops,
|
||||||
|
.msg_ops = &ffa_drv_msg_ops,
|
||||||
|
.mem_ops = &ffa_drv_mem_ops,
|
||||||
|
};
|
||||||
|
|
||||||
void ffa_device_match_uuid(struct ffa_device *ffa_dev, const uuid_t *uuid)
|
void ffa_device_match_uuid(struct ffa_device *ffa_dev, const uuid_t *uuid)
|
||||||
{
|
{
|
||||||
int count, idx;
|
int count, idx;
|
||||||
@@ -746,7 +758,7 @@ static void ffa_setup_partitions(void)
|
|||||||
* provides UUID here for each partition as part of the
|
* provides UUID here for each partition as part of the
|
||||||
* discovery API and the same is passed.
|
* discovery API and the same is passed.
|
||||||
*/
|
*/
|
||||||
ffa_dev = ffa_device_register(&uuid, tpbuf->id, &ffa_ops);
|
ffa_dev = ffa_device_register(&uuid, tpbuf->id, &ffa_drv_ops);
|
||||||
if (!ffa_dev) {
|
if (!ffa_dev) {
|
||||||
pr_err("%s: failed to register partition ID 0x%x\n",
|
pr_err("%s: failed to register partition ID 0x%x\n",
|
||||||
__func__, tpbuf->id);
|
__func__, tpbuf->id);
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ static int optee_ffa_shm_register(struct tee_context *ctx, struct tee_shm *shm,
|
|||||||
{
|
{
|
||||||
struct optee *optee = tee_get_drvdata(ctx->teedev);
|
struct optee *optee = tee_get_drvdata(ctx->teedev);
|
||||||
struct ffa_device *ffa_dev = optee->ffa.ffa_dev;
|
struct ffa_device *ffa_dev = optee->ffa.ffa_dev;
|
||||||
const struct ffa_ops *ffa_ops = ffa_dev->ops;
|
const struct ffa_mem_ops *mem_ops = ffa_dev->ops->mem_ops;
|
||||||
struct ffa_mem_region_attributes mem_attr = {
|
struct ffa_mem_region_attributes mem_attr = {
|
||||||
.receiver = ffa_dev->vm_id,
|
.receiver = ffa_dev->vm_id,
|
||||||
.attrs = FFA_MEM_RW,
|
.attrs = FFA_MEM_RW,
|
||||||
@@ -294,14 +294,14 @@ static int optee_ffa_shm_register(struct tee_context *ctx, struct tee_shm *shm,
|
|||||||
if (rc)
|
if (rc)
|
||||||
return rc;
|
return rc;
|
||||||
args.sg = sgt.sgl;
|
args.sg = sgt.sgl;
|
||||||
rc = ffa_ops->memory_share(&args);
|
rc = mem_ops->memory_share(&args);
|
||||||
sg_free_table(&sgt);
|
sg_free_table(&sgt);
|
||||||
if (rc)
|
if (rc)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
rc = optee_shm_add_ffa_handle(optee, shm, args.g_handle);
|
rc = optee_shm_add_ffa_handle(optee, shm, args.g_handle);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
ffa_ops->memory_reclaim(args.g_handle, 0);
|
mem_ops->memory_reclaim(args.g_handle, 0);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,7 +315,8 @@ static int optee_ffa_shm_unregister(struct tee_context *ctx,
|
|||||||
{
|
{
|
||||||
struct optee *optee = tee_get_drvdata(ctx->teedev);
|
struct optee *optee = tee_get_drvdata(ctx->teedev);
|
||||||
struct ffa_device *ffa_dev = optee->ffa.ffa_dev;
|
struct ffa_device *ffa_dev = optee->ffa.ffa_dev;
|
||||||
const struct ffa_ops *ffa_ops = ffa_dev->ops;
|
const struct ffa_msg_ops *msg_ops = ffa_dev->ops->msg_ops;
|
||||||
|
const struct ffa_mem_ops *mem_ops = ffa_dev->ops->mem_ops;
|
||||||
u64 global_handle = shm->sec_world_id;
|
u64 global_handle = shm->sec_world_id;
|
||||||
struct ffa_send_direct_data data = {
|
struct ffa_send_direct_data data = {
|
||||||
.data0 = OPTEE_FFA_UNREGISTER_SHM,
|
.data0 = OPTEE_FFA_UNREGISTER_SHM,
|
||||||
@@ -327,11 +328,11 @@ static int optee_ffa_shm_unregister(struct tee_context *ctx,
|
|||||||
optee_shm_rem_ffa_handle(optee, global_handle);
|
optee_shm_rem_ffa_handle(optee, global_handle);
|
||||||
shm->sec_world_id = 0;
|
shm->sec_world_id = 0;
|
||||||
|
|
||||||
rc = ffa_ops->sync_send_receive(ffa_dev, &data);
|
rc = msg_ops->sync_send_receive(ffa_dev, &data);
|
||||||
if (rc)
|
if (rc)
|
||||||
pr_err("Unregister SHM id 0x%llx rc %d\n", global_handle, rc);
|
pr_err("Unregister SHM id 0x%llx rc %d\n", global_handle, rc);
|
||||||
|
|
||||||
rc = ffa_ops->memory_reclaim(global_handle, 0);
|
rc = mem_ops->memory_reclaim(global_handle, 0);
|
||||||
if (rc)
|
if (rc)
|
||||||
pr_err("mem_reclaim: 0x%llx %d", global_handle, rc);
|
pr_err("mem_reclaim: 0x%llx %d", global_handle, rc);
|
||||||
|
|
||||||
@@ -342,7 +343,7 @@ static int optee_ffa_shm_unregister_supp(struct tee_context *ctx,
|
|||||||
struct tee_shm *shm)
|
struct tee_shm *shm)
|
||||||
{
|
{
|
||||||
struct optee *optee = tee_get_drvdata(ctx->teedev);
|
struct optee *optee = tee_get_drvdata(ctx->teedev);
|
||||||
const struct ffa_ops *ffa_ops = optee->ffa.ffa_dev->ops;
|
const struct ffa_mem_ops *mem_ops;
|
||||||
u64 global_handle = shm->sec_world_id;
|
u64 global_handle = shm->sec_world_id;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
@@ -353,7 +354,8 @@ static int optee_ffa_shm_unregister_supp(struct tee_context *ctx,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
optee_shm_rem_ffa_handle(optee, global_handle);
|
optee_shm_rem_ffa_handle(optee, global_handle);
|
||||||
rc = ffa_ops->memory_reclaim(global_handle, 0);
|
mem_ops = optee->ffa.ffa_dev->ops->mem_ops;
|
||||||
|
rc = mem_ops->memory_reclaim(global_handle, 0);
|
||||||
if (rc)
|
if (rc)
|
||||||
pr_err("mem_reclaim: 0x%llx %d", global_handle, rc);
|
pr_err("mem_reclaim: 0x%llx %d", global_handle, rc);
|
||||||
|
|
||||||
@@ -530,7 +532,7 @@ static int optee_ffa_yielding_call(struct tee_context *ctx,
|
|||||||
{
|
{
|
||||||
struct optee *optee = tee_get_drvdata(ctx->teedev);
|
struct optee *optee = tee_get_drvdata(ctx->teedev);
|
||||||
struct ffa_device *ffa_dev = optee->ffa.ffa_dev;
|
struct ffa_device *ffa_dev = optee->ffa.ffa_dev;
|
||||||
const struct ffa_ops *ffa_ops = ffa_dev->ops;
|
const struct ffa_msg_ops *msg_ops = ffa_dev->ops->msg_ops;
|
||||||
struct optee_call_waiter w;
|
struct optee_call_waiter w;
|
||||||
u32 cmd = data->data0;
|
u32 cmd = data->data0;
|
||||||
u32 w4 = data->data1;
|
u32 w4 = data->data1;
|
||||||
@@ -541,7 +543,7 @@ static int optee_ffa_yielding_call(struct tee_context *ctx,
|
|||||||
/* Initialize waiter */
|
/* Initialize waiter */
|
||||||
optee_cq_wait_init(&optee->call_queue, &w);
|
optee_cq_wait_init(&optee->call_queue, &w);
|
||||||
while (true) {
|
while (true) {
|
||||||
rc = ffa_ops->sync_send_receive(ffa_dev, data);
|
rc = msg_ops->sync_send_receive(ffa_dev, data);
|
||||||
if (rc)
|
if (rc)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
@@ -576,7 +578,7 @@ static int optee_ffa_yielding_call(struct tee_context *ctx,
|
|||||||
* OP-TEE has returned with a RPC request.
|
* OP-TEE has returned with a RPC request.
|
||||||
*
|
*
|
||||||
* Note that data->data4 (passed in register w7) is already
|
* Note that data->data4 (passed in register w7) is already
|
||||||
* filled in by ffa_ops->sync_send_receive() returning
|
* filled in by ffa_mem_ops->sync_send_receive() returning
|
||||||
* above.
|
* above.
|
||||||
*/
|
*/
|
||||||
cond_resched();
|
cond_resched();
|
||||||
@@ -654,12 +656,13 @@ static int optee_ffa_do_call_with_arg(struct tee_context *ctx,
|
|||||||
static bool optee_ffa_api_is_compatbile(struct ffa_device *ffa_dev,
|
static bool optee_ffa_api_is_compatbile(struct ffa_device *ffa_dev,
|
||||||
const struct ffa_ops *ops)
|
const struct ffa_ops *ops)
|
||||||
{
|
{
|
||||||
|
const struct ffa_msg_ops *msg_ops = ops->msg_ops;
|
||||||
struct ffa_send_direct_data data = { OPTEE_FFA_GET_API_VERSION };
|
struct ffa_send_direct_data data = { OPTEE_FFA_GET_API_VERSION };
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
ops->mode_32bit_set(ffa_dev);
|
msg_ops->mode_32bit_set(ffa_dev);
|
||||||
|
|
||||||
rc = ops->sync_send_receive(ffa_dev, &data);
|
rc = msg_ops->sync_send_receive(ffa_dev, &data);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
pr_err("Unexpected error %d\n", rc);
|
pr_err("Unexpected error %d\n", rc);
|
||||||
return false;
|
return false;
|
||||||
@@ -672,7 +675,7 @@ static bool optee_ffa_api_is_compatbile(struct ffa_device *ffa_dev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
data = (struct ffa_send_direct_data){ OPTEE_FFA_GET_OS_VERSION };
|
data = (struct ffa_send_direct_data){ OPTEE_FFA_GET_OS_VERSION };
|
||||||
rc = ops->sync_send_receive(ffa_dev, &data);
|
rc = msg_ops->sync_send_receive(ffa_dev, &data);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
pr_err("Unexpected error %d\n", rc);
|
pr_err("Unexpected error %d\n", rc);
|
||||||
return false;
|
return false;
|
||||||
@@ -694,7 +697,7 @@ static bool optee_ffa_exchange_caps(struct ffa_device *ffa_dev,
|
|||||||
struct ffa_send_direct_data data = { OPTEE_FFA_EXCHANGE_CAPABILITIES };
|
struct ffa_send_direct_data data = { OPTEE_FFA_EXCHANGE_CAPABILITIES };
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = ops->sync_send_receive(ffa_dev, &data);
|
rc = ops->msg_ops->sync_send_receive(ffa_dev, &data);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
pr_err("Unexpected error %d", rc);
|
pr_err("Unexpected error %d", rc);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -257,16 +257,28 @@ struct ffa_mem_ops_args {
|
|||||||
struct ffa_mem_region_attributes *attrs;
|
struct ffa_mem_region_attributes *attrs;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ffa_ops {
|
struct ffa_info_ops {
|
||||||
u32 (*api_version_get)(void);
|
u32 (*api_version_get)(void);
|
||||||
int (*partition_info_get)(const char *uuid_str,
|
int (*partition_info_get)(const char *uuid_str,
|
||||||
struct ffa_partition_info *buffer);
|
struct ffa_partition_info *buffer);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ffa_msg_ops {
|
||||||
void (*mode_32bit_set)(struct ffa_device *dev);
|
void (*mode_32bit_set)(struct ffa_device *dev);
|
||||||
int (*sync_send_receive)(struct ffa_device *dev,
|
int (*sync_send_receive)(struct ffa_device *dev,
|
||||||
struct ffa_send_direct_data *data);
|
struct ffa_send_direct_data *data);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ffa_mem_ops {
|
||||||
int (*memory_reclaim)(u64 g_handle, u32 flags);
|
int (*memory_reclaim)(u64 g_handle, u32 flags);
|
||||||
int (*memory_share)(struct ffa_mem_ops_args *args);
|
int (*memory_share)(struct ffa_mem_ops_args *args);
|
||||||
int (*memory_lend)(struct ffa_mem_ops_args *args);
|
int (*memory_lend)(struct ffa_mem_ops_args *args);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ffa_ops {
|
||||||
|
const struct ffa_info_ops *info_ops;
|
||||||
|
const struct ffa_msg_ops *msg_ops;
|
||||||
|
const struct ffa_mem_ops *mem_ops;
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* _LINUX_ARM_FFA_H */
|
#endif /* _LINUX_ARM_FFA_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user