[xserver-commit] xserver/hw/kdrive/ati ati_draw.h,1.1,1.2 ati_drawtmp.h,1.1,1.2 ati_dri.c,1.1,1.2 ati_dri.h,1.1,1.2 ati_dripriv.h,1.1,1.2 ati_sarea.h,1.1,1.2 r128_blendtmp.h,1.1,1.2 r128_common.h,1.1,1.2 r128_sarea.h,1.1,1.2 radeon_common.h,1.1,1.2 radeon_sarea.h,1.1,1.2 Makefile.am,1.2,1.3 ati.c,1.7,1.8 ati.h,1.3,1.4 ati_draw.c,1.5,1.6 ati_reg.h,1.2,1.3 ati_stub.c,1.2,1.3

Eric Anholt xserver-commit@pdx.freedesktop.org
Sun, 28 Dec 2003 22:24:04 -0800


Committed by: anholt

Update of /cvs/xserver/xserver/hw/kdrive/ati
In directory pdx:/home/anholt/xserver/hw/kdrive/ati

Modified Files:
	Makefile.am ati.c ati.h ati_draw.c ati_reg.h ati_stub.c 
Added Files:
	ati_draw.h ati_drawtmp.h ati_dri.c ati_dri.h ati_dripriv.h 
	ati_sarea.h r128_blendtmp.h r128_common.h r128_sarea.h 
	radeon_common.h radeon_sarea.h 
Log Message:
Merge dri-0-1-branch to trunk.  Notable changes:
- Add libdrm and libdri.  Portions of the DRI extension are stubbed
  out.
- Use the DRM in the ATI driver when available.  This provides a
  minor performance improvement in x11perf, and opens the possibility
  of using the 3d hardware for acceleration in the future.
- Implement solid fill acceleration for Composite in KAA.
- Implement Blend hook for Composite and use it on r128.
- Fix a bug of mine that resulted in overuse of offscreen memory.
- Fix many miscellaneous bugs in ATI driver and add PCI IDs.













Index: Makefile.am
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/ati/Makefile.am,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Makefile.am	1 Dec 2003 04:33:33 -0000	1.2
+++ Makefile.am	29 Dec 2003 06:24:01 -0000	1.3
@@ -1,3 +1,17 @@
+if DRI
+DRI_INCLUDES = 	-I$(top_srcdir)/dri	\
+		-I$(top_srcdir)/drm
+DRI_LIBS = 	$(top_builddir)/dri/libdri.a	\
+		$(top_builddir)/drm/libdrm.a
+DRI_SOURCES =	ati_dri.c	\
+		ati_dri.h	\
+		ati_dripriv.h	\
+		r128_common.h	\
+		r128_sarea.h	\
+		radeon_common.h	\
+		radeon_sarea.h
+endif
+
 if KDRIVEFBDEV
 FBDEV_INCLUDES =-I$(top_srcdir)/hw/kdrive/fbdev
 FBDEV_LIBS = $(top_builddir)/hw/kdrive/fbdev/libfbdev.a
@@ -8,9 +22,9 @@
 VESA_LIBS = $(top_builddir)/hw/kdrive/vesa/libvesa.a
 endif
 
-
 INCLUDES = 					\
 	@KDRIVE_INCS@				\
+	$(DRI_INCLUDES)				\
 	$(FBDEV_INCLUDES)			\
 	$(VESA_INCLUDES)			\
 	@XSERVER_CFLAGS@
@@ -25,15 +39,20 @@
 
 libati_a_SOURCES = 	\
 	ati_draw.c	\
+	ati_draw.h	\
+	ati_drawtmp.h	\
 	ati.c		\
 	ati.h		\
-	ati_reg.h
+	ati_reg.h	\
+	r128_blendtmp.h	\
+	$(DRI_SOURCES)
 
 Xati_SOURCES = \
 	ati_stub.c
 
 Xati_LDADD = \
 	libati.a 				\
+	$(DRI_LIBS)				\
 	$(FBDEV_LIBS)				\
 	$(VESA_LIBS)				\
 	@KDRIVE_LIBS@				\

Index: ati.c
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/ati/ati.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- ati.c	1 Dec 2003 04:33:33 -0000	1.7
+++ ati.c	29 Dec 2003 06:24:01 -0000	1.8
@@ -27,130 +27,140 @@
 #include <config.h>
 #endif
 #include "ati.h"
+#include "ati_reg.h"
 
