1450N/A/*
1450N/A * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
1450N/A */
1450N/A
1450N/A/* radeon_state.c -- State support for Radeon -*- linux-c -*- */
1450N/A/*
1450N/A * Copyright 2000 VA Linux Systems, Inc., Fremont, California.
1450N/A * All Rights Reserved.
1450N/A *
1450N/A * Permission is hereby granted, free of charge, to any person obtaining a
1450N/A * copy of this software and associated documentation files (the "Software"),
1450N/A * to deal in the Software without restriction, including without limitation
1450N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1450N/A * and/or sell copies of the Software, and to permit persons to whom the
1450N/A * Software is furnished to do so, subject to the following conditions:
1450N/A *
1450N/A * The above copyright notice and this permission notice (including the next
1450N/A * paragraph) shall be included in all copies or substantial portions of the
1450N/A * Software.
1450N/A *
1450N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1450N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1450N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1450N/A * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
1450N/A * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1450N/A * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1450N/A * DEALINGS IN THE SOFTWARE.
1450N/A *
1450N/A * Authors:
1450N/A * Gareth Hughes <gareth@valinux.com>
1450N/A * Kevin E. Martin <martin@valinux.com>
1450N/A */
1450N/A
1450N/A#include "drmP.h"
1450N/A#include "drm.h"
1450N/A#include "drm_sarea.h"
1450N/A#include "radeon_drm.h"
1450N/A#include "radeon_drv.h"
1450N/A#include "radeon_io32.h"
1450N/A
1450N/A#include <sys/systm.h>
1450N/A
1450N/A/*
1450N/A * Helper functions for client state checking and fixup
1450N/A */
1450N/A
1450N/Astatic inline int
1450N/Aradeon_check_and_fixup_offset(drm_radeon_private_t *dev_priv,
1450N/A drm_file_t *filp_priv, u32 *offset)
1450N/A{
1450N/A u64 off = *offset;
1450N/A u32 fb_end = dev_priv->fb_location + dev_priv->fb_size - 1;
1450N/A struct drm_radeon_driver_file_fields *radeon_priv;
1450N/A
1450N/A /*
1450N/A * Hrm ... the story of the offset ... So this function converts
1450N/A * the various ideas of what userland clients might have for an
1450N/A * offset in the card address space into an offset into the card
1450N/A * address space :) So with a sane client, it should just keep
1450N/A * the value intact and just do some boundary checking. However,
1450N/A * not all clients are sane. Some older clients pass us 0 based
1450N/A * offsets relative to the start of the framebuffer and some may
1450N/A * assume the AGP aperture it appended to the framebuffer, so we
1450N/A * try to detect those cases and fix them up.
1450N/A *
1450N/A * Note: It might be a good idea here to make sure the offset lands
1450N/A * in some "allowed" area to protect things like the PCIE GART...
1450N/A */
1450N/A
1450N/A /*
1450N/A * First, the best case, the offset already lands in either the
1450N/A * framebuffer or the GART mapped space
1450N/A */
1450N/A
1450N/A if (radeon_check_offset(dev_priv, off))
1450N/A return (0);
1450N/A
1450N/A /*
1450N/A * Ok, that didn't happen... now check if we have a zero based
1450N/A * offset that fits in the framebuffer + gart space, apply the
1450N/A * magic offset we get from SETPARAM or calculated from fb_location
1450N/A */
1450N/A if (off < (dev_priv->fb_size + dev_priv->gart_size)) {
1450N/A radeon_priv = filp_priv->driver_priv;
1450N/A off += radeon_priv->radeon_fb_delta;
1450N/A }
1450N/A
1450N/A /* Finally, assume we aimed at a GART offset if beyond the fb */
1450N/A if (off > fb_end)
1450N/A off = off - fb_end - 1 + dev_priv->gart_vm_start;
1450N/A
1450N/A /* Now recheck and fail if out of bounds */
1450N/A if (radeon_check_offset(dev_priv, off)) {
1450N/A DRM_DEBUG("offset fixed up to 0x%x\n", (unsigned int)off);
1450N/A *offset = (uint32_t)off;
1450N/A return (0);
1450N/A }
1450N/A return (EINVAL);
1450N/A}
1450N/A
1450N/Astatic inline int
1450N/Aradeon_check_and_fixup_packets(drm_radeon_private_t *dev_priv,
1450N/A drm_file_t *filp_priv, int id, u32 *data)
1450N/A{
1450N/A switch (id) {
1450N/A
1450N/A case RADEON_EMIT_PP_MISC:
1450N/A if (radeon_check_and_fixup_offset(dev_priv, filp_priv,
1450N/A &data[(RADEON_RB3D_DEPTHOFFSET - RADEON_PP_MISC) / 4])) {
1450N/A DRM_ERROR("Invalid depth buffer offset\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A break;
1450N/A
1450N/A case RADEON_EMIT_PP_CNTL:
1450N/A if (radeon_check_and_fixup_offset(dev_priv, filp_priv,
1450N/A &data[(RADEON_RB3D_COLOROFFSET - RADEON_PP_CNTL) / 4])) {
1450N/A DRM_ERROR("Invalid colour buffer offset\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A break;
1450N/A
1450N/A case R200_EMIT_PP_TXOFFSET_0:
1450N/A case R200_EMIT_PP_TXOFFSET_1:
1450N/A case R200_EMIT_PP_TXOFFSET_2:
1450N/A case R200_EMIT_PP_TXOFFSET_3:
1450N/A case R200_EMIT_PP_TXOFFSET_4:
1450N/A case R200_EMIT_PP_TXOFFSET_5:
1450N/A if (radeon_check_and_fixup_offset(dev_priv, filp_priv,
1450N/A &data[0])) {
1450N/A DRM_ERROR("Invalid R200 texture offset\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A break;
1450N/A
1450N/A case RADEON_EMIT_PP_TXFILTER_0:
1450N/A case RADEON_EMIT_PP_TXFILTER_1:
1450N/A case RADEON_EMIT_PP_TXFILTER_2:
1450N/A if (radeon_check_and_fixup_offset(dev_priv, filp_priv,
1450N/A &data[(RADEON_PP_TXOFFSET_0 - RADEON_PP_TXFILTER_0) / 4])) {
1450N/A DRM_ERROR("Invalid R100 texture offset\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A break;
1450N/A
1450N/A case R200_EMIT_PP_CUBIC_OFFSETS_0:
1450N/A case R200_EMIT_PP_CUBIC_OFFSETS_1:
1450N/A case R200_EMIT_PP_CUBIC_OFFSETS_2:
1450N/A case R200_EMIT_PP_CUBIC_OFFSETS_3:
1450N/A case R200_EMIT_PP_CUBIC_OFFSETS_4:
1450N/A case R200_EMIT_PP_CUBIC_OFFSETS_5: {
1450N/A int i;
1450N/A for (i = 0; i < 5; i++) {
1450N/A if (radeon_check_and_fixup_offset(dev_priv,
1450N/A filp_priv, &data[i])) {
1450N/A DRM_ERROR("Invalid R200 cubic"
1450N/A " texture offset\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A }
1450N/A break;
1450N/A }
1450N/A
1450N/A case RADEON_EMIT_PP_CUBIC_OFFSETS_T0:
1450N/A case RADEON_EMIT_PP_CUBIC_OFFSETS_T1:
1450N/A case RADEON_EMIT_PP_CUBIC_OFFSETS_T2:
1450N/A {
1450N/A int i;
1450N/A for (i = 0; i < 5; i++) {
1450N/A if (radeon_check_and_fixup_offset(dev_priv,
1450N/A filp_priv, &data[i])) {
1450N/A DRM_ERROR("Invalid R100 cubic"
1450N/A " texture offset\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A }
1450N/A }
1450N/A break;
1450N/A
1450N/A case R200_EMIT_VAP_CTL:
1450N/A {
1450N/A RING_LOCALS;
1450N/A BEGIN_RING(2);
1450N/A OUT_RING_REG(RADEON_SE_TCL_STATE_FLUSH, 0);
1450N/A ADVANCE_RING();
1450N/A }
1450N/A break;
1450N/A
1450N/A case RADEON_EMIT_RB3D_COLORPITCH:
1450N/A case RADEON_EMIT_RE_LINE_PATTERN:
1450N/A case RADEON_EMIT_SE_LINE_WIDTH:
1450N/A case RADEON_EMIT_PP_LUM_MATRIX:
1450N/A case RADEON_EMIT_PP_ROT_MATRIX_0:
1450N/A case RADEON_EMIT_RB3D_STENCILREFMASK:
1450N/A case RADEON_EMIT_SE_VPORT_XSCALE:
1450N/A case RADEON_EMIT_SE_CNTL:
1450N/A case RADEON_EMIT_SE_CNTL_STATUS:
1450N/A case RADEON_EMIT_RE_MISC:
1450N/A case RADEON_EMIT_PP_BORDER_COLOR_0:
1450N/A case RADEON_EMIT_PP_BORDER_COLOR_1:
1450N/A case RADEON_EMIT_PP_BORDER_COLOR_2:
1450N/A case RADEON_EMIT_SE_ZBIAS_FACTOR:
1450N/A case RADEON_EMIT_SE_TCL_OUTPUT_VTX_FMT:
1450N/A case RADEON_EMIT_SE_TCL_MATERIAL_EMMISSIVE_RED:
1450N/A case R200_EMIT_PP_TXCBLEND_0:
1450N/A case R200_EMIT_PP_TXCBLEND_1:
1450N/A case R200_EMIT_PP_TXCBLEND_2:
1450N/A case R200_EMIT_PP_TXCBLEND_3:
1450N/A case R200_EMIT_PP_TXCBLEND_4:
1450N/A case R200_EMIT_PP_TXCBLEND_5:
1450N/A case R200_EMIT_PP_TXCBLEND_6:
1450N/A case R200_EMIT_PP_TXCBLEND_7:
1450N/A case R200_EMIT_TCL_LIGHT_MODEL_CTL_0:
1450N/A case R200_EMIT_TFACTOR_0:
1450N/A case R200_EMIT_VTX_FMT_0:
1450N/A case R200_EMIT_MATRIX_SELECT_0:
1450N/A case R200_EMIT_TEX_PROC_CTL_2:
1450N/A case R200_EMIT_TCL_UCP_VERT_BLEND_CTL:
1450N/A case R200_EMIT_PP_TXFILTER_0:
1450N/A case R200_EMIT_PP_TXFILTER_1:
1450N/A case R200_EMIT_PP_TXFILTER_2:
1450N/A case R200_EMIT_PP_TXFILTER_3:
1450N/A case R200_EMIT_PP_TXFILTER_4:
1450N/A case R200_EMIT_PP_TXFILTER_5:
1450N/A case R200_EMIT_VTE_CNTL:
1450N/A case R200_EMIT_OUTPUT_VTX_COMP_SEL:
1450N/A case R200_EMIT_PP_TAM_DEBUG3:
1450N/A case R200_EMIT_PP_CNTL_X:
1450N/A case R200_EMIT_RB3D_DEPTHXY_OFFSET:
1450N/A case R200_EMIT_RE_AUX_SCISSOR_CNTL:
1450N/A case R200_EMIT_RE_SCISSOR_TL_0:
1450N/A case R200_EMIT_RE_SCISSOR_TL_1:
1450N/A case R200_EMIT_RE_SCISSOR_TL_2:
1450N/A case R200_EMIT_SE_VAP_CNTL_STATUS:
1450N/A case R200_EMIT_SE_VTX_STATE_CNTL:
1450N/A case R200_EMIT_RE_POINTSIZE:
1450N/A case R200_EMIT_TCL_INPUT_VTX_VECTOR_ADDR_0:
1450N/A case R200_EMIT_PP_CUBIC_FACES_0:
1450N/A case R200_EMIT_PP_CUBIC_FACES_1:
1450N/A case R200_EMIT_PP_CUBIC_FACES_2:
1450N/A case R200_EMIT_PP_CUBIC_FACES_3:
1450N/A case R200_EMIT_PP_CUBIC_FACES_4:
1450N/A case R200_EMIT_PP_CUBIC_FACES_5:
1450N/A case RADEON_EMIT_PP_TEX_SIZE_0:
1450N/A case RADEON_EMIT_PP_TEX_SIZE_1:
1450N/A case RADEON_EMIT_PP_TEX_SIZE_2:
1450N/A case R200_EMIT_RB3D_BLENDCOLOR:
1450N/A case R200_EMIT_TCL_POINT_SPRITE_CNTL:
1450N/A case RADEON_EMIT_PP_CUBIC_FACES_0:
1450N/A case RADEON_EMIT_PP_CUBIC_FACES_1:
1450N/A case RADEON_EMIT_PP_CUBIC_FACES_2:
1450N/A case R200_EMIT_PP_TRI_PERF_CNTL:
1450N/A case R200_EMIT_PP_AFS_0:
1450N/A case R200_EMIT_PP_AFS_1:
1450N/A case R200_EMIT_ATF_TFACTOR:
1450N/A case R200_EMIT_PP_TXCTLALL_0:
1450N/A case R200_EMIT_PP_TXCTLALL_1:
1450N/A case R200_EMIT_PP_TXCTLALL_2:
1450N/A case R200_EMIT_PP_TXCTLALL_3:
1450N/A case R200_EMIT_PP_TXCTLALL_4:
1450N/A case R200_EMIT_PP_TXCTLALL_5:
1450N/A case R200_EMIT_VAP_PVS_CNTL:
1450N/A /* These packets don't contain memory offsets */
1450N/A break;
1450N/A
1450N/A default:
1450N/A DRM_ERROR("Unknown state packet ID %d\n", id);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A return (0);
1450N/A}
1450N/A
1450N/Astatic inline int
1450N/Aradeon_check_and_fixup_packet3(drm_radeon_private_t *dev_priv,
1450N/A drm_file_t *filp_priv, drm_radeon_kcmd_buffer_t *cmdbuf,
1450N/A unsigned int *cmdsz)
1450N/A{
1450N/A u32 *cmd = (u32 *)(uintptr_t)cmdbuf->buf;
1450N/A u32 offset, narrays;
1450N/A int count, i, k;
1450N/A
1450N/A *cmdsz = 2 + ((cmd[0] & RADEON_CP_PACKET_COUNT_MASK) >> 16);
1450N/A
1450N/A if ((cmd[0] & 0xc0000000) != RADEON_CP_PACKET3) {
1450N/A DRM_ERROR("Not a type 3 packet\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A if (4 * *cmdsz > cmdbuf->bufsz) {
1450N/A DRM_ERROR("Packet size larger than size of data provided\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A
1450N/A switch (cmd[0] & 0xff00) {
1450N/A /* XXX Are there old drivers needing other packets? */
1450N/A
1450N/A case RADEON_3D_DRAW_IMMD:
1450N/A case RADEON_3D_DRAW_VBUF:
1450N/A case RADEON_3D_DRAW_INDX:
1450N/A case RADEON_WAIT_FOR_IDLE:
1450N/A case RADEON_CP_NOP:
1450N/A case RADEON_3D_CLEAR_ZMASK:
1450N/A#if 0
1450N/A case RADEON_CP_NEXT_CHAR:
1450N/A case RADEON_CP_PLY_NEXTSCAN:
1450N/A case RADEON_CP_SET_SCISSORS:
1450N/A /* probably safe but will never need them? */
1450N/A#endif
1450N/A/* these packets are safe */
1450N/A break;
1450N/A
1450N/A case RADEON_CP_3D_DRAW_IMMD_2:
1450N/A case RADEON_CP_3D_DRAW_VBUF_2:
1450N/A case RADEON_CP_3D_DRAW_INDX_2:
1450N/A case RADEON_3D_CLEAR_HIZ:
1450N/A /* safe but r200 only */
1450N/A if (dev_priv->microcode_version != UCODE_R200) {
1450N/A DRM_ERROR("Invalid 3d packet for r100-class chip\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A break;
1450N/A
1450N/A case RADEON_3D_LOAD_VBPNTR:
1450N/A count = (cmd[0] >> 16) & 0x3fff;
1450N/A
1450N/A if (count > 18) { /* 12 arrays max */
1450N/A DRM_ERROR(
1450N/A "Too large payload in 3D_LOAD_VBPNTR (count=%d)\n",
1450N/A count);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A /* carefully check packet contents */
1450N/A narrays = cmd[1] & ~0xc000;
1450N/A k = 0;
1450N/A i = 2;
1450N/A while ((k < narrays) && (i < (count + 2))) {
1450N/A i++; /* skip attribute field */
1450N/A if (radeon_check_and_fixup_offset(dev_priv,
1450N/A filp_priv, &cmd[i])) {
1450N/A DRM_ERROR(
1450N/A "Invalid offset (k=%d i=%d) ini"
1450N/A " 3D_LOAD_VBPNTR packet.\n", k, i);
1450N/A return (EINVAL);
1450N/A }
1450N/A k++;
1450N/A i++;
1450N/A if (k == narrays)
1450N/A break;
1450N/A /* have one more to process, they come in pairs */
1450N/A if (radeon_check_and_fixup_offset(dev_priv,
1450N/A filp_priv, &cmd[i])) {
1450N/A DRM_ERROR(
1450N/A "Invalid offset (k=%d i=%d) in"
1450N/A " 3D_LOAD_VBPNTR packet.\n", k, i);
1450N/A return (EINVAL);
1450N/A }
1450N/A k++;
1450N/A i++;
1450N/A }
1450N/A /* do the counts match what we expect ? */
1450N/A if ((k != narrays) || (i != (count + 2))) {
1450N/A DRM_ERROR(
1450N/A "Malformed 3D_LOAD_VBPNTR packet"
1450N/A "(k=%d i=%d narrays=%d count+1=%d).\n",
1450N/A k, i, narrays, count + 1);
1450N/A return (EINVAL);
1450N/A }
1450N/A break;
1450N/A
1450N/A case RADEON_3D_RNDR_GEN_INDX_PRIM:
1450N/A if (dev_priv->microcode_version != UCODE_R100) {
1450N/A DRM_ERROR("Invalid 3d packet for r200-class chip\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A if (radeon_check_and_fixup_offset(dev_priv,
1450N/A filp_priv, &cmd[1])) {
1450N/A DRM_ERROR("Invalid rndr_gen_indx offset\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A break;
1450N/A
1450N/A case RADEON_CP_INDX_BUFFER:
1450N/A if (dev_priv->microcode_version != UCODE_R200) {
1450N/A DRM_ERROR("Invalid 3d packet for r100-class chip\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A if ((cmd[1] & 0x8000ffff) != 0x80000810) {
1450N/A DRM_ERROR(
1450N/A "Invalid indx_buffer reg address %08X\n", cmd[1]);
1450N/A return (EINVAL);
1450N/A }
1450N/A if (radeon_check_and_fixup_offset(dev_priv,
1450N/A filp_priv, &cmd[2])) {
1450N/A DRM_ERROR(
1450N/A "Invalid indx_buffer offset is %08X\n", cmd[2]);
1450N/A return (EINVAL);
1450N/A }
1450N/A break;
1450N/A
1450N/A case RADEON_CNTL_HOSTDATA_BLT:
1450N/A case RADEON_CNTL_PAINT_MULTI:
1450N/A case RADEON_CNTL_BITBLT_MULTI:
1450N/A /* MSB of opcode: next DWORD GUI_CNTL */
1450N/A if (cmd[1] & (RADEON_GMC_SRC_PITCH_OFFSET_CNTL |
1450N/A RADEON_GMC_DST_PITCH_OFFSET_CNTL)) {
1450N/A offset = cmd[2] << 10;
1450N/A if (radeon_check_and_fixup_offset
1450N/A (dev_priv, filp_priv, &offset)) {
1450N/A DRM_ERROR("Invalid first packet offset\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A cmd[2] = (cmd[2] & 0xffc00000) | offset >> 10;
1450N/A }
1450N/A
1450N/A if ((cmd[1] & RADEON_GMC_SRC_PITCH_OFFSET_CNTL) &&
1450N/A (cmd[1] & RADEON_GMC_DST_PITCH_OFFSET_CNTL)) {
1450N/A offset = cmd[3] << 10;
1450N/A if (radeon_check_and_fixup_offset
1450N/A (dev_priv, filp_priv, &offset)) {
1450N/A DRM_ERROR("Invalid second packet offset\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A cmd[3] = (cmd[3] & 0xffc00000) | offset >> 10;
1450N/A }
1450N/A break;
1450N/A
1450N/A default:
1450N/A DRM_ERROR("Invalid packet type %x\n", cmd[0] & 0xff00);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A return (0);
1450N/A}
1450N/A
1450N/A/*
1450N/A * CP hardware state programming functions
1450N/A */
1450N/A
1450N/Astatic inline void radeon_emit_clip_rect(drm_radeon_private_t *dev_priv,
1450N/A drm_clip_rect_t *box)
1450N/A{
1450N/A RING_LOCALS;
1450N/A
1450N/A DRM_DEBUG(" box: x1=%d y1=%d x2=%d y2=%d\n",
1450N/A box->x1, box->y1, box->x2, box->y2);
1450N/A
1450N/A BEGIN_RING(4);
1450N/A OUT_RING(CP_PACKET0(RADEON_RE_TOP_LEFT, 0));
1450N/A OUT_RING((box->y1 << 16) | box->x1);
1450N/A OUT_RING(CP_PACKET0(RADEON_RE_WIDTH_HEIGHT, 0));
1450N/A OUT_RING(((box->y2 - 1) << 16) | (box->x2 - 1));
1450N/A ADVANCE_RING();
1450N/A}
1450N/A
1450N/A/* Emit 1.1 state */
1450N/Astatic int radeon_emit_state(drm_radeon_private_t *dev_priv,
1450N/A drm_file_t *filp_priv, drm_radeon_context_regs_t *ctx,
1450N/A drm_radeon_texture_regs_t *tex, unsigned int dirty)
1450N/A{
1450N/A RING_LOCALS;
1450N/A DRM_DEBUG("dirty=0x%08x\n", dirty);
1450N/A
1450N/A if (dirty & RADEON_UPLOAD_CONTEXT) {
1450N/A if (radeon_check_and_fixup_offset(dev_priv, filp_priv,
1450N/A &ctx->rb3d_depthoffset)) {
1450N/A DRM_ERROR("Invalid depth buffer offset\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A if (radeon_check_and_fixup_offset(dev_priv, filp_priv,
1450N/A &ctx->rb3d_coloroffset)) {
1450N/A DRM_ERROR("Invalid depth buffer offset\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A BEGIN_RING(14);
1450N/A OUT_RING(CP_PACKET0(RADEON_PP_MISC, 6));
1450N/A OUT_RING(ctx->pp_misc);
1450N/A OUT_RING(ctx->pp_fog_color);
1450N/A OUT_RING(ctx->re_solid_color);
1450N/A OUT_RING(ctx->rb3d_blendcntl);
1450N/A OUT_RING(ctx->rb3d_depthoffset);
1450N/A OUT_RING(ctx->rb3d_depthpitch);
1450N/A OUT_RING(ctx->rb3d_zstencilcntl);
1450N/A OUT_RING(CP_PACKET0(RADEON_PP_CNTL, 2));
1450N/A OUT_RING(ctx->pp_cntl);
1450N/A OUT_RING(ctx->rb3d_cntl);
1450N/A OUT_RING(ctx->rb3d_coloroffset);
1450N/A OUT_RING(CP_PACKET0(RADEON_RB3D_COLORPITCH, 0));
1450N/A OUT_RING(ctx->rb3d_colorpitch);
1450N/A ADVANCE_RING();
1450N/A }
1450N/A
1450N/A if (dirty & RADEON_UPLOAD_VERTFMT) {
1450N/A BEGIN_RING(2);
1450N/A OUT_RING(CP_PACKET0(RADEON_SE_COORD_FMT, 0));
1450N/A OUT_RING(ctx->se_coord_fmt);
1450N/A ADVANCE_RING();
1450N/A }
1450N/A
1450N/A if (dirty & RADEON_UPLOAD_LINE) {
1450N/A BEGIN_RING(5);
1450N/A OUT_RING(CP_PACKET0(RADEON_RE_LINE_PATTERN, 1));
1450N/A OUT_RING(ctx->re_line_pattern);
1450N/A OUT_RING(ctx->re_line_state);
1450N/A OUT_RING(CP_PACKET0(RADEON_SE_LINE_WIDTH, 0));
1450N/A OUT_RING(ctx->se_line_width);
1450N/A ADVANCE_RING();
1450N/A }
1450N/A
1450N/A if (dirty & RADEON_UPLOAD_BUMPMAP) {
1450N/A BEGIN_RING(5);
1450N/A OUT_RING(CP_PACKET0(RADEON_PP_LUM_MATRIX, 0));
1450N/A OUT_RING(ctx->pp_lum_matrix);
1450N/A OUT_RING(CP_PACKET0(RADEON_PP_ROT_MATRIX_0, 1));
1450N/A OUT_RING(ctx->pp_rot_matrix_0);
1450N/A OUT_RING(ctx->pp_rot_matrix_1);
1450N/A ADVANCE_RING();
1450N/A }
1450N/A
1450N/A if (dirty & RADEON_UPLOAD_MASKS) {
1450N/A BEGIN_RING(4);
1450N/A OUT_RING(CP_PACKET0(RADEON_RB3D_STENCILREFMASK, 2));
1450N/A OUT_RING(ctx->rb3d_stencilrefmask);
1450N/A OUT_RING(ctx->rb3d_ropcntl);
1450N/A OUT_RING(ctx->rb3d_planemask);
1450N/A ADVANCE_RING();
1450N/A }
1450N/A
1450N/A if (dirty & RADEON_UPLOAD_VIEWPORT) {
1450N/A BEGIN_RING(7);
1450N/A OUT_RING(CP_PACKET0(RADEON_SE_VPORT_XSCALE, 5));
1450N/A OUT_RING(ctx->se_vport_xscale);
1450N/A OUT_RING(ctx->se_vport_xoffset);
1450N/A OUT_RING(ctx->se_vport_yscale);
1450N/A OUT_RING(ctx->se_vport_yoffset);
1450N/A OUT_RING(ctx->se_vport_zscale);
1450N/A OUT_RING(ctx->se_vport_zoffset);
1450N/A ADVANCE_RING();
1450N/A }
1450N/A
1450N/A if (dirty & RADEON_UPLOAD_SETUP) {
1450N/A BEGIN_RING(4);
1450N/A OUT_RING(CP_PACKET0(RADEON_SE_CNTL, 0));
1450N/A OUT_RING(ctx->se_cntl);
1450N/A OUT_RING(CP_PACKET0(RADEON_SE_CNTL_STATUS, 0));
1450N/A OUT_RING(ctx->se_cntl_status);
1450N/A ADVANCE_RING();
1450N/A }
1450N/A
1450N/A if (dirty & RADEON_UPLOAD_MISC) {
1450N/A BEGIN_RING(2);
1450N/A OUT_RING(CP_PACKET0(RADEON_RE_MISC, 0));
1450N/A OUT_RING(ctx->re_misc);
1450N/A ADVANCE_RING();
1450N/A }
1450N/A
1450N/A if (dirty & RADEON_UPLOAD_TEX0) {
1450N/A if (radeon_check_and_fixup_offset(dev_priv,
1450N/A filp_priv, &tex[0].pp_txoffset)) {
1450N/A DRM_ERROR("Invalid texture offset for unit 0\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A BEGIN_RING(9);
1450N/A OUT_RING(CP_PACKET0(RADEON_PP_TXFILTER_0, 5));
1450N/A OUT_RING(tex[0].pp_txfilter);
1450N/A OUT_RING(tex[0].pp_txformat);
1450N/A OUT_RING(tex[0].pp_txoffset);
1450N/A OUT_RING(tex[0].pp_txcblend);
1450N/A OUT_RING(tex[0].pp_txablend);
1450N/A OUT_RING(tex[0].pp_tfactor);
1450N/A OUT_RING(CP_PACKET0(RADEON_PP_BORDER_COLOR_0, 0));
1450N/A OUT_RING(tex[0].pp_border_color);
1450N/A ADVANCE_RING();
1450N/A }
1450N/A
1450N/A if (dirty & RADEON_UPLOAD_TEX1) {
1450N/A if (radeon_check_and_fixup_offset(dev_priv,
1450N/A filp_priv, &tex[1].pp_txoffset)) {
1450N/A DRM_ERROR("Invalid texture offset for unit 1\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A BEGIN_RING(9);
1450N/A OUT_RING(CP_PACKET0(RADEON_PP_TXFILTER_1, 5));
1450N/A OUT_RING(tex[1].pp_txfilter);
1450N/A OUT_RING(tex[1].pp_txformat);
1450N/A OUT_RING(tex[1].pp_txoffset);
1450N/A OUT_RING(tex[1].pp_txcblend);
1450N/A OUT_RING(tex[1].pp_txablend);
1450N/A OUT_RING(tex[1].pp_tfactor);
1450N/A OUT_RING(CP_PACKET0(RADEON_PP_BORDER_COLOR_1, 0));
1450N/A OUT_RING(tex[1].pp_border_color);
1450N/A ADVANCE_RING();
1450N/A }
1450N/A
1450N/A if (dirty & RADEON_UPLOAD_TEX2) {
1450N/A if (radeon_check_and_fixup_offset(dev_priv,
1450N/A filp_priv, &tex[2].pp_txoffset)) {
1450N/A DRM_ERROR("Invalid texture offset for unit 2\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A BEGIN_RING(9);
1450N/A OUT_RING(CP_PACKET0(RADEON_PP_TXFILTER_2, 5));
1450N/A OUT_RING(tex[2].pp_txfilter);
1450N/A OUT_RING(tex[2].pp_txformat);
1450N/A OUT_RING(tex[2].pp_txoffset);
1450N/A OUT_RING(tex[2].pp_txcblend);
1450N/A OUT_RING(tex[2].pp_txablend);
1450N/A OUT_RING(tex[2].pp_tfactor);
1450N/A OUT_RING(CP_PACKET0(RADEON_PP_BORDER_COLOR_2, 0));
1450N/A OUT_RING(tex[2].pp_border_color);
1450N/A ADVANCE_RING();
1450N/A }
1450N/A
1450N/A return (0);
1450N/A}
1450N/A
1450N/A/* Emit 1.2 state */
1450N/Astatic int radeon_emit_state2(drm_radeon_private_t *dev_priv,
1450N/A drm_file_t *filp_priv, drm_radeon_state_t *state)
1450N/A{
1450N/A RING_LOCALS;
1450N/A
1450N/A if (state->dirty & RADEON_UPLOAD_ZBIAS) {
1450N/A BEGIN_RING(3);
1450N/A OUT_RING(CP_PACKET0(RADEON_SE_ZBIAS_FACTOR, 1));
1450N/A OUT_RING(state->context2.se_zbias_factor);
1450N/A OUT_RING(state->context2.se_zbias_constant);
1450N/A ADVANCE_RING();
1450N/A }
1450N/A
1450N/A return (radeon_emit_state(dev_priv, filp_priv,
1450N/A &state->context, state->tex, state->dirty));
1450N/A}
1450N/A
1450N/A/*
1450N/A * New (1.3) state mechanism. 3 commands (packet, scalar, vector) in
1450N/A * 1.3 cmdbuffers allow all previous state to be updated as well as
1450N/A * the tcl scalar and vector areas.
1450N/A */
1450N/Astatic const struct {
1450N/A int start;
1450N/A int len;
1450N/A const char *name;
1450N/A} packet[RADEON_MAX_STATE_PACKETS] = {
1450N/A {RADEON_PP_MISC, 7, "RADEON_PP_MISC"},
1450N/A {RADEON_PP_CNTL, 3, "RADEON_PP_CNTL"},
1450N/A {RADEON_RB3D_COLORPITCH, 1, "RADEON_RB3D_COLORPITCH"},
1450N/A {RADEON_RE_LINE_PATTERN, 2, "RADEON_RE_LINE_PATTERN"},
1450N/A {RADEON_SE_LINE_WIDTH, 1, "RADEON_SE_LINE_WIDTH"},
1450N/A {RADEON_PP_LUM_MATRIX, 1, "RADEON_PP_LUM_MATRIX"},
1450N/A {RADEON_PP_ROT_MATRIX_0, 2, "RADEON_PP_ROT_MATRIX_0"},
1450N/A {RADEON_RB3D_STENCILREFMASK, 3, "RADEON_RB3D_STENCILREFMASK"},
1450N/A {RADEON_SE_VPORT_XSCALE, 6, "RADEON_SE_VPORT_XSCALE"},
1450N/A {RADEON_SE_CNTL, 2, "RADEON_SE_CNTL"},
1450N/A {RADEON_SE_CNTL_STATUS, 1, "RADEON_SE_CNTL_STATUS"},
1450N/A {RADEON_RE_MISC, 1, "RADEON_RE_MISC"},
1450N/A {RADEON_PP_TXFILTER_0, 6, "RADEON_PP_TXFILTER_0"},
1450N/A {RADEON_PP_BORDER_COLOR_0, 1, "RADEON_PP_BORDER_COLOR_0"},
1450N/A {RADEON_PP_TXFILTER_1, 6, "RADEON_PP_TXFILTER_1"},
1450N/A {RADEON_PP_BORDER_COLOR_1, 1, "RADEON_PP_BORDER_COLOR_1"},
1450N/A {RADEON_PP_TXFILTER_2, 6, "RADEON_PP_TXFILTER_2"},
1450N/A {RADEON_PP_BORDER_COLOR_2, 1, "RADEON_PP_BORDER_COLOR_2"},
1450N/A {RADEON_SE_ZBIAS_FACTOR, 2, "RADEON_SE_ZBIAS_FACTOR"},
1450N/A {RADEON_SE_TCL_OUTPUT_VTX_FMT, 11, "RADEON_SE_TCL_OUTPUT_VTX_FMT"},
1450N/A {RADEON_SE_TCL_MATERIAL_EMMISSIVE_RED, 17,
1450N/A "RADEON_SE_TCL_MATERIAL_EMMISSIVE_RED"},
1450N/A {R200_PP_TXCBLEND_0, 4, "R200_PP_TXCBLEND_0"},
1450N/A {R200_PP_TXCBLEND_1, 4, "R200_PP_TXCBLEND_1"},
1450N/A {R200_PP_TXCBLEND_2, 4, "R200_PP_TXCBLEND_2"},
1450N/A {R200_PP_TXCBLEND_3, 4, "R200_PP_TXCBLEND_3"},
1450N/A {R200_PP_TXCBLEND_4, 4, "R200_PP_TXCBLEND_4"},
1450N/A {R200_PP_TXCBLEND_5, 4, "R200_PP_TXCBLEND_5"},
1450N/A {R200_PP_TXCBLEND_6, 4, "R200_PP_TXCBLEND_6"},
1450N/A {R200_PP_TXCBLEND_7, 4, "R200_PP_TXCBLEND_7"},
1450N/A {R200_SE_TCL_LIGHT_MODEL_CTL_0, 6, "R200_SE_TCL_LIGHT_MODEL_CTL_0"},
1450N/A {R200_PP_TFACTOR_0, 6, "R200_PP_TFACTOR_0"},
1450N/A {R200_SE_VTX_FMT_0, 4, "R200_SE_VTX_FMT_0"},
1450N/A {R200_SE_VAP_CNTL, 1, "R200_SE_VAP_CNTL"},
1450N/A {R200_SE_TCL_MATRIX_SEL_0, 5, "R200_SE_TCL_MATRIX_SEL_0"},
1450N/A {R200_SE_TCL_TEX_PROC_CTL_2, 5, "R200_SE_TCL_TEX_PROC_CTL_2"},
1450N/A {R200_SE_TCL_UCP_VERT_BLEND_CTL, 1, "R200_SE_TCL_UCP_VERT_BLEND_CTL"},
1450N/A {R200_PP_TXFILTER_0, 6, "R200_PP_TXFILTER_0"},
1450N/A {R200_PP_TXFILTER_1, 6, "R200_PP_TXFILTER_1"},
1450N/A {R200_PP_TXFILTER_2, 6, "R200_PP_TXFILTER_2"},
1450N/A {R200_PP_TXFILTER_3, 6, "R200_PP_TXFILTER_3"},
1450N/A {R200_PP_TXFILTER_4, 6, "R200_PP_TXFILTER_4"},
1450N/A {R200_PP_TXFILTER_5, 6, "R200_PP_TXFILTER_5"},
1450N/A {R200_PP_TXOFFSET_0, 1, "R200_PP_TXOFFSET_0"},
1450N/A {R200_PP_TXOFFSET_1, 1, "R200_PP_TXOFFSET_1"},
1450N/A {R200_PP_TXOFFSET_2, 1, "R200_PP_TXOFFSET_2"},
1450N/A {R200_PP_TXOFFSET_3, 1, "R200_PP_TXOFFSET_3"},
1450N/A {R200_PP_TXOFFSET_4, 1, "R200_PP_TXOFFSET_4"},
1450N/A {R200_PP_TXOFFSET_5, 1, "R200_PP_TXOFFSET_5"},
1450N/A {R200_SE_VTE_CNTL, 1, "R200_SE_VTE_CNTL"},
1450N/A {R200_SE_TCL_OUTPUT_VTX_COMP_SEL, 1,
1450N/A "R200_SE_TCL_OUTPUT_VTX_COMP_SEL"},
1450N/A {R200_PP_TAM_DEBUG3, 1, "R200_PP_TAM_DEBUG3"},
1450N/A {R200_PP_CNTL_X, 1, "R200_PP_CNTL_X"},
1450N/A {R200_RB3D_DEPTHXY_OFFSET, 1, "R200_RB3D_DEPTHXY_OFFSET"},
1450N/A {R200_RE_AUX_SCISSOR_CNTL, 1, "R200_RE_AUX_SCISSOR_CNTL"},
1450N/A {R200_RE_SCISSOR_TL_0, 2, "R200_RE_SCISSOR_TL_0"},
1450N/A {R200_RE_SCISSOR_TL_1, 2, "R200_RE_SCISSOR_TL_1"},
1450N/A {R200_RE_SCISSOR_TL_2, 2, "R200_RE_SCISSOR_TL_2"},
1450N/A {R200_SE_VAP_CNTL_STATUS, 1, "R200_SE_VAP_CNTL_STATUS"},
1450N/A {R200_SE_VTX_STATE_CNTL, 1, "R200_SE_VTX_STATE_CNTL"},
1450N/A {R200_RE_POINTSIZE, 1, "R200_RE_POINTSIZE"},
1450N/A {R200_SE_TCL_INPUT_VTX_VECTOR_ADDR_0, 4,
1450N/A "R200_SE_TCL_INPUT_VTX_VECTOR_ADDR_0"},
1450N/A {R200_PP_CUBIC_FACES_0, 1, "R200_PP_CUBIC_FACES_0"}, /* 61 */
1450N/A {R200_PP_CUBIC_OFFSET_F1_0, 5, "R200_PP_CUBIC_OFFSET_F1_0"}, /* 62 */
1450N/A {R200_PP_CUBIC_FACES_1, 1, "R200_PP_CUBIC_FACES_1"},
1450N/A {R200_PP_CUBIC_OFFSET_F1_1, 5, "R200_PP_CUBIC_OFFSET_F1_1"},
1450N/A {R200_PP_CUBIC_FACES_2, 1, "R200_PP_CUBIC_FACES_2"},
1450N/A {R200_PP_CUBIC_OFFSET_F1_2, 5, "R200_PP_CUBIC_OFFSET_F1_2"},
1450N/A {R200_PP_CUBIC_FACES_3, 1, "R200_PP_CUBIC_FACES_3"},
1450N/A {R200_PP_CUBIC_OFFSET_F1_3, 5, "R200_PP_CUBIC_OFFSET_F1_3"},
1450N/A {R200_PP_CUBIC_FACES_4, 1, "R200_PP_CUBIC_FACES_4"},
1450N/A {R200_PP_CUBIC_OFFSET_F1_4, 5, "R200_PP_CUBIC_OFFSET_F1_4"},
1450N/A {R200_PP_CUBIC_FACES_5, 1, "R200_PP_CUBIC_FACES_5"},
1450N/A {R200_PP_CUBIC_OFFSET_F1_5, 5, "R200_PP_CUBIC_OFFSET_F1_5"},
1450N/A {RADEON_PP_TEX_SIZE_0, 2, "RADEON_PP_TEX_SIZE_0"},
1450N/A {RADEON_PP_TEX_SIZE_1, 2, "RADEON_PP_TEX_SIZE_1"},
1450N/A {RADEON_PP_TEX_SIZE_2, 2, "RADEON_PP_TEX_SIZE_2"},
1450N/A {R200_RB3D_BLENDCOLOR, 3, "R200_RB3D_BLENDCOLOR"},
1450N/A {R200_SE_TCL_POINT_SPRITE_CNTL, 1, "R200_SE_TCL_POINT_SPRITE_CNTL"},
1450N/A {RADEON_PP_CUBIC_FACES_0, 1, "RADEON_PP_CUBIC_FACES_0"},
1450N/A {RADEON_PP_CUBIC_OFFSET_T0_0, 5, "RADEON_PP_CUBIC_OFFSET_T0_0"},
1450N/A {RADEON_PP_CUBIC_FACES_1, 1, "RADEON_PP_CUBIC_FACES_1"},
1450N/A {RADEON_PP_CUBIC_OFFSET_T1_0, 5, "RADEON_PP_CUBIC_OFFSET_T1_0"},
1450N/A {RADEON_PP_CUBIC_FACES_2, 1, "RADEON_PP_CUBIC_FACES_2"},
1450N/A {RADEON_PP_CUBIC_OFFSET_T2_0, 5, "RADEON_PP_CUBIC_OFFSET_T2_0"},
1450N/A {R200_PP_TRI_PERF, 2, "R200_PP_TRI_PERF"},
1450N/A {R200_PP_AFS_0, 32, "R200_PP_AFS_0"}, /* 85 */
1450N/A {R200_PP_AFS_1, 32, "R200_PP_AFS_1"},
1450N/A {R200_PP_TFACTOR_0, 8, "R200_ATF_TFACTOR"},
1450N/A {R200_PP_TXFILTER_0, 8, "R200_PP_TXCTLALL_0"},
1450N/A {R200_PP_TXFILTER_1, 8, "R200_PP_TXCTLALL_1"},
1450N/A {R200_PP_TXFILTER_2, 8, "R200_PP_TXCTLALL_2"},
1450N/A {R200_PP_TXFILTER_3, 8, "R200_PP_TXCTLALL_3"},
1450N/A {R200_PP_TXFILTER_4, 8, "R200_PP_TXCTLALL_4"},
1450N/A {R200_PP_TXFILTER_5, 8, "R200_PP_TXCTLALL_5"},
1450N/A {R200_VAP_PVS_CNTL_1, 2, "R200_VAP_PVS_CNTL"},
1450N/A};
1450N/A
1450N/A/*
1450N/A * Performance monitoring functions
1450N/A */
1450N/A
1450N/Astatic void radeon_clear_box(drm_radeon_private_t *dev_priv,
1450N/A int x, int y, int w, int h, int r, int g, int b)
1450N/A{
1450N/A u32 color;
1450N/A RING_LOCALS;
1450N/A
1450N/A x += dev_priv->sarea_priv->boxes[0].x1;
1450N/A y += dev_priv->sarea_priv->boxes[0].y1;
1450N/A
1450N/A switch (dev_priv->color_fmt) {
1450N/A case RADEON_COLOR_FORMAT_RGB565:
1450N/A color = (((r & 0xf8) << 8) |
1450N/A ((g & 0xfc) << 3) | ((b & 0xf8) >> 3));
1450N/A break;
1450N/A case RADEON_COLOR_FORMAT_ARGB8888:
1450N/A default:
1450N/A color = (((0xfful) << 24) | (r << 16) | (g << 8) | b);
1450N/A break;
1450N/A }
1450N/A
1450N/A BEGIN_RING(4);
1450N/A RADEON_WAIT_UNTIL_3D_IDLE();
1450N/A OUT_RING(CP_PACKET0(RADEON_DP_WRITE_MASK, 0));
1450N/A OUT_RING(0xffffffff);
1450N/A ADVANCE_RING();
1450N/A
1450N/A BEGIN_RING(6);
1450N/A
1450N/A OUT_RING(CP_PACKET3(RADEON_CNTL_PAINT_MULTI, 4));
1450N/A OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL |
1450N/A RADEON_GMC_BRUSH_SOLID_COLOR |
1450N/A (dev_priv->color_fmt << 8) |
1450N/A RADEON_GMC_SRC_DATATYPE_COLOR |
1450N/A RADEON_ROP3_P | RADEON_GMC_CLR_CMP_CNTL_DIS);
1450N/A
1450N/A if (dev_priv->page_flipping && dev_priv->current_page == 1) {
1450N/A OUT_RING(dev_priv->front_pitch_offset);
1450N/A } else {
1450N/A OUT_RING(dev_priv->back_pitch_offset);
1450N/A }
1450N/A
1450N/A OUT_RING(color);
1450N/A
1450N/A OUT_RING((x << 16) | y);
1450N/A OUT_RING((w << 16) | h);
1450N/A
1450N/A ADVANCE_RING();
1450N/A}
1450N/A
1450N/Astatic void radeon_cp_performance_boxes(drm_radeon_private_t *dev_priv)
1450N/A{
1450N/A /*
1450N/A * Collapse various things into a wait flag -- trying to
1450N/A * guess if userspace slept -- better just to have them tell us.
1450N/A */
1450N/A if (dev_priv->stats.last_frame_reads > 1 ||
1450N/A dev_priv->stats.last_clear_reads > dev_priv->stats.clears) {
1450N/A dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
1450N/A }
1450N/A
1450N/A if (dev_priv->stats.freelist_loops) {
1450N/A dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
1450N/A }
1450N/A
1450N/A /* Purple box for page flipping */
1450N/A if (dev_priv->stats.boxes & RADEON_BOX_FLIP)
1450N/A radeon_clear_box(dev_priv, 4, 4, 8, 8, 255, 0, 255);
1450N/A
1450N/A /* Red box if we have to wait for idle at any point */
1450N/A if (dev_priv->stats.boxes & RADEON_BOX_WAIT_IDLE)
1450N/A radeon_clear_box(dev_priv, 16, 4, 8, 8, 255, 0, 0);
1450N/A
1450N/A /* Blue box: lost context? */
1450N/A
1450N/A /* Yellow box for texture swaps */
1450N/A if (dev_priv->stats.boxes & RADEON_BOX_TEXTURE_LOAD)
1450N/A radeon_clear_box(dev_priv, 40, 4, 8, 8, 255, 255, 0);
1450N/A
1450N/A /* Green box if hardware never idles (as far as we can tell) */
1450N/A if (!(dev_priv->stats.boxes & RADEON_BOX_DMA_IDLE))
1450N/A radeon_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
1450N/A
1450N/A /*
1450N/A * Draw bars indicating number of buffers allocated
1450N/A * (not a great measure, easily confused)
1450N/A */
1450N/A if (dev_priv->stats.requested_bufs) {
1450N/A if (dev_priv->stats.requested_bufs > 100)
1450N/A dev_priv->stats.requested_bufs = 100;
1450N/A
1450N/A radeon_clear_box(dev_priv, 4, 16,
1450N/A dev_priv->stats.requested_bufs, 4, 196, 128, 128);
1450N/A }
1450N/A
1450N/A (void) memset(&dev_priv->stats, 0, sizeof (dev_priv->stats));
1450N/A
1450N/A}
1450N/A
1450N/A/*
1450N/A * CP command dispatch functions
1450N/A */
1450N/A
1450N/Astatic void radeon_cp_dispatch_clear(drm_device_t *dev,
1450N/A drm_radeon_clear_t *clear, drm_radeon_clear_rect_t *depth_boxes)
1450N/A{
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
1450N/A drm_radeon_depth_clear_t *depth_clear = &dev_priv->depth_clear;
1450N/A int nbox = sarea_priv->nbox;
1450N/A drm_clip_rect_t *pbox = sarea_priv->boxes;
1450N/A unsigned int flags = clear->flags;
1450N/A u32 rb3d_cntl = 0, rb3d_stencilrefmask = 0;
1450N/A int i;
1450N/A RING_LOCALS;
1450N/A DRM_DEBUG("flags = 0x%x\n", flags);
1450N/A
1450N/A dev_priv->stats.clears++;
1450N/A
1450N/A if (dev_priv->page_flipping && dev_priv->current_page == 1) {
1450N/A unsigned int tmp = flags;
1450N/A
1450N/A flags &= ~(RADEON_FRONT | RADEON_BACK);
1450N/A if (tmp & RADEON_FRONT)
1450N/A flags |= RADEON_BACK;
1450N/A if (tmp & RADEON_BACK)
1450N/A flags |= RADEON_FRONT;
1450N/A }
1450N/A
1450N/A if (flags & (RADEON_FRONT | RADEON_BACK)) {
1450N/A
1450N/A BEGIN_RING(4);
1450N/A
1450N/A /*
1450N/A * Ensure the 3D stream is idle before doing a
1450N/A * 2D fill to clear the front or back buffer.
1450N/A */
1450N/A RADEON_WAIT_UNTIL_3D_IDLE();
1450N/A
1450N/A OUT_RING(CP_PACKET0(RADEON_DP_WRITE_MASK, 0));
1450N/A OUT_RING(clear->color_mask);
1450N/A
1450N/A ADVANCE_RING();
1450N/A
1450N/A /* Make sure we restore the 3D state next time. */
1450N/A dev_priv->sarea_priv->ctx_owner = 0;
1450N/A
1450N/A for (i = 0; i < nbox; i++) {
1450N/A int x = pbox[i].x1;
1450N/A int y = pbox[i].y1;
1450N/A int w = pbox[i].x2 - x;
1450N/A int h = pbox[i].y2 - y;
1450N/A
1450N/A DRM_DEBUG("dispatch clear %d,%d-%d,%d flags 0x%x\n",
1450N/A x, y, w, h, flags);
1450N/A
1450N/A if (flags & RADEON_FRONT) {
1450N/A BEGIN_RING(6);
1450N/A
1450N/A OUT_RING(CP_PACKET3
1450N/A (RADEON_CNTL_PAINT_MULTI, 4));
1450N/A OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL |
1450N/A RADEON_GMC_BRUSH_SOLID_COLOR |
1450N/A (dev_priv-> color_fmt << 8) |
1450N/A RADEON_GMC_SRC_DATATYPE_COLOR |
1450N/A RADEON_ROP3_P |
1450N/A RADEON_GMC_CLR_CMP_CNTL_DIS);
1450N/A
1450N/A OUT_RING(dev_priv->front_pitch_offset);
1450N/A OUT_RING(clear->clear_color);
1450N/A
1450N/A OUT_RING((x << 16) | y);
1450N/A OUT_RING((w << 16) | h);
1450N/A
1450N/A ADVANCE_RING();
1450N/A }
1450N/A
1450N/A if (flags & RADEON_BACK) {
1450N/A BEGIN_RING(6);
1450N/A
1450N/A OUT_RING(CP_PACKET3
1450N/A (RADEON_CNTL_PAINT_MULTI, 4));
1450N/A OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL |
1450N/A RADEON_GMC_BRUSH_SOLID_COLOR |
1450N/A (dev_priv-> color_fmt << 8) |
1450N/A RADEON_GMC_SRC_DATATYPE_COLOR |
1450N/A RADEON_ROP3_P |
1450N/A RADEON_GMC_CLR_CMP_CNTL_DIS);
1450N/A
1450N/A OUT_RING(dev_priv->back_pitch_offset);
1450N/A OUT_RING(clear->clear_color);
1450N/A
1450N/A OUT_RING((x << 16) | y);
1450N/A OUT_RING((w << 16) | h);
1450N/A
1450N/A ADVANCE_RING();
1450N/A }
1450N/A }
1450N/A }
1450N/A
1450N/A /* hyper z clear */
1450N/A /*
1450N/A * no docs available, based on reverse engeneering
1450N/A * by Stephane Marchesin
1450N/A */
1450N/A if ((flags & (RADEON_DEPTH | RADEON_STENCIL)) &&
1450N/A (flags & RADEON_CLEAR_FASTZ)) {
1450N/A
1450N/A int i;
1450N/A int depthpixperline =
1450N/A dev_priv->depth_fmt ==
1450N/A RADEON_DEPTH_FORMAT_16BIT_INT_Z ?
1450N/A (dev_priv->depth_pitch / 2) :
1450N/A (dev_priv-> depth_pitch / 4);
1450N/A
1450N/A u32 clearmask;
1450N/A
1450N/A u32 tempRB3D_DEPTHCLEARVALUE = clear->clear_depth |
1450N/A ((clear->depth_mask & 0xff) << 24);
1450N/A
1450N/A /*
1450N/A * Make sure we restore the 3D state next time.
1450N/A * we haven't touched any "normal" state - still
1450N/A * need this?
1450N/A */
1450N/A dev_priv->sarea_priv->ctx_owner = 0;
1450N/A
1450N/A if ((dev_priv->flags & RADEON_HAS_HIERZ) &&
1450N/A (flags & RADEON_USE_HIERZ)) {
1450N/A /* FIXME : reverse engineer that for Rx00 cards */
1450N/A /*
1450N/A * FIXME : the mask supposedly contains low-res
1450N/A * z values. So can't set just to the max (0xff?
1450N/A * or actually 0x3fff?), need to take z clear
1450N/A * value into account?
1450N/A */
1450N/A /*
1450N/A * pattern seems to work for r100, though get
1450N/A * slight rendering errors with glxgears. If
1450N/A * hierz is not enabled for r100, only 4 bits
1450N/A * which indicate clear (15,16,31,32, all zero)
1450N/A * matter, the other ones are ignored, and the
1450N/A * same clear mask can be used. That's very
1450N/A * different behaviour than R200 which needs
1450N/A * different clear mask and different number
1450N/A * of tiles to clear if hierz is enabled or not !?!
1450N/A */
1450N/A clearmask = (0xff << 22) | (0xff << 6) | 0x003f003f;
1450N/A } else {
1450N/A /*
1450N/A * clear mask : chooses the clearing pattern.
1450N/A * rv250: could be used to clear only parts of macrotiles
1450N/A * (but that would get really complicated...)?
1450N/A * bit 0 and 1 (either or both of them ?!?!) are used to
1450N/A * not clear tile (or maybe one of the bits indicates if
1450N/A * the tile is compressed or not), bit 2 and 3 to not
1450N/A * clear tile 1,...,.
1450N/A * Pattern is as follows:
1450N/A * | 0,1 | 4,5 | 8,9 |12,13|16,17|20,21|24,25|28,29|
1450N/A * bits -------------------------------------------------
1450N/A * | 2,3 | 6,7 |10,11|14,15|18,19|22,23|26,27|30,31|
1450N/A * rv100: clearmask covers 2x8 4x1 tiles, but one clear
1450N/A * still covers 256 pixels ?!?
1450N/A */
1450N/A clearmask = 0x0;
1450N/A }
1450N/A
1450N/A BEGIN_RING(8);
1450N/A RADEON_WAIT_UNTIL_2D_IDLE();
1450N/A OUT_RING_REG(RADEON_RB3D_DEPTHCLEARVALUE,
1450N/A tempRB3D_DEPTHCLEARVALUE);
1450N/A /* what offset is this exactly ? */
1450N/A OUT_RING_REG(RADEON_RB3D_ZMASKOFFSET, 0);
1450N/A /* need ctlstat, otherwise get some strange black flickering */
1450N/A OUT_RING_REG(RADEON_RB3D_ZCACHE_CTLSTAT,
1450N/A RADEON_RB3D_ZC_FLUSH_ALL);
1450N/A ADVANCE_RING();
1450N/A
1450N/A for (i = 0; i < nbox; i++) {
1450N/A int tileoffset, nrtilesx, nrtilesy, j;
1450N/A /*
1450N/A * it looks like r200 needs rv-style clears, at
1450N/A * least if hierz is not enabled?
1450N/A */
1450N/A if ((dev_priv->flags & RADEON_HAS_HIERZ) &&
1450N/A !(dev_priv->microcode_version == UCODE_R200)) {
1450N/A /*
1450N/A * FIXME : figure this out for r200 (when hierz
1450N/A * is enabled). Or maybe r200 actually doesn't
1450N/A * need to put the low-res z value into the tile
1450N/A * cache like r100, but just needs to clear the
1450N/A * hi-level z-buffer? Works for R100, both with
1450N/A * hierz and without.R100 seems to operate on
1450N/A * 2x1 8x8 tiles, but... odd: offset/nrtiles
1450N/A * need to be 64 pix (4 blocka) aligned?
1450N/A * Potentially problematic with resolutions
1450N/A * which are not 64 pix aligned?
1450N/A */
1450N/A tileoffset =
1450N/A ((pbox[i].y1 >> 3) * depthpixperline +
1450N/A pbox[i].x1) >> 6;
1450N/A nrtilesx =
1450N/A ((pbox[i].x2 & ~63) -
1450N/A (pbox[i].x1 & ~63)) >> 4;
1450N/A nrtilesy =
1450N/A (pbox[i].y2 >> 3) - (pbox[i].y1 >> 3);
1450N/A for (j = 0; j <= nrtilesy; j++) {
1450N/A BEGIN_RING(4);
1450N/A OUT_RING(CP_PACKET3
1450N/A (RADEON_3D_CLEAR_ZMASK, 2));
1450N/A /* first tile */
1450N/A OUT_RING(tileoffset * 8);
1450N/A /* the number of tiles to clear */
1450N/A OUT_RING(nrtilesx + 4);
1450N/A /*
1450N/A * clear mask :
1450N/A * chooses the clearing pattern.
1450N/A */
1450N/A OUT_RING(clearmask);
1450N/A ADVANCE_RING();
1450N/A tileoffset += depthpixperline >> 6;
1450N/A }
1450N/A } else if (dev_priv->microcode_version == UCODE_R200) {
1450N/A /* works for rv250. */
1450N/A /*
1450N/A * find first macro tile
1450N/A * (8x2 4x4 z-pixels on rv250)
1450N/A */
1450N/A tileoffset =
1450N/A ((pbox[i].y1 >> 3) * depthpixperline +
1450N/A pbox[i].x1) >> 5;
1450N/A nrtilesx =
1450N/A (pbox[i].x2 >> 5) - (pbox[i].x1 >> 5);
1450N/A nrtilesy =
1450N/A (pbox[i].y2 >> 3) - (pbox[i].y1 >> 3);
1450N/A for (j = 0; j <= nrtilesy; j++) {
1450N/A BEGIN_RING(4);
1450N/A OUT_RING(CP_PACKET3
1450N/A (RADEON_3D_CLEAR_ZMASK, 2));
1450N/A /* first tile */
1450N/A /*
1450N/A * judging by the first tile
1450N/A * offset needed, could possibly
1450N/A * directly address/clear 4x4
1450N/A * tiles instead of 8x2 * 4x4
1450N/A * macro tiles, though would
1450N/A * still need clear mask for
1450N/A * right/bottom if truely 4x4
1450N/A * granularity is desired ?
1450N/A */
1450N/A OUT_RING(tileoffset * 16);
1450N/A /* the number of tiles to clear */
1450N/A OUT_RING(nrtilesx + 1);
1450N/A /*
1450N/A * clear mask :
1450N/A * chooses the clearing pattern.
1450N/A */
1450N/A OUT_RING(clearmask);
1450N/A ADVANCE_RING();
1450N/A tileoffset += depthpixperline >> 5;
1450N/A }
1450N/A } else { /* rv 100 */
1450N/A /* rv100 might not need 64 pix alignment */
1450N/A /* offsets are, hmm, weird */
1450N/A tileoffset =
1450N/A ((pbox[i].y1 >> 4) * depthpixperline +
1450N/A pbox[i].x1) >> 6;
1450N/A nrtilesx =
1450N/A ((pbox[i].x2 & ~63) -
1450N/A (pbox[i].x1 & ~63)) >> 4;
1450N/A nrtilesy =
1450N/A (pbox[i].y2 >> 4) - (pbox[i].y1 >> 4);
1450N/A for (j = 0; j <= nrtilesy; j++) {
1450N/A BEGIN_RING(4);
1450N/A OUT_RING(CP_PACKET3
1450N/A (RADEON_3D_CLEAR_ZMASK, 2));
1450N/A OUT_RING(tileoffset * 128);
1450N/A /* the number of tiles to clear */
1450N/A OUT_RING(nrtilesx + 4);
1450N/A /*
1450N/A * clear mask :
1450N/A * chooses the clearing pattern.
1450N/A */
1450N/A OUT_RING(clearmask);
1450N/A ADVANCE_RING();
1450N/A tileoffset += depthpixperline >> 6;
1450N/A }
1450N/A }
1450N/A }
1450N/A
1450N/A /* TODO don't always clear all hi-level z tiles */
1450N/A if ((dev_priv->flags & RADEON_HAS_HIERZ) &&
1450N/A (dev_priv->microcode_version == UCODE_R200) &&
1450N/A (flags & RADEON_USE_HIERZ))
1450N/A /*
1450N/A * r100 and cards without hierarchical z-buffer
1450N/A * have no high-level z-buffer
1450N/A */
1450N/A /*
1450N/A * FIXME : the mask supposedly contains low-res
1450N/A * z values. So can't set just to the max (0xff?
1450N/A * or actually 0x3fff?), need to take z clear value
1450N/A * into account?
1450N/A */
1450N/A {
1450N/A BEGIN_RING(4);
1450N/A OUT_RING(CP_PACKET3(RADEON_3D_CLEAR_HIZ, 2));
1450N/A OUT_RING(0x0); /* First tile */
1450N/A OUT_RING(0x3cc0);
1450N/A OUT_RING((0xff << 22) | (0xff << 6) | 0x003f003f);
1450N/A ADVANCE_RING();
1450N/A }
1450N/A }
1450N/A
1450N/A /*
1450N/A * We have to clear the depth and/or stencil buffers by
1450N/A * rendering a quad into just those buffers. Thus, we have to
1450N/A * make sure the 3D engine is configured correctly.
1450N/A */
1450N/A else if ((dev_priv->microcode_version == UCODE_R200) &&
1450N/A (flags & (RADEON_DEPTH | RADEON_STENCIL))) {
1450N/A
1450N/A int tempPP_CNTL;
1450N/A int tempRE_CNTL;
1450N/A int tempRB3D_CNTL;
1450N/A int tempRB3D_ZSTENCILCNTL;
1450N/A int tempRB3D_STENCILREFMASK;
1450N/A int tempRB3D_PLANEMASK;
1450N/A int tempSE_CNTL;
1450N/A int tempSE_VTE_CNTL;
1450N/A int tempSE_VTX_FMT_0;
1450N/A int tempSE_VTX_FMT_1;
1450N/A int tempSE_VAP_CNTL;
1450N/A int tempRE_AUX_SCISSOR_CNTL;
1450N/A
1450N/A tempPP_CNTL = 0;
1450N/A tempRE_CNTL = 0;
1450N/A
1450N/A tempRB3D_CNTL = depth_clear->rb3d_cntl;
1450N/A
1450N/A tempRB3D_ZSTENCILCNTL = depth_clear->rb3d_zstencilcntl;
1450N/A tempRB3D_STENCILREFMASK = 0x0;
1450N/A
1450N/A tempSE_CNTL = depth_clear->se_cntl;
1450N/A
1450N/A /* Disable TCL */
1450N/A
1450N/A tempSE_VAP_CNTL =
1450N/A (/* SE_VAP_CNTL__FORCE_W_TO_ONE_MASK | */
1450N/A (0x9 << SE_VAP_CNTL__VF_MAX_VTX_NUM__SHIFT));
1450N/A
1450N/A tempRB3D_PLANEMASK = 0x0;
1450N/A
1450N/A tempRE_AUX_SCISSOR_CNTL = 0x0;
1450N/A
1450N/A tempSE_VTE_CNTL =
1450N/A SE_VTE_CNTL__VTX_XY_FMT_MASK | SE_VTE_CNTL__VTX_Z_FMT_MASK;
1450N/A
1450N/A /* Vertex format (X, Y, Z, W) */
1450N/A tempSE_VTX_FMT_0 =
1450N/A SE_VTX_FMT_0__VTX_Z0_PRESENT_MASK |
1450N/A SE_VTX_FMT_0__VTX_W0_PRESENT_MASK;
1450N/A tempSE_VTX_FMT_1 = 0x0;
1450N/A
1450N/A /*
1450N/A * Depth buffer specific enables
1450N/A */
1450N/A if (flags & RADEON_DEPTH) {
1450N/A /* Enable depth buffer */
1450N/A tempRB3D_CNTL |= RADEON_Z_ENABLE;
1450N/A } else {
1450N/A /* Disable depth buffer */
1450N/A tempRB3D_CNTL &= ~RADEON_Z_ENABLE;
1450N/A }
1450N/A
1450N/A /*
1450N/A * Stencil buffer specific enables
1450N/A */
1450N/A if (flags & RADEON_STENCIL) {
1450N/A tempRB3D_CNTL |= RADEON_STENCIL_ENABLE;
1450N/A tempRB3D_STENCILREFMASK = clear->depth_mask;
1450N/A } else {
1450N/A tempRB3D_CNTL &= ~RADEON_STENCIL_ENABLE;
1450N/A tempRB3D_STENCILREFMASK = 0x00000000;
1450N/A }
1450N/A
1450N/A if (flags & RADEON_USE_COMP_ZBUF) {
1450N/A tempRB3D_ZSTENCILCNTL |= RADEON_Z_COMPRESSION_ENABLE |
1450N/A RADEON_Z_DECOMPRESSION_ENABLE;
1450N/A }
1450N/A if (flags & RADEON_USE_HIERZ) {
1450N/A tempRB3D_ZSTENCILCNTL |= RADEON_Z_HIERARCHY_ENABLE;
1450N/A }
1450N/A
1450N/A BEGIN_RING(26);
1450N/A RADEON_WAIT_UNTIL_2D_IDLE();
1450N/A
1450N/A OUT_RING_REG(RADEON_PP_CNTL, tempPP_CNTL);
1450N/A OUT_RING_REG(R200_RE_CNTL, tempRE_CNTL);
1450N/A OUT_RING_REG(RADEON_RB3D_CNTL, tempRB3D_CNTL);
1450N/A OUT_RING_REG(RADEON_RB3D_ZSTENCILCNTL, tempRB3D_ZSTENCILCNTL);
1450N/A OUT_RING_REG(RADEON_RB3D_STENCILREFMASK,
1450N/A tempRB3D_STENCILREFMASK);
1450N/A OUT_RING_REG(RADEON_RB3D_PLANEMASK, tempRB3D_PLANEMASK);
1450N/A OUT_RING_REG(RADEON_SE_CNTL, tempSE_CNTL);
1450N/A OUT_RING_REG(R200_SE_VTE_CNTL, tempSE_VTE_CNTL);
1450N/A OUT_RING_REG(R200_SE_VTX_FMT_0, tempSE_VTX_FMT_0);
1450N/A OUT_RING_REG(R200_SE_VTX_FMT_1, tempSE_VTX_FMT_1);
1450N/A OUT_RING_REG(R200_SE_VAP_CNTL, tempSE_VAP_CNTL);
1450N/A OUT_RING_REG(R200_RE_AUX_SCISSOR_CNTL, tempRE_AUX_SCISSOR_CNTL);
1450N/A ADVANCE_RING();
1450N/A
1450N/A /* Make sure we restore the 3D state next time. */
1450N/A dev_priv->sarea_priv->ctx_owner = 0;
1450N/A
1450N/A for (i = 0; i < nbox; i++) {
1450N/A
1450N/A /*
1450N/A * Funny that this should be required --
1450N/A * sets top-left?
1450N/A */
1450N/A radeon_emit_clip_rect(dev_priv, &sarea_priv->boxes[i]);
1450N/A
1450N/A BEGIN_RING(14);
1450N/A OUT_RING(CP_PACKET3(R200_3D_DRAW_IMMD_2, 12));
1450N/A OUT_RING((RADEON_PRIM_TYPE_RECT_LIST |
1450N/A RADEON_PRIM_WALK_RING |
1450N/A (3 << RADEON_NUM_VERTICES_SHIFT)));
1450N/A OUT_RING(depth_boxes[i].ui[CLEAR_X1]);
1450N/A OUT_RING(depth_boxes[i].ui[CLEAR_Y1]);
1450N/A OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]);
1450N/A OUT_RING(0x3f800000);
1450N/A OUT_RING(depth_boxes[i].ui[CLEAR_X1]);
1450N/A OUT_RING(depth_boxes[i].ui[CLEAR_Y2]);
1450N/A OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]);
1450N/A OUT_RING(0x3f800000);
1450N/A OUT_RING(depth_boxes[i].ui[CLEAR_X2]);
1450N/A OUT_RING(depth_boxes[i].ui[CLEAR_Y2]);
1450N/A OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]);
1450N/A OUT_RING(0x3f800000);
1450N/A ADVANCE_RING();
1450N/A }
1450N/A } else if ((flags & (RADEON_DEPTH | RADEON_STENCIL))) {
1450N/A
1450N/A int tempRB3D_ZSTENCILCNTL = depth_clear->rb3d_zstencilcntl;
1450N/A
1450N/A rb3d_cntl = depth_clear->rb3d_cntl;
1450N/A
1450N/A if (flags & RADEON_DEPTH) {
1450N/A rb3d_cntl |= RADEON_Z_ENABLE;
1450N/A } else {
1450N/A rb3d_cntl &= ~RADEON_Z_ENABLE;
1450N/A }
1450N/A
1450N/A if (flags & RADEON_STENCIL) {
1450N/A rb3d_cntl |= RADEON_STENCIL_ENABLE;
1450N/A
1450N/A /* misnamed field */
1450N/A rb3d_stencilrefmask = clear->depth_mask;
1450N/A
1450N/A } else {
1450N/A rb3d_cntl &= ~RADEON_STENCIL_ENABLE;
1450N/A rb3d_stencilrefmask = 0x00000000;
1450N/A }
1450N/A
1450N/A if (flags & RADEON_USE_COMP_ZBUF) {
1450N/A tempRB3D_ZSTENCILCNTL |= RADEON_Z_COMPRESSION_ENABLE |
1450N/A RADEON_Z_DECOMPRESSION_ENABLE;
1450N/A }
1450N/A if (flags & RADEON_USE_HIERZ) {
1450N/A tempRB3D_ZSTENCILCNTL |= RADEON_Z_HIERARCHY_ENABLE;
1450N/A }
1450N/A
1450N/A BEGIN_RING(13);
1450N/A RADEON_WAIT_UNTIL_2D_IDLE();
1450N/A
1450N/A OUT_RING(CP_PACKET0(RADEON_PP_CNTL, 1));
1450N/A OUT_RING(0x00000000);
1450N/A OUT_RING(rb3d_cntl);
1450N/A
1450N/A OUT_RING_REG(RADEON_RB3D_ZSTENCILCNTL, tempRB3D_ZSTENCILCNTL);
1450N/A OUT_RING_REG(RADEON_RB3D_STENCILREFMASK, rb3d_stencilrefmask);
1450N/A OUT_RING_REG(RADEON_RB3D_PLANEMASK, 0x00000000);
1450N/A OUT_RING_REG(RADEON_SE_CNTL, depth_clear->se_cntl);
1450N/A ADVANCE_RING();
1450N/A
1450N/A /* Make sure we restore the 3D state next time. */
1450N/A dev_priv->sarea_priv->ctx_owner = 0;
1450N/A
1450N/A for (i = 0; i < nbox; i++) {
1450N/A
1450N/A /*
1450N/A * Funny that this should be required --
1450N/A * sets top-left?
1450N/A */
1450N/A radeon_emit_clip_rect(dev_priv, &sarea_priv->boxes[i]);
1450N/A
1450N/A BEGIN_RING(15);
1450N/A
1450N/A OUT_RING(CP_PACKET3(RADEON_3D_DRAW_IMMD, 13));
1450N/A OUT_RING(RADEON_VTX_Z_PRESENT |
1450N/A RADEON_VTX_PKCOLOR_PRESENT);
1450N/A OUT_RING((RADEON_PRIM_TYPE_RECT_LIST |
1450N/A RADEON_PRIM_WALK_RING |
1450N/A RADEON_MAOS_ENABLE |
1450N/A RADEON_VTX_FMT_RADEON_MODE |
1450N/A (3 << RADEON_NUM_VERTICES_SHIFT)));
1450N/A
1450N/A OUT_RING(depth_boxes[i].ui[CLEAR_X1]);
1450N/A OUT_RING(depth_boxes[i].ui[CLEAR_Y1]);
1450N/A OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]);
1450N/A OUT_RING(0x0);
1450N/A
1450N/A OUT_RING(depth_boxes[i].ui[CLEAR_X1]);
1450N/A OUT_RING(depth_boxes[i].ui[CLEAR_Y2]);
1450N/A OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]);
1450N/A OUT_RING(0x0);
1450N/A
1450N/A OUT_RING(depth_boxes[i].ui[CLEAR_X2]);
1450N/A OUT_RING(depth_boxes[i].ui[CLEAR_Y2]);
1450N/A OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]);
1450N/A OUT_RING(0x0);
1450N/A
1450N/A ADVANCE_RING();
1450N/A }
1450N/A }
1450N/A
1450N/A /*
1450N/A * Increment the clear counter. The client-side 3D driver must
1450N/A * wait on this value before performing the clear ioctl. We
1450N/A * need this because the card's so damned fast...
1450N/A */
1450N/A dev_priv->sarea_priv->last_clear++;
1450N/A
1450N/A BEGIN_RING(4);
1450N/A
1450N/A RADEON_CLEAR_AGE(dev_priv->sarea_priv->last_clear);
1450N/A RADEON_WAIT_UNTIL_IDLE();
1450N/A
1450N/A ADVANCE_RING();
1450N/A}
1450N/A
1450N/Astatic void radeon_cp_dispatch_swap(drm_device_t *dev)
1450N/A{
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
1450N/A int nbox = sarea_priv->nbox;
1450N/A drm_clip_rect_t *pbox = sarea_priv->boxes;
1450N/A int i;
1450N/A RING_LOCALS;
1450N/A
1450N/A /* Do some trivial performance monitoring... */
1450N/A if (dev_priv->do_boxes)
1450N/A radeon_cp_performance_boxes(dev_priv);
1450N/A
1450N/A /*
1450N/A * Wait for the 3D stream to idle before dispatching the bitblt.
1450N/A * This will prevent data corruption between the two streams.
1450N/A */
1450N/A BEGIN_RING(2);
1450N/A
1450N/A RADEON_WAIT_UNTIL_3D_IDLE();
1450N/A
1450N/A ADVANCE_RING();
1450N/A
1450N/A for (i = 0; i < nbox; i++) {
1450N/A int x = pbox[i].x1;
1450N/A int y = pbox[i].y1;
1450N/A int w = pbox[i].x2 - x;
1450N/A int h = pbox[i].y2 - y;
1450N/A
1450N/A DRM_DEBUG("dispatch swap %d,%d-%d,%d\n", x, y, w, h);
1450N/A
1450N/A BEGIN_RING(9);
1450N/A
1450N/A OUT_RING(CP_PACKET0(RADEON_DP_GUI_MASTER_CNTL, 0));
1450N/A OUT_RING(RADEON_GMC_SRC_PITCH_OFFSET_CNTL |
1450N/A RADEON_GMC_DST_PITCH_OFFSET_CNTL |
1450N/A RADEON_GMC_BRUSH_NONE |
1450N/A (dev_priv->color_fmt << 8) |
1450N/A RADEON_GMC_SRC_DATATYPE_COLOR |
1450N/A RADEON_ROP3_S |
1450N/A RADEON_DP_SRC_SOURCE_MEMORY |
1450N/A RADEON_GMC_CLR_CMP_CNTL_DIS | RADEON_GMC_WR_MSK_DIS);
1450N/A
1450N/A /* Make this work even if front & back are flipped: */
1450N/A OUT_RING(CP_PACKET0(RADEON_SRC_PITCH_OFFSET, 1));
1450N/A if (dev_priv->current_page == 0) {
1450N/A OUT_RING(dev_priv->back_pitch_offset);
1450N/A OUT_RING(dev_priv->front_pitch_offset);
1450N/A } else {
1450N/A OUT_RING(dev_priv->front_pitch_offset);
1450N/A OUT_RING(dev_priv->back_pitch_offset);
1450N/A }
1450N/A
1450N/A OUT_RING(CP_PACKET0(RADEON_SRC_X_Y, 2));
1450N/A OUT_RING((x << 16) | y);
1450N/A OUT_RING((x << 16) | y);
1450N/A OUT_RING((w << 16) | h);
1450N/A
1450N/A ADVANCE_RING();
1450N/A }
1450N/A
1450N/A /*
1450N/A * Increment the frame counter. The client-side 3D driver must
1450N/A * throttle the framerate by waiting for this value before
1450N/A * performing the swapbuffer ioctl.
1450N/A */
1450N/A dev_priv->sarea_priv->last_frame ++;
1450N/A
1450N/A BEGIN_RING(4);
1450N/A
1450N/A RADEON_FRAME_AGE(dev_priv->sarea_priv->last_frame);
1450N/A RADEON_WAIT_UNTIL_2D_IDLE();
1450N/A
1450N/A ADVANCE_RING();
1450N/A}
1450N/A
1450N/Astatic void radeon_cp_dispatch_flip(drm_device_t *dev)
1450N/A{
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_sarea_t *sarea = (drm_sarea_t *)dev_priv->sarea->handle;
1450N/A int offset = (dev_priv->current_page == 1)
1450N/A ? dev_priv->front_offset : dev_priv->back_offset;
1450N/A RING_LOCALS;
1450N/A DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n",
1450N/A __FUNCTION__,
1450N/A dev_priv->current_page, dev_priv->sarea_priv->pfCurrentPage);
1450N/A
1450N/A /* Do some trivial performance monitoring... */
1450N/A if (dev_priv->do_boxes) {
1450N/A dev_priv->stats.boxes |= RADEON_BOX_FLIP;
1450N/A radeon_cp_performance_boxes(dev_priv);
1450N/A }
1450N/A
1450N/A /* Update the frame offsets for both CRTCs */
1450N/A BEGIN_RING(6);
1450N/A
1450N/A RADEON_WAIT_UNTIL_3D_IDLE();
1450N/A OUT_RING_REG(RADEON_CRTC_OFFSET,
1450N/A ((sarea->frame.y * dev_priv->front_pitch +
1450N/A sarea->frame.x * (dev_priv->color_fmt - 2)) & ~7) + offset);
1450N/A OUT_RING_REG(RADEON_CRTC2_OFFSET,
1450N/A dev_priv->sarea_priv->crtc2_base + offset);
1450N/A
1450N/A ADVANCE_RING();
1450N/A
1450N/A /*
1450N/A * Increment the frame counter. The client-side 3D driver must
1450N/A * throttle the framerate by waiting for this value before
1450N/A * performing the swapbuffer ioctl.
1450N/A */
1450N/A dev_priv->sarea_priv->last_frame ++;
1450N/A dev_priv->sarea_priv->pfCurrentPage = dev_priv->current_page =
1450N/A 1 - dev_priv->current_page;
1450N/A
1450N/A BEGIN_RING(2);
1450N/A
1450N/A RADEON_FRAME_AGE(dev_priv->sarea_priv->last_frame);
1450N/A
1450N/A ADVANCE_RING();
1450N/A}
1450N/A
1450N/Astatic int bad_prim_vertex_nr(int primitive, int nr)
1450N/A{
1450N/A switch (primitive & RADEON_PRIM_TYPE_MASK) {
1450N/A case RADEON_PRIM_TYPE_NONE:
1450N/A case RADEON_PRIM_TYPE_POINT:
1450N/A return (nr < 1);
1450N/A case RADEON_PRIM_TYPE_LINE:
1450N/A return ((nr & 1) || nr == 0);
1450N/A case RADEON_PRIM_TYPE_LINE_STRIP:
1450N/A return (nr < 2);
1450N/A case RADEON_PRIM_TYPE_TRI_LIST:
1450N/A case RADEON_PRIM_TYPE_3VRT_POINT_LIST:
1450N/A case RADEON_PRIM_TYPE_3VRT_LINE_LIST:
1450N/A case RADEON_PRIM_TYPE_RECT_LIST:
1450N/A return (nr % 3 || nr == 0);
1450N/A case RADEON_PRIM_TYPE_TRI_FAN:
1450N/A case RADEON_PRIM_TYPE_TRI_STRIP:
1450N/A return (nr < 3);
1450N/A default:
1450N/A return (1);
1450N/A }
1450N/A}
1450N/A
1450N/Atypedef struct {
1450N/A unsigned int start;
1450N/A unsigned int finish;
1450N/A unsigned int prim;
1450N/A unsigned int numverts;
1450N/A unsigned int offset;
1450N/A unsigned int vc_format;
1450N/A} drm_radeon_tcl_prim_t;
1450N/A
1450N/Astatic void radeon_cp_dispatch_vertex(drm_device_t *dev,
1450N/A drm_buf_t *buf, drm_radeon_tcl_prim_t *prim)
1450N/A{
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
1450N/A int offset = dev_priv->gart_buffers_offset + buf->offset + prim->start;
1450N/A int numverts = (int)prim->numverts;
1450N/A int nbox = sarea_priv->nbox;
1450N/A int i = 0;
1450N/A RING_LOCALS;
1450N/A
1450N/A DRM_DEBUG("hwprim 0x%x vfmt 0x%x %d..%d %d verts\n",
1450N/A prim->prim, prim->vc_format, prim->start,
1450N/A prim->finish, prim->numverts);
1450N/A
1450N/A if (bad_prim_vertex_nr(prim->prim, prim->numverts)) {
1450N/A DRM_ERROR("bad prim %x numverts %d\n",
1450N/A prim->prim, prim->numverts);
1450N/A return;
1450N/A }
1450N/A
1450N/A do {
1450N/A /* Emit the next cliprect */
1450N/A if (i < nbox) {
1450N/A radeon_emit_clip_rect(dev_priv, &sarea_priv->boxes[i]);
1450N/A }
1450N/A
1450N/A /* Emit the vertex buffer rendering commands */
1450N/A BEGIN_RING(5);
1450N/A
1450N/A OUT_RING(CP_PACKET3(RADEON_3D_RNDR_GEN_INDX_PRIM, 3));
1450N/A OUT_RING(offset);
1450N/A OUT_RING(numverts);
1450N/A OUT_RING(prim->vc_format);
1450N/A OUT_RING(prim->prim | RADEON_PRIM_WALK_LIST |
1450N/A RADEON_COLOR_ORDER_RGBA |
1450N/A RADEON_VTX_FMT_RADEON_MODE |
1450N/A (numverts << RADEON_NUM_VERTICES_SHIFT));
1450N/A
1450N/A ADVANCE_RING();
1450N/A
1450N/A i++;
1450N/A } while (i < nbox);
1450N/A}
1450N/A
1450N/Astatic void radeon_cp_discard_buffer(drm_device_t *dev, drm_buf_t *buf)
1450N/A{
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_radeon_buf_priv_t *buf_priv = buf->dev_private;
1450N/A RING_LOCALS;
1450N/A
1450N/A buf_priv->age = ++dev_priv->sarea_priv->last_dispatch;
1450N/A
1450N/A /* Emit the vertex buffer age */
1450N/A BEGIN_RING(2);
1450N/A RADEON_DISPATCH_AGE(buf_priv->age);
1450N/A ADVANCE_RING();
1450N/A
1450N/A buf->pending = 1;
1450N/A buf->used = 0;
1450N/A}
1450N/A
1450N/Astatic void radeon_cp_dispatch_indirect(drm_device_t *dev,
1450N/A drm_buf_t *buf, int start, int end)
1450N/A{
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A RING_LOCALS;
1450N/A DRM_DEBUG("indirect: buf=%d s=0x%x e=0x%x\n", buf->idx, start, end);
1450N/A
1450N/A if (start != end) {
1450N/A int offset = (dev_priv->gart_buffers_offset +
1450N/A buf->offset + start);
1450N/A int dwords = (end - start + 3) / sizeof (u32);
1450N/A
1450N/A /*
1450N/A * Indirect buffer data must be an even number of
1450N/A * dwords, so if we've been given an odd number we must
1450N/A * pad the data with a Type-2 CP packet.
1450N/A */
1450N/A if (dwords & 1) {
1450N/A u32 *data = (u32 *)(uintptr_t)
1450N/A ((char *)dev->agp_buffer_map->handle
1450N/A + buf->offset + start);
1450N/A data[dwords++] = RADEON_CP_PACKET2;
1450N/A }
1450N/A
1450N/A /* Fire off the indirect buffer */
1450N/A BEGIN_RING(3);
1450N/A
1450N/A OUT_RING(CP_PACKET0(RADEON_CP_IB_BASE, 1));
1450N/A OUT_RING(offset);
1450N/A OUT_RING(dwords);
1450N/A
1450N/A ADVANCE_RING();
1450N/A }
1450N/A}
1450N/A
1450N/Astatic void radeon_cp_dispatch_indices(drm_device_t *dev,
1450N/A drm_buf_t *elt_buf, drm_radeon_tcl_prim_t *prim)
1450N/A{
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
1450N/A int offset = dev_priv->gart_buffers_offset + prim->offset;
1450N/A u32 *data;
1450N/A int dwords;
1450N/A int i = 0;
1450N/A int start = prim->start + RADEON_INDEX_PRIM_OFFSET;
1450N/A int count = (prim->finish - start) / sizeof (u16);
1450N/A int nbox = sarea_priv->nbox;
1450N/A
1450N/A DRM_DEBUG("hwprim 0x%x vfmt 0x%x %d..%d offset: %x nr %d\n",
1450N/A prim->prim, prim->vc_format, prim->start,
1450N/A prim->finish, prim->offset, prim->numverts);
1450N/A
1450N/A if (bad_prim_vertex_nr(prim->prim, count)) {
1450N/A DRM_ERROR("bad prim %x count %d\n", prim->prim, count);
1450N/A return;
1450N/A }
1450N/A
1450N/A if (start >= prim->finish || (prim->start & 0x7)) {
1450N/A DRM_ERROR("buffer prim %d\n", prim->prim);
1450N/A return;
1450N/A }
1450N/A
1450N/A dwords = (prim->finish - prim->start + 3) / sizeof (u32);
1450N/A
1450N/A data = (u32 *)(uintptr_t)((char *)dev->agp_buffer_map->handle +
1450N/A elt_buf->offset + prim->start);
1450N/A
1450N/A data[0] = CP_PACKET3(RADEON_3D_RNDR_GEN_INDX_PRIM, dwords - 2);
1450N/A data[1] = offset;
1450N/A data[2] = prim->numverts;
1450N/A data[3] = prim->vc_format;
1450N/A data[4] = (prim->prim |
1450N/A RADEON_PRIM_WALK_IND |
1450N/A RADEON_COLOR_ORDER_RGBA |
1450N/A RADEON_VTX_FMT_RADEON_MODE |
1450N/A (count << RADEON_NUM_VERTICES_SHIFT));
1450N/A
1450N/A do {
1450N/A if (i < nbox)
1450N/A radeon_emit_clip_rect(dev_priv, &sarea_priv->boxes[i]);
1450N/A
1450N/A radeon_cp_dispatch_indirect(dev, elt_buf,
1450N/A prim->start, prim->finish);
1450N/A
1450N/A i++;
1450N/A } while (i < nbox);
1450N/A
1450N/A}
1450N/A
1450N/A#define RADEON_MAX_TEXTURE_SIZE RADEON_BUFFER_SIZE
1450N/A
1450N/A/*ARGSUSED*/
1450N/Astatic int radeon_cp_dispatch_texture(drm_file_t *fpriv,
1450N/A drm_device_t *dev, drm_radeon_texture_t *tex,
1450N/A drm_radeon_tex_image_t *image, int mode)
1450N/A{
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_buf_t *buf;
1450N/A u32 format;
1450N/A u32 *buffer;
1450N/A const u8 __user *data;
1450N/A int size, dwords, tex_width, blit_width, spitch;
1450N/A u32 height;
1450N/A int i;
1450N/A u32 texpitch, microtile;
1450N/A u32 offset;
1450N/A RING_LOCALS;
1450N/A
1450N/A
1450N/A if (radeon_check_and_fixup_offset(dev_priv, fpriv, &tex->offset)) {
1450N/A DRM_ERROR("Invalid destination offset\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A dev_priv->stats.boxes |= RADEON_BOX_TEXTURE_LOAD;
1450N/A
1450N/A /*
1450N/A * Flush the pixel cache. This ensures no pixel data gets mixed
1450N/A * up with the texture data from the host data blit, otherwise
1450N/A * part of the texture image may be corrupted.
1450N/A */
1450N/A BEGIN_RING(4);
1450N/A RADEON_FLUSH_CACHE();
1450N/A RADEON_WAIT_UNTIL_IDLE();
1450N/A ADVANCE_RING();
1450N/A
1450N/A /*
1450N/A * The compiler won't optimize away a division by a variable,
1450N/A * even if the only legal values are powers of two. Thus, we'll
1450N/A * use a shift instead.
1450N/A */
1450N/A switch (tex->format) {
1450N/A case RADEON_TXFORMAT_ARGB8888:
1450N/A case RADEON_TXFORMAT_RGBA8888:
1450N/A format = RADEON_COLOR_FORMAT_ARGB8888;
1450N/A tex_width = tex->width * 4;
1450N/A blit_width = image->width * 4;
1450N/A break;
1450N/A case RADEON_TXFORMAT_AI88:
1450N/A case RADEON_TXFORMAT_ARGB1555:
1450N/A case RADEON_TXFORMAT_RGB565:
1450N/A case RADEON_TXFORMAT_ARGB4444:
1450N/A case RADEON_TXFORMAT_VYUY422:
1450N/A case RADEON_TXFORMAT_YVYU422:
1450N/A format = RADEON_COLOR_FORMAT_RGB565;
1450N/A tex_width = tex->width * 2;
1450N/A blit_width = image->width * 2;
1450N/A break;
1450N/A case RADEON_TXFORMAT_I8:
1450N/A case RADEON_TXFORMAT_RGB332:
1450N/A format = RADEON_COLOR_FORMAT_CI8;
1450N/A tex_width = tex->width * 1;
1450N/A blit_width = image->width * 1;
1450N/A break;
1450N/A default:
1450N/A DRM_ERROR("invalid texture format %d\n", tex->format);
1450N/A return (EINVAL);
1450N/A }
1450N/A spitch = blit_width >> 6;
1450N/A if (spitch == 0 && image->height > 1)
1450N/A return (EINVAL);
1450N/A
1450N/A texpitch = tex->pitch;
1450N/A if ((texpitch << 22) & RADEON_DST_TILE_MICRO) {
1450N/A microtile = 1;
1450N/A if (tex_width < 64) {
1450N/A texpitch &= ~(RADEON_DST_TILE_MICRO >> 22);
1450N/A /* we got tiled coordinates, untile them */
1450N/A image->x *= 2;
1450N/A }
1450N/A } else
1450N/A microtile = 0;
1450N/A
1450N/A DRM_DEBUG("tex=%dx%d blit=%d\n", tex_width, tex->height, blit_width);
1450N/A
1450N/A do {
1450N/A DRM_DEBUG("tex: ofs=0x%x p=%d f=%d x=%hd y=%hd w=%hd h=%hd\n",
1450N/A tex->offset >> 10, tex->pitch, tex->format,
1450N/A image->x, image->y, image->width, image->height);
1450N/A
1450N/A /*
1450N/A * Make a copy of some parameters in case we have to
1450N/A * update them for a multi-pass texture blit.
1450N/A */
1450N/A height = image->height;
1450N/A data = (const u8 __user *)image->data;
1450N/A
1450N/A size = height * blit_width;
1450N/A
1450N/A if (size > RADEON_MAX_TEXTURE_SIZE) {
1450N/A height = RADEON_MAX_TEXTURE_SIZE / blit_width;
1450N/A size = height * blit_width;
1450N/A } else if (size < 4 && size > 0) {
1450N/A size = 4;
1450N/A } else if (size == 0) {
1450N/A return (0);
1450N/A }
1450N/A
1450N/A buf = radeon_freelist_get(dev);
1450N/A#if 0
1450N/A if (0 && !buf) {
1450N/A radeon_do_cp_idle(dev_priv);
1450N/A buf = radeon_freelist_get(dev);
1450N/A }
1450N/A#endif
1450N/A if (!buf) {
1450N/A DRM_DEBUG("radeon_cp_dispatch_texture: EAGAIN\n");
1450N/A
1450N/A#ifdef _MULTI_DATAMODEL
1450N/A if (ddi_model_convert_from(mode & FMODELS) ==
1450N/A DDI_MODEL_ILP32) {
1450N/A drm_radeon_tex_image_32_t image32;
1450N/A image32.x = image->x;
1450N/A image32.y = image->y;
1450N/A image32.width = image->width;
1450N/A image32.height = image->height;
1450N/A image32.data = (uint32_t)(uintptr_t)image->data;
1450N/A DRM_COPYTO_WITH_RETURN(tex->image, &image32,
1450N/A sizeof (image32));
1450N/A } else {
1450N/A#endif
1450N/A DRM_COPYTO_WITH_RETURN(tex->image, image,
1450N/A sizeof (*image));
1450N/A#ifdef _MULTI_DATAMODEL
1450N/A }
1450N/A#endif
1450N/A return (EAGAIN);
1450N/A }
1450N/A
1450N/A /*
1450N/A * Dispatch the indirect buffer.
1450N/A */
1450N/A buffer = (u32 *)(uintptr_t)
1450N/A ((char *)dev->agp_buffer_map->handle + buf->offset);
1450N/A
1450N/A dwords = size / 4;
1450N/A
1450N/A#define RADEON_COPY_MT(_buf, _data, _width) \
1450N/A do { \
1450N/A if (DRM_COPY_FROM_USER(_buf, _data, (_width))) {\
1450N/A DRM_ERROR("%d: EFAULT on pad, %d bytes\n", \
1450N/A __LINE__, (_width)); \
1450N/A return (EFAULT); \
1450N/A } \
1450N/A } while (__lintzero)
1450N/A
1450N/A if (microtile) {
1450N/A /*
1450N/A * texture micro tiling in use, minimum texture
1450N/A * width is thus 16 bytes. however, we cannot use
1450N/A * blitter directly for texture width < 64 bytes,
1450N/A * since minimum tex pitch is 64 bytes and we need
1450N/A * this to match the texture width, otherwise the
1450N/A * blitter will tile it wrong. Thus, tiling manually
1450N/A * in this case. Additionally, need to special case
1450N/A * tex height = 1, since our actual image will have
1450N/A * height 2 and we need to ensure we don't read
1450N/A * beyond the texture size from user space.
1450N/A */
1450N/A if (tex->height == 1) {
1450N/A if (tex_width >= 64 || tex_width <= 16) {
1450N/A RADEON_COPY_MT(buffer, data,
1450N/A (int)(tex_width * sizeof (u32)));
1450N/A } else if (tex_width == 32) {
1450N/A RADEON_COPY_MT(buffer, data, 16);
1450N/A RADEON_COPY_MT(buffer + 8,
1450N/A data + 16, 16);
1450N/A }
1450N/A } else if (tex_width >= 64 || tex_width == 16) {
1450N/A RADEON_COPY_MT(buffer, data,
1450N/A (int)(dwords * sizeof (u32)));
1450N/A } else if (tex_width < 16) {
1450N/A for (i = 0; i < tex->height; i++) {
1450N/A RADEON_COPY_MT(buffer, data, tex_width);
1450N/A buffer += 4;
1450N/A data += tex_width;
1450N/A }
1450N/A } else if (tex_width == 32) {
1450N/A /*
1450N/A * TODO: make sure this works when not
1450N/A * fitting in one buffer
1450N/A * (i.e. 32bytes x 2048...)
1450N/A */
1450N/A for (i = 0; i < tex->height; i += 2) {
1450N/A RADEON_COPY_MT(buffer, data, 16);
1450N/A data += 16;
1450N/A RADEON_COPY_MT(buffer + 8, data, 16);
1450N/A data += 16;
1450N/A RADEON_COPY_MT(buffer + 4, data, 16);
1450N/A data += 16;
1450N/A RADEON_COPY_MT(buffer + 12, data, 16);
1450N/A data += 16;
1450N/A buffer += 16;
1450N/A }
1450N/A }
1450N/A } else {
1450N/A if (tex_width >= 32) {
1450N/A /*
1450N/A * Texture image width is larger than the
1450N/A * minimum, so we can upload it directly.
1450N/A */
1450N/A RADEON_COPY_MT(buffer, data,
1450N/A (int)(dwords * sizeof (u32)));
1450N/A } else {
1450N/A /*
1450N/A * Texture image width is less than the minimum,
1450N/A * so we need to pad out each image scanline to
1450N/A * the minimum width.
1450N/A */
1450N/A for (i = 0; i < tex->height; i++) {
1450N/A RADEON_COPY_MT(buffer, data, tex_width);
1450N/A buffer += 8;
1450N/A data += tex_width;
1450N/A }
1450N/A }
1450N/A }
1450N/A
1450N/A#undef RADEON_COPY_MT
1450N/A buf->filp = fpriv;
1450N/A buf->used = size;
1450N/A offset = dev_priv->gart_buffers_offset + buf->offset;
1450N/A
1450N/A BEGIN_RING(9);
1450N/A OUT_RING(CP_PACKET3(RADEON_CNTL_BITBLT_MULTI, 5));
1450N/A OUT_RING(RADEON_GMC_SRC_PITCH_OFFSET_CNTL |
1450N/A RADEON_GMC_DST_PITCH_OFFSET_CNTL |
1450N/A RADEON_GMC_BRUSH_NONE |
1450N/A (format << 8) |
1450N/A RADEON_GMC_SRC_DATATYPE_COLOR |
1450N/A RADEON_ROP3_S |
1450N/A RADEON_DP_SRC_SOURCE_MEMORY |
1450N/A RADEON_GMC_CLR_CMP_CNTL_DIS | RADEON_GMC_WR_MSK_DIS);
1450N/A OUT_RING((spitch << 22) | (offset >> 10));
1450N/A OUT_RING((texpitch << 22) | (tex->offset >> 10));
1450N/A OUT_RING(0);
1450N/A OUT_RING((image->x << 16) | image->y);
1450N/A OUT_RING((image->width << 16) | height);
1450N/A RADEON_WAIT_UNTIL_2D_IDLE();
1450N/A ADVANCE_RING();
1450N/A COMMIT_RING();
1450N/A
1450N/A
1450N/A radeon_cp_discard_buffer(dev, buf);
1450N/A
1450N/A /* Update the input parameters for next time */
1450N/A image->y += height;
1450N/A image->height -= height;
1450N/A image->data = (const u8 __user *)image->data + size;
1450N/A } while (image->height > 0);
1450N/A
1450N/A /*
1450N/A * Flush the pixel cache after the blit completes. This ensures
1450N/A * the texture data is written out to memory before rendering
1450N/A * continues.
1450N/A */
1450N/A BEGIN_RING(4);
1450N/A RADEON_FLUSH_CACHE();
1450N/A RADEON_WAIT_UNTIL_2D_IDLE();
1450N/A ADVANCE_RING();
1450N/A COMMIT_RING();
1450N/A return (0);
1450N/A}
1450N/A
1450N/Astatic void radeon_cp_dispatch_stipple(drm_device_t *dev, u32 *stipple)
1450N/A{
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A int i;
1450N/A RING_LOCALS;
1450N/A DRM_DEBUG("\n");
1450N/A
1450N/A BEGIN_RING(35);
1450N/A
1450N/A OUT_RING(CP_PACKET0(RADEON_RE_STIPPLE_ADDR, 0));
1450N/A OUT_RING(0x00000000);
1450N/A
1450N/A OUT_RING(CP_PACKET0_TABLE(RADEON_RE_STIPPLE_DATA, 31));
1450N/A for (i = 0; i < 32; i++) {
1450N/A OUT_RING(stipple[i]);
1450N/A }
1450N/A
1450N/A ADVANCE_RING();
1450N/A}
1450N/A
1450N/Astatic void radeon_apply_surface_regs(int surf_index,
1450N/A drm_radeon_private_t *dev_priv)
1450N/A{
1450N/A if (!dev_priv->mmio)
1450N/A return;
1450N/A
1450N/A (void) radeon_do_cp_idle(dev_priv);
1450N/A
1450N/A RADEON_WRITE(RADEON_SURFACE0_INFO + 16 * surf_index,
1450N/A dev_priv->surfaces[surf_index].flags);
1450N/A RADEON_WRITE(RADEON_SURFACE0_LOWER_BOUND + 16 * surf_index,
1450N/A dev_priv->surfaces[surf_index].lower);
1450N/A RADEON_WRITE(RADEON_SURFACE0_UPPER_BOUND + 16 * surf_index,
1450N/A dev_priv->surfaces[surf_index].upper);
1450N/A}
1450N/A
1450N/A/*
1450N/A * Allocates a virtual surface
1450N/A * doesn't always allocate a real surface, will stretch an existing
1450N/A * surface when possible.
1450N/A *
1450N/A * Note that refcount can be at most 2, since during a free refcount=3
1450N/A * might mean we have to allocate a new surface which might not always
1450N/A * be available.
1450N/A * For example : we allocate three contigous surfaces ABC. If B is
1450N/A * freed, we suddenly need two surfaces to store A and C, which might
1450N/A * not always be available.
1450N/A */
1450N/Astatic int alloc_surface(drm_radeon_surface_alloc_t *new,
1450N/A drm_radeon_private_t *dev_priv, drm_file_t *filp)
1450N/A{
1450N/A struct radeon_virt_surface *s;
1450N/A int i;
1450N/A int virt_surface_index;
1450N/A uint32_t new_upper, new_lower;
1450N/A
1450N/A new_lower = new->address;
1450N/A new_upper = new_lower + new->size - 1;
1450N/A
1450N/A /* sanity check */
1450N/A if ((new_lower >= new_upper) || (new->flags == 0) || (new->size == 0) ||
1450N/A ((new_upper & RADEON_SURF_ADDRESS_FIXED_MASK) !=
1450N/A RADEON_SURF_ADDRESS_FIXED_MASK) ||
1450N/A ((new_lower & RADEON_SURF_ADDRESS_FIXED_MASK) != 0))
1450N/A return (-1);
1450N/A
1450N/A /* make sure there is no overlap with existing surfaces */
1450N/A for (i = 0; i < RADEON_MAX_SURFACES; i++) {
1450N/A if ((dev_priv->surfaces[i].refcount != 0) &&
1450N/A (((new_lower >= dev_priv->surfaces[i].lower) &&
1450N/A (new_lower < dev_priv->surfaces[i].upper)) ||
1450N/A ((new_lower < dev_priv->surfaces[i].lower) &&
1450N/A (new_upper > dev_priv->surfaces[i].lower)))) {
1450N/A return (-1);
1450N/A }
1450N/A }
1450N/A
1450N/A /* find a virtual surface */
1450N/A for (i = 0; i < 2 * RADEON_MAX_SURFACES; i++)
1450N/A if (dev_priv->virt_surfaces[i].filp == 0)
1450N/A break;
1450N/A if (i == 2 * RADEON_MAX_SURFACES) {
1450N/A return (-1);
1450N/A }
1450N/A virt_surface_index = i;
1450N/A
1450N/A /* try to reuse an existing surface */
1450N/A for (i = 0; i < RADEON_MAX_SURFACES; i++) {
1450N/A /* extend before */
1450N/A if ((dev_priv->surfaces[i].refcount == 1) &&
1450N/A (new->flags == dev_priv->surfaces[i].flags) &&
1450N/A (new_upper + 1 == dev_priv->surfaces[i].lower)) {
1450N/A s = &(dev_priv->virt_surfaces[virt_surface_index]);
1450N/A s->surface_index = i;
1450N/A s->lower = new_lower;
1450N/A s->upper = new_upper;
1450N/A s->flags = new->flags;
1450N/A s->filp = filp;
1450N/A dev_priv->surfaces[i].refcount++;
1450N/A dev_priv->surfaces[i].lower = s->lower;
1450N/A radeon_apply_surface_regs(s->surface_index, dev_priv);
1450N/A return (virt_surface_index);
1450N/A }
1450N/A
1450N/A /* extend after */
1450N/A if ((dev_priv->surfaces[i].refcount == 1) &&
1450N/A (new->flags == dev_priv->surfaces[i].flags) &&
1450N/A (new_lower == dev_priv->surfaces[i].upper + 1)) {
1450N/A s = &(dev_priv->virt_surfaces[virt_surface_index]);
1450N/A s->surface_index = i;
1450N/A s->lower = new_lower;
1450N/A s->upper = new_upper;
1450N/A s->flags = new->flags;
1450N/A s->filp = filp;
1450N/A dev_priv->surfaces[i].refcount++;
1450N/A dev_priv->surfaces[i].upper = s->upper;
1450N/A radeon_apply_surface_regs(s->surface_index, dev_priv);
1450N/A return (virt_surface_index);
1450N/A }
1450N/A }
1450N/A
1450N/A /* okay, we need a new one */
1450N/A for (i = 0; i < RADEON_MAX_SURFACES; i++) {
1450N/A if (dev_priv->surfaces[i].refcount == 0) {
1450N/A s = &(dev_priv->virt_surfaces[virt_surface_index]);
1450N/A s->surface_index = i;
1450N/A s->lower = new_lower;
1450N/A s->upper = new_upper;
1450N/A s->flags = new->flags;
1450N/A s->filp = filp;
1450N/A dev_priv->surfaces[i].refcount = 1;
1450N/A dev_priv->surfaces[i].lower = s->lower;
1450N/A dev_priv->surfaces[i].upper = s->upper;
1450N/A dev_priv->surfaces[i].flags = s->flags;
1450N/A radeon_apply_surface_regs(s->surface_index, dev_priv);
1450N/A return (virt_surface_index);
1450N/A }
1450N/A }
1450N/A
1450N/A /* we didn't find anything */
1450N/A return (-1);
1450N/A}
1450N/A
1450N/Astatic int
1450N/Afree_surface(drm_file_t *filp, drm_radeon_private_t *dev_priv, int lower)
1450N/A{
1450N/A struct radeon_virt_surface *s;
1450N/A int i;
1450N/A
1450N/A /* find the virtual surface */
1450N/A for (i = 0; i < 2 * RADEON_MAX_SURFACES; i++) {
1450N/A s = &(dev_priv->virt_surfaces[i]);
1450N/A if (s->filp) {
1450N/A if ((lower == s->lower) && (filp == s->filp)) {
1450N/A if (dev_priv->surfaces[s->surface_index].
1450N/A lower == s->lower)
1450N/A dev_priv->surfaces[s->surface_index].
1450N/A lower = s->upper;
1450N/A
1450N/A if (dev_priv->surfaces[s->surface_index].
1450N/A upper == s->upper)
1450N/A dev_priv->surfaces[s->surface_index].
1450N/A upper = s->lower;
1450N/A
1450N/A dev_priv->surfaces[s->surface_index].refcount--;
1450N/A if (dev_priv->surfaces[s->surface_index].
1450N/A refcount == 0)
1450N/A dev_priv->surfaces[s->surface_index].
1450N/A flags = 0;
1450N/A s->filp = NULL;
1450N/A radeon_apply_surface_regs(s->surface_index,
1450N/A dev_priv);
1450N/A return (0);
1450N/A }
1450N/A }
1450N/A }
1450N/A
1450N/A return (1);
1450N/A}
1450N/A
1450N/Astatic void radeon_surfaces_release(drm_file_t *filp,
1450N/A drm_radeon_private_t *dev_priv)
1450N/A{
1450N/A int i;
1450N/A
1450N/A for (i = 0; i < 2 * RADEON_MAX_SURFACES; i++) {
1450N/A if (dev_priv->virt_surfaces[i].filp == filp)
1450N/A (void) free_surface(filp, dev_priv,
1450N/A dev_priv->virt_surfaces[i].lower);
1450N/A }
1450N/A}
1450N/A
1450N/A/*
1450N/A * IOCTL functions
1450N/A */
1450N/A/*ARGSUSED*/
1450N/Astatic int radeon_surface_alloc(DRM_IOCTL_ARGS)
1450N/A{
1450N/A DRM_DEVICE;
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_radeon_surface_alloc_t alloc;
1450N/A
1450N/A if (!dev_priv) {
1450N/A DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A DRM_COPYFROM_WITH_RETURN(&alloc, (void *)data, sizeof (alloc));
1450N/A
1450N/A if (alloc_surface(&alloc, dev_priv, fpriv) == -1)
1450N/A return (EINVAL);
1450N/A else
1450N/A return (0);
1450N/A}
1450N/A
1450N/A/*ARGSUSED*/
1450N/Astatic int radeon_surface_free(DRM_IOCTL_ARGS)
1450N/A{
1450N/A DRM_DEVICE;
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_radeon_surface_free_t memfree;
1450N/A
1450N/A if (!dev_priv) {
1450N/A DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A DRM_COPYFROM_WITH_RETURN(&memfree, (void *)data, sizeof (memfree));
1450N/A if (free_surface(fpriv, dev_priv, memfree.address)) {
1450N/A return (EINVAL);
1450N/A }
1450N/A else
1450N/A return (0);
1450N/A}
1450N/A
1450N/A/*ARGSUSED*/
1450N/Astatic int radeon_cp_clear(DRM_IOCTL_ARGS)
1450N/A{
1450N/A DRM_DEVICE;
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
1450N/A drm_radeon_clear_t clear;
1450N/A drm_radeon_clear_rect_t depth_boxes[RADEON_NR_SAREA_CLIPRECTS];
1450N/A
1450N/A LOCK_TEST_WITH_RETURN(dev, fpriv);
1450N/A
1450N/A#ifdef _MULTI_DATAMODEL
1450N/A if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
1450N/A drm_radeon_clear_32_t clear32;
1450N/A DRM_COPYFROM_WITH_RETURN(&clear32, (void *)data,
1450N/A sizeof (clear32));
1450N/A clear.flags = clear32.flags;
1450N/A clear.clear_color = clear32.clear_color;
1450N/A clear.clear_depth = clear32.clear_depth;
1450N/A clear.color_mask = clear32.color_mask;
1450N/A clear.depth_mask = clear32.depth_mask;
1450N/A clear.depth_boxes = (void*)(uintptr_t)clear32.depth_boxes;
1450N/A } else {
1450N/A#endif
1450N/A DRM_COPYFROM_WITH_RETURN(&clear, (void *)data, sizeof (clear));
1450N/A#ifdef _MULTI_DATAMODEL
1450N/A }
1450N/A#endif
1450N/A
1450N/A RING_SPACE_TEST_WITH_RETURN(dev_priv);
1450N/A
1450N/A if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
1450N/A sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
1450N/A
1450N/A if (DRM_COPY_FROM_USER(&depth_boxes, clear.depth_boxes,
1450N/A sarea_priv->nbox * sizeof (depth_boxes[0])))
1450N/A return (EFAULT);
1450N/A
1450N/A radeon_cp_dispatch_clear(dev, &clear, depth_boxes);
1450N/A
1450N/A COMMIT_RING();
1450N/A return (0);
1450N/A}
1450N/A
1450N/A/*
1450N/A * Not sure why this isn't set all the time:
1450N/A */
1450N/Astatic int radeon_do_init_pageflip(drm_device_t *dev)
1450N/A{
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A RING_LOCALS;
1450N/A
1450N/A BEGIN_RING(6);
1450N/A RADEON_WAIT_UNTIL_3D_IDLE();
1450N/A OUT_RING(CP_PACKET0(RADEON_CRTC_OFFSET_CNTL, 0));
1450N/A OUT_RING(RADEON_READ(RADEON_CRTC_OFFSET_CNTL) |
1450N/A RADEON_CRTC_OFFSET_FLIP_CNTL);
1450N/A OUT_RING(CP_PACKET0(RADEON_CRTC2_OFFSET_CNTL, 0));
1450N/A OUT_RING(RADEON_READ(RADEON_CRTC2_OFFSET_CNTL) |
1450N/A RADEON_CRTC_OFFSET_FLIP_CNTL);
1450N/A ADVANCE_RING();
1450N/A
1450N/A dev_priv->page_flipping = 1;
1450N/A dev_priv->current_page = 0;
1450N/A dev_priv->sarea_priv->pfCurrentPage = dev_priv->current_page;
1450N/A
1450N/A return (0);
1450N/A}
1450N/A
1450N/A/*
1450N/A * Called whenever a client dies, from drm_release.
1450N/A * NOTE: Lock isn't necessarily held when this is called!
1450N/A */
1450N/Astatic int radeon_do_cleanup_pageflip(drm_device_t *dev)
1450N/A{
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A
1450N/A if (dev_priv->current_page != 0)
1450N/A radeon_cp_dispatch_flip(dev);
1450N/A
1450N/A dev_priv->page_flipping = 0;
1450N/A return (0);
1450N/A}
1450N/A
1450N/A/*
1450N/A * Swapping and flipping are different operations, need different ioctls.
1450N/A * They can & should be intermixed to support multiple 3d windows.
1450N/A */
1450N/A/*ARGSUSED*/
1450N/Astatic int radeon_cp_flip(DRM_IOCTL_ARGS)
1450N/A{
1450N/A DRM_DEVICE;
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A
1450N/A LOCK_TEST_WITH_RETURN(dev, fpriv);
1450N/A
1450N/A RING_SPACE_TEST_WITH_RETURN(dev_priv);
1450N/A
1450N/A if (!dev_priv->page_flipping)
1450N/A (void) radeon_do_init_pageflip(dev);
1450N/A
1450N/A radeon_cp_dispatch_flip(dev);
1450N/A
1450N/A COMMIT_RING();
1450N/A return (0);
1450N/A}
1450N/A
1450N/A/*ARGSUSED*/
1450N/Astatic int radeon_cp_swap(DRM_IOCTL_ARGS)
1450N/A{
1450N/A DRM_DEVICE;
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
1450N/A
1450N/A LOCK_TEST_WITH_RETURN(dev, fpriv);
1450N/A
1450N/A RING_SPACE_TEST_WITH_RETURN(dev_priv);
1450N/A
1450N/A if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
1450N/A sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
1450N/A
1450N/A radeon_cp_dispatch_swap(dev);
1450N/A dev_priv->sarea_priv->ctx_owner = 0;
1450N/A
1450N/A COMMIT_RING();
1450N/A return (0);
1450N/A}
1450N/A
1450N/A/*ARGSUSED*/
1450N/Astatic int radeon_cp_vertex(DRM_IOCTL_ARGS)
1450N/A{
1450N/A DRM_DEVICE;
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_radeon_sarea_t *sarea_priv;
1450N/A drm_device_dma_t *dma = dev->dma;
1450N/A drm_buf_t *buf;
1450N/A drm_radeon_vertex_t vertex;
1450N/A drm_radeon_tcl_prim_t prim;
1450N/A
1450N/A LOCK_TEST_WITH_RETURN(dev, fpriv);
1450N/A
1450N/A if (!dev_priv) {
1450N/A DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A sarea_priv = dev_priv->sarea_priv;
1450N/A
1450N/A DRM_COPYFROM_WITH_RETURN(&vertex, (void *)data, sizeof (vertex));
1450N/A
1450N/A DRM_DEBUG("pid=%d index=%d count=%d discard=%d\n",
1450N/A DRM_CURRENTPID, vertex.idx, vertex.count, vertex.discard);
1450N/A
1450N/A if (vertex.idx < 0 || vertex.idx >= dma->buf_count) {
1450N/A DRM_ERROR("buffer index %d (of %d max)\n",
1450N/A vertex.idx, dma->buf_count - 1);
1450N/A return (EINVAL);
1450N/A }
1450N/A if (vertex.prim < 0 || vertex.prim > RADEON_PRIM_TYPE_3VRT_LINE_LIST) {
1450N/A DRM_ERROR("buffer prim %d\n", vertex.prim);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A RING_SPACE_TEST_WITH_RETURN(dev_priv);
1450N/A VB_AGE_TEST_WITH_RETURN(dev_priv);
1450N/A
1450N/A buf = dma->buflist[vertex.idx];
1450N/A
1450N/A if (buf->filp != fpriv) {
1450N/A DRM_ERROR("process %d using buffer owned by %p\n",
1450N/A DRM_CURRENTPID, (void *)buf->filp);
1450N/A return (EINVAL);
1450N/A }
1450N/A if (buf->pending) {
1450N/A DRM_ERROR("sending pending buffer %d\n", vertex.idx);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A /*
1450N/A * Build up a prim_t record:
1450N/A */
1450N/A if (vertex.count) {
1450N/A buf->used = vertex.count; /* not used? */
1450N/A
1450N/A if (sarea_priv->dirty & ~RADEON_UPLOAD_CLIPRECTS) {
1450N/A if (radeon_emit_state(dev_priv, fpriv,
1450N/A &sarea_priv->context_state,
1450N/A sarea_priv->tex_state,
1450N/A sarea_priv->dirty)) {
1450N/A DRM_ERROR("radeon_emit_state failed\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A sarea_priv->dirty &= ~(RADEON_UPLOAD_TEX0IMAGES |
1450N/A RADEON_UPLOAD_TEX1IMAGES |
1450N/A RADEON_UPLOAD_TEX2IMAGES |
1450N/A RADEON_REQUIRE_QUIESCENCE);
1450N/A }
1450N/A
1450N/A prim.start = 0;
1450N/A prim.finish = vertex.count; /* unused */
1450N/A prim.prim = vertex.prim;
1450N/A prim.numverts = vertex.count;
1450N/A prim.vc_format = dev_priv->sarea_priv->vc_format;
1450N/A
1450N/A radeon_cp_dispatch_vertex(dev, buf, &prim);
1450N/A }
1450N/A
1450N/A if (vertex.discard) {
1450N/A radeon_cp_discard_buffer(dev, buf);
1450N/A }
1450N/A
1450N/A COMMIT_RING();
1450N/A return (0);
1450N/A}
1450N/A
1450N/A/*ARGSUSED*/
1450N/Astatic int radeon_cp_indices(DRM_IOCTL_ARGS)
1450N/A{
1450N/A DRM_DEVICE;
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_radeon_sarea_t *sarea_priv;
1450N/A drm_device_dma_t *dma = dev->dma;
1450N/A drm_buf_t *buf;
1450N/A drm_radeon_indices_t elts;
1450N/A drm_radeon_tcl_prim_t prim;
1450N/A/* int count; */
1450N/A
1450N/A LOCK_TEST_WITH_RETURN(dev, fpriv);
1450N/A
1450N/A if (!dev_priv) {
1450N/A DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
1450N/A return (EINVAL);
1450N/A }
1450N/A sarea_priv = dev_priv->sarea_priv;
1450N/A
1450N/A DRM_COPYFROM_WITH_RETURN(&elts, (void *)data, sizeof (elts));
1450N/A
1450N/A DRM_DEBUG("pid=%d index=%d start=%d end=%d discard=%d\n",
1450N/A DRM_CURRENTPID, elts.idx, elts.start, elts.end, elts.discard);
1450N/A
1450N/A if (elts.idx < 0 || elts.idx >= dma->buf_count) {
1450N/A DRM_ERROR("buffer index %d (of %d max)\n",
1450N/A elts.idx, dma->buf_count - 1);
1450N/A return (EINVAL);
1450N/A }
1450N/A if (elts.prim < 0 || elts.prim > RADEON_PRIM_TYPE_3VRT_LINE_LIST) {
1450N/A DRM_ERROR("buffer prim %d\n", elts.prim);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A RING_SPACE_TEST_WITH_RETURN(dev_priv);
1450N/A VB_AGE_TEST_WITH_RETURN(dev_priv);
1450N/A
1450N/A buf = dma->buflist[elts.idx];
1450N/A
1450N/A if (buf->filp != fpriv) {
1450N/A DRM_ERROR("process %d using buffer owned by %p\n",
1450N/A DRM_CURRENTPID, (void *)buf->filp);
1450N/A return (EINVAL);
1450N/A }
1450N/A if (buf->pending) {
1450N/A DRM_ERROR("sending pending buffer %d\n", elts.idx);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A/* count = (elts.end - elts.start) / sizeof(u16); */
1450N/A elts.start -= RADEON_INDEX_PRIM_OFFSET;
1450N/A
1450N/A if (elts.start & 0x7) {
1450N/A DRM_ERROR("misaligned buffer 0x%x\n", elts.start);
1450N/A return (EINVAL);
1450N/A }
1450N/A if (elts.start < buf->used) {
1450N/A DRM_ERROR("no header 0x%x - 0x%x\n", elts.start, buf->used);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A buf->used = elts.end;
1450N/A
1450N/A if (sarea_priv->dirty & ~RADEON_UPLOAD_CLIPRECTS) {
1450N/A if (radeon_emit_state(dev_priv, fpriv,
1450N/A &sarea_priv->context_state,
1450N/A sarea_priv->tex_state,
1450N/A sarea_priv->dirty)) {
1450N/A DRM_ERROR("radeon_emit_state failed\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A sarea_priv->dirty &= ~(RADEON_UPLOAD_TEX0IMAGES |
1450N/A RADEON_UPLOAD_TEX1IMAGES |
1450N/A RADEON_UPLOAD_TEX2IMAGES |
1450N/A RADEON_REQUIRE_QUIESCENCE);
1450N/A }
1450N/A
1450N/A /*
1450N/A * Build up a prim_t record:
1450N/A */
1450N/A prim.start = elts.start;
1450N/A prim.finish = elts.end;
1450N/A prim.prim = elts.prim;
1450N/A prim.offset = 0; /* offset from start of dma buffers */
1450N/A prim.numverts = RADEON_MAX_VB_VERTS; /* duh */
1450N/A prim.vc_format = dev_priv->sarea_priv->vc_format;
1450N/A
1450N/A radeon_cp_dispatch_indices(dev, buf, &prim);
1450N/A if (elts.discard) {
1450N/A radeon_cp_discard_buffer(dev, buf);
1450N/A }
1450N/A
1450N/A COMMIT_RING();
1450N/A return (0);
1450N/A}
1450N/A
1450N/A/*ARGSUSED*/
1450N/Astatic int radeon_cp_texture(DRM_IOCTL_ARGS)
1450N/A{
1450N/A DRM_DEVICE;
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_radeon_texture_t tex;
1450N/A drm_radeon_tex_image_t image;
1450N/A int ret;
1450N/A
1450N/A LOCK_TEST_WITH_RETURN(dev, fpriv);
1450N/A
1450N/A#ifdef _MULTI_DATAMODEL
1450N/A if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
1450N/A drm_radeon_texture_32_t tex32;
1450N/A drm_radeon_tex_image_32_t image32;
1450N/A
1450N/A DRM_COPYFROM_WITH_RETURN(&tex32, (void *)data, sizeof (tex32));
1450N/A if (tex32.image == 0) {
1450N/A DRM_ERROR("null texture image!\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A if (DRM_COPY_FROM_USER(&image32,
1450N/A (void *)(uintptr_t)tex32.image, sizeof (image32))) {
1450N/A cmn_err(CE_WARN, "copyin32 failed");
1450N/A return (EFAULT);
1450N/A }
1450N/A
1450N/A tex.offset = tex32.offset;
1450N/A tex.pitch = tex32.pitch;
1450N/A tex.format = tex32.format;
1450N/A tex.width = tex32.width;
1450N/A tex.height = tex32.height;
1450N/A tex.image = (void*)(uintptr_t)tex32.image;
1450N/A
1450N/A image.x = image32.x;
1450N/A image.y = image32.y;
1450N/A image.width = image32.width;
1450N/A image.height = image32.height;
1450N/A image.data = (void*)(uintptr_t)image32.data;
1450N/A
1450N/A } else {
1450N/A#endif
1450N/A DRM_COPYFROM_WITH_RETURN(&tex, (void *)data, sizeof (tex));
1450N/A if (tex.image == NULL) {
1450N/A return (EINVAL);
1450N/A }
1450N/A if (DRM_COPY_FROM_USER(&image,
1450N/A (drm_radeon_tex_image_t *)tex.image, sizeof (image))) {
1450N/A return (EFAULT);
1450N/A }
1450N/A#ifdef _MULTI_DATAMODEL
1450N/A }
1450N/A#endif
1450N/A
1450N/A RING_SPACE_TEST_WITH_RETURN(dev_priv);
1450N/A VB_AGE_TEST_WITH_RETURN(dev_priv);
1450N/A
1450N/A ret = radeon_cp_dispatch_texture(fpriv, dev, &tex, &image, mode);
1450N/A
1450N/A COMMIT_RING();
1450N/A return (ret);
1450N/A}
1450N/A
1450N/A/*ARGSUSED*/
1450N/Astatic int radeon_cp_stipple(DRM_IOCTL_ARGS)
1450N/A{
1450N/A DRM_DEVICE;
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_radeon_stipple_t stipple;
1450N/A u32 mask[32];
1450N/A
1450N/A LOCK_TEST_WITH_RETURN(dev, fpriv);
1450N/A
1450N/A#ifdef _MULTI_DATAMODEL
1450N/A if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
1450N/A drm_radeon_stipple_32_t stipple32;
1450N/A DRM_COPYFROM_WITH_RETURN(&stipple32, (void *)data,
1450N/A sizeof (stipple32));
1450N/A stipple.mask = (void *)(uintptr_t)stipple32.mask;
1450N/A } else {
1450N/A#endif
1450N/A DRM_COPYFROM_WITH_RETURN(&stipple, (void *)data,
1450N/A sizeof (stipple));
1450N/A#ifdef _MULTI_DATAMODEL
1450N/A }
1450N/A#endif
1450N/A if (DRM_COPY_FROM_USER(&mask, stipple.mask, 32 * sizeof (u32)))
1450N/A return (EFAULT);
1450N/A
1450N/A
1450N/A RING_SPACE_TEST_WITH_RETURN(dev_priv);
1450N/A
1450N/A radeon_cp_dispatch_stipple(dev, mask);
1450N/A
1450N/A COMMIT_RING();
1450N/A return (0);
1450N/A}
1450N/A
1450N/A/*ARGSUSED*/
1450N/Astatic int radeon_cp_indirect(DRM_IOCTL_ARGS)
1450N/A{
1450N/A DRM_DEVICE;
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_device_dma_t *dma = dev->dma;
1450N/A drm_buf_t *buf;
1450N/A drm_radeon_indirect_t indirect;
1450N/A RING_LOCALS;
1450N/A
1450N/A LOCK_TEST_WITH_RETURN(dev, fpriv);
1450N/A
1450N/A if (!dev_priv) {
1450N/A DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A DRM_COPYFROM_WITH_RETURN(&indirect, (void *) data, sizeof (indirect));
1450N/A
1450N/A DRM_DEBUG("indirect: idx=%d s=%d e=%d d=%d\n",
1450N/A indirect.idx, indirect.start, indirect.end, indirect.discard);
1450N/A
1450N/A if (indirect.idx < 0 || indirect.idx >= dma->buf_count) {
1450N/A DRM_ERROR("buffer index %d (of %d max)\n",
1450N/A indirect.idx, dma->buf_count - 1);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A buf = dma->buflist[indirect.idx];
1450N/A
1450N/A if (buf->filp != fpriv) {
1450N/A DRM_ERROR("process %d using buffer owned by %p\n",
1450N/A DRM_CURRENTPID, (void *)buf->filp);
1450N/A return (EINVAL);
1450N/A }
1450N/A if (buf->pending) {
1450N/A DRM_ERROR("sending pending buffer %d\n", indirect.idx);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A if (indirect.start < buf->used) {
1450N/A DRM_ERROR("reusing indirect: start=0x%x actual=0x%x\n",
1450N/A indirect.start, buf->used);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A RING_SPACE_TEST_WITH_RETURN(dev_priv);
1450N/A VB_AGE_TEST_WITH_RETURN(dev_priv);
1450N/A
1450N/A buf->used = indirect.end;
1450N/A
1450N/A /*
1450N/A * Wait for the 3D stream to idle before the indirect buffer
1450N/A * containing 2D acceleration commands is processed.
1450N/A */
1450N/A BEGIN_RING(2);
1450N/A
1450N/A RADEON_WAIT_UNTIL_3D_IDLE();
1450N/A
1450N/A ADVANCE_RING();
1450N/A
1450N/A /*
1450N/A * Dispatch the indirect buffer full of commands from the
1450N/A * X server. This is insecure and is thus only available to
1450N/A * privileged clients.
1450N/A */
1450N/A radeon_cp_dispatch_indirect(dev, buf, indirect.start, indirect.end);
1450N/A if (indirect.discard) {
1450N/A radeon_cp_discard_buffer(dev, buf);
1450N/A }
1450N/A
1450N/A COMMIT_RING();
1450N/A return (0);
1450N/A}
1450N/A
1450N/A/*ARGSUSED*/
1450N/Astatic int radeon_cp_vertex2(DRM_IOCTL_ARGS)
1450N/A{
1450N/A DRM_DEVICE;
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_radeon_sarea_t *sarea_priv;
1450N/A drm_device_dma_t *dma = dev->dma;
1450N/A drm_buf_t *buf;
1450N/A drm_radeon_vertex2_t vertex;
1450N/A int i;
1450N/A unsigned char laststate;
1450N/A
1450N/A LOCK_TEST_WITH_RETURN(dev, fpriv);
1450N/A
1450N/A if (!dev_priv) {
1450N/A DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A sarea_priv = dev_priv->sarea_priv;
1450N/A
1450N/A
1450N/A#ifdef _MULTI_DATAMODEL
1450N/A if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
1450N/A drm_radeon_vertex2_32_t vertex32;
1450N/A
1450N/A DRM_COPYFROM_WITH_RETURN(&vertex32, (void *) data,
1450N/A sizeof (vertex32));
1450N/A vertex.idx = vertex32.idx;
1450N/A vertex.discard = vertex32.discard;
1450N/A vertex.nr_states = vertex32.nr_states;
1450N/A vertex.state = (void *) (uintptr_t)vertex32.state;
1450N/A vertex.nr_prims = vertex32.nr_prims;
1450N/A vertex.prim = (void *)(uintptr_t)vertex32.prim;
1450N/A } else {
1450N/A#endif
1450N/A DRM_COPYFROM_WITH_RETURN(&vertex, (void *) data,
1450N/A sizeof (vertex));
1450N/A#ifdef _MULTI_DATAMODEL
1450N/A }
1450N/A#endif
1450N/A
1450N/A DRM_DEBUG("pid=%d index=%d discard=%d\n",
1450N/A DRM_CURRENTPID, vertex.idx, vertex.discard);
1450N/A
1450N/A if (vertex.idx < 0 || vertex.idx >= dma->buf_count) {
1450N/A DRM_ERROR("buffer index %d (of %d max)\n",
1450N/A vertex.idx, dma->buf_count - 1);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A RING_SPACE_TEST_WITH_RETURN(dev_priv);
1450N/A VB_AGE_TEST_WITH_RETURN(dev_priv);
1450N/A
1450N/A buf = dma->buflist[vertex.idx];
1450N/A
1450N/A if (buf->filp != fpriv) {
1450N/A DRM_ERROR("process %d using buffer owned by %p\n",
1450N/A DRM_CURRENTPID, (void *)buf->filp);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A if (buf->pending) {
1450N/A DRM_ERROR("sending pending buffer %d\n", vertex.idx);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
1450N/A return (EINVAL);
1450N/A
1450N/A for (laststate = 0xff, i = 0; i < vertex.nr_prims; i++) {
1450N/A drm_radeon_prim_t prim;
1450N/A drm_radeon_tcl_prim_t tclprim;
1450N/A
1450N/A if (DRM_COPY_FROM_USER(&prim, &vertex.prim[i], sizeof (prim)))
1450N/A return (EFAULT);
1450N/A
1450N/A if (prim.stateidx != laststate) {
1450N/A drm_radeon_state_t state;
1450N/A
1450N/A if (DRM_COPY_FROM_USER(&state,
1450N/A &vertex.state[prim.stateidx], sizeof (state)))
1450N/A return (EFAULT);
1450N/A
1450N/A if (radeon_emit_state2(dev_priv, fpriv, &state)) {
1450N/A DRM_ERROR("radeon_emit_state2 failed\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A laststate = prim.stateidx;
1450N/A }
1450N/A
1450N/A tclprim.start = prim.start;
1450N/A tclprim.finish = prim.finish;
1450N/A tclprim.prim = prim.prim;
1450N/A tclprim.vc_format = prim.vc_format;
1450N/A
1450N/A if (prim.prim & RADEON_PRIM_WALK_IND) {
1450N/A tclprim.offset = prim.numverts * 64;
1450N/A tclprim.numverts = RADEON_MAX_VB_VERTS; /* duh */
1450N/A
1450N/A radeon_cp_dispatch_indices(dev, buf, &tclprim);
1450N/A } else {
1450N/A tclprim.numverts = prim.numverts;
1450N/A tclprim.offset = 0; /* not used */
1450N/A
1450N/A radeon_cp_dispatch_vertex(dev, buf, &tclprim);
1450N/A }
1450N/A
1450N/A if (sarea_priv->nbox == 1)
1450N/A sarea_priv->nbox = 0;
1450N/A }
1450N/A
1450N/A if (vertex.discard) {
1450N/A radeon_cp_discard_buffer(dev, buf);
1450N/A }
1450N/A
1450N/A COMMIT_RING();
1450N/A return (0);
1450N/A}
1450N/A
1450N/Astatic int radeon_emit_packets(drm_radeon_private_t *dev_priv,
1450N/A drm_file_t *filp_priv, drm_radeon_cmd_header_t header,
1450N/A drm_radeon_kcmd_buffer_t *cmdbuf)
1450N/A{
1450N/A int id = (int)header.packet.packet_id;
1450N/A int sz, reg;
1450N/A u32 *data = (u32 *)(uintptr_t)cmdbuf->buf;
1450N/A RING_LOCALS;
1450N/A
1450N/A if (id >= RADEON_MAX_STATE_PACKETS)
1450N/A return (EINVAL);
1450N/A
1450N/A sz = packet[id].len;
1450N/A reg = packet[id].start;
1450N/A
1450N/A if (sz * sizeof (int) > cmdbuf->bufsz) {
1450N/A DRM_ERROR("Packet size provided larger than data provided\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A if (radeon_check_and_fixup_packets(dev_priv, filp_priv, id, data)) {
1450N/A DRM_ERROR("Packet verification failed\n");
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A BEGIN_RING(sz + 1);
1450N/A OUT_RING(CP_PACKET0(reg, (sz - 1)));
1450N/A OUT_RING_TABLE(data, sz);
1450N/A ADVANCE_RING();
1450N/A
1450N/A cmdbuf->buf += sz * sizeof (int);
1450N/A cmdbuf->bufsz -= sz * sizeof (int);
1450N/A return (0);
1450N/A}
1450N/A
1450N/Astatic inline int
1450N/Aradeon_emit_scalars(drm_radeon_private_t *dev_priv,
1450N/A drm_radeon_cmd_header_t header, drm_radeon_kcmd_buffer_t *cmdbuf)
1450N/A{
1450N/A int sz = header.scalars.count;
1450N/A int start = header.scalars.offset;
1450N/A int stride = header.scalars.stride;
1450N/A RING_LOCALS;
1450N/A
1450N/A BEGIN_RING(3 + sz);
1450N/A OUT_RING(CP_PACKET0(RADEON_SE_TCL_SCALAR_INDX_REG, 0));
1450N/A OUT_RING(start | (stride << RADEON_SCAL_INDX_DWORD_STRIDE_SHIFT));
1450N/A OUT_RING(CP_PACKET0_TABLE(RADEON_SE_TCL_SCALAR_DATA_REG, sz - 1));
1450N/A OUT_RING_TABLE(cmdbuf->buf, sz);
1450N/A ADVANCE_RING();
1450N/A cmdbuf->buf += sz * sizeof (int);
1450N/A cmdbuf->bufsz -= sz * sizeof (int);
1450N/A return (0);
1450N/A}
1450N/A
1450N/A/*
1450N/A * God this is ugly
1450N/A */
1450N/Astatic inline int
1450N/Aradeon_emit_scalars2(drm_radeon_private_t *dev_priv,
1450N/A drm_radeon_cmd_header_t header, drm_radeon_kcmd_buffer_t *cmdbuf)
1450N/A{
1450N/A int sz = header.scalars.count;
1450N/A int start = ((unsigned int)header.scalars.offset) + 0x100;
1450N/A int stride = header.scalars.stride;
1450N/A RING_LOCALS;
1450N/A
1450N/A BEGIN_RING(3 + sz);
1450N/A OUT_RING(CP_PACKET0(RADEON_SE_TCL_SCALAR_INDX_REG, 0));
1450N/A OUT_RING(start | (stride << RADEON_SCAL_INDX_DWORD_STRIDE_SHIFT));
1450N/A OUT_RING(CP_PACKET0_TABLE(RADEON_SE_TCL_SCALAR_DATA_REG, sz - 1));
1450N/A OUT_RING_TABLE(cmdbuf->buf, sz);
1450N/A ADVANCE_RING();
1450N/A cmdbuf->buf += sz * sizeof (int);
1450N/A cmdbuf->bufsz -= sz * sizeof (int);
1450N/A return (0);
1450N/A}
1450N/A
1450N/Astatic inline int
1450N/Aradeon_emit_vectors(drm_radeon_private_t *dev_priv,
1450N/A drm_radeon_cmd_header_t header, drm_radeon_kcmd_buffer_t *cmdbuf)
1450N/A{
1450N/A int sz = header.vectors.count;
1450N/A int start = header.vectors.offset;
1450N/A int stride = header.vectors.stride;
1450N/A RING_LOCALS;
1450N/A
1450N/A BEGIN_RING(5 + sz);
1450N/A OUT_RING_REG(RADEON_SE_TCL_STATE_FLUSH, 0);
1450N/A OUT_RING(CP_PACKET0(RADEON_SE_TCL_VECTOR_INDX_REG, 0));
1450N/A OUT_RING(start | (stride << RADEON_VEC_INDX_OCTWORD_STRIDE_SHIFT));
1450N/A OUT_RING(CP_PACKET0_TABLE(RADEON_SE_TCL_VECTOR_DATA_REG, (sz - 1)));
1450N/A OUT_RING_TABLE(cmdbuf->buf, sz);
1450N/A ADVANCE_RING();
1450N/A
1450N/A cmdbuf->buf += sz * sizeof (int);
1450N/A cmdbuf->bufsz -= sz * sizeof (int);
1450N/A return (0);
1450N/A}
1450N/A
1450N/Astatic inline int
1450N/Aradeon_emit_veclinear(drm_radeon_private_t *dev_priv,
1450N/A drm_radeon_cmd_header_t header, drm_radeon_kcmd_buffer_t *cmdbuf)
1450N/A{
1450N/A int sz = header.veclinear.count * 4;
1450N/A int start = header.veclinear.addr_lo | (header.veclinear.addr_hi << 8);
1450N/A RING_LOCALS;
1450N/A
1450N/A if (!sz)
1450N/A return (0);
1450N/A if (sz * 4 > cmdbuf->bufsz)
1450N/A return (EINVAL);
1450N/A
1450N/A BEGIN_RING(5 + sz);
1450N/A OUT_RING_REG(RADEON_SE_TCL_STATE_FLUSH, 0);
1450N/A OUT_RING(CP_PACKET0(RADEON_SE_TCL_VECTOR_INDX_REG, 0));
1450N/A OUT_RING(start | (1 << RADEON_VEC_INDX_OCTWORD_STRIDE_SHIFT));
1450N/A OUT_RING(CP_PACKET0_TABLE(RADEON_SE_TCL_VECTOR_DATA_REG, (sz - 1)));
1450N/A OUT_RING_TABLE(cmdbuf->buf, sz);
1450N/A ADVANCE_RING();
1450N/A
1450N/A cmdbuf->buf += sz * sizeof (int);
1450N/A cmdbuf->bufsz -= sz * sizeof (int);
1450N/A return (0);
1450N/A}
1450N/A
1450N/Astatic int
1450N/Aradeon_emit_packet3(drm_device_t *dev, drm_file_t *filp_priv,
1450N/A drm_radeon_kcmd_buffer_t *cmdbuf)
1450N/A{
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A unsigned int cmdsz;
1450N/A int ret;
1450N/A RING_LOCALS;
1450N/A
1450N/A
1450N/A if ((ret = radeon_check_and_fixup_packet3(dev_priv,
1450N/A filp_priv, cmdbuf, &cmdsz))) {
1450N/A DRM_ERROR("Packet verification failed\n");
1450N/A return (ret);
1450N/A }
1450N/A
1450N/A BEGIN_RING(cmdsz);
1450N/A OUT_RING_TABLE(cmdbuf->buf, cmdsz);
1450N/A ADVANCE_RING();
1450N/A
1450N/A cmdbuf->buf += cmdsz * 4;
1450N/A cmdbuf->bufsz -= cmdsz * 4;
1450N/A return (0);
1450N/A}
1450N/A
1450N/Astatic int radeon_emit_packet3_cliprect(drm_device_t *dev,
1450N/A drm_file_t *filp_priv,
1450N/A drm_radeon_kcmd_buffer_t *cmdbuf,
1450N/A int orig_nbox)
1450N/A{
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_clip_rect_t box;
1450N/A unsigned int cmdsz;
1450N/A int ret;
1450N/A drm_clip_rect_t __user *boxes = cmdbuf->boxes;
1450N/A int i = 0;
1450N/A RING_LOCALS;
1450N/A
1450N/A if ((ret = radeon_check_and_fixup_packet3(dev_priv,
1450N/A filp_priv, cmdbuf, &cmdsz))) {
1450N/A DRM_ERROR("Packet verification failed\n");
1450N/A return (ret);
1450N/A }
1450N/A
1450N/A if (!orig_nbox)
1450N/A goto out;
1450N/A
1450N/A do {
1450N/A if (i < cmdbuf->nbox) {
1450N/A if (DRM_COPY_FROM_USER(&box, &boxes[i], sizeof (box)))
1450N/A return (EFAULT);
1450N/A /*
1450N/A * FIXME The second and subsequent times round
1450N/A * this loop, send a WAIT_UNTIL_3D_IDLE before
1450N/A * calling emit_clip_rect(). This fixes a
1450N/A * lockup on fast machines when sending
1450N/A * several cliprects with a cmdbuf, as when
1450N/A * waving a 2D window over a 3D
1450N/A * window. Something in the commands from user
1450N/A * space seems to hang the card when they're
1450N/A * sent several times in a row. That would be
1450N/A * the correct place to fix it but this works
1450N/A * around it until I can figure that out - Tim
1450N/A * Smith
1450N/A */
1450N/A if (i) {
1450N/A BEGIN_RING(2);
1450N/A RADEON_WAIT_UNTIL_3D_IDLE();
1450N/A ADVANCE_RING();
1450N/A }
1450N/A radeon_emit_clip_rect(dev_priv, &box);
1450N/A }
1450N/A
1450N/A BEGIN_RING(cmdsz);
1450N/A OUT_RING_TABLE(cmdbuf->buf, cmdsz);
1450N/A ADVANCE_RING();
1450N/A
1450N/A } while (++i < cmdbuf->nbox);
1450N/A if (cmdbuf->nbox == 1)
1450N/A cmdbuf->nbox = 0;
1450N/A
1450N/Aout:
1450N/A cmdbuf->buf += cmdsz * 4;
1450N/A cmdbuf->bufsz -= cmdsz * 4;
1450N/A return (0);
1450N/A}
1450N/A
1450N/Astatic int
1450N/Aradeon_emit_wait(drm_device_t *dev, int flags)
1450N/A{
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A RING_LOCALS;
1450N/A
1450N/A DRM_DEBUG("%s: %x\n", __FUNCTION__, flags);
1450N/A switch (flags) {
1450N/A case RADEON_WAIT_2D:
1450N/A BEGIN_RING(2);
1450N/A RADEON_WAIT_UNTIL_2D_IDLE();
1450N/A ADVANCE_RING();
1450N/A break;
1450N/A case RADEON_WAIT_3D:
1450N/A BEGIN_RING(2);
1450N/A RADEON_WAIT_UNTIL_3D_IDLE();
1450N/A ADVANCE_RING();
1450N/A break;
1450N/A case RADEON_WAIT_2D | RADEON_WAIT_3D:
1450N/A BEGIN_RING(2);
1450N/A RADEON_WAIT_UNTIL_IDLE();
1450N/A ADVANCE_RING();
1450N/A break;
1450N/A default:
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A return (0);
1450N/A}
1450N/A
1450N/A/*ARGSUSED*/
1450N/Astatic int radeon_cp_cmdbuf(DRM_IOCTL_ARGS)
1450N/A{
1450N/A DRM_DEVICE;
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_device_dma_t *dma = dev->dma;
1450N/A drm_buf_t *buf = NULL;
1450N/A int idx;
1450N/A drm_radeon_kcmd_buffer_t cmdbuf;
1450N/A drm_radeon_cmd_header_t header;
1450N/A int orig_nbox, orig_bufsz;
1450N/A char *kbuf = NULL;
1450N/A
1450N/A LOCK_TEST_WITH_RETURN(dev, fpriv);
1450N/A
1450N/A if (!dev_priv) {
1450N/A DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A#ifdef _MULTI_DATAMODEL
1450N/A if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
1450N/A drm_radeon_kcmd_buffer_32_t cmdbuf32;
1450N/A
1450N/A DRM_COPYFROM_WITH_RETURN(&cmdbuf32, (void *)data,
1450N/A sizeof (cmdbuf32));
1450N/A cmdbuf.bufsz = cmdbuf32.bufsz;
1450N/A cmdbuf.buf = (void *)(uintptr_t)cmdbuf32.buf;
1450N/A cmdbuf.nbox = cmdbuf32.nbox;
1450N/A cmdbuf.boxes = (void *)(uintptr_t)cmdbuf32.boxes;
1450N/A } else {
1450N/A#endif
1450N/A DRM_COPYFROM_WITH_RETURN(&cmdbuf, (void *) data,
1450N/A sizeof (cmdbuf));
1450N/A#ifdef _MULTI_DATAMODEL
1450N/A }
1450N/A#endif
1450N/A RING_SPACE_TEST_WITH_RETURN(dev_priv);
1450N/A VB_AGE_TEST_WITH_RETURN(dev_priv);
1450N/A
1450N/A if (cmdbuf.bufsz > 64 * 1024 || cmdbuf.bufsz < 0) {
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A /*
1450N/A * Allocate an in-kernel area and copy in the cmdbuf. Do this
1450N/A * to avoid races between checking values and using those values
1450N/A * in other code, and simply to avoid a lot of function calls
1450N/A * to copy in data.
1450N/A */
1450N/A orig_bufsz = cmdbuf.bufsz;
1450N/A if (orig_bufsz != 0) {
1450N/A kbuf = drm_alloc(cmdbuf.bufsz, DRM_MEM_DRIVER);
1450N/A if (kbuf == NULL)
1450N/A return (ENOMEM);
1450N/A if (DRM_COPY_FROM_USER(kbuf, (void *)cmdbuf.buf,
1450N/A cmdbuf.bufsz)) {
1450N/A drm_free(kbuf, orig_bufsz, DRM_MEM_DRIVER);
1450N/A return (EFAULT);
1450N/A }
1450N/A cmdbuf.buf = kbuf;
1450N/A }
1450N/A
1450N/A orig_nbox = cmdbuf.nbox;
1450N/A
1450N/A if (dev_priv->microcode_version == UCODE_R300) {
1450N/A int temp;
1450N/A temp = r300_do_cp_cmdbuf(dev, fpriv, &cmdbuf);
1450N/A
1450N/A if (orig_bufsz != 0)
1450N/A drm_free(kbuf, orig_bufsz, DRM_MEM_DRIVER);
1450N/A
1450N/A return (temp);
1450N/A }
1450N/A
1450N/A /* microcode_version != r300 */
1450N/A while (cmdbuf.bufsz >= sizeof (header)) {
1450N/A
1450N/A header.i = *(int *)(uintptr_t)cmdbuf.buf;
1450N/A cmdbuf.buf += sizeof (header);
1450N/A cmdbuf.bufsz -= sizeof (header);
1450N/A
1450N/A switch (header.header.cmd_type) {
1450N/A case RADEON_CMD_PACKET:
1450N/A DRM_DEBUG("RADEON_CMD_PACKET\n");
1450N/A if (radeon_emit_packets
1450N/A (dev_priv, fpriv, header, &cmdbuf)) {
1450N/A DRM_ERROR("radeon_emit_packets failed\n");
1450N/A goto err;
1450N/A }
1450N/A break;
1450N/A
1450N/A case RADEON_CMD_SCALARS:
1450N/A DRM_DEBUG("RADEON_CMD_SCALARS\n");
1450N/A if (radeon_emit_scalars(dev_priv, header, &cmdbuf)) {
1450N/A DRM_ERROR("radeon_emit_scalars failed\n");
1450N/A goto err;
1450N/A }
1450N/A break;
1450N/A
1450N/A case RADEON_CMD_VECTORS:
1450N/A DRM_DEBUG("RADEON_CMD_VECTORS\n");
1450N/A if (radeon_emit_vectors(dev_priv, header, &cmdbuf)) {
1450N/A DRM_ERROR("radeon_emit_vectors failed\n");
1450N/A goto err;
1450N/A }
1450N/A break;
1450N/A
1450N/A case RADEON_CMD_DMA_DISCARD:
1450N/A DRM_DEBUG("RADEON_CMD_DMA_DISCARD\n");
1450N/A idx = header.dma.buf_idx;
1450N/A if (idx < 0 || idx >= dma->buf_count) {
1450N/A DRM_ERROR("buffer index %d (of %d max)\n",
1450N/A idx, dma->buf_count - 1);
1450N/A goto err;
1450N/A }
1450N/A
1450N/A buf = dma->buflist[idx];
1450N/A if (buf->filp != fpriv || buf->pending) {
1450N/A DRM_ERROR("bad buffer %p %p %d\n",
1450N/A (void *)buf->filp, (void *)fpriv,
1450N/A buf->pending);
1450N/A goto err;
1450N/A }
1450N/A
1450N/A radeon_cp_discard_buffer(dev, buf);
1450N/A break;
1450N/A
1450N/A case RADEON_CMD_PACKET3:
1450N/A DRM_DEBUG("RADEON_CMD_PACKET3\n");
1450N/A if (radeon_emit_packet3(dev, fpriv, &cmdbuf)) {
1450N/A DRM_ERROR("radeon_emit_packet3 failed\n");
1450N/A goto err;
1450N/A }
1450N/A break;
1450N/A
1450N/A case RADEON_CMD_PACKET3_CLIP:
1450N/A DRM_DEBUG("RADEON_CMD_PACKET3_CLIP\n");
1450N/A if (radeon_emit_packet3_cliprect
1450N/A (dev, fpriv, &cmdbuf, orig_nbox)) {
1450N/A DRM_ERROR("radeon_emit_packet3_clip failed\n");
1450N/A goto err;
1450N/A }
1450N/A break;
1450N/A
1450N/A case RADEON_CMD_SCALARS2:
1450N/A DRM_DEBUG("RADEON_CMD_SCALARS2\n");
1450N/A if (radeon_emit_scalars2(dev_priv, header, &cmdbuf)) {
1450N/A DRM_ERROR("radeon_emit_scalars2 failed\n");
1450N/A goto err;
1450N/A }
1450N/A break;
1450N/A
1450N/A case RADEON_CMD_WAIT:
1450N/A DRM_DEBUG("RADEON_CMD_WAIT\n");
1450N/A if (radeon_emit_wait(dev, header.wait.flags)) {
1450N/A DRM_ERROR("radeon_emit_wait failed\n");
1450N/A goto err;
1450N/A }
1450N/A break;
1450N/A case RADEON_CMD_VECLINEAR:
1450N/A DRM_DEBUG("RADEON_CMD_VECLINEAR\n");
1450N/A if (radeon_emit_veclinear(dev_priv, header, &cmdbuf)) {
1450N/A DRM_ERROR("radeon_emit_veclinear failed\n");
1450N/A goto err;
1450N/A }
1450N/A break;
1450N/A
1450N/A default:
1450N/A DRM_ERROR("bad cmd_type %d at %p\n",
1450N/A header.header.cmd_type,
1450N/A (void *)(cmdbuf.buf - sizeof (header)));
1450N/A goto err;
1450N/A }
1450N/A }
1450N/A
1450N/A if (orig_bufsz != 0)
1450N/A drm_free(kbuf, orig_bufsz, DRM_MEM_DRIVER);
1450N/A
1450N/A COMMIT_RING();
1450N/A return (0);
1450N/A
1450N/Aerr:
1450N/A if (orig_bufsz != 0)
1450N/A drm_free(kbuf, orig_bufsz, DRM_MEM_DRIVER);
1450N/A return (EINVAL);
1450N/A}
1450N/A
1450N/A/*ARGSUSED*/
1450N/Astatic int radeon_cp_getparam(DRM_IOCTL_ARGS)
1450N/A{
1450N/A DRM_DEVICE;
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_radeon_getparam_t param;
1450N/A int value;
1450N/A
1450N/A if (!dev_priv) {
1450N/A DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A#ifdef _MULTI_DATAMODEL
1450N/A if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
1450N/A drm_radeon_getparam_32_t param32;
1450N/A
1450N/A DRM_COPYFROM_WITH_RETURN(&param32,
1450N/A (drm_radeon_getparam_32_t *)data, sizeof (param32));
1450N/A param.param = param32.param;
1450N/A param.value = (void *)(uintptr_t)param32.value;
1450N/A } else {
1450N/A#endif
1450N/A DRM_COPYFROM_WITH_RETURN(&param,
1450N/A (drm_radeon_getparam_t *)data, sizeof (param));
1450N/A#ifdef _MULTI_DATAMODEL
1450N/A }
1450N/A#endif
1450N/A DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
1450N/A
1450N/A switch (param.param) {
1450N/A case RADEON_PARAM_GART_BUFFER_OFFSET:
1450N/A value = dev_priv->gart_buffers_offset;
1450N/A break;
1450N/A case RADEON_PARAM_LAST_FRAME:
1450N/A dev_priv->stats.last_frame_reads++;
1450N/A value = GET_SCRATCH(0);
1450N/A break;
1450N/A case RADEON_PARAM_LAST_DISPATCH:
1450N/A value = GET_SCRATCH(1);
1450N/A break;
1450N/A case RADEON_PARAM_LAST_CLEAR:
1450N/A dev_priv->stats.last_clear_reads++;
1450N/A value = GET_SCRATCH(2);
1450N/A break;
1450N/A case RADEON_PARAM_IRQ_NR:
1450N/A value = dev->irq;
1450N/A break;
1450N/A case RADEON_PARAM_GART_BASE:
1450N/A value = dev_priv->gart_vm_start;
1450N/A break;
1450N/A case RADEON_PARAM_REGISTER_HANDLE:
1450N/A value = dev_priv->mmio->offset;
1450N/A break;
1450N/A case RADEON_PARAM_STATUS_HANDLE:
1450N/A value = dev_priv->ring_rptr_offset;
1450N/A break;
1450N/A#ifndef __LP64__
1450N/A /*
1450N/A * This ioctl() doesn't work on 64-bit platforms because
1450N/A * hw_lock is a pointer which can't fit into an int-sized
1450N/A * variable. According to Michel Dänzer, the ioctl) is
1450N/A * only used on embedded platforms, so not supporting it
1450N/A * shouldn't be a problem. If the same functionality is
1450N/A * needed on 64-bit platforms, a new ioctl() would have
1450N/A * to be added, so backwards-compatibility for the embedded
1450N/A * platforms can be maintained. --davidm 4-Feb-2004.
1450N/A */
1450N/A case RADEON_PARAM_SAREA_HANDLE:
1450N/A /* The lock is the first dword in the sarea. */
1450N/A value = (long)dev->lock.hw_lock;
1450N/A break;
1450N/A#endif
1450N/A case RADEON_PARAM_GART_TEX_HANDLE:
1450N/A value = dev_priv->gart_textures_offset;
1450N/A break;
1450N/A case RADEON_PARAM_SCRATCH_OFFSET:
1450N/A if (!dev_priv->writeback_works)
1450N/A return (EINVAL);
1450N/A value = RADEON_SCRATCH_REG_OFFSET;
1450N/A break;
1450N/A
1450N/A case RADEON_PARAM_CARD_TYPE:
1450N/A if (dev_priv->flags & RADEON_IS_PCIE)
1450N/A value = RADEON_CARD_PCIE;
1450N/A else if (dev_priv->flags & RADEON_IS_AGP)
1450N/A value = RADEON_CARD_AGP;
1450N/A else
1450N/A value = RADEON_CARD_PCI;
1450N/A break;
1450N/A case RADEON_PARAM_VBLANK_CRTC:
1450N/A value = radeon_vblank_crtc_get(dev);
1450N/A break;
1450N/A default:
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A if (DRM_COPY_TO_USER(param.value, &value, sizeof (int))) {
1450N/A DRM_ERROR("copy_to_user\n");
1450N/A return (EFAULT);
1450N/A }
1450N/A return (0);
1450N/A}
1450N/A
1450N/A/*ARGSUSED*/
1450N/Astatic int radeon_cp_setparam(DRM_IOCTL_ARGS)
1450N/A{
1450N/A DRM_DEVICE;
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A drm_radeon_setparam_t sp;
1450N/A struct drm_radeon_driver_file_fields *radeon_priv;
1450N/A
1450N/A if (!dev_priv) {
1450N/A DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A#ifdef _MULTI_DATAMODEL
1450N/A if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
1450N/A drm_radeon_setparam_32_t sp32;
1450N/A
1450N/A DRM_COPYFROM_WITH_RETURN(&sp32, (void *) data, sizeof (sp32));
1450N/A sp.param = sp32.param;
1450N/A sp.value = sp32.value;
1450N/A } else {
1450N/A#endif
1450N/A DRM_COPYFROM_WITH_RETURN(&sp, (void *) data, sizeof (sp));
1450N/A#ifdef _MULTI_DATAMODEL
1450N/A }
1450N/A#endif
1450N/A switch (sp.param) {
1450N/A case RADEON_SETPARAM_FB_LOCATION:
1450N/A radeon_priv = fpriv->driver_priv;
1450N/A radeon_priv->radeon_fb_delta = dev_priv->fb_location - sp.value;
1450N/A break;
1450N/A case RADEON_SETPARAM_SWITCH_TILING:
1450N/A if (sp.value == 0) {
1450N/A DRM_DEBUG("color tiling disabled\n");
1450N/A dev_priv->front_pitch_offset &= ~RADEON_DST_TILE_MACRO;
1450N/A dev_priv->back_pitch_offset &= ~RADEON_DST_TILE_MACRO;
1450N/A dev_priv->sarea_priv->tiling_enabled = 0;
1450N/A } else if (sp.value == 1) {
1450N/A DRM_DEBUG("color tiling enabled\n");
1450N/A dev_priv->front_pitch_offset |= RADEON_DST_TILE_MACRO;
1450N/A dev_priv->back_pitch_offset |= RADEON_DST_TILE_MACRO;
1450N/A dev_priv->sarea_priv->tiling_enabled = 1;
1450N/A }
1450N/A break;
1450N/A case RADEON_SETPARAM_PCIGART_LOCATION:
1450N/A dev_priv->pcigart_offset = (unsigned long)sp.value;
1450N/A break;
1450N/A case RADEON_SETPARAM_NEW_MEMMAP:
1450N/A dev_priv->new_memmap = (int)sp.value;
1450N/A break;
1450N/A case RADEON_SETPARAM_VBLANK_CRTC:
1450N/A return (radeon_vblank_crtc_set(dev, sp.value));
1450N/A default:
1450N/A DRM_DEBUG("Invalid parameter %d\n", sp.param);
1450N/A return (EINVAL);
1450N/A }
1450N/A
1450N/A return (0);
1450N/A}
1450N/A
1450N/A/*
1450N/A * When a client dies:
1450N/A * - Check for and clean up flipped page state
1450N/A * - Free any alloced GART memory.
1450N/A * - Free any alloced radeon surfaces.
1450N/A *
1450N/A * DRM infrastructure takes care of reclaiming dma buffers.
1450N/A */
1450N/Avoid
1450N/Aradeon_driver_preclose(drm_device_t *dev, drm_file_t *filp)
1450N/A{
1450N/A if (dev->dev_private) {
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A if (dev_priv->page_flipping) {
1450N/A (void) radeon_do_cleanup_pageflip(dev);
1450N/A }
1450N/A radeon_mem_release(filp, dev_priv->gart_heap);
1450N/A radeon_mem_release(filp, dev_priv->fb_heap);
1450N/A radeon_surfaces_release(filp, dev_priv);
1450N/A }
1450N/A}
1450N/A
1450N/Avoid
1450N/Aradeon_driver_lastclose(drm_device_t *dev)
1450N/A{
1450N/A radeon_do_release(dev);
1450N/A}
1450N/A
1450N/Aint
1450N/Aradeon_driver_open(drm_device_t *dev, drm_file_t *filp_priv)
1450N/A{
1450N/A drm_radeon_private_t *dev_priv = dev->dev_private;
1450N/A struct drm_radeon_driver_file_fields *radeon_priv;
1450N/A
1450N/A radeon_priv =
1450N/A (struct drm_radeon_driver_file_fields *)
1450N/A drm_alloc(sizeof (*radeon_priv), DRM_MEM_FILES);
1450N/A
1450N/A if (!radeon_priv)
1450N/A return (-ENOMEM);
1450N/A
1450N/A filp_priv->driver_priv = radeon_priv;
1450N/A
1450N/A if (dev_priv)
1450N/A radeon_priv->radeon_fb_delta = dev_priv->fb_location;
1450N/A else
1450N/A radeon_priv->radeon_fb_delta = 0;
1450N/A return (0);
1450N/A}
1450N/A
1450N/A/*ARGSUSED*/
1450N/Avoid
1450N/Aradeon_driver_postclose(drm_device_t *dev, drm_file_t *filp_priv)
1450N/A{
1450N/A struct drm_radeon_driver_file_fields *radeon_priv =
1450N/A filp_priv->driver_priv;
1450N/A
1450N/A drm_free(radeon_priv, sizeof (* radeon_priv), DRM_MEM_FILES);
1450N/A}
1450N/A
1450N/A#ifndef __sparc
1450N/Adrm_ioctl_desc_t radeon_ioctls[] = {
1450N/A [DRM_IOCTL_NR(DRM_RADEON_CP_INIT)] =
1450N/A {radeon_cp_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_CP_START)] =
1450N/A {radeon_cp_start, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_CP_STOP)] =
1450N/A {radeon_cp_stop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_CP_RESET)] =
1450N/A {radeon_cp_reset, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_CP_IDLE)] =
1450N/A {radeon_cp_idle, DRM_AUTH},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_CP_RESUME)] =
1450N/A {radeon_cp_resume, DRM_AUTH},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_RESET)] =
1450N/A {radeon_engine_reset, DRM_AUTH},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_FULLSCREEN)] =
1450N/A {radeon_fullscreen, DRM_AUTH},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_SWAP)] =
1450N/A {radeon_cp_swap, DRM_AUTH},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_CLEAR)] =
1450N/A {radeon_cp_clear, DRM_AUTH},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_VERTEX)] =
1450N/A {radeon_cp_vertex, DRM_AUTH},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_INDICES)] =
1450N/A {radeon_cp_indices, DRM_AUTH},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_TEXTURE)] =
1450N/A {radeon_cp_texture, DRM_AUTH},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_STIPPLE)] =
1450N/A {radeon_cp_stipple, DRM_AUTH},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_INDIRECT)] =
1450N/A {radeon_cp_indirect, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_VERTEX2)] =
1450N/A {radeon_cp_vertex2, DRM_AUTH},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_CMDBUF)] =
1450N/A {radeon_cp_cmdbuf, DRM_AUTH},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_GETPARAM)] =
1450N/A {radeon_cp_getparam, DRM_AUTH},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_FLIP)] =
1450N/A {radeon_cp_flip, DRM_AUTH},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_ALLOC)] =
1450N/A {radeon_mem_alloc, DRM_AUTH},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_FREE)] =
1450N/A {radeon_mem_free, DRM_AUTH},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_INIT_HEAP)] =
1450N/A {radeon_mem_init_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_IRQ_EMIT)] =
1450N/A {radeon_irq_emit, DRM_AUTH},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_IRQ_WAIT)] =
1450N/A {radeon_irq_wait, DRM_AUTH},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_SETPARAM)] =
1450N/A {radeon_cp_setparam, DRM_AUTH},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_SURF_ALLOC)] =
1450N/A {radeon_surface_alloc, DRM_AUTH},
1450N/A [DRM_IOCTL_NR(DRM_RADEON_SURF_FREE)] =
1450N/A {radeon_surface_free, DRM_AUTH}
1450N/A};
1450N/A#else
1450N/Adrm_ioctl_desc_t radeon_ioctls[] = {
1450N/A {radeon_cp_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
1450N/A {radeon_cp_start, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
1450N/A {radeon_cp_stop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
1450N/A {radeon_cp_reset, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
1450N/A {radeon_cp_idle, DRM_AUTH},
1450N/A {radeon_engine_reset, DRM_AUTH},
1450N/A {radeon_fullscreen, DRM_AUTH},
1450N/A {radeon_cp_swap, DRM_AUTH},
1450N/A {radeon_cp_clear, DRM_AUTH},
1450N/A {radeon_cp_vertex, DRM_AUTH},
1450N/A {radeon_cp_indices, DRM_AUTH},
1450N/A {NULL, DRM_AUTH},
1450N/A {radeon_cp_stipple, DRM_AUTH},
1450N/A {radeon_cp_indirect, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
1450N/A {radeon_cp_texture, DRM_AUTH},
1450N/A {radeon_cp_vertex2, DRM_AUTH},
1450N/A {radeon_cp_cmdbuf, DRM_AUTH},
1450N/A {radeon_cp_getparam, DRM_AUTH},
1450N/A {radeon_cp_flip, DRM_AUTH},
1450N/A {radeon_mem_alloc, DRM_AUTH},
1450N/A {radeon_mem_free, DRM_AUTH},
1450N/A {radeon_mem_init_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
1450N/A {radeon_irq_emit, DRM_AUTH},
1450N/A {radeon_irq_wait, DRM_AUTH},
1450N/A {radeon_cp_resume, DRM_AUTH},
1450N/A {radeon_cp_setparam, DRM_AUTH},
1450N/A {radeon_surface_alloc, DRM_AUTH},
1450N/A {radeon_surface_free, DRM_AUTH},
1450N/A};
1450N/A#endif
1450N/A
1450N/Aint radeon_max_ioctl = DRM_ARRAY_SIZE(radeon_ioctls);