/* i830_dma.c -- DMA support for the I830 -*- linux-c -*- * Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com * * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 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 NONINFRINGEMENT. IN NO EVENT SHALL * PRECISION INSIGHT 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. * * Authors: Rickard E. (Rik) Faith * Jeff Hartmann * Keith Whitwell * Abraham vd Merwe * */ #include "i830.h" #include "drmP.h" #include "drm.h" #include "i830_drm.h" #include "i830_drv.h" #include /* For task queue support */ #include /* For FASTCALL on unlock_page() */ #include #include #ifdef DO_MUNMAP_4_ARGS #define DO_MUNMAP(m, a, l) do_munmap(m, a, l, 1) #else #define DO_MUNMAP(m, a, l) do_munmap(m, a, l) #endif #define I830_BUF_FREE 2 #define I830_BUF_CLIENT 1 #define I830_BUF_HARDWARE 0 #define I830_BUF_UNMAPPED 0 #define I830_BUF_MAPPED 1 static inline void i830_print_status_page(drm_device_t *dev) { drm_device_dma_t *dma = dev->dma; drm_i830_private_t *dev_priv = dev->dev_private; u32 *temp = dev_priv->hw_status_page; int i; DRM_DEBUG( "hw_status: Interrupt Status : %x\n", temp[0]); DRM_DEBUG( "hw_status: LpRing Head ptr : %x\n", temp[1]); DRM_DEBUG( "hw_status: IRing Head ptr : %x\n", temp[2]); DRM_DEBUG( "hw_status: Reserved : %x\n", temp[3]); DRM_DEBUG( "hw_status: Driver Counter : %d\n", temp[5]); for(i = 9; i < dma->buf_count + 9; i++) { DRM_DEBUG( "buffer status idx : %d used: %d\n", i - 9, temp[i]); } } static drm_buf_t *i830_freelist_get(drm_device_t *dev) { drm_device_dma_t *dma = dev->dma; int i; int used; /* Linear search might not be the best solution */ for (i = 0; i < dma->buf_count; i++) { drm_buf_t *buf = dma->buflist[ i ]; drm_i830_buf_priv_t *buf_priv = buf->dev_private; /* In use is already a pointer */ used = cmpxchg(buf_priv->in_use, I830_BUF_FREE, I830_BUF_CLIENT); if(used == I830_BUF_FREE) { return buf; } } return NULL; } /* This should only be called if the buffer is not sent to the hardware * yet, the hardware updates in use for us once its on the ring buffer. */ static int i830_freelist_put(drm_device_t *dev, drm_buf_t *buf) { drm_i830_buf_priv_t *buf_priv = buf->dev_private; int used; /* In use is already a pointer */ used = cmpxchg(buf_priv->in_use, I830_BUF_CLIENT, I830_BUF_FREE); if(used != I830_BUF_CLIENT) { DRM_ERROR("Freeing buffer thats not in use : %d\n", buf->idx); return -EINVAL; } return 0; } static struct file_operations i830_buffer_fops = { .open = DRM(open), .flush = DRM(flush), .release = DRM(release), .ioctl = DRM(ioctl), .mmap = i830_mmap_buffers, .fasync = DRM(fasync), }; int i830_mmap_buffers(struct file *filp, struct vm_area_struct *vma) { drm_file_t *priv = filp->private_data; drm_device_t *dev; drm_i830_private_t *dev_priv; drm_buf_t *buf; drm_i830_buf_priv_t *buf_priv; lock_kernel(); dev = priv->dev; dev_priv = dev->dev_private; buf = dev_priv->mmap_buffer; buf_priv = buf->dev_private; vma->vm_flags |= (VM_IO | VM_DONTCOPY); vma->vm_file = filp; buf_priv->currently_mapped = I830_BUF_MAPPED; unlock_kernel(); if (remap_page_range(DRM_RPR_ARG(vma) vma->vm_start, VM_OFFSET(vma), vma->vm_end - vma->vm_start, vma->vm_page_prot)) return -EAGAIN; return 0; } static int i830_map_buffer(drm_buf_t *buf, struct file *filp) { drm_file_t *priv = filp->private_data; drm_device_t *dev = priv->dev; drm_i830_buf_priv_t *buf_priv = buf->dev_private; drm_i830_private_t *dev_priv = dev->dev_private; struct file_operations *old_fops; unsigned long virtual; int retcode = 0; if(buf_priv->currently_mapped == I830_BUF_MAPPED) return -EINVAL; down_write( ¤t->mm->mmap_sem ); old_fops = filp->f_op; filp->f_op = &i830_buffer_fops; dev_priv->mmap_buffer = buf; virtual = do_mmap(filp, 0, buf->total, PROT_READ|PROT_WRITE, MAP_SHARED, buf->bus_address); dev_priv->mmap_buffer = NULL; filp->f_op = old_fops; if (IS_ERR((void *)virtual)) { /* ugh */ /* Real error */ DRM_ERROR("mmap error\n"); retcode = virtual; buf_priv->virtual = NULL; } else { buf_priv->virtual = (void __user *)virtual; } up_write( ¤t->mm->mmap_sem ); return retcode; } static int i830_unmap_buffer(drm_buf_t *buf) { drm_i830_buf_priv_t *buf_priv = buf->dev_private; int retcode = 0; if(buf_priv->currently_mapped != I830_BUF_MAPPED) return -EINVAL; down_write(¤t->mm->mmap_sem); retcode = DO_MUNMAP(current->mm, (unsigned long)buf_priv->virtual, (size_t) buf->total); up_write(¤t->mm->mmap_sem); buf_priv->currently_mapped = I830_BUF_UNMAPPED; buf_priv->virtual = NULL; return retcode; } static int i830_dma_get_buffer(drm_device_t *dev, drm_i830_dma_t *d, struct file *filp) { drm_buf_t *buf; drm_i830_buf_priv_t *buf_priv; int retcode = 0; buf = i830_freelist_get(dev); if (!buf) { retcode = -ENOMEM; DRM_DEBUG("retcode=%d\n", retcode); return retcode; } retcode = i830_map_buffer(buf, filp); if(retcode) { i830_freelist_put(dev, buf); DRM_ERROR("mapbuf failed, retcode %d\n", retcode); return retcode; } buf->filp = filp; buf_priv = buf->dev_private; d->granted = 1; d->request_idx = buf->idx; d->request_size = buf->total; d->virtual = buf_priv->virtual; return retcode; } int i830_dma_cleanup(drm_device_t *dev) { drm_device_dma_t *dma = dev->dma; /* Make sure interrupts are disabled here because the uninstall ioctl * may not have been called from userspace and after dev_private * is freed, it's too late. */ if (dev->irq_enabled) DRM(irq_uninstall)(dev); if (dev->dev_private) { int i; drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private; if (dev_priv->ring.virtual_start) { DRM(ioremapfree)((void *) dev_priv->ring.virtual_start, dev_priv->ring.Size, dev); } if (dev_priv->hw_status_page) { pci_free_consistent(dev->pdev, PAGE_SIZE, dev_priv->hw_status_page, dev_priv->dma_status_page); /* Need to rewrite hardware status page */ I830_WRITE(0x02080, 0x1ffff000); } DRM(free)(dev->dev_private, sizeof(drm_i830_private_t), DRM_MEM_DRIVER); dev->dev_private = NULL; for (i = 0; i < dma->buf_count; i++) { drm_buf_t *buf = dma->buflist[ i ]; drm_i830_buf_priv_t *buf_priv = buf->dev_private; if ( buf_priv->kernel_virtual && buf->total ) DRM(ioremapfree)(buf_priv->kernel_virtual, buf->total, dev); } } return 0; } int i830_wait_ring(drm_device_t *dev, int n, const char *caller) { drm_i830_private_t *dev_priv = dev->dev_private; drm_i830_ring_buffer_t *ring = &(dev_priv->ring); int iters = 0; unsigned long end; unsigned int last_head = I830_READ(LP_RING + RING_HEAD) & HEAD_ADDR; end = jiffies + (HZ*3); while (ring->space < n) { ring->head = I830_READ(LP_RING + RING_HEAD) & HEAD_ADDR; ring->space = ring->head - (ring->tail+8); if (ring->space < 0) ring->space += ring->Size; if (ring->head != last_head) { end = jiffies + (HZ*3); last_head = ring->head; } iters++; if(time_before(end, jiffies)) { DRM_ERROR("space: %d wanted %d\n", ring->space, n); DRM_ERROR("lockup\n"); goto out_wait_ring; } udelay(1); dev_priv->sarea_priv->perf_boxes |= I830_BOX_WAIT; } out_wait_ring: return iters; } static void i830_kernel_lost_context(drm_device_t *dev) { drm_i830_private_t *dev_priv = dev->dev_private; drm_i830_ring_buffer_t *ring = &(dev_priv->ring); ring->head = I830_READ(LP_RING + RING_HEAD) & HEAD_ADDR; ring->tail = I830_READ(LP_RING + RING_TAIL) & TAIL_ADDR; ring->space = ring->head - (ring->tail+8); if (ring->space < 0) ring->space += ring->Size; if (ring->head == ring->tail) dev_priv->sarea_priv->perf_boxes |= I830_BOX_RING_EMPTY; } static int i830_freelist_init(drm_device_t *dev, drm_i830_private_t *dev_priv) { drm_device_dma_t *dma = dev->dma; int my_idx = 36; u32 *hw_status = (u32 *)(dev_priv->hw_status_page + my_idx); int i; if(dma->buf_count > 1019) { /* Not enough space in the status page for the freelist */ return -EINVAL; } for (i = 0; i < dma->buf_count; i++) { drm_buf_t *buf = dma->buflist[ i ]; drm_i830_buf_priv_t *buf_priv = buf->dev_private; buf_priv->in_use = hw_status++; buf_priv->my_use_idx = my_idx; my_idx += 4; *buf_priv->in_use = I830_BUF_FREE; buf_priv->kernel_virtual = DRM(ioremap)(buf->bus_address, buf->total, dev); } return 0; } static int i830_dma_initialize(drm_device_t *dev, drm_i830_private_t *dev_priv, drm_i830_init_t *init) { struct list_head *list; memset(dev_priv, 0, sizeof(drm_i830_private_t)); list_for_each(list, &dev->maplist->head) { drm_map_list_t *r_list = list_entry(list, drm_map_list_t, head); if( r_list->map && r_list->map->type == _DRM_SHM && r_list->map->flags & _DRM_CONTAINS_LOCK ) { dev_priv->sarea_map = r_list->map; break; } } if(!dev_priv->sarea_map) { dev->dev_private = (void *)dev_priv; i830_dma_cleanup(dev); DRM_ERROR("can not find sarea!\n"); return -EINVAL; } dev_priv->mmio_map = drm_core_findmap(dev, init->mmio_offset); if(!dev_priv->mmio_map) { dev->dev_private = (void *)dev_priv; i830_dma_cleanup(dev); DRM_ERROR("can not find mmio map!\n"); return -EINVAL; } dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset); if(!dev->agp_buffer_map) { dev->dev_private = (void *)dev_priv; i830_dma_cleanup(dev); DRM_ERROR("can not find dma buffer map!\n"); return -EINVAL; } dev_priv->sarea_priv = (drm_i830_sarea_t *) ((u8 *)dev_priv->sarea_map->handle + init->sarea_priv_offset); dev_priv->ring.Start = init->ring_start; dev_priv->ring.End = init->ring_end; dev_priv->ring.Size = init->ring_size; dev_priv->ring.virtual_start = DRM(ioremap)(dev->agp->base + init->ring_start, init->ring_size, dev); if (dev_priv->ring.virtual_start == NULL) { dev->dev_private = (void *) dev_priv; i830_dma_cleanup(dev); DRM_ERROR("can not ioremap virtual address for" " ring buffer\n"); return -ENOMEM; } dev_priv->ring.tail_mask = dev_priv->ring.Size - 1; dev_priv->w = init->w; dev_priv->h = init->h; dev_priv->pitch = init->pitch; dev_priv->back_offset = init->back_offset; dev_priv->depth_offset = init->depth_offset; dev_priv->front_offset = init->front_offset; dev_priv->front_di1 = init->front_offset | init->pitch_bits; dev_priv->back_di1 = init->back_offset | init->pitch_bits; dev_priv->zi1 = init->depth_offset | init->pitch_bits; DRM_DEBUG("front_di1 %x\n", dev_priv->front_di1); DRM_DEBUG("back_offset %x\n", dev_priv->back_offset); DRM_DEBUG("back_di1 %x\n", dev_priv->back_di1); DRM_DEBUG("pitch_bits %x\n", init->pitch_bits); dev_priv->cpp = init->cpp; /* We are using separate values as placeholders for mechanisms for * private backbuffer/depthbuffer usage. */ dev_priv->back_pitch = init->back_pitch; dev_priv->depth_pitch = init->depth_pitch; dev_priv->do_boxes = 0; dev_priv->use_mi_batchbuffer_start = 0; /* Program Hardware Status Page */ dev_priv->hw_status_page = pci_alloc_consistent(dev->pdev, PAGE_SIZE, &dev_priv->dma_status_page); if (!dev_priv->hw_status_page) { dev->dev_private = (void *)dev_priv; i830_dma_cleanup(dev); DRM_ERROR("Can not allocate hardware status page\n"); return -ENOMEM; } memset(dev_priv->hw_status_page, 0, PAGE_SIZE); DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page); I830_WRITE(0x02080, dev_priv->dma_status_page); DRM_DEBUG("Enabled hardware status page\n"); /* Now we need to init our freelist */ if(i830_freelist_init(dev, dev_priv) != 0) { dev->dev_private = (void *)dev_priv; i830_dma_cleanup(dev); DRM_ERROR("Not enough space in the status page for" " the freelist\n"); return -ENOMEM; } dev->dev_private = (void *)dev_priv; return 0; } int i830_dma_init(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) { drm_file_t *priv = filp->private_data; drm_device_t *dev = priv->dev; drm_i830_private_t *dev_priv; drm_i830_init_t init; int retcode = 0; if (copy_from_user(&init, (void * __user) arg, sizeof(init))) return -EFAULT; switch(init.func) { case I830_INIT_DMA: dev_priv = DRM(alloc)(sizeof(drm_i830_private_t), DRM_MEM_DRIVER); if(dev_priv == NULL) return -ENOMEM; retcode = i830_dma_initialize(dev, dev_priv, &init); break; case I830_CLEANUP_DMA: retcode = i830_dma_cleanup(dev); break; default: retcode = -EINVAL; break; } return retcode; } #define GFX_OP_STIPPLE ((0x3<<29)|(0x1d<<24)|(0x83<<16)) #define ST1_ENABLE (1<<16) #define ST1_MASK (0xffff) /* Most efficient way to verify state for the i830 is as it is * emitted. Non-conformant state is silently dropped. */ static void i830EmitContextVerified( drm_device_t *dev, unsigned int *code ) { drm_i830_private_t *dev_priv = dev->dev_private; int i, j = 0; unsigned int tmp; RING_LOCALS; BEGIN_LP_RING( I830_CTX_SETUP_SIZE + 4 ); for ( i = 0 ; i < I830_CTXREG_BLENDCOLR0 ; i++ ) { tmp = code[i]; if ((tmp & (7<<29)) == CMD_3D && (tmp & (0x1f<<24)) < (0x1d<<24)) { OUT_RING( tmp ); j++; } else { DRM_ERROR("Skipping %d\n", i); } } OUT_RING( STATE3D_CONST_BLEND_COLOR_CMD ); OUT_RING( code[I830_CTXREG_BLENDCOLR] ); j += 2; for ( i = I830_CTXREG_VF ; i < I830_CTXREG_MCSB0 ; i++ ) { tmp = code[i]; if ((tmp & (7<<29)) == CMD_3D && (tmp & (0x1f<<24)) < (0x1d<<24)) { OUT_RING( tmp ); j++; } else { DRM_ERROR("Skipping %d\n", i); } } OUT_RING( STATE3D_MAP_COORD_SETBIND_CMD ); OUT_RING( code[I830_CTXREG_MCSB1] ); j += 2; if (j & 1) OUT_RING( 0 ); ADVANCE_LP_RING(); } static void i830EmitTexVerified( drm_device_t *dev, unsigned int *code ) { drm_i830_private_t *dev_priv = dev->dev_private; int i, j = 0; unsigned int tmp; RING_LOCALS; if (code[I830_TEXREG_MI0] == GFX_OP_MAP_INFO || (code[I830_TEXREG_MI0] & ~(0xf*LOAD_TEXTURE_MAP0)) == (STATE3D_LOAD_STATE_IMMEDIATE_2|4)) { BEGIN_LP_RING( I830_TEX_SETUP_SIZE ); OUT_RING( code[I830_TEXREG_MI0] ); /* TM0LI */ OUT_RING( code[I830_TEXREG_MI1] ); /* TM0S0 */ OUT_RING( code[I830_TEXREG_MI2] ); /* TM0S1 */ OUT_RING( code[I830_TEXREG_MI3] ); /* TM0S2 */ OUT_RING( code[I830_TEXREG_MI4] ); /* TM0S3 */ OUT_RING( code[I830_TEXREG_MI5] ); /* TM0S4 */ for ( i = 6 ; i < I830_TEX_SETUP_SIZE ; i++ ) { tmp = code[i]; OUT_RING( tmp ); j++; } if (j & 1) OUT_RING( 0 ); ADVANCE_LP_RING(); } else printk("rejected packet %x\n", code[0]); } static void i830EmitTexBlendVerified( drm_device_t *dev, unsigned int *code, unsigned int num) { drm_i830_private_t *dev_priv = dev->dev_private; int i, j = 0; unsigned int tmp; RING_LOCALS; if (!num) return; BEGIN_LP_RING( num + 1 ); for ( i = 0 ; i < num ; i++ ) { tmp = code[i]; OUT_RING( tmp ); j++; } if (j & 1) OUT_RING( 0 ); ADVANCE_LP_RING(); } static void i830EmitTexPalette( drm_device_t *dev, unsigned int *palette, int number, int is_shared ) { drm_i830_private_t *dev_priv = dev->dev_private; int i; RING_LOCALS; return; BEGIN_LP_RING( 258 ); if(is_shared == 1) { OUT_RING(CMD_OP_MAP_PALETTE_LOAD | MAP_PALETTE_NUM(0) | MAP_PALETTE_BOTH); } else { OUT_RING(CMD_OP_MAP_PALETTE_LOAD | MAP_PALETTE_NUM(number)); } for(i = 0; i < 256; i++) { OUT_RING(palette[i]); } OUT_RING(0); /* KW: WHERE IS THE ADVANCE_LP_RING? This is effectively a noop! */ } /* Need to do some additional checking when setting the dest buffer. */ static void i830EmitDestVerified( drm_device_t *dev, unsigned int *code ) { drm_i830_private_t *dev_priv = dev->dev_private; unsigned int tmp; RING_LOCALS; BEGIN_LP_RING( I830_DEST_SETUP_SIZE + 10 ); tmp = code[I830_DESTREG_CBUFADDR]; if (tmp == dev_priv->front_di1 || tmp == dev_priv->back_di1) { if (((int)outring) & 8) { OUT_RING(0); OUT_RING(0); } OUT_RING( CMD_OP_DESTBUFFER_INFO ); OUT_RING( BUF_3D_ID_COLOR_BACK | BUF_3D_PITCH(dev_priv->back_pitch * dev_priv->cpp) | BUF_3D_USE_FENCE); OUT_RING( tmp ); OUT_RING( 0 ); OUT_RING( CMD_OP_DESTBUFFER_INFO ); OUT_RING( BUF_3D_ID_DEPTH | BUF_3D_USE_FENCE | BUF_3D_PITCH(dev_priv->depth_pitch * dev_priv->cpp)); OUT_RING( dev_priv->zi1 ); OUT_RING( 0 ); } else { DRM_ERROR("bad di1 %x (allow %x or %x)\n", tmp, dev_priv->front_di1, dev_priv->back_di1); } /* invarient: */ OUT_RING( GFX_OP_DESTBUFFER_VARS ); OUT_RING( code[I830_DESTREG_DV1] ); OUT_RING( GFX_OP_DRAWRECT_INFO ); OUT_RING( code[I830_DESTREG_DR1] ); OUT_RING( code[I830_DESTREG_DR2] ); OUT_RING( code[I830_DESTREG_DR3] ); OUT_RING( code[I830_DESTREG_DR4] ); /* Need to verify this */ tmp = code[I830_DESTREG_SENABLE]; if((tmp & ~0x3) == GFX_OP_SCISSOR_ENABLE) { OUT_RING( tmp ); } else { DRM_ERROR("bad scissor enable\n"); OUT_RING( 0 ); } OUT_RING( GFX_OP_SCISSOR_RECT ); OUT_RING( code[I830_DESTREG_SR1] ); OUT_RING( code[I830_DESTREG_SR2] ); OUT_RING( 0 ); ADVANCE_LP_RING(); } static void i830EmitStippleVerified( drm_device_t *dev, unsigned int *code ) { drm_i830_private_t *dev_priv = dev->dev_private; RING_LOCALS; BEGIN_LP_RING( 2 ); OUT_RING( GFX_OP_STIPPLE ); OUT_RING( code[1] ); ADVANCE_LP_RING(); } static void i830EmitState( drm_device_t *dev ) { drm_i830_private_t *dev_priv = dev->dev_private; drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv; unsigned int dirty = sarea_priv->dirty; DRM_DEBUG("%s %x\n", __FUNCTION__, dirty); if (dirty & I830_UPLOAD_BUFFERS) { i830EmitDestVerified( dev, sarea_priv->BufferState ); sarea_priv->dirty &= ~I830_UPLOAD_BUFFERS; } if (dirty & I830_UPLOAD_CTX) { i830EmitContextVerified( dev, sarea_priv->ContextState ); sarea_priv->dirty &= ~I830_UPLOAD_CTX; } if (dirty & I830_UPLOAD_TEX0) { i830EmitTexVerified( dev, sarea_priv->TexState[0] ); sarea_priv->dirty &= ~I830_UPLOAD_TEX0; } if (dirty & I830_UPLOAD_TEX1) { i830EmitTexVerified( dev, sarea_priv->TexState[1] ); sarea_priv->dirty &= ~I830_UPLOAD_TEX1; } if (dirty & I830_UPLOAD_TEXBLEND0) { i830EmitTexBlendVerified( dev, sarea_priv->TexBlendState[0], sarea_priv->TexBlendStateWordsUsed[0]); sarea_priv->dirty &= ~I830_UPLOAD_TEXBLEND0; } if (dirty & I830_UPLOAD_TEXBLEND1) { i830EmitTexBlendVerified( dev, sarea_priv->TexBlendState[1], sarea_priv->TexBlendStateWordsUsed[1]); sarea_priv->dirty &= ~I830_UPLOAD_TEXBLEND1; } if (dirty & I830_UPLOAD_TEX_PALETTE_SHARED) { i830EmitTexPalette(dev, sarea_priv->Palette[0], 0, 1); } else { if (dirty & I830_UPLOAD_TEX_PALETTE_N(0)) { i830EmitTexPalette(dev, sarea_priv->Palette[0], 0, 0); sarea_priv->dirty &= ~I830_UPLOAD_TEX_PALETTE_N(0); } if (dirty & I830_UPLOAD_TEX_PALETTE_N(1)) { i830EmitTexPalette(dev, sarea_priv->Palette[1], 1, 0); sarea_priv->dirty &= ~I830_UPLOAD_TEX_PALETTE_N(1); } /* 1.3: */ #if 0 if (dirty & I830_UPLOAD_TEX_PALETTE_N(2)) { i830EmitTexPalette(dev, sarea_priv->Palette2[0], 0, 0); sarea_priv->dirty &= ~I830_UPLOAD_TEX_PALETTE_N(2); } if (dirty & I830_UPLOAD_TEX_PALETTE_N(3)) { i830EmitTexPalette(dev, sarea_priv->Palette2[1], 1, 0); sarea_priv->dirty &= ~I830_UPLOAD_TEX_PALETTE_N(2); } #endif } /* 1.3: */ if (dirty & I830_UPLOAD_STIPPLE) { i830EmitStippleVerified( dev, sarea_priv->StippleState); sarea_priv->dirty &= ~I830_UPLOAD_STIPPLE; } if (dirty & I830_UPLOAD_TEX2) { i830EmitTexVerified( dev, sarea_priv->TexState2 ); sarea_priv->dirty &= ~I830_UPLOAD_TEX2; } if (dirty & I830_UPLOAD_TEX3) { i830EmitTexVerified( dev, sarea_priv->TexState3 ); sarea_priv->dirty &= ~I830_UPLOAD_TEX3; } if (dirty & I830_UPLOAD_TEXBLEND2) { i830EmitTexBlendVerified( dev, sarea_priv->TexBlendState2, sarea_priv->TexBlendStateWordsUsed2); sarea_priv->dirty &= ~I830_UPLOAD_TEXBLEND2; } if (dirty & I830_UPLOAD_TEXBLEND3) { i830EmitTexBlendVerified( dev, sarea_priv->TexBlendState3, sarea_priv->TexBlendStateWordsUsed3); sarea_priv->dirty &= ~I830_UPLOAD_TEXBLEND3; } } /* ================================================================ * Performance monitoring functions */ static void i830_fill_box( drm_device_t *dev, int x, int y, int w, int h, int r, int g, int b ) { drm_i830_private_t *dev_priv = dev->dev_private; u32 color; unsigned int BR13, CMD; RING_LOCALS; BR13 = (0xF0 << 16) | (dev_priv->pitch * dev_priv->cpp) | (1<<24); CMD = XY_COLOR_BLT_CMD; x += dev_priv->sarea_priv->boxes[0].x1; y += dev_priv->sarea_priv->boxes[0].y1; if (dev_priv->cpp == 4) { BR13 |= (1<<25); CMD |= (XY_COLOR_BLT_WRITE_ALPHA | XY_COLOR_BLT_WRITE_RGB); color = (((0xff) << 24) | (r << 16) | (g << 8) | b); } else { color = (((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3)); } BEGIN_LP_RING( 6 ); OUT_RING( CMD ); OUT_RING( BR13 ); OUT_RING( (y << 16) | x ); OUT_RING( ((y+h) << 16) | (x+w) ); if ( dev_priv->current_page == 1 ) { OUT_RING( dev_priv->front_offset ); } else { OUT_RING( dev_priv->back_offset ); } OUT_RING( color ); ADVANCE_LP_RING(); } static void i830_cp_performance_boxes( drm_device_t *dev ) { drm_i830_private_t *dev_priv = dev->dev_private; /* Purple box for page flipping */ if ( dev_priv->sarea_priv->perf_boxes & I830_BOX_FLIP ) i830_fill_box( dev, 4, 4, 8, 8, 255, 0, 255 ); /* Red box if we have to wait for idle at any point */ if ( dev_priv->sarea_priv->perf_boxes & I830_BOX_WAIT ) i830_fill_box( dev, 16, 4, 8, 8, 255, 0, 0 ); /* Blue box: lost context? */ if ( dev_priv->sarea_priv->perf_boxes & I830_BOX_LOST_CONTEXT ) i830_fill_box( dev, 28, 4, 8, 8, 0, 0, 255 ); /* Yellow box for texture swaps */ if ( dev_priv->sarea_priv->perf_boxes & I830_BOX_TEXTURE_LOAD ) i830_fill_box( dev, 40, 4, 8, 8, 255, 255, 0 ); /* Green box if hardware never idles (as far as we can tell) */ if ( !(dev_priv->sarea_priv->perf_boxes & I830_BOX_RING_EMPTY) ) i830_fill_box( dev, 64, 4, 8, 8, 0, 255, 0 ); /* Draw bars indicating number of buffers allocated * (not a great measure, easily confused) */ if (dev_priv->dma_used) { int bar = dev_priv->dma_used / 10240; if (bar > 100) bar = 100; if (bar < 1) bar = 1; i830_fill_box( dev, 4, 16, bar, 4, 196, 128, 128 ); dev_priv->dma_used = 0; } dev_priv->sarea_priv->perf_boxes = 0; } static void i830_dma_dispatch_clear( drm_device_t *dev, int flags, unsigned int clear_color, unsigned int clear_zval, unsigned int clear_depthmask) { drm_i830_private_t *dev_priv = dev->dev_private; drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv; int nbox = sarea_priv->nbox; drm_clip_rect_t *pbox = sarea_priv->boxes; int pitch = dev_priv->pitch; int cpp = dev_priv->cpp; int i; unsigned int BR13, CMD, D_CMD; RING_LOCALS; if ( dev_priv->current_page == 1 ) { unsigned int tmp = flags; flags &= ~(I830_FRONT | I830_BACK); if ( tmp & I830_FRONT ) flags |= I830_BACK; if ( tmp & I830_BACK ) flags |= I830_FRONT; } i830_kernel_lost_context(dev); switch(cpp) { case 2: BR13 = (0xF0 << 16) | (pitch * cpp) | (1<<24); D_CMD = CMD = XY_COLOR_BLT_CMD; break; case 4: BR13 = (0xF0 << 16) | (pitch * cpp) | (1<<24) | (1<<25); CMD = (XY_COLOR_BLT_CMD | XY_COLOR_BLT_WRITE_ALPHA | XY_COLOR_BLT_WRITE_RGB); D_CMD = XY_COLOR_BLT_CMD; if(clear_depthmask & 0x00ffffff) D_CMD |= XY_COLOR_BLT_WRITE_RGB; if(clear_depthmask & 0xff000000) D_CMD |= XY_COLOR_BLT_WRITE_ALPHA; break; default: BR13 = (0xF0 << 16) | (pitch * cpp) | (1<<24); D_CMD = CMD = XY_COLOR_BLT_CMD; break; } if (nbox > I830_NR_SAREA_CLIPRECTS) nbox = I830_NR_SAREA_CLIPRECTS; for (i = 0 ; i < nbox ; i++, pbox++) { if (pbox->x1 > pbox->x2 || pbox->y1 > pbox->y2 || pbox->x2 > dev_priv->w || pbox->y2 > dev_priv->h) continue; if ( flags & I830_FRONT ) { DRM_DEBUG("clear front\n"); BEGIN_LP_RING( 6 ); OUT_RING( CMD ); OUT_RING( BR13 ); OUT_RING( (pbox->y1 << 16) | pbox->x1 ); OUT_RING( (pbox->y2 << 16) | pbox->x2 ); OUT_RING( dev_priv->front_offset ); OUT_RING( clear_color ); ADVANCE_LP_RING(); } if ( flags & I830_BACK ) { DRM_DEBUG("clear back\n"); BEGIN_LP_RING( 6 ); OUT_RING( CMD ); OUT_RING( BR13 ); OUT_RING( (pbox->y1 << 16) | pbox->x1 ); OUT_RING( (pbox->y2 << 16) | pbox->x2 ); OUT_RING( dev_priv->back_offset ); OUT_RING( clear_color ); ADVANCE_LP_RING(); } if ( flags & I830_DEPTH ) { DRM_DEBUG("clear depth\n"); BEGIN_LP_RING( 6 ); OUT_RING( D_CMD ); OUT_RING( BR13 ); OUT_RING( (pbox->y1 << 16) | pbox->x1 ); OUT_RING( (pbox->y2 << 16) | pbox->x2 ); OUT_RING( dev_priv->depth_offset ); OUT_RING( clear_zval ); ADVANCE_LP_RING(); } } } static void i830_dma_dispatch_swap( drm_device_t *dev ) { drm_i830_private_t *dev_priv = dev->dev_private; drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv; int nbox = sarea_priv->nbox; drm_clip_rect_t *pbox = sarea_priv->boxes; int pitch = dev_priv->pitch; int cpp = dev_priv->cpp; int i; unsigned int CMD, BR13; RING_LOCALS; DRM_DEBUG("swapbuffers\n"); i830_kernel_lost_context(dev); if (dev_priv->do_boxes) i830_cp_performance_boxes( dev ); switch(cpp) { case 2: BR13 = (pitch * cpp) | (0xCC << 16) | (1<<24); CMD = XY_SRC_COPY_BLT_CMD; break; case 4: BR13 = (pitch * cpp) | (0xCC << 16) | (1<<24) | (1<<25); CMD = (XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA | XY_SRC_COPY_BLT_WRITE_RGB); break; default: BR13 = (pitch * cpp) | (0xCC << 16) | (1<<24); CMD = XY_SRC_COPY_BLT_CMD; break; } if (nbox > I830_NR_SAREA_CLIPRECTS) nbox = I830_NR_SAREA_CLIPRECTS; for (i = 0 ; i < nbox; i++, pbox++) { if (pbox->x1 > pbox->x2 || pbox->y1 > pbox->y2 || pbox->x2 > dev_priv->w || pbox->y2 > dev_priv->h) continue; DRM_DEBUG("dispatch swap %d,%d-%d,%d!\n", pbox->x1, pbox->y1, pbox->x2, pbox->y2); BEGIN_LP_RING( 8 ); OUT_RING( CMD ); OUT_RING( BR13 ); OUT_RING( (pbox->y1 << 16) | pbox->x1 ); OUT_RING( (pbox->y2 << 16) | pbox->x2 ); if (dev_priv->current_page == 0) OUT_RING( dev_priv->front_offset ); else OUT_RING( dev_priv->back_offset ); OUT_RING( (pbox->y1 << 16) | pbox->x1 ); OUT_RING( BR13 & 0xffff ); if (dev_priv->current_page == 0) OUT_RING( dev_priv->back_offset ); else OUT_RING( dev_priv->front_offset ); ADVANCE_LP_RING(); } } static void i830_dma_dispatch_flip( drm_device_t *dev ) { drm_i830_private_t *dev_priv = dev->dev_private; RING_LOCALS; DRM_DEBUG( "%s: page=%d pfCurrentPage=%d\n", __FUNCTION__, dev_priv->current_page, dev_priv->sarea_priv->pf_current_page); i830_kernel_lost_context(dev); if (dev_priv->do_boxes) { dev_priv->sarea_priv->perf_boxes |= I830_BOX_FLIP; i830_cp_performance_boxes( dev ); } BEGIN_LP_RING( 2 ); OUT_RING( INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE ); OUT_RING( 0 ); ADVANCE_LP_RING(); BEGIN_LP_RING( 6 ); OUT_RING( CMD_OP_DISPLAYBUFFER_INFO | ASYNC_FLIP ); OUT_RING( 0 ); if ( dev_priv->current_page == 0 ) { OUT_RING( dev_priv->back_offset ); dev_priv->current_page = 1; } else { OUT_RING( dev_priv->front_offset ); dev_priv->current_page = 0; } OUT_RING(0); ADVANCE_LP_RING(); BEGIN_LP_RING( 2 ); OUT_RING( MI_WAIT_FOR_EVENT | MI_WAIT_FOR_PLANE_A_FLIP ); OUT_RING( 0 ); ADVANCE_LP_RING(); dev_priv->sarea_priv->pf_current_page = dev_priv->current_page; } static void i830_dma_dispatch_vertex(drm_device_t *dev, drm_buf_t *buf, int discard, int used) { drm_i830_private_t *dev_priv = dev->dev_private; drm_i830_buf_priv_t *buf_priv = buf->dev_private; drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv; drm_clip_rect_t *box = sarea_priv->boxes; int nbox = sarea_priv->nbox; unsigned long address = (unsigned long)buf->bus_address; unsigned long start = address - dev->agp->base; int i = 0, u; RING_LOCALS; i830_kernel_lost_context(dev); if (nbox > I830_NR_SAREA_CLIPRECTS) nbox = I830_NR_SAREA_CLIPRECTS; if (discard) { u = cmpxchg(buf_priv->in_use, I830_BUF_CLIENT, I830_BUF_HARDWARE); if(u != I830_BUF_CLIENT) { DRM_DEBUG("xxxx 2\n"); } } if (used > 4*1023) used = 0; if (sarea_priv->dirty) i830EmitState( dev ); DRM_DEBUG("dispatch vertex addr 0x%lx, used 0x%x nbox %d\n", address, used, nbox); dev_priv->counter++; DRM_DEBUG( "dispatch counter : %ld\n", dev_priv->counter); DRM_DEBUG( "i830_dma_dispatch\n"); DRM_DEBUG( "start : %lx\n", start); DRM_DEBUG( "used : %d\n", used); DRM_DEBUG( "start + used - 4 : %ld\n", start + used - 4); if (buf_priv->currently_mapped == I830_BUF_MAPPED) { u32 *vp = buf_priv->kernel_virtual; vp[0] = (GFX_OP_PRIMITIVE | sarea_priv->vertex_prim | ((used/4)-2)); if (dev_priv->use_mi_batchbuffer_start) { vp[used/4] = MI_BATCH_BUFFER_END; used += 4; } if (used & 4) { vp[used/4] = 0; used += 4; } i830_unmap_buffer(buf); } if (used) { do { if (i < nbox) { BEGIN_LP_RING(6); OUT_RING( GFX_OP_DRAWRECT_INFO ); OUT_RING( sarea_priv->BufferState[I830_DESTREG_DR1] ); OUT_RING( box[i].x1 | (box[i].y1<<16) ); OUT_RING( box[i].x2 | (box[i].y2<<16) ); OUT_RING( sarea_priv->BufferState[I830_DESTREG_DR4] ); OUT_RING( 0 ); ADVANCE_LP_RING(); } if (dev_priv->use_mi_batchbuffer_start) { BEGIN_LP_RING(2); OUT_RING( MI_BATCH_BUFFER_START | (2<<6) ); OUT_RING( start | MI_BATCH_NON_SECURE ); ADVANCE_LP_RING(); } else { BEGIN_LP_RING(4); OUT_RING( MI_BATCH_BUFFER ); OUT_RING( start | MI_BATCH_NON_SECURE ); OUT_RING( start + used - 4 ); OUT_RING( 0 ); ADVANCE_LP_RING(); } } while (++i < nbox); } if (discard) { dev_priv->counter++; (void) cmpxchg(buf_priv->in_use, I830_BUF_CLIENT, I830_BUF_HARDWARE); BEGIN_LP_RING(8); OUT_RING( CMD_STORE_DWORD_IDX ); OUT_RING( 20 ); OUT_RING( dev_priv->counter ); OUT_RING( CMD_STORE_DWORD_IDX ); OUT_RING( buf_priv->my_use_idx ); OUT_RING( I830_BUF_FREE ); OUT_RING( CMD_REPORT_HEAD ); OUT_RING( 0 ); ADVANCE_LP_RING(); } } void i830_dma_quiescent(drm_device_t *dev) { drm_i830_private_t *dev_priv = dev->dev_private; RING_LOCALS; i830_kernel_lost_context(dev); BEGIN_LP_RING(4); OUT_RING( INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE ); OUT_RING( CMD_REPORT_HEAD ); OUT_RING( 0 ); OUT_RING( 0 ); ADVANCE_LP_RING(); i830_wait_ring( dev, dev_priv->ring.Size - 8, __FUNCTION__ ); } static int i830_flush_queue(drm_device_t *dev) { drm_i830_private_t *dev_priv = dev->dev_private; drm_device_dma_t *dma = dev->dma; int i, ret = 0; RING_LOCALS; i830_kernel_lost_context(dev); BEGIN_LP_RING(2); OUT_RING( CMD_REPORT_HEAD ); OUT_RING( 0 ); ADVANCE_LP_RING(); i830_wait_ring( dev, dev_priv->ring.Size - 8, __FUNCTION__ ); for (i = 0; i < dma->buf_count; i++) { drm_buf_t *buf = dma->buflist[ i ]; drm_i830_buf_priv_t *buf_priv = buf->dev_private; int used = cmpxchg(buf_priv->in_use, I830_BUF_HARDWARE, I830_BUF_FREE); if (used == I830_BUF_HARDWARE) DRM_DEBUG("reclaimed from HARDWARE\n"); if (used == I830_BUF_CLIENT) DRM_DEBUG("still on client\n"); } return ret; } /* Must be called with the lock held */ void i830_reclaim_buffers( drm_device_t *dev, struct file *filp ) { drm_device_dma_t *dma = dev->dma; int i; if (!dma) return; if (!dev->dev_private) return; if (!dma->buflist) return; i830_flush_queue(dev); for (i = 0; i < dma->buf_count; i++) { drm_buf_t *buf = dma->buflist[ i ]; drm_i830_buf_priv_t *buf_priv = buf->dev_private; if (buf->filp == filp && buf_priv) { int used = cmpxchg(buf_priv->in_use, I830_BUF_CLIENT, I830_BUF_FREE); if (used == I830_BUF_CLIENT) DRM_DEBUG("reclaimed from client\n"); if(buf_priv->currently_mapped == I830_BUF_MAPPED) buf_priv->currently_mapped = I830_BUF_UNMAPPED; } } } int i830_flush_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) { drm_file_t *priv = filp->private_data; drm_device_t *dev = priv->dev; if(!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)) { DRM_ERROR("i830_flush_ioctl called without lock held\n"); return -EINVAL; } i830_flush_queue(dev); return 0; } int i830_dma_vertex(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) { drm_file_t *priv = filp->private_data; drm_device_t *dev = priv->dev; drm_device_dma_t *dma = dev->dma; drm_i830_private_t *dev_priv = (drm_i830_private_t *)dev->dev_private; u32 *hw_status = dev_priv->hw_status_page; drm_i830_sarea_t *sarea_priv = (drm_i830_sarea_t *) dev_priv->sarea_priv; drm_i830_vertex_t vertex; if (copy_from_user(&vertex, (drm_i830_vertex_t __user *)arg, sizeof(vertex))) return -EFAULT; if(!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)) { DRM_ERROR("i830_dma_vertex called without lock held\n"); return -EINVAL; } DRM_DEBUG("i830 dma vertex, idx %d used %d discard %d\n", vertex.idx, vertex.used, vertex.discard); if(vertex.idx < 0 || vertex.idx > dma->buf_count) return -EINVAL; i830_dma_dispatch_vertex( dev, dma->buflist[ vertex.idx ], vertex.discard, vertex.used ); sarea_priv->last_enqueue = dev_priv->counter-1; sarea_priv->last_dispatch = (int) hw_status[5]; return 0; } int i830_clear_bufs(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) { drm_file_t *priv = filp->private_data; drm_device_t *dev = priv->dev; drm_i830_clear_t clear; if (copy_from_user(&clear, (drm_i830_clear_t __user *)arg, sizeof(clear))) return -EFAULT; if(!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)) { DRM_ERROR("i830_clear_bufs called without lock held\n"); return -EINVAL; } /* GH: Someone's doing nasty things... */ if (!dev->dev_private) { return -EINVAL; } i830_dma_dispatch_clear( dev, clear.flags, clear.clear_color, clear.clear_depth, clear.clear_depthmask); return 0; } int i830_swap_bufs(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) { drm_file_t *priv = filp->private_data; drm_device_t *dev = priv->dev; DRM_DEBUG("i830_swap_bufs\n"); if(!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)) { DRM_ERROR("i830_swap_buf called without lock held\n"); return -EINVAL; } i830_dma_dispatch_swap( dev ); return 0; } /* Not sure why this isn't set all the time: */ static void i830_do_init_pageflip( drm_device_t *dev ) { drm_i830_private_t *dev_priv = dev->dev_private; DRM_DEBUG("%s\n", __FUNCTION__); dev_priv->page_flipping = 1; dev_priv->current_page = 0; dev_priv->sarea_priv->pf_current_page = dev_priv->current_page; } int i830_do_cleanup_pageflip( drm_device_t *dev ) { drm_i830_private_t *dev_priv = dev->dev_private; DRM_DEBUG("%s\n", __FUNCTION__); if (dev_priv->current_page != 0) i830_dma_dispatch_flip( dev ); dev_priv->page_flipping = 0; return 0; } int i830_flip_bufs(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) { drm_file_t *priv = filp->private_data; drm_device_t *dev = priv->dev; drm_i830_private_t *dev_priv = dev->dev_private; DRM_DEBUG("%s\n", __FUNCTION__); if(!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)) { DRM_ERROR("i830_flip_buf called without lock held\n"); return -EINVAL; } if (!dev_priv->page_flipping) i830_do_init_pageflip( dev ); i830_dma_dispatch_flip( dev ); return 0; } int i830_getage(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) { drm_file_t *priv = filp->private_data; drm_device_t *dev = priv->dev; drm_i830_private_t *dev_priv = (drm_i830_private_t *)dev->dev_private; u32 *hw_status = dev_priv->hw_status_page; drm_i830_sarea_t *sarea_priv = (drm_i830_sarea_t *) dev_priv->sarea_priv; sarea_priv->last_dispatch = (int) hw_status[5]; return 0; } int i830_getbuf(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) { drm_file_t *priv = filp->private_data; drm_device_t *dev = priv->dev; int retcode = 0; drm_i830_dma_t d; drm_i830_private_t *dev_priv = (drm_i830_private_t *)dev->dev_private; u32 *hw_status = dev_priv->hw_status_page; drm_i830_sarea_t *sarea_priv = (drm_i830_sarea_t *) dev_priv->sarea_priv; DRM_DEBUG("getbuf\n"); if (copy_from_user(&d, (drm_i830_dma_t __user *)arg, sizeof(d))) return -EFAULT; if(!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)) { DRM_ERROR("i830_dma called without lock held\n"); return -EINVAL; } d.granted = 0; retcode = i830_dma_get_buffer(dev, &d, filp); DRM_DEBUG("i830_dma: %d returning %d, granted = %d\n", current->pid, retcode, d.granted); if (copy_to_user((drm_dma_t __user *)arg, &d, sizeof(d))) return -EFAULT; sarea_priv->last_dispatch = (int) hw_status[5]; return retcode; } int i830_copybuf(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) { /* Never copy - 2.4.x doesn't need it */ return 0; } int i830_docopy(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) { return 0; } int i830_getparam( struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg ) { drm_file_t *priv = filp->private_data; drm_device_t *dev = priv->dev; drm_i830_private_t *dev_priv = dev->dev_private; drm_i830_getparam_t param; int value; if ( !dev_priv ) { DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ ); return -EINVAL; } if (copy_from_user(¶m, (drm_i830_getparam_t __user *)arg, sizeof(param) )) return -EFAULT; switch( param.param ) { case I830_PARAM_IRQ_ACTIVE: value = dev->irq_enabled; break; default: return -EINVAL; } if ( copy_to_user( param.value, &value, sizeof(int) ) ) { DRM_ERROR( "copy_to_user\n" ); return -EFAULT; } return 0; } int i830_setparam( struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg ) { drm_file_t *priv = filp->private_data; drm_device_t *dev = priv->dev; drm_i830_private_t *dev_priv = dev->dev_private; drm_i830_setparam_t param; if ( !dev_priv ) { DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ ); return -EINVAL; } if (copy_from_user(¶m, (drm_i830_setparam_t __user *)arg, sizeof(param) )) return -EFAULT; switch( param.param ) { case I830_SETPARAM_USE_MI_BATCHBUFFER_START: dev_priv->use_mi_batchbuffer_start = param.value; break; default: return -EINVAL; } return 0; } static void i830_driver_pretakedown(drm_device_t *dev) { i830_dma_cleanup( dev ); } static void i830_driver_release(drm_device_t *dev, struct file *filp) { i830_reclaim_buffers(dev, filp); } static int i830_driver_dma_quiescent(drm_device_t *dev) { i830_dma_quiescent( dev ); return 0; } void i830_driver_register_fns(drm_device_t *dev) { dev->driver_features = DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_DMA | DRIVER_DMA_QUEUE; #if USE_IRQS dev->driver_features |= DRIVER_HAVE_IRQ | DRIVER_SHARED_IRQ; #endif dev->dev_priv_size = sizeof(drm_i830_buf_priv_t); dev->fn_tbl.pretakedown = i830_driver_pretakedown; dev->fn_tbl.release = i830_driver_release; dev->fn_tbl.dma_quiescent = i830_driver_dma_quiescent; dev->fn_tbl.reclaim_buffers = i830_reclaim_buffers; #if USE_IRQS dev->fn_tbl.irq_preinstall = i830_driver_irq_preinstall; dev->fn_tbl.irq_postinstall = i830_driver_irq_postinstall; dev->fn_tbl.irq_uninstall = i830_driver_irq_uninstall; dev->fn_tbl.irq_handler = i830_driver_irq_handler; #endif dev->counters += 4; dev->types[6] = _DRM_STAT_IRQ; dev->types[7] = _DRM_STAT_PRIMARY; dev->types[8] = _DRM_STAT_SECONDARY; dev->types[9] = _DRM_STAT_DMA; } a id='n1150' href='#n1150'>1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196
/*
 * Copyright (C) 2007 Ben Skeggs.
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, 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 NONINFRINGEMENT.
 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) 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.
 *
 */

