Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 76d03b12 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "soc: qcom: Add better support for early random numbers"

parents 64de89c6 567dff53
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#ifndef ARM_ASM_ARCHRANDOM_H
#define ARM_ASM_ARCHRANDOM_H

extern int arch_get_random_long(unsigned long *v);
extern int arch_get_random_int(unsigned int *v);

#endif
+8 −0
Original line number Diff line number Diff line
@@ -842,6 +842,14 @@ config QCOM_SMCINVOKE
	  Enable SMCInvoke driver which supports capability based secure
	  communication between QSEE and HLOS.

config QCOM_EARLY_RANDOM
	bool "Initialize random pool very early"
	help
	  The standard random pool may not initialize until late in the boot
	  process which means that any calls to get random numbers before then
	  may not be truly random. Select this option to make an early call
	  to get some random data to put in the pool. If unsure, say N.

source "drivers/soc/qcom/memshare/Kconfig"

endif # ARCH_MSM
+1 −0
Original line number Diff line number Diff line
@@ -101,3 +101,4 @@ obj-$(CONFIG_MSM_KERNEL_PROTECT) += kernel_protect.o
obj-$(CONFIG_MSM_RTB) += msm_rtb-hotplug.o
obj-$(CONFIG_MSM_REMOTEQDSS) += remoteqdss.o
obj-$(CONFIG_QCOM_SMCINVOKE) += smcinvoke.o
obj-$(CONFIG_QCOM_EARLY_RANDOM)	+= early_random.o
+53 −0
Original line number Diff line number Diff line
/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#include <linux/kernel.h>
#include <linux/random.h>

#include <soc/qcom/scm.h>

#include <asm/io.h>
#include <asm/cacheflush.h>

#define TZ_SVC_CRYPTO	10
#define PRNG_CMD_ID	0x01

struct tz_prng_data {
	uint8_t		*out_buf;
	uint32_t	out_buf_sz;
} __packed;

DEFINE_SCM_BUFFER(common_scm_buf)
#define RANDOM_BUFFER_SIZE	PAGE_SIZE
char random_buffer[RANDOM_BUFFER_SIZE] __aligned(PAGE_SIZE);

void __init init_random_pool(void)
{
	struct tz_prng_data data;
	int ret;
	u32 resp;

	data.out_buf = (uint8_t *) virt_to_phys(random_buffer);
	data.out_buf_sz = SZ_512;
	dmac_flush_range(random_buffer, random_buffer + RANDOM_BUFFER_SIZE);

	ret = scm_call_noalloc(TZ_SVC_CRYPTO, PRNG_CMD_ID, &data,
			sizeof(data), &resp, sizeof(resp),
			common_scm_buf, SCM_BUFFER_SIZE(common_scm_buf));
	if (!ret) {
		dmac_inv_range(random_buffer, random_buffer +
						RANDOM_BUFFER_SIZE);
		add_device_randomness(random_buffer, SZ_512);
	}
}