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

Commit a697e21d authored by Vikram Mulukutla's avatar Vikram Mulukutla
Browse files

msm: scm-pas: Provide a strongly ordered buffer to the secure world



The secure world requires that the metadata-containing buffer
be strongly ordered. Use the dma_alloc_attrs API to obtain a
strongly ordered region for this purpose.

CRs-Fixed: 525863
Change-Id: I0fdfb9957aa0eb66279afa362edec075c3dff131
Signed-off-by: default avatarVikram Mulukutla <markivx@codeaurora.org>
parent 6e5f62e7
Loading
Loading
Loading
Loading
+13 −10
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/clk.h>
#include <linux/dma-mapping.h>

#include <asm/cacheflush.h>

@@ -138,28 +139,30 @@ int pas_init_image(enum pas_id id, const u8 *metadata, size_t size)
	} request;
	u32 scm_ret = 0;
	void *mdata_buf;
	dma_addr_t mdata_phys;
	DEFINE_DMA_ATTRS(attrs);

	ret = scm_pas_enable_bw();
	if (ret)
		return ret;

	/* Make memory physically contiguous */
	mdata_buf = kmemdup(metadata, size, GFP_KERNEL);

	if (!mdata_buf)
	dma_set_attr(DMA_ATTR_STRONGLY_ORDERED, &attrs);
	mdata_buf = dma_alloc_attrs(NULL, size, &mdata_phys, GFP_KERNEL,
					&attrs);
	if (!mdata_buf) {
		pr_err("Allocation for metadata failed.\n");
		return -ENOMEM;
	}

	request.proc = id;
	request.image_addr = virt_to_phys(mdata_buf);
	memcpy(mdata_buf, metadata, size);

	/* Flush metadata to ensure secure world doesn't read stale data */
	__cpuc_flush_dcache_area(mdata_buf, size);
	outer_flush_range(request.image_addr, request.image_addr + size);
	request.proc = id;
	request.image_addr = mdata_phys;

	ret = scm_call(SCM_SVC_PIL, PAS_INIT_IMAGE_CMD, &request,
			sizeof(request), &scm_ret, sizeof(scm_ret));

	kfree(mdata_buf);
	dma_free_attrs(NULL, size, mdata_buf, mdata_phys, &attrs);
	scm_pas_disable_bw();

	if (ret)