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

Commit 46f34103 authored by Ravi Aravamudhan's avatar Ravi Aravamudhan Committed by Gerrit - the friendly Code Review server
Browse files

diag: Initialize SMD buffers only when needed



Diag driver initializes SMD buffers during driver initialization
irrespective of the peripheral being present. Defer buffer
initialization to the channel probe function.

Change-Id: I251e705bc68b4f5fd9e698725b7a958dde8ce7fc
Signed-off-by: default avatarRavi Aravamudhan <aravamud@codeaurora.org>
parent 9d92106b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -2230,6 +2230,8 @@ static int diag_dci_probe(struct platform_device *pdev)
		if (err)
			pr_err("diag: In %s, cannot open DCI Modem port, Id = %d, err: %d\n",
				__func__, pdev->id, err);
		else
			diag_smd_buffer_init(&driver->smd_dci[index]);
	}

	if (pdev->id == SMD_APPS_QDSP) {
@@ -2243,6 +2245,8 @@ static int diag_dci_probe(struct platform_device *pdev)
		if (err)
			pr_err("diag: In %s, cannot open DCI Lpass port, Id = %d, err: %d\n",
				__func__, pdev->id, err);
		else
			diag_smd_buffer_init(&driver->smd_dci[index]);
	}

	return err;
@@ -2265,6 +2269,8 @@ static int diag_dci_cmd_probe(struct platform_device *pdev)
		if (err)
			pr_err("diag: In %s, cannot open DCI Modem CMD port, Id = %d, err: %d\n",
				__func__, pdev->id, err);
		else
			diag_smd_buffer_init(&driver->smd_dci_cmd[index]);
	}

	return err;
+1 −0
Original line number Diff line number Diff line
@@ -323,6 +323,7 @@ struct diag_smd_info {
	int notify_context;
	struct work_struct diag_general_smd_work;
	int general_context;
	uint8_t inited;

	/*
	 * Function ptr for function to call to process the data that
+54 −33
Original line number Diff line number Diff line
@@ -2246,6 +2246,7 @@ static int diag_smd_probe(struct platform_device *pdev)
					&driver->smd_data[index],
					diag_smd_notify);
		driver->smd_data[index].ch_save = driver->smd_data[index].ch;
		diag_smd_buffer_init(&driver->smd_data[index]);
	}

	pm_runtime_set_active(&pdev->dev);
@@ -2278,6 +2279,7 @@ static int diag_smd_cmd_probe(struct platform_device *pdev)
			diag_smd_notify);
		driver->smd_cmd[index].ch_save =
			driver->smd_cmd[index].ch;
		diag_smd_buffer_init(&driver->smd_cmd[index]);
	}

	pr_debug("diag: In %s, open SMD CMD port, Id = %d, r = %d\n",
@@ -2361,36 +2363,18 @@ void diag_smd_destructor(struct diag_smd_info *smd_info)
	kfree(smd_info->buf_in_2_raw);
}

int diag_smd_constructor(struct diag_smd_info *smd_info, int peripheral,
			  int type)
void diag_smd_buffer_init(struct diag_smd_info *smd_info)
{
	if (!smd_info)
		return -EIO;

	smd_info->peripheral = peripheral;
	smd_info->type = type;
	smd_info->encode_hdlc = 0;
	mutex_init(&smd_info->smd_ch_mutex);
	spin_lock_init(&smd_info->in_busy_lock);

	switch (peripheral) {
	case MODEM_DATA:
		smd_info->peripheral_mask = DIAG_CON_MPSS;
		break;
	case LPASS_DATA:
		smd_info->peripheral_mask = DIAG_CON_LPASS;
		break;
	case WCNSS_DATA:
		smd_info->peripheral_mask = DIAG_CON_WCNSS;
		break;
	default:
		pr_err("diag: In %s, unknown peripheral, peripheral: %d\n",
			__func__, peripheral);
		goto err;
	if (!smd_info) {
		pr_err("diag: Invalid smd_info\n");
		return;
	}

	smd_info->ch = 0;
	smd_info->ch_save = 0;
	if (smd_info->inited) {
		pr_debug("diag: smd buffers are already initialized, peripheral: %d, type: %d\n",
			 smd_info->peripheral, smd_info->type);
		return;
	}

	if (smd_info->buf_in_1 == NULL) {
		smd_info->buf_in_1 = kzalloc(IN_BUF_SIZE, GFP_KERNEL);
@@ -2458,6 +2442,49 @@ int diag_smd_constructor(struct diag_smd_info *smd_info, int peripheral,
			kmemleak_not_leak(smd_info->buf_in_1_raw);
		}
	}
	smd_info->inited = 1;
	return;
err:
	smd_info->inited = 0;
	kfree(smd_info->buf_in_1);
	kfree(smd_info->buf_in_2);
	kfree(smd_info->write_ptr_1);
	kfree(smd_info->write_ptr_2);
	kfree(smd_info->buf_in_1_raw);
	kfree(smd_info->buf_in_2_raw);
}

int diag_smd_constructor(struct diag_smd_info *smd_info, int peripheral,
			  int type)
{
	if (!smd_info)
		return -EIO;

	smd_info->peripheral = peripheral;
	smd_info->type = type;
	smd_info->encode_hdlc = 0;
	smd_info->inited = 0;
	mutex_init(&smd_info->smd_ch_mutex);
	spin_lock_init(&smd_info->in_busy_lock);

	switch (peripheral) {
	case MODEM_DATA:
		smd_info->peripheral_mask = DIAG_CON_MPSS;
		break;
	case LPASS_DATA:
		smd_info->peripheral_mask = DIAG_CON_LPASS;
		break;
	case WCNSS_DATA:
		smd_info->peripheral_mask = DIAG_CON_WCNSS;
		break;
	default:
		pr_err("diag: In %s, unknown peripheral, peripheral: %d\n",
			__func__, peripheral);
		goto err;
	}

	smd_info->ch = 0;
	smd_info->ch_save = 0;

	/* The smd data type needs separate work queues for reads */
	if (type == SMD_DATA_TYPE) {
@@ -2570,12 +2597,6 @@ int diag_smd_constructor(struct diag_smd_info *smd_info, int peripheral,

	return 0;
err:
	kfree(smd_info->buf_in_1);
	kfree(smd_info->buf_in_2);
	kfree(smd_info->write_ptr_1);
	kfree(smd_info->write_ptr_2);
	kfree(smd_info->buf_in_1_raw);
	kfree(smd_info->buf_in_2_raw);
	if (smd_info->wq)
		destroy_workqueue(smd_info->wq);

+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ void encode_rsp_and_send(int buf_length);
void diag_smd_notify(void *ctxt, unsigned event);
int diag_smd_constructor(struct diag_smd_info *smd_info, int peripheral,
			 int type);
void diag_smd_buffer_init(struct diag_smd_info *smd_info);
void diag_smd_destructor(struct diag_smd_info *smd_info);
int diag_switch_logging(int);
int diag_command_reg(unsigned long);
+1 −0
Original line number Diff line number Diff line
@@ -628,6 +628,7 @@ static int diag_smd_cntl_probe(struct platform_device *pdev)
				diag_smd_notify);
			driver->smd_cntl[index].ch_save =
				driver->smd_cntl[index].ch;
			diag_smd_buffer_init(&driver->smd_cntl[index]);
		}
		pr_debug("diag: In %s, open SMD CNTL port, Id = %d, r = %d\n",
			__func__, pdev->id, r);