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

Commit 4589f677 authored by Jordan Crouse's avatar Jordan Crouse
Browse files

msm: kgsl: Add KGSL_RB_DEVICE macro



The ringbuffer structures are static members of struct adreno_device
which means that they are permanently associated with a specific
adreno device and by extension a struct kgsl_device too. The upshot
is that we can use macro math to derive the adreno device from
a ringbuffer pointer and get rid of the device shortcut in the
ringbuffer struct.  This also gives us a chance to clean up
how functions use the ringbuffer and adreno_device structs
to limit unnessesary dereferencing.

Change-Id: Ic0dedbad909ef71e99cd3319713cee38fb1700f0
Signed-off-by: default avatarJordan Crouse <jcrouse@codeaurora.org>
parent a3883c35
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
/* Copyright (c) 2008-2015, The Linux Foundation. All rights reserved.
/* Copyright (c) 2008-2016, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -1309,7 +1309,7 @@ static inline unsigned int adreno_preempt_state(
static inline unsigned int
adreno_get_rptr(struct adreno_ringbuffer *rb)
{
	struct adreno_device *adreno_dev = ADRENO_DEVICE(rb->device);
	struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb);
	if (adreno_dev->cur_rb == rb &&
		adreno_preempt_state(adreno_dev,
			ADRENO_DISPATCHER_PREEMPT_CLEAR))
@@ -1373,7 +1373,7 @@ static inline void adreno_set_active_ctxs_null(struct adreno_device *adreno_dev)
		if (rb->drawctxt_active)
			kgsl_context_put(&(rb->drawctxt_active->base));
		rb->drawctxt_active = NULL;
		kgsl_sharedmem_writel(rb->device, &rb->pagetable_desc,
		kgsl_sharedmem_writel(&adreno_dev->dev, &rb->pagetable_desc,
			offsetof(struct adreno_ringbuffer_pagetable_info,
				current_rb_ptname), 0);
	}
+14 −15
Original line number Diff line number Diff line
/* Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -1604,7 +1604,8 @@ static inline int adreno_ringbuffer_load_pfp_ucode(struct kgsl_device *device,

/**
 * _ringbuffer_bootstrap_ucode() - Bootstrap GPU Ucode
 * @rb: Pointer to adreno ringbuffer
 * @adreno_dev: Pointer to an adreno device
 * @rb: The ringbuffer to boostrap the code into
 * @load_jt: If non zero only load Jump tables
 *
 * Bootstrap ucode for GPU
@@ -1620,14 +1621,13 @@ static inline int adreno_ringbuffer_load_pfp_ucode(struct kgsl_device *device,
 * PFP dwords from microcode to bootstrap
 * PM4 size dwords from microcode to bootstrap
 */
static int _ringbuffer_bootstrap_ucode(struct adreno_ringbuffer *rb,
					unsigned int load_jt)
static int _ringbuffer_bootstrap_ucode(struct adreno_device *adreno_dev,
		struct adreno_ringbuffer *rb, unsigned int load_jt)
{
	struct kgsl_device *device = &adreno_dev->dev;
	unsigned int *cmds, bootstrap_size, rb_size;
	int i = 0;
	int ret;
	struct kgsl_device *device = rb->device;
	struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
	unsigned int pm4_size, pm4_idx, pm4_addr, pfp_size, pfp_idx, pfp_addr;