-struct pci_id_list radeon_id_list[] = {
-	{0x1002, 0x4136, "ATI Radeon RS100"},
-	{0x1002, 0x4137, "ATI Radeon RS200"},
-	{0x1002, 0x4237, "ATI Radeon RS250"},
-	{0x1002, 0x4144, "ATI Radeon R300 AD"},
-	{0x1002, 0x4145, "ATI Radeon R300 AE"},
-	{0x1002, 0x4146, "ATI Radeon R300 AF"},
-	{0x1002, 0x4147, "ATI Radeon R300 AG"},
-	{0x1002, 0x4148, "ATI Radeon R350 AH"},
-	{0x1002, 0x4149, "ATI Radeon R350 AI"},
-	{0x1002, 0x414a, "ATI Radeon R350 AJ"},
-	{0x1002, 0x414b, "ATI Radeon R350 AK"},
-	{0x1002, 0x4150, "ATI Radeon RV350 AP"},
-	{0x1002, 0x4151, "ATI Radeon RV350 AQ"},
-	{0x1002, 0x4152, "ATI Radeon RV350 AR"},
-	{0x1002, 0x4153, "ATI Radeon RV350 AS"},
-	{0x1002, 0x4154, "ATI Radeon RV350 AT"},
-	{0x1002, 0x4156, "ATI Radeon RV350 AV"},
-	{0x1002, 0x4242, "ATI Radeon R200 BB"},
-	{0x1002, 0x4243, "ATI Radeon R200 BC"},
-	{0x1002, 0x4336, "ATI Radeon RS100"},
-	{0x1002, 0x4337, "ATI Radeon RS200"},
-	{0x1002, 0x4437, "ATI Radeon RS250"},
-	{0x1002, 0x4964, "ATI Radeon RV250 Id"},
-	{0x1002, 0x4965, "ATI Radeon RV250 Ie"},
-	{0x1002, 0x4966, "ATI Radeon RV250 If"},
-	{0x1002, 0x4967, "ATI Radeon RV250 Ig"},
-	{0x1002, 0x4c57, "ATI Radeon RV200 LW"},
-	{0x1002, 0x4c58, "ATI Radeon RV200 LX"},
-	{0x1002, 0x4c59, "ATI Radeon Mobility M6 LY"},
-	{0x1002, 0x4c5a, "ATI Radeon Mobility LZ"},
-	{0x1002, 0x4c64, "ATI Radeon RV250 Ld"},
-	{0x1002, 0x4c65, "ATI Radeon RV250 Le"},
-	{0x1002, 0x4c66, "ATI Radeon Mobility M9 RV250 Lf"},
-	{0x1002, 0x4c67, "ATI Radeon RV250 Lg"},
-	{0x1002, 0x4e44, "ATI Radeon R300 ND"},
-	{0x1002, 0x4e45, "ATI Radeon R300 NE"},
-	{0x1002, 0x4e46, "ATI Radeon R300 NF"},
-	{0x1002, 0x4e47, "ATI Radeon R300 NG"},
-	{0x1002, 0x4e48, "ATI Radeon R350 NH"},
-	{0x1002, 0x4e49, "ATI Radeon R350 NI"},
-	{0x1002, 0x4e4a, "ATI Radeon R350 NJ"},
-	{0x1002, 0x4e4b, "ATI Radeon R350 NK"},
-	{0x1002, 0x4e50, "ATI Radeon Mobility RV350 NP"},
-	{0x1002, 0x4e51, "ATI Radeon Mobility RV350 NQ"},
-	{0x1002, 0x4e52, "ATI Radeon Mobility RV350 NR"},
-	{0x1002, 0x4e53, "ATI Radeon Mobility RV350 NS"},
-	{0x1002, 0x4e54, "ATI Radeon Mobility RV350 NT"},
-	{0x1002, 0x4e56, "ATI Radeon Mobility RV350 NV"},
-	{0x1002, 0x5144, "ATI Radeon R100 QD"},
-	{0x1002, 0x5145, "ATI Radeon R100 QE"},
-	{0x1002, 0x5146, "ATI Radeon R100 QF"},
-	{0x1002, 0x5147, "ATI Radeon R100 QG"},
-	{0x1002, 0x5148, "ATI Radeon R200 QH"},
-	{0x1002, 0x514c, "ATI Radeon R200 QL"},
-	{0x1002, 0x514d, "ATI Radeon R200 QM"},
-	{0x1002, 0x5157, "ATI Radeon RV200 QW"},
-	{0x1002, 0x5158, "ATI Radeon RV200 QX"},
-	{0x1002, 0x5159, "ATI Radeon RV100 QY"},
-	{0x1002, 0x515a, "ATI Radeon RV100 QZ"},
-	{0x1002, 0x5834, "ATI Radeon RS300"},
-	{0x1002, 0x5835, "ATI Radeon Mobility RS300"},
-	{0x1002, 0x5941, "ATI Radeon RV280 (9200)"},
-	{0x1002, 0x5961, "ATI Radeon RV280 (9200 SE)"},
-	{0x1002, 0x5964, "ATI Radeon RV280 (9200 SE)"},
-	{0x1002, 0x5c60, "ATI Radeon RV280"},
-	{0x1002, 0x5c61, "ATI Mobility Radeon RV280"},
-	{0x1002, 0x5c62, "ATI Radeon RV280"},
-	{0x1002, 0x5c63, "ATI Mobility Radeon RV280"},
-	{0x1002, 0x5c64, "ATI Radeon RV280"},
-	{0, 0, NULL}
+struct pci_id_entry ati_pci_ids[] = {
+	{0x1002, 0x4136, 0x1, "ATI Radeon RS100"},
+	{0x1002, 0x4137, 0x3, "ATI Radeon RS200"},
+	{0x1002, 0x4237, 0x3, "ATI Radeon RS250"},
+	{0x1002, 0x4144, 0x5, "ATI Radeon R300 AD"},
+	{0x1002, 0x4145, 0x5, "ATI Radeon R300 AE"},
+	{0x1002, 0x4146, 0x5, "ATI Radeon R300 AF"},
+	{0x1002, 0x4147, 0x5, "ATI Radeon R300 AG"},
+	{0x1002, 0x4148, 0x5, "ATI Radeon R350 AH"},
+	{0x1002, 0x4149, 0x5, "ATI Radeon R350 AI"},
+	{0x1002, 0x414a, 0x5, "ATI Radeon R350 AJ"},
+	{0x1002, 0x414b, 0x5, "ATI Radeon R350 AK"},
+	{0x1002, 0x4150, 0x5, "ATI Radeon RV350 AP"},
+	{0x1002, 0x4151, 0x5, "ATI Radeon RV350 AQ"},
+	{0x1002, 0x4152, 0x5, "ATI Radeon RV350 AR"},
+	{0x1002, 0x4153, 0x5, "ATI Radeon RV350 AS"},
+	{0x1002, 0x4154, 0x5, "ATI Radeon RV350 AT"},
+	{0x1002, 0x4156, 0x5, "ATI Radeon RV350 AV"},
+	{0x1002, 0x4242, 0x3, "ATI Radeon R200 BB"},
+	{0x1002, 0x4243, 0x3, "ATI Radeon R200 BC"},
+	{0x1002, 0x4336, 0x1, "ATI Radeon RS100"},
+	{0x1002, 0x4337, 0x3, "ATI Radeon RS200"},
+	{0x1002, 0x4437, 0x3, "ATI Radeon RS250"},
+	{0x1002, 0x4964, 0x3, "ATI Radeon RV250 Id"},
+	{0x1002, 0x4965, 0x3, "ATI Radeon RV250 Ie"},
+	{0x1002, 0x4966, 0x3, "ATI Radeon RV250 If"},
+	{0x1002, 0x4967, 0x3, "ATI Radeon RV250 Ig"},
+	{0x1002, 0x4c45, 0x0, "ATI Rage 128 LE"},
+	{0x1002, 0x4c46, 0x0, "ATI Rage 128 LF"},
+	{0x1002, 0x4c57, 0x3, "ATI Radeon RV200 LW"},
+	{0x1002, 0x4c58, 0x3, "ATI Radeon RV200 LX"},
+	{0x1002, 0x4c59, 0x3, "ATI Radeon Mobility M6 LY"},
+	{0x1002, 0x4c5a, 0x3, "ATI Radeon Mobility LZ"},
+	{0x1002, 0x4c64, 0x3, "ATI Radeon RV250 Ld"},
+	{0x1002, 0x4c65, 0x3, "ATI Radeon RV250 Le"},
+	{0x1002, 0x4c66, 0x3, "ATI Radeon Mobility M9 RV250 Lf"},
+	{0x1002, 0x4c67, 0x3, "ATI Radeon RV250 Lg"},
+	{0x1002, 0x4d46, 0x0, "ATI Rage 128 MF"},
+	{0x1002, 0x4d46, 0x0, "ATI Rage 128 ML"},
+	{0x1002, 0x4e44, 0x5, "ATI Radeon R300 ND"},
+	{0x1002, 0x4e45, 0x5, "ATI Radeon R300 NE"},
+	{0x1002, 0x4e46, 0x5, "ATI Radeon R300 NF"},
+	{0x1002, 0x4e47, 0x5, "ATI Radeon R300 NG"},
+	{0x1002, 0x4e48, 0x5, "ATI Radeon R350 NH"},
+	{0x1002, 0x4e49, 0x5, "ATI Radeon R350 NI"},
+	{0x1002, 0x4e4a, 0x5, "ATI Radeon R350 NJ"},
+	{0x1002, 0x4e4b, 0x5, "ATI Radeon R350 NK"},
+	{0x1002, 0x4e50, 0x5, "ATI Radeon Mobility RV350 NP"},
+	{0x1002, 0x4e51, 0x5, "ATI Radeon Mobility RV350 NQ"},
+	{0x1002, 0x4e52, 0x5, "ATI Radeon Mobility RV350 NR"},
+	{0x1002, 0x4e53, 0x5, "ATI Radeon Mobility RV350 NS"},
+	{0x1002, 0x4e54, 0x5, "ATI Radeon Mobility RV350 NT"},
+	{0x1002, 0x4e56, 0x5, "ATI Radeon Mobility RV350 NV"},
+	{0x1002, 0x5041, 0x0, "ATI Rage 128 PA"},
+	{0x1002, 0x5042, 0x0, "ATI Rage 128 PB"},
+	{0x1002, 0x5043, 0x0, "ATI Rage 128 PC"},
+	{0x1002, 0x5044, 0x0, "ATI Rage 128 PD"},
+	{0x1002, 0x5045, 0x0, "ATI Rage 128 PE"},
+	{0x1002, 0x5046, 0x0, "ATI Rage 128 PF"},
+	{0x1002, 0x5047, 0x0, "ATI Rage 128 PG"},
+	{0x1002, 0x5048, 0x0, "ATI Rage 128 PH"},
+	{0x1002, 0x5049, 0x0, "ATI Rage 128 PI"},
+	{0x1002, 0x504a, 0x0, "ATI Rage 128 PJ"},
+	{0x1002, 0x504b, 0x0, "ATI Rage 128 PK"},
+	{0x1002, 0x504c, 0x0, "ATI Rage 128 PL"},
+	{0x1002, 0x504d, 0x0, "ATI Rage 128 PM"},
+	{0x1002, 0x504e, 0x0, "ATI Rage 128 PN"},
+	{0x1002, 0x504f, 0x0, "ATI Rage 128 PO"},
+	{0x1002, 0x5050, 0x0, "ATI Rage 128 PP"},
+	{0x1002, 0x5051, 0x0, "ATI Rage 128 PQ"},
+	{0x1002, 0x5052, 0x0, "ATI Rage 128 PR"},
+	{0x1002, 0x5053, 0x0, "ATI Rage 128 PS"},
+	{0x1002, 0x5054, 0x0, "ATI Rage 128 PT"},
+	{0x1002, 0x5055, 0x0, "ATI Rage 128 PU"},
+	{0x1002, 0x5056, 0x0, "ATI Rage 128 PV"},
+	{0x1002, 0x5057, 0x0, "ATI Rage 128 PW"},
+	{0x1002, 0x5058, 0x0, "ATI Rage 128 PX"},
+	{0x1002, 0x5144, 0x1, "ATI Radeon R100 QD"},
+	{0x1002, 0x5145, 0x1, "ATI Radeon R100 QE"},
+	{0x1002, 0x5146, 0x1, "ATI Radeon R100 QF"},
+	{0x1002, 0x5147, 0x1, "ATI Radeon R100 QG"},
+	{0x1002, 0x5148, 0x1, "ATI Radeon R200 QH"},
+	{0x1002, 0x514c, 0x1, "ATI Radeon R200 QL"},
+	{0x1002, 0x514d, 0x1, "ATI Radeon R200 QM"},
+	{0x1002, 0x5157, 0x1, "ATI Radeon RV200 QW"},
+	{0x1002, 0x5158, 0x1, "ATI Radeon RV200 QX"},
+	{0x1002, 0x5159, 0x1, "ATI Radeon RV100 QY"},
+	{0x1002, 0x515a, 0x1, "ATI Radeon RV100 QZ"},
+	{0x1002, 0x5245, 0x0, "ATI Rage 128 RE"},
+	{0x1002, 0x5246, 0x0, "ATI Rage 128 RF"},
+	{0x1002, 0x5247, 0x0, "ATI Rage 128 RG"},
+	{0x1002, 0x524b, 0x0, "ATI Rage 128 RK"},
+	{0x1002, 0x524c, 0x0, "ATI Rage 128 RL"},
+	{0x1002, 0x5345, 0x0, "ATI Rage 128 SE"},
+	{0x1002, 0x5346, 0x0, "ATI Rage 128 SF"},
+	{0x1002, 0x5347, 0x0, "ATI Rage 128 SG"},
+	{0x1002, 0x5348, 0x0, "ATI Rage 128 SH"},
+	{0x1002, 0x534b, 0x0, "ATI Rage 128 SK"},
+	{0x1002, 0x534c, 0x0, "ATI Rage 128 SL"},
+	{0x1002, 0x534d, 0x0, "ATI Rage 128 SM"},
+	{0x1002, 0x534e, 0x0, "ATI Rage 128 SN"},
+	{0x1002, 0x5446, 0x0, "ATI Rage 128 TF"},
+	{0x1002, 0x544c, 0x0, "ATI Rage 128 TL"},
+	{0x1002, 0x5452, 0x0, "ATI Rage 128 TR"},
+	{0x1002, 0x5453, 0x0, "ATI Rage 128 TS"},
+	{0x1002, 0x5454, 0x0, "ATI Rage 128 TT"},
+	{0x1002, 0x5455, 0x0, "ATI Rage 128 TU"},
+	{0x1002, 0x5834, 0x5, "ATI Radeon RS300"},
+	{0x1002, 0x5835, 0x5, "ATI Radeon RS300 Mobility"},
+	{0x1002, 0x5941, 0x3, "ATI Radeon RV280 (9200)"},
+	{0x1002, 0x5961, 0x3, "ATI Radeon RV280 (9200 SE)"},
+	{0x1002, 0x5964, 0x3, "ATI Radeon RV280 (9200 SE)"},
+	{0x1002, 0x5c60, 0x3, "ATI Radeon RV280"},
+	{0x1002, 0x5c61, 0x3, "ATI Radeon RV280 Mobility"},
+	{0x1002, 0x5c62, 0x3, "ATI Radeon RV280"},
+	{0x1002, 0x5c63, 0x3, "ATI Radeon RV280 Mobility"},
+	{0x1002, 0x5c64, 0x3, "ATI Radeon RV280"},
+	{0, 0, 0, NULL}
 };
 
-struct pci_id_list r128_id_list[] = {
-	{0x1002, 0x4c45, "ATI Rage 128 LE"},
-	{0x1002, 0x4c46, "ATI Rage 128 LF"},
-	{0x1002, 0x4d46, "ATI Rage 128 MF"},
-	{0x1002, 0x4d46, "ATI Rage 128 ML"},
-	{0x1002, 0x5041, "ATI Rage 128 PA"},
-	{0x1002, 0x5042, "ATI Rage 128 PB"},
-	{0x1002, 0x5043, "ATI Rage 128 PC"},
-	{0x1002, 0x5044, "ATI Rage 128 PD"},
-	{0x1002, 0x5045, "ATI Rage 128 PE"},
-	{0x1002, 0x5046, "ATI Rage 128 PF"},
-	{0x1002, 0x5047, "ATI Rage 128 PG"},
-	{0x1002, 0x5048, "ATI Rage 128 PH"},
-	{0x1002, 0x5049, "ATI Rage 128 PI"},
-	{0x1002, 0x504a, "ATI Rage 128 PJ"},
-	{0x1002, 0x504b, "ATI Rage 128 PK"},
-	{0x1002, 0x504c, "ATI Rage 128 PL"},
-	{0x1002, 0x504d, "ATI Rage 128 PM"},
-	{0x1002, 0x504e, "ATI Rage 128 PN"},
-	{0x1002, 0x504f, "ATI Rage 128 PO"},
-	{0x1002, 0x5050, "ATI Rage 128 PP"},
-	{0x1002, 0x5051, "ATI Rage 128 PQ"},
-	{0x1002, 0x5052, "ATI Rage 128 PR"},
-	{0x1002, 0x5053, "ATI Rage 128 PS"},
-	{0x1002, 0x5054, "ATI Rage 128 PT"},
-	{0x1002, 0x5055, "ATI Rage 128 PU"},
-	{0x1002, 0x5056, "ATI Rage 128 PV"},
-	{0x1002, 0x5057, "ATI Rage 128 PW"},
-	{0x1002, 0x5058, "ATI Rage 128 PX"},
-	{0x1002, 0x5245, "ATI Rage 128 RE"},
-	{0x1002, 0x5246, "ATI Rage 128 RF"},
-	{0x1002, 0x5247, "ATI Rage 128 RG"},
-	{0x1002, 0x524b, "ATI Rage 128 RK"},
-	{0x1002, 0x524c, "ATI Rage 128 RL"},
-	{0x1002, 0x5345, "ATI Rage 128 SE"},
-	{0x1002, 0x5346, "ATI Rage 128 SF"},
-	{0x1002, 0x5347, "ATI Rage 128 SG"},
-	{0x1002, 0x5348, "ATI Rage 128 SH"},
-	{0x1002, 0x534b, "ATI Rage 128 SK"},
-	{0x1002, 0x534c, "ATI Rage 128 SL"},
-	{0x1002, 0x534d, "ATI Rage 128 SM"},
-	{0x1002, 0x534e, "ATI Rage 128 SN"},
-	{0x1002, 0x5446, "ATI Rage 128 TF"},
-	{0x1002, 0x544c, "ATI Rage 128 TL"},
-	{0x1002, 0x5452, "ATI Rage 128 TR"},
-	{0x1002, 0x5453, "ATI Rage 128 TS"},
-	{0x1002, 0x5454, "ATI Rage 128 TT"},
-	{0x1002, 0x5455, "ATI Rage 128 TU"},
-	{0, 0, NULL}
-};
+static char *
+make_busid(KdCardAttr *attr)
+{
+	char *busid;
+	
+	busid = xalloc(20);
+	if (busid == NULL)
+		return NULL;
+	snprintf(busid, 20, "pci:%04x:%02x:%02x.%d", attr->domain, attr->bus, 
+	    attr->slot, attr->func);
+	return busid;
+}
 
 static Bool
 ATICardInit(KdCardInfo *card)
@@ -205,11 +215,28 @@
 		return FALSE;
 	}
 
