linux/drivers/crypto/exynos-rng.c

// SPDX-License-Identifier: GPL-2.0
/*
 * exynos-rng.c - Random Number Generator driver for the Exynos
 *
 * Copyright (c) 2017 Krzysztof Kozlowski <[email protected]>
 *
 * Loosely based on old driver from drivers/char/hw_random/exynos-rng.c:
 * Copyright (C) 2012 Samsung Electronics
 * Jonghwa Lee <[email protected]>
 */

#include <linux/clk.h>
#include <linux/crypto.h>
#include <linux/err.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/of.h>
#include <linux/platform_device.h>

#include <crypto/internal/rng.h>

#define EXYNOS_RNG_CONTROL
#define EXYNOS_RNG_STATUS

#define EXYNOS_RNG_SEED_CONF
#define EXYNOS_RNG_GEN_PRNG

#define EXYNOS_RNG_SEED_BASE
#define EXYNOS_RNG_SEED(n)
#define EXYNOS_RNG_OUT_BASE
#define EXYNOS_RNG_OUT(n)

/* EXYNOS_RNG_CONTROL bit fields */
#define EXYNOS_RNG_CONTROL_START
/* EXYNOS_RNG_STATUS bit fields */
#define EXYNOS_RNG_STATUS_SEED_SETTING_DONE
#define EXYNOS_RNG_STATUS_RNG_DONE

/* Five seed and output registers, each 4 bytes */
#define EXYNOS_RNG_SEED_REGS
#define EXYNOS_RNG_SEED_SIZE

enum exynos_prng_type {};

/*
 * Driver re-seeds itself with generated random numbers to hinder
 * backtracking of the original seed.
 *
 * Time for next re-seed in ms.
 */
#define EXYNOS_RNG_RESEED_TIME
#define EXYNOS_RNG_RESEED_BYTES

/*
 * In polling mode, do not wait infinitely for the engine to finish the work.
 */
#define EXYNOS_RNG_WAIT_RETRIES

/* Context for crypto */
struct exynos_rng_ctx {};

/* Device associated memory */
struct exynos_rng_dev {};

static struct exynos_rng_dev *exynos_rng_dev;

static u32 exynos_rng_readl(struct exynos_rng_dev *rng, u32 offset)
{}

static void exynos_rng_writel(struct exynos_rng_dev *rng, u32 val, u32 offset)
{}

static int exynos_rng_set_seed(struct exynos_rng_dev *rng,
			       const u8 *seed, unsigned int slen)
{}

/*
 * Start the engine and poll for finish.  Then read from output registers
 * filling the 'dst' buffer up to 'dlen' bytes or up to size of generated
 * random data (EXYNOS_RNG_SEED_SIZE).
 *
 * On success: return 0 and store number of read bytes under 'read' address.
 * On error: return -ERRNO.
 */
static int exynos_rng_get_random(struct exynos_rng_dev *rng,
				 u8 *dst, unsigned int dlen,
				 unsigned int *read)
{}

/* Re-seed itself from time to time */
static void exynos_rng_reseed(struct exynos_rng_dev *rng)
{}

static int exynos_rng_generate(struct crypto_rng *tfm,
			       const u8 *src, unsigned int slen,
			       u8 *dst, unsigned int dlen)
{}

static int exynos_rng_seed(struct crypto_rng *tfm, const u8 *seed,
			   unsigned int slen)
{}

static int exynos_rng_kcapi_init(struct crypto_tfm *tfm)
{}

static struct rng_alg exynos_rng_alg =;

static int exynos_rng_probe(struct platform_device *pdev)
{}

static void exynos_rng_remove(struct platform_device *pdev)
{}

static int __maybe_unused exynos_rng_suspend(struct device *dev)
{}

static int __maybe_unused exynos_rng_resume(struct device *dev)
{}

static SIMPLE_DEV_PM_OPS(exynos_rng_pm_ops, exynos_rng_suspend,
			 exynos_rng_resume);

static const struct of_device_id exynos_rng_dt_match[] =;
MODULE_DEVICE_TABLE(of, exynos_rng_dt_match);

static struct platform_driver exynos_rng_driver =;

module_platform_driver();

MODULE_DESCRIPTION();
MODULE_AUTHOR();
MODULE_LICENSE();