dm: hash: Add new UCLASS_HASH support

Add UCLASS_HASH for hash driver development. Thus the
hash drivers (SW or HW-accelerated) can be developed
in the DM-based fashion.

Signed-off-by: Chia-Wei Wang <chiawei_wang@aspeedtech.com>
This commit is contained in:
Chia-Wei Wang
2021-07-30 09:08:03 +08:00
committed by Tom Rini
parent 74bda4fe3d
commit 4deaff791c
7 changed files with 196 additions and 0 deletions

View File

@@ -54,6 +54,7 @@ enum uclass_id {
UCLASS_FIRMWARE, /* Firmware */
UCLASS_FS_FIRMWARE_LOADER, /* Generic loader */
UCLASS_GPIO, /* Bank of general-purpose I/O pins */
UCLASS_HASH, /* Hash device */
UCLASS_HWSPINLOCK, /* Hardware semaphores */
UCLASS_I2C, /* I2C bus */
UCLASS_I2C_EEPROM, /* I2C EEPROM device */

61
include/u-boot/hash.h Normal file
View File

@@ -0,0 +1,61 @@
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Copyright (c) 2021 ASPEED Technology Inc.
*/
#ifndef _UBOOT_HASH_H
#define _UBOOT_HASH_H
enum HASH_ALGO {
HASH_ALGO_CRC16_CCITT,
HASH_ALGO_CRC32,
HASH_ALGO_MD5,
HASH_ALGO_SHA1,
HASH_ALGO_SHA256,
HASH_ALGO_SHA384,
HASH_ALGO_SHA512,
HASH_ALGO_NUM,
HASH_ALGO_INVALID = 0xffffffff,
};
/* general APIs for hash algo information */
enum HASH_ALGO hash_algo_lookup_by_name(const char *name);
ssize_t hash_algo_digest_size(enum HASH_ALGO algo);
const char *hash_algo_name(enum HASH_ALGO algo);
/* device-dependent APIs */
int hash_digest(struct udevice *dev, enum HASH_ALGO algo,
const void *ibuf, const uint32_t ilen,
void *obuf);
int hash_digest_wd(struct udevice *dev, enum HASH_ALGO algo,
const void *ibuf, const uint32_t ilen,
void *obuf, uint32_t chunk_sz);
int hash_init(struct udevice *dev, enum HASH_ALGO algo, void **ctxp);
int hash_update(struct udevice *dev, void *ctx, const void *ibuf, const uint32_t ilen);
int hash_finish(struct udevice *dev, void *ctx, void *obuf);
/*
* struct hash_ops - Driver model for Hash operations
*
* The uclass interface is implemented by all hash devices
* which use driver model.
*/
struct hash_ops {
/* progressive operations */
int (*hash_init)(struct udevice *dev, enum HASH_ALGO algo, void **ctxp);
int (*hash_update)(struct udevice *dev, void *ctx, const void *ibuf, const uint32_t ilen);
int (*hash_finish)(struct udevice *dev, void *ctx, void *obuf);
/* all-in-one operation */
int (*hash_digest)(struct udevice *dev, enum HASH_ALGO algo,
const void *ibuf, const uint32_t ilen,
void *obuf);
/* all-in-one operation with watchdog triggering every chunk_sz */
int (*hash_digest_wd)(struct udevice *dev, enum HASH_ALGO algo,
const void *ibuf, const uint32_t ilen,
void *obuf, uint32_t chunk_sz);
};
#endif