summaryrefslogtreecommitdiff
path: root/linux-core/Makefile
blob: 3aecec43aa378f9a97893a137a739b95c61e3a1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# Makefile -- For the Direct Rendering Manager module (drm)
#
# Based on David Woodhouse's mtd build.
#
# Modified to handle the DRM requirements and builds on a wider range of
# platforms in a flexible way by David Dawes.  It's not clear, however,
# that this approach is simpler than the old one.
#
# The purpose of this Makefile is to handle setting up everything
# needed for an out-of-kernel source build.  Makefile.kernel contains
# everything required for in-kernel source builds.  It is included into
# this file, so none of that should be duplicated here.
#
# $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/Makefile.linux,v 1.40 2003/08/17 17:12:25 dawes Exp $
#

#
# By default, the build is done against the running linux kernel source.
# To build against a different kernel source tree, set LINUXDIR:
#
#    make LINUXDIR=/path/to/kernel/source

#
# To build only some modules, either set DRM_MODULES to the list of modules,
# or specify the modules as targets:
#
#    make r128.o radeon.o
#
# or:
#
#    make DRM_MODULES="r128 radeon"
#

SHELL=/bin/sh

.SUFFIXES:

ifndef LINUXDIR
RUNNING_REL := $(shell uname -r)

LINUXDIR := $(shell if [ -e /lib/modules/$(RUNNING_REL)/source ]; then \
		 echo /lib/modules/$(RUNNING_REL)/source; \
		 else echo /lib/modules/$(RUNNING_REL)/build; fi)
endif

ifndef O
O := $(shell if [ -e /lib/modules/$(RUNNING_REL)/build ]; then \
		 echo /lib/modules/$(RUNNING_REL)/build; \
		 else echo ""; fi)
#O := $(LINUXDIR)
endif

ifdef ARCH
MACHINE := $(ARCH)
else
MACHINE := $(shell uname -m)
endif

# Modules for all architectures
MODULE_LIST := drm.o tdfx.o r128.o radeon.o mga.o sis.o savage.o via.o \
               mach64.o nv.o

# Modules only for ix86 architectures
ifneq (,$(findstring 86,$(MACHINE)))
ARCHX86 := 1
MODULE_LIST += i830.o i810.o i915.o
endif

ifneq (,$(findstring sparc64,$(MACHINE)))
ARCHSPARC64 := 1
#MODULE_LIST += ffb.o
endif

DRM_MODULES ?= $(MODULE_LIST)

# These definitions are for handling dependencies in the out of kernel build.

DRMSHARED =     drm.h drm_sarea.h drm_drawable.c
DRMHEADERS =    drmP.h drm_compat.h drm_os_linux.h drm.h drm_sarea.h
COREHEADERS =   drm_core.h drm_sman.h drm_hashtab.h 

TDFXHEADERS =   tdfx_drv.h $(DRMHEADERS)
TDFXSHARED =    tdfx_drv.h
R128HEADERS =   r128_drv.h r128_drm.h $(DRMHEADERS)
R128SHARED =    r128_drv.h r128_drm.h r128_cce.c r128_state.c r128_irq.c
RADEONHEADERS = radeon_drv.h radeon_drm.h r300_reg.h $(DRMHEADERS)
RADEONSHARED =  radeon_drv.h radeon_drm.h radeon_cp.c radeon_irq.c \
                radeon_mem.c radeon_state.c r300_cmdbuf.c r300_reg.h
MGAHEADERS =    mga_drv.h mga_drm.h mga_ucode.h $(DRMHEADERS)
MGASHARED =     mga_dma.c mga_drm.h mga_drv.h mga_irq.c mga_state.c \
                mga_ucode.h mga_warp.c
I810HEADERS =   i810_drv.h i810_drm.h $(DRMHEADERS)
I830HEADERS =   i830_drv.h i830_drm.h $(DRMHEADERS)
I915HEADERS =   i915_drv.h i915_drm.h $(DRMHEADERS)
I915SHARED  =   i915_drv.h i915_drm.h i915_irq.c i915_mem.c i915_dma.c
SISHEADERS=     sis_drv.h sis_drm.h drm_hashtab.h drm_sman.h $(DRMHEADERS)
SISSHARED=      sis_drv.h sis_drm.h
SAVAGEHEADERS=  savage_drv.h savage_drm.h $(DRMHEADERS)
SAVAGESHARED=	savage_drv.h savage_drm.h savage_bci.c savage_state.c
VIAHEADERS =	via_drm.h via_drv.h via_3d_reg.h via_verifier.h $(DRMHEADERS)
VIASHARED	= via_drm.h via_drv.h via_3d_reg.h via_drv.c via_irq.c via_map.c \
		via_dma.c via_verifier.c via_verifier.h via_video.c
MACH64HEADERS = mach64_drv.h mach64_drm.h $(DRMHEADERS)
MACH64SHARED = 	mach64_drv.h mach64_drm.h mach64_dma.c \
		mach64_irq.c mach64_state.c
NVHEADERS =     nv_drv.h $(DRMHEADERS)
NVSHARED  =     nv_drv.h
FFBHEADERS = 	ffb_drv.h $(DRMHEADERS)

SHAREDSRC = $(DRMSHARED) $(MGASHARED) $(R128SHARED) $(RADEONSHARED) \
	$(SISSHARED) $(TDFXSHARED) $(VIASHARED) $(MACH64SHARED) \
	$(I915SHARED) $(SAVAGESHARED) $(NVSHARED)

PROGS = dristat drmstat

CLEANFILES = *.o *.ko $(PROGS) .depend .*.flags .*.d .*.cmd *.mod.c linux drm_pciids.h .tmp_versions

# VERSION is not defined from the initial invocation.  It is defined when
# this Makefile is invoked from the kernel's root Makefile.

ifndef VERSION

ifdef RUNNING_REL

# SuSE has the version.h and autoconf.h headers for the current kernel
# in /boot as /boot/vmlinuz.version.h and /boot/vmlinuz.autoconf.h.
# Check these first to see if they match the running kernel.

BOOTVERSION_PREFIX = /boot/vmlinuz.

V := $(shell if [ -f $(BOOTVERSION_PREFIX)version.h ]; then \
	grep UTS_RELEASE $(BOOTVERSION_PREFIX)version.h | \
	cut -d' ' -f3; fi)

ifeq ($(V),"$(RUNNING_REL)")
HEADERFROMBOOT := 1
GETCONFIG := MAKEFILES=$(shell pwd)/.config
HAVECONFIG := y
endif

# On Red Hat we need to check if there is a .config file in the kernel
# source directory.  If there isn't, we need to check if there's a
# matching file in the configs subdirectory.

ifneq ($(HAVECONFIG),y)
HAVECONFIG := $(shell if [ -e $(LINUXDIR)/.config ]; then echo y; fi)
endif

ifneq ($(HAVECONFIG),y)
REL_BASE := $(shell echo $(RUNNING_REL) | sed 's/-.*//')
REL_TYPE := $(shell echo $(RUNNING_REL) | sed 's/[0-9.-]//g')
ifeq ($(REL_TYPE),)
RHCONFIG := configs/kernel-$(REL_BASE)-$(MACHINE).config
else
RHCONFIG := configs/kernel-$(REL_BASE)-$(MACHINE)-$(REL_TYPE).config
endif
HAVECONFIG := $(shell if [ -e $(LINUXDIR)/$(RHCONFIG) ]; then echo y; fi)
ifneq ($(HAVECONFIG),y)
RHCONFIG :=
endif
endif

ifneq ($(HAVECONFIG),y)
ifneq ($(0),$(LINUXDIR))
GETCONFIG += O=$(O)
endif
HAVECONFIG := $(shell if [ -e $(O)/.config ]; then echo y; fi)
endif

ifneq ($(HAVECONFIG),y)
$(error Cannot find a kernel config file)
endif

endif

CLEANCONFIG := $(shell if cmp -s $(LINUXDIR)/.config .config; then echo y; fi)
ifeq ($(CLEANCONFIG),y)
CLEANFILES += $(LINUXDIR)/.config .config $(LINUXDIR)/tmp_include_depends
endif

all: modules

modules: includes
	make -C $(LINUXDIR) $(GETCONFIG) SUBDIRS=`pwd` DRMSRCDIR=`pwd` modules

ifeq ($(HEADERFROMBOOT),1)

BOOTHEADERS = version.h autoconf.h
BOOTCONFIG = .config

CLEANFILES += $(BOOTHEADERS) $(BOOTCONFIG)

includes:: $(BOOTHEADERS) $(BOOTCONFIG)

version.h: $(BOOTVERSION_PREFIX)version.h
	rm -f $@
	ln -s $< $@

autoconf.h: $(BOOTVERSION_PREFIX)autoconf.h
	rm -f $@
	ln -s $< $@

.config: $(BOOTVERSION_PREFIX)config
	rm -f $@
	ln -s $< $@
endif

# This prepares an unused Red Hat kernel tree for the build.
ifneq ($(RHCONFIG),)
includes:: $(LINUXDIR)/.config $(LINUXDIR)/tmp_include_depends .config

$(LINUXDIR)/.config: $(LINUXDIR)/$(RHCONFIG)
	rm -f $@
	ln -s $< $@

.config: $(LINUXDIR)/$(RHCONFIG)
	rm -f $@
	ln -s $< $@

$(LINUXDIR)/tmp_include_depends:
	echo all: > $@
endif

# Make sure that the shared source files are linked into this directory.


SHAREDDIR := ../shared-core