+	atic->busid = make_busid(&card->attr);
+	if (atic->busid == NULL)
+		return FALSE;
+
+#ifdef USE_DRI
+	/* We demand identification by busid, not driver name */
+	atic->drmFd = drmOpen(NULL, atic->busid);
+	if (atic->drmFd < 0)
+		ErrorF("Failed to open DRM.  DMA won't be used.\n");
+#endif /* USE_DRI */
+
 	card->driver = atic;
 
-	for (i = 0; radeon_id_list[i].name != NULL; i++) {
-		if (radeon_id_list[i].device == card->attr.deviceID)
-			atic->is_radeon = TRUE;
+	for (i = 0; ati_pci_ids[i].name != NULL; i++) {
+		struct pci_id_entry *id = &ati_pci_ids[i];
+		if (id->device == card->attr.deviceID) {
+			if (id->caps & CAP_RADEON) {
+				if (id->caps & CAP_R200)
+					atic->is_r200 = TRUE;
+				atic->is_radeon = TRUE;
+			}
+		}
 	}
 	return TRUE;
 }
@@ -227,15 +254,14 @@
 ATIScreenInit(KdScreenInfo *screen)
 {
 	ATIScreenInfo *atis;
-	ATICardInfo *atic = screen->card->driver;
+	ATICardInfo(screen);
 	int success = FALSE;
 
 	atis = xcalloc(sizeof(ATIScreenInfo), 1);
 	if (atis == NULL)
 		return FALSE;
 
-	if (screen->fb[0].depth == 0)
-		screen->fb[0].depth = 16;
+	atis->atic = atic;
 
 	screen->driver = atis;
 

Index: ati.h
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/ati/ati.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ati.h	1 Dec 2003 04:33:33 -0000	1.3
+++ ati.h	29 Dec 2003 06:24:01 -0000	1.4
@@ -35,8 +35,14 @@
 #include <vesa.h>
 #endif
 
+#ifdef XF86DRI
+#define USE_DRI
+#include "libdrm.h"
+#include "dri.h"
+#endif
+
 #define RADEON_REG_BASE(c)		((c)->attr.address[1])
-#define RADEON_REG_SIZE(c)		(0x10000)
+#define RADEON_REG_SIZE(c)		(0x4000)
 
 #ifdef __powerpc__
 
@@ -75,9 +81,14 @@
 typedef volatile CARD16	VOL16;
 typedef volatile CARD32	VOL32;
 
-struct pci_id_list {
+#define CAP_RADEON	0x1	/* Whether it's a Radeon vs R128 */
+#define CAP_R200	0x2	/* If CAP_RADEON, whether it's an R200 */
+#define CAP_NODRM	0x4	/* Set if no initialization for the DRM yet. */
+
+struct pci_id_entry {
 	CARD16 vendor;
 	CARD16 device;
+	CARD8 caps;
 	char *name;
 };
 
@@ -107,8 +118,14 @@
 	} backend_priv;
 	struct backend_funcs backend_funcs;
 
+	struct pci_id_entry *pci_id;
 	CARD8 *reg_base;
 	Bool is_radeon;
+	Bool is_r200;
+	char *busid;
+#ifdef USE_DRI
+	int drmFd;
+#endif /* USE_DRI */
 	Bool use_fbdev, use_vesa;
 } ATICardInfo;
 
