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

Commit e29967ac authored by Jordan Crouse's avatar Jordan Crouse Committed by Jeremy Gebben
Browse files

msm: kgsl: Use a fixed constant for the ringbuffer size



We do not have dynamic ringbuffer sizes so it doesn't make much
sense to carry around the ringbuffer size as a variable.  Use a
#define constant instead and give the compiler a fighting shot at
optimizing math when it can.

Change-Id: Ic0dedbadcd4ae371bc06086a8647703a30020c68
Signed-off-by: default avatarJordan Crouse <jcrouse@codeaurora.org>
parent 1e51b157
Loading
Loading
Loading
Loading
+7 −14
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ adreno_ringbuffer_waitspace(struct adreno_ringbuffer *rb,
	/* if wptr ahead, fill the remaining with NOPs */
	if (wptr_ahead) {
		/* -1 for header */
		nopcount = rb->sizedwords - rb->wptr - 1;
		nopcount = KGSL_RB_DWORDS - rb->wptr - 1;

		cmds = (unsigned int *)rb->buffer_desc.hostptr + rb->wptr;
		cmds_gpu = rb->buffer_desc.gpuaddr + sizeof(uint)*rb->wptr;
@@ -112,14 +112,14 @@ unsigned int *adreno_ringbuffer_allocspace(struct adreno_ringbuffer *rb,
	unsigned int *ptr = NULL;
	int ret = 0;
	unsigned int rptr;
	BUG_ON(numcmds >= rb->sizedwords);
	BUG_ON(numcmds >= KGSL_RB_DWORDS);

	rptr = adreno_get_rptr(rb);
	/* check for available space */
	if (rb->wptr >= rptr) {
		/* wptr ahead or equal to rptr */
		/* reserve dwords for nop packet */
		if ((rb->wptr + numcmds) > (rb->sizedwords -
		if ((rb->wptr + numcmds) > (KGSL_RB_DWORDS -
				GSL_RB_NOP_SIZEDWORDS))
			ret = adreno_ringbuffer_waitspace(rb, context,
							numcmds, 1);
@@ -130,7 +130,7 @@ unsigned int *adreno_ringbuffer_allocspace(struct adreno_ringbuffer *rb,
							numcmds, 0);
		/* check for remaining space */
		/* reserve dwords for nop packet */
		if (!ret && (rb->wptr + numcmds) > (rb->sizedwords -
		if (!ret && (rb->wptr + numcmds) > (KGSL_RB_DWORDS -
				GSL_RB_NOP_SIZEDWORDS))
			ret = adreno_ringbuffer_waitspace(rb, context,
							numcmds, 1);
@@ -370,8 +370,7 @@ static void _ringbuffer_setup_common(struct adreno_ringbuffer *rb)
	struct kgsl_device *device = rb->device;
	struct adreno_device *adreno_dev = ADRENO_DEVICE(device);

	kgsl_sharedmem_set(rb->device, &rb->buffer_desc, 0, 0xAA,
			   (rb->sizedwords << 2));
	kgsl_sharedmem_set(rb->device, &rb->buffer_desc, 0, 0xAA, KGSL_RB_SIZE);

	/*
	 * The size of the ringbuffer in the hardware is the log2
@@ -381,7 +380,7 @@ static void _ringbuffer_setup_common(struct adreno_ringbuffer *rb)
	 */

	adreno_writereg(adreno_dev, ADRENO_REG_CP_RB_CNTL,
		(ilog2(rb->sizedwords >> 1) & 0x3F) |
		(ilog2(KGSL_RB_DWORDS >> 1) & 0x3F) |
		(1 << 27));

	adreno_writereg(adreno_dev, ADRENO_REG_CP_RB_BASE,
@@ -556,17 +555,11 @@ int adreno_ringbuffer_init(struct kgsl_device *device)
	struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer;

	rb->device = device;
	/*
	 * It is silly to convert this to words and then back to bytes
	 * immediately below, but most of the rest of the code deals
	 * in words, so we might as well only do the math once
	 */
	rb->sizedwords = KGSL_RB_SIZE >> 2;

	rb->buffer_desc.flags = KGSL_MEMFLAGS_GPUREADONLY;
	/* allocate memory for ringbuffer */
	status = kgsl_allocate_contiguous(device, &rb->buffer_desc,
		(rb->sizedwords << 2));
		KGSL_RB_SIZE);

	if (status != 0) {
		adreno_ringbuffer_close(rb);
+17 −12
Original line number Diff line number Diff line
/* Copyright (c) 2002,2007-2013, The Linux Foundation. All rights reserved.
/* Copyright (c) 2002,2007-2014, 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
@@ -13,27 +13,32 @@
#ifndef __ADRENO_RINGBUFFER_H
#define __ADRENO_RINGBUFFER_H

/* Adreno ringbuffer size in bytes */
#define KGSL_RB_SIZE (32 * 1024)

/*
 * Adreno ringbuffer sizes in bytes - these are converted to
 * the appropriate log2 values in the code
 * A handy macro to convert the RB size to dwords since most ringbuffer
 * operations happen in dword increments
 */

#define KGSL_RB_SIZE (32 * 1024)
#define KGSL_RB_DWORDS (KGSL_RB_SIZE >> 2)

struct kgsl_device;
struct kgsl_device_private;

/**
 * struct adreno_ringbuffer - Definition for an adreno ringbuffer object
 * @device: KGSL device that owns the ringbuffer object
 * @flags: Internal control flags for the ringbuffer
 * @buffer_desc: Pointer to the ringbuffer memory descriptor
 * @wptr: Local copy of the wptr offset
 * @global_ts: Current global timestamp for the ringbuffer
 */
struct adreno_ringbuffer {
	struct kgsl_device *device;
	uint32_t flags;

	struct kgsl_memdesc buffer_desc;

	/*ringbuffer size */
	unsigned int sizedwords;

	unsigned int wptr; /* write pointer offset in dwords from baseaddr */

	unsigned int wptr;
	unsigned int global_ts;
};

@@ -98,7 +103,7 @@ static inline int adreno_ringbuffer_count(struct adreno_ringbuffer *rb,
{
	if (rb->wptr >= rptr)
		return rb->wptr - rptr;
	return rb->wptr + rb->sizedwords - rptr;
	return rb->wptr + KGSL_RB_DWORDS - rptr;
}

/* Increment a value by 4 bytes with wrap-around based on size */
+9 −11
Original line number Diff line number Diff line
@@ -217,7 +217,7 @@ static int snapshot_rb(struct kgsl_device *device, void *snapshot,
	struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer;
	unsigned int rptr, *rbptr, ibbase;
	phys_addr_t ptbase;
	int index, size, i;
	int index, i;
	int parse_ibs = 0, ib_parse_start;

	/* Get the physical address of the MMU pagetable */
@@ -242,7 +242,7 @@ static int snapshot_rb(struct kgsl_device *device, void *snapshot,
		index--;

		if (index < 0) {
			index = rb->sizedwords - 3;
			index = KGSL_RB_DWORDS - 3;

			/* We wrapped without finding what we wanted */
			if (index < rb->wptr) {
@@ -266,7 +266,7 @@ static int snapshot_rb(struct kgsl_device *device, void *snapshot,
		index--;

		if (index < 0) {
			index = rb->sizedwords - 2;
			index = KGSL_RB_DWORDS - 2;

			/*
			 * Wrapped without finding the context switch. This is
@@ -298,9 +298,7 @@ static int snapshot_rb(struct kgsl_device *device, void *snapshot,
	 * process
	 */

	size = (rb->sizedwords << 2);

	if (remain < size + sizeof(*header)) {
	if (remain < KGSL_RB_SIZE + sizeof(*header)) {
		KGSL_DRV_ERR(device,
			"snapshot: Not enough memory for the rb section");
		return 0;
@@ -310,8 +308,8 @@ static int snapshot_rb(struct kgsl_device *device, void *snapshot,
	header->start = rb->wptr;
	header->end = rb->wptr;
	header->wptr = rb->wptr;
	header->rbsize = rb->sizedwords;
	header->count = rb->sizedwords;
	header->rbsize = KGSL_RB_DWORDS;
	header->count = KGSL_RB_DWORDS;

	/*
	 * Loop through the RB, copying the data and looking for indirect
@@ -319,7 +317,7 @@ static int snapshot_rb(struct kgsl_device *device, void *snapshot,
	 */

	index = rb->wptr;
	for (i = 0; i < rb->sizedwords; i++) {
	for (i = 0; i < KGSL_RB_DWORDS; i++) {
		*data = rbptr[index];

		/*
@@ -357,14 +355,14 @@ static int snapshot_rb(struct kgsl_device *device, void *snapshot,

		index = index + 1;

		if (index == rb->sizedwords)
		if (index == KGSL_RB_DWORDS)
			index = 0;

		data++;
	}

	/* Return the size of the section */
	return size + sizeof(*header);
	return KGSL_RB_SIZE + sizeof(*header);
}

static int snapshot_capture_mem_list(struct kgsl_device *device, void *snapshot,