42 #define CMDBUF_ALIGNMENT_SIZE (0x100)
43 #define CMDBUF_ALIGNMENT_MASK (0x0ff)
46 #define VIA_REG_STATUS 0x400
47 #define VIA_REG_TRANSET 0x43C
48 #define VIA_REG_TRANSPACE 0x440
51 #define VIA_CMD_RGTR_BUSY 0x00000080
52 #define VIA_2D_ENG_BUSY 0x00000001
53 #define VIA_3D_ENG_BUSY 0x00000002
54 #define VIA_VR_QUEUE_BUSY 0x00020000
56 #define SetReg2DAGP(nReg, nData) { \
57 *((uint32_t *)(vb)) = ((nReg) >> 2) | HALCYON_HEADER1; \
58 *((uint32_t *)(vb) + 1) = (nData); \
59 vb = ((uint32_t *)vb) + 2; \
60 dev_priv->dma_low += 8; \
63 #define via_flush_write_combine() DRM_MEMORYBARRIER()
65 #define VIA_OUT_RING_QW(w1, w2) do { \
68 dev_priv->dma_low += 8; \
87 return ((hw_addr <= dev_priv->dma_low) ?
101 return ((hw_addr <= dev_priv->dma_low) ?
102 (dev_priv->
dma_low - hw_addr) :
114 uint32_t cur_addr, hw_addr, next_addr;
119 next_addr = cur_addr + size + 512 * 1024;
122 hw_addr = *hw_addr_ptr - agp_base;
125 (
"via_cmdbuf_wait timed out hw %x cur_addr %x next_addr %x\n",
126 hw_addr, cur_addr, next_addr);
129 if ((cur_addr < hw_addr) && (next_addr >= hw_addr))
131 }
while ((cur_addr < hw_addr) && (next_addr >= hw_addr));
147 via_cmdbuf_rewind(dev_priv);
149 if (via_cmdbuf_wait(dev_priv, size) != 0)
157 if (dev->dev_private) {
162 via_cmdbuf_reset(dev_priv);
177 if (!dev_priv || !dev_priv->
mmio) {
178 DRM_ERROR(
"via_dma_init called before via_map_init\n");
183 DRM_ERROR(
"called again without calling cleanup\n");
187 if (!dev->agp || !dev->agp->base) {
188 DRM_ERROR(
"called with no agp memory available\n");
193 DRM_ERROR(
"AGP DMA is not supported on this chip\n");
207 DRM_ERROR(
"can not ioremap virtual address for"
224 via_cmdbuf_start(dev_priv);
229 static int via_dma_init(
struct drm_device *dev,
void *
data,
struct drm_file *file_priv)
235 switch (init->
func) {
240 retcode = via_initialize(dev, dev_priv, init);
242 case VIA_CLEANUP_DMA:
248 case VIA_DMA_INITIALIZED:
269 DRM_ERROR(
"called without initializing AGP ring buffer.\n");
287 cmd->
size, dev, 1))) {
291 vb = via_check_dma(dev_priv, (cmd->
size < 0x100) ? 0x102 : cmd->
size);
304 if (cmd->
size < 0x100)
305 via_pad_cache(dev_priv, (0x100 - cmd->
size) >> 3);
306 via_cmdbuf_pause(dev_priv);
315 if (!via_wait_idle(dev_priv))
320 static int via_flush_ioctl(
struct drm_device *dev,
void *data,
struct drm_file *file_priv)
323 LOCK_TEST_WITH_RETURN(dev, file_priv);
328 static int via_cmdbuffer(
struct drm_device *dev,
void *data,
struct drm_file *file_priv)
333 LOCK_TEST_WITH_RETURN(dev, file_priv);
335 DRM_DEBUG(
"buf %p size %lu\n", cmdbuf->
buf, cmdbuf->
size);
337 ret = via_dispatch_cmdbuffer(dev, cmdbuf);
341 static int via_dispatch_pci_cmdbuffer(
struct drm_device *dev,
354 cmd->
size, dev, 0))) {
364 static int via_pci_cmdbuffer(
struct drm_device *dev,
void *data,
struct drm_file *file_priv)
369 LOCK_TEST_WITH_RETURN(dev, file_priv);
371 DRM_DEBUG(
"buf %p size %lu\n", cmdbuf->
buf, cmdbuf->
size);
373 ret = via_dispatch_pci_cmdbuffer(dev, cmdbuf);
380 for (; qw_count > 0; --qw_count)
411 (
void) *(
volatile uint32_t *)(via_get_dma(dev_priv) - 1);
413 *paused_at = pause_addr_lo;
418 ptr = ((
volatile char *)paused_at - dev_priv->
dma_ptr) +
432 while (diff == 0 && count--) {
433 paused = (
VIA_READ(0x41c) & 0x80000000);
440 paused =
VIA_READ(0x41c) & 0x80000000;
442 if (paused && !no_pci_fire) {
446 if (diff != 0 && diff < (dev_priv->
dma_high >> 1)) {
447 DRM_ERROR(
"Paused at incorrect address. "
448 "0x%08x, 0x%08x 0x%08x\n",
450 }
else if (diff == 0) {
468 int count = 10000000;
482 uint32_t *cmd_addr_lo,
int skip_wait)
485 uint32_t cmd_addr, addr_lo, addr_hi;
492 vb = via_get_dma(dev_priv);
499 cmd_addr = (
addr) ? addr :
500 agp_base + dev_priv->
dma_low - 8 + (qw_pad_count << 3);
503 addr_hi = ((HC_SubA_HAGPBpH << 24) | (cmd_addr >> 24));
505 vb = via_align_buffer(dev_priv, vb, qw_pad_count - 1);
512 uint32_t pause_addr_lo, pause_addr_hi;
524 start_addr = agp_base;
525 end_addr = agp_base + dev_priv->
dma_high;
529 command = ((HC_SubA_HAGPCMNT << 24) | (start_addr >> 24) |
530 ((end_addr & 0xff000000) >> 16));
534 &pause_addr_hi, &pause_addr_lo, 1) - 1;
553 while (!(
VIA_READ(0x41c) & 0x80000000) && count--);
573 via_cmdbuf_wait(dev_priv, qwords + 2);
574 vb = via_get_dma(dev_priv);
576 via_align_buffer(dev_priv, vb, qwords);
581 uint32_t *vb = via_get_dma(dev_priv);
590 uint32_t pause_addr_lo, pause_addr_hi;
591 uint32_t jump_addr_lo, jump_addr_hi;
593 uint32_t dma_low_save1, dma_low_save2;
607 DRM_ERROR(
"via_cmdbuf_jump failed\n");
609 via_dummy_bitblt(dev_priv);
610 via_dummy_bitblt(dev_priv);
614 &pause_addr_lo, 0) - 1;
618 *last_pause_ptr = pause_addr_lo;
619 dma_low_save1 = dev_priv->
dma_low;
632 &pause_addr_lo, 0) - 1;
635 *last_pause_ptr = pause_addr_lo;
637 dma_low_save2 = dev_priv->
dma_low;
638 dev_priv->
dma_low = dma_low_save1;
639 via_hook_segment(dev_priv, jump_addr_hi, jump_addr_lo, 0);
640 dev_priv->
dma_low = dma_low_save2;
641 via_hook_segment(dev_priv, pause_addr_hi, pause_addr_lo, 0);
647 via_cmdbuf_jump(dev_priv);
652 uint32_t pause_addr_lo, pause_addr_hi;
654 via_align_cmd(dev_priv, cmd_type, 0, &pause_addr_hi, &pause_addr_lo, 0);
655 via_hook_segment(dev_priv, pause_addr_hi, pause_addr_lo, 0);
666 via_wait_idle(dev_priv);
673 static int via_cmdbuf_size(
struct drm_device *dev,
void *data,
struct drm_file *file_priv)
681 LOCK_TEST_WITH_RETURN(dev, file_priv);
686 DRM_ERROR(
"called without initializing AGP ring buffer.\n");
691 tmp_size = d_siz->
size;
692 switch (d_siz->
func) {
693 case VIA_CMDBUF_SPACE:
694 while (((tmp_size = via_cmdbuf_space(dev_priv)) < d_siz->
size)
700 DRM_ERROR(
"VIA_CMDBUF_SPACE timed out.\n");
705 while (((tmp_size = via_cmdbuf_lag(dev_priv)) > d_siz->
size)
711 DRM_ERROR(
"VIA_CMDBUF_LAG timed out.\n");
718 d_siz->
size = tmp_size;
726 DRM_IOCTL_DEF_DRV(VIA_AGP_INIT,
via_agp_init, DRM_AUTH|DRM_MASTER),
727 DRM_IOCTL_DEF_DRV(VIA_FB_INIT,
via_fb_init, DRM_AUTH|DRM_MASTER),
728 DRM_IOCTL_DEF_DRV(VIA_MAP_INIT,
via_map_init, DRM_AUTH|DRM_MASTER),
730 DRM_IOCTL_DEF_DRV(VIA_DMA_INIT, via_dma_init, DRM_AUTH),
731 DRM_IOCTL_DEF_DRV(VIA_CMDBUFFER, via_cmdbuffer, DRM_AUTH),
732 DRM_IOCTL_DEF_DRV(VIA_FLUSH, via_flush_ioctl, DRM_AUTH),
733 DRM_IOCTL_DEF_DRV(VIA_PCICMD, via_pci_cmdbuffer, DRM_AUTH),
734 DRM_IOCTL_DEF_DRV(VIA_CMDBUF_SIZE, via_cmdbuf_size, DRM_AUTH),
735 DRM_IOCTL_DEF_DRV(VIA_WAIT_IRQ,
via_wait_irq, DRM_AUTH),
736 DRM_IOCTL_DEF_DRV(VIA_DMA_BLIT,
via_dma_blit, DRM_AUTH),