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

Commit 30e3148a 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 a28dc9ed 4eb6c6d5
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -70,5 +70,4 @@ obj-$(CONFIG_MSM_SMCMOD) += smcmod.o

obj-$(CONFIG_ARCH_MSM8974) += msm_mpmctr.o

obj-$(CONFIG_ARCH_RANDOM) += early_random.o
obj-$(CONFIG_PERFMAP) += perfmap.o
+8 −0
Original line number Diff line number Diff line
@@ -514,6 +514,14 @@ config MSM_SYSTEM_HEALTH_MONITOR
	  health check. If any failures are detected during the health-check,
	  then a subsystem restart will be triggered for the failed subsystem.

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
@@ -71,3 +71,4 @@ obj-$(CONFIG_MSM_SHARED_HEAP_ACCESS) += shared_memory.o
obj-$(CONFIG_MSM_SYSTEM_HEALTH_MONITOR) += system_health_monitor_v01.o
obj-$(CONFIG_MSM_SYSTEM_HEALTH_MONITOR) += system_health_monitor.o
obj-$(CONFIG_MSM_RTB) += msm_rtb-hotplug.o
obj-$(CONFIG_QCOM_EARLY_RANDOM)	+= early_random.o
+7 −37
Original line number Diff line number Diff line
/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
/* 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
@@ -12,8 +12,9 @@
 */

#include <linux/kernel.h>
#include <soc/qcom/scm.h>
#include <linux/random.h>

#include <soc/qcom/scm.h>

#include <asm/io.h>
#include <asm/cacheflush.h>
@@ -21,32 +22,24 @@
#define TZ_SVC_CRYPTO	10
#define PRNG_CMD_ID	0x01

static int use_arch_random = 1;
struct tz_prng_data {
	uint8_t		*out_buf;
	uint32_t	out_buf_sz;
} __packed;

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

int arch_get_random_common(void *v, size_t size)
void __init init_random_pool(void)
{
	struct tz_prng_data data;
	int ret;
	u32 resp;

	if (!use_arch_random)
		return 0;

	if (size > sizeof(random_buffer))
		return 0;

	mutex_lock(&arch_random_lock);
	data.out_buf = (uint8_t *) virt_to_phys(random_buffer);
	data.out_buf_sz = size;
	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),
@@ -54,30 +47,7 @@ int arch_get_random_common(void *v, size_t size)
	if (!ret) {
		dmac_inv_range(random_buffer, random_buffer +
						RANDOM_BUFFER_SIZE);
		outer_inv_range(
			(unsigned long) virt_to_phys(random_buffer),
			(unsigned long) virt_to_phys(random_buffer) +
						RANDOM_BUFFER_SIZE);
		memcpy(v, random_buffer, size);
	}
	mutex_unlock(&arch_random_lock);
	return !ret;
}

int arch_get_random_long(unsigned long *v)
{
	return arch_get_random_common(v, sizeof(unsigned long));
		add_device_randomness(random_buffer, SZ_512);
	}

int arch_get_random_int(unsigned int *v)
{
	return arch_get_random_common(v, sizeof(unsigned int));
}
int arch_random_init(void)
{
	use_arch_random = 0;

	return 0;
}
module_init(arch_random_init);