r300_cs.h revision 29a4f5493529042d1068a7d35da1e7f542474503
178b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson/* 278b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com> 378b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * 478b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * Permission is hereby granted, free of charge, to any person obtaining a 578b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * copy of this software and associated documentation files (the "Software"), 678b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * to deal in the Software without restriction, including without limitation 778b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * on the rights to use, copy, modify, merge, publish, distribute, sub 878b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * license, and/or sell copies of the Software, and to permit persons to whom 978b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * the Software is furnished to do so, subject to the following conditions: 1078b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * 1178b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * The above copyright notice and this permission notice (including the next 1278b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * paragraph) shall be included in all copies or substantial portions of the 1378b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * Software. 1478b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * 1578b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1678b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1778b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 1878b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 1978b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 2078b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 2178b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * USE OR OTHER DEALINGS IN THE SOFTWARE. */ 2278b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 2378b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson#ifndef R300_CS_H 2478b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson#define R300_CS_H 2578b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 2674288078eab1971cc6ce3ae00fa55eb917b5826aCorbin Simpson#include "r300_reg.h" 27fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson#include "r300_winsys.h" 28fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson 2922877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson/* Pack a 32-bit float into a dword. */ 3022877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpsonstatic uint32_t pack_float_32(float f) 3122877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson{ 3222877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson union { 3322877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson float f; 3422877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson uint32_t u; 3522877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson } u; 3622877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson 3722877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson u.f = f; 3822877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson return u.u; 3922877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson} 4022877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson 4178b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson/* Yes, I know macros are ugly. However, they are much prettier than the code 4278b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * that they neatly hide away, and don't have the cost of function setup,so 4378b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * we're going to use them. */ 4478b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 4578b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson#define MAX_CS_SIZE 64 * 1024 / 4 4678b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 47fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson/* XXX stolen from radeon_drm.h */ 48fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson#define RADEON_GEM_DOMAIN_CPU 0x1 49fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson#define RADEON_GEM_DOMAIN_GTT 0x2 50fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson#define RADEON_GEM_DOMAIN_VRAM 0x4 51fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson 527961974fc28257b293961d35f15c0ce7a85f2669Corbin Simpson/* XXX stolen from radeon_reg.h */ 537961974fc28257b293961d35f15c0ce7a85f2669Corbin Simpson#define RADEON_CP_PACKET0 0x0 547961974fc28257b293961d35f15c0ce7a85f2669Corbin Simpson 5578b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson#define CP_PACKET0(register, count) \ 5678b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson (RADEON_CP_PACKET0 | ((count) << 16) | ((register) >> 2)) 5778b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 580ff7cb7c89f0c9ac4e363296e53eada008717252Corbin Simpson#define CP_PACKET3(op, count) \ 590ff7cb7c89f0c9ac4e363296e53eada008717252Corbin Simpson (RADEON_CP_PACKET3 | (op) | ((count) << 16)) 600ff7cb7c89f0c9ac4e363296e53eada008717252Corbin Simpson 6178b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson#define CS_LOCALS(context) \ 62fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson struct r300_winsys* cs_winsys = context->winsys; \ 63fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson struct radeon_cs* cs = cs_winsys->cs 6478b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 65fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson#define CHECK_CS(size) \ 66fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson cs_winsys->check_cs(cs, (size)) 6778b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 6878b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson#define BEGIN_CS(size) do { \ 6978b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson CHECK_CS(size); \ 70f2a7d4f2e8e890e69e1dfa9067db4e90df63989fCorbin Simpson debug_printf("r300: BEGIN_CS in %s (%s:%d)\n", __FUNCTION__, __FILE__, \ 71902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson __LINE__); \ 72fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson cs_winsys->begin_cs(cs, (size), __FILE__, __FUNCTION__, __LINE__); \ 7378b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson} while (0) 7478b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 75412cf4d38be628200982208b7f93bb17530bb6dbCorbin Simpson#define OUT_CS(value) do { \ 76412cf4d38be628200982208b7f93bb17530bb6dbCorbin Simpson cs_winsys->write_cs_dword(cs, value); \ 77412cf4d38be628200982208b7f93bb17530bb6dbCorbin Simpson} while (0) 7878b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 79412cf4d38be628200982208b7f93bb17530bb6dbCorbin Simpson#define OUT_CS_32F(value) do { \ 80412cf4d38be628200982208b7f93bb17530bb6dbCorbin Simpson cs_winsys->write_cs_dword(cs, pack_float_32(value)); \ 81412cf4d38be628200982208b7f93bb17530bb6dbCorbin Simpson} while (0) 8222877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson 8378b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson#define OUT_CS_REG(register, value) do { \ 8429a4f5493529042d1068a7d35da1e7f542474503Corbin Simpson debug_printf("r300: writing 0x%x to register 0x%x\n", value, register); \ 8578b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson OUT_CS(CP_PACKET0(register, 0)); \ 86412cf4d38be628200982208b7f93bb17530bb6dbCorbin Simpson OUT_CS(value); \ 87412cf4d38be628200982208b7f93bb17530bb6dbCorbin Simpson} while (0) 8878b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 8922877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson/* Note: This expects count to be the number of registers, 9022877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson * not the actual packet0 count! */ 9122877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson#define OUT_CS_REG_SEQ(register, count) do { \ 9229a4f5493529042d1068a7d35da1e7f542474503Corbin Simpson debug_printf("r300: writing register sequence 0x%x\n", register); \ 9322877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson OUT_CS(CP_PACKET0(register, ((count) - 1))); \ 9422877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson} while (0) 9522877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson 9678b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson#define OUT_CS_RELOC(bo, offset, rd, wd, flags) do { \ 9729a4f5493529042d1068a7d35da1e7f542474503Corbin Simpson debug_printf("r300: writing relocation for buffer %p, offset %d\n", \ 9829a4f5493529042d1068a7d35da1e7f542474503Corbin Simpson bo, offset); \ 99fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson OUT_CS(offset); \ 100fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson cs_winsys->write_cs_reloc(cs, bo, rd, wd, flags); \ 10178b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson} while (0) 10278b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 103902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson#define END_CS do { \ 104f2a7d4f2e8e890e69e1dfa9067db4e90df63989fCorbin Simpson debug_printf("r300: END_CS in %s (%s:%d)\n", __FUNCTION__, __FILE__, \ 105902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson __LINE__); \ 106902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson cs_winsys->end_cs(cs, __FILE__, __FUNCTION__, __LINE__); \ 107902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson} while (0) 10878b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 109902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson#define FLUSH_CS do { \ 110f2a7d4f2e8e890e69e1dfa9067db4e90df63989fCorbin Simpson debug_printf("r300: FLUSH_CS in %s (%s:%d)\n", __FUNCTION__, __FILE__, \ 111902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson __LINE__); \ 112902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson cs_winsys->flush_cs(cs); \ 113902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson} while (0) 114432ab001d042b816b5892398064e5735d0293955Corbin Simpson 11529a4f5493529042d1068a7d35da1e7f542474503Corbin Simpson#include "r300_cs_inlines.h" 11629a4f5493529042d1068a7d35da1e7f542474503Corbin Simpson 11722877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson#endif /* R300_CS_H */ 118