public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Jaehoon Chung <jh80.chung@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V2 1/3] cpu: exynos4: ace_sha: add hardware random number generator support.
Date: Thu, 06 Mar 2014 14:43:35 +0900	[thread overview]
Message-ID: <53180B07.1030502@samsung.com> (raw)
In-Reply-To: <1882e4320da26486d3759d81f1b440a0f89457b8.1394038415.git.p.marczak@samsung.com>

On 03/06/2014 01:57 AM, Przemyslaw Marczak wrote:
> This patch adds implementation of function hw_rand() based on exynos
> security sub system.
> 
> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
> cc: Akshay Saraswat <akshay.s@samsung.com>
> cc: ARUN MANKUZHI <arun.m@samsung.com>
> cc: Minkyu Kang <mk7.kang@samsung.com>
> ---
> Changes v2:
> - none
> 
>  arch/arm/include/asm/arch-exynos/cpu.h |    4 ++--
>  drivers/crypto/ace_sha.c               |   41 ++++++++++++++++++++++++++++++++
>  drivers/crypto/ace_sha.h               |    8 ++++---
>  3 files changed, 48 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/arm/include/asm/arch-exynos/cpu.h b/arch/arm/include/asm/arch-exynos/cpu.h
> index bccce63..a5c280d 100644
> --- a/arch/arm/include/asm/arch-exynos/cpu.h
> +++ b/arch/arm/include/asm/arch-exynos/cpu.h
> @@ -48,7 +48,7 @@
>  #define EXYNOS4_GPIO_PART4_BASE		DEVICE_NOT_AVAILABLE
>  #define EXYNOS4_DP_BASE			DEVICE_NOT_AVAILABLE
>  #define EXYNOS4_SPI_ISP_BASE		DEVICE_NOT_AVAILABLE
> -#define EXYNOS4_ACE_SFR_BASE		DEVICE_NOT_AVAILABLE
> +#define EXYNOS4_ACE_SFR_BASE		0x10830000
>  #define EXYNOS4_DMC_PHY_BASE		DEVICE_NOT_AVAILABLE
>  #define EXYNOS4_AUDIOSS_BASE		DEVICE_NOT_AVAILABLE
>  #define EXYNOS4_USB_HOST_XHCI_BASE	DEVICE_NOT_AVAILABLE
> @@ -87,7 +87,7 @@
>  #define EXYNOS4X12_I2S_BASE		DEVICE_NOT_AVAILABLE
>  #define EXYNOS4X12_SPI_BASE		DEVICE_NOT_AVAILABLE
>  #define EXYNOS4X12_SPI_ISP_BASE		DEVICE_NOT_AVAILABLE
> -#define EXYNOS4X12_ACE_SFR_BASE		DEVICE_NOT_AVAILABLE
> +#define EXYNOS4X12_ACE_SFR_BASE		0x10830000
>  #define EXYNOS4X12_DMC_PHY_BASE		DEVICE_NOT_AVAILABLE
>  #define EXYNOS4X12_AUDIOSS_BASE		DEVICE_NOT_AVAILABLE
>  #define EXYNOS4X12_USB_HOST_XHCI_BASE	DEVICE_NOT_AVAILABLE
> diff --git a/drivers/crypto/ace_sha.c b/drivers/crypto/ace_sha.c
> index acbafde..d12a507 100644
> --- a/drivers/crypto/ace_sha.c
> +++ b/drivers/crypto/ace_sha.c
> @@ -111,3 +111,44 @@ void hw_sha1(const unsigned char *pbuf, unsigned int buf_len,
>  	if (ace_sha_hash_digest(pbuf, buf_len, pout, ACE_SHA_TYPE_SHA1))
>  		debug("ACE was not setup properly or it is faulty\n");
>  }
> +
> +unsigned int hw_rand(void)
> +{
> +	struct exynos_ace_sfr *reg =
> +		(struct exynos_ace_sfr *)samsung_get_base_ace_sfr();
> +	int status, i;
> +	int seed[5];
> +	unsigned int ret = 0;
> +
> +	/* Seed data */
> +	for (i = 0; i < ACE_HASH_PRNG_REG_NUM; i++)
> +		writel(seed[i], &reg->hash_seed[i]);
> +
> +	status = 0;
> +	/* Wait for seed setup done */
> +	while (!(status & ACE_HASH_SEEDSETTING_MASK)) {
> +		status = readl(&reg->hash_status);
> +		if (status & ACE_HASH_PRNGERROR_MASK)
> +			return 0;
> +	}
Can it use "do{ }while"?

> +
> +	/* Start PRNG */
> +	writel(ACE_HASH_ENGSEL_PRNG | ACE_HASH_STARTBIT_ON, &reg->hash_control);
> +
> +	status = 0;
> +	/* Wait for PRNG done */
> +	while (!(status & ACE_HASH_PRNGDONE_MASK)) {
> +		status = readl(&reg->hash_status);
> +		if (status & ACE_HASH_PRNGERROR_MASK)
> +			return 0;
> +	}
> +
> +	/* Clear Done IRQ */
> +	writel(ACE_HASH_PRNGDONE_MASK, &reg->hash_status);
> +
> +	/* Read a PRNG result */
> +	for (i = 0; i < ACE_HASH_PRNG_REG_NUM; i++)
> +		ret += readl(&reg->hash_prng[i]);
> +
> +	return ret;
> +}
> diff --git a/drivers/crypto/ace_sha.h b/drivers/crypto/ace_sha.h
> index a426d52..f1097f7 100644
> --- a/drivers/crypto/ace_sha.h
> +++ b/drivers/crypto/ace_sha.h
> @@ -72,9 +72,10 @@ struct exynos_ace_sfr {
>  	unsigned char   res12[0x30];
>  	unsigned int	hash_result[8];
>  	unsigned char   res13[0x20];
> -	unsigned int	hash_seed[8];
> -	unsigned int	hash_prng[8];
> -	unsigned char   res14[0x180];
> +	unsigned int	hash_seed[5];
> +	unsigned char	res14[12];
> +	unsigned int	hash_prng[5];
> +	unsigned char	res15[0x18c];
>  
>  	unsigned int	pka_sfr[5];		/* base + 0x700 */
>  };
> @@ -291,6 +292,7 @@ struct exynos_ace_sfr {
>  #define ACE_HASH_PRNGERROR_MASK	(1 << 7)
>  #define ACE_HASH_PRNGERROR_OFF		(0 << 7)
>  #define ACE_HASH_PRNGERROR_ON		(1 << 7)
> +#define ACE_HASH_PRNG_REG_NUM		5
>  
>  #define ACE_SHA_TYPE_SHA1		1
>  #define ACE_SHA_TYPE_SHA256		2
> 

  parent reply	other threads:[~2014-03-06  5:43 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-28 16:30 [U-Boot] [PATCH 1/3] cpu: exynos4: ace_sha: add hardware random number generator support Przemyslaw Marczak
2014-02-28 16:30 ` [U-Boot] [PATCH 2/3] lib: rand: add call to hw_rand() - hardware random number generator Przemyslaw Marczak
2014-02-28 17:02   ` Michael Walle
2014-03-03 14:19     ` Przemyslaw Marczak
2014-02-28 16:30 ` [U-Boot] [PATCH 3/3] trats/trats2: enable exynos security subsystem and function hw_rand() Przemyslaw Marczak
2014-03-05 16:57 ` [U-Boot] [PATCH V2 1/3] cpu: exynos4: ace_sha: add hardware random number generator support Przemyslaw Marczak
2014-03-05 16:57   ` [U-Boot] [PATCH V2 2/3] lib: rand: add call to hw_rand() - hardware random number generator Przemyslaw Marczak
2014-03-05 21:22     ` Tom Rini
2014-03-06  4:58       ` Masahiro Yamada
2014-03-05 16:57   ` [U-Boot] [PATCH V2 3/3] trats/trats2: enable exynos security subsystem and function hw_rand() Przemyslaw Marczak
2014-03-06  5:43   ` Jaehoon Chung [this message]
2014-03-13  1:58   ` [U-Boot] [PATCH V2 1/3] cpu: exynos4: ace_sha: add hardware random number generator support Minkyu Kang
2014-03-20 17:23 ` [U-Boot] [PATCH v3 1/4] lib: rand: introduce new configs: CONFIG_LIB_RAND CONFIG_LIB_HW_RAND Przemyslaw Marczak
2014-03-20 17:23   ` [U-Boot] [PATCH v3 2/4] cpu: exynos4: add ace sha base address Przemyslaw Marczak
2014-03-20 17:23   ` [U-Boot] [PATCH v3 3/4] drivers: crypto: ace_sha: add implementation of hardware based lib rand Przemyslaw Marczak
2014-03-20 17:23   ` [U-Boot] [PATCH v3 4/4] trats/trats2: enable exynos ace sha subsystem and " Przemyslaw Marczak
2014-03-20 17:36   ` [U-Boot] [PATCH v3 1/4] lib: rand: introduce new configs: CONFIG_LIB_RAND CONFIG_LIB_HW_RAND Przemyslaw Marczak
2014-03-20 21:10     ` Michael Walle
2014-03-21  8:56   ` [U-Boot] [PATCH v4 1/4] lib: rand: introduce new configs: CONFIG_LIB_RAND and CONFIG_LIB_HW_RAND Przemyslaw Marczak
2014-03-21  8:56     ` [U-Boot] [PATCH v4 2/4] cpu: exynos4: add ace sha base address Przemyslaw Marczak
2014-03-21 15:09       ` Tom Rini
2014-03-22 15:18       ` Minkyu Kang
2014-03-24  7:44         ` Przemyslaw Marczak
2014-03-25  1:26           ` Minkyu Kang
2014-03-25  7:38             ` Przemyslaw Marczak
2014-03-21  8:56     ` [U-Boot] [PATCH v4 3/4] drivers: crypto: ace_sha: add implementation of hardware based lib rand Przemyslaw Marczak
2014-03-21 15:14       ` Tom Rini
2014-03-21  8:56     ` [U-Boot] [PATCH v4 4/4] trats/trats2: enable exynos ace sha subsystem and " Przemyslaw Marczak
2014-03-21 15:14       ` Tom Rini
2014-03-21  9:00     ` [U-Boot] [PATCH v4 1/4] lib: rand: introduce new configs: CONFIG_LIB_RAND and CONFIG_LIB_HW_RAND Przemyslaw Marczak
2014-03-21 15:00       ` Tom Rini
2014-03-25  9:58 ` [U-Boot] [PATCH v5 " Przemyslaw Marczak
2014-03-25  9:58   ` [U-Boot] [PATCH v5 2/4] cpu: exynos4: add ace sha base address Przemyslaw Marczak
2014-03-28 21:17     ` [U-Boot] [U-Boot, v5, " Tom Rini
2014-03-25  9:58   ` [U-Boot] [PATCH v5 3/4] drivers: crypto: ace_sha: add implementation of hardware based lib rand Przemyslaw Marczak
2014-03-28 21:17     ` [U-Boot] [U-Boot, v5, " Tom Rini
2014-03-25  9:58   ` [U-Boot] [PATCH v5 4/4] trats/trats2: enable exynos ace sha subsystem and " Przemyslaw Marczak
2014-03-28 21:17     ` [U-Boot] [U-Boot, v5, " Tom Rini
2014-03-25 10:17   ` [U-Boot] [PATCH v5 1/4] lib: rand: introduce new configs: CONFIG_LIB_RAND and CONFIG_LIB_HW_RAND Przemyslaw Marczak
2014-03-28 21:16   ` [U-Boot] [U-Boot, v5, " Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53180B07.1030502@samsung.com \
    --to=jh80.chung@samsung.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox