2007-06-26 14:10:30 -06:00
|
|
|
/****************************************************************************
|
2007-07-24 14:36:02 -06:00
|
|
|
* Copyright (C) 2003-2006 by XGI Technology, Taiwan.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
2007-06-26 14:10:30 -06:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
2007-07-24 14:36:02 -06:00
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation on the rights to use, copy, modify, merge,
|
|
|
|
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
|
* and to permit persons to whom the Software is furnished to do so,
|
|
|
|
* subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* XGI AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
2007-06-26 14:10:30 -06:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "xgi_drv.h"
|
|
|
|
#include "xgi_regs.h"
|
|
|
|
#include "xgi_misc.h"
|
|
|
|
#include "xgi_cmdlist.h"
|
|
|
|
|
2007-08-15 22:05:26 -06:00
|
|
|
static void xgi_emit_flush(struct xgi_info * info, bool stop);
|
|
|
|
static void xgi_emit_nop(struct xgi_info * info);
|
2007-07-20 11:57:40 -06:00
|
|
|
static unsigned int get_batch_command(enum xgi_batch_type type);
|
2007-07-21 21:34:56 -06:00
|
|
|
static void triggerHWCommandList(struct xgi_info * info);
|
2007-07-21 21:39:22 -06:00
|
|
|
static void xgi_cmdlist_reset(struct xgi_info * info);
|
2007-06-26 14:10:30 -06:00
|
|
|
|
2007-08-14 14:20:37 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Graphic engine register (2d/3d) acessing interface
|
|
|
|
*/
|
|
|
|
static inline void dwWriteReg(struct drm_map * map, u32 addr, u32 data)
|
|
|
|
{
|
|
|
|
#ifdef XGI_MMIO_DEBUG
|
|
|
|
DRM_INFO("mmio_map->handle = 0x%p, addr = 0x%x, data = 0x%x\n",
|
|
|
|
map->handle, addr, data);
|
|
|
|
#endif
|
2007-10-10 16:25:30 -06:00
|
|
|
DRM_WRITE32(map, addr, data);
|
2007-08-14 14:20:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-09 16:23:13 -06:00
|
|
|
int xgi_cmdlist_initialize(struct xgi_info * info, size_t size,
|
|
|
|
struct drm_file * filp)
|
2007-06-26 14:10:30 -06:00
|
|
|
{
|
2007-07-09 16:59:09 -06:00
|
|
|
struct xgi_mem_alloc mem_alloc = {
|
2007-08-06 17:09:05 -06:00
|
|
|
.location = XGI_MEMLOC_NON_LOCAL,
|
2007-07-09 16:59:09 -06:00
|
|
|
.size = size,
|
|
|
|
};
|
2007-07-19 20:08:47 -06:00
|
|
|
int err;
|
2007-06-26 14:10:30 -06:00
|
|
|
|
2007-08-09 16:23:13 -06:00
|
|
|
err = xgi_alloc(info, &mem_alloc, filp);
|
2007-07-19 20:08:47 -06:00
|
|
|
if (err) {
|
|
|
|
return err;
|
2007-06-26 14:10:30 -06:00
|
|
|
}
|
|
|
|
|
2007-07-24 17:17:30 -06:00
|
|
|
info->cmdring.ptr = xgi_find_pcie_virt(info, mem_alloc.hw_addr);
|
2007-07-21 22:35:06 -06:00
|
|
|
info->cmdring.size = mem_alloc.size;
|
|
|
|
info->cmdring.ring_hw_base = mem_alloc.hw_addr;
|
|
|
|
info->cmdring.last_ptr = NULL;
|
|
|
|
info->cmdring.ring_offset = 0;
|
2007-06-26 14:10:30 -06:00
|
|
|
|
2007-07-19 20:08:47 -06:00
|
|
|
return 0;
|
2007-06-26 14:10:30 -06:00
|
|
|
}
|
|
|
|
|
2007-07-20 11:57:40 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get_batch_command - Get the command ID for the current begin type.
|
|
|
|
* @type: Type of the current batch
|
|
|
|
*
|
|
|
|
* See section 3.2.2 "Begin" (page 15) of the 3D SPG.
|
|
|
|
*
|
|
|
|
* This function assumes that @type is on the range [0,3].
|
|
|
|
*/
|
|
|
|
unsigned int get_batch_command(enum xgi_batch_type type)
|
|
|
|
{
|
|
|
|
static const unsigned int ports[4] = {
|
|
|
|
0x30 >> 2, 0x40 >> 2, 0x50 >> 2, 0x20 >> 2
|
|
|
|
};
|
|
|
|
|
|
|
|
return ports[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-27 16:45:59 -06:00
|
|
|
int xgi_submit_cmdlist(struct drm_device * dev, void * data,
|
|
|
|
struct drm_file * filp)
|
2007-06-26 14:10:30 -06:00
|
|
|
{
|
2007-07-27 16:45:59 -06:00
|
|
|
struct xgi_info *const info = dev->dev_private;
|
|
|
|
const struct xgi_cmd_info *const pCmdInfo =
|
|
|
|
(struct xgi_cmd_info *) data;
|
2007-07-21 21:34:56 -06:00
|
|
|
const unsigned int cmd = get_batch_command(pCmdInfo->type);
|
2007-07-20 12:29:16 -06:00
|
|
|
u32 begin[4];
|
2007-06-26 14:10:30 -06:00
|
|
|
|
|
|
|
|
2007-07-21 21:34:56 -06:00
|
|
|
begin[0] = (cmd << 24) | BEGIN_VALID_MASK
|
2007-08-15 22:05:26 -06:00
|
|
|
| (BEGIN_BEGIN_IDENTIFICATION_MASK & info->next_sequence);
|
2007-07-21 21:34:56 -06:00
|
|
|
begin[1] = BEGIN_LINK_ENABLE_MASK | pCmdInfo->size;
|
|
|
|
begin[2] = pCmdInfo->hw_addr >> 4;
|
2007-07-20 12:29:16 -06:00
|
|
|
begin[3] = 0;
|
|
|
|
|
2007-07-21 22:35:06 -06:00
|
|
|
if (info->cmdring.last_ptr == NULL) {
|
2007-07-20 11:57:40 -06:00
|
|
|
const unsigned int portOffset = BASE_3D_ENG + (cmd << 2);
|
2007-06-26 14:10:30 -06:00
|
|
|
|
|
|
|
|
2007-07-19 20:05:52 -06:00
|
|
|
/* Enable PCI Trigger Mode
|
|
|
|
*/
|
2007-07-19 11:29:18 -06:00
|
|
|
dwWriteReg(info->mmio_map,
|
|
|
|
BASE_3D_ENG + M2REG_AUTO_LINK_SETTING_ADDRESS,
|
2007-06-26 14:10:30 -06:00
|
|
|
(M2REG_AUTO_LINK_SETTING_ADDRESS << 22) |
|
|
|
|
M2REG_CLEAR_COUNTERS_MASK | 0x08 |
|
|
|
|
M2REG_PCI_TRIGGER_MODE_MASK);
|
|
|
|
|
2007-07-19 11:29:18 -06:00
|
|
|
dwWriteReg(info->mmio_map,
|
|
|
|
BASE_3D_ENG + M2REG_AUTO_LINK_SETTING_ADDRESS,
|
2007-06-26 14:10:30 -06:00
|
|
|
(M2REG_AUTO_LINK_SETTING_ADDRESS << 22) | 0x08 |
|
|
|
|
M2REG_PCI_TRIGGER_MODE_MASK);
|
|
|
|
|
|
|
|
|
2007-07-19 20:05:52 -06:00
|
|
|
/* Send PCI begin command
|
|
|
|
*/
|
2007-07-20 12:29:16 -06:00
|
|
|
dwWriteReg(info->mmio_map, portOffset, begin[0]);
|
|
|
|
dwWriteReg(info->mmio_map, portOffset + 4, begin[1]);
|
|
|
|
dwWriteReg(info->mmio_map, portOffset + 8, begin[2]);
|
|
|
|
dwWriteReg(info->mmio_map, portOffset + 12, begin[3]);
|
2007-06-26 14:10:30 -06:00
|
|
|
} else {
|
2007-07-23 19:50:07 -06:00
|
|
|
DRM_DEBUG("info->cmdring.last_ptr != NULL\n");
|
2007-06-26 14:10:30 -06:00
|
|
|
|
2007-07-21 21:34:56 -06:00
|
|
|
if (pCmdInfo->type == BTYPE_3D) {
|
2007-08-15 22:05:26 -06:00
|
|
|
xgi_emit_flush(info, FALSE);
|
2007-06-26 14:10:30 -06:00
|
|
|
}
|
|
|
|
|
2007-10-03 15:08:18 -06:00
|
|
|
info->cmdring.last_ptr[1] = cpu_to_le32(begin[1]);
|
|
|
|
info->cmdring.last_ptr[2] = cpu_to_le32(begin[2]);
|
|
|
|
info->cmdring.last_ptr[3] = cpu_to_le32(begin[3]);
|
2007-08-15 22:05:26 -06:00
|
|
|
DRM_WRITEMEMORYBARRIER();
|
2007-10-03 15:08:18 -06:00
|
|
|
info->cmdring.last_ptr[0] = cpu_to_le32(begin[0]);
|
2007-07-20 12:29:16 -06:00
|
|
|
|
2007-07-21 21:34:56 -06:00
|
|
|
triggerHWCommandList(info);
|
2007-06-26 14:10:30 -06:00
|
|
|
}
|
|
|
|
|
2007-07-21 22:35:06 -06:00
|
|
|
info->cmdring.last_ptr = xgi_find_pcie_virt(info, pCmdInfo->hw_addr);
|
2007-08-15 22:05:26 -06:00
|
|
|
drm_fence_flush_old(info->dev, 0, info->next_sequence);
|
2007-07-19 11:29:18 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-26 14:10:30 -06:00
|
|
|
/*
|
|
|
|
state: 0 - console
|
|
|
|
1 - graphic
|
|
|
|
2 - fb
|
|
|
|
3 - logout
|
|
|
|
*/
|
2007-07-19 11:29:18 -06:00
|
|
|
int xgi_state_change(struct xgi_info * info, unsigned int to,
|
|
|
|
unsigned int from)
|
2007-06-26 14:10:30 -06:00
|
|
|
{
|
|
|
|
#define STATE_CONSOLE 0
|
|
|
|
#define STATE_GRAPHIC 1
|
|
|
|
#define STATE_FBTERM 2
|
|
|
|
#define STATE_LOGOUT 3
|
|
|
|
#define STATE_REBOOT 4
|
|
|
|
#define STATE_SHUTDOWN 5
|
|
|
|
|
2007-07-19 11:29:18 -06:00
|
|
|
if ((from == STATE_GRAPHIC) && (to == STATE_CONSOLE)) {
|
2007-07-23 19:50:07 -06:00
|
|
|
DRM_INFO("Leaving graphical mode (probably VT switch)\n");
|
2007-07-19 11:29:18 -06:00
|
|
|
} else if ((from == STATE_CONSOLE) && (to == STATE_GRAPHIC)) {
|
2007-07-23 19:50:07 -06:00
|
|
|
DRM_INFO("Entering graphical mode (probably VT switch)\n");
|
2007-07-21 21:39:22 -06:00
|
|
|
xgi_cmdlist_reset(info);
|
2007-07-19 11:29:18 -06:00
|
|
|
} else if ((from == STATE_GRAPHIC)
|
|
|
|
&& ((to == STATE_LOGOUT)
|
|
|
|
|| (to == STATE_REBOOT)
|
|
|
|
|| (to == STATE_SHUTDOWN))) {
|
2007-07-23 19:50:07 -06:00
|
|
|
DRM_INFO("Leaving graphical mode (probably X shutting down)\n");
|
2007-06-26 14:10:30 -06:00
|
|
|
} else {
|
2007-07-23 19:50:07 -06:00
|
|
|
DRM_ERROR("Invalid state change.\n");
|
2007-07-26 18:01:16 -06:00
|
|
|
return -EINVAL;
|
2007-06-26 14:10:30 -06:00
|
|
|
}
|
|
|
|
|
2007-07-19 11:29:18 -06:00
|
|
|
return 0;
|
2007-06-26 14:10:30 -06:00
|
|
|
}
|
|
|
|
|
2007-07-19 11:29:18 -06:00
|
|
|
|
2007-07-27 16:45:59 -06:00
|
|
|
int xgi_state_change_ioctl(struct drm_device * dev, void * data,
|
|
|
|
struct drm_file * filp)
|
2007-07-19 11:29:18 -06:00
|
|
|
{
|
2007-07-27 16:45:59 -06:00
|
|
|
struct xgi_state_info *const state =
|
|
|
|
(struct xgi_state_info *) data;
|
2007-07-19 11:29:18 -06:00
|
|
|
struct xgi_info *info = dev->dev_private;
|
|
|
|
|
|
|
|
|
2007-07-27 16:45:59 -06:00
|
|
|
return xgi_state_change(info, state->_toState, state->_fromState);
|
2007-07-19 11:29:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-21 21:39:22 -06:00
|
|
|
void xgi_cmdlist_reset(struct xgi_info * info)
|
2007-06-26 14:10:30 -06:00
|
|
|
{
|
2007-07-21 22:35:06 -06:00
|
|
|
info->cmdring.last_ptr = NULL;
|
|
|
|
info->cmdring.ring_offset = 0;
|
2007-06-26 14:10:30 -06:00
|
|
|
}
|
|
|
|
|
2007-07-30 11:20:15 -06:00
|
|
|
|
2007-06-29 16:27:38 -06:00
|
|
|
void xgi_cmdlist_cleanup(struct xgi_info * info)
|
2007-06-26 14:10:30 -06:00
|
|
|
{
|
2007-07-21 22:35:06 -06:00
|
|
|
if (info->cmdring.ring_hw_base != 0) {
|
2007-07-30 11:20:15 -06:00
|
|
|
/* If command lists have been issued, terminate the command
|
|
|
|
* list chain with a flush command.
|
|
|
|
*/
|
|
|
|
if (info->cmdring.last_ptr != NULL) {
|
|
|
|
xgi_emit_flush(info, FALSE);
|
2007-08-15 22:05:26 -06:00
|
|
|
xgi_emit_nop(info);
|
2007-07-30 11:20:15 -06:00
|
|
|
}
|
|
|
|
|
2007-08-15 22:05:26 -06:00
|
|
|
xgi_waitfor_pci_idle(info);
|
|
|
|
|
2007-08-09 16:23:13 -06:00
|
|
|
(void) memset(&info->cmdring, 0, sizeof(info->cmdring));
|
2007-06-26 14:10:30 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-21 21:34:56 -06:00
|
|
|
static void triggerHWCommandList(struct xgi_info * info)
|
2007-06-26 14:10:30 -06:00
|
|
|
{
|
2007-06-29 22:48:31 -06:00
|
|
|
static unsigned int s_triggerID = 1;
|
2007-06-26 14:10:30 -06:00
|
|
|
|
2007-07-21 21:34:56 -06:00
|
|
|
dwWriteReg(info->mmio_map,
|
|
|
|
BASE_3D_ENG + M2REG_PCI_TRIGGER_REGISTER_ADDRESS,
|
|
|
|
0x05000000 + (0x0ffff & s_triggerID++));
|
2007-06-26 14:10:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-30 11:20:15 -06:00
|
|
|
/**
|
|
|
|
* Emit a flush to the CRTL command stream.
|
|
|
|
* @info XGI info structure
|
|
|
|
*
|
|
|
|
* This function assumes info->cmdring.ptr is non-NULL.
|
|
|
|
*/
|
2007-08-15 22:05:26 -06:00
|
|
|
void xgi_emit_flush(struct xgi_info * info, bool stop)
|
2007-06-26 14:10:30 -06:00
|
|
|
{
|
2007-08-15 22:05:26 -06:00
|
|
|
const u32 flush_command[8] = {
|
|
|
|
((0x10 << 24)
|
|
|
|
| (BEGIN_BEGIN_IDENTIFICATION_MASK & info->next_sequence)),
|
2007-07-30 11:20:15 -06:00
|
|
|
BEGIN_LINK_ENABLE_MASK | (0x00004),
|
|
|
|
0x00000000, 0x00000000,
|
|
|
|
|
2007-08-15 22:05:26 -06:00
|
|
|
/* Flush the 2D engine with the default 32 clock delay.
|
2007-07-30 11:20:15 -06:00
|
|
|
*/
|
2007-08-15 22:05:26 -06:00
|
|
|
M2REG_FLUSH_ENGINE_COMMAND | M2REG_FLUSH_2D_ENGINE_MASK,
|
|
|
|
M2REG_FLUSH_ENGINE_COMMAND | M2REG_FLUSH_2D_ENGINE_MASK,
|
|
|
|
M2REG_FLUSH_ENGINE_COMMAND | M2REG_FLUSH_2D_ENGINE_MASK,
|
|
|
|
M2REG_FLUSH_ENGINE_COMMAND | M2REG_FLUSH_2D_ENGINE_MASK,
|
2007-07-30 11:20:15 -06:00
|
|
|
};
|
2007-08-15 22:05:26 -06:00
|
|
|
const unsigned int flush_size = sizeof(flush_command);
|
2007-07-30 11:20:15 -06:00
|
|
|
u32 *batch_addr;
|
|
|
|
u32 hw_addr;
|
2007-10-03 15:08:18 -06:00
|
|
|
unsigned int i;
|
|
|
|
|
2007-06-26 14:10:30 -06:00
|
|
|
|
|
|
|
/* check buf is large enough to contain a new flush batch */
|
2007-07-30 11:20:15 -06:00
|
|
|
if ((info->cmdring.ring_offset + flush_size) >= info->cmdring.size) {
|
2007-07-21 22:35:06 -06:00
|
|
|
info->cmdring.ring_offset = 0;
|
2007-06-26 14:10:30 -06:00
|
|
|
}
|
|
|
|
|
2007-07-30 11:20:15 -06:00
|
|
|
hw_addr = info->cmdring.ring_hw_base
|
|
|
|
+ info->cmdring.ring_offset;
|
|
|
|
batch_addr = info->cmdring.ptr
|
2007-07-21 22:35:06 -06:00
|
|
|
+ (info->cmdring.ring_offset / 4);
|
2007-06-26 14:10:30 -06:00
|
|
|
|
2007-10-03 15:08:18 -06:00
|
|
|
for (i = 0; i < (flush_size / 4); i++) {
|
|
|
|
batch_addr[i] = cpu_to_le32(flush_command[i]);
|
|
|
|
}
|
2007-08-15 22:05:26 -06:00
|
|
|
|
|
|
|
if (stop) {
|
2007-10-03 15:08:18 -06:00
|
|
|
*batch_addr |= cpu_to_le32(BEGIN_STOP_STORE_CURRENT_POINTER_MASK);
|
2007-08-15 22:05:26 -06:00
|
|
|
}
|
2007-07-30 11:20:15 -06:00
|
|
|
|
2007-10-03 15:08:18 -06:00
|
|
|
info->cmdring.last_ptr[1] = cpu_to_le32(BEGIN_LINK_ENABLE_MASK | (flush_size / 4));
|
|
|
|
info->cmdring.last_ptr[2] = cpu_to_le32(hw_addr >> 4);
|
2007-07-21 22:35:06 -06:00
|
|
|
info->cmdring.last_ptr[3] = 0;
|
2007-08-15 22:05:26 -06:00
|
|
|
DRM_WRITEMEMORYBARRIER();
|
2007-10-03 15:08:18 -06:00
|
|
|
info->cmdring.last_ptr[0] = cpu_to_le32((get_batch_command(BTYPE_CTRL) << 24)
|
|
|
|
| (BEGIN_VALID_MASK));
|
2007-06-26 14:10:30 -06:00
|
|
|
|
2007-07-21 21:34:56 -06:00
|
|
|
triggerHWCommandList(info);
|
2007-06-26 14:10:30 -06:00
|
|
|
|
2007-07-30 11:20:15 -06:00
|
|
|
info->cmdring.ring_offset += flush_size;
|
2007-08-15 22:05:26 -06:00
|
|
|
info->cmdring.last_ptr = batch_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Emit an empty command to the CRTL command stream.
|
|
|
|
* @info XGI info structure
|
|
|
|
*
|
|
|
|
* This function assumes info->cmdring.ptr is non-NULL. In addition, since
|
|
|
|
* this function emits a command that does not have linkage information,
|
|
|
|
* it sets info->cmdring.ptr to NULL.
|
|
|
|
*/
|
|
|
|
void xgi_emit_nop(struct xgi_info * info)
|
|
|
|
{
|
2007-10-10 16:25:30 -06:00
|
|
|
info->cmdring.last_ptr[1] = cpu_to_le32(BEGIN_LINK_ENABLE_MASK
|
|
|
|
| (BEGIN_BEGIN_IDENTIFICATION_MASK & info->next_sequence));
|
2007-08-15 22:05:26 -06:00
|
|
|
info->cmdring.last_ptr[2] = 0;
|
|
|
|
info->cmdring.last_ptr[3] = 0;
|
|
|
|
DRM_WRITEMEMORYBARRIER();
|
2007-10-10 16:25:30 -06:00
|
|
|
info->cmdring.last_ptr[0] = cpu_to_le32((get_batch_command(BTYPE_CTRL) << 24)
|
|
|
|
| (BEGIN_VALID_MASK));
|
2007-08-15 22:05:26 -06:00
|
|
|
|
|
|
|
triggerHWCommandList(info);
|
|
|
|
|
|
|
|
info->cmdring.last_ptr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void xgi_emit_irq(struct xgi_info * info)
|
|
|
|
{
|
|
|
|
if (info->cmdring.last_ptr == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
xgi_emit_flush(info, TRUE);
|
2007-06-26 14:10:30 -06:00
|
|
|
}
|