	/* Only bootstrap jump tables of ucode */
@@ -1731,8 +1731,7 @@ static int _ringbuffer_bootstrap_ucode(struct adreno_ringbuffer *rb,
	ret = adreno_spin_idle(device, 2000);

	if (ret) {
		KGSL_DRV_ERR(rb->device,
		"microcode bootstrap failed to idle\n");
		KGSL_DRV_ERR(device, "microcode bootstrap failed to idle\n");
		kgsl_device_snapshot(device, NULL);
	}

@@ -1749,7 +1748,7 @@ int a3xx_microcode_load(struct adreno_device *adreno_dev,
{
	int status;
	struct adreno_ringbuffer *rb = ADRENO_CURRENT_RINGBUFFER(adreno_dev);
	struct kgsl_device *device = rb->device;
	struct kgsl_device *device = &adreno_dev->dev;

	if (start_type == ADRENO_START_COLD) {
		/* If bootstrapping if supported to load ucode */
@@ -1765,30 +1764,30 @@ int a3xx_microcode_load(struct adreno_device *adreno_dev,
			 * microcode.
			 */

			status = adreno_ringbuffer_load_pm4_ucode(rb->device, 1,
			status = adreno_ringbuffer_load_pm4_ucode(device, 1,
				adreno_dev->gpucore->pm4_bstrp_size+1, 0);
			if (status != 0)
				return status;

			status = adreno_ringbuffer_load_pfp_ucode(rb->device, 1,
			status = adreno_ringbuffer_load_pfp_ucode(device, 1,
				adreno_dev->gpucore->pfp_bstrp_size+1, 0);
			if (status != 0)
				return status;

			/* Bootstrap rest of the ucode here */
			status = _ringbuffer_bootstrap_ucode(rb, 0);
			status = _ringbuffer_bootstrap_ucode(adreno_dev, rb, 0);
			if (status != 0)
				return status;

		} else {
			/* load the CP ucode using AHB writes */
			status = adreno_ringbuffer_load_pm4_ucode(rb->device, 1,
			status = adreno_ringbuffer_load_pm4_ucode(device, 1,
						adreno_dev->pm4_fw_size, 0);
			if (status != 0)
				return status;

			/* load the prefetch parser ucode using AHB writes */
			status = adreno_ringbuffer_load_pfp_ucode(rb->device, 1,
			status = adreno_ringbuffer_load_pfp_ucode(device, 1,
						adreno_dev->pfp_fw_size, 0);
			if (status != 0)
				return status;
@@ -1796,7 +1795,7 @@ int a3xx_microcode_load(struct adreno_device *adreno_dev,
	} else if (start_type == ADRENO_START_WARM) {
			/* If bootstrapping if supported to load jump tables */
		if (adreno_bootstrap_ucode(adreno_dev)) {
			status = _ringbuffer_bootstrap_ucode(rb, 1);
			status = _ringbuffer_bootstrap_ucode(adreno_dev, rb, 1);
			if (status != 0)
				return status;

+3 −2
Original line number Diff line number Diff line
/* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
/* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -250,11 +250,12 @@ static int a4xx_preemption_pre_ibsubmit(
			struct kgsl_context *context, uint64_t cond_addr,
			struct kgsl_memobj_node *ib)
{
	struct kgsl_device *device = &adreno_dev->dev;
	unsigned int *cmds_orig = cmds;
	int exec_ib = 0;

	cmds += a4xx_preemption_token(adreno_dev, rb, cmds,
				rb->device->memstore.gpuaddr +
				device->memstore.gpuaddr +
				KGSL_MEMSTORE_OFFSET(context->id, preempted));

	if (ib)
+16 −14
Original line number Diff line number Diff line
@@ -218,29 +218,29 @@ static int a5xx_preemption_init(struct adreno_device *adreno_dev)

	/* Allocate mem for storing preemption switch record */
	FOR_EACH_RINGBUFFER(adreno_dev, rb, i) {
		ret = kgsl_allocate_global(&adreno_dev->dev,
		ret = kgsl_allocate_global(device,
			&rb->preemption_desc, A5XX_CP_CTXRECORD_SIZE_IN_BYTES,
			0, KGSL_MEMDESC_PRIVILEGED);
		if (ret)
			return ret;

		/* Initialize the context switch record here */
		kgsl_sharedmem_writel(rb->device, &rb->preemption_desc,
		kgsl_sharedmem_writel(device, &rb->preemption_desc,
			PREEMPT_RECORD(magic), A5XX_CP_CTXRECORD_MAGIC_REF);
		kgsl_sharedmem_writel(rb->device, &rb->preemption_desc,
		kgsl_sharedmem_writel(device, &rb->preemption_desc,
			PREEMPT_RECORD(info), 0);
		kgsl_sharedmem_writel(rb->device, &rb->preemption_desc,
		kgsl_sharedmem_writel(device, &rb->preemption_desc,
			PREEMPT_RECORD(data), 0);
		kgsl_sharedmem_writel(rb->device, &rb->preemption_desc,
		kgsl_sharedmem_writel(device, &rb->preemption_desc,
			PREEMPT_RECORD(cntl), 0x0800000C);
		kgsl_sharedmem_writel(rb->device, &rb->preemption_desc,
		kgsl_sharedmem_writel(device, &rb->preemption_desc,
			PREEMPT_RECORD(rptr), 0);
		kgsl_sharedmem_writel(rb->device, &rb->preemption_desc,
		kgsl_sharedmem_writel(device, &rb->preemption_desc,
			PREEMPT_RECORD(wptr), 0);
		kgsl_sharedmem_writeq(rb->device, &rb->preemption_desc,
		kgsl_sharedmem_writeq(device, &rb->preemption_desc,
			PREEMPT_RECORD(rbase),
			adreno_dev->ringbuffers[i].buffer_desc.gpuaddr);
		kgsl_sharedmem_writeq(rb->device, &rb->preemption_desc,
		kgsl_sharedmem_writeq(device, &rb->preemption_desc,
			PREEMPT_RECORD(counter), addr);

		addr += A5XX_CP_CTXRECORD_PREEMPTION_COUNTER_SIZE;
@@ -353,6 +353,7 @@ static int a5xx_preemption_post_ibsubmit(
			struct adreno_ringbuffer *rb, unsigned int *cmds,
			struct kgsl_context *context)
{
	struct kgsl_device *device = &adreno_dev->dev;
	unsigned int *cmds_orig = cmds;
	unsigned int ctx_id = context ? context->id : 0;

@@ -371,7 +372,7 @@ static int a5xx_preemption_post_ibsubmit(
	*cmds++ = 0;

	cmds += a5xx_preemption_token(adreno_dev, rb, cmds,
				rb->device->memstore.gpuaddr +
				device->memstore.gpuaddr +
				KGSL_MEMSTORE_OFFSET(ctx_id, preempted));

	return cmds - cmds_orig;
@@ -2049,11 +2050,11 @@ static void a5xx_start(struct adreno_device *adreno_dev)
				iommu->smmu_info.gpuaddr);

		FOR_EACH_RINGBUFFER(adreno_dev, rb, i) {
			kgsl_sharedmem_writel(rb->device, &rb->preemption_desc,
			kgsl_sharedmem_writel(device, &rb->preemption_desc,
				PREEMPT_RECORD(rptr), 0);
			kgsl_sharedmem_writel(rb->device, &rb->preemption_desc,
			kgsl_sharedmem_writel(device, &rb->preemption_desc,
				PREEMPT_RECORD(wptr), 0);
			kgsl_sharedmem_writeq(rb->device, &rb->pagetable_desc,
			kgsl_sharedmem_writeq(device, &rb->pagetable_desc,
			  offsetof(struct adreno_ringbuffer_pagetable_info,
			  ttbr0), def_ttbr0);
		}
@@ -2067,9 +2068,10 @@ static int _preemption_init(
			struct adreno_ringbuffer *rb, unsigned int *cmds,
			struct kgsl_context *context)
{
	struct kgsl_device *device = &adreno_dev->dev;
	unsigned int *cmds_orig = cmds;
	uint64_t gpuaddr = rb->preemption_desc.gpuaddr;
	uint64_t gpuaddr_token = rb->device->memstore.gpuaddr +
	uint64_t gpuaddr_token = device->memstore.gpuaddr +
				KGSL_MEMSTORE_OFFSET(0, preempted);

	/* Turn CP protection OFF */
+18 −22
Original line number Diff line number Diff line
/* Copyright (c) 2002,2007-2015, The Linux Foundation. All rights reserved.
/* Copyright (c) 2002,2007-2016, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -346,8 +346,7 @@ static unsigned int _adreno_mmu_set_pt_update_condition(
			struct adreno_ringbuffer *rb,
			unsigned int *cmds, unsigned int ptname)
{
	struct kgsl_device *device = rb->device;
	struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
	struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb);
	unsigned int *cmds_orig = cmds;
	/*
	 * write 1 to switch pt flag indicating that we need to execute the
@@ -397,8 +396,7 @@ static unsigned int _adreno_iommu_pt_update_pid_to_mem(
				struct adreno_ringbuffer *rb,
				unsigned int *cmds, int ptname)
{
	struct kgsl_device *device = rb->device;
	struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
	struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb);
	unsigned int *cmds_orig = cmds;

	*cmds++ = cp_mem_packet(adreno_dev, CP_MEM_WRITE, 2, 1);
@@ -431,8 +429,7 @@ static unsigned int _adreno_iommu_set_pt_v1(struct adreno_ringbuffer *rb,
					unsigned int *cmds_orig,
					u64 ttbr0, u32 contextidr, u32 ptname)
{
	struct kgsl_device *device = rb->device;
	struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
	struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb);
	unsigned int *cmds = cmds_orig;
	unsigned int *cond_exec_ptr;

@@ -587,12 +584,12 @@ unsigned int adreno_iommu_set_pt_generate_cmds(
					unsigned int *cmds,
					struct kgsl_pagetable *pt)
{
	struct kgsl_device *device = rb->device;
	struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
	struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb);
	struct kgsl_device *device = &adreno_dev->dev;
	u64 ttbr0;
	u32 contextidr;
	unsigned int *cmds_orig = cmds;
	struct kgsl_iommu *iommu = adreno_dev->dev.mmu.priv;
	struct kgsl_iommu *iommu = device->mmu.priv;

	ttbr0 = kgsl_mmu_pagetable_get_ttbr0(pt);
	contextidr = kgsl_mmu_pagetable_get_contextidr(pt);
@@ -638,8 +635,7 @@ unsigned int adreno_iommu_set_pt_ib(struct adreno_ringbuffer *rb,
				unsigned int *cmds,
				struct kgsl_pagetable *pt)
{
	struct kgsl_device *device = rb->device;
	struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
	struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb);
	unsigned int *cmds_orig = cmds;
	struct kgsl_iommu_pt *iommu_pt = pt->priv;

@@ -680,9 +676,9 @@ static unsigned int __add_curr_ctxt_cmds(struct adreno_ringbuffer *rb,
			unsigned int *cmds,
			struct adreno_context *drawctxt)
{
	struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb);
	struct kgsl_device *device = &adreno_dev->dev;
	unsigned int *cmds_orig = cmds;
	struct kgsl_device *device = rb->device;
	struct adreno_device *adreno_dev = ADRENO_DEVICE(device);

	/* write the context identifier to memstore memory */
	*cmds++ = cp_packet(adreno_dev, CP_NOP, 1);
@@ -731,8 +727,8 @@ static unsigned int __add_curr_ctxt_cmds(struct adreno_ringbuffer *rb,
static void _set_ctxt_cpu(struct adreno_ringbuffer *rb,
			struct adreno_context *drawctxt)
{
	struct kgsl_device *device = rb->device;
	struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
	struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb);
	struct kgsl_device *device = &adreno_dev->dev;

	if (rb == adreno_dev->cur_rb) {
		_invalidate_uche_cpu(adreno_dev);
@@ -774,8 +770,8 @@ static int _set_ctxt_gpu(struct adreno_ringbuffer *rb,
static int _set_pagetable_cpu(struct adreno_ringbuffer *rb,
			struct kgsl_pagetable *new_pt)
{
	struct kgsl_device *device = rb->device;
	struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
	struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb);
	struct kgsl_device *device = &adreno_dev->dev;
	int result;

	/* update TTBR0 only if we are updating current RB */
@@ -817,9 +813,9 @@ static int _set_pagetable_cpu(struct adreno_ringbuffer *rb,
static int _set_pagetable_gpu(struct adreno_ringbuffer *rb,
			struct kgsl_pagetable *new_pt)
{
	struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb);
	struct kgsl_device *device = &adreno_dev->dev;
	unsigned int *link = NULL, *cmds;
	struct kgsl_device *device = rb->device;
	struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
	int result;

	link = kmalloc(PAGE_SIZE, GFP_KERNEL);
@@ -924,8 +920,8 @@ int adreno_iommu_set_pt_ctx(struct adreno_ringbuffer *rb,
			struct kgsl_pagetable *new_pt,
			struct adreno_context *drawctxt)
{
	struct kgsl_device *device = rb->device;
	struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
	struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb);
	struct kgsl_device *device = &adreno_dev->dev;
	struct kgsl_pagetable *cur_pt = device->mmu.defaultpagetable;
	int result = 0;
	int cpu_path = 0;
Loading