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

Commit 7e4cc1c1 authored by Sujeev Dias's avatar Sujeev Dias Committed by Gerrit - the friendly Code Review server
Browse files

mhi: core: allocate SBL image buffer using CMA pool if configured



Depending on memory configuration, MHI may have a dedicated CMA
pool for buffer management. Always use DMA allocation methods,
so if a memory pool is tied to device, it will allocate memory
from that pool.

CRs-Fixed: 2280387
Change-Id: I60ce09ccf0f04f170461bcea268f963ba8244d29
Signed-off-by: default avatarSujeev Dias <sdias@codeaurora.org>
parent c3d80394
Loading
Loading
Loading
Loading
+6 −12
Original line number Diff line number Diff line
@@ -268,15 +268,13 @@ static int mhi_fw_load_amss(struct mhi_controller *mhi_cntrl,
}

static int mhi_fw_load_sbl(struct mhi_controller *mhi_cntrl,
			   void *buf,
			   dma_addr_t dma_addr,
			   size_t size)
{
	u32 tx_status, val;
	int i, ret;
	void __iomem *base = mhi_cntrl->bhi;
	rwlock_t *pm_lock = &mhi_cntrl->pm_lock;
	dma_addr_t dma_addr = dma_map_single(mhi_cntrl->dev, buf, size,
					     DMA_TO_DEVICE);
	struct {
		char *name;
		u32 offset;
@@ -288,9 +286,6 @@ static int mhi_fw_load_sbl(struct mhi_controller *mhi_cntrl,
		{ NULL },
	};

	if (dma_mapping_error(mhi_cntrl->dev, dma_addr))
		return -ENOMEM;

	MHI_LOG("Starting BHI programming\n");

	/* program start sbl download via  bhi protocol */
@@ -339,12 +334,9 @@ static int mhi_fw_load_sbl(struct mhi_controller *mhi_cntrl,
		goto invalid_pm_state;
	}

	dma_unmap_single(mhi_cntrl->dev, dma_addr, size, DMA_TO_DEVICE);

	return (tx_status == BHI_STATUS_SUCCESS) ? 0 : -ETIMEDOUT;

invalid_pm_state:
	dma_unmap_single(mhi_cntrl->dev, dma_addr, size, DMA_TO_DEVICE);

	return -EIO;
}
@@ -462,6 +454,7 @@ void mhi_fw_load_worker(struct work_struct *work)
	const struct firmware *firmware;
	struct image_info *image_info;
	void *buf;
	dma_addr_t dma_addr;
	size_t size;

	mhi_cntrl = container_of(work, struct mhi_controller, fw_worker);
@@ -506,7 +499,7 @@ void mhi_fw_load_worker(struct work_struct *work)
	if (size > firmware->size)
		size = firmware->size;

	buf = kmemdup(firmware->data, size, GFP_KERNEL);
	buf = mhi_alloc_coherent(mhi_cntrl, size, &dma_addr, GFP_KERNEL);
	if (!buf) {
		MHI_ERR("Could not allocate memory for image\n");
		release_firmware(firmware);
@@ -514,8 +507,9 @@ void mhi_fw_load_worker(struct work_struct *work)
	}

	/* load sbl image */
	ret = mhi_fw_load_sbl(mhi_cntrl, buf, size);
	kfree(buf);
	memcpy(buf, firmware->data, size);
	ret = mhi_fw_load_sbl(mhi_cntrl, dma_addr, size);
	mhi_free_coherent(mhi_cntrl, size, buf, dma_addr);

	if (!mhi_cntrl->fbc_download || ret || mhi_cntrl->ee == MHI_EE_EDL)
		release_firmware(firmware);