diff --git a/drivers/crypto/rockchip/cryptodev_linux/Makefile b/drivers/crypto/rockchip/cryptodev_linux/Makefile index 02c74bed7a8e..628262fb2e50 100644 --- a/drivers/crypto/rockchip/cryptodev_linux/Makefile +++ b/drivers/crypto/rockchip/cryptodev_linux/Makefile @@ -5,5 +5,6 @@ cryptodev-objs := ioctl.o \ cryptlib.o \ authenc.o \ zc.o \ - util.o + util.o \ + rk_cryptodev.o diff --git a/drivers/crypto/rockchip/cryptodev_linux/rk_cryptodev.c b/drivers/crypto/rockchip/cryptodev_linux/rk_cryptodev.c new file mode 100644 index 000000000000..4f199d138e07 --- /dev/null +++ b/drivers/crypto/rockchip/cryptodev_linux/rk_cryptodev.c @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Crypto acceleration support for Rockchip crypto + * + * Copyright (c) 2021, Rockchip Electronics Co., Ltd + * + * Author: Lin Jinhan + * + */ +#include +#include "rk_cryptodev_int.h" + +#define MAX_CRYPTO_DEV 1 +#define MAX_CRYPTO_NAME_LEN 64 + +struct crypto_dev_info { + struct device *dev; + char name[MAX_CRYPTO_NAME_LEN]; +}; + +static struct crypto_dev_info g_dev_infos[MAX_CRYPTO_DEV]; + +/* + * rk_cryptodev_register_dev - register crypto device into rk_cryptodev. + * @dev: [in] crypto device to register + * @name: [in] crypto device name to register + */ +int rk_cryptodev_register_dev(struct device *dev, const char *name) +{ + uint32_t i; + + if (WARN_ON(!dev)) + return -EINVAL; + + if (WARN_ON(!name)) + return -EINVAL; + + for (i = 0; i < ARRAY_SIZE(g_dev_infos); i++) { + if (!g_dev_infos[i].dev) { + memset(&g_dev_infos[i], 0x00, sizeof(g_dev_infos[i])); + + g_dev_infos[i].dev = dev; + strncpy(g_dev_infos[i].name, name, sizeof(g_dev_infos[i].name)); + dev_info(dev, "register to cryptodev ok!\n"); + return 0; + } + } + + return -ENOMEM; +} +EXPORT_SYMBOL_GPL(rk_cryptodev_register_dev); + +/* + * rk_cryptodev_unregister_dev - unregister crypto device from rk_cryptodev + * @dev: [in] crypto device to unregister + */ +int rk_cryptodev_unregister_dev(struct device *dev) +{ + uint32_t i; + + if (WARN_ON(!dev)) + return -EINVAL; + + for (i = 0; i < ARRAY_SIZE(g_dev_infos); i++) { + if (g_dev_infos[i].dev == dev) { + memset(&g_dev_infos[i], 0x00, sizeof(g_dev_infos[i])); + return 0; + } + } + + return -EINVAL; +} +EXPORT_SYMBOL_GPL(rk_cryptodev_unregister_dev); diff --git a/drivers/crypto/rockchip/cryptodev_linux/rk_cryptodev_int.h b/drivers/crypto/rockchip/cryptodev_linux/rk_cryptodev_int.h new file mode 100644 index 000000000000..6bda63c36058 --- /dev/null +++ b/drivers/crypto/rockchip/cryptodev_linux/rk_cryptodev_int.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* Copyright (c) 2021 Rockchip Electronics Co. Ltd. */ + +#ifndef __RK_CRYPTODEV_INT_H__ +#define __RK_CRYPTODEV_INT_H__ + +#include + +#if IS_ENABLED(CONFIG_CRYPTO_DEV_ROCKCHIP_DEV) +int rk_cryptodev_register_dev(struct device *dev, const char *name); +int rk_cryptodev_unregister_dev(struct device *dev); +#else +static inline int rk_cryptodev_register_dev(struct device *dev, const char *name) +{ + return 0; +} + +static inline int rk_cryptodev_unregister_dev(struct device *dev) +{ + return 0; +} +#endif + +#endif