#include "drmP.h"
#include "drm.h"
#include "nouveau_drv.h"

#define IS_G80 ((dev_priv->chipset & 0xf0) == 0x50)

static void
nv50_graph_init_reset(struct drm_device *dev)
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	uint32_t pmc_e = NV_PMC_ENABLE_PGRAPH | (1 << 21);

	DRM_DEBUG("\n");

	NV_WRITE(NV03_PMC_ENABLE, NV_READ(NV03_PMC_ENABLE) & ~pmc_e);
	NV_WRITE(NV03_PMC_ENABLE, NV_READ(NV03_PMC_ENABLE) |  pmc_e);
}

static void
nv50_graph_init_intr(struct drm_device *dev)
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;

	DRM_DEBUG("\n");
	NV_WRITE(NV03_PGRAPH_INTR, 0xffffffff);
	NV_WRITE(0x400138, 0xffffffff);
	NV_WRITE(NV40_PGRAPH_INTR_EN, 0xffffffff);
}

static void
nv50_graph_init_regs__nv(struct drm_device *dev)
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;

	DRM_DEBUG("\n");

	NV_WRITE(0x400804, 0xc0000000);
	NV_WRITE(0x406800, 0xc0000000);
	NV_WRITE(0x400c04, 0xc0000000);
	NV_WRITE(0x401804, 0xc0000000);
	NV_WRITE(0x405018, 0xc0000000);
	NV_WRITE(0x402000, 0xc0000000);

	NV_WRITE(0x400108, 0xffffffff);

	NV_WRITE(0x400824, 0x00004000);
	NV_WRITE(0x400500, 0x00010001);
}