@@ -124,9 +141,89 @@
 		VesaScreenPrivRec vesa;
 #endif
 	} backend_priv;
+	KaaScreenInfoRec kaa;
+	ATICardInfo *atic;
 
-	int datatype;
-	int dp_gui_master_cntl;
+	Bool using_dri;
+	Bool using_dma;
+
+#ifdef USE_DRI
+	drmSize         registerSize;
+	drmHandle       registerHandle;
+	drmHandle       fbHandle;
+
+	int		IsAGP;
+	drmSize		gartSize;
+	drmHandle	agpMemHandle;		/* Handle from drmAgpAlloc */
+	unsigned long	gartOffset;
+	unsigned char	*AGP;			/* Map */
+	int		agpMode;
+	drmSize         pciSize;
+	drmHandle       pciMemHandle;
+
+	/* ring buffer data */
+	unsigned long	ringStart;		/* Offset into AGP space */
+	drmHandle	ringHandle;		/* Handle from drmAddMap */
+	drmSize		ringMapSize;		/* Size of map */
+	int		ringSize;		/* Size of ring (MB) */
+	unsigned char	*ring;			/* Map */
+
+	unsigned long	ringReadOffset;		/* Offset into AGP space */
+	drmHandle	ringReadPtrHandle;	/* Handle from drmAddMap */
+	drmSize		ringReadMapSize;	/* Size of map */
+	unsigned char	*ringReadPtr;		/* Map */
+
+	/* vertex/indirect buffer data */
+	unsigned long	bufStart;		/* Offset into AGP space */
+	drmHandle	bufHandle;		/* Handle from drmAddMap */
+	drmSize		bufMapSize;		/* Size of map */
+	int		bufSize;		/* Size of buffers (MB) */
+	unsigned char	*buf;			/* Map */
+	int		bufNumBufs;		/* Number of buffers */
+	drmBufMapPtr	buffers;		/* Buffer map */
+	
+	/* AGP Texture data */
+	unsigned long	gartTexStart;		/* Offset into AGP space */
+	drmHandle	gartTexHandle;		/* Handle from drmAddMap */
+	drmSize		gartTexMapSize;		/* Size of map */
+	int		gartTexSize;		/* Size of AGP tex space (MB) */
+	unsigned char	*gartTex;		/* Map */
+	int		log2GARTTexGran;
+
+	int		CCEMode;          /* CCE mode that server/clients use */
+	int		CPMode;           /* CP mode that server/clients use */
+	int		CCEFifoSize;      /* Size of the CCE command FIFO */
+	int		DMAusecTimeout;   /* CCE timeout in usecs */
+
+	/* DMA 2D accleration */
+	drmBufPtr	indirectBuffer;
+	int		indirectStart;
+
+	/* DRI screen private data */
+	int		fbX;
+	int		fbY;
+	int		backX;
+	int		backY;
+	int		depthX;
+	int		depthY;
+	
+	int		frontOffset;
+	int		frontPitch;
+	int		backOffset;
+	int		backPitch;
+	int		depthOffset;
+	int		depthPitch;
+	int		spanOffset;
+	int		textureOffset;
+	int		textureSize;
+	int		log2TexGran;
+
+	int		irqEnabled;
+
+	int		serverContext;
+
+	DRIInfoPtr	pDRIInfo;
+#endif /* USE_DRI */
 } ATIScreenInfo;
 
 #define getATIScreenInfo(kd)	((ATIScreenInfo *) ((kd)->screen->driver))
@@ -156,6 +253,14 @@
 void
 ATIDrawFini(ScreenPtr pScreen);
 
+#ifdef USE_DRI
+Bool
+ATIDRIScreenInit(ScreenPtr pScreen);
+
+void
+ATIDRICloseScreen(ScreenPtr pScreen);
+#endif /* USE_DRI */
+
 extern KdCardFuncs ATIFuncs;
 
 #endif /* _ATI_H_ */

Index: ati_draw.c
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/ati/ati_draw.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- ati_draw.c	1 Dec 2003 01:46:38 -0000	1.5
+++ ati_draw.c	29 Dec 2003 06:24:01 -0000	1.6
@@ -28,6 +28,12 @@
 #endif
 #include "ati.h"
 #include "ati_reg.h"
+#include "ati_draw.h"
+#ifdef USE_DRI
+#include "radeon_common.h"
+#include "r128_common.h"
+#include "ati_sarea.h"
+#endif /* USE_DRI */
 
 CARD8 ATISolidRop[16] = {
     /* GXclear      */      0x00,         /* 0 */
@@ -67,24 +73,57 @@
     /* GXset        */      0xff,         /* 1 */
 };
 
+static CARD32 R128BlendOp[] = {
+	/* Clear */
+	R128_ALPHA_BLEND_SRC_ZERO	 | R128_ALPHA_BLEND_DST_ZERO,
+	/* Src */
+	R128_ALPHA_BLEND_SRC_ONE	 | R128_ALPHA_BLEND_DST_ZERO,
+	/* Dst */
+	R128_ALPHA_BLEND_SRC_ZERO	 | R128_ALPHA_BLEND_DST_ONE,
+	/* Over */
+	R128_ALPHA_BLEND_SRC_ONE	 | R128_ALPHA_BLEND_DST_INVSRCALPHA,
+	/* OverReverse */
+	R128_ALPHA_BLEND_SRC_INVDSTALPHA | R128_ALPHA_BLEND_DST_ONE,
+	/* In */
+	R128_ALPHA_BLEND_SRC_DSTALPHA	 | R128_ALPHA_BLEND_DST_ZERO,
+	/* InReverse */
+	R128_ALPHA_BLEND_SRC_ZERO	 | R128_ALPHA_BLEND_DST_SRCALPHA,
+	/* Out */
+	R128_ALPHA_BLEND_SRC_INVDSTALPHA | R128_ALPHA_BLEND_DST_ZERO,
+	/* OutReverse */
+	R128_ALPHA_BLEND_SRC_ZERO	 | R128_ALPHA_BLEND_DST_INVSRCALPHA,
+	/* Atop */
+	R128_ALPHA_BLEND_SRC_DSTALPHA	 | R128_ALPHA_BLEND_DST_INVSRCALPHA,
+	/* AtopReverse */
+	R128_ALPHA_BLEND_SRC_INVDSTALPHA | R128_ALPHA_BLEND_DST_SRCALPHA,
+	/* Xor */
+	R128_ALPHA_BLEND_SRC_INVDSTALPHA | R128_ALPHA_BLEND_DST_INVSRCALPHA,
+	/* Add */
+	R128_ALPHA_BLEND_SRC_ONE	 | R128_ALPHA_BLEND_DST_ONE,
+};
+
 int copydx, copydy;
-Bool is_radeon;
+int fifo_size;
+ATIScreenInfo *accel_atis;
+int src_pitch;
+int src_offset;
+int src_bpp;
 /* If is_24bpp is set, then we are using the accelerator in 8-bit mode due
  * to it being broken for 24bpp, so coordinates have to be multiplied by 3.
  */
-Bool is_24bpp;
-int fifo_size;
-char *mmio;
-CARD32 bltCmd;
+int is_24bpp;
 
 static void