HASSHARED := $(shell if [ -d $(SHAREDDIR) ]; then echo y; fi)

ifeq ($(HASSHARED),y)
includes:: $(SHAREDSRC) drm_pciids.h

drm_pciids.h: $(SHAREDDIR)/drm_pciids.txt
	sh ../scripts/create_linux_pci_lists.sh < $(SHAREDDIR)/drm_pciids.txt

$(SHAREDSRC):
	@if [ -r $(SHAREDDIR)/$@ ]; then \
		(rm -f $@; set -x; ln -s $(SHAREDDIR)/$@ $@); fi

CLEANFILES += $(SHAREDSRC)
endif

includes:: linux

linux:
	rm -f linux
	ln -s . linux

clean cleandir:
	rm -rf $(CLEANFILES)

$(MODULE_LIST)::
	make DRM_MODULES=$@ modules

# Build test utilities

PRGCFLAGS = $(CFLAGS) -g -ansi -pedantic -DPOSIX_C_SOURCE=199309L \
	    -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \
	    -I. -I../../..

DRMSTATLIBS = -L../../.. -L.. -ldrm -lxf86_os \
	      -L../../../../dummylib -ldummy -lm

programs: $(PROGS)

dristat: dristat.c
	$(CC) $(PRGCFLAGS) $< -o $@

drmstat: drmstat.c
	$(CC) $(PRGCFLAGS) $< -o $@ $(DRMSTATLIBS)

else

# Check for kernel versions that we don't support.

BELOW24 := $(shell if [ $(VERSION) -lt 2 -o $(PATCHLEVEL) -lt 4 ]; then \
		echo y; fi)

ifeq ($(BELOW24),y)
$(error Only 2.4.x and later kernels are supported \
	($(VERSION).$(PATCHLEVEL).$(SUBLEVEL)))
endif

ifdef ARCHX86
ifndef CONFIG_X86_CMPXCHG
$(error CONFIG_X86_CMPXCHG needs to be enabled in the kernel)
endif
endif

# This needs to go before all other include paths.
CC += -I$(DRMSRCDIR)

# Check for Red Hat's 4-argument do_munmap().
DOMUNMAP := $(shell grep do_munmap $(LINUXDIR)/include/linux/mm.h | \
                grep -c acct)

ifneq ($(DOMUNMAP),0)
EXTRA_CFLAGS += -DDO_MUNMAP_4_ARGS
endif

# Check for 5-argument remap_page_range() in RH9 kernel, and 2.5.x kernels
RPR := $(shell grep remap_page_range $(LINUXDIR)/include/linux/mm.h | \
		grep -c vma)

ifneq ($(RPR),0)
EXTRA_CFLAGS += -DREMAP_PAGE_RANGE_5_ARGS
endif

# Check for 4-argument vmap() in some 2.5.x and 2.4.x kernels
VMAP := $(shell grep -A1 'vmap.*count,$$' $(LINUXDIR)/include/linux/vmalloc.h | \
		grep -c prot)

ifneq ($(VMAP),0)
EXTRA_CFLAGS += -DVMAP_4_ARGS
endif

# Check for PAGE_AGP definition
PAGE_AGP := $(shell cat $(LINUXDIR)/include/asm/agp.h 2>/dev/null | \
		grep -c PAGE_AGP)

ifneq ($(PAGE_AGP),0)
EXTRA_CFLAGS += -DHAVE_PAGE_AGP
endif


# Start with all modules turned off.
CONFIG_DRM_GAMMA := n
CONFIG_DRM_TDFX := n
CONFIG_DRM_MGA := n
CONFIG_DRM_I810 := n
CONFIG_DRM_R128 := n
CONFIG_DRM_RADEON := n
CONFIG_DRM_I830 := n
CONFIG_DRM_I915 := n
CONFIG_DRM_SIS := n
CONFIG_DRM_FFB := n
CONFIG_DRM_SAVAGE := n
CONFIG_DRM_VIA := n
CONFIG_DRM_MACH64 := n
CONFIG_DRM_NV := n

# Enable module builds for the modules requested/supported.

ifneq (,$(findstring tdfx,$(DRM_MODULES)))
CONFIG_DRM_TDFX := m
endif
ifneq (,$(findstring r128,$(DRM_MODULES)))
CONFIG_DRM_R128 := m
endif
ifneq (,$(findstring radeon,$(DRM_MODULES)))
CONFIG_DRM_RADEON := m
endif
ifneq (,$(findstring sis,$(DRM_MODULES)))
CONFIG_DRM_SIS := m
endif
ifneq (,$(findstring via,$(DRM_MODULES)))
CONFIG_DRM_VIA := m
endif
ifneq (,$(findstring mach64,$(DRM_MODULES)))
CONFIG_DRM_MACH64 := m
endif
ifneq (,$(findstring ffb,$(DRM_MODULES)))
CONFIG_DRM_FFB := m
endif
ifneq (,$(findstring savage,$(DRM_MODULES)))
CONFIG_DRM_SAVAGE := m
endif
ifneq (,$(findstring mga,$(DRM_MODULES)))
CONFIG_DRM_MGA := m
endif
ifneq (,$(findstring nv,$(DRM_MODULES)))
CONFIG_DRM_NV := m
endif

# These require AGP support

ifneq (,$(findstring i810,$(DRM_MODULES)))
CONFIG_DRM_I810 := m
endif
ifneq (,$(findstring i830,$(DRM_MODULES)))
CONFIG_DRM_I830 := m
endif
ifneq (,$(findstring i915,$(DRM_MODULES)))
CONFIG_DRM_I915 := m
endif

include $(DRMSRCDIR)/Makefile.kernel

# Depencencies
$(drm-objs):	$(DRMHEADERS) $(COREHEADERS)
$(tdfx-objs):	$(TDFXHEADERS)
$(r128-objs):	$(R128HEADERS)
$(mga-objs):	$(MGAHEADERS)
$(i810-objs):	$(I810HEADERS)
$(i830-objs):	$(I830HEADERS)
$(i915-objs):	$(I915HEADERS)
$(radeon-objs):	$(RADEONHEADERS)
$(sis-objs):	$(SISHEADERS)
$(ffb-objs):	$(FFBHEADERS)
$(savage-objs): $(SAVAGEHEADERS)
$(via-objs):	$(VIAHEADERS)
$(mach64-objs): $(MACH64HEADERS)
$(nv-objs):     $(NVHEADERS)

endif

46' href='#n1346'>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
/*
 * 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"

/* The sizes are taken from the difference between the start of two
 * grctx addresses while running the nvidia driver.  Probably slightly
 * larger than they actually are, because of other objects being created
 * between the contexts
 */
#define NV40_GRCTX_SIZE (175*1024)
#define NV43_GRCTX_SIZE (70*1024)
#define NV46_GRCTX_SIZE (70*1024) /* probably ~64KiB */
#define NV49_GRCTX_SIZE (164640)
#define NV4A_GRCTX_SIZE (64*1024)
#define NV4B_GRCTX_SIZE (164640)
#define NV4C_GRCTX_SIZE (25*1024)
#define NV4E_GRCTX_SIZE (25*1024)

/*TODO: deciper what each offset in the context represents. The below
 *      contexts are taken from dumps just after the 3D object is
 *      created.
 */