static void
nv50_graph_init_regs(struct drm_device *dev)
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;

	DRM_DEBUG("\n");

	NV_WRITE(NV04_PGRAPH_DEBUG_3, (1<<2) /* HW_CONTEXT_SWITCH_ENABLED */);
}

static uint32_t nv84_ctx_voodoo[] = {
	0x0070008e, 0x0070009c, 0x00200020, 0x00600008, 0x0050004c, 0x00400e89,
	0x00200000, 0x00600007, 0x00300000, 0x00c000ff, 0x00200000, 0x008000ff,
	0x00700009, 0x0041634d, 0x00402944, 0x00402905, 0x0040290d, 0x00413e06,
	0x00600005, 0x004015c5, 0x00600011, 0x0040270b, 0x004021c5, 0x00700000,
	0x00700081, 0x00600004, 0x0050004a, 0x00216f40, 0x00600007, 0x00c02801,
	0x0020002e, 0x00800001, 0x005000cb, 0x0090ffff, 0x0091ffff, 0x00200020,
	0x00600008, 0x0050004c, 0x00600009, 0x00413e45, 0x0041594d, 0x0070009d,
	0x00402dcf, 0x0070009f, 0x0050009f, 0x00402ac0, 0x00200200, 0x00600008,
	0x00402a4f, 0x00402ac0, 0x004030cc, 0x00700081, 0x00200000, 0x00600006,
	0x00700000, 0x00111bfc, 0x00700083, 0x00300000, 0x00216f40, 0x00600007,
	0x00c00b01, 0x0020001e, 0x00800001, 0x005000cb, 0x00c000ff, 0x00700080,
	0x00700083, 0x00200047, 0x00600006, 0x0011020a, 0x00200480, 0x00600007,
	0x00300000, 0x00c000ff, 0x00c800ff, 0x00414907, 0x00202916, 0x008000ff,
	0x0040508c, 0x005000cb, 0x00a0023f, 0x00200040, 0x00600006, 0x0070000f,
	0x00170202, 0x0011020a, 0x00200032, 0x0010020d, 0x001c0242, 0x00120302,
	0x00140402, 0x00180500, 0x00130509, 0x00150550, 0x00110605, 0x0020000f,
	0x00100607, 0x00110700, 0x00110900, 0x00120902, 0x00110a00, 0x00160b02,
	0x00120b28, 0x00140b2b, 0x00110c01, 0x00111400, 0x00111405, 0x00111407,
	0x00111409, 0x0011140b, 0x002000cb, 0x00101500, 0x0040790f, 0x0040794b,
	0x00214d40, 0x00600007, 0x0020043e, 0x008800ff, 0x0070008f, 0x0040798c,
	0x005000cb, 0x00000000, 0x0020002b, 0x00101a05, 0x00131c00, 0x00121c04,
	0x00141c20, 0x00111c25, 0x00131c40, 0x00121c44, 0x00141c60, 0x00111c65,
	0x00131c80, 0x00121c84, 0x00141ca0, 0x00111ca5, 0x00131cc0, 0x00121cc4,
	0x00141ce0, 0x00111ce5, 0x00131f00, 0x00191f40, 0x0040a1e0, 0x002001ed,
	0x00600006, 0x00200044, 0x00102080, 0x001120c6, 0x001520c9, 0x001920d0,
	0x00122100, 0x00122103, 0x00162200, 0x00122207, 0x00112280, 0x00112300,
	0x00112302, 0x00122380, 0x0011238b, 0x00112394, 0x0011239c, 0x0040bee1,
	0x00200254, 0x00600006, 0x00200044, 0x00102480, 0x0040af0f, 0x0040af4b,
	0x00214d40, 0x00600007, 0x0020043e, 0x008800ff, 0x0070008f, 0x0040af8c,
	0x005000cb, 0x00000000, 0x001124c6, 0x001524c9, 0x001924d0, 0x00122500,
	0x00122503, 0x00162600, 0x00122607, 0x00112680, 0x00112700, 0x00112702,
	0x00122780, 0x0011278b, 0x00112794, 0x0011279c, 0x0040d1e2, 0x002002bb,
	0x00600006, 0x00200044, 0x00102880, 0x001128c6, 0x001528c9, 0x001928d0,
	0x00122900, 0x00122903, 0x00162a00, 0x00122a07, 0x00112a80, 0x00112b00,
	0x00112b02, 0x00122b80, 0x00112b8b, 0x00112b94, 0x00112b9c, 0x0040eee3,
	0x00200322, 0x00600006, 0x00200044, 0x00102c80, 0x0040df0f, 0x0040df4b,
	0x00214d40, 0x00600007, 0x0020043e, 0x008800ff, 0x0070008f, 0x0040df8c,
	0x005000cb, 0x00000000, 0x00112cc6, 0x00152cc9, 0x00192cd0, 0x00122d00,
	0x00122d03, 0x00162e00, 0x00122e07, 0x00112e80, 0x00112f00, 0x00112f02,
	0x00122f80, 0x00112f8b, 0x00112f94, 0x00112f9c, 0x004101e4, 0x00200389,
	0x00600006, 0x00200044, 0x00103080, 0x001130c6, 0x001530c9, 0x001930d0,
	0x00123100, 0x00123103, 0x00163200, 0x00123207, 0x00113280, 0x00113300,
	0x00113302, 0x00123380, 0x0011338b, 0x00113394, 0x0011339c, 0x00411ee5,
	0x002003f0, 0x00600006, 0x00200044, 0x00103480, 0x00410f0f, 0x00410f4b,
	0x00214d40, 0x00600007, 0x0020043e, 0x008800ff, 0x0070008f, 0x00410f8c,
	0x005000cb, 0x00000000, 0x001134c6, 0x001534c9, 0x001934d0, 0x00123500,
	0x00123503, 0x00163600, 0x00123607, 0x00113680, 0x00113700, 0x00113702,
	0x00123780, 0x0011378b, 0x00113794, 0x0011379c, 0x00000000, 0x0041250f,
	0x005000cb, 0x00214d40, 0x00600007, 0x0020043e, 0x008800ff, 0x005000cb,
	0x00412887, 0x0060000a, 0x00000000, 0x00413700, 0x007000a0, 0x00700080,
	0x00200480, 0x00600007, 0x00200004, 0x00c000ff, 0x008000ff, 0x005000cb,
	0x00700000, 0x00200000, 0x00600006, 0x00111bfe, 0x0041594d, 0x00700000,
	0x00200000, 0x00600006, 0x00111bfe, 0x00700080, 0x0070001d, 0x0040114d,
	0x00700081, 0x00600004, 0x0050004a, 0x00414388, 0x0060000b, 0x00200000,
	0x00600006, 0x00700000, 0x0041590b, 0x00111bfd, 0x0040424d, 0x00202916,
	0x008000fd, 0x005000cb, 0x00c00002, 0x00200480, 0x00600007, 0x00200160,
	0x00800002, 0x005000cb, 0x00c01802, 0x002027b6, 0x00800002, 0x005000cb,
	0x00404e4d, 0x0060000b, 0x0041574d, 0x00700001, 0x005000cf, 0x00700003,
	0x00415e06, 0x00415f05, 0x0060000d, 0x00700005, 0x0070000d, 0x00700006,
	0x0070000b, 0x0070000e, 0x0070001c, 0x0060000c, ~0
};
 
static uint32_t nv86_ctx_voodoo[] = {
	0x0070008e, 0x0070009c, 0x00200020, 0x00600008, 0x0050004c, 0x00400e89,
	0x00200000, 0x00600007, 0x00300000, 0x00c000ff, 0x00200000, 0x008000ff,
	0x00700009, 0x0040dd4d, 0x00402944, 0x00402905, 0x0040290d, 0x0040b906,
	0x00600005, 0x004015c5, 0x00600011, 0x0040270b, 0x004021c5, 0x00700000,
	0x00700081, 0x00600004, 0x0050004a, 0x00216d80, 0x00600007, 0x00c02801,
	0x0020002e, 0x00800001, 0x005000cb, 0x0090ffff, 0x0091ffff, 0x00200020,
	0x00600008, 0x0050004c, 0x00600009, 0x0040b945, 0x0040d44d, 0x0070009d,
	0x00402dcf, 0x0070009f, 0x0050009f, 0x00402ac0, 0x00200200, 0x00600008,
	0x00402a4f, 0x00402ac0, 0x004030cc, 0x00700081, 0x00200000, 0x00600006,
	0x00700000, 0x00111bfc, 0x00700083, 0x00300000, 0x00216d80, 0x00600007,
	0x00c00b01, 0x0020001e, 0x00800001, 0x005000cb, 0x00c000ff, 0x00700080,
	0x00700083, 0x00200047, 0x00600006, 0x0011020a, 0x00200280, 0x00600007,
	0x00300000, 0x00c000ff, 0x00c800ff, 0x0040c407, 0x00202916, 0x008000ff,
	0x0040508c, 0x005000cb, 0x00a0023f, 0x00200040, 0x00600006, 0x0070000f,
	0x00170202, 0x0011020a, 0x00200032, 0x0010020d, 0x001c0242, 0x00120302,
	0x00140402, 0x00180500, 0x00130509, 0x00150550, 0x00110605, 0x0020000f,
	0x00100607, 0x00110700, 0x00110900, 0x00120902, 0x00110a00, 0x00160b02,
	0x00120b28, 0x00140b2b, 0x00110c01, 0x00111400, 0x00111405, 0x00111407,
	0x00111409, 0x0011140b, 0x002000cb, 0x00101500, 0x0040790f, 0x0040794b,
	0x00214b40, 0x00600007, 0x00200442, 0x008800ff, 0x0070008f, 0x0040798c,
	0x005000cb, 0x00000000, 0x0020002b, 0x00101a05, 0x00131c00, 0x00121c04,
	0x00141c20, 0x00111c25, 0x00131c40, 0x00121c44, 0x00141c60, 0x00111c65,
	0x00131f00, 0x00191f40, 0x004099e0, 0x002001d9, 0x00600006, 0x00200044,
	0x00102080, 0x001120c6, 0x001520c9, 0x001920d0, 0x00122100, 0x00122103,
	0x00162200, 0x00122207, 0x00112280, 0x00112300, 0x00112302, 0x00122380,
	0x0011238b, 0x00112394, 0x0011239c, 0x00000000, 0x0040a00f, 0x005000cb,
	0x00214b40, 0x00600007, 0x00200442, 0x008800ff, 0x005000cb, 0x0040a387,
	0x0060000a, 0x00000000, 0x0040b200, 0x007000a0, 0x00700080, 0x00200280,
	0x00600007, 0x00200004, 0x00c000ff, 0x008000ff, 0x005000cb, 0x00700000,
	0x00200000, 0x00600006, 0x00111bfe, 0x0040d44d, 0x00700000, 0x00200000,
	0x00600006, 0x00111bfe, 0x00700080, 0x0070001d, 0x0040114d, 0x00700081,
	0x00600004, 0x0050004a, 0x0040be88, 0x0060000b, 0x00200000, 0x00600006,
	0x00700000, 0x0040d40b, 0x00111bfd, 0x0040424d, 0x00202916, 0x008000fd,
	0x005000cb, 0x00c00002, 0x00200280, 0x00600007, 0x00200160, 0x00800002,
	0x005000cb, 0x00c01802, 0x002027b6, 0x00800002, 0x005000cb, 0x00404e4d,
	0x0060000b, 0x0040d24d, 0x00700001, 0x00700003, 0x0040d806, 0x0040d905,
	0x0060000d, 0x00700005, 0x0070000d, 0x00700006, 0x0070000b, 0x0070000e,
	0x0060000c, ~0
};

static int
nv50_graph_init_ctxctl(struct drm_device *dev)
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	uint32_t *voodoo = NULL;

	DRM_DEBUG("\n");

	switch (dev_priv->chipset) {
	case 0x84:
		voodoo = nv84_ctx_voodoo;
		break;
	case 0x86:
		voodoo = nv86_ctx_voodoo;
		break;
	default:
		DRM_ERROR("no voodoo for chipset NV%02x\n", dev_priv->chipset);
		return -EINVAL;
	}

	NV_WRITE(NV40_PGRAPH_CTXCTL_UCODE_INDEX, 0);
	while (*voodoo != ~0) {
		NV_WRITE(NV40_PGRAPH_CTXCTL_UCODE_DATA, *voodoo);
		voodoo++;
	}

	NV_WRITE(0x400320, 4);
	NV_WRITE(NV40_PGRAPH_CTXCTL_CUR, 0);
	NV_WRITE(NV20_PGRAPH_CHANNEL_CTX_POINTER, 0);

	return 0;
}

int
nv50_graph_init(struct drm_device *dev)
{
	int ret;

	DRM_DEBUG("\n");

	nv50_graph_init_reset(dev);
	nv50_graph_init_intr(dev);
	nv50_graph_init_regs__nv(dev);
	nv50_graph_init_regs(dev);

	ret = nv50_graph_init_ctxctl(dev);
	if (ret)
		return ret;

	return 0;
}

void
nv50_graph_takedown(struct drm_device *dev)
{
	DRM_DEBUG("\n");
}

