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

Commit 90797c34 authored by Channagoud Kadabi's avatar Channagoud Kadabi
Browse files

msm: Add snapshot of early random number driver



This is a snapshot of minidump driver as of msm-4.14 commit
<1cef27dd1d8f>. (Merge "net: cnss_prealloc: add debugfs entry to check
the memory status").

Change-Id: I0576fae97a45b2610fa103d63e0a52fb4068d336
Signed-off-by: default avatarChannagoud Kadabi <ckadabi@codeaurora.org>
parent 48bacd24
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -202,6 +202,14 @@ config QCOM_SCM
	  world(EL2 and EL3) by using smc call.
	  SCM driver provides the support for atomic scm calls also.

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.

config QCOM_MEMORY_DUMP_V2
	bool "QCOM Memory Dump V2 Support"
	help
+1 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ obj-$(CONFIG_QCOM_SECURE_BUFFER) += secure_buffer.o
obj-$(CONFIG_MSM_TZ_SMMU) += msm_tz_smmu.o
CFLAGS_scm.o :=$(call as-instr,.arch_extension sec,-DREQUIRES_SEC=1)
obj-$(CONFIG_QCOM_SCM)  +=      scm.o
obj-$(CONFIG_QCOM_EARLY_RANDOM) += early_random.o
obj-$(CONFIG_MSM_BOOT_STATS) += boot_stats.o
obj-$(CONFIG_MSM_CORE_HANG_DETECT) += core_hang_detect.o
obj-$(CONFIG_QCOM_MINIDUMP) += msm_minidump.o minidump_log.o
+55 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2013-2014, 2016-2018, The Linux Foundation. All rights
 */

#include <linux/kernel.h>
#include <linux/hw_random.h>
#include <linux/io.h>

#include <soc/qcom/scm.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 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;
	struct scm_desc desc;

	data.out_buf = (uint8_t *) virt_to_phys(random_buffer);
	desc.args[0] = (unsigned long) data.out_buf;
	desc.args[1] = data.out_buf_sz = SZ_512;
	desc.arginfo = SCM_ARGS(2, SCM_RW, SCM_VAL);

	dmac_flush_range(random_buffer, random_buffer + RANDOM_BUFFER_SIZE);

	ret = scm_call2(SCM_SIP_FNID(TZ_SVC_CRYPTO, PRNG_CMD_ID), &desc);

	if (!ret) {
		u64 bytes_received = desc.ret[0];

		if (bytes_received != SZ_512)
			pr_warn("Did not receive the expected number of bytes from PRNG: %llu\n",
				bytes_received);

		dmac_inv_range(random_buffer, random_buffer +
						RANDOM_BUFFER_SIZE);
		bytes_received = (bytes_received <= RANDOM_BUFFER_SIZE) ?
					bytes_received : RANDOM_BUFFER_SIZE;
		add_hwgenerator_randomness(random_buffer, bytes_received,
					   bytes_received << 3);
	}
}