mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-06 10:58:48 +09:00
crypto: rockchip: cryptodev_linux: add rk_cryptodev.c
Add register and unregister for crypto driver. Signed-off-by: Lin Jinhan <troy.lin@rock-chips.com> Change-Id: I406776514374bb460875ce8bd71a3031cd110587
This commit is contained in:
@@ -5,5 +5,6 @@ cryptodev-objs := ioctl.o \
|
||||
cryptlib.o \
|
||||
authenc.o \
|
||||
zc.o \
|
||||
util.o
|
||||
util.o \
|
||||
rk_cryptodev.o
|
||||
|
||||
|
||||
73
drivers/crypto/rockchip/cryptodev_linux/rk_cryptodev.c
Normal file
73
drivers/crypto/rockchip/cryptodev_linux/rk_cryptodev.c
Normal file
@@ -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 <troy.lin@rock-chips.com>
|
||||
*
|
||||
*/
|
||||
#include <linux/kernel.h>
|
||||
#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);
|
||||
25
drivers/crypto/rockchip/cryptodev_linux/rk_cryptodev_int.h
Normal file
25
drivers/crypto/rockchip/cryptodev_linux/rk_cryptodev_int.h
Normal file
@@ -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 <linux/device.h>
|
||||
|
||||
#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
|
||||
Reference in New Issue
Block a user