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

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

Merge changes I5d492061,Iefdf8369,I0de63420,Id756a874 into msm-next

* changes:
  drivers: soc: qcom: Use number of bytes returned from PRNG for entropy
  drivers: soc: qcom: Add random bits to pool
  arm: Add weak function definition for random pool initialization
  msm: Add support for early random numbers
parents a331def2 4c8a86c8
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1070,6 +1070,8 @@ void __init hyp_mode_check(void)
#endif
}

void __init __weak init_random_pool(void) { }

void __init setup_arch(char **cmdline_p)
{
	const struct machine_desc *mdesc;
@@ -1158,6 +1160,8 @@ void __init setup_arch(char **cmdline_p)

	if (mdesc->init_early)
		mdesc->init_early();

	init_random_pool();
}


+4 −0
Original line number Diff line number Diff line
@@ -248,6 +248,8 @@ static void __init request_standard_resources(void)

u64 __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID };

void __init __weak init_random_pool(void) { }

void __init setup_arch(char **cmdline_p)
{
	pr_info("Boot CPU: AArch64 Processor [%08x]\n", read_cpuid_id());
@@ -332,6 +334,8 @@ void __init setup_arch(char **cmdline_p)
			"This indicates a broken bootloader or old kernel\n",
			boot_args[1], boot_args[2], boot_args[3]);
	}

	init_random_pool();
}

static int __init topology_init(void)
+8 −0
Original line number Diff line number Diff line
@@ -349,6 +349,14 @@ config QCOM_COMMAND_DB
	  Command DB queries shared memory by key string for shared system
	  resources

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 QTI_RPMH_API
	bool "QTI RPMH (h/w accelerators) Communication API"
	select MAILBOX
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ obj-$(CONFIG_QCOM_SMSM) += smsm.o
obj-$(CONFIG_QCOM_WCNSS_CTRL) += wcnss_ctrl.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_SOC_BUS) += socinfo.o
obj-$(CONFIG_MSM_BOOT_STATS) += boot_stats.o
obj-$(CONFIG_MSM_CORE_HANG_DETECT) += core_hang_detect.o
+65 −0
Original line number Diff line number Diff line
/* Copyright (c) 2013-2014, 2016-2017, 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/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_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;
	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);
	}
}