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

Commit 9204b942 authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "soc: qcom: secure_buffer: add API page_accessible"

parents 0a94ea27 724d27be
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
@@ -146,6 +146,32 @@ static int batched_hyp_assign(struct sg_table *table, u32 *source_vmids,
	return ret;
}

static inline void set_each_page_of_sg(struct sg_table *table, u64 flag)
{
	struct scatterlist *sg;
	int npages;
	int i = 0;

	for_each_sg(table->sgl, sg, table->nents, i) {
		npages = sg->length / PAGE_SIZE;
		if (sg->length % PAGE_SIZE)
			npages++;
		while (npages--)
			set_page_private(nth_page(sg_page(sg), npages), flag);
	}
}

#define SECURE_PAGE_MAGIC 0xEEEEEEEE
int page_accessible(unsigned long pfn)
{
	struct page *page = pfn_to_page(pfn);

	if (page->private == SECURE_PAGE_MAGIC)
		return 0;
	else
		return 1;
}

/*
 *  When -EADDRNOTAVAIL is returned the memory may no longer be in
 *  a usable state and should no longer be accessed by the HLOS.
@@ -207,6 +233,19 @@ int hyp_assign_table(struct sg_table *table,
	ret = batched_hyp_assign(table, source_vm_copy, source_vm_copy_size,
				 dest_vm_copy, dest_vm_copy_size);

	if (!ret) {
		while (dest_nelems--) {
			if (dest_vmids[dest_nelems] == VMID_HLOS)
				break;
		}

		if (dest_nelems == -1)
			set_each_page_of_sg(table, SECURE_PAGE_MAGIC);
		else
			set_each_page_of_sg(table, 0);
	}


	dma_unmap_single(qcom_secure_buffer_dev, dest_dma_addr,
			 dest_vm_copy_size, DMA_TO_DEVICE);
out_free_dest:
+6 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ int hyp_assign_phys(phys_addr_t addr, u64 size,
			int *dest_vmids, int *dest_perms, int dest_nelems);
const char *msm_secure_vmid_to_string(int secure_vmid);
u32 msm_secure_get_vmid_perms(u32 vmid);
int page_accessible(unsigned long pfn);
#else
static inline int hyp_assign_table(struct sg_table *table,
			u32 *source_vm_list, int source_nelems,
@@ -79,5 +80,10 @@ static inline u32 msm_secure_get_vmid_perms(u32 vmid)
{
	return 0;
}

static inline int page_accessible(unsigned long pfn)
{
	return 1;
}
#endif
#endif