static void
nv86_graph_init_ctxvals(struct drm_device *dev, struct nouveau_gpuobj_ref *ref)
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	struct nouveau_gpuobj *ctx = ref->gpuobj;

	INSTANCE_WR(ctx, 0x10C/4, 0x30);
	INSTANCE_WR(ctx, 0x1D4/4, 0x3);
	INSTANCE_WR(ctx, 0x1D8/4, 0x1000);
	INSTANCE_WR(ctx, 0x218/4, 0xFE0C);
	INSTANCE_WR(ctx, 0x22C/4, 0x1000);
	INSTANCE_WR(ctx, 0x258/4, 0x187);
	INSTANCE_WR(ctx, 0x26C/4, 0x1018);
	INSTANCE_WR(ctx, 0x270/4, 0xFF);
	INSTANCE_WR(ctx, 0x2AC/4, 0x4);
	INSTANCE_WR(ctx, 0x2B0/4, 0x44D00DF);
	INSTANCE_WR(ctx, 0x2B8/4, 0x600);
	INSTANCE_WR(ctx, 0x2D0/4, 0x1000000);
	INSTANCE_WR(ctx, 0x2D4/4, 0xFF);
	INSTANCE_WR(ctx, 0x2DC/4, 0x400);
	INSTANCE_WR(ctx, 0x2F4/4, 0x1);
	INSTANCE_WR(ctx, 0x2F8/4, 0x80);
	INSTANCE_WR(ctx, 0x2FC/4, 0x4);
	INSTANCE_WR(ctx, 0x318/4, 0x2);
	INSTANCE_WR(ctx, 0x31C/4, 0x1);
	INSTANCE_WR(ctx, 0x328/4, 0x1);
	INSTANCE_WR(ctx, 0x32C/4, 0x100);
	INSTANCE_WR(ctx, 0x344/4, 0x2);
	INSTANCE_WR(ctx, 0x348/4, 0x1);
	INSTANCE_WR(ctx, 0x34C/4, 0x1);
	INSTANCE_WR(ctx, 0x35C/4, 0x1);
	INSTANCE_WR(ctx, 0x360/4, 0x3FFFFF);
	INSTANCE_WR(ctx, 0x364/4, 0x1FFF);
	INSTANCE_WR(ctx, 0x36C/4, 0x1);
	INSTANCE_WR(ctx, 0x370/4, 0x1);
	INSTANCE_WR(ctx, 0x378/4, 0x1);
	INSTANCE_WR(ctx, 0x37C/4, 0x1);
	INSTANCE_WR(ctx, 0x380/4, 0x1);
	INSTANCE_WR(ctx, 0x384/4, 0x4);
	INSTANCE_WR(ctx, 0x388/4, 0x1);
	INSTANCE_WR(ctx, 0x38C/4, 0x1);
	INSTANCE_WR(ctx, 0x390/4, 0x1);
	INSTANCE_WR(ctx, 0x394/4, 0x7);
	INSTANCE_WR(ctx, 0x398/4, 0x1);
	INSTANCE_WR(ctx, 0x39C/4, 0x7);
	INSTANCE_WR(ctx, 0x3A0/4, 0x1);
	INSTANCE_WR(ctx, 0x3A4/4, 0x1);
	INSTANCE_WR(ctx, 0x3A8/4, 0x1);
	INSTANCE_WR(ctx, 0x3BC/4, 0x1);
	INSTANCE_WR(ctx, 0x3C0/4, 0x100);
	INSTANCE_WR(ctx, 0x3C8/4, 0x1);
	INSTANCE_WR(ctx, 0x3D4/4, 0x100);
	INSTANCE_WR(ctx, 0x3D8/4, 0x1);
	INSTANCE_WR(ctx, 0x3DC/4, 0x100);
	INSTANCE_WR(ctx, 0x3E4/4, 0x1);
	INSTANCE_WR(ctx, 0x3F0/4, 0x100);
	INSTANCE_WR(ctx, 0x404/4, 0x4);
	INSTANCE_WR(ctx, 0x408/4, 0x70);
	INSTANCE_WR(ctx, 0x40C/4, 0x80);
	INSTANCE_WR(ctx, 0x420/4, 0xC);
	INSTANCE_WR(ctx, 0x428/4, 0x8);
	INSTANCE_WR(ctx, 0x42C/4, 0x14);
	INSTANCE_WR(ctx, 0x434/4, 0x29);
	INSTANCE_WR(ctx, 0x438/4, 0x27);
	INSTANCE_WR(ctx, 0x43C/4, 0x26);
	INSTANCE_WR(ctx, 0x440/4, 0x8);
	INSTANCE_WR(ctx, 0x444/4, 0x4);
	INSTANCE_WR(ctx, 0x448/4, 0x27);
	INSTANCE_WR(ctx, 0x454/4, 0x1);
	INSTANCE_WR(ctx, 0x458/4, 0x2);
	INSTANCE_WR(ctx, 0x45C/4, 0x3);
	INSTANCE_WR(ctx, 0x460/4, 0x4);
	INSTANCE_WR(ctx, 0x464/4, 0x5);
	INSTANCE_WR(ctx, 0x468/4, 0x6);
	INSTANCE_WR(ctx, 0x46C/4, 0x7);
	INSTANCE_WR(ctx, 0x470/4, 0x1);
	INSTANCE_WR(ctx, 0x4B4/4, 0xCF);
	INSTANCE_WR(ctx, 0x4E4/4, 0x80);
	INSTANCE_WR(ctx, 0x4E8/4, 0x4);
	INSTANCE_WR(ctx, 0x4EC/4, 0x4);
	INSTANCE_WR(ctx, 0x4F0/4, 0x3);
	INSTANCE_WR(ctx, 0x4F4/4, 0x1);
	INSTANCE_WR(ctx, 0x500/4, 0x12);
	INSTANCE_WR(ctx, 0x504/4, 0x10);
	INSTANCE_WR(ctx, 0x508/4, 0xC);
	INSTANCE_WR(ctx, 0x50C/4, 0x1);
	INSTANCE_WR(ctx, 0x51C/4, 0x4);
	INSTANCE_WR(ctx, 0x520/4, 0x2);
	INSTANCE_WR(ctx, 0x524/4, 0x4);
	INSTANCE_WR(ctx, 0x530/4, 0x3FFFFF);
	INSTANCE_WR(ctx, 0x534/4, 0x1FFF);
	INSTANCE_WR(ctx, 0x55C/4, 0x4);
	INSTANCE_WR(ctx, 0x560/4, 0x14);
	INSTANCE_WR(ctx, 0x564/4, 0x1);
	INSTANCE_WR(ctx, 0x570/4, 0x2);
	INSTANCE_WR(ctx, 0x57C/4, 0x1);
	INSTANCE_WR(ctx, 0x584/4, 0x2);
	INSTANCE_WR(ctx, 0x588/4, 0x1000);
	INSTANCE_WR(ctx, 0x58C/4, 0xE00);
	INSTANCE_WR(ctx, 0x590/4, 0x1000);
	INSTANCE_WR(ctx, 0x594/4, 0x1E00);
	INSTANCE_WR(ctx, 0x59C/4, 0x1);
	INSTANCE_WR(ctx, 0x5A0/4, 0x1);
	INSTANCE_WR(ctx, 0x5A4/4, 0x1);
	INSTANCE_WR(ctx, 0x5A8/4, 0x1);
	INSTANCE_WR(ctx, 0x5AC/4, 0x1);
	INSTANCE_WR(ctx, 0x5BC/4, 0x200);
	INSTANCE_WR(ctx, 0x5C4/4, 0x1);
	INSTANCE_WR(ctx, 0x5C8/4, 0x70);
	INSTANCE_WR(ctx, 0x5CC/4, 0x80);
	INSTANCE_WR(ctx, 0x5D8/4, 0x1);
	INSTANCE_WR(ctx, 0x5DC/4, 0x70);
	INSTANCE_WR(ctx, 0x5E0/4, 0x80);
	INSTANCE_WR(ctx, 0x5F0/4, 0x1);
	INSTANCE_WR(ctx, 0x5F4/4, 0xCF);
	INSTANCE_WR(ctx, 0x5FC/4, 0x1);
	INSTANCE_WR(ctx, 0x60C/4, 0xCF);
	INSTANCE_WR(ctx, 0x614/4, 0x2);
	INSTANCE_WR(ctx, 0x61C/4, 0x1);
	INSTANCE_WR(ctx, 0x624/4, 0x1);
	INSTANCE_WR(ctx, 0x62C/4, 0xCF);
	INSTANCE_WR(ctx, 0x630/4, 0xCF);
	INSTANCE_WR(ctx, 0x634/4, 0x1);
	INSTANCE_WR(ctx, 0x63C/4, 0xF80);
	INSTANCE_WR(ctx, 0x684/4, 0x7F0080);
	INSTANCE_WR(ctx, 0x6C0/4, 0x7F0080);
	INSTANCE_WR(ctx, 0x6E4/4, 0x3B74F821);
	INSTANCE_WR(ctx, 0x6E8/4, 0x89058001);
	INSTANCE_WR(ctx, 0x6F0/4, 0x1000);
	INSTANCE_WR(ctx, 0x6F4/4, 0x1F);
	INSTANCE_WR(ctx, 0x6F8/4, 0x27C10FA);
	INSTANCE_WR(ctx, 0x6FC/4, 0x400000C0);
	INSTANCE_WR(ctx, 0x700/4, 0xB7892080);
	INSTANCE_WR(ctx, 0x70C/4, 0x3B74F821);
	INSTANCE_WR(ctx, 0x710/4, 0x89058001);
	INSTANCE_WR(ctx, 0x718/4, 0x1000);
	INSTANCE_WR(ctx, 0x71C/4, 0x1F);
	INSTANCE_WR(ctx, 0x720/4, 0x27C10FA);
	INSTANCE_WR(ctx, 0x724/4, 0x400000C0);
	INSTANCE_WR(ctx, 0x728/4, 0xB7892080);
	INSTANCE_WR(ctx, 0x734/4, 0x10040);
	INSTANCE_WR(ctx, 0x73C/4, 0x22);
	INSTANCE_WR(ctx, 0x748/4, 0x10040);
	INSTANCE_WR(ctx, 0x74C/4, 0x22);
	INSTANCE_WR(ctx, 0x764/4, 0x1800000);
	INSTANCE_WR(ctx, 0x768/4, 0x160000);
	INSTANCE_WR(ctx, 0x76C/4, 0x1800000);
	INSTANCE_WR(ctx, 0x77C/4, 0x3FFFF);
	INSTANCE_WR(ctx, 0x780/4, 0x8C0000);
	INSTANCE_WR(ctx, 0x7A4/4, 0x10401);
	INSTANCE_WR(ctx, 0x7AC/4, 0x78);
	INSTANCE_WR(ctx, 0x7B4/4, 0xBF);
	INSTANCE_WR(ctx, 0x7BC/4, 0x1210);
	INSTANCE_WR(ctx, 0x7C0/4, 0x8000080);
	INSTANCE_WR(ctx, 0x7E4/4, 0x1800000);
	INSTANCE_WR(ctx, 0x7E8/4, 0x160000);
	INSTANCE_WR(ctx, 0x7EC/4, 0x1800000);
	INSTANCE_WR(ctx, 0x7FC/4, 0x3FFFF);
	INSTANCE_WR(ctx, 0x800/4, 0x8C0000);
	INSTANCE_WR(ctx, 0x824/4, 0x10401);
	INSTANCE_WR(ctx, 0x82C/4, 0x78);
	INSTANCE_WR(ctx, 0x834/4, 0xBF);
	INSTANCE_WR(ctx, 0x83C/4, 0x1210);
	INSTANCE_WR(ctx, 0x840/4, 0x8000080);
	INSTANCE_WR(ctx, 0x868/4, 0x27070);
	INSTANCE_WR(ctx, 0x874/4, 0x3FFFFFF);
	INSTANCE_WR(ctx, 0x88C/4, 0x120407);
	INSTANCE_WR(ctx, 0x890/4, 0x5091507);
	INSTANCE_WR(ctx, 0x894/4, 0x5010202);
	INSTANCE_WR(ctx, 0x898/4, 0x30201);
	INSTANCE_WR(ctx, 0x8B4/4, 0x40);
	INSTANCE_WR(ctx, 0x8B8/4, 0xD0C0B0A);
	INSTANCE_WR(ctx, 0x8BC/4, 0x141210);
	INSTANCE_WR(ctx, 0x8C0/4, 0x1F0);
	INSTANCE_WR(ctx, 0x8C4/4, 0x1);
	INSTANCE_WR(ctx, 0x8C8/4, 0x3);
	INSTANCE_WR(ctx, 0x8D4/4, 0x39E00);
	INSTANCE_WR(ctx, 0x8D8/4, 0x100);
	INSTANCE_WR(ctx, 0x8DC/4, 0x3800);
	INSTANCE_WR(ctx, 0x8E0/4, 0x404040);
	INSTANCE_WR(ctx, 0x8E4/4, 0xFF0A);
	INSTANCE_WR(ctx, 0x8EC/4, 0x77F005);
	INSTANCE_WR(ctx, 0x8F0/4, 0x3F7FFF);
	INSTANCE_WR(ctx, 0x7BA0/4, 0x21);
	INSTANCE_WR(ctx, 0x7BC0/4, 0x1);
	INSTANCE_WR(ctx, 0x7BE0/4, 0x2);
	INSTANCE_WR(ctx, 0x7C00/4, 0x100);
	INSTANCE_WR(ctx, 0x7C20/4, 0x100);
	INSTANCE_WR(ctx, 0x7C40/4, 0x1);
	INSTANCE_WR(ctx, 0x7CA0/4, 0x1);
	INSTANCE_WR(ctx, 0x7CC0/4, 0x2);
	INSTANCE_WR(ctx, 0x7CE0/4, 0x100);
	INSTANCE_WR(ctx, 0x7D00/4, 0x100);
	INSTANCE_WR(ctx, 0x7D20/4, 0x1);
	INSTANCE_WR(ctx, 0x11640/4, 0x4);
	INSTANCE_WR(ctx, 0x11660/4, 0x4);
	INSTANCE_WR(ctx, 0x49FE0/4, 0x4);
	INSTANCE_WR(ctx, 0x4A000/4, 0x4);
	INSTANCE_WR(ctx, 0x4A020/4, 0x8100C12);
	INSTANCE_WR(ctx, 0x4A040/4, 0x3);
	INSTANCE_WR(ctx, 0x4A080/4, 0x8100C12);
	INSTANCE_WR(ctx, 0x4A0C0/4, 0x80C14);
	INSTANCE_WR(ctx, 0x4A0E0/4, 0x1);
	INSTANCE_WR(ctx, 0x4A100/4, 0x80C14);
	INSTANCE_WR(ctx, 0x4A160/4, 0x8100C12);
	INSTANCE_WR(ctx, 0x4A180/4, 0x27);
	INSTANCE_WR(ctx, 0x4A1E0/4, 0x1);
	INSTANCE_WR(ctx, 0x51A20/4, 0x1);
	INSTANCE_WR(ctx, 0x51D00/4, 0x8100C12);
	INSTANCE_WR(ctx, 0x51EA0/4, 0x4000000);
	INSTANCE_WR(ctx, 0x51EC0/4, 0x4000000);
	INSTANCE_WR(ctx, 0x51F00/4, 0x80);
	INSTANCE_WR(ctx, 0x51F80/4, 0x80);
	INSTANCE_WR(ctx, 0x51FC0/4, 0x3F);
	INSTANCE_WR(ctx, 0x52120/4, 0x2);
	INSTANCE_WR(ctx, 0x52140/4, 0x4000000);
	INSTANCE_WR(ctx, 0x52160/4, 0x4000000);
	INSTANCE_WR(ctx, 0x52280/4, 0x4);
	INSTANCE_WR(ctx, 0x52300/4, 0x4);
	INSTANCE_WR(ctx, 0x52540/4, 0x1);
	INSTANCE_WR(ctx, 0x52560/4, 0x1001);
	INSTANCE_WR(ctx, 0x52580/4, 0xFFFF);
	INSTANCE_WR(ctx, 0x525A0/4, 0xFFFF);
	INSTANCE_WR(ctx, 0x525C0/4, 0xFFFF);
	INSTANCE_WR(ctx, 0x525E0/4, 0xFFFF);
	INSTANCE_WR(ctx, 0x52A00/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x52A20/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x52A40/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x52A60/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x52A80/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x52AA0/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x52AC0/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x52AE0/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x52B00/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x52B20/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x52B40/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x52B60/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x52B80/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x52BA0/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x52BC0/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x52BE0/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x52C00/4, 0x10);
	INSTANCE_WR(ctx, 0x52C60/4, 0x3);
	INSTANCE_WR(ctx, 0xA84/4, 0xF);
	INSTANCE_WR(ctx, 0xB24/4, 0x20);
	INSTANCE_WR(ctx, 0xD04/4, 0x1A);
	INSTANCE_WR(ctx, 0xEC4/4, 0x4);
	INSTANCE_WR(ctx, 0xEE4/4, 0x4);
	INSTANCE_WR(ctx, 0xF24/4, 0x4);
	INSTANCE_WR(ctx, 0xF44/4, 0x8);
	INSTANCE_WR(ctx, 0xF84/4, 0x7FF);
	INSTANCE_WR(ctx, 0x1124/4, 0xF);
	INSTANCE_WR(ctx, 0x3604/4, 0xF);
	INSTANCE_WR(ctx, 0x3644/4, 0x1);
	INSTANCE_WR(ctx, 0x41A4/4, 0xF);
	INSTANCE_WR(ctx, 0x14844/4, 0xF);
	INSTANCE_WR(ctx, 0x14AE4/4, 0x1);
	INSTANCE_WR(ctx, 0x14B04/4, 0x100);
	INSTANCE_WR(ctx, 0x14B24/4, 0x100);
	INSTANCE_WR(ctx, 0x14B44/4, 0x11);
	INSTANCE_WR(ctx, 0x14B84/4, 0x8);
	INSTANCE_WR(ctx, 0x14C44/4, 0x1);
	INSTANCE_WR(ctx, 0x14C84/4, 0x1);
	INSTANCE_WR(ctx, 0x14CA4/4, 0x1);
	INSTANCE_WR(ctx, 0x14CC4/4, 0x1);
	INSTANCE_WR(ctx, 0x14CE4/4, 0xCF);
	INSTANCE_WR(ctx, 0x14D04/4, 0x2);
	INSTANCE_WR(ctx, 0x14DE4/4, 0x1);
	INSTANCE_WR(ctx, 0x14E24/4, 0x1);
	INSTANCE_WR(ctx, 0x14E44/4, 0x1);
	INSTANCE_WR(ctx, 0x14E64/4, 0x1);
	INSTANCE_WR(ctx, 0x14F04/4, 0x4);
	INSTANCE_WR(ctx, 0x14F44/4, 0x1);
	INSTANCE_WR(ctx, 0x14F64/4, 0x15);
	INSTANCE_WR(ctx, 0x14FE4/4, 0x4444480);
	INSTANCE_WR(ctx, 0x15764/4, 0x8100C12);
	INSTANCE_WR(ctx, 0x15804/4, 0x100);
	INSTANCE_WR(ctx, 0x15864/4, 0x10001);
	INSTANCE_WR(ctx, 0x158A4/4, 0x10001);
	INSTANCE_WR(ctx, 0x158C4/4, 0x1);
	INSTANCE_WR(ctx, 0x158E4/4, 0x10001);
	INSTANCE_WR(ctx, 0x15904/4, 0x1);
	INSTANCE_WR(ctx, 0x15924/4, 0x4);
	INSTANCE_WR(ctx, 0x15944/4, 0x2);
	INSTANCE_WR(ctx, 0x166C4/4, 0x4E3BFDF);
	INSTANCE_WR(ctx, 0x166E4/4, 0x4E3BFDF);
	INSTANCE_WR(ctx, 0x16784/4, 0xFAC6881);
	INSTANCE_WR(ctx, 0x16904/4, 0x4E3BFDF);
	INSTANCE_WR(ctx, 0x16924/4, 0x4E3BFDF);
	INSTANCE_WR(ctx, 0x15948/4, 0x3FFFFF);
	INSTANCE_WR(ctx, 0x159A8/4, 0x1FFF);
	INSTANCE_WR(ctx, 0x15B88/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x15C68/4, 0x4);
	INSTANCE_WR(ctx, 0x15C88/4, 0x1A);
	INSTANCE_WR(ctx, 0x15CE8/4, 0x1);
	INSTANCE_WR(ctx, 0x15F48/4, 0xFFFF00);
	INSTANCE_WR(ctx, 0x16028/4, 0xF);
	INSTANCE_WR(ctx, 0x16128/4, 0xFAC6881);
	INSTANCE_WR(ctx, 0x16148/4, 0x11);
	INSTANCE_WR(ctx, 0x16348/4, 0x4);
	INSTANCE_WR(ctx, 0x163E8/4, 0x2);
	INSTANCE_WR(ctx, 0x16408/4, 0x4000000);
	INSTANCE_WR(ctx, 0x16428/4, 0x4000000);
	INSTANCE_WR(ctx, 0x164A8/4, 0x5);
	INSTANCE_WR(ctx, 0x164C8/4, 0x52);
	INSTANCE_WR(ctx, 0x16568/4, 0x1);
	INSTANCE_WR(ctx, 0x16788/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x167A8/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x167C8/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x167E8/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x16808/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x16828/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x16848/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x16868/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x16888/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x168A8/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x168C8/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x168E8/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x16908/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x16928/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x16948/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x16968/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x16988/4, 0x10);
	INSTANCE_WR(ctx, 0x16E68/4, 0x8100C12);
	INSTANCE_WR(ctx, 0x16E88/4, 0x5);
	INSTANCE_WR(ctx, 0x16EE8/4, 0x1);
	INSTANCE_WR(ctx, 0x16F28/4, 0xFFFF);
	INSTANCE_WR(ctx, 0x16F48/4, 0xFFFF);
	INSTANCE_WR(ctx, 0x16F68/4, 0xFFFF);
	INSTANCE_WR(ctx, 0x16F88/4, 0xFFFF);
	INSTANCE_WR(ctx, 0x16FA8/4, 0x3);
	INSTANCE_WR(ctx, 0x173A8/4, 0xFFFF00);
	INSTANCE_WR(ctx, 0x173C8/4, 0x1A);
	INSTANCE_WR(ctx, 0x17408/4, 0x3);
	INSTANCE_WR(ctx, 0x178E8/4, 0x102);
	INSTANCE_WR(ctx, 0x17928/4, 0x4);
	INSTANCE_WR(ctx, 0x17948/4, 0x4);
	INSTANCE_WR(ctx, 0x17968/4, 0x4);
	INSTANCE_WR(ctx, 0x17988/4, 0x4);
	INSTANCE_WR(ctx, 0x179A8/4, 0x4);
	INSTANCE_WR(ctx, 0x179C8/4, 0x4);
	INSTANCE_WR(ctx, 0x17A08/4, 0x7FF);
	INSTANCE_WR(ctx, 0x17A48/4, 0x102);
	INSTANCE_WR(ctx, 0x17B88/4, 0x4);
	INSTANCE_WR(ctx, 0x17BA8/4, 0x4);
	INSTANCE_WR(ctx, 0x17BC8/4, 0x4);
	INSTANCE_WR(ctx, 0x17BE8/4, 0x4);
	INSTANCE_WR(ctx, 0x18228/4, 0x80C14);
	INSTANCE_WR(ctx, 0x18288/4, 0x804);
	INSTANCE_WR(ctx, 0x182C8/4, 0x4);
	INSTANCE_WR(ctx, 0x182E8/4, 0x4);
	INSTANCE_WR(ctx, 0x18308/4, 0x8100C12);
	INSTANCE_WR(ctx, 0x18348/4, 0x4);
	INSTANCE_WR(ctx, 0x18368/4, 0x4);
	INSTANCE_WR(ctx, 0x183A8/4, 0x10);
	INSTANCE_WR(ctx, 0x18448/4, 0x804);
	INSTANCE_WR(ctx, 0x18468/4, 0x1);
	INSTANCE_WR(ctx, 0x18488/4, 0x1A);
	INSTANCE_WR(ctx, 0x184A8/4, 0x7F);
	INSTANCE_WR(ctx, 0x184E8/4, 0x1);
	INSTANCE_WR(ctx, 0x18508/4, 0x80C14);
	INSTANCE_WR(ctx, 0x18548/4, 0x8100C12);
	INSTANCE_WR(ctx, 0x18568/4, 0x4);
	INSTANCE_WR(ctx, 0x18588/4, 0x4);
	INSTANCE_WR(ctx, 0x185C8/4, 0x10);
	INSTANCE_WR(ctx, 0x18648/4, 0x1);
	INSTANCE_WR(ctx, 0x18668/4, 0x8100C12);
	INSTANCE_WR(ctx, 0x18748/4, 0x7FF);
	INSTANCE_WR(ctx, 0x18768/4, 0x80C14);
	INSTANCE_WR(ctx, 0x18E88/4, 0x1);
	INSTANCE_WR(ctx, 0x18EE8/4, 0x10);
	INSTANCE_WR(ctx, 0x19608/4, 0x88);
	INSTANCE_WR(ctx, 0x19628/4, 0x88);
	INSTANCE_WR(ctx, 0x19688/4, 0x4);
	INSTANCE_WR(ctx, 0x19968/4, 0x26);
	INSTANCE_WR(ctx, 0x199C8/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x19A48/4, 0x1A);
	INSTANCE_WR(ctx, 0x19A68/4, 0x10);
	INSTANCE_WR(ctx, 0x19F88/4, 0x52);
	INSTANCE_WR(ctx, 0x19FC8/4, 0x26);
	INSTANCE_WR(ctx, 0x1A008/4, 0x4);
	INSTANCE_WR(ctx, 0x1A028/4, 0x4);
	INSTANCE_WR(ctx, 0x1A068/4, 0x1A);
	INSTANCE_WR(ctx, 0x1A0C8/4, 0xFFFF00);
	INSTANCE_WR(ctx, 0x1A108/4, 0x4);
	INSTANCE_WR(ctx, 0x1A128/4, 0x4);
	INSTANCE_WR(ctx, 0x1A168/4, 0x80);
	INSTANCE_WR(ctx, 0x1A188/4, 0x4);
	INSTANCE_WR(ctx, 0x1A1A8/4, 0x80C14);
	INSTANCE_WR(ctx, 0x1A1E8/4, 0x7FF);
	INSTANCE_WR(ctx, 0x24A48/4, 0x4);
	INSTANCE_WR(ctx, 0x24A68/4, 0x4);
	INSTANCE_WR(ctx, 0x24AA8/4, 0x80);
	INSTANCE_WR(ctx, 0x24AC8/4, 0x4);
	INSTANCE_WR(ctx, 0x24AE8/4, 0x1);
	INSTANCE_WR(ctx, 0x24B28/4, 0x27);
	INSTANCE_WR(ctx, 0x24B68/4, 0x26);
	INSTANCE_WR(ctx, 0x24BE8/4, 0x4000000);
	INSTANCE_WR(ctx, 0x24C08/4, 0x4000000);
	INSTANCE_WR(ctx, 0x24C28/4, 0x4000000);
	INSTANCE_WR(ctx, 0x24C48/4, 0x4000000);
	INSTANCE_WR(ctx, 0x24C68/4, 0x4000000);
	INSTANCE_WR(ctx, 0x24C88/4, 0x4000000);
	INSTANCE_WR(ctx, 0x24CA8/4, 0x4000000);
	INSTANCE_WR(ctx, 0x24CC8/4, 0x4000000);
	INSTANCE_WR(ctx, 0x24CE8/4, 0x4000000);
	INSTANCE_WR(ctx, 0x24D08/4, 0x4000000);
	INSTANCE_WR(ctx, 0x24D28/4, 0x4000000);
	INSTANCE_WR(ctx, 0x24D48/4, 0x4000000);
	INSTANCE_WR(ctx, 0x24D68/4, 0x4000000);
	INSTANCE_WR(ctx, 0x24D88/4, 0x4000000);
	INSTANCE_WR(ctx, 0x24DA8/4, 0x4000000);
	INSTANCE_WR(ctx, 0x24DC8/4, 0x4000000);
	INSTANCE_WR(ctx, 0x25268/4, 0x4E3BFDF);
	INSTANCE_WR(ctx, 0x25288/4, 0x4E3BFDF);
	INSTANCE_WR(ctx, 0x252E8/4, 0x1FE21);
	INSTANCE_WR(ctx, 0xB0C/4, 0x2);
	INSTANCE_WR(ctx, 0xB4C/4, 0x1FFE67);
	INSTANCE_WR(ctx, 0xCEC/4, 0x1);
	INSTANCE_WR(ctx, 0xD0C/4, 0x10);
	INSTANCE_WR(ctx, 0xD6C/4, 0x1);
	INSTANCE_WR(ctx, 0xE0C/4, 0x4);
	INSTANCE_WR(ctx, 0xE2C/4, 0x400);
	INSTANCE_WR(ctx, 0xE4C/4, 0x300);
	INSTANCE_WR(ctx, 0xE6C/4, 0x1001);
	INSTANCE_WR(ctx, 0xE8C/4, 0x15);
	INSTANCE_WR(ctx, 0xF4C/4, 0x2);
	INSTANCE_WR(ctx, 0x106C/4, 0x1);
	INSTANCE_WR(ctx, 0x108C/4, 0x10);
	INSTANCE_WR(ctx, 0x10CC/4, 0x1);
	INSTANCE_WR(ctx, 0x134C/4, 0x10);
	INSTANCE_WR(ctx, 0x156C/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x158C/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x15AC/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x15CC/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x15EC/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x160C/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x162C/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x164C/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x166C/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x168C/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x16AC/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x16CC/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x16EC/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x170C/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x172C/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x174C/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x1A8C/4, 0x10);
	INSTANCE_WR(ctx, 0x1ACC/4, 0x3F);
	INSTANCE_WR(ctx, 0x1BAC/4, 0x1);
	INSTANCE_WR(ctx, 0x1BEC/4, 0x1);
	INSTANCE_WR(ctx, 0x1C2C/4, 0x1);
	INSTANCE_WR(ctx, 0x1DCC/4, 0x11);
	INSTANCE_WR(ctx, 0x1ECC/4, 0xF);
	INSTANCE_WR(ctx, 0x1FCC/4, 0x11);
	INSTANCE_WR(ctx, 0x20AC/4, 0x1);
	INSTANCE_WR(ctx, 0x20CC/4, 0x1);
	INSTANCE_WR(ctx, 0x20EC/4, 0x1);
	INSTANCE_WR(ctx, 0x210C/4, 0x2);
	INSTANCE_WR(ctx, 0x212C/4, 0x1);
	INSTANCE_WR(ctx, 0x214C/4, 0x2);
	INSTANCE_WR(ctx, 0x216C/4, 0x1);
	INSTANCE_WR(ctx, 0x21AC/4, 0x1FFE67);
	INSTANCE_WR(ctx, 0x21EC/4, 0xFAC6881);
	INSTANCE_WR(ctx, 0x24AC/4, 0x1);
	INSTANCE_WR(ctx, 0x24CC/4, 0x2);
	INSTANCE_WR(ctx, 0x24EC/4, 0x1);
	INSTANCE_WR(ctx, 0x250C/4, 0x1);
	INSTANCE_WR(ctx, 0x252C/4, 0x2);
	INSTANCE_WR(ctx, 0x254C/4, 0x1);
	INSTANCE_WR(ctx, 0x256C/4, 0x1);
	INSTANCE_WR(ctx, 0x25EC/4, 0x11);
	INSTANCE_WR(ctx, 0x260C/4, 0x1);
	INSTANCE_WR(ctx, 0x328C/4, 0x2);
	INSTANCE_WR(ctx, 0x32CC/4, 0x1FFE67);
	INSTANCE_WR(ctx, 0x346C/4, 0x1);
	INSTANCE_WR(ctx, 0x348C/4, 0x10);
	INSTANCE_WR(ctx, 0x34EC/4, 0x1);
	INSTANCE_WR(ctx, 0x358C/4, 0x4);
	INSTANCE_WR(ctx, 0x35AC/4, 0x400);
	INSTANCE_WR(ctx, 0x35CC/4, 0x300);
	INSTANCE_WR(ctx, 0x35EC/4, 0x1001);
	INSTANCE_WR(ctx, 0x360C/4, 0x15);
	INSTANCE_WR(ctx, 0x36CC/4, 0x2);
	INSTANCE_WR(ctx, 0x37EC/4, 0x1);
	INSTANCE_WR(ctx, 0x380C/4, 0x10);
	INSTANCE_WR(ctx, 0x384C/4, 0x1);
	INSTANCE_WR(ctx, 0x3ACC/4, 0x10);
	INSTANCE_WR(ctx, 0x3CEC/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x3D0C/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x3D2C/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x3D4C/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x3D6C/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x3D8C/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x3DAC/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x3DCC/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x3DEC/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x3E0C/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x3E2C/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x3E4C/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x3E6C/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x3E8C/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x3EAC/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x3ECC/4, 0x3F800000);
	INSTANCE_WR(ctx, 0x420C/4, 0x10);
	INSTANCE_WR(ctx, 0x424C/4, 0x3F);
	INSTANCE_WR(ctx, 0x432C/4, 0x1);
	INSTANCE_WR(ctx, 0x436C/4, 0x1);
	INSTANCE_WR(ctx, 0x43AC/4, 0x1);
	INSTANCE_WR(ctx, 0x454C/4, 0x11);
	INSTANCE_WR(ctx, 0x464C/4, 0xF);
	INSTANCE_WR(ctx, 0x474C/4, 0x11);
	INSTANCE_WR(ctx, 0x482C/4, 0x1);
	INSTANCE_WR(ctx, 0x484C/4, 0x1);
	INSTANCE_WR(ctx, 0x486C/4, 0x1);
	INSTANCE_WR(ctx, 0x488C/4, 0x2);
	INSTANCE_WR(ctx, 0x48AC/4, 0x1);
	INSTANCE_WR(ctx, 0x48CC/4, 0x2);
	INSTANCE_WR(ctx, 0x48EC/4, 0x1);
	INSTANCE_WR(ctx, 0x492C/4, 0x1FFE67);
	INSTANCE_WR(ctx, 0x496C/4, 0xFAC6881);
	INSTANCE_WR(ctx, 0x4C2C/4, 0x1);
	INSTANCE_WR(ctx, 0x4C4C/4, 0x2);
	INSTANCE_WR(ctx, 0x4C6C/4, 0x1);
	INSTANCE_WR(ctx, 0x4C8C/4, 0x1);
	INSTANCE_WR(ctx, 0x4CAC/4, 0x2);
	INSTANCE_WR(ctx, 0x4CCC/4, 0x1);
	INSTANCE_WR(ctx, 0x4CEC/4, 0x1);
	INSTANCE_WR(ctx, 0x4D6C/4, 0x11);
	INSTANCE_WR(ctx, 0x4D8C/4, 0x1);
	INSTANCE_WR(ctx, 0xA30/4, 0x4);
	INSTANCE_WR(ctx, 0xCF0/4, 0x4);
	INSTANCE_WR(ctx, 0xD10/4, 0x4);
	INSTANCE_WR(ctx, 0xD30/4, 0x608080);
	INSTANCE_WR(ctx, 0xDD0/4, 0x4);
	INSTANCE_WR(ctx, 0xE30/4, 0x4);
	INSTANCE_WR(ctx, 0xE50/4, 0x4);
	INSTANCE_WR(ctx, 0xE70/4, 0x80);
	INSTANCE_WR(ctx, 0xE90/4, 0x1E00);
	INSTANCE_WR(ctx, 0xEB0/4, 0x4);
	INSTANCE_WR(ctx, 0x1350/4, 0x4);
	INSTANCE_WR(ctx, 0x1370/4, 0x80);
	INSTANCE_WR(ctx, 0x1390/4, 0x4);
	INSTANCE_WR(ctx, 0x13B0/4, 0x3020100);
	INSTANCE_WR(ctx, 0x13D0/4, 0x3);
	INSTANCE_WR(ctx, 0x13F0/4, 0x1E00);
	INSTANCE_WR(ctx, 0x1410/4, 0x4);
	INSTANCE_WR(ctx, 0x14B0/4, 0x4);
	INSTANCE_WR(ctx, 0x14D0/4, 0x3);
	INSTANCE_WR(ctx, 0x1550/4, 0x4);
	INSTANCE_WR(ctx, 0x159F0/4, 0x4);
	INSTANCE_WR(ctx, 0x15A10/4, 0x3);
	INSTANCE_WR(ctx, 0x15C50/4, 0xF);
	INSTANCE_WR(ctx, 0x15DD0/4, 0x4);
	INSTANCE_WR(ctx, 0x15DF0/4, 0xFFFF);
	INSTANCE_WR(ctx, 0x15E10/4, 0xFFFF);
	INSTANCE_WR(ctx, 0x15E30/4, 0xFFFF);
	INSTANCE_WR(ctx, 0x15E50/4, 0xFFFF);
	INSTANCE_WR(ctx, 0x15F70/4, 0x1);
	INSTANCE_WR(ctx, 0x15FF0/4, 0x1);
	INSTANCE_WR(ctx, 0x160B0/4, 0x1);
	INSTANCE_WR(ctx, 0x16250/4, 0x1);
	INSTANCE_WR(ctx, 0x16270/4, 0x1);
	INSTANCE_WR(ctx, 0x16290/4, 0x2);
	INSTANCE_WR(ctx, 0x162B0/4, 0x1);
	INSTANCE_WR(ctx, 0x162D0/4, 0x1);
	INSTANCE_WR(ctx, 0x162F0/4, 0x2);
	INSTANCE_WR(ctx, 0x16310/4, 0x1);
	INSTANCE_WR(ctx, 0x16350/4, 0x11);
	INSTANCE_WR(ctx, 0x16450/4, 0xFAC6881);
	INSTANCE_WR(ctx, 0x164B0/4, 0x4);
	INSTANCE_WR(ctx, 0x16530/4, 0x11);
	INSTANCE_WR(ctx, 0x16550/4, 0x1);
	INSTANCE_WR(ctx, 0x16590/4, 0xCF);
	INSTANCE_WR(ctx, 0x165B0/4, 0xCF);
	INSTANCE_WR(ctx, 0x165D0/4, 0xCF);
	INSTANCE_WR(ctx, 0x16730/4, 0x1);
	INSTANCE_WR(ctx, 0x16750/4, 0x1);
	INSTANCE_WR(ctx, 0x16770/4, 0x2);
	INSTANCE_WR(ctx, 0x16790/4, 0x1);
	INSTANCE_WR(ctx, 0x167B0/4, 0x1);
	INSTANCE_WR(ctx, 0x167D0/4, 0x2);
	INSTANCE_WR(ctx, 0x167F0/4, 0x1);
	INSTANCE_WR(ctx, 0x16830/4, 0x1);
	INSTANCE_WR(ctx, 0x16850/4, 0x1);
	INSTANCE_WR(ctx, 0x16870/4, 0x1);
	INSTANCE_WR(ctx, 0x16890/4, 0x1);
	INSTANCE_WR(ctx, 0x168B0/4, 0x1);
	INSTANCE_WR(ctx, 0x168D0/4, 0x1);
	INSTANCE_WR(ctx, 0x168F0/4, 0x1);
	INSTANCE_WR(ctx, 0x16910/4, 0x1);
	INSTANCE_WR(ctx, 0x16930/4, 0x11);
	INSTANCE_WR(ctx, 0x16A30/4, 0xFAC6881);
	INSTANCE_WR(ctx, 0x16A50/4, 0xF);
	INSTANCE_WR(ctx, 0x16B50/4, 0x1FFE67);
	INSTANCE_WR(ctx, 0x16BB0/4, 0x11);
	INSTANCE_WR(ctx, 0x16BD0/4, 0x1);
	INSTANCE_WR(ctx, 0x16C50/4, 0x4);
	INSTANCE_WR(ctx, 0x16D10/4, 0x1);
	INSTANCE_WR(ctx, 0x16DB0/4, 0x11);
	INSTANCE_WR(ctx, 0x16EB0/4, 0xFAC6881);
	INSTANCE_WR(ctx, 0x16F30/4, 0x11);
	INSTANCE_WR(ctx, 0x16F50/4, 0x1);
	INSTANCE_WR(ctx, 0x16F90/4, 0x1);
	INSTANCE_WR(ctx, 0x16FD0/4, 0x1);
	INSTANCE_WR(ctx, 0x17010/4, 0x7FF);
	INSTANCE_WR(ctx, 0x17050/4, 0x1);
	INSTANCE_WR(ctx, 0x17090/4, 0x1);
	INSTANCE_WR(ctx, 0x175F0/4, 0x8);
	INSTANCE_WR(ctx, 0x17610/4, 0x8);
	INSTANCE_WR(ctx, 0x17630/4, 0x8);
	INSTANCE_WR(ctx, 0x17650/4, 0x8);
	INSTANCE_WR(ctx, 0x17670/4, 0x8);
	INSTANCE_WR(ctx, 0x17690/4, 0x8);
	INSTANCE_WR(ctx, 0x176B0/4, 0x8);
	INSTANCE_WR(ctx, 0x176D0/4, 0x8);
	INSTANCE_WR(ctx, 0x176F0/4, 0x11);
	INSTANCE_WR(ctx, 0x177F0/4, 0xFAC6881);
	INSTANCE_WR(ctx, 0x17810/4, 0x400);
	INSTANCE_WR(ctx, 0x17830/4, 0x400);
	INSTANCE_WR(ctx, 0x17850/4, 0x400);
	INSTANCE_WR(ctx, 0x17870/4, 0x400);
	INSTANCE_WR(ctx, 0x17890/4, 0x400);
	INSTANCE_WR(ctx, 0x178B0/4, 0x400);
	INSTANCE_WR(ctx, 0x178D0/4, 0x400);
	INSTANCE_WR(ctx, 0x178F0/4, 0x400);
	INSTANCE_WR(ctx, 0x17910/4, 0x300);
	INSTANCE_WR(ctx, 0x17930/4, 0x300);
	INSTANCE_WR(ctx, 0x17950/4, 0x300);
	INSTANCE_WR(ctx, 0x17970/4, 0x300);
	INSTANCE_WR(ctx, 0x17990/4, 0x300);
	INSTANCE_WR(ctx, 0x179B0/4, 0x300);
	INSTANCE_WR(ctx, 0x179D0/4, 0x300);
	INSTANCE_WR(ctx, 0x179F0/4, 0x300);
	INSTANCE_WR(ctx, 0x17A10/4, 0x1);
	INSTANCE_WR(ctx, 0x17A30/4, 0xF);
	INSTANCE_WR(ctx, 0x17B30/4, 0x20);
	INSTANCE_WR(ctx, 0x17B50/4, 0x11);
	INSTANCE_WR(ctx, 0x17B70/4, 0x100);
	INSTANCE_WR(ctx, 0x17BB0/4, 0x1);
	INSTANCE_WR(ctx, 0x17C10/4, 0x40);
	INSTANCE_WR(ctx, 0x17C30/4, 0x100);
	INSTANCE_WR(ctx, 0x17C70/4, 0x3);
	INSTANCE_WR(ctx, 0x17D10/4, 0x1FFE67);
	INSTANCE_WR(ctx, 0x17D90/4, 0x2);
	INSTANCE_WR(ctx, 0x17DB0/4, 0xFAC6881);
	INSTANCE_WR(ctx, 0x17EF0/4, 0x1);
	INSTANCE_WR(ctx, 0x17F90/4, 0x4);
	INSTANCE_WR(ctx, 0x17FD0/4, 0x1);
	INSTANCE_WR(ctx, 0x17FF0/4, 0x400);
	INSTANCE_WR(ctx, 0x18010/4, 0x300);
	INSTANCE_WR(ctx, 0x18030/4, 0x1001);
	INSTANCE_WR(ctx, 0x180B0/4, 0x11);
	INSTANCE_WR(ctx, 0x181B0/4, 0xFAC6881);
	INSTANCE_WR(ctx, 0x181D0/4, 0xF);
	INSTANCE_WR(ctx, 0x184D0/4, 0x1FFE67);
	INSTANCE_WR(ctx, 0x18550/4, 0x11);
	INSTANCE_WR(ctx, 0x185B0/4, 0x4);
	INSTANCE_WR(ctx, 0x185F0/4, 0x1);
	INSTANCE_WR(ctx, 0x18610/4, 0x1);
	INSTANCE_WR(ctx, 0x18690/4, 0x1);
	INSTANCE_WR(ctx, 0x18730/4, 0x1);
	INSTANCE_WR(ctx, 0x18770/4, 0x1);
	INSTANCE_WR(ctx, 0x187F0/4, 0x2A712488);
	INSTANCE_WR(ctx, 0x18830/4, 0x4085C000);
	INSTANCE_WR(ctx, 0x18850/4, 0x40);
	INSTANCE_WR(ctx, 0x18870/4, 0x100);
	INSTANCE_WR(ctx, 0x18890/4, 0x10100);
	INSTANCE_WR(ctx, 0x188B0/4, 0x2800000);
	INSTANCE_WR(ctx, 0x18B10/4, 0x4E3BFDF);
	INSTANCE_WR(ctx, 0x18B30/4, 0x4E3BFDF);
	INSTANCE_WR(ctx, 0x18B50/4, 0x1);
	INSTANCE_WR(ctx, 0x18B90/4, 0xFFFF00);
	INSTANCE_WR(ctx, 0x18BB0/4, 0x1);
	INSTANCE_WR(ctx, 0x18C10/4, 0xFFFF00);
	INSTANCE_WR(ctx, 0x18D30/4, 0x1);
	INSTANCE_WR(ctx, 0x18D70/4, 0x1);
	INSTANCE_WR(ctx, 0x18D90/4, 0x30201000);
	INSTANCE_WR(ctx, 0x18DB0/4, 0x70605040);
	INSTANCE_WR(ctx, 0x18DD0/4, 0xB8A89888);
	INSTANCE_WR(ctx, 0x18DF0/4, 0xF8E8D8C8);
	INSTANCE_WR(ctx, 0x18E30/4, 0x1A);
}


