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

Commit 6d74baa2 authored by Sujeev Dias's avatar Sujeev Dias
Browse files

mhi: devices: satellite: add option to defer initialization



Add option to defer MHI satellite driver initialization due to
missing memory carve-outs in TZ as it can lead to access
control violations and crashes. Instead expose a debugfs entry
to initialize it.

CRs-Fixed: 2361053
Change-Id: I94c92a1f67d257481424ff9ed54bd3cba2f6c9bf
Acked-by: default avatarBhaumik Vasav Bhatt <bbhatt@qti.qualcomm.com>
Signed-off-by: default avatarTony Truong <truong@codeaurora.org>
Signed-off-by: default avatarSujeev Dias <sdias@codeaurora.org>
parent 4e5ff1ff
Loading
Loading
Loading
Loading
+58 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/* Copyright (c) 2019, The Linux Foundation. All rights reserved.*/

#include <linux/debugfs.h>
#include <linux/device.h>
#include <linux/dma-direction.h>
#include <linux/dma-mapping.h>
@@ -18,6 +19,8 @@

#define MHI_SAT_DRIVER_NAME "mhi_satellite"

static bool mhi_sat_defer_init = true; /* set by default */

/* logging macros */
#define IPC_LOG_PAGES (10)
#define IPC_LOG_LVL (MHI_MSG_LVL_INFO)
@@ -282,6 +285,9 @@ struct mhi_sat_driver {

	struct mhi_sat_subsys *subsys; /* pointer to subsystem array */
	unsigned int num_subsys;

	struct dentry *dentry; /* debugfs directory */
	bool deferred_init_done; /* flag for deferred init protection */
};

static struct mhi_sat_driver mhi_sat_driver;
@@ -1041,6 +1047,44 @@ static struct mhi_driver mhi_sat_dev_driver = {
	},
};

int mhi_sat_trigger_init(void *data, u64 val)
{
	struct mhi_sat_subsys *subsys;
	int i, ret;

	if (mhi_sat_driver.deferred_init_done)
		return -EIO;

	ret = register_rpmsg_driver(&mhi_sat_rpmsg_driver);
	if (ret)
		goto error_sat_trigger_init;

	ret = mhi_driver_register(&mhi_sat_dev_driver);
	if (ret)
		goto error_sat_trigger_register;

	mhi_sat_driver.deferred_init_done = true;

	return 0;

error_sat_trigger_register:
	unregister_rpmsg_driver(&mhi_sat_rpmsg_driver);

error_sat_trigger_init:
	subsys = mhi_sat_driver.subsys;
	for (i = 0; i < mhi_sat_driver.num_subsys; i++, subsys++) {
		ipc_log_context_destroy(subsys->ipc_log);
		mutex_destroy(&subsys->cntrl_mutex);
	}
	kfree(mhi_sat_driver.subsys);
	mhi_sat_driver.subsys = NULL;

	return ret;
}

DEFINE_SIMPLE_ATTRIBUTE(mhi_sat_debugfs_fops, NULL,
			mhi_sat_trigger_init, "%llu\n");

static int mhi_sat_init(void)
{
	struct mhi_sat_subsys *subsys;
@@ -1066,6 +1110,20 @@ static int mhi_sat_init(void)
		subsys->ipc_log = ipc_log_context_create(IPC_LOG_PAGES, log, 0);
	}

	/* create debugfs entry if defer_init is enabled */
	if (mhi_sat_defer_init) {
		mhi_sat_driver.dentry = debugfs_create_dir("mhi_sat", NULL);
		if (IS_ERR_OR_NULL(mhi_sat_driver.dentry)) {
			ret = -ENODEV;
			goto error_sat_init;
		}

		debugfs_create_file("debug", 0444, mhi_sat_driver.dentry, NULL,
				    &mhi_sat_debugfs_fops);

		return 0;
	}

	ret = register_rpmsg_driver(&mhi_sat_rpmsg_driver);
	if (ret)
		goto error_sat_init;