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

Commit 63767aa7 authored by Jordan Crouse's avatar Jordan Crouse Committed by Deepak Kumar
Browse files

msm: kgsl: Make the "scratch" global buffer use a random GPU address



Select a random global GPU address for the "scratch" buffer that is used
by the ringbuffer for various tasks.

Change-Id: Ic0dedbaddda71dbf9cb2adab3c6c33a24d6a604c
Signed-off-by: default avatarJordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: default avatarDeepak Kumar <dkumar@codeaurora.org>
parent a8acbcb0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -327,7 +327,7 @@ int adreno_ringbuffer_probe(struct adreno_device *adreno_dev, bool nopreempt)

	if (!adreno_is_a3xx(adreno_dev)) {
		status = kgsl_allocate_global(device, &device->scratch,
				PAGE_SIZE, 0, 0, "scratch");
				PAGE_SIZE, 0, KGSL_MEMDESC_RANDOM, "scratch");
		if (status != 0)
			return status;
	}
+2 −0
Original line number Diff line number Diff line
@@ -201,6 +201,8 @@ struct kgsl_memdesc_ops {
#define KGSL_MEMDESC_CONTIG BIT(8)
/* This is an instruction buffer */
#define KGSL_MEMDESC_UCODE BIT(9)
/* For global buffers, randomly assign an address from the region */
#define KGSL_MEMDESC_RANDOM BIT(10)

/**
 * struct kgsl_memdesc - GPU memory object descriptor
+21 −4
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <linux/msm_kgsl.h>
#include <linux/ratelimit.h>
#include <linux/of_platform.h>
#include <linux/random.h>
#include <soc/qcom/scm.h>
#include <soc/qcom/secure_buffer.h>
#include <linux/compat.h>
@@ -223,7 +224,7 @@ static void kgsl_iommu_remove_global(struct kgsl_mmu *mmu,
static void kgsl_iommu_add_global(struct kgsl_mmu *mmu,
		struct kgsl_memdesc *memdesc, const char *name)
{
	int bit;
	u32 bit, start = 0;
	u64 size = kgsl_memdesc_footprint(memdesc);

	if (memdesc->gpuaddr != 0)
@@ -232,10 +233,26 @@ static void kgsl_iommu_add_global(struct kgsl_mmu *mmu,
	if (WARN_ON(global_pt_count >= GLOBAL_PT_ENTRIES))
		return;

	if (WARN_ON(size > KGSL_IOMMU_GLOBAL_MEM_SIZE))
		return;

	if (memdesc->priv & KGSL_MEMDESC_RANDOM) {
		u32 range = GLOBAL_MAP_PAGES - (size >> PAGE_SHIFT);

		start = get_random_int() % range;
	}

	while (start >= 0) {
		bit = bitmap_find_next_zero_area(global_map, GLOBAL_MAP_PAGES,
		0, size >> PAGE_SHIFT, 0);
			start, size >> PAGE_SHIFT, 0);

		if (bit < GLOBAL_MAP_PAGES)
			break;

		start--;
	}

	if (WARN_ON(bit >= GLOBAL_MAP_PAGES))
	if (WARN_ON(start < 0))
		return;

	memdesc->gpuaddr =