static void
nv84_graph_init_ctxvals(struct drm_device *dev, struct nouveau_gpuobj_ref *ref)
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	struct nouveau_gpuobj *ctx = ref->gpuobj;

	INSTANCE_WR(ctx, 0x0010c/4, 0x00000030);
	INSTANCE_WR(ctx, 0x00130/4, 0x00000002);
	INSTANCE_WR(ctx, 0x001d4/4, 0x00000003);
	INSTANCE_WR(ctx, 0x001d8/4, 0x00001000);
	INSTANCE_WR(ctx, 0x00218/4, 0x0000fe0c);
	INSTANCE_WR(ctx, 0x0022c/4, 0x00001000);
	INSTANCE_WR(ctx, 0x00258/4, 0x00000187);
	INSTANCE_WR(ctx, 0x0026c/4, 0x00001018);
	INSTANCE_WR(ctx, 0x00270/4, 0x000000ff);
	INSTANCE_WR(ctx, 0x002ac/4, 0x00000004);
	INSTANCE_WR(ctx, 0x002b0/4, 0x044d00df);
	INSTANCE_WR(ctx, 0x002b8/4, 0x00000600);
	INSTANCE_WR(ctx, 0x002d0/4, 0x01000000);
	INSTANCE_WR(ctx, 0x002d4/4, 0x000000ff);
	INSTANCE_WR(ctx, 0x002dc/4, 0x00000400);
	INSTANCE_WR(ctx, 0x002f4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x002f8/4, 0x000e0080);
	INSTANCE_WR(ctx, 0x002fc/4, 0x00000004);
	INSTANCE_WR(ctx, 0x00318/4, 0x00000002);
	INSTANCE_WR(ctx, 0x0031c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00328/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0032c/4, 0x00000100);
	INSTANCE_WR(ctx, 0x00344/4, 0x00000002);
	INSTANCE_WR(ctx, 0x00348/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0034c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0035c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00360/4, 0x003fffff);
	INSTANCE_WR(ctx, 0x00364/4, 0x00001fff);
	INSTANCE_WR(ctx, 0x0036c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00370/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00378/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0037c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00380/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00384/4, 0x00000004);
	INSTANCE_WR(ctx, 0x00388/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0038c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00390/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00394/4, 0x00000007);
	INSTANCE_WR(ctx, 0x00398/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0039c/4, 0x00000007);
	INSTANCE_WR(ctx, 0x003a0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x003a4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x003a8/4, 0x00000001);
	INSTANCE_WR(ctx, 0x003bc/4, 0x00000001);
	INSTANCE_WR(ctx, 0x003c0/4, 0x00000100);
	INSTANCE_WR(ctx, 0x003c8/4, 0x00000001);
	INSTANCE_WR(ctx, 0x003d4/4, 0x00000100);
	INSTANCE_WR(ctx, 0x003d8/4, 0x00000001);
	INSTANCE_WR(ctx, 0x003dc/4, 0x00000100);
	INSTANCE_WR(ctx, 0x003e4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x003f0/4, 0x00000100);
	INSTANCE_WR(ctx, 0x00404/4, 0x00000004);
	INSTANCE_WR(ctx, 0x00408/4, 0x00000070);
	INSTANCE_WR(ctx, 0x0040c/4, 0x00000080);
	INSTANCE_WR(ctx, 0x00420/4, 0x0000000c);
	INSTANCE_WR(ctx, 0x00428/4, 0x00000008);
	INSTANCE_WR(ctx, 0x0042c/4, 0x00000014);
	INSTANCE_WR(ctx, 0x00434/4, 0x00000029);
	INSTANCE_WR(ctx, 0x00438/4, 0x00000027);
	INSTANCE_WR(ctx, 0x0043c/4, 0x00000026);
	INSTANCE_WR(ctx, 0x00440/4, 0x00000008);
	INSTANCE_WR(ctx, 0x00444/4, 0x00000004);
	INSTANCE_WR(ctx, 0x00448/4, 0x00000027);
	INSTANCE_WR(ctx, 0x00454/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00458/4, 0x00000002);
	INSTANCE_WR(ctx, 0x0045c/4, 0x00000003);
	INSTANCE_WR(ctx, 0x00460/4, 0x00000004);
	INSTANCE_WR(ctx, 0x00464/4, 0x00000005);
	INSTANCE_WR(ctx, 0x00468/4, 0x00000006);
	INSTANCE_WR(ctx, 0x0046c/4, 0x00000007);
	INSTANCE_WR(ctx, 0x00470/4, 0x00000001);
	INSTANCE_WR(ctx, 0x004b4/4, 0x000000cf);
	INSTANCE_WR(ctx, 0x004e4/4, 0x00000080);
	INSTANCE_WR(ctx, 0x004e8/4, 0x00000004);
	INSTANCE_WR(ctx, 0x004ec/4, 0x00000004);
	INSTANCE_WR(ctx, 0x004f0/4, 0x00000003);
	INSTANCE_WR(ctx, 0x004f4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00500/4, 0x00000012);
	INSTANCE_WR(ctx, 0x00504/4, 0x00000010);
	INSTANCE_WR(ctx, 0x00508/4, 0x0000000c);
	INSTANCE_WR(ctx, 0x0050c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0051c/4, 0x00000004);
	INSTANCE_WR(ctx, 0x00520/4, 0x00000002);
	INSTANCE_WR(ctx, 0x00524/4, 0x00000004);
	INSTANCE_WR(ctx, 0x00530/4, 0x003fffff);
	INSTANCE_WR(ctx, 0x00534/4, 0x00001fff);
	INSTANCE_WR(ctx, 0x0055c/4, 0x00000004);
	INSTANCE_WR(ctx, 0x00560/4, 0x00000014);
	INSTANCE_WR(ctx, 0x00564/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00570/4, 0x00000002);
	INSTANCE_WR(ctx, 0x0057c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00584/4, 0x00000002);
	INSTANCE_WR(ctx, 0x00588/4, 0x00001000);
	INSTANCE_WR(ctx, 0x0058c/4, 0x00000e00);
	INSTANCE_WR(ctx, 0x00590/4, 0x00001000);
	INSTANCE_WR(ctx, 0x00594/4, 0x00001e00);
	INSTANCE_WR(ctx, 0x0059c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x005a0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x005a4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x005a8/4, 0x00000001);
	INSTANCE_WR(ctx, 0x005ac/4, 0x00000001);
	INSTANCE_WR(ctx, 0x005bc/4, 0x00000200);
	INSTANCE_WR(ctx, 0x005c4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x005c8/4, 0x00000070);
	INSTANCE_WR(ctx, 0x005cc/4, 0x00000080);
	INSTANCE_WR(ctx, 0x005d8/4, 0x00000001);
	INSTANCE_WR(ctx, 0x005dc/4, 0x00000070);
	INSTANCE_WR(ctx, 0x005e0/4, 0x00000080);
	INSTANCE_WR(ctx, 0x005f0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x005f4/4, 0x000000cf);
	INSTANCE_WR(ctx, 0x005fc/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0060c/4, 0x000000cf);
	INSTANCE_WR(ctx, 0x00614/4, 0x00000002);
	INSTANCE_WR(ctx, 0x0061c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00624/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0062c/4, 0x000000cf);
	INSTANCE_WR(ctx, 0x00630/4, 0x000000cf);
	INSTANCE_WR(ctx, 0x00634/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0063c/4, 0x00000f80);
	INSTANCE_WR(ctx, 0x00684/4, 0x007f0080);
	INSTANCE_WR(ctx, 0x006c0/4, 0x007f0080);

	INSTANCE_WR(ctx, 0x006e4/4, 0x3b74f821);
	INSTANCE_WR(ctx, 0x006e8/4, 0x89058001);
	INSTANCE_WR(ctx, 0x006f0/4, 0x00001000);
	INSTANCE_WR(ctx, 0x006f4/4, 0x0000001f);
	INSTANCE_WR(ctx, 0x006f8/4, 0x027c10fa);
	INSTANCE_WR(ctx, 0x006fc/4, 0x400000c0);
	INSTANCE_WR(ctx, 0x00700/4, 0xb7892080);

	INSTANCE_WR(ctx, 0x0070c/4, 0x3b74f821);
	INSTANCE_WR(ctx, 0x00710/4, 0x89058001);
	INSTANCE_WR(ctx, 0x00718/4, 0x00001000);
	INSTANCE_WR(ctx, 0x0071c/4, 0x0000001f);
	INSTANCE_WR(ctx, 0x00720/4, 0x027c10fa);
	INSTANCE_WR(ctx, 0x00724/4, 0x400000c0);
	INSTANCE_WR(ctx, 0x00728/4, 0xb7892080);

	INSTANCE_WR(ctx, 0x00734/4, 0x3b74f821);
	INSTANCE_WR(ctx, 0x00738/4, 0x89058001);
	INSTANCE_WR(ctx, 0x00740/4, 0x00001000);
	INSTANCE_WR(ctx, 0x00744/4, 0x0000001f);
	INSTANCE_WR(ctx, 0x00748/4, 0x027c10fa);
	INSTANCE_WR(ctx, 0x0074c/4, 0x400000c0);
	INSTANCE_WR(ctx, 0x00750/4, 0xb7892080);

	INSTANCE_WR(ctx, 0x0075c/4, 0x3b74f821);
	INSTANCE_WR(ctx, 0x00760/4, 0x89058001);
	INSTANCE_WR(ctx, 0x00768/4, 0x00001000);
	INSTANCE_WR(ctx, 0x0076c/4, 0x0000001f);
	INSTANCE_WR(ctx, 0x00770/4, 0x027c10fa);
	INSTANCE_WR(ctx, 0x00774/4, 0x400000c0);
	INSTANCE_WR(ctx, 0x00778/4, 0xb7892080);

	INSTANCE_WR(ctx, 0x00784/4, 0x00010040);
	INSTANCE_WR(ctx, 0x0078c/4, 0x00000022);
	INSTANCE_WR(ctx, 0x00798/4, 0x00010040);
	INSTANCE_WR(ctx, 0x0079c/4, 0x00000022);

	INSTANCE_WR(ctx, 0x007b4/4, 0x01800000);
	INSTANCE_WR(ctx, 0x007b8/4, 0x00160000);
	INSTANCE_WR(ctx, 0x007bc/4, 0x01800000);
	INSTANCE_WR(ctx, 0x007cc/4, 0x0003ffff);
	INSTANCE_WR(ctx, 0x007d0/4, 0x00880000);
	INSTANCE_WR(ctx, 0x007f4/4, 0x00010401);
	INSTANCE_WR(ctx, 0x007fc/4, 0x00000078);
	INSTANCE_WR(ctx, 0x00804/4, 0x000000bf);
	INSTANCE_WR(ctx, 0x0080c/4, 0x00001210);
	INSTANCE_WR(ctx, 0x00810/4, 0x08000080);
	INSTANCE_WR(ctx, 0x00834/4, 0x01800000);
	INSTANCE_WR(ctx, 0x00838/4, 0x00160000);
	INSTANCE_WR(ctx, 0x0083c/4, 0x01800000);
	INSTANCE_WR(ctx, 0x0084c/4, 0x0003ffff);
	INSTANCE_WR(ctx, 0x00850/4, 0x00880000);
	INSTANCE_WR(ctx, 0x00874/4, 0x00010401);
	INSTANCE_WR(ctx, 0x0087c/4, 0x00000078);
	INSTANCE_WR(ctx, 0x00884/4, 0x000000bf);
	INSTANCE_WR(ctx, 0x0088c/4, 0x00001210);
	INSTANCE_WR(ctx, 0x00890/4, 0x08000080);
	INSTANCE_WR(ctx, 0x008b8/4, 0x00027070);
	INSTANCE_WR(ctx, 0x008c4/4, 0x03ffffff);
	INSTANCE_WR(ctx, 0x008dc/4, 0x00120407);
	INSTANCE_WR(ctx, 0x008e0/4, 0x05091507);
	INSTANCE_WR(ctx, 0x008e4/4, 0x05100202);
	INSTANCE_WR(ctx, 0x008e8/4, 0x00030201);
	INSTANCE_WR(ctx, 0x00904/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00908/4, 0x0d0c0b0a);
	INSTANCE_WR(ctx, 0x0090c/4, 0x00141210);
	INSTANCE_WR(ctx, 0x00910/4, 0x000001f0);
	INSTANCE_WR(ctx, 0x00914/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00918/4, 0x00000003);
	INSTANCE_WR(ctx, 0x00924/4, 0x00039e00);
	INSTANCE_WR(ctx, 0x00928/4, 0x00000100);
	INSTANCE_WR(ctx, 0x0092c/4, 0x00003800);
	INSTANCE_WR(ctx, 0x00930/4, 0x00404040);
	INSTANCE_WR(ctx, 0x00934/4, 0x0000ff0a);
	INSTANCE_WR(ctx, 0x0093c/4, 0x0077f005);
	INSTANCE_WR(ctx, 0x00940/4, 0x003f7fff);

	INSTANCE_WR(ctx, 0x00950/4, 0x01800000);
	INSTANCE_WR(ctx, 0x00954/4, 0x00160000);
	INSTANCE_WR(ctx, 0x00958/4, 0x01800000);
	INSTANCE_WR(ctx, 0x00968/4, 0x0003ffff);
	INSTANCE_WR(ctx, 0x0096c/4, 0x00880000);
	INSTANCE_WR(ctx, 0x00990/4, 0x00010401);
	INSTANCE_WR(ctx, 0x00998/4, 0x00000078);
	INSTANCE_WR(ctx, 0x009a0/4, 0x000000bf);
	INSTANCE_WR(ctx, 0x009a8/4, 0x00001210);
	INSTANCE_WR(ctx, 0x009ac/4, 0x08000080);
	INSTANCE_WR(ctx, 0x009d0/4, 0x01800000);
	INSTANCE_WR(ctx, 0x009d4/4, 0x00160000);
	INSTANCE_WR(ctx, 0x009d8/4, 0x01800000);
	INSTANCE_WR(ctx, 0x009e8/4, 0x0003ffff);
	INSTANCE_WR(ctx, 0x009ec/4, 0x00880000);
	INSTANCE_WR(ctx, 0x00a10/4, 0x00010401);
	INSTANCE_WR(ctx, 0x00a18/4, 0x00000078);
	INSTANCE_WR(ctx, 0x00a20/4, 0x000000bf);
	INSTANCE_WR(ctx, 0x00a28/4, 0x00001210);
	INSTANCE_WR(ctx, 0x00a2c/4, 0x08000080);
	INSTANCE_WR(ctx, 0x00a54/4, 0x00027070);
	INSTANCE_WR(ctx, 0x00a60/4, 0x03ffffff);
	INSTANCE_WR(ctx, 0x00a78/4, 0x00120407);
	INSTANCE_WR(ctx, 0x00a7c/4, 0x05091507);
	INSTANCE_WR(ctx, 0x00a80/4, 0x05100202);
	INSTANCE_WR(ctx, 0x00a84/4, 0x00030201);
	INSTANCE_WR(ctx, 0x00aa0/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00aa4/4, 0x0d0c0b0a);
	INSTANCE_WR(ctx, 0x00aa8/4, 0x00141210);
	INSTANCE_WR(ctx, 0x00aac/4, 0x000001f0);
	INSTANCE_WR(ctx, 0x00ab0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00ab4/4, 0x00000003);
	INSTANCE_WR(ctx, 0x00ac0/4, 0x00039e00);
	INSTANCE_WR(ctx, 0x00ac4/4, 0x00000100);
	INSTANCE_WR(ctx, 0x00ac8/4, 0x00003800);
	INSTANCE_WR(ctx, 0x00acc/4, 0x00404040);
	INSTANCE_WR(ctx, 0x00ad0/4, 0x0000ff0a);
	INSTANCE_WR(ctx, 0x00ad8/4, 0x0077f005);
	INSTANCE_WR(ctx, 0x00adc/4, 0x003f7fff);

	INSTANCE_WR(ctx, 0x00aec/4, 0x01800000);
	INSTANCE_WR(ctx, 0x00af0/4, 0x00160000);
	INSTANCE_WR(ctx, 0x00af4/4, 0x01800000);
	INSTANCE_WR(ctx, 0x00b04/4, 0x0003ffff);
	INSTANCE_WR(ctx, 0x00b08/4, 0x00880000);
	INSTANCE_WR(ctx, 0x00b2c/4, 0x00010401);
	INSTANCE_WR(ctx, 0x00b34/4, 0x00000078);
	INSTANCE_WR(ctx, 0x00b3c/4, 0x000000bf);
	INSTANCE_WR(ctx, 0x00b44/4, 0x00001210);
	INSTANCE_WR(ctx, 0x00b48/4, 0x08000080);
	INSTANCE_WR(ctx, 0x00b6c/4, 0x01800000);
	INSTANCE_WR(ctx, 0x00b70/4, 0x00160000);
	INSTANCE_WR(ctx, 0x00b74/4, 0x01800000);
	INSTANCE_WR(ctx, 0x00b84/4, 0x0003ffff);
	INSTANCE_WR(ctx, 0x00b88/4, 0x00880000);
	INSTANCE_WR(ctx, 0x00bac/4, 0x00010401);
	INSTANCE_WR(ctx, 0x00bb4/4, 0x00000078);
	INSTANCE_WR(ctx, 0x00bbc/4, 0x000000bf);
	INSTANCE_WR(ctx, 0x00bc4/4, 0x00001210);
	INSTANCE_WR(ctx, 0x00bc8/4, 0x08000080);
	INSTANCE_WR(ctx, 0x00bf0/4, 0x00027070);
	INSTANCE_WR(ctx, 0x00bfc/4, 0x03ffffff);
	INSTANCE_WR(ctx, 0x00c14/4, 0x00120407);
	INSTANCE_WR(ctx, 0x00c18/4, 0x05091507);
	INSTANCE_WR(ctx, 0x00c1c/4, 0x05100202);
	INSTANCE_WR(ctx, 0x00c20/4, 0x00030201);
	INSTANCE_WR(ctx, 0x00c3c/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00c40/4, 0x0d0c0b0a);
	INSTANCE_WR(ctx, 0x00c44/4, 0x00141210);
	INSTANCE_WR(ctx, 0x00c48/4, 0x000001f0);
	INSTANCE_WR(ctx, 0x00c4c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00c50/4, 0x00000003);
	INSTANCE_WR(ctx, 0x00c5c/4, 0x00039e00);
	INSTANCE_WR(ctx, 0x00c60/4, 0x00000100);
	INSTANCE_WR(ctx, 0x00c64/4, 0x00003800);
	INSTANCE_WR(ctx, 0x00c68/4, 0x00404040);
	INSTANCE_WR(ctx, 0x00c6c/4, 0x0000ff0a);
	INSTANCE_WR(ctx, 0x00c74/4, 0x0077f005);
	INSTANCE_WR(ctx, 0x00c78/4, 0x003f7fff);

	INSTANCE_WR(ctx, 0x00c88/4, 0x01800000);
	INSTANCE_WR(ctx, 0x00c8c/4, 0x00160000);
	INSTANCE_WR(ctx, 0x00c90/4, 0x01800000);
	INSTANCE_WR(ctx, 0x00ca0/4, 0x0003ffff);
	INSTANCE_WR(ctx, 0x00ca4/4, 0x00880000);
	INSTANCE_WR(ctx, 0x00cc8/4, 0x00010401);
	INSTANCE_WR(ctx, 0x00cd0/4, 0x00000078);
	INSTANCE_WR(ctx, 0x00cd8/4, 0x000000bf);
	INSTANCE_WR(ctx, 0x00ce0/4, 0x00001210);
	INSTANCE_WR(ctx, 0x00ce4/4, 0x08000080);
	INSTANCE_WR(ctx, 0x00d08/4, 0x01800000);
	INSTANCE_WR(ctx, 0x00d0c/4, 0x00160000);
	INSTANCE_WR(ctx, 0x00d10/4, 0x01800000);
	INSTANCE_WR(ctx, 0x00d20/4, 0x0003ffff);
	INSTANCE_WR(ctx, 0x00d24/4, 0x00880000);
	INSTANCE_WR(ctx, 0x00d48/4, 0x00010401);
	INSTANCE_WR(ctx, 0x00d50/4, 0x00000078);
	INSTANCE_WR(ctx, 0x00d58/4, 0x000000bf);
	INSTANCE_WR(ctx, 0x00d60/4, 0x00001210);
	INSTANCE_WR(ctx, 0x00d64/4, 0x08000080);
	INSTANCE_WR(ctx, 0x00d8c/4, 0x00027070);
	INSTANCE_WR(ctx, 0x00d98/4, 0x03ffffff);
	INSTANCE_WR(ctx, 0x00db0/4, 0x00120407);
	INSTANCE_WR(ctx, 0x00db4/4, 0x05091507);
	INSTANCE_WR(ctx, 0x00db8/4, 0x05100202);
	INSTANCE_WR(ctx, 0x00dbc/4, 0x00030201);
	INSTANCE_WR(ctx, 0x00dd8/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00ddc/4, 0x0d0c0b0a);
	INSTANCE_WR(ctx, 0x00de0/4, 0x00141210);
	INSTANCE_WR(ctx, 0x00de4/4, 0x000001f0);
	INSTANCE_WR(ctx, 0x00de8/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00dec/4, 0x00000003);
	INSTANCE_WR(ctx, 0x00df8/4, 0x00039e00);
	INSTANCE_WR(ctx, 0x00dfc/4, 0x00000100);
	INSTANCE_WR(ctx, 0x00e00/4, 0x00003800);
	INSTANCE_WR(ctx, 0x00e04/4, 0x00404040);
	INSTANCE_WR(ctx, 0x00e08/4, 0x0000ff0a);
	INSTANCE_WR(ctx, 0x00e10/4, 0x0077f005);
	INSTANCE_WR(ctx, 0x00e14/4, 0x003f7fff);

	INSTANCE_WR(ctx, 0x00e24/4, 0x01800000);
	INSTANCE_WR(ctx, 0x00e28/4, 0x00160000);
	INSTANCE_WR(ctx, 0x00e2c/4, 0x01800000);
	INSTANCE_WR(ctx, 0x00e3c/4, 0x0003ffff);
	INSTANCE_WR(ctx, 0x00e40/4, 0x00880000);
	INSTANCE_WR(ctx, 0x00e64/4, 0x00010401);
	INSTANCE_WR(ctx, 0x00e6c/4, 0x00000078);
	INSTANCE_WR(ctx, 0x00e74/4, 0x000000bf);
	INSTANCE_WR(ctx, 0x00e7c/4, 0x00001210);
	INSTANCE_WR(ctx, 0x00e80/4, 0x08000080);
	INSTANCE_WR(ctx, 0x00ea4/4, 0x01800000);
	INSTANCE_WR(ctx, 0x00ea8/4, 0x00160000);
	INSTANCE_WR(ctx, 0x00eac/4, 0x01800000);
	INSTANCE_WR(ctx, 0x00ebc/4, 0x0003ffff);
	INSTANCE_WR(ctx, 0x00ec0/4, 0x00880000);
	INSTANCE_WR(ctx, 0x00ee4/4, 0x00010401);
	INSTANCE_WR(ctx, 0x00eec/4, 0x00000078);
	INSTANCE_WR(ctx, 0x00ef4/4, 0x000000bf);
	INSTANCE_WR(ctx, 0x00efc/4, 0x00001210);
	INSTANCE_WR(ctx, 0x00f00/4, 0x08000080);
	INSTANCE_WR(ctx, 0x00f28/4, 0x00027070);
	INSTANCE_WR(ctx, 0x00f34/4, 0x03ffffff);
	INSTANCE_WR(ctx, 0x00f4c/4, 0x00120407);
	INSTANCE_WR(ctx, 0x00f50/4, 0x05091507);
	INSTANCE_WR(ctx, 0x00f54/4, 0x05100202);
	INSTANCE_WR(ctx, 0x00f58/4, 0x00030201);
	INSTANCE_WR(ctx, 0x00f74/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00f78/4, 0x0d0c0b0a);
	INSTANCE_WR(ctx, 0x00f7c/4, 0x00141210);
	INSTANCE_WR(ctx, 0x00f80/4, 0x000001f0);
	INSTANCE_WR(ctx, 0x00f84/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00f88/4, 0x00000003);
	INSTANCE_WR(ctx, 0x00f94/4, 0x00039e00);
	INSTANCE_WR(ctx, 0x00f98/4, 0x00000100);
	INSTANCE_WR(ctx, 0x00f9c/4, 0x00003800);
	INSTANCE_WR(ctx, 0x00fa0/4, 0x00404040);
	INSTANCE_WR(ctx, 0x00fa4/4, 0x0000ff0a);
	INSTANCE_WR(ctx, 0x00fac/4, 0x0077f005);
	INSTANCE_WR(ctx, 0x00fb0/4, 0x003f7fff);

	INSTANCE_WR(ctx, 0x00fc0/4, 0x01800000);
	INSTANCE_WR(ctx, 0x00fc4/4, 0x00160000);
	INSTANCE_WR(ctx, 0x00fc8/4, 0x01800000);
	INSTANCE_WR(ctx, 0x00fd8/4, 0x0003ffff);
	INSTANCE_WR(ctx, 0x00fdc/4, 0x00880000);
	INSTANCE_WR(ctx, 0x01000/4, 0x00010401);
	INSTANCE_WR(ctx, 0x01008/4, 0x00000078);
	INSTANCE_WR(ctx, 0x01010/4, 0x000000bf);
	INSTANCE_WR(ctx, 0x01018/4, 0x00001210);
	INSTANCE_WR(ctx, 0x0101c/4, 0x08000080);
	INSTANCE_WR(ctx, 0x01040/4, 0x01800000);
	INSTANCE_WR(ctx, 0x01044/4, 0x00160000);
	INSTANCE_WR(ctx, 0x01048/4, 0x01800000);
	INSTANCE_WR(ctx, 0x01058/4, 0x0003ffff);
	INSTANCE_WR(ctx, 0x0105c/4, 0x00880000);
	INSTANCE_WR(ctx, 0x01080/4, 0x00010401);
	INSTANCE_WR(ctx, 0x01088/4, 0x00000078);
	INSTANCE_WR(ctx, 0x01090/4, 0x000000bf);
	INSTANCE_WR(ctx, 0x01098/4, 0x00001210);
	INSTANCE_WR(ctx, 0x0109c/4, 0x08000080);
	INSTANCE_WR(ctx, 0x010c4/4, 0x00027070);
	INSTANCE_WR(ctx, 0x010d0/4, 0x03ffffff);
	INSTANCE_WR(ctx, 0x010e8/4, 0x00120407);
	INSTANCE_WR(ctx, 0x010ec/4, 0x05091507);
	INSTANCE_WR(ctx, 0x010f0/4, 0x05100202);
	INSTANCE_WR(ctx, 0x010f4/4, 0x00030201);
	INSTANCE_WR(ctx, 0x01110/4, 0x00000040);
	INSTANCE_WR(ctx, 0x01114/4, 0x0d0c0b0a);
	INSTANCE_WR(ctx, 0x01118/4, 0x00141210);
	INSTANCE_WR(ctx, 0x0111c/4, 0x000001f0);
	INSTANCE_WR(ctx, 0x01120/4, 0x00000001);
	INSTANCE_WR(ctx, 0x01124/4, 0x00000003);
	INSTANCE_WR(ctx, 0x01130/4, 0x00039e00);
	INSTANCE_WR(ctx, 0x01134/4, 0x00000100);
	INSTANCE_WR(ctx, 0x01138/4, 0x00003800);
	INSTANCE_WR(ctx, 0x0113c/4, 0x00404040);
	INSTANCE_WR(ctx, 0x01140/4, 0x0000ff0a);
	INSTANCE_WR(ctx, 0x01148/4, 0x0077f005);
	INSTANCE_WR(ctx, 0x0114c/4, 0x003f7fff);

	INSTANCE_WR(ctx, 0x01230/4, 0x00000004);
	INSTANCE_WR(ctx, 0x01284/4, 0x0000000f);
	INSTANCE_WR(ctx, 0x0130c/4, 0x00000002);
	INSTANCE_WR(ctx, 0x01324/4, 0x00000020);
	INSTANCE_WR(ctx, 0x0134c/4, 0x001ffe67);
	INSTANCE_WR(ctx, 0x014ec/4, 0x00000001);
	INSTANCE_WR(ctx, 0x014f0/4, 0x00000004);
	INSTANCE_WR(ctx, 0x01504/4, 0x0000001a);
	INSTANCE_WR(ctx, 0x0150c/4, 0x00000010);
	INSTANCE_WR(ctx, 0x01510/4, 0x00000004);
	INSTANCE_WR(ctx, 0x01530/4, 0x00608080);
	INSTANCE_WR(ctx, 0x0156c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x015d0/4, 0x00000004);
	INSTANCE_WR(ctx, 0x01630/4, 0x00000004);
	INSTANCE_WR(ctx, 0x0164c/4, 0x00000002);
	INSTANCE_WR(ctx, 0x01650/4, 0x00000004);
	INSTANCE_WR(ctx, 0x01670/4, 0x00000080);
	INSTANCE_WR(ctx, 0x01690/4, 0x00000004);
	INSTANCE_WR(ctx, 0x016c4/4, 0x00000004);
	INSTANCE_WR(ctx, 0x016e4/4, 0x00000004);
	INSTANCE_WR(ctx, 0x01724/4, 0x00000004);
	INSTANCE_WR(ctx, 0x01744/4, 0x00000008);
	INSTANCE_WR(ctx, 0x0176c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x01784/4, 0x000007ff);
	INSTANCE_WR(ctx, 0x0178c/4, 0x00000010);
	INSTANCE_WR(ctx, 0x017cc/4, 0x00000001);
	INSTANCE_WR(ctx, 0x01924/4, 0x0000000f);
	INSTANCE_WR(ctx, 0x01a4c/4, 0x00000010);
	INSTANCE_WR(ctx, 0x01b30/4, 0x00000004);
	INSTANCE_WR(ctx, 0x01b50/4, 0x00000080);
	INSTANCE_WR(ctx, 0x01b70/4, 0x00000004);
	INSTANCE_WR(ctx, 0x01b90/4, 0x03020100);
	INSTANCE_WR(ctx, 0x01bb0/4, 0x00000003);
	INSTANCE_WR(ctx, 0x01bd0/4, 0x00000004);
	INSTANCE_WR(ctx, 0x01c6c/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x01c70/4, 0x00000004);
	INSTANCE_WR(ctx, 0x01c8c/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x01c90/4, 0x00000003);
	INSTANCE_WR(ctx, 0x01cac/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x01ccc/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x01cec/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x01d0c/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x01d10/4, 0x00000004);
	INSTANCE_WR(ctx, 0x01d2c/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x01d4c/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x01d6c/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x01d8c/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x01dac/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x01dcc/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x01dec/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x01e0c/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x01e2c/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x01e4c/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x0218c/4, 0x00000010);
	INSTANCE_WR(ctx, 0x021cc/4, 0x0000003f);
	INSTANCE_WR(ctx, 0x022ac/4, 0x00000001);
	INSTANCE_WR(ctx, 0x022ec/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0232c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x024cc/4, 0x00000011);
	INSTANCE_WR(ctx, 0x025cc/4, 0x0000000f);
	INSTANCE_WR(ctx, 0x026cc/4, 0x00000011);
	INSTANCE_WR(ctx, 0x027ac/4, 0x00000001);
	INSTANCE_WR(ctx, 0x027cc/4, 0x00000001);
	INSTANCE_WR(ctx, 0x027ec/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0280c/4, 0x00000002);
	INSTANCE_WR(ctx, 0x0282c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0284c/4, 0x00000002);
	INSTANCE_WR(ctx, 0x0286c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x028ac/4, 0x001ffe67);
	INSTANCE_WR(ctx, 0x028ec/4, 0x0fac6881);
	INSTANCE_WR(ctx, 0x02bac/4, 0x00000001);
	INSTANCE_WR(ctx, 0x02bcc/4, 0x00000002);
	INSTANCE_WR(ctx, 0x02bec/4, 0x00000001);
	INSTANCE_WR(ctx, 0x02c0c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x02c2c/4, 0x00000002);
	INSTANCE_WR(ctx, 0x02c4c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x02c6c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x02cec/4, 0x00000011);
	INSTANCE_WR(ctx, 0x02d0c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0398c/4, 0x00000002);
	INSTANCE_WR(ctx, 0x039cc/4, 0x001ffe67);
	INSTANCE_WR(ctx, 0x03b6c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x03b8c/4, 0x00000010);
	INSTANCE_WR(ctx, 0x03bec/4, 0x00000001);
	INSTANCE_WR(ctx, 0x03ccc/4, 0x00000002);
	INSTANCE_WR(ctx, 0x03dec/4, 0x00000001);
	INSTANCE_WR(ctx, 0x03e04/4, 0x0000000f);
	INSTANCE_WR(ctx, 0x03e0c/4, 0x00000010);
	INSTANCE_WR(ctx, 0x03e44/4, 0x00000001);
	INSTANCE_WR(ctx, 0x03e4c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x040cc/4, 0x00000010);
	INSTANCE_WR(ctx, 0x042ec/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x0430c/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x0432c/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x0434c/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x0436c/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x0438c/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x043ac/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x043cc/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x043ec/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x0440c/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x0442c/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x0444c/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x0446c/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x0448c/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x044ac/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x044cc/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x0480c/4, 0x00000010);
	INSTANCE_WR(ctx, 0x0484c/4, 0x0000003f);
	INSTANCE_WR(ctx, 0x0492c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0496c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x049a4/4, 0x0000000f);
	INSTANCE_WR(ctx, 0x049ac/4, 0x00000001);
	INSTANCE_WR(ctx, 0x04b4c/4, 0x00000011);
	INSTANCE_WR(ctx, 0x04c4c/4, 0x0000000f);
	INSTANCE_WR(ctx, 0x04d4c/4, 0x00000011);
	INSTANCE_WR(ctx, 0x04e2c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x04e4c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x04e6c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x04e8c/4, 0x00000002);
	INSTANCE_WR(ctx, 0x04eac/4, 0x00000001);
	INSTANCE_WR(ctx, 0x04ecc/4, 0x00000002);
	INSTANCE_WR(ctx, 0x04eec/4, 0x00000001);
	INSTANCE_WR(ctx, 0x04f2c/4, 0x001ffe67);
	INSTANCE_WR(ctx, 0x04f6c/4, 0x0fac6881);
	INSTANCE_WR(ctx, 0x0522c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0524c/4, 0x00000002);
	INSTANCE_WR(ctx, 0x0526c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0528c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x052ac/4, 0x00000002);
	INSTANCE_WR(ctx, 0x052cc/4, 0x00000001);
	INSTANCE_WR(ctx, 0x052ec/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0536c/4, 0x00000011);
	INSTANCE_WR(ctx, 0x0538c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x083a0/4, 0x00000021);
	INSTANCE_WR(ctx, 0x083c0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x083e0/4, 0x00000002);
	INSTANCE_WR(ctx, 0x08400/4, 0x00000100);
	INSTANCE_WR(ctx, 0x08420/4, 0x00000100);
	INSTANCE_WR(ctx, 0x08440/4, 0x00000001);
	INSTANCE_WR(ctx, 0x084a0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x084c0/4, 0x00000002);
	INSTANCE_WR(ctx, 0x084e0/4, 0x00000100);
	INSTANCE_WR(ctx, 0x08500/4, 0x00000100);
	INSTANCE_WR(ctx, 0x08520/4, 0x00000001);
	INSTANCE_WR(ctx, 0x11e40/4, 0x00000004);
	INSTANCE_WR(ctx, 0x11e60/4, 0x00000004);
	INSTANCE_WR(ctx, 0x15044/4, 0x0000000f);
	INSTANCE_WR(ctx, 0x152e4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x15304/4, 0x00000100);
	INSTANCE_WR(ctx, 0x15324/4, 0x00000100);
	INSTANCE_WR(ctx, 0x15344/4, 0x00000011);
	INSTANCE_WR(ctx, 0x15384/4, 0x00000008);
	INSTANCE_WR(ctx, 0x15444/4, 0x00000001);
	INSTANCE_WR(ctx, 0x15484/4, 0x00000001);
	INSTANCE_WR(ctx, 0x154a4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x154c4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x154e4/4, 0x000000cf);
	INSTANCE_WR(ctx, 0x15504/4, 0x00000002);
	INSTANCE_WR(ctx, 0x155e4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x15624/4, 0x00000001);
	INSTANCE_WR(ctx, 0x15644/4, 0x00000001);
	INSTANCE_WR(ctx, 0x15664/4, 0x00000001);
	INSTANCE_WR(ctx, 0x15704/4, 0x00000004);
	INSTANCE_WR(ctx, 0x15744/4, 0x00000001);
	INSTANCE_WR(ctx, 0x15764/4, 0x00000015);
	INSTANCE_WR(ctx, 0x157e4/4, 0x04444480);
	INSTANCE_WR(ctx, 0x15f64/4, 0x08100c12);
	INSTANCE_WR(ctx, 0x16004/4, 0x00000100);
	INSTANCE_WR(ctx, 0x16064/4, 0x00010001);
	INSTANCE_WR(ctx, 0x160a4/4, 0x00010001);
	INSTANCE_WR(ctx, 0x160c4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x160e4/4, 0x00010001);
	INSTANCE_WR(ctx, 0x16104/4, 0x00000001);
	INSTANCE_WR(ctx, 0x16124/4, 0x00000004);
	INSTANCE_WR(ctx, 0x16144/4, 0x00000002);
	INSTANCE_WR(ctx, 0x161b0/4, 0x00000004);
	INSTANCE_WR(ctx, 0x161c8/4, 0x003fffff);
	INSTANCE_WR(ctx, 0x161d0/4, 0x00000003);
	INSTANCE_WR(ctx, 0x16228/4, 0x00001fff);
	INSTANCE_WR(ctx, 0x16408/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x16410/4, 0x0000000f);
	INSTANCE_WR(ctx, 0x164e8/4, 0x00000004);
	INSTANCE_WR(ctx, 0x16508/4, 0x0000001a);
	INSTANCE_WR(ctx, 0x16568/4, 0x00000001);
	INSTANCE_WR(ctx, 0x16590/4, 0x00000004);
	INSTANCE_WR(ctx, 0x165b0/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x165d0/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x165f0/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x16610/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x16730/4, 0x00000001);
	INSTANCE_WR(ctx, 0x167b0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x167c8/4, 0x00ffff00);
	INSTANCE_WR(ctx, 0x16870/4, 0x00000001);
	INSTANCE_WR(ctx, 0x168a8/4, 0x0000000f);
	INSTANCE_WR(ctx, 0x169a8/4, 0x0fac6881);
	INSTANCE_WR(ctx, 0x169c8/4, 0x00000011);
	INSTANCE_WR(ctx, 0x16a10/4, 0x00000001);
	INSTANCE_WR(ctx, 0x16a30/4, 0x00000001);
	INSTANCE_WR(ctx, 0x16a50/4, 0x00000002);
	INSTANCE_WR(ctx, 0x16a70/4, 0x00000001);
	INSTANCE_WR(ctx, 0x16a90/4, 0x00000001);
	INSTANCE_WR(ctx, 0x16ab0/4, 0x00000002);
	INSTANCE_WR(ctx, 0x16ad0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x16b10/4, 0x00000011);
	INSTANCE_WR(ctx, 0x16bc8/4, 0x00000004);
	INSTANCE_WR(ctx, 0x16c10/4, 0x0fac6881);
	INSTANCE_WR(ctx, 0x16c68/4, 0x00000002);
	INSTANCE_WR(ctx, 0x16c70/4, 0x00000004);
	INSTANCE_WR(ctx, 0x16c88/4, 0x04000000);
	INSTANCE_WR(ctx, 0x16ca8/4, 0x04000000);
	INSTANCE_WR(ctx, 0x16cf0/4, 0x00000011);
	INSTANCE_WR(ctx, 0x16d10/4, 0x00000001);
	INSTANCE_WR(ctx, 0x16d28/4, 0x00000005);
	INSTANCE_WR(ctx, 0x16d48/4, 0x00000052);
	INSTANCE_WR(ctx, 0x16d50/4, 0x000000cf);
	INSTANCE_WR(ctx, 0x16d70/4, 0x000000cf);
	INSTANCE_WR(ctx, 0x16d90/4, 0x000000cf);
	INSTANCE_WR(ctx, 0x16de8/4, 0x00000001);
	INSTANCE_WR(ctx, 0x16ef0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x16f10/4, 0x00000001);
	INSTANCE_WR(ctx, 0x16f30/4, 0x00000002);
	INSTANCE_WR(ctx, 0x16f50/4, 0x00000001);
	INSTANCE_WR(ctx, 0x16f70/4, 0x00000001);
	INSTANCE_WR(ctx, 0x16f90/4, 0x00000002);
	INSTANCE_WR(ctx, 0x16fb0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x16ff0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x17008/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x17010/4, 0x00000001);
	INSTANCE_WR(ctx, 0x17028/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x17030/4, 0x00000001);
	INSTANCE_WR(ctx, 0x17048/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x17050/4, 0x00000001);
	INSTANCE_WR(ctx, 0x17068/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x17070/4, 0x00000001);
	INSTANCE_WR(ctx, 0x17088/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x17090/4, 0x00000001);
	INSTANCE_WR(ctx, 0x170a8/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x170b0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x170c8/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x170d0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x170e8/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x170f0/4, 0x00000011);
	INSTANCE_WR(ctx, 0x17108/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x17128/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x17148/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x17168/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x17188/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x171a8/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x171c8/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x171e8/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x171f0/4, 0x0fac6881);
	INSTANCE_WR(ctx, 0x17208/4, 0x00000010);
	INSTANCE_WR(ctx, 0x17210/4, 0x0000000f);
	INSTANCE_WR(ctx, 0x17310/4, 0x001ffe67);
	INSTANCE_WR(ctx, 0x17370/4, 0x00000011);
	INSTANCE_WR(ctx, 0x17390/4, 0x00000001);
	INSTANCE_WR(ctx, 0x17410/4, 0x00000004);
	INSTANCE_WR(ctx, 0x174d0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x17570/4, 0x00000011);
	INSTANCE_WR(ctx, 0x17670/4, 0x0fac6881);
	INSTANCE_WR(ctx, 0x176e8/4, 0x08100c12);
	INSTANCE_WR(ctx, 0x176f0/4, 0x00000011);
	INSTANCE_WR(ctx, 0x17708/4, 0x00000005);
	INSTANCE_WR(ctx, 0x17710/4, 0x00000001);
	INSTANCE_WR(ctx, 0x17750/4, 0x00000001);
	INSTANCE_WR(ctx, 0x17768/4, 0x00000001);
	INSTANCE_WR(ctx, 0x17790/4, 0x00000001);
	INSTANCE_WR(ctx, 0x177a8/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x177c8/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x177d0/4, 0x000007ff);
	INSTANCE_WR(ctx, 0x177e8/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x17808/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x17810/4, 0x00000001);
	INSTANCE_WR(ctx, 0x17828/4, 0x00000003);
	INSTANCE_WR(ctx, 0x17850/4, 0x00000001);
	INSTANCE_WR(ctx, 0x17bc4/4, 0x04e3bfdf);
	INSTANCE_WR(ctx, 0x17be4/4, 0x04e3bfdf);
	INSTANCE_WR(ctx, 0x17c28/4, 0x00ffff00);
	INSTANCE_WR(ctx, 0x17c48/4, 0x0000001a);
	INSTANCE_WR(ctx, 0x17c84/4, 0x0fac6881);
	INSTANCE_WR(ctx, 0x17c88/4, 0x00000003);
	INSTANCE_WR(ctx, 0x17db0/4, 0x00000008);
	INSTANCE_WR(ctx, 0x17dd0/4, 0x00000008);
	INSTANCE_WR(ctx, 0x17df0/4, 0x00000008);
	INSTANCE_WR(ctx, 0x17e04/4, 0x04e3bfdf);
	INSTANCE_WR(ctx, 0x17e10/4, 0x00000008);
	INSTANCE_WR(ctx, 0x17e24/4, 0x04e3bfdf);
	INSTANCE_WR(ctx, 0x17e30/4, 0x00000008);
	INSTANCE_WR(ctx, 0x17e50/4, 0x00000008);
	INSTANCE_WR(ctx, 0x17e70/4, 0x00000008);
	INSTANCE_WR(ctx, 0x17e90/4, 0x00000008);
	INSTANCE_WR(ctx, 0x17eb0/4, 0x00000011);
	INSTANCE_WR(ctx, 0x17fb0/4, 0x0fac6881);
	INSTANCE_WR(ctx, 0x17fd0/4, 0x00000400);
	INSTANCE_WR(ctx, 0x17ff0/4, 0x00000400);
	INSTANCE_WR(ctx, 0x18010/4, 0x00000400);
	INSTANCE_WR(ctx, 0x18030/4, 0x00000400);
	INSTANCE_WR(ctx, 0x18050/4, 0x00000400);
	INSTANCE_WR(ctx, 0x18070/4, 0x00000400);
	INSTANCE_WR(ctx, 0x18090/4, 0x00000400);
	INSTANCE_WR(ctx, 0x180b0/4, 0x00000400);
	INSTANCE_WR(ctx, 0x180d0/4, 0x00000300);
	INSTANCE_WR(ctx, 0x180f0/4, 0x00000300);
	INSTANCE_WR(ctx, 0x18110/4, 0x00000300);
	INSTANCE_WR(ctx, 0x18130/4, 0x00000300);
	INSTANCE_WR(ctx, 0x18150/4, 0x00000300);
	INSTANCE_WR(ctx, 0x18168/4, 0x00000102);
	INSTANCE_WR(ctx, 0x18170/4, 0x00000300);
	INSTANCE_WR(ctx, 0x18190/4, 0x00000300);
	INSTANCE_WR(ctx, 0x181a8/4, 0x00000004);
	INSTANCE_WR(ctx, 0x181b0/4, 0x00000300);
	INSTANCE_WR(ctx, 0x181c8/4, 0x00000004);
	INSTANCE_WR(ctx, 0x181d0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x181e8/4, 0x00000004);
	INSTANCE_WR(ctx, 0x181f0/4, 0x0000000f);
	INSTANCE_WR(ctx, 0x18208/4, 0x00000004);
	INSTANCE_WR(ctx, 0x18228/4, 0x00000004);
	INSTANCE_WR(ctx, 0x18248/4, 0x00000004);
	INSTANCE_WR(ctx, 0x18288/4, 0x000007ff);
	INSTANCE_WR(ctx, 0x182c8/4, 0x00000102);
	INSTANCE_WR(ctx, 0x182f0/4, 0x00000020);
	INSTANCE_WR(ctx, 0x18310/4, 0x00000011);
	INSTANCE_WR(ctx, 0x18330/4, 0x00000100);
	INSTANCE_WR(ctx, 0x18370/4, 0x00000001);
	INSTANCE_WR(ctx, 0x183d0/4, 0x00000040);
	INSTANCE_WR(ctx, 0x183f0/4, 0x00000100);
	INSTANCE_WR(ctx, 0x18408/4, 0x00000004);
	INSTANCE_WR(ctx, 0x18428/4, 0x00000004);
	INSTANCE_WR(ctx, 0x18430/4, 0x00000003);
	INSTANCE_WR(ctx, 0x18448/4, 0x00000004);
	INSTANCE_WR(ctx, 0x18468/4, 0x00000004);
	INSTANCE_WR(ctx, 0x184d0/4, 0x001ffe67);
	INSTANCE_WR(ctx, 0x18550/4, 0x00000002);
	INSTANCE_WR(ctx, 0x18570/4, 0x0fac6881);
	INSTANCE_WR(ctx, 0x186b0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x18750/4, 0x00000004);
	INSTANCE_WR(ctx, 0x18790/4, 0x00000001);
	INSTANCE_WR(ctx, 0x187b0/4, 0x00000400);
	INSTANCE_WR(ctx, 0x187d0/4, 0x00000300);
	INSTANCE_WR(ctx, 0x187f0/4, 0x00001001);
	INSTANCE_WR(ctx, 0x18870/4, 0x00000011);
	INSTANCE_WR(ctx, 0x18970/4, 0x0fac6881);
	INSTANCE_WR(ctx, 0x18990/4, 0x0000000f);
	INSTANCE_WR(ctx, 0x18aa8/4, 0x00080c14);
	INSTANCE_WR(ctx, 0x18b08/4, 0x00000804);
	INSTANCE_WR(ctx, 0x18b48/4, 0x00000004);
	INSTANCE_WR(ctx, 0x18b68/4, 0x00000004);
	INSTANCE_WR(ctx, 0x18b88/4, 0x08100c12);
	INSTANCE_WR(ctx, 0x18bc8/4, 0x00000004);
	INSTANCE_WR(ctx, 0x18be8/4, 0x00000004);
	INSTANCE_WR(ctx, 0x18c28/4, 0x00000010);
	INSTANCE_WR(ctx, 0x18c90/4, 0x001ffe67);
	INSTANCE_WR(ctx, 0x18cc8/4, 0x00000804);
	INSTANCE_WR(ctx, 0x18ce8/4, 0x00000001);
	INSTANCE_WR(ctx, 0x18d08/4, 0x0000001a);
	INSTANCE_WR(ctx, 0x18d10/4, 0x00000011);
	INSTANCE_WR(ctx, 0x18d28/4, 0x0000007f);
	INSTANCE_WR(ctx, 0x18d68/4, 0x00000001);
	INSTANCE_WR(ctx, 0x18d70/4, 0x00000004);
	INSTANCE_WR(ctx, 0x18d88/4, 0x00080c14);
	INSTANCE_WR(ctx, 0x18db0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x18dc8/4, 0x08100c12);
	INSTANCE_WR(ctx, 0x18dd0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x18de8/4, 0x00000004);
	INSTANCE_WR(ctx, 0x18e08/4, 0x00000004);
	INSTANCE_WR(ctx, 0x18e48/4, 0x00000010);
	INSTANCE_WR(ctx, 0x18e50/4, 0x00000001);
	INSTANCE_WR(ctx, 0x18ec8/4, 0x00000001);
	INSTANCE_WR(ctx, 0x18ee8/4, 0x08100c12);
	INSTANCE_WR(ctx, 0x18ef0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x18f30/4, 0x00000001);
	INSTANCE_WR(ctx, 0x18fb0/4, 0x2a712488);
	INSTANCE_WR(ctx, 0x18fc8/4, 0x000007ff);
	INSTANCE_WR(ctx, 0x18fe8/4, 0x00080c14);
	INSTANCE_WR(ctx, 0x18ff0/4, 0x4085c000);
	INSTANCE_WR(ctx, 0x19010/4, 0x00000040);
	INSTANCE_WR(ctx, 0x19030/4, 0x00000100);
	INSTANCE_WR(ctx, 0x19050/4, 0x00010100);
	INSTANCE_WR(ctx, 0x19070/4, 0x02800000);
	INSTANCE_WR(ctx, 0x192d0/4, 0x04e3bfdf);
	INSTANCE_WR(ctx, 0x192f0/4, 0x04e3bfdf);
	INSTANCE_WR(ctx, 0x19310/4, 0x00000001);
	INSTANCE_WR(ctx, 0x19350/4, 0x00ffff00);
	INSTANCE_WR(ctx, 0x19370/4, 0x00000001);
	INSTANCE_WR(ctx, 0x193d0/4, 0x00ffff00);
	INSTANCE_WR(ctx, 0x194f0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x19530/4, 0x00000001);
	INSTANCE_WR(ctx, 0x19550/4, 0x30201000);
	INSTANCE_WR(ctx, 0x19570/4, 0x70605040);
	INSTANCE_WR(ctx, 0x19590/4, 0xb8a89888);
	INSTANCE_WR(ctx, 0x195b0/4, 0xf8e8d8c8);
	INSTANCE_WR(ctx, 0x195f0/4, 0x0000001a);
	INSTANCE_WR(ctx, 0x19630/4, 0x00000004);
	INSTANCE_WR(ctx, 0x19708/4, 0x00000001);
	INSTANCE_WR(ctx, 0x19768/4, 0x00000010);
	INSTANCE_WR(ctx, 0x198f0/4, 0x00000004);
	INSTANCE_WR(ctx, 0x19910/4, 0x00000004);
	INSTANCE_WR(ctx, 0x19930/4, 0x00608080);
	INSTANCE_WR(ctx, 0x199d0/4, 0x00000004);
	INSTANCE_WR(ctx, 0x19a30/4, 0x00000004);
	INSTANCE_WR(ctx, 0x19a50/4, 0x00000004);
	INSTANCE_WR(ctx, 0x19a70/4, 0x00000080);
	INSTANCE_WR(ctx, 0x19a90/4, 0x00000004);
	INSTANCE_WR(ctx, 0x19e88/4, 0x00000088);
	INSTANCE_WR(ctx, 0x19ea8/4, 0x00000088);
	INSTANCE_WR(ctx, 0x19f08/4, 0x00000004);
	INSTANCE_WR(ctx, 0x19f30/4, 0x00000004);
	INSTANCE_WR(ctx, 0x19f50/4, 0x00000080);
	INSTANCE_WR(ctx, 0x19f70/4, 0x00000004);
	INSTANCE_WR(ctx, 0x19f90/4, 0x03020100);
	INSTANCE_WR(ctx, 0x19fb0/4, 0x00000003);
	INSTANCE_WR(ctx, 0x19fd0/4, 0x00000004);
	INSTANCE_WR(ctx, 0x1a070/4, 0x00000004);
	INSTANCE_WR(ctx, 0x1a090/4, 0x00000003);
	INSTANCE_WR(ctx, 0x1a110/4, 0x00000004);
	INSTANCE_WR(ctx, 0x1a1e8/4, 0x00000026);
	INSTANCE_WR(ctx, 0x1a248/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x1a2c8/4, 0x0000001a);
	INSTANCE_WR(ctx, 0x1a2e8/4, 0x00000010);
	INSTANCE_WR(ctx, 0x1a808/4, 0x00000052);
	INSTANCE_WR(ctx, 0x1a848/4, 0x00000026);
	INSTANCE_WR(ctx, 0x1a888/4, 0x00000004);
	INSTANCE_WR(ctx, 0x1a8a8/4, 0x00000004);
	INSTANCE_WR(ctx, 0x1a8e8/4, 0x0000001a);
	INSTANCE_WR(ctx, 0x1a948/4, 0x00ffff00);
	INSTANCE_WR(ctx, 0x1a988/4, 0x00000004);
	INSTANCE_WR(ctx, 0x1a9a8/4, 0x00000004);
	INSTANCE_WR(ctx, 0x1a9e8/4, 0x00000080);
	INSTANCE_WR(ctx, 0x1aa08/4, 0x00000004);
	INSTANCE_WR(ctx, 0x1aa28/4, 0x00080c14);
	INSTANCE_WR(ctx, 0x1aa68/4, 0x000007ff);
	INSTANCE_WR(ctx, 0x2d2c8/4, 0x00000004);
	INSTANCE_WR(ctx, 0x2d2e8/4, 0x00000004);
	INSTANCE_WR(ctx, 0x2d328/4, 0x00000080);
	INSTANCE_WR(ctx, 0x2d348/4, 0x00000004);
	INSTANCE_WR(ctx, 0x2d368/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2d3a8/4, 0x00000027);
	INSTANCE_WR(ctx, 0x2d3e8/4, 0x00000026);
	INSTANCE_WR(ctx, 0x2d468/4, 0x04000000);
	INSTANCE_WR(ctx, 0x2d488/4, 0x04000000);
	INSTANCE_WR(ctx, 0x2d4a8/4, 0x04000000);
	INSTANCE_WR(ctx, 0x2d4c8/4, 0x04000000);
	INSTANCE_WR(ctx, 0x2d4e8/4, 0x04000000);
	INSTANCE_WR(ctx, 0x2d508/4, 0x04000000);
	INSTANCE_WR(ctx, 0x2d528/4, 0x04000000);
	INSTANCE_WR(ctx, 0x2d548/4, 0x04000000);
	INSTANCE_WR(ctx, 0x2d568/4, 0x04000000);
	INSTANCE_WR(ctx, 0x2d588/4, 0x04000000);
	INSTANCE_WR(ctx, 0x2d5a8/4, 0x04000000);
	INSTANCE_WR(ctx, 0x2d5c8/4, 0x04000000);
	INSTANCE_WR(ctx, 0x2d5e8/4, 0x04000000);
	INSTANCE_WR(ctx, 0x2d608/4, 0x04000000);
	INSTANCE_WR(ctx, 0x2d628/4, 0x04000000);
	INSTANCE_WR(ctx, 0x2d648/4, 0x04000000);
	INSTANCE_WR(ctx, 0x2dae8/4, 0x04e3bfdf);
	INSTANCE_WR(ctx, 0x2db08/4, 0x04e3bfdf);
	INSTANCE_WR(ctx, 0x2db68/4, 0x0001fe21);
	INSTANCE_WR(ctx, 0x2e5b0/4, 0x00000004);
	INSTANCE_WR(ctx, 0x2e5d0/4, 0x00000003);
	INSTANCE_WR(ctx, 0x2e810/4, 0x0000000f);
	INSTANCE_WR(ctx, 0x2e990/4, 0x00000004);
	INSTANCE_WR(ctx, 0x2e9b0/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x2e9d0/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x2e9f0/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x2ea10/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x2eb30/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2ebb0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2ec70/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2ee10/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2ee30/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2ee50/4, 0x00000002);
	INSTANCE_WR(ctx, 0x2ee70/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2ee90/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2eeb0/4, 0x00000002);
	INSTANCE_WR(ctx, 0x2eed0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2ef10/4, 0x00000011);
	INSTANCE_WR(ctx, 0x2f010/4, 0x0fac6881);
	INSTANCE_WR(ctx, 0x2f070/4, 0x00000004);
	INSTANCE_WR(ctx, 0x2f0f0/4, 0x00000011);
	INSTANCE_WR(ctx, 0x2f110/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2f150/4, 0x000000cf);
	INSTANCE_WR(ctx, 0x2f170/4, 0x000000cf);
	INSTANCE_WR(ctx, 0x2f190/4, 0x000000cf);
	INSTANCE_WR(ctx, 0x2f2f0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2f310/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2f330/4, 0x00000002);
	INSTANCE_WR(ctx, 0x2f350/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2f370/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2f390/4, 0x00000002);
	INSTANCE_WR(ctx, 0x2f3b0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2f3f0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2f410/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2f430/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2f450/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2f470/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2f490/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2f4b0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2f4d0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2f4f0/4, 0x00000011);
	INSTANCE_WR(ctx, 0x2f5f0/4, 0x0fac6881);
	INSTANCE_WR(ctx, 0x2f610/4, 0x0000000f);
	INSTANCE_WR(ctx, 0x2f710/4, 0x001ffe67);
	INSTANCE_WR(ctx, 0x2f770/4, 0x00000011);
	INSTANCE_WR(ctx, 0x2f790/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2f810/4, 0x00000004);
	INSTANCE_WR(ctx, 0x2f8d0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2f970/4, 0x00000011);
	INSTANCE_WR(ctx, 0x2fa70/4, 0x0fac6881);
	INSTANCE_WR(ctx, 0x2faf0/4, 0x00000011);
	INSTANCE_WR(ctx, 0x2fb10/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2fb50/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2fb90/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2fbd0/4, 0x000007ff);
	INSTANCE_WR(ctx, 0x2fc10/4, 0x00000001);
	INSTANCE_WR(ctx, 0x2fc50/4, 0x00000001);
	INSTANCE_WR(ctx, 0x301b0/4, 0x00000008);
	INSTANCE_WR(ctx, 0x301d0/4, 0x00000008);
	INSTANCE_WR(ctx, 0x301f0/4, 0x00000008);
	INSTANCE_WR(ctx, 0x30210/4, 0x00000008);
	INSTANCE_WR(ctx, 0x30230/4, 0x00000008);
	INSTANCE_WR(ctx, 0x30250/4, 0x00000008);
	INSTANCE_WR(ctx, 0x30270/4, 0x00000008);
	INSTANCE_WR(ctx, 0x30290/4, 0x00000008);
	INSTANCE_WR(ctx, 0x302b0/4, 0x00000011);
	INSTANCE_WR(ctx, 0x303b0/4, 0x0fac6881);
	INSTANCE_WR(ctx, 0x303d0/4, 0x00000400);
	INSTANCE_WR(ctx, 0x303f0/4, 0x00000400);
	INSTANCE_WR(ctx, 0x30410/4, 0x00000400);
	INSTANCE_WR(ctx, 0x30430/4, 0x00000400);
	INSTANCE_WR(ctx, 0x30450/4, 0x00000400);
	INSTANCE_WR(ctx, 0x30470/4, 0x00000400);
	INSTANCE_WR(ctx, 0x30490/4, 0x00000400);
	INSTANCE_WR(ctx, 0x304b0/4, 0x00000400);
	INSTANCE_WR(ctx, 0x304d0/4, 0x00000300);
	INSTANCE_WR(ctx, 0x304f0/4, 0x00000300);
	INSTANCE_WR(ctx, 0x30510/4, 0x00000300);
	INSTANCE_WR(ctx, 0x30530/4, 0x00000300);
	INSTANCE_WR(ctx, 0x30550/4, 0x00000300);
	INSTANCE_WR(ctx, 0x30570/4, 0x00000300);
	INSTANCE_WR(ctx, 0x30590/4, 0x00000300);
	INSTANCE_WR(ctx, 0x305b0/4, 0x00000300);
	INSTANCE_WR(ctx, 0x305d0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x305f0/4, 0x0000000f);
	INSTANCE_WR(ctx, 0x306f0/4, 0x00000020);
	INSTANCE_WR(ctx, 0x30710/4, 0x00000011);
	INSTANCE_WR(ctx, 0x30730/4, 0x00000100);
	INSTANCE_WR(ctx, 0x30770/4, 0x00000001);
	INSTANCE_WR(ctx, 0x307d0/4, 0x00000040);
	INSTANCE_WR(ctx, 0x307f0/4, 0x00000100);
	INSTANCE_WR(ctx, 0x30830/4, 0x00000003);
	INSTANCE_WR(ctx, 0x308d0/4, 0x001ffe67);
	INSTANCE_WR(ctx, 0x30950/4, 0x00000002);
	INSTANCE_WR(ctx, 0x30970/4, 0x0fac6881);
	INSTANCE_WR(ctx, 0x30ab0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x30b50/4, 0x00000004);
	INSTANCE_WR(ctx, 0x30b90/4, 0x00000001);
	INSTANCE_WR(ctx, 0x30bb0/4, 0x00000400);
	INSTANCE_WR(ctx, 0x30bd0/4, 0x00000300);
	INSTANCE_WR(ctx, 0x30bf0/4, 0x00001001);
	INSTANCE_WR(ctx, 0x30c70/4, 0x00000011);
	INSTANCE_WR(ctx, 0x30d70/4, 0x0fac6881);
	INSTANCE_WR(ctx, 0x30d90/4, 0x0000000f);
	INSTANCE_WR(ctx, 0x31090/4, 0x001ffe67);
	INSTANCE_WR(ctx, 0x31110/4, 0x00000011);
	INSTANCE_WR(ctx, 0x31170/4, 0x00000004);
	INSTANCE_WR(ctx, 0x311b0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x311d0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x31250/4, 0x00000001);
	INSTANCE_WR(ctx, 0x312f0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x31330/4, 0x00000001);
	INSTANCE_WR(ctx, 0x313b0/4, 0x2a712488);
	INSTANCE_WR(ctx, 0x313f0/4, 0x4085c000);
	INSTANCE_WR(ctx, 0x31410/4, 0x00000040);
	INSTANCE_WR(ctx, 0x31430/4, 0x00000100);
	INSTANCE_WR(ctx, 0x31450/4, 0x00010100);
	INSTANCE_WR(ctx, 0x31470/4, 0x02800000);
	INSTANCE_WR(ctx, 0x316d0/4, 0x04e3bfdf);
	INSTANCE_WR(ctx, 0x316f0/4, 0x04e3bfdf);
	INSTANCE_WR(ctx, 0x31710/4, 0x00000001);
	INSTANCE_WR(ctx, 0x31750/4, 0x00ffff00);
	INSTANCE_WR(ctx, 0x31770/4, 0x00000001);
	INSTANCE_WR(ctx, 0x317d0/4, 0x00ffff00);
	INSTANCE_WR(ctx, 0x318f0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x31930/4, 0x00000001);
	INSTANCE_WR(ctx, 0x31950/4, 0x30201000);
	INSTANCE_WR(ctx, 0x31970/4, 0x70605040);
	INSTANCE_WR(ctx, 0x31990/4, 0xb8a89888);
	INSTANCE_WR(ctx, 0x319b0/4, 0xf8e8d8c8);
	INSTANCE_WR(ctx, 0x319f0/4, 0x0000001a);
	INSTANCE_WR(ctx, 0x4a7e0/4, 0x00000004);
	INSTANCE_WR(ctx, 0x4a800/4, 0x00000004);
	INSTANCE_WR(ctx, 0x4a820/4, 0x08100c12);
	INSTANCE_WR(ctx, 0x4a840/4, 0x00000003);
	INSTANCE_WR(ctx, 0x4a880/4, 0x08100c12);
	INSTANCE_WR(ctx, 0x4a8c0/4, 0x00080c14);
	INSTANCE_WR(ctx, 0x4a8e0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x4a900/4, 0x00080c14);
	INSTANCE_WR(ctx, 0x4a960/4, 0x08100c12);
	INSTANCE_WR(ctx, 0x4a980/4, 0x00000027);
	INSTANCE_WR(ctx, 0x4a9e0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x52220/4, 0x00000001);
	INSTANCE_WR(ctx, 0x52500/4, 0x08100c12);
	INSTANCE_WR(ctx, 0x526a0/4, 0x04000000);
	INSTANCE_WR(ctx, 0x526c0/4, 0x04000000);
	INSTANCE_WR(ctx, 0x52700/4, 0x00000080);
	INSTANCE_WR(ctx, 0x52780/4, 0x00000080);
	INSTANCE_WR(ctx, 0x527c0/4, 0x0000003f);
	INSTANCE_WR(ctx, 0x52920/4, 0x00000002);
	INSTANCE_WR(ctx, 0x52940/4, 0x04000000);
	INSTANCE_WR(ctx, 0x52960/4, 0x04000000);
	INSTANCE_WR(ctx, 0x52a80/4, 0x00000004);
	INSTANCE_WR(ctx, 0x52b00/4, 0x00000004);
	INSTANCE_WR(ctx, 0x52d40/4, 0x00000001);
	INSTANCE_WR(ctx, 0x52d60/4, 0x00001001);
	INSTANCE_WR(ctx, 0x52d80/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x52da0/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x52dc0/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x52de0/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x53200/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x53220/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x53240/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x53260/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x53280/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x532a0/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x532c0/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x532e0/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x53300/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x53320/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x53340/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x53360/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x53380/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x533a0/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x533c0/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x533e0/4, 0x3f800000);
	INSTANCE_WR(ctx, 0x53400/4, 0x00000010);
	INSTANCE_WR(ctx, 0x53460/4, 0x00000003);
	INSTANCE_WR(ctx, 0x53500/4, 0x08100c12);
	INSTANCE_WR(ctx, 0x53524/4, 0x00000080);
	INSTANCE_WR(ctx, 0x53540/4, 0x00000080);
	INSTANCE_WR(ctx, 0x53544/4, 0x80007004);
	INSTANCE_WR(ctx, 0x53560/4, 0x80007004);
	INSTANCE_WR(ctx, 0x53564/4, 0x04000400);
	INSTANCE_WR(ctx, 0x53580/4, 0x04000400);
	INSTANCE_WR(ctx, 0x53584/4, 0x00001000);
	INSTANCE_WR(ctx, 0x535a0/4, 0x00001000);
	INSTANCE_WR(ctx, 0x535e4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x53600/4, 0x00000001);
	INSTANCE_WR(ctx, 0x53644/4, 0x00000001);
	INSTANCE_WR(ctx, 0x53660/4, 0x00000001);
	INSTANCE_WR(ctx, 0x53684/4, 0x00000004);
	INSTANCE_WR(ctx, 0x536a0/4, 0x00000004);
	INSTANCE_WR(ctx, 0x536a4/4, 0x00000002);
	INSTANCE_WR(ctx, 0x536c0/4, 0x00000002);
	INSTANCE_WR(ctx, 0x53824/4, 0x00000080);
	INSTANCE_WR(ctx, 0x53840/4, 0x00000080);
	INSTANCE_WR(ctx, 0x53844/4, 0x80007004);
	INSTANCE_WR(ctx, 0x53860/4, 0x80007004);
	INSTANCE_WR(ctx, 0x53864/4, 0x04000400);
	INSTANCE_WR(ctx, 0x53880/4, 0x04000400);
	INSTANCE_WR(ctx, 0x53884/4, 0x00001000);
	INSTANCE_WR(ctx, 0x538a0/4, 0x00001000);
	INSTANCE_WR(ctx, 0x538e4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x53900/4, 0x00000001);
	INSTANCE_WR(ctx, 0x53944/4, 0x00000001);
	INSTANCE_WR(ctx, 0x53960/4, 0x00000001);
	INSTANCE_WR(ctx, 0x53984/4, 0x00000004);
	INSTANCE_WR(ctx, 0x539a0/4, 0x00000004);
	INSTANCE_WR(ctx, 0x539a4/4, 0x00000002);
	INSTANCE_WR(ctx, 0x539c0/4, 0x00000002);
	INSTANCE_WR(ctx, 0x53b04/4, 0x08100c12);
	INSTANCE_WR(ctx, 0x53b20/4, 0x08100c12);
	INSTANCE_WR(ctx, 0x53be4/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x53c00/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x53c04/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x53c20/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x53c24/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x53c40/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x53c44/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x53c60/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x53c64/4, 0x00000001);
	INSTANCE_WR(ctx, 0x53c80/4, 0x00000001);
	INSTANCE_WR(ctx, 0x53c84/4, 0x00010001);
	INSTANCE_WR(ctx, 0x53ca0/4, 0x00010001);
	INSTANCE_WR(ctx, 0x53ca4/4, 0x00010001);
	INSTANCE_WR(ctx, 0x53cc0/4, 0x00010001);
	INSTANCE_WR(ctx, 0x53cc4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x53ce0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x53d04/4, 0x0001fe21);
	INSTANCE_WR(ctx, 0x53d20/4, 0x0001fe21);
	INSTANCE_WR(ctx, 0x53dc4/4, 0x08100c12);
	INSTANCE_WR(ctx, 0x53de0/4, 0x08100c12);
	INSTANCE_WR(ctx, 0x53de4/4, 0x00000004);
	INSTANCE_WR(ctx, 0x53e00/4, 0x00000004);
	INSTANCE_WR(ctx, 0x53e24/4, 0x00000002);
	INSTANCE_WR(ctx, 0x53e40/4, 0x00000002);
	INSTANCE_WR(ctx, 0x53e44/4, 0x00000011);
	INSTANCE_WR(ctx, 0x53e60/4, 0x00000011);
	INSTANCE_WR(ctx, 0x53f64/4, 0x0fac6881);
	INSTANCE_WR(ctx, 0x53f80/4, 0x0fac6881);
	INSTANCE_WR(ctx, 0x54004/4, 0x00000004);
	INSTANCE_WR(ctx, 0x54020/4, 0x00000004);
	INSTANCE_WR(ctx, 0x54144/4, 0x00000002);
	INSTANCE_WR(ctx, 0x54160/4, 0x00000002);
	INSTANCE_WR(ctx, 0x54164/4, 0x00000001);
	INSTANCE_WR(ctx, 0x54180/4, 0x00000001);
	INSTANCE_WR(ctx, 0x54184/4, 0x00000001);
	INSTANCE_WR(ctx, 0x541a0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x541a4/4, 0x00000002);
	INSTANCE_WR(ctx, 0x541c0/4, 0x00000002);
	INSTANCE_WR(ctx, 0x541c4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x541e0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x541e4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x54200/4, 0x00000001);
	INSTANCE_WR(ctx, 0x54204/4, 0x00000001);
	INSTANCE_WR(ctx, 0x54220/4, 0x00000001);
	INSTANCE_WR(ctx, 0x54244/4, 0x00000004);
	INSTANCE_WR(ctx, 0x54260/4, 0x00000004);
	INSTANCE_WR(ctx, 0x5b6a4/4, 0x00000011);
	INSTANCE_WR(ctx, 0x5b6c0/4, 0x00000011);
	INSTANCE_WR(ctx, 0x5b6e4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x5b700/4, 0x00000001);
}

