/*
*/
/* radeon_state.c -- State support for Radeon -*- linux-c -*- */
/*
* Copyright 2000 VA Linux Systems, Inc., Fremont, California.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Authors:
* Gareth Hughes <gareth@valinux.com>
* Kevin E. Martin <martin@valinux.com>
*/
#include "drmP.h"
#include "drm.h"
#include "drm_sarea.h"
#include "radeon_drm.h"
#include "radeon_drv.h"
#include "radeon_io32.h"
/*
* Helper functions for client state checking and fixup
*/
static inline int
{
/*
* Hrm ... the story of the offset ... So this function converts
* the various ideas of what userland clients might have for an
* offset in the card address space into an offset into the card
* address space :) So with a sane client, it should just keep
* the value intact and just do some boundary checking. However,
* not all clients are sane. Some older clients pass us 0 based
* offsets relative to the start of the framebuffer and some may
* assume the AGP aperture it appended to the framebuffer, so we
* try to detect those cases and fix them up.
*
* Note: It might be a good idea here to make sure the offset lands
* in some "allowed" area to protect things like the PCIE GART...
*/
/*
* First, the best case, the offset already lands in either the
* framebuffer or the GART mapped space
*/
return (0);
/*
* Ok, that didn't happen... now check if we have a zero based
* offset that fits in the framebuffer + gart space, apply the
* magic offset we get from SETPARAM or calculated from fb_location
*/
}
/* Finally, assume we aimed at a GART offset if beyond the fb */
/* Now recheck and fail if out of bounds */
return (0);
}
return (EINVAL);
}
static inline int
{
switch (id) {
case RADEON_EMIT_PP_MISC:
DRM_ERROR("Invalid depth buffer offset\n");
return (EINVAL);
}
break;
case RADEON_EMIT_PP_CNTL:
DRM_ERROR("Invalid colour buffer offset\n");
return (EINVAL);
}
break;
case R200_EMIT_PP_TXOFFSET_0:
case R200_EMIT_PP_TXOFFSET_1:
case R200_EMIT_PP_TXOFFSET_2:
case R200_EMIT_PP_TXOFFSET_3:
case R200_EMIT_PP_TXOFFSET_4:
case R200_EMIT_PP_TXOFFSET_5:
&data[0])) {
DRM_ERROR("Invalid R200 texture offset\n");
return (EINVAL);
}
break;
DRM_ERROR("Invalid R100 texture offset\n");
return (EINVAL);
}
break;
case R200_EMIT_PP_CUBIC_OFFSETS_5: {
int i;
for (i = 0; i < 5; i++) {
DRM_ERROR("Invalid R200 cubic"
" texture offset\n");
return (EINVAL);
}
}
break;
}
{
int i;
for (i = 0; i < 5; i++) {
DRM_ERROR("Invalid R100 cubic"
" texture offset\n");
return (EINVAL);
}
}
}
break;
case R200_EMIT_VAP_CTL:
{
BEGIN_RING(2);
ADVANCE_RING();
}
break;
case RADEON_EMIT_SE_CNTL:
case RADEON_EMIT_RE_MISC:
case R200_EMIT_PP_TXCBLEND_0:
case R200_EMIT_PP_TXCBLEND_1:
case R200_EMIT_PP_TXCBLEND_2:
case R200_EMIT_PP_TXCBLEND_3:
case R200_EMIT_PP_TXCBLEND_4:
case R200_EMIT_PP_TXCBLEND_5:
case R200_EMIT_PP_TXCBLEND_6:
case R200_EMIT_PP_TXCBLEND_7:
case R200_EMIT_TFACTOR_0:
case R200_EMIT_VTX_FMT_0:
case R200_EMIT_TEX_PROC_CTL_2:
case R200_EMIT_PP_TXFILTER_0:
case R200_EMIT_PP_TXFILTER_1:
case R200_EMIT_PP_TXFILTER_2:
case R200_EMIT_PP_TXFILTER_3:
case R200_EMIT_PP_TXFILTER_4:
case R200_EMIT_PP_TXFILTER_5:
case R200_EMIT_VTE_CNTL:
case R200_EMIT_PP_TAM_DEBUG3:
case R200_EMIT_PP_CNTL_X:
case R200_EMIT_RE_POINTSIZE:
case R200_EMIT_PP_AFS_0:
case R200_EMIT_PP_AFS_1:
case R200_EMIT_ATF_TFACTOR:
case R200_EMIT_PP_TXCTLALL_0:
case R200_EMIT_PP_TXCTLALL_1:
case R200_EMIT_PP_TXCTLALL_2:
case R200_EMIT_PP_TXCTLALL_3:
case R200_EMIT_PP_TXCTLALL_4:
case R200_EMIT_PP_TXCTLALL_5:
case R200_EMIT_VAP_PVS_CNTL:
/* These packets don't contain memory offsets */
break;
default:
return (EINVAL);
}
return (0);
}
static inline int
unsigned int *cmdsz)
{
int count, i, k;
DRM_ERROR("Not a type 3 packet\n");
return (EINVAL);
}
DRM_ERROR("Packet size larger than size of data provided\n");
return (EINVAL);
}
switch (cmd[0] & 0xff00) {
/* XXX Are there old drivers needing other packets? */
case RADEON_3D_DRAW_IMMD:
case RADEON_3D_DRAW_VBUF:
case RADEON_3D_DRAW_INDX:
case RADEON_WAIT_FOR_IDLE:
case RADEON_CP_NOP:
case RADEON_3D_CLEAR_ZMASK:
#if 0
case RADEON_CP_NEXT_CHAR:
case RADEON_CP_PLY_NEXTSCAN:
case RADEON_CP_SET_SCISSORS:
/* probably safe but will never need them? */
#endif
/* these packets are safe */
break;
case RADEON_CP_3D_DRAW_IMMD_2:
case RADEON_CP_3D_DRAW_VBUF_2:
case RADEON_CP_3D_DRAW_INDX_2:
case RADEON_3D_CLEAR_HIZ:
/* safe but r200 only */
DRM_ERROR("Invalid 3d packet for r100-class chip\n");
return (EINVAL);
}
break;
case RADEON_3D_LOAD_VBPNTR:
"Too large payload in 3D_LOAD_VBPNTR (count=%d)\n",
count);
return (EINVAL);
}
/* carefully check packet contents */
k = 0;
i = 2;
i++; /* skip attribute field */
"Invalid offset (k=%d i=%d) ini"
" 3D_LOAD_VBPNTR packet.\n", k, i);
return (EINVAL);
}
k++;
i++;
if (k == narrays)
break;
/* have one more to process, they come in pairs */
"Invalid offset (k=%d i=%d) in"
" 3D_LOAD_VBPNTR packet.\n", k, i);
return (EINVAL);
}
k++;
i++;
}
/* do the counts match what we expect ? */
"Malformed 3D_LOAD_VBPNTR packet"
"(k=%d i=%d narrays=%d count+1=%d).\n",
return (EINVAL);
}
break;
DRM_ERROR("Invalid 3d packet for r200-class chip\n");
return (EINVAL);
}
DRM_ERROR("Invalid rndr_gen_indx offset\n");
return (EINVAL);
}
break;
case RADEON_CP_INDX_BUFFER:
DRM_ERROR("Invalid 3d packet for r100-class chip\n");
return (EINVAL);
}
return (EINVAL);
}
return (EINVAL);
}
break;
case RADEON_CNTL_HOSTDATA_BLT:
case RADEON_CNTL_PAINT_MULTI:
case RADEON_CNTL_BITBLT_MULTI:
/* MSB of opcode: next DWORD GUI_CNTL */
DRM_ERROR("Invalid first packet offset\n");
return (EINVAL);
}
}
DRM_ERROR("Invalid second packet offset\n");
return (EINVAL);
}
}
break;
default:
return (EINVAL);
}
return (0);
}
/*
* CP hardware state programming functions
*/
{
DRM_DEBUG(" box: x1=%d y1=%d x2=%d y2=%d\n",
BEGIN_RING(4);
ADVANCE_RING();
}
/* Emit 1.1 state */
{
if (dirty & RADEON_UPLOAD_CONTEXT) {
&ctx->rb3d_depthoffset)) {
DRM_ERROR("Invalid depth buffer offset\n");
return (EINVAL);
}
&ctx->rb3d_coloroffset)) {
DRM_ERROR("Invalid depth buffer offset\n");
return (EINVAL);
}
BEGIN_RING(14);
ADVANCE_RING();
}
if (dirty & RADEON_UPLOAD_VERTFMT) {
BEGIN_RING(2);
ADVANCE_RING();
}
if (dirty & RADEON_UPLOAD_LINE) {
BEGIN_RING(5);
ADVANCE_RING();
}
if (dirty & RADEON_UPLOAD_BUMPMAP) {
BEGIN_RING(5);
ADVANCE_RING();
}
if (dirty & RADEON_UPLOAD_MASKS) {
BEGIN_RING(4);
ADVANCE_RING();
}
if (dirty & RADEON_UPLOAD_VIEWPORT) {
BEGIN_RING(7);
ADVANCE_RING();
}
if (dirty & RADEON_UPLOAD_SETUP) {
BEGIN_RING(4);
ADVANCE_RING();
}
if (dirty & RADEON_UPLOAD_MISC) {
BEGIN_RING(2);
ADVANCE_RING();
}
if (dirty & RADEON_UPLOAD_TEX0) {
DRM_ERROR("Invalid texture offset for unit 0\n");
return (EINVAL);
}
BEGIN_RING(9);
ADVANCE_RING();
}
if (dirty & RADEON_UPLOAD_TEX1) {
DRM_ERROR("Invalid texture offset for unit 1\n");
return (EINVAL);
}
BEGIN_RING(9);
ADVANCE_RING();
}
if (dirty & RADEON_UPLOAD_TEX2) {
DRM_ERROR("Invalid texture offset for unit 2\n");
return (EINVAL);
}
BEGIN_RING(9);
ADVANCE_RING();
}
return (0);
}
/* Emit 1.2 state */
{
BEGIN_RING(3);
ADVANCE_RING();
}
}
/*
* New (1.3) state mechanism. 3 commands (packet, scalar, vector) in
* 1.3 cmdbuffers allow all previous state to be updated as well as
* the tcl scalar and vector areas.
*/
static const struct {
int start;
int len;
const char *name;
"RADEON_SE_TCL_MATERIAL_EMMISSIVE_RED"},
"R200_SE_TCL_OUTPUT_VTX_COMP_SEL"},
"R200_SE_TCL_INPUT_VTX_VECTOR_ADDR_0"},
};
/*
* Performance monitoring functions
*/
int x, int y, int w, int h, int r, int g, int b)
{
((g & 0xfc) << 3) | ((b & 0xf8) >> 3));
break;
default:
break;
}
BEGIN_RING(4);
OUT_RING(0xffffffff);
ADVANCE_RING();
BEGIN_RING(6);
} else {
}
OUT_RING((x << 16) | y);
OUT_RING((w << 16) | h);
ADVANCE_RING();
}
{
/*
* Collapse various things into a wait flag -- trying to
* guess if userspace slept -- better just to have them tell us.
*/
}
}
/* Purple box for page flipping */
/* Red box if we have to wait for idle at any point */
/* Blue box: lost context? */
/* Yellow box for texture swaps */
/* Green box if hardware never idles (as far as we can tell) */
/*
* Draw bars indicating number of buffers allocated
* (not a great measure, easily confused)
*/
}
}
/*
* CP command dispatch functions
*/
{
int i;
if (tmp & RADEON_FRONT)
flags |= RADEON_BACK;
if (tmp & RADEON_BACK)
flags |= RADEON_FRONT;
}
BEGIN_RING(4);
/*
* Ensure the 3D stream is idle before doing a
* 2D fill to clear the front or back buffer.
*/
ADVANCE_RING();
/* Make sure we restore the 3D state next time. */
for (i = 0; i < nbox; i++) {
DRM_DEBUG("dispatch clear %d,%d-%d,%d flags 0x%x\n",
x, y, w, h, flags);
if (flags & RADEON_FRONT) {
BEGIN_RING(6);
(RADEON_CNTL_PAINT_MULTI, 4));
OUT_RING((x << 16) | y);
OUT_RING((w << 16) | h);
ADVANCE_RING();
}
if (flags & RADEON_BACK) {
BEGIN_RING(6);
(RADEON_CNTL_PAINT_MULTI, 4));
OUT_RING((x << 16) | y);
OUT_RING((w << 16) | h);
ADVANCE_RING();
}
}
}
/* hyper z clear */
/*
* no docs available, based on reverse engeneering
* by Stephane Marchesin
*/
(flags & RADEON_CLEAR_FASTZ)) {
int i;
int depthpixperline =
/*
* Make sure we restore the 3D state next time.
* we haven't touched any "normal" state - still
* need this?
*/
(flags & RADEON_USE_HIERZ)) {
/* FIXME : reverse engineer that for Rx00 cards */
/*
* FIXME : the mask supposedly contains low-res
* z values. So can't set just to the max (0xff?
* or actually 0x3fff?), need to take z clear
* value into account?
*/
/*
* pattern seems to work for r100, though get
* slight rendering errors with glxgears. If
* hierz is not enabled for r100, only 4 bits
* which indicate clear (15,16,31,32, all zero)
* matter, the other ones are ignored, and the
* same clear mask can be used. That's very
* different behaviour than R200 which needs
* different clear mask and different number
* of tiles to clear if hierz is enabled or not !?!
*/
} else {
/*
* clear mask : chooses the clearing pattern.
* rv250: could be used to clear only parts of macrotiles
* (but that would get really complicated...)?
* bit 0 and 1 (either or both of them ?!?!) are used to
* not clear tile (or maybe one of the bits indicates if
* the tile is compressed or not), bit 2 and 3 to not
* clear tile 1,...,.
* Pattern is as follows:
* | 0,1 | 4,5 | 8,9 |12,13|16,17|20,21|24,25|28,29|
* bits -------------------------------------------------
* | 2,3 | 6,7 |10,11|14,15|18,19|22,23|26,27|30,31|
* rv100: clearmask covers 2x8 4x1 tiles, but one clear
* still covers 256 pixels ?!?
*/
clearmask = 0x0;
}
BEGIN_RING(8);
/* what offset is this exactly ? */
/* need ctlstat, otherwise get some strange black flickering */
ADVANCE_RING();
for (i = 0; i < nbox; i++) {
/*
* it looks like r200 needs rv-style clears, at
* least if hierz is not enabled?
*/
/*
* FIXME : figure this out for r200 (when hierz
* is enabled). Or maybe r200 actually doesn't
* need to put the low-res z value into the tile
* cache like r100, but just needs to clear the
* hi-level z-buffer? Works for R100, both with
* hierz and without.R100 seems to operate on
* need to be 64 pix (4 blocka) aligned?
* Potentially problematic with resolutions
* which are not 64 pix aligned?
*/
nrtilesx =
nrtilesy =
for (j = 0; j <= nrtilesy; j++) {
BEGIN_RING(4);
(RADEON_3D_CLEAR_ZMASK, 2));
/* first tile */
/* the number of tiles to clear */
/*
* clear mask :
* chooses the clearing pattern.
*/
ADVANCE_RING();
}
/* works for rv250. */
/*
* find first macro tile
* (8x2 4x4 z-pixels on rv250)
*/
nrtilesx =
nrtilesy =
for (j = 0; j <= nrtilesy; j++) {
BEGIN_RING(4);
(RADEON_3D_CLEAR_ZMASK, 2));
/* first tile */
/*
* judging by the first tile
* offset needed, could possibly
* tiles instead of 8x2 * 4x4
* macro tiles, though would
* still need clear mask for
* granularity is desired ?
*/
/* the number of tiles to clear */
/*
* clear mask :
* chooses the clearing pattern.
*/
ADVANCE_RING();
}
} else { /* rv 100 */
/* rv100 might not need 64 pix alignment */
/* offsets are, hmm, weird */
nrtilesx =
nrtilesy =
for (j = 0; j <= nrtilesy; j++) {
BEGIN_RING(4);
(RADEON_3D_CLEAR_ZMASK, 2));
/* the number of tiles to clear */
/*
* clear mask :
* chooses the clearing pattern.
*/
ADVANCE_RING();
}
}
}
/* TODO don't always clear all hi-level z tiles */
(flags & RADEON_USE_HIERZ))
/*
* r100 and cards without hierarchical z-buffer
* have no high-level z-buffer
*/
/*
* FIXME : the mask supposedly contains low-res
* z values. So can't set just to the max (0xff?
* or actually 0x3fff?), need to take z clear value
* into account?
*/
{
BEGIN_RING(4);
OUT_RING(0x3cc0);
ADVANCE_RING();
}
}
/*
* rendering a quad into just those buffers. Thus, we have to
* make sure the 3D engine is configured correctly.
*/
int tempPP_CNTL;
int tempRE_CNTL;
int tempRB3D_CNTL;
int tempRB3D_PLANEMASK;
int tempSE_CNTL;
int tempSE_VTE_CNTL;
int tempSE_VTX_FMT_0;
int tempSE_VTX_FMT_1;
int tempSE_VAP_CNTL;
tempPP_CNTL = 0;
tempRE_CNTL = 0;
tempRB3D_STENCILREFMASK = 0x0;
/* Disable TCL */
(/* SE_VAP_CNTL__FORCE_W_TO_ONE_MASK | */
(0x9 << SE_VAP_CNTL__VF_MAX_VTX_NUM__SHIFT));
tempRB3D_PLANEMASK = 0x0;
tempRE_AUX_SCISSOR_CNTL = 0x0;
/* Vertex format (X, Y, Z, W) */
tempSE_VTX_FMT_1 = 0x0;
/*
* Depth buffer specific enables
*/
if (flags & RADEON_DEPTH) {
/* Enable depth buffer */
} else {
/* Disable depth buffer */
}
/*
* Stencil buffer specific enables
*/
if (flags & RADEON_STENCIL) {
} else {
tempRB3D_STENCILREFMASK = 0x00000000;
}
if (flags & RADEON_USE_COMP_ZBUF) {
}
if (flags & RADEON_USE_HIERZ) {
}
BEGIN_RING(26);
ADVANCE_RING();
/* Make sure we restore the 3D state next time. */
for (i = 0; i < nbox; i++) {
/*
* Funny that this should be required --
* sets top-left?
*/
BEGIN_RING(14);
(3 << RADEON_NUM_VERTICES_SHIFT)));
OUT_RING(0x3f800000);
OUT_RING(0x3f800000);
OUT_RING(0x3f800000);
ADVANCE_RING();
}
if (flags & RADEON_DEPTH) {
} else {
rb3d_cntl &= ~RADEON_Z_ENABLE;
}
if (flags & RADEON_STENCIL) {
/* misnamed field */
} else {
rb3d_stencilrefmask = 0x00000000;
}
if (flags & RADEON_USE_COMP_ZBUF) {
}
if (flags & RADEON_USE_HIERZ) {
}
BEGIN_RING(13);
OUT_RING(0x00000000);
ADVANCE_RING();
/* Make sure we restore the 3D state next time. */
for (i = 0; i < nbox; i++) {
/*
* Funny that this should be required --
* sets top-left?
*/
BEGIN_RING(15);
(3 << RADEON_NUM_VERTICES_SHIFT)));
OUT_RING(0x0);
OUT_RING(0x0);
OUT_RING(0x0);
ADVANCE_RING();
}
}
/*
* Increment the clear counter. The client-side 3D driver must
* wait on this value before performing the clear ioctl. We
* need this because the card's so damned fast...
*/
BEGIN_RING(4);
ADVANCE_RING();
}
{
int i;
/* Do some trivial performance monitoring... */
/*
* Wait for the 3D stream to idle before dispatching the bitblt.
* This will prevent data corruption between the two streams.
*/
BEGIN_RING(2);
ADVANCE_RING();
for (i = 0; i < nbox; i++) {
DRM_DEBUG("dispatch swap %d,%d-%d,%d\n", x, y, w, h);
BEGIN_RING(9);
/* Make this work even if front & back are flipped: */
if (dev_priv->current_page == 0) {
} else {
}
OUT_RING((x << 16) | y);
OUT_RING((x << 16) | y);
OUT_RING((w << 16) | h);
ADVANCE_RING();
}
/*
* Increment the frame counter. The client-side 3D driver must
* throttle the framerate by waiting for this value before
* performing the swapbuffer ioctl.
*/
BEGIN_RING(4);
ADVANCE_RING();
}
{
DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n",
/* Do some trivial performance monitoring... */
}
/* Update the frame offsets for both CRTCs */
BEGIN_RING(6);
ADVANCE_RING();
/*
* Increment the frame counter. The client-side 3D driver must
* throttle the framerate by waiting for this value before
* performing the swapbuffer ioctl.
*/
BEGIN_RING(2);
ADVANCE_RING();
}
{
switch (primitive & RADEON_PRIM_TYPE_MASK) {
case RADEON_PRIM_TYPE_NONE:
case RADEON_PRIM_TYPE_POINT:
return (nr < 1);
case RADEON_PRIM_TYPE_LINE:
return (nr < 2);
case RADEON_PRIM_TYPE_TRI_FAN:
return (nr < 3);
default:
return (1);
}
}
typedef struct {
unsigned int start;
unsigned int finish;
unsigned int prim;
unsigned int numverts;
unsigned int offset;
unsigned int vc_format;
{
int i = 0;
DRM_DEBUG("hwprim 0x%x vfmt 0x%x %d..%d %d verts\n",
DRM_ERROR("bad prim %x numverts %d\n",
return;
}
do {
/* Emit the next cliprect */
if (i < nbox) {
}
/* Emit the vertex buffer rendering commands */
BEGIN_RING(5);
ADVANCE_RING();
i++;
} while (i < nbox);
}
{
/* Emit the vertex buffer age */
BEGIN_RING(2);
ADVANCE_RING();
}
{
/*
* Indirect buffer data must be an even number of
* dwords, so if we've been given an odd number we must
* pad the data with a Type-2 CP packet.
*/
if (dwords & 1) {
}
/* Fire off the indirect buffer */
BEGIN_RING(3);
ADVANCE_RING();
}
}
{
int dwords;
int i = 0;
DRM_DEBUG("hwprim 0x%x vfmt 0x%x %d..%d offset: %x nr %d\n",
return;
}
return;
}
(count << RADEON_NUM_VERTICES_SHIFT));
do {
if (i < nbox)
i++;
} while (i < nbox);
}
/*ARGSUSED*/
{
int i;
DRM_ERROR("Invalid destination offset\n");
return (EINVAL);
}
/*
* Flush the pixel cache. This ensures no pixel data gets mixed
* up with the texture data from the host data blit, otherwise
* part of the texture image may be corrupted.
*/
BEGIN_RING(4);
ADVANCE_RING();
/*
* The compiler won't optimize away a division by a variable,
* even if the only legal values are powers of two. Thus, we'll
* use a shift instead.
*/
case RADEON_TXFORMAT_ARGB8888:
case RADEON_TXFORMAT_RGBA8888:
break;
case RADEON_TXFORMAT_AI88:
case RADEON_TXFORMAT_ARGB1555:
case RADEON_TXFORMAT_RGB565:
case RADEON_TXFORMAT_ARGB4444:
case RADEON_TXFORMAT_VYUY422:
case RADEON_TXFORMAT_YVYU422:
break;
case RADEON_TXFORMAT_I8:
case RADEON_TXFORMAT_RGB332:
break;
default:
return (EINVAL);
}
return (EINVAL);
microtile = 1;
if (tex_width < 64) {
/* we got tiled coordinates, untile them */
image->x *= 2;
}
} else
microtile = 0;
do {
DRM_DEBUG("tex: ofs=0x%x p=%d f=%d x=%hd y=%hd w=%hd h=%hd\n",
/*
* Make a copy of some parameters in case we have to
* update them for a multi-pass texture blit.
*/
if (size > RADEON_MAX_TEXTURE_SIZE) {
size = 4;
} else if (size == 0) {
return (0);
}
#if 0
if (0 && !buf) {
}
#endif
if (!buf) {
DRM_DEBUG("radeon_cp_dispatch_texture: EAGAIN\n");
#ifdef _MULTI_DATAMODEL
sizeof (image32));
} else {
#endif
sizeof (*image));
#ifdef _MULTI_DATAMODEL
}
#endif
return (EAGAIN);
}
/*
* Dispatch the indirect buffer.
*/
do { \
DRM_ERROR("%d: EFAULT on pad, %d bytes\n", \
return (EFAULT); \
} \
} while (__lintzero)
if (microtile) {
/*
* texture micro tiling in use, minimum texture
* width is thus 16 bytes. however, we cannot use
* blitter directly for texture width < 64 bytes,
* since minimum tex pitch is 64 bytes and we need
* this to match the texture width, otherwise the
* blitter will tile it wrong. Thus, tiling manually
* in this case. Additionally, need to special case
* tex height = 1, since our actual image will have
* height 2 and we need to ensure we don't read
* beyond the texture size from user space.
*/
} else if (tex_width == 32) {
}
} else if (tex_width < 16) {
buffer += 4;
}
} else if (tex_width == 32) {
/*
* TODO: make sure this works when not
* fitting in one buffer
* (i.e. 32bytes x 2048...)
*/
data += 16;
data += 16;
data += 16;
data += 16;
buffer += 16;
}
}
} else {
if (tex_width >= 32) {
/*
* Texture image width is larger than the
* minimum, so we can upload it directly.
*/
} else {
/*
* Texture image width is less than the minimum,
* so we need to pad out each image scanline to
* the minimum width.
*/
buffer += 8;
}
}
}
BEGIN_RING(9);
(format << 8) |
OUT_RING(0);
ADVANCE_RING();
COMMIT_RING();
/* Update the input parameters for next time */
/*
* Flush the pixel cache after the blit completes. This ensures
* the texture data is written out to memory before rendering
* continues.
*/
BEGIN_RING(4);
ADVANCE_RING();
COMMIT_RING();
return (0);
}
{
int i;
DRM_DEBUG("\n");
BEGIN_RING(35);
OUT_RING(0x00000000);
for (i = 0; i < 32; i++) {
}
ADVANCE_RING();
}
{
return;
(void) radeon_do_cp_idle(dev_priv);
}
/*
* Allocates a virtual surface
* doesn't always allocate a real surface, will stretch an existing
* surface when possible.
*
* Note that refcount can be at most 2, since during a free refcount=3
* might mean we have to allocate a new surface which might not always
* be available.
* For example : we allocate three contigous surfaces ABC. If B is
* freed, we suddenly need two surfaces to store A and C, which might
* not always be available.
*/
{
struct radeon_virt_surface *s;
int i;
int virt_surface_index;
/* sanity check */
((new_lower & RADEON_SURF_ADDRESS_FIXED_MASK) != 0))
return (-1);
/* make sure there is no overlap with existing surfaces */
for (i = 0; i < RADEON_MAX_SURFACES; i++) {
return (-1);
}
}
/* find a virtual surface */
for (i = 0; i < 2 * RADEON_MAX_SURFACES; i++)
break;
if (i == 2 * RADEON_MAX_SURFACES) {
return (-1);
}
virt_surface_index = i;
/* try to reuse an existing surface */
for (i = 0; i < RADEON_MAX_SURFACES; i++) {
/* extend before */
s->surface_index = i;
return (virt_surface_index);
}
/* extend after */
s->surface_index = i;
return (virt_surface_index);
}
}
/* okay, we need a new one */
for (i = 0; i < RADEON_MAX_SURFACES; i++) {
s->surface_index = i;
return (virt_surface_index);
}
}
/* we didn't find anything */
return (-1);
}
static int
{
struct radeon_virt_surface *s;
int i;
/* find the virtual surface */
for (i = 0; i < 2 * RADEON_MAX_SURFACES; i++) {
s = &(dev_priv->virt_surfaces[i]);
if (s->filp) {
refcount == 0)
flags = 0;
dev_priv);
return (0);
}
}
}
return (1);
}
{
int i;
for (i = 0; i < 2 * RADEON_MAX_SURFACES; i++) {
}
}
/*
* IOCTL functions
*/
/*ARGSUSED*/
{
if (!dev_priv) {
return (EINVAL);
}
return (EINVAL);
else
return (0);
}
/*ARGSUSED*/
{
if (!dev_priv) {
return (EINVAL);
}
return (EINVAL);
}
else
return (0);
}
/*ARGSUSED*/
{
#ifdef _MULTI_DATAMODEL
sizeof (clear32));
} else {
#endif
#ifdef _MULTI_DATAMODEL
}
#endif
return (EFAULT);
COMMIT_RING();
return (0);
}
/*
* Not sure why this isn't set all the time:
*/
{
BEGIN_RING(6);
ADVANCE_RING();
dev_priv->current_page = 0;
return (0);
}
/*
* Called whenever a client dies, from drm_release.
* NOTE: Lock isn't necessarily held when this is called!
*/
{
if (dev_priv->current_page != 0)
dev_priv->page_flipping = 0;
return (0);
}
/*
* Swapping and flipping are different operations, need different ioctls.
* They can & should be intermixed to support multiple 3d windows.
*/
/*ARGSUSED*/
{
if (!dev_priv->page_flipping)
(void) radeon_do_init_pageflip(dev);
COMMIT_RING();
return (0);
}
/*ARGSUSED*/
{
COMMIT_RING();
return (0);
}
/*ARGSUSED*/
{
if (!dev_priv) {
return (EINVAL);
}
DRM_DEBUG("pid=%d index=%d count=%d discard=%d\n",
DRM_ERROR("buffer index %d (of %d max)\n",
return (EINVAL);
}
return (EINVAL);
}
DRM_ERROR("process %d using buffer owned by %p\n",
return (EINVAL);
}
return (EINVAL);
}
/*
* Build up a prim_t record:
*/
sarea_priv->dirty)) {
DRM_ERROR("radeon_emit_state failed\n");
return (EINVAL);
}
}
}
}
COMMIT_RING();
return (0);
}
/*ARGSUSED*/
{
/* int count; */
if (!dev_priv) {
return (EINVAL);
}
DRM_DEBUG("pid=%d index=%d start=%d end=%d discard=%d\n",
DRM_ERROR("buffer index %d (of %d max)\n",
return (EINVAL);
}
return (EINVAL);
}
DRM_ERROR("process %d using buffer owned by %p\n",
return (EINVAL);
}
return (EINVAL);
}
/* count = (elts.end - elts.start) / sizeof(u16); */
return (EINVAL);
}
return (EINVAL);
}
sarea_priv->dirty)) {
DRM_ERROR("radeon_emit_state failed\n");
return (EINVAL);
}
}
/*
* Build up a prim_t record:
*/
}
COMMIT_RING();
return (0);
}
/*ARGSUSED*/
{
int ret;
#ifdef _MULTI_DATAMODEL
DRM_ERROR("null texture image!\n");
return (EINVAL);
}
if (DRM_COPY_FROM_USER(&image32,
return (EFAULT);
}
} else {
#endif
return (EINVAL);
}
if (DRM_COPY_FROM_USER(&image,
return (EFAULT);
}
#ifdef _MULTI_DATAMODEL
}
#endif
COMMIT_RING();
return (ret);
}
/*ARGSUSED*/
{
#ifdef _MULTI_DATAMODEL
sizeof (stipple32));
} else {
#endif
sizeof (stipple));
#ifdef _MULTI_DATAMODEL
}
#endif
return (EFAULT);
COMMIT_RING();
return (0);
}
/*ARGSUSED*/
{
if (!dev_priv) {
return (EINVAL);
}
DRM_DEBUG("indirect: idx=%d s=%d e=%d d=%d\n",
DRM_ERROR("buffer index %d (of %d max)\n",
return (EINVAL);
}
DRM_ERROR("process %d using buffer owned by %p\n",
return (EINVAL);
}
return (EINVAL);
}
DRM_ERROR("reusing indirect: start=0x%x actual=0x%x\n",
return (EINVAL);
}
/*
* Wait for the 3D stream to idle before the indirect buffer
* containing 2D acceleration commands is processed.
*/
BEGIN_RING(2);
ADVANCE_RING();
/*
* Dispatch the indirect buffer full of commands from the
* X server. This is insecure and is thus only available to
* privileged clients.
*/
}
COMMIT_RING();
return (0);
}
/*ARGSUSED*/
{
int i;
unsigned char laststate;
if (!dev_priv) {
return (EINVAL);
}
#ifdef _MULTI_DATAMODEL
sizeof (vertex32));
} else {
#endif
sizeof (vertex));
#ifdef _MULTI_DATAMODEL
}
#endif
DRM_DEBUG("pid=%d index=%d discard=%d\n",
DRM_ERROR("buffer index %d (of %d max)\n",
return (EINVAL);
}
DRM_ERROR("process %d using buffer owned by %p\n",
return (EINVAL);
}
return (EINVAL);
}
return (EINVAL);
return (EFAULT);
if (DRM_COPY_FROM_USER(&state,
return (EFAULT);
DRM_ERROR("radeon_emit_state2 failed\n");
return (EINVAL);
}
}
} else {
}
sarea_priv->nbox = 0;
}
}
COMMIT_RING();
return (0);
}
{
if (id >= RADEON_MAX_STATE_PACKETS)
return (EINVAL);
DRM_ERROR("Packet size provided larger than data provided\n");
return (EINVAL);
}
DRM_ERROR("Packet verification failed\n");
return (EINVAL);
}
ADVANCE_RING();
return (0);
}
static inline int
{
ADVANCE_RING();
return (0);
}
/*
* God this is ugly
*/
static inline int
{
ADVANCE_RING();
return (0);
}
static inline int
{
ADVANCE_RING();
return (0);
}
static inline int
{
if (!sz)
return (0);
return (EINVAL);
ADVANCE_RING();
return (0);
}
static int
{
unsigned int cmdsz;
int ret;
DRM_ERROR("Packet verification failed\n");
return (ret);
}
ADVANCE_RING();
return (0);
}
int orig_nbox)
{
unsigned int cmdsz;
int ret;
int i = 0;
DRM_ERROR("Packet verification failed\n");
return (ret);
}
if (!orig_nbox)
goto out;
do {
return (EFAULT);
/*
* FIXME The second and subsequent times round
* this loop, send a WAIT_UNTIL_3D_IDLE before
* calling emit_clip_rect(). This fixes a
* lockup on fast machines when sending
* several cliprects with a cmdbuf, as when
* waving a 2D window over a 3D
* window. Something in the commands from user
* space seems to hang the card when they're
* sent several times in a row. That would be
* the correct place to fix it but this works
* around it until I can figure that out - Tim
* Smith
*/
if (i) {
BEGIN_RING(2);
ADVANCE_RING();
}
}
ADVANCE_RING();
out:
return (0);
}
static int
{
switch (flags) {
case RADEON_WAIT_2D:
BEGIN_RING(2);
ADVANCE_RING();
break;
case RADEON_WAIT_3D:
BEGIN_RING(2);
ADVANCE_RING();
break;
case RADEON_WAIT_2D | RADEON_WAIT_3D:
BEGIN_RING(2);
ADVANCE_RING();
break;
default:
return (EINVAL);
}
return (0);
}
/*ARGSUSED*/
{
int idx;
if (!dev_priv) {
return (EINVAL);
}
#ifdef _MULTI_DATAMODEL
sizeof (cmdbuf32));
} else {
#endif
sizeof (cmdbuf));
#ifdef _MULTI_DATAMODEL
}
#endif
return (EINVAL);
}
/*
* Allocate an in-kernel area and copy in the cmdbuf. Do this
* to avoid races between checking values and using those values
* in other code, and simply to avoid a lot of function calls
* to copy in data.
*/
if (orig_bufsz != 0) {
return (ENOMEM);
return (EFAULT);
}
}
int temp;
if (orig_bufsz != 0)
return (temp);
}
/* microcode_version != r300 */
case RADEON_CMD_PACKET:
DRM_DEBUG("RADEON_CMD_PACKET\n");
DRM_ERROR("radeon_emit_packets failed\n");
goto err;
}
break;
case RADEON_CMD_SCALARS:
DRM_DEBUG("RADEON_CMD_SCALARS\n");
DRM_ERROR("radeon_emit_scalars failed\n");
goto err;
}
break;
case RADEON_CMD_VECTORS:
DRM_DEBUG("RADEON_CMD_VECTORS\n");
DRM_ERROR("radeon_emit_vectors failed\n");
goto err;
}
break;
case RADEON_CMD_DMA_DISCARD:
DRM_DEBUG("RADEON_CMD_DMA_DISCARD\n");
DRM_ERROR("buffer index %d (of %d max)\n",
goto err;
}
DRM_ERROR("bad buffer %p %p %d\n",
goto err;
}
break;
case RADEON_CMD_PACKET3:
DRM_DEBUG("RADEON_CMD_PACKET3\n");
DRM_ERROR("radeon_emit_packet3 failed\n");
goto err;
}
break;
case RADEON_CMD_PACKET3_CLIP:
DRM_DEBUG("RADEON_CMD_PACKET3_CLIP\n");
DRM_ERROR("radeon_emit_packet3_clip failed\n");
goto err;
}
break;
case RADEON_CMD_SCALARS2:
DRM_DEBUG("RADEON_CMD_SCALARS2\n");
DRM_ERROR("radeon_emit_scalars2 failed\n");
goto err;
}
break;
case RADEON_CMD_WAIT:
DRM_DEBUG("RADEON_CMD_WAIT\n");
DRM_ERROR("radeon_emit_wait failed\n");
goto err;
}
break;
case RADEON_CMD_VECLINEAR:
DRM_DEBUG("RADEON_CMD_VECLINEAR\n");
DRM_ERROR("radeon_emit_veclinear failed\n");
goto err;
}
break;
default:
DRM_ERROR("bad cmd_type %d at %p\n",
goto err;
}
}
if (orig_bufsz != 0)
COMMIT_RING();
return (0);
err:
if (orig_bufsz != 0)
return (EINVAL);
}
/*ARGSUSED*/
{
int value;
if (!dev_priv) {
return (EINVAL);
}
#ifdef _MULTI_DATAMODEL
} else {
#endif
#ifdef _MULTI_DATAMODEL
}
#endif
break;
case RADEON_PARAM_LAST_FRAME:
value = GET_SCRATCH(0);
break;
break;
case RADEON_PARAM_LAST_CLEAR:
break;
case RADEON_PARAM_IRQ_NR:
break;
case RADEON_PARAM_GART_BASE:
break;
break;
break;
#ifndef __LP64__
/*
* This ioctl() doesn't work on 64-bit platforms because
* hw_lock is a pointer which can't fit into an int-sized
* variable. According to Michel Dänzer, the ioctl) is
* only used on embedded platforms, so not supporting it
* shouldn't be a problem. If the same functionality is
* needed on 64-bit platforms, a new ioctl() would have
* to be added, so backwards-compatibility for the embedded
* platforms can be maintained. --davidm 4-Feb-2004.
*/
/* The lock is the first dword in the sarea. */
break;
#endif
break;
if (!dev_priv->writeback_works)
return (EINVAL);
break;
case RADEON_PARAM_CARD_TYPE:
else
break;
case RADEON_PARAM_VBLANK_CRTC:
break;
default:
return (EINVAL);
}
DRM_ERROR("copy_to_user\n");
return (EFAULT);
}
return (0);
}
/*ARGSUSED*/
{
if (!dev_priv) {
return (EINVAL);
}
#ifdef _MULTI_DATAMODEL
} else {
#endif
#ifdef _MULTI_DATAMODEL
}
#endif
break;
DRM_DEBUG("color tiling disabled\n");
DRM_DEBUG("color tiling enabled\n");
}
break;
break;
break;
default:
return (EINVAL);
}
return (0);
}
/*
* When a client dies:
* - Check for and clean up flipped page state
* - Free any alloced GART memory.
* - Free any alloced radeon surfaces.
*
* DRM infrastructure takes care of reclaiming dma buffers.
*/
void
{
if (dev->dev_private) {
if (dev_priv->page_flipping) {
(void) radeon_do_cleanup_pageflip(dev);
}
}
}
void
{
}
int
{
(struct drm_radeon_driver_file_fields *)
if (!radeon_priv)
return (-ENOMEM);
if (dev_priv)
else
radeon_priv->radeon_fb_delta = 0;
return (0);
}
/*ARGSUSED*/
void
{
}
#ifndef __sparc
};
#else
};
#endif