- Remove a redundant custom workqueue in the OP-TEE driver. - Fix a missing description of an argument to optee_handle_rpc(). -----BEGIN PGP SIGNATURE----- iQJOBAABCgA4FiEEFV+gSSXZJY9ZyuB5LinzTIcAHJcFAmV6/wIaHGplbnMud2lr bGFuZGVyQGxpbmFyby5vcmcACgkQLinzTIcAHJezhg//alxgaOOJABnzWxBwEUc6 /gAEmt5qOt68JyeMN2f/I5XARlrmFM93QIOM7KLFNpQ1GoMxLm8kEgz6glUSfi1Z lncCD7F+egn3ix4bwvbhMMmhVE4doyg+aof4m5628mFTj7MIesFGjAgffhAP+Cla R5clf/JDohl5NKgISwZjKIIK+QtT61hzy8TvPtiPkrMcLB2G03yhv6X5M5Lkz73V m4JRlMbs/RBoKwlEgFJYTC4PTQboKLlUZ0gyfTHTTR5LQpq2aR4SMRLQcc/uMphn 1o4falN7zcCar0Is8AD92ja0Uy2J4HyC52u8nvkhIZVbnU9eP5P/vR053CwIfJMj WGogOdAFTbunp/fvjImuUbxfyOjHKfOoMGpzYCS3DiNusP8mmHyw+SctPGGFWkqQ Rd8qz11e/FmD1vq0e0Xm4TAXDWitbJDTCi/noN8X59ShXPIFsRBf6ooeNwbtwHgV fNiU8x5r0QjuV7iuEIVvBokMg883zb6njPEwiez5axblkYthxtXfgPi8cNtiA347 8s/NFtuxMiyK74TE+Wfkb+iURC/MpHDelTOXyYT3D9ZGIGF5x6rS6nOgs0+gEZ5J 19S6pPxvNs6UaDSlDta60qzGOB9WqULkI2QGDwqZ1M5PX49q+z/aM3m/Lim7FiUD Ee3FJpbSXyKNeKOX+per0Qg= =wAS6 -----END PGP SIGNATURE----- gpgsig -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEiK/NIGsWEZVxh/FrYKtH/8kJUicFAmWFdOYACgkQYKtH/8kJ UicH7RAApoSj4P686Hbjph7hFISEkICUHjnQ+gk2piQ6PRXTsaBuleI/8qtbk1Fd Qv6viRmslinxrd/ghovamjlv10W/IdCv+gC7Pjg3IHWiIW379H0aVKAiT//vFQQX +ioMjcVdFnoKZuimsrsmWPGKEE/DMVTArIK6vFIS6JSOBnZiIEtMYEecV2As2icx JjaLEBJQjW91PCjsN07jnkvKu/JepuVM6sZBrdf99i8HTtjVK6CpsaxEEBwPPq/r TpS8MekJwvszbng0P5zXUIrqEslEXwJO4bkJSptcvPKGN+Whn559ItL9fMo0lQU0 d7FWzyxlKZUKU5MpUr3ZET4ukovLYzTdOnux/4qpB/Y7cQWusI1EkLvMmStoFJG5 SYJH4OwpKLLZ3Mgvqgy1Rmjrp5NkWpCKrLu2PMZ948ag8zc5g/KFJitLK0AyT1ut havT0GTQRyl1w/7Tw6z9aCepUU9gyWfjHxV6Ej6izK656fD6O+TLgk2y5Zsrx9RY Slu3UA8DijXRpp95JBmoxxLh0hxxt+8DryU9RRADa8v//6lkJ0Gr8QzO4SVmDNr/ fl0he2CmyOyd3QEV+AG2/eobVSr4/Ka0nZEiu++zr7uar68uQgsi3i5XwjcTR5SX 4VtdTjeL/Orhdr6aRqtTIO56kI6jaRG5YHmpq4A3xQJUqncnMO4= =Ae+Z -----END PGP SIGNATURE----- Merge tag 'optee-cleanup-for-v6.8' of https://git.linaro.org/people/jens.wiklander/linux-tee into soc/drivers OP-TEE cleanup - Remove a redundant custom workqueue in the OP-TEE driver. - Fix a missing description of an argument to optee_handle_rpc(). * tag 'optee-cleanup-for-v6.8' of https://git.linaro.org/people/jens.wiklander/linux-tee: optee: add missing description of RPC argument reference tee: optee: Remove redundant custom workqueue tee: optee: Fix supplicant based device enumeration Link: https://lore.kernel.org/r/20231214132237.GA3092763@rayden Signed-off-by: Arnd Bergmann <arnd@arndb.de>
221 lines
5.2 KiB
C
221 lines
5.2 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright (c) 2015-2021, Linaro Limited
|
|
* Copyright (c) 2016, EPAM Systems
|
|
*/
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
#include <linux/crash_dump.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/io.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/module.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/string.h>
|
|
#include <linux/tee_drv.h>
|
|
#include <linux/types.h>
|
|
#include "optee_private.h"
|
|
|
|
int optee_pool_op_alloc_helper(struct tee_shm_pool *pool, struct tee_shm *shm,
|
|
size_t size, size_t align,
|
|
int (*shm_register)(struct tee_context *ctx,
|
|
struct tee_shm *shm,
|
|
struct page **pages,
|
|
size_t num_pages,
|
|
unsigned long start))
|
|
{
|
|
size_t nr_pages = roundup(size, PAGE_SIZE) / PAGE_SIZE;
|
|
struct page **pages;
|
|
unsigned int i;
|
|
int rc = 0;
|
|
|
|
/*
|
|
* Ignore alignment since this is already going to be page aligned
|
|
* and there's no need for any larger alignment.
|
|
*/
|
|
shm->kaddr = alloc_pages_exact(nr_pages * PAGE_SIZE,
|
|
GFP_KERNEL | __GFP_ZERO);
|
|
if (!shm->kaddr)
|
|
return -ENOMEM;
|
|
|
|
shm->paddr = virt_to_phys(shm->kaddr);
|
|
shm->size = nr_pages * PAGE_SIZE;
|
|
|
|
pages = kcalloc(nr_pages, sizeof(*pages), GFP_KERNEL);
|
|
if (!pages) {
|
|
rc = -ENOMEM;
|
|
goto err;
|
|
}
|
|
|
|
for (i = 0; i < nr_pages; i++)
|
|
pages[i] = virt_to_page((u8 *)shm->kaddr + i * PAGE_SIZE);
|
|
|
|
shm->pages = pages;
|
|
shm->num_pages = nr_pages;
|
|
|
|
if (shm_register) {
|
|
rc = shm_register(shm->ctx, shm, pages, nr_pages,
|
|
(unsigned long)shm->kaddr);
|
|
if (rc)
|
|
goto err;
|
|
}
|
|
|
|
return 0;
|
|
err:
|
|
free_pages_exact(shm->kaddr, shm->size);
|
|
shm->kaddr = NULL;
|
|
return rc;
|
|
}
|
|
|
|
void optee_pool_op_free_helper(struct tee_shm_pool *pool, struct tee_shm *shm,
|
|
int (*shm_unregister)(struct tee_context *ctx,
|
|
struct tee_shm *shm))
|
|
{
|
|
if (shm_unregister)
|
|
shm_unregister(shm->ctx, shm);
|
|
free_pages_exact(shm->kaddr, shm->size);
|
|
shm->kaddr = NULL;
|
|
kfree(shm->pages);
|
|
shm->pages = NULL;
|
|
}
|
|
|
|
static void optee_bus_scan(struct work_struct *work)
|
|
{
|
|
WARN_ON(optee_enumerate_devices(PTA_CMD_GET_DEVICES_SUPP));
|
|
}
|
|
|
|
int optee_open(struct tee_context *ctx, bool cap_memref_null)
|
|
{
|
|
struct optee_context_data *ctxdata;
|
|
struct tee_device *teedev = ctx->teedev;
|
|
struct optee *optee = tee_get_drvdata(teedev);
|
|
|
|
ctxdata = kzalloc(sizeof(*ctxdata), GFP_KERNEL);
|
|
if (!ctxdata)
|
|
return -ENOMEM;
|
|
|
|
if (teedev == optee->supp_teedev) {
|
|
bool busy = true;
|
|
|
|
mutex_lock(&optee->supp.mutex);
|
|
if (!optee->supp.ctx) {
|
|
busy = false;
|
|
optee->supp.ctx = ctx;
|
|
}
|
|
mutex_unlock(&optee->supp.mutex);
|
|
if (busy) {
|
|
kfree(ctxdata);
|
|
return -EBUSY;
|
|
}
|
|
|
|
if (!optee->scan_bus_done) {
|
|
INIT_WORK(&optee->scan_bus_work, optee_bus_scan);
|
|
schedule_work(&optee->scan_bus_work);
|
|
optee->scan_bus_done = true;
|
|
}
|
|
}
|
|
mutex_init(&ctxdata->mutex);
|
|
INIT_LIST_HEAD(&ctxdata->sess_list);
|
|
|
|
ctx->cap_memref_null = cap_memref_null;
|
|
ctx->data = ctxdata;
|
|
return 0;
|
|
}
|
|
|
|
static void optee_release_helper(struct tee_context *ctx,
|
|
int (*close_session)(struct tee_context *ctx,
|
|
u32 session,
|
|
bool system_thread))
|
|
{
|
|
struct optee_context_data *ctxdata = ctx->data;
|
|
struct optee_session *sess;
|
|
struct optee_session *sess_tmp;
|
|
|
|
if (!ctxdata)
|
|
return;
|
|
|
|
list_for_each_entry_safe(sess, sess_tmp, &ctxdata->sess_list,
|
|
list_node) {
|
|
list_del(&sess->list_node);
|
|
close_session(ctx, sess->session_id, sess->use_sys_thread);
|
|
kfree(sess);
|
|
}
|
|
kfree(ctxdata);
|
|
ctx->data = NULL;
|
|
}
|
|
|
|
void optee_release(struct tee_context *ctx)
|
|
{
|
|
optee_release_helper(ctx, optee_close_session_helper);
|
|
}
|
|
|
|
void optee_release_supp(struct tee_context *ctx)
|
|
{
|
|
struct optee *optee = tee_get_drvdata(ctx->teedev);
|
|
|
|
optee_release_helper(ctx, optee_close_session_helper);
|
|
|
|
optee_supp_release(&optee->supp);
|
|
}
|
|
|
|
void optee_remove_common(struct optee *optee)
|
|
{
|
|
/* Unregister OP-TEE specific client devices on TEE bus */
|
|
optee_unregister_devices();
|
|
|
|
optee_notif_uninit(optee);
|
|
optee_shm_arg_cache_uninit(optee);
|
|
teedev_close_context(optee->ctx);
|
|
/*
|
|
* The two devices have to be unregistered before we can free the
|
|
* other resources.
|
|
*/
|
|
tee_device_unregister(optee->supp_teedev);
|
|
tee_device_unregister(optee->teedev);
|
|
|
|
tee_shm_pool_free(optee->pool);
|
|
optee_supp_uninit(&optee->supp);
|
|
mutex_destroy(&optee->call_queue.mutex);
|
|
}
|
|
|
|
static int smc_abi_rc;
|
|
static int ffa_abi_rc;
|
|
|
|
static int __init optee_core_init(void)
|
|
{
|
|
/*
|
|
* The kernel may have crashed at the same time that all available
|
|
* secure world threads were suspended and we cannot reschedule the
|
|
* suspended threads without access to the crashed kernel's wait_queue.
|
|
* Therefore, we cannot reliably initialize the OP-TEE driver in the
|
|
* kdump kernel.
|
|
*/
|
|
if (is_kdump_kernel())
|
|
return -ENODEV;
|
|
|
|
smc_abi_rc = optee_smc_abi_register();
|
|
ffa_abi_rc = optee_ffa_abi_register();
|
|
|
|
/* If both failed there's no point with this module */
|
|
if (smc_abi_rc && ffa_abi_rc)
|
|
return smc_abi_rc;
|
|
return 0;
|
|
}
|
|
module_init(optee_core_init);
|
|
|
|
static void __exit optee_core_exit(void)
|
|
{
|
|
if (!smc_abi_rc)
|
|
optee_smc_abi_unregister();
|
|
if (!ffa_abi_rc)
|
|
optee_ffa_abi_unregister();
|
|
}
|
|
module_exit(optee_core_exit);
|
|
|
|
MODULE_AUTHOR("Linaro");
|
|
MODULE_DESCRIPTION("OP-TEE driver");
|
|
MODULE_VERSION("1.0");
|
|
MODULE_LICENSE("GPL v2");
|
|
MODULE_ALIAS("platform:optee");
|