/* Copyright (c) 2002,2007-2009, Code Aurora Forum. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Code Aurora Forum nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* Alternatively, provided that this notice is retained in full, this software
* may be relicensed by the recipient under the terms of the GNU General Public
* License version 2 ("GPL") and only version 2, in which case the provisions of
* the GPL apply INSTEAD OF those given above. If the recipient relicenses the
* software under the GPL, then the identification text in the MODULE_LICENSE
* macro must be changed to reflect "GPLv2" instead of "Dual BSD/GPL". Once a
* recipient changes the license terms to the GPL, subsequent recipients shall
* not relicense under alternate licensing terms, including the BSD or dual
* BSD/GPL terms. In addition, the following license statement immediately
* below and between the words START and END shall also then apply when this
* software is relicensed under the GPL:
*
* START
*
* 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 only version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* END
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <linux/string.h>
#include <linux/types.h>
#include <linux/msm_kgsl.h>
#include "kgsl_drawctxt.h"
#include "yamato_reg.h"
#include "kgsl.h"
#include "kgsl_log.h"
#include "kgsl_pm4types.h"
#define DISABLE_SHADOW_WRITES
/*
*
* Memory Map for Register, Constant & Instruction Shadow, and Command Buffers
* (34.5KB)
*
* +---------------------+------------+-------------+---+---------------------+
* | ALU Constant Shadow | Reg Shadow | C&V Buffers |Tex| Shader Instr Shadow |
* +---------------------+------------+-------------+---+---------------------+
* ________________________________/ \____________________
* / |
* +--------------+-----------+------+-----------+------------------------+
* | Restore Regs | Save Regs | Quad | Gmem Save | Gmem Restore | unused |
* +--------------+-----------+------+-----------+------------------------+
*
* 8K - ALU Constant Shadow (8K aligned)
* 4K - H/W Register Shadow (8K aligned)
* 4K - Command and Vertex Buffers
* - Indirect command buffer : Const/Reg restore
* - includes Loop & Bool const shadows
* - Indirect command buffer : Const/Reg save
* - Quad vertices & texture coordinates
* - Indirect command buffer : Gmem save
* - Indirect command buffer : Gmem restore
* - Unused (padding to 8KB boundary)
* <1K - Texture Constant Shadow (768 bytes) (8K aligned)
* 18K - Shader Instruction Shadow
* - 6K vertex (32 byte aligned)
* - 6K pixel (32 byte aligned)
* - 6K shared (32 byte aligned)
*
* Note: Reading constants into a shadow, one at a time using REG_TO_MEM, takes
* 3 DWORDS per DWORD transfered, plus 1 DWORD for the shadow, for a total of
* 16 bytes per constant. If the texture constants were transfered this way,
* the Command & Vertex Buffers section would extend past the 16K boundary.
* By moving the texture constant shadow area to start at 16KB boundary, we
* only require approximately 40 bytes more memory, but are able to use the
* LOAD_CONSTANT_CONTEXT shadowing feature for the textures, speeding up
* context switching.
*
* [Using LOAD_CONSTANT_CONTEXT shadowing feature for the Loop and/or Bool
* constants would require an additional 8KB each, for alignment.]
*
*/
/* Constants */
#define ALU_CONSTANTS 2048 /* DWORDS */
#define NUM_REGISTERS 1024 /* DWORDS */
#ifdef DISABLE_SHADOW_WRITES
#define CMD_BUFFER_LEN 9216 /* DWORDS */
#else
#define CMD_BUFFER_LEN 3072 /* DWORDS */
#endif
#define TEX_CONSTANTS (32*6) /* DWORDS */
#define BOOL_CONSTANTS 8 /* DWORDS */
#define LOOP_CONSTANTS 56 /* DWORDS */
#define SHADER_INSTRUCT_LOG2 9U /* 2^n == SHADER_INSTRUCTIONS */
#if defined(PM4_IM_STORE)
/* 96-bit instructions */
#define SHADER_INSTRUCT (1<<SHADER_INSTRUCT_LOG2)
#else
#define SHADER_INSTRUCT 0
#endif
/* LOAD_CONSTANT_CONTEXT shadow size */
#define LCC_SHADOW_SIZE 0x2000 /* 8KB */
#define ALU_SHADOW_SIZE LCC_SHADOW_SIZE /* 8KB */
#define REG_SHADOW_SIZE 0x1000 /* 4KB */
#ifdef DISABLE_SHADOW_WRITES
#define CMD_BUFFER_SIZE 0x9000 /* 36KB */
#else
#define CMD_BUFFER_SIZE 0x3000 /* 12KB */
#endif
#define TEX_SHADOW_SIZE (TEX_CONSTANTS*4) /* 768 bytes */
#define SHADER_SHADOW_SIZE (SHADER_INSTRUCT*12) /* 6KB */
#define REG_OFFSET LCC_SHADOW_SIZE
#define CMD_OFFSET (REG_OFFSET + REG_SHADOW_SIZE)
#define TEX_OFFSET (CMD_OFFSET + CMD_BUFFER_SIZE)
#define SHADER_OFFSET ((TEX_OFFSET + TEX_SHADOW_SIZE + 32) & ~31)
#define CONTEXT_SIZE (SHADER_OFFSET + 3 * SHADER_SHADOW_SIZE)
/* temporary work structure */
struct tmp_ctx {
unsigned int *start; /* Command & Vertex buffer start */
unsigned int *cmd; /* Next available dword in C&V buffer */
/* address of buffers, needed when creating IB1 command buffers. */
uint32_t bool_shadow; /* bool constants */
uint32_t loop_shadow; /* loop constants */
#if defined(PM4_IM_STORE)
uint32_t shader_shared; /* shared shader instruction shadow */
uint32_t shader_vertex; /* vertex shader instruction shadow */
uint32_t shader_pixel; /* pixel shader instruction shadow */
#endif
/* Addresses in command buffer where separately handled registers
* are saved
*/
uint32_t reg_values[4];
uint32_t chicken_restore;
uint32_t gmem_base; /* Base gpu address of GMEM */
};
/* Helper function to calculate IEEE754 single precision float values
* without FPU
*/
unsigned int uint2float(unsigned int uintval)
{
unsigned int exp = 0;
unsigned int frac = 0;
unsigned int u = uintval;
/* Handle zero separately */
if (uintval == 0)
return 0;
/* Find log2 of u */
if (u >= 0x10000) {
exp += 16;
u >>= 16;
}
if (u >= 0x100) {
exp += 8;
u >>= 8;
}
if (u >= 0x10) {
exp += 4;
u >>= 4;
}
if (u >= 0x4) {
exp += 2;
u >>= 2;
}
if (u >= 0x2) {
exp += 1;
u >>= 1;
}
评论0