int
nv50_graph_create_context(struct nouveau_channel *chan)
{
	struct drm_device *dev = chan->dev;
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	struct nouveau_gpuobj *ramin = chan->ramin->gpuobj;
	struct nouveau_engine *engine = &dev_priv->Engine;
	int grctx_size = 0x60000, hdr;
	int ret;

	DRM_DEBUG("ch%d\n", chan->id);

	ret = nouveau_gpuobj_new_ref(dev, chan, NULL, 0, grctx_size, 0x1000,
				     NVOBJ_FLAG_ZERO_ALLOC |
				     NVOBJ_FLAG_ZERO_FREE, &chan->ramin_grctx);
	if (ret)
		return ret;

	hdr = IS_G80 ? 0x200 : 0x20;
	INSTANCE_WR(ramin, (hdr + 0x00)/4, 0x00190002);
	INSTANCE_WR(ramin, (hdr + 0x04)/4, chan->ramin_grctx->instance +
					   grctx_size - 1);
	INSTANCE_WR(ramin, (hdr + 0x08)/4, chan->ramin_grctx->instance);
	INSTANCE_WR(ramin, (hdr + 0x0c)/4, 0);
	INSTANCE_WR(ramin, (hdr + 0x10)/4, 0);
	INSTANCE_WR(ramin, (hdr + 0x14)/4, 0x00010000);

	INSTANCE_WR(chan->ramin_grctx->gpuobj, 0x00000/4,
		    chan->ramin->instance >> 12);
	INSTANCE_WR(chan->ramin_grctx->gpuobj, 0x0011c/4, 0x00000002);

	switch (dev_priv->chipset) {
	case 0x84:
		nv84_graph_init_ctxvals(dev, chan->ramin_grctx);
		break;
	case 0x86:
		nv86_graph_init_ctxvals(dev, chan->ramin_grctx);
		break;
	default:
		/* This is complete crack, it accidently used to make at
		 * least some G8x cards work partially somehow, though there's
		 * no good reason why - and it stopped working as the rest
		 * of the code got off the drugs..
		 */
		ret = engine->graph.load_context(chan);
		if (ret) {
			DRM_ERROR("Error hacking up context: %d\n", ret);
			return ret;
		}
		break;
	}

	return 0;
}