-ATIWaitAvail(int n)
+ATIWaitAvailMMIO(int n)
 {
+	ATICardInfo *atic = accel_atis->atic;
+	char *mmio = atic->reg_base;
+
 	if (fifo_size >= n) {
 		fifo_size -= n;
 		return;
 	}
-	if (is_radeon) {
+	if (atic->is_radeon) {
 		do {
 			fifo_size = MMIO_IN32(mmio, RADEON_REG_RBBM_STATUS) &
 			    RADEON_RBBM_FIFOCNT_MASK;
@@ -100,9 +139,25 @@
 static void
 RadeonWaitIdle(void)
 {
+	ATIScreenInfo *atis = accel_atis;
+	ATICardInfo *atic = atis->atic;
+	char *mmio = atic->reg_base;
 	CARD32 temp;
+
+#ifdef USE_DRI
+	if (atis->using_dma) {
+		int ret;
+
+		do {
+			ret = drmCommandNone(atic->drmFd, DRM_RADEON_CP_IDLE);
+		} while (ret == -EBUSY);
+		if (ret != 0)
+			ErrorF("Failed to idle DMA, returned %d\n", ret);
+	}
+#endif /* USE_DRI */
+
 	/* Wait for the engine to go idle */
-	ATIWaitAvail(64);
+	ATIWaitAvailMMIO(64);
 
 	while ((MMIO_IN32(mmio, RADEON_REG_RBBM_STATUS) &
 	    RADEON_RBBM_ACTIVE) != 0)
@@ -121,10 +176,25 @@
 static void
 R128WaitIdle(void)
 {
+	ATIScreenInfo *atis = accel_atis;
+	ATICardInfo *atic = atis->atic;
+	char *mmio = atic->reg_base;
 	CARD32 temp;
 	int tries;
 
-	ATIWaitAvail(64);
+#ifdef USE_DRI
+	if (atis->using_dma) {
+		int ret;
+
+		do {
+			ret = drmCommandNone(atic->drmFd, DRM_R128_CCE_IDLE);
+		} while (ret == -EBUSY);
+		if (ret != 0)
+			ErrorF("Failed to idle DMA, returned %d\n", ret);
+	}
+#endif /* USE_DRI */
+
+	ATIWaitAvailMMIO(64);
 
 	tries = 1000000;
 	while (tries--) {
@@ -146,170 +216,199 @@
 static void
 ATIWaitIdle(void)
 {
-	if (is_radeon)
+	ATIScreenInfo *atis = accel_atis;
+	ATICardInfo *atic = atis->atic;
+
+#ifdef USE_DRI
+	/* Dispatch any accumulated commands first. */
+	if (atis->using_dma && atis->indirectBuffer != NULL)
+		ATIDMAFlushIndirect(0);
+#endif /* USE_DRI */
+
+	if (atic->is_radeon)
 		RadeonWaitIdle();
 	else
 		R128WaitIdle();
 }
 
-static Bool
-ATISetup(PixmapPtr pDst, PixmapPtr pSrc)
+#ifdef USE_DRI
+void ATIDMAStart(ScreenPtr pScreen)
 {
-	KdScreenPriv(pDst->drawable.pScreen);
+	KdScreenPriv(pScreen);
 	ATICardInfo(pScreenPriv);
-	int dst_offset, dst_pitch, src_offset = 0, src_pitch = 0;
-	int bpp = pScreenPriv->screen->fb[0].bitsPerPixel;
-
-	mmio = atic->reg_base;
-
-	/* No acceleration for other formats (yet) */
-	if (pDst->drawable.bitsPerPixel != bpp)
-		return FALSE;
-
-	dst_pitch = pDst->devKind;
-	dst_offset = ((CARD8 *)pDst->devPrivate.ptr -
-	    pScreenPriv->screen->memory_base);
-	if (pSrc != NULL) {
-		src_pitch = pSrc->devKind;
-		src_offset = ((CARD8 *)pSrc->devPrivate.ptr -
-		    pScreenPriv->screen->memory_base);
-	}
+	ATIScreenInfo(pScreenPriv);
+	int ret;
 
-	ATIWaitAvail((pSrc != NULL) ? 3 : 2);
-	if (is_radeon) {
-		MMIO_OUT32(mmio, RADEON_REG_DST_PITCH_OFFSET,
-		    ((dst_pitch >> 6) << 22) | (dst_offset >> 10));
-		if (pSrc != NULL) {
-			MMIO_OUT32(mmio, RADEON_REG_SRC_PITCH_OFFSET,
-			    ((src_pitch >> 6) << 22) | (src_offset >> 10));
-		}
-	} else {
-		if (is_24bpp) {
-			dst_pitch *= 3;
-			src_pitch *= 3;
-		}
-		/* R128 pitch is in units of 8 pixels, offset in 32 bytes */
-		MMIO_OUT32(mmio, RADEON_REG_DST_PITCH_OFFSET,
-		    ((dst_pitch/bpp) << 21) | (dst_offset >> 5));
-		if (pSrc != NULL) {
-			MMIO_OUT32(mmio, RADEON_REG_SRC_PITCH_OFFSET,
-			    ((src_pitch/bpp) << 21) | (src_offset >> 5));
-		}
-	}
-	MMIO_OUT32(mmio, RADEON_REG_DEFAULT_SC_BOTTOM_RIGHT,
-	    (RADEON_DEFAULT_SC_RIGHT_MAX | RADEON_DEFAULT_SC_BOTTOM_MAX));
+	if (atic->is_radeon)
+		ret = drmCommandNone(atic->drmFd, DRM_RADEON_CP_START);
+	else
+		ret = drmCommandNone(atic->drmFd, DRM_R128_CCE_START);
 
-	return TRUE;
+	if (ret == 0)
+		atis->using_dma = TRUE;
+	else
+		ErrorF("%s: DMA start returned %d\n", __FUNCTION__, ret);
 }
 
-static Bool
-ATIPrepareSolid(PixmapPtr pPixmap, int alu, Pixel pm, Pixel fg)
+/* Attempts to idle the DMA engine, and stops it.  Note that the ioctl is the
+ * same for both R128 and Radeon, so we can just use the name of one of them.
+ */
+void ATIDMAStop(ScreenPtr pScreen)
 {
-	KdScreenPriv(pPixmap->drawable.pScreen);
+	KdScreenPriv(pScreen);
+	ATICardInfo(pScreenPriv);
 	ATIScreenInfo(pScreenPriv);
+	drmRadeonCPStop stop;
+	int ret;
 
-	if (is_24bpp) {
-		if (pm != 0xffffffff)
-			return FALSE;
-		/* Solid fills in fake-24bpp mode only work if the pixel color
-		 * is all the same byte.
-		 */
-		if ((fg & 0xffffff) != (((fg & 0xff) << 16) | ((fg >> 8) &
-		    0xffff)))
-			return FALSE;
-	}
-
-	if (!ATISetup(pPixmap, NULL))
-		return FALSE;
+	stop.flush = 1;
+	stop.idle  = 1;
+	ret = drmCommandWrite(atic->drmFd, DRM_RADEON_CP_STOP, &stop, 
+	    sizeof(drmRadeonCPStop));
 
-	ATIWaitAvail(4);
-	MMIO_OUT32(mmio, RADEON_REG_DP_GUI_MASTER_CNTL,
-	    atis->dp_gui_master_cntl |
-	    RADEON_GMC_BRUSH_SOLID_COLOR |
-	    RADEON_GMC_DST_PITCH_OFFSET_CNTL |
-	    RADEON_GMC_SRC_DATATYPE_COLOR |
-	    (ATISolidRop[alu] << 16));
-	MMIO_OUT32(mmio, RADEON_REG_DP_BRUSH_FRGD_CLR, fg);
-	MMIO_OUT32(mmio, RADEON_REG_DP_WRITE_MASK, pm);
-	MMIO_OUT32(mmio, RADEON_REG_DP_CNTL, RADEON_DST_X_LEFT_TO_RIGHT |
-	    RADEON_DST_Y_TOP_TO_BOTTOM);
+	if (ret != 0 && errno == EBUSY) {
+		ErrorF("Failed to idle the DMA engine\n");
 
-	return TRUE;
+		stop.idle = 0;
+		ret = drmCommandWrite(atic->drmFd, DRM_RADEON_CP_STOP, &stop,
+		    sizeof(drmRadeonCPStop));
+	}
+	atis->using_dma = FALSE;
 }
 
-static void
-ATISolid(int x1, int y1, int x2, int y2)
+/* The R128 and Radeon Indirect ioctls differ only in the ioctl number */
+void ATIDMADispatchIndirect(Bool discard)
 {
-	if (is_24bpp) {
-		x1 *= 3;
-		x2 *= 3;
-	}
-	ATIWaitAvail(2);
-	MMIO_OUT32(mmio, RADEON_REG_DST_Y_X, (y1 << 16) | x1);
-	MMIO_OUT32(mmio, RADEON_REG_DST_WIDTH_HEIGHT, ((x2 - x1) << 16) |
-	    (y2 - y1));
+	ATIScreenInfo *atis = accel_atis;
+	ATICardInfo *atic = atis->atic;
+	drmBufPtr buffer = atis->indirectBuffer;
+	drmR128Indirect indirect;
+	int cmd;
+
+	indirect.idx = buffer->idx;
+	indirect.start = atis->indirectStart;
+	indirect.end = buffer->used;
+	indirect.discard = discard;
+	cmd = atic->is_radeon ? DRM_RADEON_INDIRECT : DRM_R128_INDIRECT;
+	drmCommandWriteRead(atic->drmFd, cmd, &indirect,
+	    sizeof(drmR128Indirect));
 }
 
-static void
-ATIDoneSolid(void)
+/* Flush the indirect buffer to the kernel for submission to the card */
+void ATIDMAFlushIndirect(Bool discard)
 {
+	ATIScreenInfo *atis = accel_atis;
+	drmBufPtr buffer = atis->indirectBuffer;
+
+	if (buffer == NULL)
+		return;
+	if ((atis->indirectStart == buffer->used) && !discard)
+		return;
+
+	ATIDMADispatchIndirect(discard);
+
+	if (discard) {
+		atis->indirectBuffer = ATIDMAGetBuffer();
+		atis->indirectStart = 0;
+	} else {
+		/* Start on a double word boundary */
+		atis->indirectStart = buffer->used = (buffer->used + 7) & ~7;
+	}
 }
 
-static Bool
-ATIPrepareCopy(PixmapPtr pSrc, PixmapPtr pDst, int dx, int dy, int alu, Pixel pm)
+/* Get an indirect buffer for the DMA 2D acceleration commands  */
+drmBufPtr ATIDMAGetBuffer()
 {
-	KdScreenPriv(pDst->drawable.pScreen);
-	ATIScreenInfo(pScreenPriv);
+	ATIScreenInfo *atis = accel_atis;
+	ATICardInfo *atic = atis->atic;
+	drmDMAReq dma;
+	drmBufPtr buf = NULL;
+	int indx = 0;
+	int size = 0;
+	int ret;
 
-	copydx = dx;
-	copydy = dy;
+	dma.context = atis->serverContext;
+	dma.send_count = 0;
+	dma.send_list = NULL;
+	dma.send_sizes = NULL;
+	dma.flags = 0;
+	dma.request_count = 1;
+	if (atis->atic->is_radeon)
+		dma.request_size = RADEON_BUFFER_SIZE;
+	else
+		dma.request_size = R128_BUFFER_SIZE;
+	dma.request_list = &indx;
+	dma.request_sizes = &size;
+	dma.granted_count = 0;
 
-	if (is_24bpp && pm != 0xffffffff)
-		return FALSE;
+	do {
+		ret = drmDMA(atic->drmFd, &dma);
+	} while (ret != 0);
 
-	if (!ATISetup(pDst, pSrc))
-		return FALSE;
+	buf = &atis->buffers->list[indx];
+	buf->used = 0;
+	return buf;
+}
+#endif /* USE_DRI */
 
-	ATIWaitAvail(3);
-	MMIO_OUT32(mmio, RADEON_REG_DP_GUI_MASTER_CNTL,
-	    atis->dp_gui_master_cntl |
-	    RADEON_GMC_BRUSH_SOLID_COLOR |
-	    RADEON_GMC_SRC_DATATYPE_COLOR |
-	    (ATIBltRop[alu] << 16) |
-	    RADEON_GMC_SRC_PITCH_OFFSET_CNTL |
-	    RADEON_GMC_DST_PITCH_OFFSET_CNTL |
-	    RADEON_DP_SRC_SOURCE_MEMORY);
-	MMIO_OUT32(mmio, RADEON_REG_DP_WRITE_MASK, pm);
-	MMIO_OUT32(mmio, RADEON_REG_DP_CNTL, 
-	    (dx >= 0 ? RADEON_DST_X_LEFT_TO_RIGHT : 0) |
-	    (dy >= 0 ? RADEON_DST_Y_TOP_TO_BOTTOM : 0));
+static Bool
+R128GetDatatypePict(CARD32 format, CARD32 *type)
+{
+	switch (format) {
+	case PICT_a8r8g8b8:
+		*type = R128_DATATYPE_ARGB_8888;
+		return TRUE;
+	case PICT_r5g6b5:
+		*type = R128_DATATYPE_RGB_565;
+		return TRUE;
+	}
 
-	return TRUE;
+	ErrorF ("Unsupported format: %x\n", format);
+
+	return FALSE;
 }
 
-static void
-ATICopy(int srcX, int srcY, int dstX, int dstY, int w, int h)
+/* Assumes that depth 15 and 16 can be used as depth 16, which is okay since we
+ * require src and dest datatypes to be equal.
+ */
+static Bool
+ATIGetDatatypeBpp(int bpp, CARD32 *type)
 {
-	if (is_24bpp) {
-		srcX *= 3;
-		dstX *= 3;
-		w *= 3;
-	}
+	is_24bpp = FALSE;
 
-	if (copydx < 0) {
-		srcX += w - 1;
-		dstX += w - 1;
+	switch (bpp) {
+	case 8:
+		*type = R128_DATATYPE_C8;
+		return TRUE;
+	case 16:
+		*type = R128_DATATYPE_RGB_565;
+		return TRUE;
+	case 24:
+		*type = R128_DATATYPE_C8;
+		is_24bpp = TRUE;
+		return TRUE;
+	case 32:
+		*type = R128_DATATYPE_ARGB_8888;
+		return TRUE;
+	default:
+		ErrorF("Unsupported bpp: %x\n", bpp);
+		return FALSE;
 	}
+}
 
-	if (copydy < 0)  {
-		srcY += h - 1;
-		dstY += h - 1;
-	}
+#ifdef USE_DRI
+#define USE_DMA
+#include "ati_drawtmp.h"
+#include "r128_blendtmp.h"
+#endif /* USE_DRI */
 
-	ATIWaitAvail(3);
-	MMIO_OUT32(mmio, RADEON_REG_SRC_Y_X, (srcY << 16) | srcX);
-	MMIO_OUT32(mmio, RADEON_REG_DST_Y_X, (dstY << 16) | dstX);
-	MMIO_OUT32(mmio, RADEON_REG_DST_HEIGHT_WIDTH, (h << 16) | w);
+#undef USE_DMA
+#include "ati_drawtmp.h"
+#include "r128_blendtmp.h"
+
+static void
+ATIDoneSolid(void)
+{
 }
 
 static void
@@ -317,20 +416,6 @@
 {
 }
 
-static KaaScreenInfoRec ATIKaa = {
-	ATIPrepareSolid,
-	ATISolid,
-	ATIDoneSolid,
-
-	ATIPrepareCopy,
-	ATICopy,
-	ATIDoneCopy,
-
-	0,				/* offscreenByteAlign */
-	0,				/* offscreenPitch */
-	KAA_OFFSCREEN_PIXMAPS,		/* flags */
-};
-
 Bool
 ATIDrawInit(ScreenPtr pScreen)
 {
@@ -338,50 +423,57 @@
 	ATIScreenInfo(pScreenPriv);
 	ATICardInfo(pScreenPriv);
 
-	is_radeon = atic->is_radeon;
-	is_24bpp = FALSE;
+	ErrorF("Screen: %d/%d depth/bpp\n", pScreenPriv->screen->fb[0].depth,
+	    pScreenPriv->screen->fb[0].bitsPerPixel);
+#ifdef USE_DRI
+	if (atis->using_dri)
+		ATIDMAStart(pScreen);
+	else {
+		if (ATIDRIScreenInit(pScreen))
+			atis->using_dri = TRUE;
+	}
+#endif /* USE_DRI */
 
-	switch (pScreenPriv->screen->fb[0].depth)
+	memset(&atis->kaa, 0, sizeof(KaaScreenInfoRec));
+#ifdef USE_DRI
+	if (atis->using_dma) {
+		atis->kaa.PrepareSolid = ATIPrepareSolidDMA;
+		atis->kaa.Solid = ATISolidDMA;
+		atis->kaa.PrepareCopy = ATIPrepareCopyDMA;
+		atis->kaa.Copy = ATICopyDMA;
+		if (!atic->is_radeon) {
+			atis->kaa.PrepareBlend = R128PrepareBlendDMA;
+			atis->kaa.Blend = R128BlendDMA;
+			atis->kaa.DoneBlend = R128DoneBlendDMA;
+		}
+	} else {
+#else
 	{
-	case 8:
-		atis->datatype = 2;
-		break;
-	case 15:
-		atis->datatype = 3;
-		break;
-	case 16:
-		atis->datatype = 4;
-		break;
-	case 24:
-		if (pScreenPriv->screen->fb[0].bitsPerPixel == 24) {
-			is_24bpp = TRUE;
-			atis->datatype = 2;
-		} else {
-			atis->datatype = 6;
+#endif /* USE_DRI */
+		atis->kaa.PrepareSolid = ATIPrepareSolidMMIO;
+		atis->kaa.Solid = ATISolidMMIO;
+		atis->kaa.PrepareCopy = ATIPrepareCopyMMIO;
+		atis->kaa.Copy = ATICopyMMIO;
+		if (!atic->is_radeon) {
+			atis->kaa.PrepareBlend = R128PrepareBlendMMIO;
+			atis->kaa.Blend = R128BlendMMIO;
+			atis->kaa.DoneBlend = R128DoneBlendMMIO;
 		}
-		break;
-	default:
-		FatalError("[ati]: depth %d unsupported\n",
-		    pScreenPriv->screen->fb[0].depth);
-		return FALSE;
 	}
-
-	atis->dp_gui_master_cntl = (atis->datatype << 8) |
-	    RADEON_GMC_CLR_CMP_CNTL_DIS | RADEON_GMC_AUX_CLIP_DIS;
-
-	if (is_radeon) {
-		ATIKaa.offscreenByteAlign = 1024;
-		ATIKaa.offscreenPitch = 1024;
+	atis->kaa.DoneSolid = ATIDoneSolid;
+	atis->kaa.DoneCopy = ATIDoneCopy;
+	atis->kaa.flags = KAA_OFFSCREEN_PIXMAPS;
+	if (atic->is_radeon) {
+		atis->kaa.offscreenByteAlign = 1024;
+		atis->kaa.offscreenPitch = 1024;
 	} else {
-		ATIKaa.offscreenByteAlign = 8;
-		/* Workaround for corrupation at 8 and 24bpp. Why? */
-		if (atis->datatype == 2)
-			ATIKaa.offscreenPitch = 16;
-		else
-			ATIKaa.offscreenPitch =
-			    pScreenPriv->screen->fb[0].bitsPerPixel;
+		atis->kaa.offscreenByteAlign = 32;
+		/* Pitch alignment is in sets of 8 pixels, and we need to cover
+		 * 32bpp, so 32 bytes.
+		 */
+		atis->kaa.offscreenPitch = 32;
 	}
-	if (!kaaDrawInit(pScreen, &ATIKaa))
+	if (!kaaDrawInit(pScreen, &atis->kaa))
 		return FALSE;
 
 	return TRUE;
@@ -401,15 +493,27 @@
 void
 ATIDrawFini(ScreenPtr pScreen)
 {
+#ifdef USE_DRI
+	KdScreenPriv(pScreen);
+	ATIScreenInfo(pScreenPriv);
+
+	if (atis->using_dma)
+		ATIDMAStop(pScreen);
+
+	if (atis->using_dri)
+		ATIDRICloseScreen(pScreen);
+#endif /* USE_DRI */
+
+	kaaDrawFini(pScreen);
 }
 
 void
 ATIDrawSync(ScreenPtr pScreen)
 {
 	KdScreenPriv(pScreen);
-	ATICardInfo(pScreenPriv);
+	ATIScreenInfo(pScreenPriv);
 
-	mmio = atic->reg_base;
+	accel_atis = atis;
 
 	ATIWaitIdle();
 }

Index: ati_reg.h
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/ati/ati_reg.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- ati_reg.h	20 Nov 2003 07:49:45 -0000	1.2
+++ ati_reg.h	29 Dec 2003 06:24:01 -0000	1.3
@@ -24,29 +24,47 @@
 /* $Header$ */
 
 /* The Radeon register definitions are almost all the same for r128 */
+#define RADEON_REG_BUS_CNTL			0x0030
+# define RADEON_BUS_MASTER_DIS			(1 << 6)
+#define RADEON_GEN_INT_CNTL			0x0040
+#define RADEON_REG_AGP_BASE			0x0170
+#define RADEON_REG_AGP_CNTL			0x0174
+# define RADEON_AGP_APER_SIZE_256MB		(0x00 << 0)
+# define RADEON_AGP_APER_SIZE_128MB		(0x20 << 0)
+# define RADEON_AGP_APER_SIZE_64MB		(0x30 << 0)
+# define RADEON_AGP_APER_SIZE_32MB		(0x38 << 0)
+# define RADEON_AGP_APER_SIZE_16MB		(0x3c << 0)
+# define RADEON_AGP_APER_SIZE_8MB		(0x3e << 0)
+# define RADEON_AGP_APER_SIZE_4MB		(0x3f << 0)
+# define RADEON_AGP_APER_SIZE_MASK		(0x3f << 0)
 #define RADEON_REG_RBBM_STATUS			0x0e40
 # define RADEON_RBBM_FIFOCNT_MASK		0x007f
 # define RADEON_RBBM_ACTIVE			(1 << 31)
+#define RADEON_REG_CP_CSQ_CNTL			0x0740
+# define RADEON_CSQ_PRIBM_INDBM			(4    << 28)
 #define RADEON_REG_SRC_PITCH_OFFSET		0x1428
 #define RADEON_REG_DST_PITCH_OFFSET		0x142c
 #define RADEON_REG_SRC_Y_X			0x1434
 #define RADEON_REG_DST_Y_X			0x1438
 #define RADEON_REG_DST_HEIGHT_WIDTH		0x143c
 #define RADEON_REG_DP_GUI_MASTER_CNTL		0x146c
-#define RADEON_REG_DP_BRUSH_FRGD_CLR		0x147c
 # define RADEON_GMC_SRC_PITCH_OFFSET_CNTL	(1    <<  0)
 # define RADEON_GMC_DST_PITCH_OFFSET_CNTL	(1    <<  1)
 # define RADEON_GMC_BRUSH_SOLID_COLOR		(13   <<  4)
 # define RADEON_GMC_BRUSH_NONE			(15   <<  4)
 # define RADEON_GMC_SRC_DATATYPE_COLOR		(3    << 12)
 # define RADEON_DP_SRC_SOURCE_MEMORY		(2    << 24)
+# define RADEON_GMC_3D_FCN_EN			(1    << 27)
 # define RADEON_GMC_CLR_CMP_CNTL_DIS		(1    << 28)
 # define RADEON_GMC_AUX_CLIP_DIS		(1    << 29)
+#define RADEON_REG_DP_BRUSH_FRGD_CLR		0x147c
+#define RADEON_REG_DST_WIDTH_HEIGHT		0x1598
+#define RADEON_REG_CLR_CMP_CNTL			0x15c0
+#define RADEON_REG_AUX_SC_CNTL			0x1660
 #define RADEON_REG_DP_CNTL			0x16c0
 # define RADEON_DST_X_LEFT_TO_RIGHT		(1 <<  0)
 # define RADEON_DST_Y_TOP_TO_BOTTOM		(1 <<  1)
-#define RADEON_REG_DST_WIDTH_HEIGHT		0x1598
-#define RADEON_REG_AUX_SC_CNTL			0x1660
+#define RADEON_REG_DP_MIX			0x16c8
 #define RADEON_REG_DP_WRITE_MASK		0x16cc
 #define RADEON_REG_DEFAULT_OFFSET		0x16e0
 #define RADEON_REG_DEFAULT_PITCH		0x16e4
@@ -61,7 +79,121 @@
 # define RADEON_RB2D_DC_FLUSH_ALL		0xf
 # define RADEON_RB2D_DC_BUSY			(1 << 31)
 
+#define RADEON_CP_PACKET0			0x00000000
+#define RADEON_CP_PACKET1			0x40000000
+#define RADEON_CP_PACKET2			0x80000000
+
 #define R128_REG_PC_NGUI_CTLSTAT		0x0184
 # define R128_PC_BUSY				(1 << 31)
+#define R128_REG_PCI_GART_PAGE			0x017c
+#define R128_REG_PC_NGUI_CTLSTAT		0x0184
+#define R128_REG_BM_CHUNK_0_VAL			0x0a18
+# define R128_BM_PTR_FORCE_TO_PCI		(1 << 21)
+# define R128_BM_PM4_RD_FORCE_TO_PCI		(1 << 22)
+# define R128_BM_GLOBAL_FORCE_TO_PCI		(1 << 23)
 #define R128_REG_GUI_STAT			0x1740
 # define R128_GUI_ACTIVE			(1 << 31)
+
+#define R128_REG_TEX_CNTL			0x1800
+#define R128_REG_SCALE_SRC_HEIGHT_WIDTH		0x1994
+#define R128_REG_SCALE_OFFSET_0			0x1998
+#define R128_REG_SCALE_PITCH			0x199c
+#define R128_REG_SCALE_X_INC			0x19a0
+#define R128_REG_SCALE_Y_INC			0x19a4
+#define R128_REG_SCALE_HACC			0x19a8
+#define R128_REG_SCALE_VACC			0x19ac
+#define R128_REG_SCALE_DST_X_Y			0x19b0
+#define R128_REG_SCALE_DST_HEIGHT_WIDTH		0x19b4
+
+#define R128_REG_SCALE_3D_CNTL			0x1a00
+# define R128_SCALE_DITHER_ERR_DIFF		(0  <<  1)
+# define R128_SCALE_DITHER_TABLE		(1  <<  1)
+# define R128_TEX_CACHE_SIZE_FULL		(0  <<  2)
+# define R128_TEX_CACHE_SIZE_HALF		(1  <<  2)
+# define R128_DITHER_INIT_CURR			(0  <<  3)
+# define R128_DITHER_INIT_RESET			(1  <<  3)
+# define R128_ROUND_24BIT			(1  <<  4)
+# define R128_TEX_CACHE_DISABLE			(1  <<  5)
+# define R128_SCALE_3D_NOOP			(0  <<  6)
+# define R128_SCALE_3D_SCALE			(1  <<  6)
+# define R128_SCALE_3D_TEXMAP_SHADE		(2  <<  6)
+# define R128_SCALE_PIX_BLEND			(0  <<  8)
+# define R128_SCALE_PIX_REPLICATE		(1  <<  8)
+# define R128_TEX_CACHE_SPLIT			(1  <<  9)
+# define R128_APPLE_YUV_MODE			(1  << 10)
+# define R128_TEX_CACHE_PALLETE_MODE		(1  << 11)
+# define R128_ALPHA_COMB_ADD_CLAMP		(0  << 12)
+# define R128_ALPHA_COMB_ADD_NCLAMP		(1  << 12)
+# define R128_ALPHA_COMB_SUB_DST_SRC_CLAMP	(2  << 12)
+# define R128_ALPHA_COMB_SUB_DST_SRC_NCLAMP	(3  << 12)
+# define R128_FOG_TABLE				(1  << 14)
+# define R128_SIGNED_DST_CLAMP			(1  << 15)
+# define R128_ALPHA_BLEND_SRC_ZERO		(0  << 16)
+# define R128_ALPHA_BLEND_SRC_ONE		(1  << 16)
+# define R128_ALPHA_BLEND_SRC_SRCCOLOR		(2  << 16)
+# define R128_ALPHA_BLEND_SRC_INVSRCCOLOR	(3  << 16)
+# define R128_ALPHA_BLEND_SRC_SRCALPHA		(4  << 16)
+# define R128_ALPHA_BLEND_SRC_INVSRCALPHA	(5  << 16)
+# define R128_ALPHA_BLEND_SRC_DSTALPHA		(6  << 16)
+# define R128_ALPHA_BLEND_SRC_INVDSTALPHA	(7  << 16)
+# define R128_ALPHA_BLEND_SRC_DSTCOLOR		(8  << 16)
+# define R128_ALPHA_BLEND_SRC_INVDSTCOLOR	(9  << 16)
+# define R128_ALPHA_BLEND_SRC_SAT		(10 << 16)
+# define R128_ALPHA_BLEND_SRC_BLEND		(11 << 16)
+# define R128_ALPHA_BLEND_SRC_INVBLEND		(12 << 16)
+# define R128_ALPHA_BLEND_DST_ZERO		(0  << 20)
+# define R128_ALPHA_BLEND_DST_ONE		(1  << 20)
+# define R128_ALPHA_BLEND_DST_SRCCOLOR		(2  << 20)
+# define R128_ALPHA_BLEND_DST_INVSRCCOLOR	(3  << 20)
+# define R128_ALPHA_BLEND_DST_SRCALPHA		(4  << 20)
+# define R128_ALPHA_BLEND_DST_INVSRCALPHA	(5  << 20)
+# define R128_ALPHA_BLEND_DST_DSTALPHA		(6  << 20)
+# define R128_ALPHA_BLEND_DST_INVDSTALPHA	(7  << 20)
+# define R128_ALPHA_BLEND_DST_DSTCOLOR		(8  << 20)
+# define R128_ALPHA_BLEND_DST_INVDSTCOLOR	(9  << 20)
+# define R128_ALPHA_TEST_NEVER			(0  << 24)
+# define R128_ALPHA_TEST_LESS			(1  << 24)
+# define R128_ALPHA_TEST_LESSEQUAL		(2  << 24)
+# define R128_ALPHA_TEST_EQUAL			(3  << 24)
+# define R128_ALPHA_TEST_GREATEREQUAL		(4  << 24)
+# define R128_ALPHA_TEST_GREATER		(5  << 24)
+# define R128_ALPHA_TEST_NEQUAL			(6  << 24)
+# define R128_ALPHA_TEST_ALWAYS			(7  << 24)
+# define R128_COMPOSITE_SHADOW_CMP_EQUAL	(0  << 28)
+# define R128_COMPOSITE_SHADOW_CMP_NEQUAL	(1  << 28)
+# define R128_COMPOSITE_SHADOW			(1  << 29)
+# define R128_TEX_MAP_ALPHA_IN_TEXTURE		(1  << 30)
+# define R128_TEX_CACHE_LINE_SIZE_8QW		(0  << 31)
+# define R128_TEX_CACHE_LINE_SIZE_4QW		(1  << 31)
+
+#define R128_REG_SCALE_3D_DATATYPE		0x1a20
+
+#define R128_REG_TEX_CNTL_C			0x1c9c
+# define R128_TEX_ALPHA_EN			(1 << 9)
+# define R128_TEX_CACHE_FLUSH			(1 << 23)
+
+#define R128_REG_PRIM_TEX_CNTL_C		0x1cb0
+#define R128_REG_PRIM_TEXTURE_COMBINE_CNTL_C	0x1cb4
+
+#define R128_DATATYPE_C8			2
+#define R128_DATATYPE_ARGB_1555			3
+#define R128_DATATYPE_RGB_565			4
+#define R128_DATATYPE_ARGB_8888			6
+#define R128_DATATYPE_RGB_332			7
+#define R128_DATATYPE_Y8			8
+#define R128_DATATYPE_RGB_8			9
+#define R128_DATATYPE_VYUY_422			11
+#define R128_DATATYPE_YVYU_422			12
+#define R128_DATATYPE_AYUV_444			14
+#define R128_DATATYPE_ARGB_4444			15
+
+#define R128_PM4_NONPM4				(0  << 28)
+#define R128_PM4_192PIO				(1  << 28)
+#define R128_PM4_192BM				(2  << 28)
+#define R128_PM4_128PIO_64INDBM			(3  << 28)
+#define R128_PM4_128BM_64INDBM			(4  << 28)
+#define R128_PM4_64PIO_128INDBM			(5  << 28)
+#define R128_PM4_64BM_128INDBM			(6  << 28)
+#define R128_PM4_64PIO_64VCBM_64INDBM		(7  << 28)
+#define R128_PM4_64BM_64VCBM_64INDBM		(8  << 28)
+#define R128_PM4_64PIO_64VCPIO_64INDPIO		(15 << 28)

Index: ati_stub.c
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/ati/ati_stub.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- ati_stub.c	1 Dec 2003 04:33:33 -0000	1.2
+++ ati_stub.c	29 Dec 2003 06:24:01 -0000	1.3
@@ -29,30 +29,17 @@
 #include "ati.h"
 #include "klinux.h"
 
-extern struct pci_id_list radeon_id_list[];
-extern struct pci_id_list r128_id_list[];
+extern struct pci_id_entry ati_pci_ids[];
 
 void
 InitCard(char *name)
 {
+	struct pci_id_entry *id;
 	KdCardAttr attr;
-	int i, j;
-
-	for (i = 0; radeon_id_list[i].name != NULL; i++) {
-		CARD16 vendor = radeon_id_list[i].vendor;
-		CARD16 device = radeon_id_list[i].device;
 
-		j = 0;
-		while (LinuxFindPci(vendor, device, j++, &attr))
-			KdCardInfoAdd(&ATIFuncs, &attr, 0);
-	}
-
-	for (i = 0; r128_id_list[i].name != NULL; i++) {
-		CARD16 vendor = r128_id_list[i].vendor;
-		CARD16 device = r128_id_list[i].device;
-
-		j = 0;
-		while (LinuxFindPci(vendor, device, j++, &attr))
+	for (id = ati_pci_ids; id->name != NULL; id++) {
+		int j = 0;
+		while (LinuxFindPci(id->vendor, id->device, j++, &attr))
 			KdCardInfoAdd(&ATIFuncs, &attr, 0);
 	}
 }