static void
nv40_graph_context_init(drm_device_t *dev, nouveau_gpuobj_t *ctx)
{
	drm_nouveau_private_t *dev_priv = dev->dev_private;
	int i;

	/* Always has the "instance address" of itself at offset 0 */
	INSTANCE_WR(ctx, 0x00000/4, ctx->im_pramin->start);
	/* unknown */
	INSTANCE_WR(ctx, 0x00024/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00028/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00030/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0011c/4, 0x20010001);
	INSTANCE_WR(ctx, 0x00120/4, 0x0f73ef00);
	INSTANCE_WR(ctx, 0x00128/4, 0x02008821);
	INSTANCE_WR(ctx, 0x0016c/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00170/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00174/4, 0x00000040);
	INSTANCE_WR(ctx, 0x0017c/4, 0x80000000);
	INSTANCE_WR(ctx, 0x00180/4, 0x80000000);
	INSTANCE_WR(ctx, 0x00184/4, 0x80000000);
	INSTANCE_WR(ctx, 0x00188/4, 0x80000000);
	INSTANCE_WR(ctx, 0x0018c/4, 0x80000000);
	INSTANCE_WR(ctx, 0x0019c/4, 0x00000040);
	INSTANCE_WR(ctx, 0x001a0/4, 0x80000000);
	INSTANCE_WR(ctx, 0x001b0/4, 0x80000000);
	INSTANCE_WR(ctx, 0x001c0/4, 0x80000000);
	INSTANCE_WR(ctx, 0x001d0/4, 0x0b0b0b0c);
	INSTANCE_WR(ctx, 0x00340/4, 0x00040000);
	INSTANCE_WR(ctx, 0x00350/4, 0x55555555);
	INSTANCE_WR(ctx, 0x00354/4, 0x55555555);
	INSTANCE_WR(ctx, 0x00358/4, 0x55555555);
	INSTANCE_WR(ctx, 0x0035c/4, 0x55555555);
	INSTANCE_WR(ctx, 0x00388/4, 0x00000008);
	INSTANCE_WR(ctx, 0x0039c/4, 0x00000010);
	INSTANCE_WR(ctx, 0x00480/4, 0x00000100);
	INSTANCE_WR(ctx, 0x00494/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00498/4, 0x00080060);
	INSTANCE_WR(ctx, 0x004b4/4, 0x00000080);
	INSTANCE_WR(ctx, 0x004b8/4, 0xffff0000);
	INSTANCE_WR(ctx, 0x004bc/4, 0x00000001);
	INSTANCE_WR(ctx, 0x004d0/4, 0x46400000);
	INSTANCE_WR(ctx, 0x004ec/4, 0xffff0000);
	INSTANCE_WR(ctx, 0x004f8/4, 0x0fff0000);
	INSTANCE_WR(ctx, 0x004fc/4, 0x0fff0000);
	INSTANCE_WR(ctx, 0x00504/4, 0x00011100);
	for (i=0x00520; i<=0x0055c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x00568/4, 0x4b7fffff);
	INSTANCE_WR(ctx, 0x00594/4, 0x30201000);
	INSTANCE_WR(ctx, 0x00598/4, 0x70605040);
	INSTANCE_WR(ctx, 0x0059c/4, 0xb8a89888);
	INSTANCE_WR(ctx, 0x005a0/4, 0xf8e8d8c8);
	INSTANCE_WR(ctx, 0x005b4/4, 0x40100000);
	INSTANCE_WR(ctx, 0x005cc/4, 0x00000004);
	INSTANCE_WR(ctx, 0x005d8/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x0060c/4, 0x435185d6);
	INSTANCE_WR(ctx, 0x00610/4, 0x2155b699);
	INSTANCE_WR(ctx, 0x00614/4, 0xfedcba98);
	INSTANCE_WR(ctx, 0x00618/4, 0x00000098);
	INSTANCE_WR(ctx, 0x00628/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x0062c/4, 0x00ff7000);
	INSTANCE_WR(ctx, 0x00630/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00640/4, 0x00ff0000);
	INSTANCE_WR(ctx, 0x0067c/4, 0x00ffff00);
	/* 0x680-0x6BC - NV30_TCL_PRIMITIVE_3D_TX_ADDRESS_UNIT(0-15) */
	/* 0x6C0-0x6FC - NV30_TCL_PRIMITIVE_3D_TX_FORMAT_UNIT(0-15) */
	for (i=0x006C0; i<=0x006fc; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00018488);
	/* 0x700-0x73C - NV30_TCL_PRIMITIVE_3D_TX_WRAP_UNIT(0-15) */
	for (i=0x00700; i<=0x0073c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00028202);
	/* 0x740-0x77C - NV30_TCL_PRIMITIVE_3D_TX_ENABLE_UNIT(0-15) */
	/* 0x780-0x7BC - NV30_TCL_PRIMITIVE_3D_TX_SWIZZLE_UNIT(0-15) */
	for (i=0x00780; i<=0x007bc; i+=4)
		INSTANCE_WR(ctx, i/4, 0x0000aae4);
	/* 0x7C0-0x7FC - NV30_TCL_PRIMITIVE_3D_TX_FILTER_UNIT(0-15) */
	for (i=0x007c0; i<=0x007fc; i+=4)
		INSTANCE_WR(ctx, i/4, 0x01012000);
	/* 0x800-0x83C - NV30_TCL_PRIMITIVE_3D_TX_XY_DIM_UNIT(0-15) */
	for (i=0x00800; i<=0x0083c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00080008);
	/* 0x840-0x87C - NV30_TCL_PRIMITIVE_3D_TX_UNK07_UNIT(0-15) */
	/* 0x880-0x8BC - NV30_TCL_PRIMITIVE_3D_TX_DEPTH_UNIT(0-15) */
	for (i=0x00880; i<=0x008bc; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00100008);
	/* unknown */
	for (i=0x00910; i<=0x0091c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x0001bc80);
	for (i=0x00920; i<=0x0092c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00000202);
	for (i=0x00940; i<=0x0094c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00000008);
	for (i=0x00960; i<=0x0096c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00080008);
	INSTANCE_WR(ctx, 0x00980/4, 0x00000002);
	INSTANCE_WR(ctx, 0x009b4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x009c0/4, 0x3e020200);
	INSTANCE_WR(ctx, 0x009c4/4, 0x00ffffff);
	INSTANCE_WR(ctx, 0x009c8/4, 0x60103f00);
	INSTANCE_WR(ctx, 0x009d4/4, 0x00020000);
	INSTANCE_WR(ctx, 0x00a08/4, 0x00008100);
	INSTANCE_WR(ctx, 0x00aac/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00af0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00af8/4, 0x80800001);
	INSTANCE_WR(ctx, 0x00bcc/4, 0x00000005);
	INSTANCE_WR(ctx, 0x00bf8/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00bfc/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c00/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c04/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c08/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c0c/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c44/4, 0x00000001);
	for (i=0x03008; i<=0x03080; i+=8)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for (i=0x05288; i<=0x08570; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for (i=0x08628; i<=0x08e18; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for (i=0x0bd28; i<=0x0f010; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for (i=0x0f0c8; i<=0x0f8b8; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for (i=0x127c8; i<=0x15ab0; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for (i=0x15b68; i<=0x16358; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for (i=0x19268; i<=0x1c550; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for (i=0x1c608; i<=0x1cdf8; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for (i=0x1fd08; i<=0x22ff0; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for (i=0x230a8; i<=0x23898; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for (i=0x267a8; i<=0x29a90; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for (i=0x29b48; i<=0x2a338; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
}

static void
nv43_graph_context_init(drm_device_t *dev, nouveau_gpuobj_t *ctx)
{
	drm_nouveau_private_t *dev_priv = dev->dev_private;
	int i;
	
	INSTANCE_WR(ctx, 0x00000/4, ctx->im_pramin->start);
	INSTANCE_WR(ctx, 0x00024/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00028/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00030/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0011c/4, 0x20010001);
	INSTANCE_WR(ctx, 0x00120/4, 0x0f73ef00);
	INSTANCE_WR(ctx, 0x00128/4, 0x02008821);
	INSTANCE_WR(ctx, 0x00178/4, 0x00000040);
	INSTANCE_WR(ctx, 0x0017c/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00180/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00188/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00194/4, 0x80000000);
	INSTANCE_WR(ctx, 0x00198/4, 0x80000000);
	INSTANCE_WR(ctx, 0x0019c/4, 0x80000000);
	INSTANCE_WR(ctx, 0x001a0/4, 0x80000000);
	INSTANCE_WR(ctx, 0x001a4/4, 0x80000000);
	INSTANCE_WR(ctx, 0x001a8/4, 0x80000000);
	INSTANCE_WR(ctx, 0x001ac/4, 0x80000000);
	INSTANCE_WR(ctx, 0x001b0/4, 0x80000000);
	INSTANCE_WR(ctx, 0x001d0/4, 0x0b0b0b0c);
	INSTANCE_WR(ctx, 0x00340/4, 0x00040000);
	INSTANCE_WR(ctx, 0x00350/4, 0x55555555);
	INSTANCE_WR(ctx, 0x00354/4, 0x55555555);
	INSTANCE_WR(ctx, 0x00358/4, 0x55555555);
	INSTANCE_WR(ctx, 0x0035c/4, 0x55555555);
	INSTANCE_WR(ctx, 0x00388/4, 0x00000008);
	INSTANCE_WR(ctx, 0x0039c/4, 0x00001010);
	INSTANCE_WR(ctx, 0x003cc/4, 0x00000111);
	INSTANCE_WR(ctx, 0x003d0/4, 0x00080060);
	INSTANCE_WR(ctx, 0x003ec/4, 0x00000080);
	INSTANCE_WR(ctx, 0x003f0/4, 0xffff0000);
	INSTANCE_WR(ctx, 0x003f4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00408/4, 0x46400000);
	INSTANCE_WR(ctx, 0x00418/4, 0xffff0000);
	INSTANCE_WR(ctx, 0x00424/4, 0x0fff0000);
	INSTANCE_WR(ctx, 0x00428/4, 0x0fff0000);
	INSTANCE_WR(ctx, 0x00430/4, 0x00011100);
	for (i=0x0044c; i<=0x00488; i+=4)
		INSTANCE_WR(ctx, i/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x00494/4, 0x4b7fffff);
	INSTANCE_WR(ctx, 0x004bc/4, 0x30201000);
	INSTANCE_WR(ctx, 0x004c0/4, 0x70605040);
	INSTANCE_WR(ctx, 0x004c4/4, 0xb8a89888);
	INSTANCE_WR(ctx, 0x004c8/4, 0xf8e8d8c8);
	INSTANCE_WR(ctx, 0x004dc/4, 0x40100000);
	INSTANCE_WR(ctx, 0x004f8/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x0052c/4, 0x435185d6);
	INSTANCE_WR(ctx, 0x00530/4, 0x2155b699);
	INSTANCE_WR(ctx, 0x00534/4, 0xfedcba98);
	INSTANCE_WR(ctx, 0x00538/4, 0x00000098);
	INSTANCE_WR(ctx, 0x00548/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x0054c/4, 0x00ff7000);
	INSTANCE_WR(ctx, 0x00550/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00560/4, 0x00ff0000);
	INSTANCE_WR(ctx, 0x00598/4, 0x00ffff00);
	for (i=0x005dc; i<=0x00618; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00018488);
	for (i=0x0061c; i<=0x00658; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00028202);
	for (i=0x0069c; i<=0x006d8; i+=4)
		INSTANCE_WR(ctx, i/4, 0x0000aae4);
	for (i=0x006dc; i<=0x00718; i+=4)
		INSTANCE_WR(ctx, i/4, 0x01012000);
	for (i=0x0071c; i<=0x00758; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00080008);
	for (i=0x0079c; i<=0x007d8; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00100008);
	for (i=0x0082c; i<=0x00838; i+=4)
		INSTANCE_WR(ctx, i/4, 0x0001bc80);
	for (i=0x0083c; i<=0x00848; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00000202);
	for (i=0x0085c; i<=0x00868; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00000008);
	for (i=0x0087c; i<=0x00888; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00080008);
	INSTANCE_WR(ctx, 0x0089c/4, 0x00000002);
	INSTANCE_WR(ctx, 0x008d0/4, 0x00000021);
	INSTANCE_WR(ctx, 0x008d4/4, 0x030c30c3);
	INSTANCE_WR(ctx, 0x008e0/4, 0x3e020200);
	INSTANCE_WR(ctx, 0x008e4/4, 0x00ffffff);
	INSTANCE_WR(ctx, 0x008e8/4, 0x0c103f00);
	INSTANCE_WR(ctx, 0x008f4/4, 0x00020000);
	INSTANCE_WR(ctx, 0x0092c/4, 0x00008100);
	INSTANCE_WR(ctx, 0x009b8/4, 0x00000001);
	INSTANCE_WR(ctx, 0x009fc/4, 0x00001001);
	INSTANCE_WR(ctx, 0x00a04/4, 0x00000003);
	INSTANCE_WR(ctx, 0x00a08/4, 0x00888001);
	INSTANCE_WR(ctx, 0x00a8c/4, 0x00000005);
	INSTANCE_WR(ctx, 0x00a98/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00ab4/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00ab8/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00abc/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00ac0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00af8/4, 0x00000001);
	for (i=0x02ec0; i<=0x02f38; i+=8)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for (i=0x04c80; i<=0x06e70; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for (i=0x06e80; i<=0x07270; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for (i=0x096c0; i<=0x0b8b0; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for (i=0x0b8c0; i<=0x0bcb0; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for (i=0x0e100; i<=0x102f0; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for (i=0x10300; i<=0x106f0; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
};

static void
nv46_graph_context_init(drm_device_t *dev, nouveau_gpuobj_t *ctx)
{
	drm_nouveau_private_t *dev_priv = dev->dev_private;
	int i;

	INSTANCE_WR(ctx, 0x00000/4, ctx->im_pramin->start);
	INSTANCE_WR(ctx, 0x00040/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00044/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x0004c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00138/4, 0x20010001);
	INSTANCE_WR(ctx, 0x0013c/4, 0x0f73ef00);
	INSTANCE_WR(ctx, 0x00144/4, 0x02008821);
	INSTANCE_WR(ctx, 0x00174/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00178/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0017c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00180/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00184/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00188/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0018c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00190/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00194/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00198/4, 0x00000040);
	INSTANCE_WR(ctx, 0x0019c/4, 0x00000040);
	INSTANCE_WR(ctx, 0x001a4/4, 0x00000040);
	INSTANCE_WR(ctx, 0x001ec/4, 0x0b0b0b0c);
	INSTANCE_WR(ctx, 0x0035c/4, 0x00040000);
	INSTANCE_WR(ctx, 0x0036c/4, 0x55555555);
	INSTANCE_WR(ctx, 0x00370/4, 0x55555555);
	INSTANCE_WR(ctx, 0x00374/4, 0x55555555);
	INSTANCE_WR(ctx, 0x00378/4, 0x55555555);
	INSTANCE_WR(ctx, 0x003a4/4, 0x00000008);
	INSTANCE_WR(ctx, 0x003b8/4, 0x00003010);
	INSTANCE_WR(ctx, 0x003dc/4, 0x00000111);
	INSTANCE_WR(ctx, 0x003e0/4, 0x00000111);
	INSTANCE_WR(ctx, 0x003e4/4, 0x00000111);
	INSTANCE_WR(ctx, 0x003e8/4, 0x00000111);
	INSTANCE_WR(ctx, 0x003ec/4, 0x00000111);
	INSTANCE_WR(ctx, 0x003f0/4, 0x00000111);
	INSTANCE_WR(ctx, 0x003f4/4, 0x00000111);
	INSTANCE_WR(ctx, 0x003f8/4, 0x00000111);
	INSTANCE_WR(ctx, 0x003fc/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00400/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00404/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00408/4, 0x00000111);
	INSTANCE_WR(ctx, 0x0040c/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00410/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00414/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00418/4, 0x00000111);
	INSTANCE_WR(ctx, 0x004b0/4, 0x00000111);
	INSTANCE_WR(ctx, 0x004b4/4, 0x00080060);
	INSTANCE_WR(ctx, 0x004d0/4, 0x00000080);
	INSTANCE_WR(ctx, 0x004d4/4, 0xffff0000);
	INSTANCE_WR(ctx, 0x004d8/4, 0x00000001);
	INSTANCE_WR(ctx, 0x004ec/4, 0x46400000);
	INSTANCE_WR(ctx, 0x004fc/4, 0xffff0000);
	INSTANCE_WR(ctx, 0x00500/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00504/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00508/4, 0x88888888);
	INSTANCE_WR(ctx, 0x0050c/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00510/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00514/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00518/4, 0x88888888);
	INSTANCE_WR(ctx, 0x0051c/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00520/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00524/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00528/4, 0x88888888);
	INSTANCE_WR(ctx, 0x0052c/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00530/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00534/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00538/4, 0x88888888);
	INSTANCE_WR(ctx, 0x0053c/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00550/4, 0x0fff0000);
	INSTANCE_WR(ctx, 0x00554/4, 0x0fff0000);
	INSTANCE_WR(ctx, 0x0055c/4, 0x00011100);
	for (i=0x00578; i<0x005b4; i+=4)
		INSTANCE_WR(ctx, i/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005c0/4, 0x4b7fffff);
	INSTANCE_WR(ctx, 0x005e8/4, 0x30201000);
	INSTANCE_WR(ctx, 0x005ec/4, 0x70605040);
	INSTANCE_WR(ctx, 0x005f0/4, 0xb8a89888);
	INSTANCE_WR(ctx, 0x005f4/4, 0xf8e8d8c8);
	INSTANCE_WR(ctx, 0x00608/4, 0x40100000);
	INSTANCE_WR(ctx, 0x00624/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00658/4, 0x435185d6);
	INSTANCE_WR(ctx, 0x0065c/4, 0x2155b699);
	INSTANCE_WR(ctx, 0x00660/4, 0xfedcba98);
	INSTANCE_WR(ctx, 0x00664/4, 0x00000098);
	INSTANCE_WR(ctx, 0x00674/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00678/4, 0x00ff7000);
	INSTANCE_WR(ctx, 0x0067c/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x0068c/4, 0x00ff0000);
	INSTANCE_WR(ctx, 0x006c8/4, 0x00ffff00);
	for (i=0x0070c; i<=0x00748; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00018488);
	for (i=0x0074c; i<=0x00788; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00028202);
	for (i=0x007cc; i<=0x00808; i+=4)
		INSTANCE_WR(ctx, i/4, 0x0000aae4);
	for (i=0x0080c; i<=0x00848; i+=4)
		INSTANCE_WR(ctx, i/4, 0x01012000);
	for (i=0x0084c; i<=0x00888; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00080008);
	for (i=0x008cc; i<=0x00908; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00100008);
	for (i=0x0095c; i<=0x00968; i+=4)
		INSTANCE_WR(ctx, i/4, 0x0001bc80);
	for (i=0x0096c; i<=0x00978; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00000202);
	for (i=0x0098c; i<=0x00998; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00000008);
	for (i=0x009ac; i<=0x009b8; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00080008);
	INSTANCE_WR(ctx, 0x009cc/4, 0x00000002);
	INSTANCE_WR(ctx, 0x00a00/4, 0x00000421);
	INSTANCE_WR(ctx, 0x00a04/4, 0x030c30c3);
	INSTANCE_WR(ctx, 0x00a08/4, 0x00011001);
	INSTANCE_WR(ctx, 0x00a14/4, 0x3e020200);
	INSTANCE_WR(ctx, 0x00a18/4, 0x00ffffff);
	INSTANCE_WR(ctx, 0x00a1c/4, 0x0c103f00);
	INSTANCE_WR(ctx, 0x00a28/4, 0x00040000);
	INSTANCE_WR(ctx, 0x00a60/4, 0x00008100);
	INSTANCE_WR(ctx, 0x00aec/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00b30/4, 0x00001001);
	INSTANCE_WR(ctx, 0x00b38/4, 0x00000003);
	INSTANCE_WR(ctx, 0x00b3c/4, 0x00888001);
	INSTANCE_WR(ctx, 0x00bc0/4, 0x00000005);
	INSTANCE_WR(ctx, 0x00bcc/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00be8/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00bec/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00bf0/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00bf4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00c2c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00c30/4, 0x08e00001);
	INSTANCE_WR(ctx, 0x00c34/4, 0x000e3000);
	for (i=0x017f8; i<=0x01870; i+=8)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for (i=0x035b8; i<=0x057a8; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for (i=0x057b8; i<=0x05ba8; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for (i=0x07f38; i<=0x0a128; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for (i=0x0a138; i<=0x0a528; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for (i=0x0c8b8; i<=0x0eaa8; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for (i=0x0eab8; i<=0x0eea8; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
}

static void
nv49_graph_context_init(drm_device_t *dev, nouveau_gpuobj_t *ctx)
{
	drm_nouveau_private_t *dev_priv = dev->dev_private;
	int i;

	INSTANCE_WR(ctx, 0x00000/4, ctx->im_pramin->start);
	INSTANCE_WR(ctx, 0x00004/4, 0x0000c040);
	INSTANCE_WR(ctx, 0x00008/4, 0x0000c040);
	INSTANCE_WR(ctx, 0x0000c/4, 0x0000c040);
	INSTANCE_WR(ctx, 0x00010/4, 0x0000c040);
	INSTANCE_WR(ctx, 0x00014/4, 0x0000c040);
	INSTANCE_WR(ctx, 0x00018/4, 0x0000c040);
	INSTANCE_WR(ctx, 0x0001c/4, 0x0000c040);
	INSTANCE_WR(ctx, 0x00020/4, 0x0000c040);
	INSTANCE_WR(ctx, 0x000c4/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x000c8/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x000d0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x001bc/4, 0x20010001);
	INSTANCE_WR(ctx, 0x001c0/4, 0x0f73ef00);
	INSTANCE_WR(ctx, 0x001c8/4, 0x02008821);
	INSTANCE_WR(ctx, 0x00218/4, 0x00000040);
	INSTANCE_WR(ctx, 0x0021c/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00220/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00228/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00234/4, 0x80000000);
	INSTANCE_WR(ctx, 0x00238/4, 0x80000000);
	INSTANCE_WR(ctx, 0x0023c/4, 0x80000000);
	INSTANCE_WR(ctx, 0x00240/4, 0x80000000);
	INSTANCE_WR(ctx, 0x00244/4, 0x80000000);
	INSTANCE_WR(ctx, 0x00248/4, 0x80000000);
	INSTANCE_WR(ctx, 0x0024c/4, 0x80000000);
	INSTANCE_WR(ctx, 0x00250/4, 0x80000000);
	INSTANCE_WR(ctx, 0x00270/4, 0x0b0b0b0c);
	INSTANCE_WR(ctx, 0x003e0/4, 0x00040000);
	INSTANCE_WR(ctx, 0x003f0/4, 0x55555555);
	INSTANCE_WR(ctx, 0x003f4/4, 0x55555555);
	INSTANCE_WR(ctx, 0x003f8/4, 0x55555555);
	INSTANCE_WR(ctx, 0x003fc/4, 0x55555555);
	INSTANCE_WR(ctx, 0x00428/4, 0x00000008);
	INSTANCE_WR(ctx, 0x0043c/4, 0x00001010);
	INSTANCE_WR(ctx, 0x00460/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00464/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00468/4, 0x00000111);
	INSTANCE_WR(ctx, 0x0046c/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00470/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00474/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00478/4, 0x00000111);
	INSTANCE_WR(ctx, 0x0047c/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00480/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00484/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00488/4, 0x00000111);
	INSTANCE_WR(ctx, 0x0048c/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00490/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00494/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00498/4, 0x00000111);
	INSTANCE_WR(ctx, 0x0049c/4, 0x00000111);
	INSTANCE_WR(ctx, 0x004f4/4, 0x00000111);
	INSTANCE_WR(ctx, 0x004f8/4, 0x00080060);
	INSTANCE_WR(ctx, 0x00514/4, 0x00000080);
	INSTANCE_WR(ctx, 0x00518/4, 0xffff0000);
	INSTANCE_WR(ctx, 0x0051c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00530/4, 0x46400000);
	INSTANCE_WR(ctx, 0x00540/4, 0xffff0000);
	INSTANCE_WR(ctx, 0x00544/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00548/4, 0x88888888);
	INSTANCE_WR(ctx, 0x0054c/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00550/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00554/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00558/4, 0x88888888);
	INSTANCE_WR(ctx, 0x0055c/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00560/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00564/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00568/4, 0x88888888);
	INSTANCE_WR(ctx, 0x0056c/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00570/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00574/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00578/4, 0x88888888);
	INSTANCE_WR(ctx, 0x0057c/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00580/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00594/4, 0x0fff0000);
	INSTANCE_WR(ctx, 0x00598/4, 0x0fff0000);
	INSTANCE_WR(ctx, 0x005a0/4, 0x00011100);
	INSTANCE_WR(ctx, 0x005bc/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005c0/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005c4/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005c8/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005cc/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005d0/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005d4/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005d8/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005dc/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005e0/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005e4/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005e8/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005ec/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005f0/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005f4/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005f8/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x00604/4, 0x4b7fffff);
	INSTANCE_WR(ctx, 0x0062c/4, 0x30201000);
	INSTANCE_WR(ctx, 0x00630/4, 0x70605040);
	INSTANCE_WR(ctx, 0x00634/4, 0xb8a89888);
	INSTANCE_WR(ctx, 0x00638/4, 0xf8e8d8c8);
	INSTANCE_WR(ctx, 0x0064c/4, 0x40100000);
	INSTANCE_WR(ctx, 0x00668/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x0069c/4, 0x435185d6);
	INSTANCE_WR(ctx, 0x006a0/4, 0x2155b699);
	INSTANCE_WR(ctx, 0x006a4/4, 0xfedcba98);
	INSTANCE_WR(ctx, 0x006a8/4, 0x00000098);
	INSTANCE_WR(ctx, 0x006b8/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x006bc/4, 0x00ff7000);
	INSTANCE_WR(ctx, 0x006c0/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x006d0/4, 0x00ff0000);
	INSTANCE_WR(ctx, 0x0070c/4, 0x00ffff00);
	for (i=0x00750; i<=0x0078c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00018488);
	for (i=0x00790; i<=0x007cc; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00028202);
	for (i=0x00810; i<=0x0084c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x0000aae4);
	for (i=0x00850; i<=0x0088c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x01012000);
	for (i=0x00890; i<=0x008cc; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00080008);
	for (i=0x00910; i<=0x0094c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00100008);
	for (i=0x009a0; i<=0x009ac; i+=4)
		INSTANCE_WR(ctx, i/4, 0x0001bc80);
	for (i=0x009b0; i<=0x009bc; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00000202);
	for (i=0x009d0; i<=0x009dc; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00000008);
	for (i=0x009f0; i<=0x009fc; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00080008);
	INSTANCE_WR(ctx, 0x00a10/4, 0x00000002);
	INSTANCE_WR(ctx, 0x00a44/4, 0x00000421);
	INSTANCE_WR(ctx, 0x00a48/4, 0x030c30c3);
	INSTANCE_WR(ctx, 0x00a54/4, 0x3e020200);
	INSTANCE_WR(ctx, 0x00a58/4, 0x00ffffff);
	INSTANCE_WR(ctx, 0x00a5c/4, 0x20103f00);
	INSTANCE_WR(ctx, 0x00a68/4, 0x00040000);
	INSTANCE_WR(ctx, 0x00aa0/4, 0x00008100);
	INSTANCE_WR(ctx, 0x00b2c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00b70/4, 0x00001001);
	INSTANCE_WR(ctx, 0x00b7c/4, 0x00000003);
	INSTANCE_WR(ctx, 0x00b80/4, 0x00888001);
	INSTANCE_WR(ctx, 0x00bb0/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bb4/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bb8/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bbc/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bc0/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bc4/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bc8/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bcc/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bd0/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bd4/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bd8/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bdc/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00be0/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00be4/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00be8/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bec/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bf0/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bf4/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bf8/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bfc/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c00/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c04/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c08/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c0c/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c10/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c14/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c18/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c1c/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c20/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c24/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c28/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c2c/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c54/4, 0x00000005);
	INSTANCE_WR(ctx, 0x00c60/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00c7c/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c80/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c84/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c88/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c8c/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c90/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c94/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c98/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c9c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00cd4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00cd8/4, 0x08e00001);
	INSTANCE_WR(ctx, 0x00cdc/4, 0x000e3000);
	for(i=0x030a0; i<=0x03118; i+=8)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for(i=0x098a0; i<=0x0ba90; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for(i=0x0baa0; i<=0x0be90; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for(i=0x0e2e0; i<=0x0fff0; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for(i=0x10008; i<=0x104d0; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for(i=0x104e0; i<=0x108d0; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for(i=0x12d20; i<=0x14f10; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for(i=0x14f20; i<=0x15310; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for(i=0x17760; i<=0x19950; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for(i=0x19960; i<=0x19d50; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for(i=0x1c1a0; i<=0x1e390; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for(i=0x1e3a0; i<=0x1e790; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for(i=0x20be0; i<=0x22dd0; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for(i=0x22de0; i<=0x231d0; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
}

static void
nv4a_graph_context_init(drm_device_t *dev, nouveau_gpuobj_t *ctx)
{
	drm_nouveau_private_t *dev_priv = dev->dev_private;
	int i;

	INSTANCE_WR(ctx, 0x00000/4, ctx->im_pramin->start);
	INSTANCE_WR(ctx, 0x00024/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00028/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00030/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0011c/4, 0x20010001);
	INSTANCE_WR(ctx, 0x00120/4, 0x0f73ef00);
	INSTANCE_WR(ctx, 0x00128/4, 0x02008821);
	INSTANCE_WR(ctx, 0x00158/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0015c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00160/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00164/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00168/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0016c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00170/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00174/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00178/4, 0x00000040);
	INSTANCE_WR(ctx, 0x0017c/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00180/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00188/4, 0x00000040);
	INSTANCE_WR(ctx, 0x001d0/4, 0x0b0b0b0c);
	INSTANCE_WR(ctx, 0x00340/4, 0x00040000);
	INSTANCE_WR(ctx, 0x00350/4, 0x55555555);
	INSTANCE_WR(ctx, 0x00354/4, 0x55555555);
	INSTANCE_WR(ctx, 0x00358/4, 0x55555555);
	INSTANCE_WR(ctx, 0x0035c/4, 0x55555555);
	INSTANCE_WR(ctx, 0x00388/4, 0x00000008);
	INSTANCE_WR(ctx, 0x0039c/4, 0x00003010);
	INSTANCE_WR(ctx, 0x003cc/4, 0x00000111);
	INSTANCE_WR(ctx, 0x003d0/4, 0x00080060);
	INSTANCE_WR(ctx, 0x003ec/4, 0x00000080);
	INSTANCE_WR(ctx, 0x003f0/4, 0xffff0000);
	INSTANCE_WR(ctx, 0x003f4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00408/4, 0x46400000);
	INSTANCE_WR(ctx, 0x00418/4, 0xffff0000);
	INSTANCE_WR(ctx, 0x00424/4, 0x0fff0000);
	INSTANCE_WR(ctx, 0x00428/4, 0x0fff0000);
	INSTANCE_WR(ctx, 0x00430/4, 0x00011100);
	for (i=0x0044c; i<=0x00488; i+=4)
		INSTANCE_WR(ctx, i/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x00494/4, 0x4b7fffff);
	INSTANCE_WR(ctx, 0x004bc/4, 0x30201000);
	INSTANCE_WR(ctx, 0x004c0/4, 0x70605040);
	INSTANCE_WR(ctx, 0x004c4/4, 0xb8a89888);
	INSTANCE_WR(ctx, 0x004c8/4, 0xf8e8d8c8);
	INSTANCE_WR(ctx, 0x004dc/4, 0x40100000);
	INSTANCE_WR(ctx, 0x004f8/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x0052c/4, 0x435185d6);
	INSTANCE_WR(ctx, 0x00530/4, 0x2155b699);
	INSTANCE_WR(ctx, 0x00534/4, 0xfedcba98);
	INSTANCE_WR(ctx, 0x00538/4, 0x00000098);
	INSTANCE_WR(ctx, 0x00548/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x0054c/4, 0x00ff7000);
	INSTANCE_WR(ctx, 0x00550/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x0055c/4, 0x00ff0000);
	INSTANCE_WR(ctx, 0x00594/4, 0x00ffff00);
	for (i=0x005d8; i<=0x00614; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00018488);
	for (i=0x00618; i<=0x00654; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00028202);
	for (i=0x00698; i<=0x006d4; i+=4)
		INSTANCE_WR(ctx, i/4, 0x0000aae4);
	for (i=0x006d8; i<=0x00714; i+=4)
		INSTANCE_WR(ctx, i/4, 0x01012000);
	for (i=0x00718; i<=0x00754; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00080008);
	for (i=0x00798; i<=0x007d4; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00100008);
	for (i=0x00828; i<=0x00834; i+=4)
		INSTANCE_WR(ctx, i/4, 0x0001bc80);
	for (i=0x00838; i<=0x00844; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00000202);
	for (i=0x00858; i<=0x00864; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00000008);
	for (i=0x00878; i<=0x00884; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00080008);
	INSTANCE_WR(ctx, 0x00898/4, 0x00000002);
	INSTANCE_WR(ctx, 0x008cc/4, 0x00000021);
	INSTANCE_WR(ctx, 0x008d0/4, 0x030c30c3);
	INSTANCE_WR(ctx, 0x008d4/4, 0x00011001);
	INSTANCE_WR(ctx, 0x008e0/4, 0x3e020200);
	INSTANCE_WR(ctx, 0x008e4/4, 0x00ffffff);
	INSTANCE_WR(ctx, 0x008e8/4, 0x0c103f00);
	INSTANCE_WR(ctx, 0x008f4/4, 0x00040000);
	INSTANCE_WR(ctx, 0x0092c/4, 0x00008100);
	INSTANCE_WR(ctx, 0x009b8/4, 0x00000001);
	INSTANCE_WR(ctx, 0x009fc/4, 0x00001001);
	INSTANCE_WR(ctx, 0x00a04/4, 0x00000003);
	INSTANCE_WR(ctx, 0x00a08/4, 0x00888001);
	INSTANCE_WR(ctx, 0x00a8c/4, 0x00000005);
	INSTANCE_WR(ctx, 0x00a98/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00ab4/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00ab8/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00abc/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00ac0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00af8/4, 0x00000001);
	for (i=0x016c0; i<=0x01738; i+=8)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for (i=0x03840; i<=0x05670; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for (i=0x05680; i<=0x05a70; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for (i=0x07e00; i<=0x09ff0; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for (i=0x0a000; i<=0x0a3f0; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for (i=0x0c780; i<=0x0e970; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for (i=0x0e980; i<=0x0ed70; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
}

static void
nv4b_graph_context_init(drm_device_t *dev, nouveau_gpuobj_t *ctx)
{
	drm_nouveau_private_t *dev_priv = dev->dev_private;
	int i;

	INSTANCE_WR(ctx, 0x00000/4, ctx->im_pramin->start);
	INSTANCE_WR(ctx, 0x00004/4, 0x0000c040);
	INSTANCE_WR(ctx, 0x00008/4, 0x0000c040);
	INSTANCE_WR(ctx, 0x0000c/4, 0x0000c040);
	INSTANCE_WR(ctx, 0x00010/4, 0x0000c040);
	INSTANCE_WR(ctx, 0x00014/4, 0x0000c040);
	INSTANCE_WR(ctx, 0x00018/4, 0x0000c040);
	INSTANCE_WR(ctx, 0x0001c/4, 0x0000c040);
	INSTANCE_WR(ctx, 0x00020/4, 0x0000c040);
	INSTANCE_WR(ctx, 0x000c4/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x000c8/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x000d0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x001bc/4, 0x20010001);
	INSTANCE_WR(ctx, 0x001c0/4, 0x0f73ef00);
	INSTANCE_WR(ctx, 0x001c8/4, 0x02008821);
	INSTANCE_WR(ctx, 0x00218/4, 0x00000040);
	INSTANCE_WR(ctx, 0x0021c/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00220/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00228/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00234/4, 0x80000000);
	INSTANCE_WR(ctx, 0x00238/4, 0x80000000);
	INSTANCE_WR(ctx, 0x0023c/4, 0x80000000);
	INSTANCE_WR(ctx, 0x00240/4, 0x80000000);
	INSTANCE_WR(ctx, 0x00244/4, 0x80000000);
	INSTANCE_WR(ctx, 0x00248/4, 0x80000000);
	INSTANCE_WR(ctx, 0x0024c/4, 0x80000000);
	INSTANCE_WR(ctx, 0x00250/4, 0x80000000);
	INSTANCE_WR(ctx, 0x00270/4, 0x0b0b0b0c);
	INSTANCE_WR(ctx, 0x003e0/4, 0x00040000);
	INSTANCE_WR(ctx, 0x003f0/4, 0x55555555);
	INSTANCE_WR(ctx, 0x003f4/4, 0x55555555);
	INSTANCE_WR(ctx, 0x003f8/4, 0x55555555);
	INSTANCE_WR(ctx, 0x003fc/4, 0x55555555);
	INSTANCE_WR(ctx, 0x00428/4, 0x00000008);
	INSTANCE_WR(ctx, 0x0043c/4, 0x00001010);
	INSTANCE_WR(ctx, 0x00460/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00464/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00468/4, 0x00000111);
	INSTANCE_WR(ctx, 0x0046c/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00470/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00474/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00478/4, 0x00000111);
	INSTANCE_WR(ctx, 0x0047c/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00480/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00484/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00488/4, 0x00000111);
	INSTANCE_WR(ctx, 0x0048c/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00490/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00494/4, 0x00000111);
	INSTANCE_WR(ctx, 0x00498/4, 0x00000111);
	INSTANCE_WR(ctx, 0x0049c/4, 0x00000111);
	INSTANCE_WR(ctx, 0x004f4/4, 0x00000111);
	INSTANCE_WR(ctx, 0x004f8/4, 0x00080060);
	INSTANCE_WR(ctx, 0x00514/4, 0x00000080);
	INSTANCE_WR(ctx, 0x00518/4, 0xffff0000);
	INSTANCE_WR(ctx, 0x0051c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00530/4, 0x46400000);
	INSTANCE_WR(ctx, 0x00540/4, 0xffff0000);
	INSTANCE_WR(ctx, 0x00544/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00548/4, 0x88888888);
	INSTANCE_WR(ctx, 0x0054c/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00550/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00554/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00558/4, 0x88888888);
	INSTANCE_WR(ctx, 0x0055c/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00560/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00564/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00568/4, 0x88888888);
	INSTANCE_WR(ctx, 0x0056c/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00570/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00574/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00578/4, 0x88888888);
	INSTANCE_WR(ctx, 0x0057c/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00580/4, 0x88888888);
	INSTANCE_WR(ctx, 0x00594/4, 0x0fff0000);
	INSTANCE_WR(ctx, 0x00598/4, 0x0fff0000);
	INSTANCE_WR(ctx, 0x005a0/4, 0x00011100);
	INSTANCE_WR(ctx, 0x005bc/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005c0/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005c4/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005c8/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005cc/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005d0/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005d4/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005d8/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005dc/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005e0/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005e4/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005e8/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005ec/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005f0/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005f4/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x005f8/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x00604/4, 0x4b7fffff);
	INSTANCE_WR(ctx, 0x0062c/4, 0x30201000);
	INSTANCE_WR(ctx, 0x00630/4, 0x70605040);
	INSTANCE_WR(ctx, 0x00634/4, 0xb8a89888);
	INSTANCE_WR(ctx, 0x00638/4, 0xf8e8d8c8);
	INSTANCE_WR(ctx, 0x0064c/4, 0x40100000);
	INSTANCE_WR(ctx, 0x00668/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x0069c/4, 0x435185d6);
	INSTANCE_WR(ctx, 0x006a0/4, 0x2155b699);
	INSTANCE_WR(ctx, 0x006a4/4, 0xfedcba98);
	INSTANCE_WR(ctx, 0x006a8/4, 0x00000098);
	INSTANCE_WR(ctx, 0x006b8/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x006bc/4, 0x00ff7000);
	INSTANCE_WR(ctx, 0x006c0/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x006d0/4, 0x00ff0000);
	INSTANCE_WR(ctx, 0x0070c/4, 0x00ffff00);
	for (i=0x00750; i<=0x0078c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00018488);
	for (i=0x00790; i<=0x007cc; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00028202);
	for (i=0x00810; i<=0x0084c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x0000aae4);
	for (i=0x00850; i<=0x0088c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x01012000);
	for (i=0x00890; i<=0x008cc; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00080008);
	for (i=0x00910; i<=0x0094c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00100008);
	for (i=0x009a0; i<=0x009ac; i+=4)
		INSTANCE_WR(ctx, i/4, 0x0001bc80);
	for (i=0x009b0; i<=0x009bc; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00000202);
	for (i=0x009d0; i<=0x009dc; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00000008);
	for (i=0x009f0; i<=0x009fc; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00080008);
	INSTANCE_WR(ctx, 0x00a10/4, 0x00000002);
	INSTANCE_WR(ctx, 0x00a44/4, 0x00000421);
	INSTANCE_WR(ctx, 0x00a48/4, 0x030c30c3);
	INSTANCE_WR(ctx, 0x00a54/4, 0x3e020200);
	INSTANCE_WR(ctx, 0x00a58/4, 0x00ffffff);
	INSTANCE_WR(ctx, 0x00a5c/4, 0x20103f00);
	INSTANCE_WR(ctx, 0x00a68/4, 0x00040000);
	INSTANCE_WR(ctx, 0x00aa0/4, 0x00008100);
	INSTANCE_WR(ctx, 0x00b2c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00b70/4, 0x00001001);
	INSTANCE_WR(ctx, 0x00b7c/4, 0x00000003);
	INSTANCE_WR(ctx, 0x00b80/4, 0x00888001);
	INSTANCE_WR(ctx, 0x00bb0/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bb4/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bb8/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bbc/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bc0/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bc4/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bc8/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bcc/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bd0/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bd4/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bd8/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bdc/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00be0/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00be4/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00be8/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bec/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bf0/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bf4/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bf8/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00bfc/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c00/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c04/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c08/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c0c/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c10/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c14/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c18/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c1c/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c20/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c24/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c28/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c2c/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00c54/4, 0x00000005);
	INSTANCE_WR(ctx, 0x00c60/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00c7c/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c80/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c84/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c88/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c8c/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c90/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c94/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c98/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00c9c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00cd4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00cd8/4, 0x08e00001);
	INSTANCE_WR(ctx, 0x00cdc/4, 0x000e3000);
	for(i=0x030a0; i<=0x03118; i+=8)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for(i=0x098a0; i<=0x0ba90; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for(i=0x0baa0; i<=0x0be90; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for(i=0x0e2e0; i<=0x0fff0; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for(i=0x10008; i<=0x104d0; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for(i=0x104e0; i<=0x108d0; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for(i=0x12d20; i<=0x14f10; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for(i=0x14f20; i<=0x15310; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for(i=0x17760; i<=0x19950; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for(i=0x19960; i<=0x19d50; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
}

static void
nv4c_graph_context_init(drm_device_t *dev, nouveau_gpuobj_t *ctx)
{
	drm_nouveau_private_t *dev_priv = dev->dev_private;
	int i;

	INSTANCE_WR(ctx, 0x00000/4, ctx->im_pramin->start);
	INSTANCE_WR(ctx, 0x00024/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00028/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00030/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0011c/4, 0x20010001);
	INSTANCE_WR(ctx, 0x00120/4, 0x0f73ef00);
	INSTANCE_WR(ctx, 0x00128/4, 0x02008821);
	INSTANCE_WR(ctx, 0x00158/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0015c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00160/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00164/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00168/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0016c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00170/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00174/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00178/4, 0x00000040);
	INSTANCE_WR(ctx, 0x0017c/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00180/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00188/4, 0x00000040);
	INSTANCE_WR(ctx, 0x001d0/4, 0x0b0b0b0c);
	INSTANCE_WR(ctx, 0x00340/4, 0x00040000);
	INSTANCE_WR(ctx, 0x00350/4, 0x55555555);
	INSTANCE_WR(ctx, 0x00354/4, 0x55555555);
	INSTANCE_WR(ctx, 0x00358/4, 0x55555555);
	INSTANCE_WR(ctx, 0x0035c/4, 0x55555555);
	INSTANCE_WR(ctx, 0x00388/4, 0x00000008);
	INSTANCE_WR(ctx, 0x0039c/4, 0x00001010);
	INSTANCE_WR(ctx, 0x003d0/4, 0x00000111);
	INSTANCE_WR(ctx, 0x003d4/4, 0x00080060);
	INSTANCE_WR(ctx, 0x003f0/4, 0x00000080);
	INSTANCE_WR(ctx, 0x003f4/4, 0xffff0000);
	INSTANCE_WR(ctx, 0x003f8/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0040c/4, 0x46400000);
	INSTANCE_WR(ctx, 0x0041c/4, 0xffff0000);
	INSTANCE_WR(ctx, 0x00428/4, 0x0fff0000);
	INSTANCE_WR(ctx, 0x0042c/4, 0x0fff0000);
	INSTANCE_WR(ctx, 0x00434/4, 0x00011100);
	for (i=0x00450; i<0x0048c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x00498/4, 0x4b7fffff);
	INSTANCE_WR(ctx, 0x004c0/4, 0x30201000);
	INSTANCE_WR(ctx, 0x004c4/4, 0x70605040);
	INSTANCE_WR(ctx, 0x004c8/4, 0xb8a89888);
	INSTANCE_WR(ctx, 0x004cc/4, 0xf8e8d8c8);
	INSTANCE_WR(ctx, 0x004e0/4, 0x40100000);
	INSTANCE_WR(ctx, 0x004fc/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00530/4, 0x435185d6);
	INSTANCE_WR(ctx, 0x00534/4, 0x2155b699);
	INSTANCE_WR(ctx, 0x00538/4, 0xfedcba98);
	INSTANCE_WR(ctx, 0x0053c/4, 0x00000098);
	INSTANCE_WR(ctx, 0x0054c/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x00550/4, 0x00ff7000);
	INSTANCE_WR(ctx, 0x00554/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00564/4, 0x00ff0000);
	INSTANCE_WR(ctx, 0x0059c/4, 0x00ffff00);
	for (i=0x005e0; i<=0x0061c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00018488);
	for (i=0x00620; i<=0x0065c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00028202);
	for (i=0x006a0; i<=0x006dc; i+=4)
		INSTANCE_WR(ctx, i/4, 0x0000aae4);
	for (i=0x006e0; i<=0x0071c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x01012000);
	for (i=0x00720; i<=0x0075c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00080008);
	for (i=0x007a0; i<=0x007dc; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00100008);
	for (i=0x00830; i<=0x0083c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x0001bc80);
	for (i=0x00840; i<=0x0084c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00000202);
	for (i=0x00860; i<=0x0086c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00000008);
	for (i=0x00880; i<=0x0088c; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00080008);
	INSTANCE_WR(ctx, 0x008a0/4, 0x00000002);
	INSTANCE_WR(ctx, 0x008d4/4, 0x00000020);
	INSTANCE_WR(ctx, 0x008d8/4, 0x030c30c3);
	INSTANCE_WR(ctx, 0x008dc/4, 0x00011001);
	INSTANCE_WR(ctx, 0x008e8/4, 0x3e020200);
	INSTANCE_WR(ctx, 0x008ec/4, 0x00ffffff);
	INSTANCE_WR(ctx, 0x008f0/4, 0x0c103f00);
	INSTANCE_WR(ctx, 0x008fc/4, 0x00040000);
	INSTANCE_WR(ctx, 0x00934/4, 0x00008100);
	INSTANCE_WR(ctx, 0x009c0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00a04/4, 0x00001001);
	INSTANCE_WR(ctx, 0x00a0c/4, 0x00000003);
	INSTANCE_WR(ctx, 0x00a10/4, 0x00888001);
	INSTANCE_WR(ctx, 0x00a74/4, 0x00000005);
	INSTANCE_WR(ctx, 0x00a80/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00a9c/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00aa0/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00ad8/4, 0x00000001);
	for (i=0x016a0; i<0x01718; i+=8)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for (i=0x03460; i<0x05650; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for (i=0x05660; i<0x05a50; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
}

static void
nv4e_graph_context_init(drm_device_t *dev, nouveau_gpuobj_t *ctx)
{
	drm_nouveau_private_t *dev_priv = dev->dev_private;
	int i;

	INSTANCE_WR(ctx, 0x00000/4, ctx->im_pramin->start);
	INSTANCE_WR(ctx, 0x00024/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00028/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00030/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0011c/4, 0x20010001);
	INSTANCE_WR(ctx, 0x00120/4, 0x0f73ef00);
	INSTANCE_WR(ctx, 0x00128/4, 0x02008821);
	INSTANCE_WR(ctx, 0x00158/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0015c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00160/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00164/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00168/4, 0x00000001);
	INSTANCE_WR(ctx, 0x0016c/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00170/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00174/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00178/4, 0x00000040);
	INSTANCE_WR(ctx, 0x0017c/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00180/4, 0x00000040);
	INSTANCE_WR(ctx, 0x00188/4, 0x00000040);
	INSTANCE_WR(ctx, 0x001d0/4, 0x0b0b0b0c);
	INSTANCE_WR(ctx, 0x00340/4, 0x00040000);
	INSTANCE_WR(ctx, 0x00350/4, 0x55555555);
	INSTANCE_WR(ctx, 0x00354/4, 0x55555555);
	INSTANCE_WR(ctx, 0x00358/4, 0x55555555);
	INSTANCE_WR(ctx, 0x0035c/4, 0x55555555);
	INSTANCE_WR(ctx, 0x00388/4, 0x00000008);
	INSTANCE_WR(ctx, 0x0039c/4, 0x00001010);
	INSTANCE_WR(ctx, 0x003cc/4, 0x00000111);
	INSTANCE_WR(ctx, 0x003d0/4, 0x00080060);
	INSTANCE_WR(ctx, 0x003ec/4, 0x00000080);
	INSTANCE_WR(ctx, 0x003f0/4, 0xffff0000);
	INSTANCE_WR(ctx, 0x003f4/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00408/4, 0x46400000);
	INSTANCE_WR(ctx, 0x00418/4, 0xffff0000);
	INSTANCE_WR(ctx, 0x00424/4, 0x0fff0000);
	INSTANCE_WR(ctx, 0x00428/4, 0x0fff0000);
	INSTANCE_WR(ctx, 0x00430/4, 0x00011100);
	for (i=0x0044c; i<=0x00488; i+=4)
		INSTANCE_WR(ctx, i/4, 0x07ff0000);
	INSTANCE_WR(ctx, 0x00494/4, 0x4b7fffff);
	INSTANCE_WR(ctx, 0x004bc/4, 0x30201000);
	INSTANCE_WR(ctx, 0x004c0/4, 0x70605040);
	INSTANCE_WR(ctx, 0x004c4/4, 0xb8a89888);
	INSTANCE_WR(ctx, 0x004c8/4, 0xf8e8d8c8);
	INSTANCE_WR(ctx, 0x004dc/4, 0x40100000);
	INSTANCE_WR(ctx, 0x004f8/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x0052c/4, 0x435185d6);
	INSTANCE_WR(ctx, 0x00530/4, 0x2155b699);
	INSTANCE_WR(ctx, 0x00534/4, 0xfedcba98);
	INSTANCE_WR(ctx, 0x00538/4, 0x00000098);
	INSTANCE_WR(ctx, 0x00548/4, 0xffffffff);
	INSTANCE_WR(ctx, 0x0054c/4, 0x00ff7000);
	INSTANCE_WR(ctx, 0x00550/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x0055c/4, 0x00ff0000);
	INSTANCE_WR(ctx, 0x00594/4, 0x00ffff00);
	for (i=0x005d8; i<=0x00614; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00018488);
	for (i=0x00618; i<=0x00654; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00028202);
	for (i=0x00698; i<=0x006d4; i+=4)
		INSTANCE_WR(ctx, i/4, 0x0000aae4);
	for (i=0x006d8; i<=0x00714; i+=4)
		INSTANCE_WR(ctx, i/4, 0x01012000);
	for (i=0x00718; i<=0x00754; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00080008);
	for (i=0x00798; i<=0x007d4; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00100008);
	for (i=0x00828; i<=0x00834; i+=4)
		INSTANCE_WR(ctx, i/4, 0x0001bc80);
	for (i=0x00838; i<=0x00844; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00000202);
	for (i=0x00858; i<=0x00864; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00000008);
	for (i=0x00878; i<=0x00884; i+=4)
		INSTANCE_WR(ctx, i/4, 0x00080008);
	INSTANCE_WR(ctx, 0x00898/4, 0x00000002);
	INSTANCE_WR(ctx, 0x008cc/4, 0x00000020);
	INSTANCE_WR(ctx, 0x008d0/4, 0x030c30c3);
	INSTANCE_WR(ctx, 0x008d4/4, 0x00011001);
	INSTANCE_WR(ctx, 0x008e0/4, 0x3e020200);
	INSTANCE_WR(ctx, 0x008e4/4, 0x00ffffff);
	INSTANCE_WR(ctx, 0x008e8/4, 0x0c103f00);
	INSTANCE_WR(ctx, 0x008f4/4, 0x00040000);
	INSTANCE_WR(ctx, 0x0092c/4, 0x00008100);
	INSTANCE_WR(ctx, 0x009b8/4, 0x00000001);
	INSTANCE_WR(ctx, 0x009fc/4, 0x00001001);
	INSTANCE_WR(ctx, 0x00a04/4, 0x00000003);
	INSTANCE_WR(ctx, 0x00a08/4, 0x00888001);
	INSTANCE_WR(ctx, 0x00a6c/4, 0x00000005);
	INSTANCE_WR(ctx, 0x00a78/4, 0x0000ffff);
	INSTANCE_WR(ctx, 0x00a94/4, 0x00005555);
	INSTANCE_WR(ctx, 0x00a98/4, 0x00000001);
	INSTANCE_WR(ctx, 0x00aa4/4, 0x00000001);
	for (i=0x01668; i<=0x016e0; i+=8)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
	for (i=0x03428; i<=0x05618; i+=24)
		INSTANCE_WR(ctx, i/4, 0x00000001);
	for (i=0x05628; i<=0x05a18; i+=16)
		INSTANCE_WR(ctx, i/4, 0x3f800000);
}

int
nv40_graph_create_context(drm_device_t *dev, int channel)
{
	drm_nouveau_private_t *dev_priv =
		(drm_nouveau_private_t *)dev->dev_private;
	struct nouveau_fifo *chan = dev_priv->fifos[channel];
	void (*ctx_init)(drm_device_t *, nouveau_gpuobj_t *);
	unsigned int ctx_size;
	int ret;

	switch (dev_priv->chipset) {
	case 0x40:
		ctx_size = NV40_GRCTX_SIZE;
		ctx_init = nv40_graph_context_init;
		break;
	case 0x43:
		ctx_size = NV43_GRCTX_SIZE;
		ctx_init = nv43_graph_context_init;
		break;
	case 0x46:
		ctx_size = NV46_GRCTX_SIZE;
		ctx_init = nv46_graph_context_init;
		break;
	case 0x49:
		ctx_size = NV49_GRCTX_SIZE;
		ctx_init = nv49_graph_context_init;
		break;
	case 0x4a:
		ctx_size = NV4A_GRCTX_SIZE;
		ctx_init = nv4a_graph_context_init;
		break;
	case 0x4b:
		ctx_size = NV4B_GRCTX_SIZE;
		ctx_init = nv4b_graph_context_init;
		break;
	case 0x4c:
		ctx_size = NV4C_GRCTX_SIZE;
		ctx_init = nv4c_graph_context_init;
		break;
	case 0x4e:
		ctx_size = NV4E_GRCTX_SIZE;
		ctx_init = nv4e_graph_context_init;
		break;
	default:
		ctx_size = NV40_GRCTX_SIZE;
		ctx_init = nv40_graph_context_init;
		break;
	}

	if ((ret = nouveau_gpuobj_new_ref(dev, channel, -1, 0, ctx_size, 16,
					  NVOBJ_FLAG_ZERO_ALLOC,
					  &chan->ramin_grctx)))
		return ret;

	/* Initialise default context values */
	ctx_init(dev, chan->ramin_grctx->gpuobj);

	return 0;
}

void
nv40_graph_destroy_context(drm_device_t *dev, int channel)
{
	drm_nouveau_private_t *dev_priv = dev->dev_private;
	struct nouveau_fifo *chan = dev_priv->fifos[channel];

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

static int
nv40_graph_transfer_context(drm_device_t *dev, uint32_t inst, int save)
{
	drm_nouveau_private_t *dev_priv = dev->dev_private;
	uint32_t old_cp, tv = 1000;
	int i;

	old_cp = NV_READ(NV20_PGRAPH_CHANNEL_CTX_POINTER);
	NV_WRITE(NV20_PGRAPH_CHANNEL_CTX_POINTER, inst);
	NV_WRITE(NV40_PGRAPH_CTXCTL_0310,
		 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 DRM_ERR(EBUSY);
	}

	return 0;
}

/* Save current context (from PGRAPH) into the channel's context
 *XXX: fails sometimes, not sure why..
 */
int
nv40_graph_save_context(drm_device_t *dev, int channel)
{
	drm_nouveau_private_t *dev_priv = dev->dev_private;
	struct nouveau_fifo *chan = dev_priv->fifos[channel];
	uint32_t inst;

	if (!chan->ramin_grctx)
		return DRM_ERR(EINVAL);
	inst = chan->ramin_grctx->instance >> 4;

	return nv40_graph_transfer_context(dev, inst, 1);
}

/* Restore the context for a specific channel into PGRAPH
 * XXX: fails sometimes.. not sure why
 */
int
nv40_graph_load_context(drm_device_t *dev, int channel)
{
	drm_nouveau_private_t *dev_priv = dev->dev_private;
	struct nouveau_fifo *chan = dev_priv->fifos[channel];
	uint32_t inst;
	int ret;

	if (!chan->ramin_grctx)
		return DRM_ERR(EINVAL);