void
nv50_graph_destroy_context(struct nouveau_channel *chan)
{
	struct drm_device *dev = chan->dev;
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	int i, hdr;

	DRM_DEBUG("ch%d\n", chan->id);

	hdr = IS_G80 ? 0x200 : 0x20;
	for (i=hdr; i<hdr+24; i+=4)
		INSTANCE_WR(chan->ramin->gpuobj, i/4, 0);

	nouveau_gpuobj_ref_del(dev, &chan->ramin_grctx);
}

static int
nv50_graph_transfer_context(struct drm_device *dev, uint32_t inst, int save)
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	uint32_t old_cp, tv = 20000;
	int i;

	DRM_DEBUG("inst=0x%08x, save=%d\n", inst, save);

	old_cp = NV_READ(NV20_PGRAPH_CHANNEL_CTX_POINTER);
	NV_WRITE(NV20_PGRAPH_CHANNEL_CTX_POINTER, inst);
	NV_WRITE(0x400824, NV_READ(0x400824) |
		 (save ? NV40_PGRAPH_CTXCTL_0310_XFER_SAVE :
			 NV40_PGRAPH_CTXCTL_0310_XFER_LOAD));
	NV_WRITE(NV40_PGRAPH_CTXCTL_0304, NV40_PGRAPH_CTXCTL_0304_XFER_CTX);

	for (i = 0; i < tv; i++) {
		if (NV_READ(NV40_PGRAPH_CTXCTL_030C) == 0)
			break;
	}
	NV_WRITE(NV20_PGRAPH_CHANNEL_CTX_POINTER, old_cp);

	if (i == tv) {
		DRM_ERROR("failed: inst=0x%08x save=%d\n", inst, save);
		DRM_ERROR("0x40030C = 0x%08x\n",
			  NV_READ(NV40_PGRAPH_CTXCTL_030C));
		return -EBUSY;
	}

	return 0;
}

int
nv50_graph_load_context(struct nouveau_channel *chan)
{
	struct drm_device *dev = chan->dev;
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	uint32_t inst = chan->ramin->instance >> 12;
	int ret; (void)ret;

	DRM_DEBUG("ch%d\n", chan->id);

#if 0
	if ((ret = nv50_graph_transfer_context(dev, inst, 0)))
		return ret;
#endif

	NV_WRITE(NV20_PGRAPH_CHANNEL_CTX_POINTER, inst);
	NV_WRITE(0x400320, 4);
	NV_WRITE(NV40_PGRAPH_CTXCTL_CUR, inst | (1<<31));

	return 0;
}

int
nv50_graph_save_context(struct nouveau_channel *chan)
{
	struct drm_device *dev = chan->dev;
	uint32_t inst = chan->ramin->instance >> 12;

	DRM_DEBUG("ch%d\n", chan->id);

	return nv50_graph_transfer_context(dev, inst, 1);
}