PSARC 2004/801 DRI porting nv_52
authorDaniel Zhu <Daniel.Zhu@Sun.COM>
Tue, 24 Oct 2006 18:42:11 -0700
changeset 75 64e817c4a743
parent 74 42c181d8d7ed
child 76 077df25292e8
PSARC 2004/801 DRI porting 6418052 Direct Rendering Infrastructure (DRI) should be supported by Xorg
XORG_NV/packages/SUNWxorg-mesa/prototype
XORG_NV/sun-src/xc/config/cf/Imake.rules
XORG_NV/sun-src/xc/config/cf/host.def
XORG_NV/sun-src/xc/extras/Mesa/src/glx/x11/Makefile
XORG_NV/sun-src/xc/extras/Mesa/src/mesa/drivers/dri/Makefile.template
XORG_NV/sun-src/xc/extras/Mesa/src/mesa/drivers/dri/common/dri_util.h
XORG_NV/sun-src/xc/extras/Mesa/src/mesa/drivers/dri/i915/intel_context.h
XORG_NV/sun-src/xc/extras/Mesa/src/mesa/drivers/dri/i915/intel_screen.c
XORG_NV/sun-src/xc/extras/Mesa/src/mesa/drivers/dri/i915/intel_tris.c
XORG_NV/sun-src/xc/extras/Mesa/src/mesa/main/glheader.h
XORG_NV/sun-src/xc/extras/Mesa/src/mesa/tnl_dd/t_dd_tritmp.h
XORG_NV/sun-src/xc/extras/drm/libdrm/xf86drm.c
XORG_NV/sun-src/xc/extras/drm/libdrm/xf86drm.h
XORG_NV/sun-src/xc/extras/drm/shared-core/drm.h
XORG_NV/sun-src/xc/extras/drm/sunos-core/xf86drm-solaris.S
XORG_NV/sun-src/xc/lib/GL/mesa/drivers/dri/common/Imakefile.inc
XORG_NV/sun-src/xc/lib/GL/mesa/drivers/dri/i915/Imakefile
XORG_NV/sun-src/xc/programs/Xserver/hw/xfree86/drivers/i810/i830.h
XORG_NV/sun-src/xc/programs/Xserver/hw/xfree86/drivers/via/via_drmclient.h
XORG_NV/sun-src/xc/programs/Xserver/hw/xfree86/os-support/sunos/Imakefile
XORG_NV/sun-src/xc/programs/Xserver/hw/xfree86/os-support/sunos/agpgart.h
XORG_NV/sun-src/xc/programs/Xserver/hw/xfree86/os-support/sunos/drm/Imakefile
XORG_NV/sun-src/xc/programs/Xserver/hw/xfree86/os-support/sunos/drm/drmmodule.c
XORG_NV/sun-src/xc/programs/Xserver/hw/xfree86/xf86cfg/Imakefile
--- a/XORG_NV/packages/SUNWxorg-mesa/prototype	Tue Oct 24 16:13:31 2006 -0700
+++ b/XORG_NV/packages/SUNWxorg-mesa/prototype	Tue Oct 24 18:42:11 2006 -0700
@@ -29,7 +29,7 @@
 #
 ##########################################################################
 #
-# ident	"@(#)prototype	1.11	06/04/18 SMI"
+# ident	"@(#)prototype	1.12	06/10/25 SMI"
 #
 # Mesa - OpenGL Workalike for Solaris
 
@@ -148,8 +148,13 @@
 
 # X server-side components
 d none X11/lib/modules 0755 root bin
+d none X11/lib/modules/dri 0755 root bin
+!search $HOME/lib/modules/dri
+f none X11/lib/modules/dri/i915_dri.so 0755 root bin
 d none X11/lib/modules/extensions 0755 root bin
 !search $HOME/lib/modules/extensions
+f none X11/lib/modules/extensions/libdri.so 0755 root bin
+f none X11/lib/modules/extensions/libdrm.so 0755 root bin
 d none X11/lib/modules/extensions/mesa 0755 root bin
 f none X11/lib/modules/extensions/mesa/libGLcore.so 0755 root bin
 f none X11/lib/modules/extensions/mesa/libglx.so 0755 root bin
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/config/cf/Imake.rules	Tue Oct 24 18:42:11 2006 -0700
@@ -0,0 +1,3649 @@
+XCOMM ---------------------------------------------------------------------
+XCOMM Imake rules for building libraries, programs, scripts, and data files
+XCOMM rules:  $Xorg: Imake.rules,v 1.3 2000/08/17 19:41:46 cpqbld Exp $
+XCOMM rules:  $XdotOrg: xc/config/cf/Imake.rules,v 1.11 2005/11/08 06:33:24 jkj Exp $
+XCOMM
+XCOMM
+XCOMM
+XCOMM
+XCOMM rules:  $XFree86: xc/config/cf/Imake.rules,v 3.128 2003/11/15 03:25:17 dawes Exp $
+
+/*
+ *		   MACHINE-INDEPENDENT RULES; DO NOT MODIFY
+ *
+ * Warning, when defining rules: make sure you do not include both a trailing
+ * backslash and double ampersand backslash or else you will get an extra
+ * backslash in the Makefile.
+ *
+ * The following macros are defined for the various templates and Imakefiles
+ * (for a list of the applicable make variables, see the template files):
+ *
+ * Concat			(a,b)
+ * Concat3			(a,b,c)
+ * Concat4			(a,b,c,d)
+ * _Use				(a,b)
+ * _UseCat			(a,b,c)
+ * _MUse			(a,b)
+ * _MUseCat			(a,b,c)
+ * ProgramTargetName		(target)
+ * HostProgramTargetName	(target)
+ * RunProgram			(progvar,options)
+ * RunProgramWithSetup		(setup,progvar,options)
+ * RemoveFile			(file)
+ * RemoveFiles			(files)
+ * CenterLoadTarget		(target,srclist,libs,defines)
+ * CenterProgramTarget		(program,srclist,objlist,locallibs,syslibs)
+ * SentinelLinkTarget		(step,program,linklist)
+ * SentinelProgramTarget	(program,deplist,linklist)
+ * SentinelCplusplusProgramTarget	(program,deplist,linklist)
+ * PurifyLinkTarget		(step,program,linklist)
+ * PurifyProgramTarget		(program,deplist,linklist)
+ * PurifyCplusplusProgramTarget	(program,deplist,linklist)
+ * ProofLinkTarget		(step,program,linklist)
+ * ProofProgramTarget		(program,deplist,linklist)
+ * ProofCplusplusProgramTarget	(program,deplist,linklist)
+ * ProofCleanTarget		()
+ * RemoveTargetProgram		(program)
+ * MakeDir			(dir)
+ * InstallDirectory		(dir)
+ * BuildIncludesTop		(srclist)
+ * BuildIncludes		(srclist,dstsubdir,dstupdir)
+ * LinkRule			(program,options,objects,libraries)
+ * HostLinkRule			(program,options,objects,libraries)
+ * NoCmpScript			(target)
+ * NoConfigRec			(target)
+ * NormalProgramTarget		(program,objects,deplibs,locallibs,syslibs)
+ * SetUIDProgramTarget		(program,objects,deplibs,locallibs,syslibs)
+ * SingleProgramTarget		(program,objects,locallibs,syslibs)
+ * SimpleProgramTarget		(program)
+ * ComplexProgramTarget		(program)
+ * ComplexProgramTarget_1	(program,locallib,syslib)
+ * ComplexProgramTarget_2	(program,locallib,syslib)
+ * ComplexProgramTarget_3	(program,locallib,syslib)
+ * ServerTargetWithFlags	(server,subdirs,objects,libs,syslibs,flags)
+ * ServerTarget			(server,subdirs,objects,libs,syslibs)
+ * MoveToBakFile		(file)
+ * RMoveToBakFile		(file)
+ * RanLibrary			(args)
+ * LibraryTargetName		(libname)
+ * LibraryTargetNameSuffix	(libname,suffix)
+ * InstallNamedTarget		(step,srcname,flags,dest,dstname)
+ * InstallTarget		(step,file,flags,dest)
+ * InstallLibrary		(libname,dest)
+ * MergeIntoInstalledLibrary	(tolib,fromlib)
+ * InstallLibraryAlias		(libname,alias,dest)
+ * InstallLintLibrary		(libname,dest)
+ * InstallManPageLong		(file,destdir,dest)
+ * InstallManPage		(file,destdir)
+ * InstallManPageAliases	(file,destdir,aliases)
+ * ManKeywordsTarget		(manpath)
+ * InstallNamedNonExec		(srcname,dstname,dest)
+ * InstallNonExecFile		(file,dest)
+ * InstallNonExecFileNoClobber	(file,dest)
+ * InstallNonExec		(file,dest)
+ * InstallProgramWithFlags	(program,dest,flags)
+ * InstallProgram		(program,dest)
+ * InstallScript		(program,dest)
+ * InstallNamedProg		(srcname,dstname,dest)
+ * InstallNamedProgNoClobber	(srcname,dstname,dest)
+ * MakeFlagsToShellFlags	(makeflags,shellcmd)
+ * MakeNamedTargetSubdir	(dir,flags,subname)
+ * LinkConfDirectoryLong	(mdir,cdir,rdir,ldir,opath,npath)
+ * LinkConfDirectory		(mdir,cdir,rdir,ldir)
+ * LinkConfFileLong		(cfile,lfile,opath,npath)
+ * LinkConfFile			(cfile,lfile)
+ * LinkFileList			(step,list,dir,sub)
+ * LinkVarDirectory		(mdir,cdir,rdir,ldir)
+ * InstallMultipleDestFlags	(step,list,dest,flags)
+ * InstallMultipleDest		(step,list,dest)
+ * InstallMultiple		(list,dest)
+ * InstallMultipleFlags		(list,dest,flags)
+ * InstallMultipleMan		(list,dest)
+ * InstallMultipleManSuffix	(list,dest,suffix)
+ * DependDependency		()
+ * DependTarget			()
+ * DependTarget3		(srcs1,srcs2,srcs3)
+ * CleanTarget			()
+ * TagsTarget			()
+ * ImakeDependency		(target)
+ * BuildMakefileTarget		(notused,imakeflags)
+ * MakefileTarget		()
+ * LibMkdir			(dir)
+ * LibCleanDir			(dir)
+ * LintLibReferences		(varname,libname,libsource)
+ * UnsharedLibReferences	(varname,libname,libsource)
+ * ProjectUnsharedLibReferences	(varname,libname,libsource,buildlibdir)
+ * SharedLibDependencies	(libname,libsource,revname)
+ * SharedDSLibDependencies	(libname,libsource,revname)
+ * SharedLibReferences		(varname,libname,libsource,revname,rev)
+ * SharedDSLibReferences	(varname,libname,libsource,revname,rev)
+ * ObjectCompile		(options)
+ * NormalLibObjCompile		(options)
+ * NormalSharedLibObjCompile	(options)
+ * NormalRelocLibObjCompile	(options)
+ * LibObjCompile		(dir,options)
+ * DebuggedLibObjCompile	(options)
+ * ProfiledLibObjCompile	(options)
+ * SharedLibObjCompile		(options)
+ * NormalLibraryObjectRule	()
+ * NormalFortranObjectRule	()
+ * ObjectFromSpecialSource	(dst,src,flags)
+ * SpecialObjectRule		(objs,depends,options)
+ * SpecialCObjectRule		(basename,depends,options)
+ * LexFile			(file)
+ * M4File			(file,includes)
+ * YaccFile			(file,flags)
+ * YaccFileNoFlags		(file)
+ * MakeLibrary			(libname,objlist)
+ * LinkBuildLibrary		(lib)
+ * LinkBuildSonameLibrary	(lib)
+ * NormalLibraryTarget		(libname,objlist)
+ * NormalLibraryTarget2		(libname,objlist1,objlist2)
+ * NormalLibraryTarget3		(libname,objlist1,objlist2,objlist3)
+ * NormalDepLibraryTarget	(libname,deplist,objlist)
+ * UnsharedLibraryTarget	(libname,objlist,down,up)
+ * UnsharedLibraryTarget3	(libname,objlist1,objlist2,objlist3,down,up)
+ * SubdirLibraryRule		(objlist)
+ * ProfiledLibraryTarget	(libname,objlist)
+ * DebuggedLibraryTarget	(libname,objlist)
+ * AliasedLibraryTarget		(libname,alias)
+ * NormalRelocatableTarget	(objname,objlist)
+ * ProfiledRelocatableTarget	(objname,objlist)
+ * DebuggedRelocatableTarget	(objname,objlist)
+ * LintLibraryTarget		(libname,srclist)
+ * NormalLintTarget		(srclist)
+ * LintTarget			()
+ * LinkSourceFile		(src,dir)
+ * LinkFile			(tofile,fromfile)
+ * MakeSubincludesForBuild	(step,dir,srclist)
+ * LangNamedTargetSubdirs	(lang,name,dirs,verb,flags,subname)
+ * LangNamedMakeSubdirs		(lang,name,dirs)
+ * LangMakeSubdirs		(lang,dirs)
+ * NamedTargetSubdirs		(name,dirs,verb,flags,subname)
+ * NamedMakeSubdirs		(name,dirs)
+ * MakeSubdirs			(dirs)
+ * DependSubdirs		(dirs)
+ * ForceSubdirs			(dirs)
+ * InstallSubdirs		(dirs)
+ * InstallManSubdirs		(dirs)
+ * IncludesSubdirs		(dirs)
+ * NamedCleanSubdirs		(name,dirs)
+ * CleanSubdirs			(dirs)
+ * NamedTagSubdirs		(name,dirs)
+ * TagSubdirs			(dirs)
+ * MakeLintSubdirs		(dirs,target,subtarget)
+ * LintSubdirs			(dirs)
+ * MakeLintLibSubdirs		(dirs)
+ * MakeMakeSubdirs		(dirs,target)
+ * MakefileSubdirs		(dirs)
+ * CppScriptTarget		(dst,src,defs,deplist)
+ * MakeScriptFromCpp		(name,defs)
+ * CppFileTarget		(dst,src,defs,deplist)
+ * CppSourceFile		(dst,src,defs,deplist)
+ * MakeDirectories		(step,dirs)
+ * AllTarget			(depends)
+ * StaticLibrary		(libpath,libname)
+ * MakeMutex			(targets)
+ * LinkBuildModule		(module,subdir)
+ * LinkBuildNamedModule		(module,name,subdir)
+ * DynamicModuleTarget		(module,modlist)
+ * InstallDynamicModule		(module,dest,subdir)
+ * InstallDynamicNamedModule	(module,instname,dest,subdir)
+ * LinkerRuntimeLibraryPathFlag	(path)
+ *
+ *
+ * The following are in specific <os>Lib.rules:
+ *
+ * SharedLibraryTarget		(libname,rev,solist,down,up)
+ * SharedLibraryDataTarget	(libname,rev,salist)
+ * InstallSharedLibrary		(libname,rev,dest)
+ * InstallSharedLibraryData	(libname,rev,dest)
+ * SharedDepModuleTarget	(name,deps,solist)
+ *
+ */
+
+#define NullParameter
+
+/* if [ -d ] or [ ! -d ] causes make to fail, define this as - */
+#ifndef DirFailPrefix
+#define DirFailPrefix
+#endif
+
+/*
+ * NoCmpScript - suppress clearmake build script comparison.
+ */
+#ifndef NoCmpScript
+#if HasClearmake
+#define NoCmpScript(targ)						@@\
+XCOMM special target for clearmake					@@\
+.NO_CMP_SCRIPT: targ
+#else
+#define NoCmpScript(targ) /**/
+#endif
+#endif
+
+/*
+ * NoConfigRec - suppress using clearmake configuration records.
+ */
+#ifndef NoConfigRec
+#if HasClearmake
+#define NoConfigRec(targ)						@@\
+XCOMM special target for clearmake					@@\
+.NO_CONFIG_REC: targ
+#else
+#define NoConfigRec(targ) /**/
+#endif
+#endif
+
+/*
+ * Concat - concatenates two strings.
+ */
+#ifndef Concat
+#if (defined(__STDC__) && !defined(UnixCpp)) || defined(AnsiCpp)
+#define Concat(a,b)a##b
+#else
+#define Concat(a,b)a/**/b
+#endif
+#endif
+
+/*
+ * Concat3 - concatenates three strings.
+ */
+#ifndef Concat3
+#if (defined(__STDC__) && !defined(UnixCpp)) || defined(AnsiCpp)
+#define Concat3(a,b,c)a##b##c
+#else
+#define Concat3(a,b,c)a/**/b/**/c
+#endif
+#endif
+
+/*
+ * Concat4 - concatenates four strings.
+ */
+#ifndef Concat4
+#if (defined(__STDC__) && !defined(UnixCpp)) || defined(AnsiCpp)
+#define Concat4(a,b,c,d)a##b##c##d
+#else
+#define Concat4(a,b,c,d)a/**/b/**/c/**/d
+#endif
+#endif
+
+/*
+ * _XUse - makes a choice based on UseInstalledX11.
+ */
+#ifndef _XUse
+# if defined(UseInstalled) || UseInstalledX11
+#  define _XUse(a,b) a
+# else
+#  define _XUse(a,b) b
+# endif
+#endif /* _XUse */
+
+/*
+ * _Use - makes a choice based on UseInstalled.
+ */
+#ifndef _Use
+# define _Use	_XUse
+#endif /* _Use */
+
+/*
+ * _XUseCat - combination of _XUse and Concat.
+ *           exists to avoid problems with some preprocessors
+ */
+#ifndef _XUseCat
+# if (defined(__STDC__) && !defined(UnixCpp)) || defined(AnsiCpp)
+#  if defined(UseInstalled) || UseInstalledX11
+#   define _XUseCat(a,b,c) a##c
+#  else
+#   define _XUseCat(a,b,c) b##c
+#  endif
+# else
+#  if defined(UseInstalled) || UseInstalledX11
+#   define _XUseCat(a,b,c) a/**/c
+#  else
+#   define _XUseCat(a,b,c) b/**/c
+#  endif
+# endif
+#endif /* _XUseCat */
+
+/*
+ * _UseCat - combination of _Use and Concat.
+ *           exists to avoid problems with some preprocessors
+ */
+#ifndef _UseCat
+# define _UseCat	_XUseCat
+#endif /* _UseCat */
+
+#ifndef ProgramTargetName
+#define ProgramTargetName(target)target
+#endif
+
+#ifndef HostProgramTargetName
+#define HostProgramTargetName(target)target
+#endif
+
+#ifndef RunProgram
+#define RunProgram(progvar,options) $(progvar) options
+#endif
+
+#ifndef RunProgramWithSetup
+#define RunProgramWithSetup(setup,progvar,options) setup $(progvar) options
+#endif
+
+#ifndef RunPerlScript
+#define RunPerlScript(script,options) $(PERLENVSETUP) $(PERL) $(PERLOPTS) script options
+#endif
+
+#ifndef RemoveFile
+#define RemoveFile(file) $(RM) file
+#endif /* RemoveFile */
+
+#ifndef RemoveFiles
+#define RemoveFiles(files) $(RM) files
+#endif /* RemoveFiles */
+
+#if RemoveObsoleteFiles
+#define RemoveOldFile(new,old,dir)					@@\
+	@if [ -f new ]; then set -x; \					@@\
+		RemoveFile($(DESTDIR)dir/old); \			@@\
+	fi
+#else
+#define RemoveOldFile(new,old,dir) $(_NULLCMD_)
+#endif
+
+/*
+ * CenterLoadTarget - generate rules to load files into CodeCenter
+ */
+#ifndef CenterLoadTarget
+#if HasCodeCenter
+#define CenterLoadTarget(target,srclist,libs,defines)			@@\
+ProgramTargetName(target):: srclist					@@\
+	XCOMM load defines srclist libs
+#else
+#define CenterLoadTarget(target,srclist,libs,defines) /**/
+#endif
+#endif /* CenterLoadTarget */
+
+/*
+ * CenterProgramTarget - generate rules to make CodeCenter read in sources
+ * and objects.
+ */
+#ifndef CenterProgramTarget
+#define CenterProgramTarget(program,srclist,objlist,locallibs,syslibs)	@@\
+CenterLoadTarget(Concat(debug_,program),srclist,$(EXTRA_LDOPTIONS) $(LOCAL_LDFLAGS) $(LDPRELIBS) locallibs $(LDLIBS) syslibs,$(ALLDEFINES)) @@\
+									@@\
+CenterLoadTarget(Concat(odebug_,program),objlist,$(EXTRA_LDOPTIONS) $(LOCAL_LDFLAGS) $(LDPRELIBS) locallibs $(LDLIBS) syslibs,$(ALLDEFINES))
+#endif /* CenterProgramTarget */
+
+#ifndef SentinelLinkTarget
+#if HasSentinel
+#define SentinelLinkTarget(step,program,linklist)			@@\
+ProgramTargetName(step.sentinel):					@@\
+	RemoveTargetProgram($@)						@@\
+	$(CCENVSETUP) $(SENTINEL) $(SENTINELOPTIONS) $(CC) -o program.sentinel $(LDOPTIONS) linklist $(EXTRA_LOAD_FLAGS)
+#else
+#define SentinelLinkTarget(step,program,linklist) /**/
+#endif
+#endif /* SentinelLinkTarget */
+
+/*
+ * SentinelProgramTarget - generate rules to make Sentinel image
+ */
+#ifndef SentinelProgramTarget
+#if HasSentinel
+#define	SentinelProgramTarget(program,deplist,linklist)			@@\
+ProgramTargetName(program.sentinel): deplist				@@\
+	RemoveTargetProgram($@)						@@\
+	$(CCENVSETUP) $(SENTINEL) $(SENTINELOPTIONS) $(CC) -o $@ $(LDOPTIONS) linklist $(EXTRA_LOAD_FLAGS) @@\
+									@@\
+clean clean.sentinel::							@@\
+	RemoveFile(program.sentinel)
+#else
+#define	SentinelProgramTarget(program,deplist,linklist) /**/
+#endif
+#endif /* SentinelProgramTarget */
+
+/*
+ * SentinelCplusplusProgramTarget - generate rules to make Sentinel image
+ */
+#ifndef SentinelCplusplusProgramTarget
+#if HasSentinel
+#define	SentinelCplusplusProgramTarget(program,deplist,linklist)	@@\
+ProgramTargetName(program.sentinel): deplist				@@\
+	RemoveTargetProgram($@)						@@\
+	$(CXXENVSETUP) $(SENTINEL) $(SENTINELOPTIONS) $(CXX) -o $@ $(CXXLDOPTIONS) linklist $(EXTRA_LOAD_FLAGS) @@\
+									@@\
+clean clean.sentinel::							@@\
+	RemoveFile(program.sentinel)
+#else
+#define	SentinelCplusplusProgramTarget(program,deplist,linklist) /**/
+#endif
+#endif /* SentinelCplusplusProgramTarget */
+
+#ifndef PurifyLinkTarget
+#if HasPurify
+#define PurifyLinkTarget(step,program,linklist)				@@\
+ProgramTargetName(step.pure):						@@\
+	RemoveTargetProgram($@)						@@\
+	$(CCENVSETUP) $(PURIFY) $(PURIFYOPTIONS) $(CC) -o program.pure $(LDOPTIONS) linklist $(EXTRA_LOAD_FLAGS)
+#else
+#define PurifyLinkTarget(step,program,linklist) /**/
+#endif
+#endif /* PurifyLinkTarget */
+
+/*
+ * PurifyProgramTarget - generate rules to make Purify'ed image
+ */
+#ifndef PurifyProgramTarget
+#if HasPurify
+#define	PurifyProgramTarget(program,deplist,linklist)			@@\
+ProgramTargetName(program.pure): deplist				@@\
+	RemoveTargetProgram($@)						@@\
+	$(CCENVSETUP) $(PURIFY) $(PURIFYOPTIONS) $(CC) -o $@ $(LDOPTIONS) linklist $(EXTRA_LOAD_FLAGS) @@\
+									@@\
+clean clean.pure::							@@\
+	RemoveFile(program.pure)
+#else
+#define	PurifyProgramTarget(program,deplist,linklist) /**/
+#endif
+#endif /* PurifyProgramTarget */
+
+/*
+ * PurifyCplusplusProgramTarget - generate rules to make Purify'ed image
+ */
+#ifndef PurifyCplusplusProgramTarget
+#if HasPurify
+#define	PurifyCplusplusProgramTarget(program,deplist,linklist)		@@\
+ProgramTargetName(program.pure): deplist				@@\
+	RemoveTargetProgram($@)						@@\
+	$(CXXENVSETUP) $(PURIFY) $(PURIFYOPTIONS) $(CXX) -o $@ $(CXXLDOPTIONS) linklist $(EXTRA_LOAD_FLAGS) @@\
+									@@\
+clean clean.pure::							@@\
+	RemoveFile(program.pure)
+#else
+#define	PurifyCplusplusProgramTarget(program,deplist,linklist) /**/
+#endif
+#endif /* PurifyCplusplusProgramTarget */
+
+#ifndef ProofLinkTarget
+#if HasTestCenter
+#define ProofLinkTarget(step,program,linklist)				@@\
+ProgramTargetName(step.tc):						@@\
+	RemoveTargetProgram($@)						@@\
+	$(CCENVSETUP) $(PROOF) $(PROOFOPTIONS) $(CC) -o program.tc $(LDOPTIONS) linklist $(EXTRA_LOAD_FLAGS)
+#else
+#define ProofLinkTarget(step,program,linklist) /**/
+#endif
+#endif /* ProofLinkTarget */
+
+/*
+ * ProofProgramTarget - generate rules to make Proof'ed image
+ */
+#ifndef ProofProgramTarget
+#if HasTestCenter
+#define	ProofProgramTarget(program,deplist,linklist)			@@\
+ProgramTargetName(program.tc): deplist					@@\
+	RemoveTargetProgram($@)						@@\
+	$(CCENVSETUP) $(PROOF) $(PROOFOPTIONS) $(CC) -o $@ $(LDOPTIONS) linklist $(EXTRA_LOAD_FLAGS) @@\
+									@@\
+clean cleantc::								@@\
+	RemoveFiles(program.tc program.tc.*.*)
+#else
+#define	ProofProgramTarget(program,deplist,linklist) /**/
+#endif
+#endif /* ProofProgramTarget */
+
+/*
+ * ProofCplusplusProgramTarget - generate rules to make Proof'ed image
+ */
+#ifndef ProofCplusplusProgramTarget
+#if HasTestCenter
+#define	ProofCplusplusProgramTarget(program,deplist,linklist)		@@\
+ProgramTargetName(program.tc): deplist					@@\
+	RemoveTargetProgram($@)						@@\
+	$(CXXENVSETUP) $(PROOF) $(PROOFOPTIONS) $(CXX) -o $@ $(CXXLDOPTIONS) linklist $(EXTRA_LOAD_FLAGS) @@\
+									@@\
+clean cleantc::								@@\
+	RemoveFiles(program.tc program.tc.*.*)
+#else
+#define	ProofCplusplusProgramTarget(program,deplist,linklist) /**/
+#endif
+#endif /* ProofCplusplusProgramTarget */
+
+#ifndef ProofCleanTarget
+#if HasTestCenter
+#define ProofCleanTarget()						@@\
+clean cleantc::								@@\
+	$(RM) -r TC.Cache
+#else
+#define ProofCleanTarget() /**/
+#endif
+#endif /* ProofCleanTarget */
+
+#ifndef RemoveTargetProgram
+#if RemoveTargetProgramByMoving
+#define RemoveTargetProgram(program) \
+-if [ -f program ]; then RemoveFile(Concat(program,~)); $(MV) program Concat(program,~); fi
+#else
+#define RemoveTargetProgram(program) RemoveFile(program)
+#endif
+#endif /* RemoveTargetProgram */
+
+#ifndef MakeDir
+#define MakeDir(dir) DirFailPrefix@if [ -d dir ]; then \		@@\
+		set +x; \						@@\
+	else \								@@\
+		if [ -h dir ]; then \					@@\
+			(set -x; rm -f dir); \				@@\
+		fi; \							@@\
+		(set -x; $(MKDIRHIER) dir); \				@@\
+	fi
+#endif /* MakeDir */
+
+#ifndef MakeDirInline
+#define MakeDirInline(dir) if [ -d dir ]; then \			@@\
+		:; \							@@\
+	else \								@@\
+		if [ -h dir ]; then \					@@\
+			(set -x; rm -f dir); \				@@\
+		fi; \							@@\
+		(set -x; $(MKDIRHIER) dir); \				@@\
+	fi
+#endif /* MakeDirInline */
+
+#ifndef InstallDirectory
+#define InstallDirectory(dir)						@@\
+install::								@@\
+	MakeDir(dir)
+#endif /* InstallDirectory */
+
+#ifndef InstallCreateLink
+# define InstallCreateLink(dest,from,to)				@@\
+install::								@@\
+	  cd $(DESTDIR)dest && \					@@\
+	  $(LN) -sf from to
+#endif
+
+#ifndef BuildIncludesTop
+#define BuildIncludesTop(srclist)					@@\
+includes:: srclist							@@\
+	MakeDir($(BUILDINCDIR))						@@\
+	@(set -x; cd $(BUILDINCDIR) && for i in srclist; do \		@@\
+		RemoveFile($$i); \					@@\
+		$(LN) $(BUILDINCTOP)/$(CURRENT_DIR)/$$i .; \		@@\
+	done)
+#endif /* BuildIncludesTop */
+
+#ifndef BuildIncludes
+#define BuildIncludes(srclist,dstsubdir,dstupdir)			@@\
+includes:: srclist							@@\
+	MakeDir($(BUILDINCDIR)/dstsubdir)				@@\
+	@(set -x; cd $(BUILDINCDIR)/dstsubdir && for i in srclist; do \	@@\
+		RemoveFile($$i); \					@@\
+		$(LN) $(BUILDINCTOP)/dstupdir/$(CURRENT_DIR)/$$i .; \	@@\
+	done)
+#endif /* BuildIncludes */
+
+/*
+ * LinkBuildBinary - export a binary from the build tree.
+ */
+#ifndef LinkBuildBinary
+#define LinkBuildBinary(binary)						@@\
+all:: $(BUILDBINDIR)/binary binary					@@\
+									@@\
+$(BUILDBINDIR)/binary: binary						@@\
+	MakeDir($(BUILDBINDIR))						@@\
+	RemoveFile($@)							@@\
+	cd $(BUILDBINDIR) && $(LN) $(BUILDBINTOP)/$(CURRENT_DIR)/binary .
+#endif /* LinkBuildBinary */
+
+#ifndef BuildInterfaces
+#define BuildInterfaces(srclist,dstsubdir,dstupdir)			@@\
+interfaces::								@@\
+	MakeDir($(BUILDINCDIR)/dstsubdir)				@@\
+	@(set -x; cd $(BUILDINCDIR)/dstsubdir && for i in srclist; do \	@@\
+		RemoveFile($$i); \					@@\
+		$(LN) $(BUILDINCTOP)/dstupdir/$(CURRENT_DIR)/$$i .; \	@@\
+	done)
+#endif /* BuildInterfaces */
+
+/*
+ * LinkRule - link a program
+ */
+#ifndef LinkRule
+#define LinkRule(program,options,objects,libraries) \
+$(CCLINK) -o program options objects libraries $(EXTRA_LOAD_FLAGS)
+#endif /* LinkRule */
+
+/*
+ * HostLinkRule - link a utility to be used on the build host
+ * (differs from LinkRule if cross compiling)
+ */
+#ifndef HostLinkRule
+#define HostLinkRule LinkRule
+#endif
+
+#ifndef CplusplusLinkRule
+#define CplusplusLinkRule(program,options,objects,libraries) \
+$(CXXLINK) -o program options objects libraries $(EXTRA_LOAD_FLAGS)
+#endif /* CplusplusLinkRule */
+
+/*
+ * NormalProgramTarget - generate rules to compile and link the indicated
+ * program; since it does not use any default object files, it may be used for
+ * multiple programs in the same Imakefile.
+ */
+#ifndef NormalProgramTarget
+#define	NormalProgramTarget(program,objects,deplibs,locallibs,syslibs)	@@\
+ProgramTargetName(program): objects deplibs				@@\
+	RemoveTargetProgram($@)						@@\
+	LinkRule($@,$(LDOPTIONS),objects,locallibs $(LDLIBS) syslibs)	@@\
+									@@\
+SentinelProgramTarget(program,objects deplibs,objects locallibs $(LDLIBS) syslibs) @@\
+PurifyProgramTarget(program,objects deplibs,objects locallibs $(LDLIBS) syslibs) @@\
+ProofProgramTarget(program,objects deplibs,objects locallibs $(LDLIBS) syslibs) @@\
+									@@\
+clean::									@@\
+	RemoveFile(ProgramTargetName(program))
+#endif /* NormalProgramTarget */
+
+
+/*
+ * NormalCplusplusProgramTarget - Like NormalTargetProgram, but uses
+ * C++ linking rules.
+ */
+#ifndef NormalCplusplusProgramTarget
+#define	NormalCplusplusProgramTarget(program,objects,deplibs,locallibs,syslibs)	@@\
+ProgramTargetName(program): objects deplibs				@@\
+	RemoveTargetProgram($@)						@@\
+	CplusplusLinkRule($@,$(CXXLDOPTIONS),objects,locallibs $(LDLIBS) syslibs) @@\
+									@@\
+SentinelCplusplusProgramTarget(program,objects deplibs,objects locallibs $(LDLIBS) syslibs) @@\
+PurifyCplusplusProgramTarget(program,objects deplibs,objects locallibs $(LDLIBS) syslibs) @@\
+ProofCplusplusProgramTarget(program,objects deplibs,objects locallibs $(LDLIBS) syslibs) @@\
+									@@\
+clean::									@@\
+	RemoveFile(ProgramTargetName(program))
+#endif /* NormalCplusplusProgramTarget */
+
+
+#ifndef SetUIDProgramTarget
+#define SetUIDProgramTarget NormalProgramTarget
+#endif
+
+
+/*
+ * SingleProgramTarget - obsolete version of NormalProgramTarget that does
+ * not have deplibs.
+ */
+#ifndef SingleProgramTarget
+#define	SingleProgramTarget(program,objects,locallibs,syslibs)		@@\
+NormalProgramTarget(program,objects,NullParameter,locallibs,syslibs)
+#endif /* SingleProgramTarget */
+
+/*
+ * SimpleProgramTarget - generate rules for compiling and linking programs
+ * that only have one C source file.  It should only be used in Imakefiles
+ * that describe a single program.
+ */
+#ifndef SimpleProgramTarget
+#define	SimpleProgramTarget(program)					@@\
+           OBJS = program.o						@@\
+           SRCS = program.c						@@\
+									@@\
+ComplexProgramTarget(program)
+#endif /* SimpleProgramTarget */
+
+#ifndef SimpleProgramTarget_1
+#define	SimpleProgramTarget_1(program)					@@\
+           OBJS1 = program.o						@@\
+           SRCS1 = program.c						@@\
+									@@\
+ComplexProgramTarget_1(program,$(LOCAL_LIBRARIES),NullParameter)
+#endif /* SimpleProgramTarget_1 */
+#ifndef SimpleProgramTarget_2
+#define	SimpleProgramTarget_2(program)					@@\
+           OBJS2 = program.o						@@\
+           SRCS2 = program.c						@@\
+									@@\
+ComplexProgramTarget_2(program,$(LOCAL_LIBRARIES),NullParameter)
+#endif /* SimpleProgramTarget_2 */
+#ifndef SimpleProgramTarget_3
+#define	SimpleProgramTarget_3(program)					@@\
+           OBJS3 = program.o						@@\
+           SRCS3 = program.c						@@\
+									@@\
+ComplexProgramTarget_3(program,$(LOCAL_LIBRARIES),NullParameter)
+#endif /* SimpleProgramTarget_3 */
+#ifndef SimpleProgramTarget_4
+#define	SimpleProgramTarget_4(program)					@@\
+           OBJS4 = program.o						@@\
+           SRCS4 = program.c						@@\
+									@@\
+ComplexProgramTarget_4(program,$(LOCAL_LIBRARIES),NullParameter)
+#endif /* SimpleProgramTarget_4 */
+#ifndef SimpleProgramTarget_5
+#define	SimpleProgramTarget_5(program)					@@\
+           OBJS5 = program.o						@@\
+           SRCS5 = program.c						@@\
+									@@\
+ComplexProgramTarget_5(program,$(LOCAL_LIBRARIES),NullParameter)
+#endif /* SimpleProgramTarget_5 */
+#ifndef SimpleProgramTarget_6
+#define	SimpleProgramTarget_6(program)					@@\
+           OBJS6 = program.o						@@\
+           SRCS6 = program.c						@@\
+									@@\
+ComplexProgramTarget_6(program,$(LOCAL_LIBRARIES),NullParameter)
+#endif /* SimpleProgramTarget_6 */
+#ifndef SimpleProgramTarget_7
+#define	SimpleProgramTarget_7(program)					@@\
+           OBJS7 = program.o						@@\
+           SRCS7 = program.c						@@\
+									@@\
+ComplexProgramTarget_7(program,$(LOCAL_LIBRARIES),NullParameter)
+#endif /* SimpleProgramTarget_7 */
+#ifndef SimpleProgramTarget_8
+#define	SimpleProgramTarget_8(program)					@@\
+           OBJS8 = program.o						@@\
+           SRCS8 = program.c						@@\
+									@@\
+ComplexProgramTarget_8(program,$(LOCAL_LIBRARIES),NullParameter)
+#endif /* SimpleProgramTarget_8 */
+#ifndef SimpleProgramTarget_9
+#define	SimpleProgramTarget_9(program)					@@\
+           OBJS9 = program.o						@@\
+           SRCS9 = program.c						@@\
+									@@\
+ComplexProgramTarget_9(program,$(LOCAL_LIBRARIES),NullParameter)
+#endif /* SimpleProgramTarget_9 */
+#ifndef SimpleProgramTarget_10
+#define	SimpleProgramTarget_10(program)					@@\
+           OBJS10 = program.o						@@\
+           SRCS10 = program.c						@@\
+									@@\
+ComplexProgramTarget_10(program,$(LOCAL_LIBRARIES),NullParameter)
+#endif /* SimpleProgramTarget_10 */
+
+#ifndef SimpleCplusplusProgramTarget
+#define SimpleCplusplusProgramTarget(program)				@@\
+           OBJS = program.o						@@\
+           SRCS = program.CCsuf						@@\
+									@@\
+ComplexCplusplusProgramTarget(program)
+#endif /* SimpleCplusplusProgramTarget */
+
+#ifndef ProgramTargetHelper
+#define	ProgramTargetHelper(program,srcs,objs,deplib,locallib,syslib)	@@\
+ProgramTargetName(program): $(objs) $(deplib)				@@\
+	RemoveTargetProgram($@)						@@\
+	LinkRule($@,$(LDOPTIONS),$(objs),locallib $(LDLIBS) syslib)	@@\
+									@@\
+CenterProgramTarget(program,$(srcs),$(objs),locallib,syslib)		@@\
+SentinelProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+PurifyProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+ProofProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+									@@\
+InstallProgram(program,$(BINDIR))					@@\
+InstallManPage(program,$(MANDIR))
+#endif /* ProgramTargetHelper */
+
+#ifndef ProgramTargetHelperNoMan
+#define ProgramTargetHelperNoMan(program,srcs,objs,deplib,locallib,syslib) @@\
+ProgramTargetName(program): $(objs) $(deplib)				@@\
+	RemoveTargetProgram($@)						@@\
+	LinkRule($@,$(LDOPTIONS),$(objs),locallib $(LDLIBS) syslib)	@@\
+									@@\
+CenterProgramTarget(program,$(srcs),$(objs),locallib,syslib)		@@\
+SentinelProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+PurifyProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+ProofProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+									@@\
+InstallProgram(program,$(BINDIR))
+#endif /* ProgramTargetHelperNoMan */
+
+#ifndef CplusplusProgramTargetHelper
+#define	CplusplusProgramTargetHelper(program,srcs,objs,deplib,locallib,syslib) @@\
+ProgramTargetName(program): $(objs) $(deplib)				@@\
+	RemoveTargetProgram($@)						@@\
+	CplusplusLinkRule($@,$(CXXLDOPTIONS),$(objs),locallib $(LDLIBS) syslib) @@\
+									@@\
+CenterProgramTarget(program,$(srcs),$(objs),locallib,syslib)		@@\
+SentinelCplusplusProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+PurifyCplusplusProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+ProofCplusplusProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+									@@\
+InstallProgram(program,$(BINDIR))					@@\
+InstallManPage(program,$(MANDIR))
+#endif /* CplusplusProgramTargetHelper */
+
+#ifndef CplusplusProgramTargetHelperNoMan
+#define	CplusplusProgramTargetHelperNoMan(program,srcs,objs,deplib,locallib,syslib) @@\
+ProgramTargetName(program): $(objs) $(deplib)				@@\
+	RemoveTargetProgram($@)						@@\
+	CplusplusLinkRule($@,$(CXXLDOPTIONS),$(objs),locallib $(LDLIBS) syslib) @@\
+									@@\
+CenterProgramTarget(program,$(srcs),$(objs),locallib,syslib)		@@\
+SentinelCplusplusProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+PurifyCplusplusProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+ProofCplusplusProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+									@@\
+InstallProgram(program,$(BINDIR))					@@
+#endif /* CplusplusProgramTargetHelperNoMan */
+
+/*
+ * ComplexProgramTarget - generate rules for compiling and linking the
+ * program specified by $(OBJS) and $(SRCS), installing the program and its
+ * man page, and generating dependencies.  It should only be used in
+ * Imakefiles that describe a single program.
+ */
+#ifndef ComplexProgramTarget
+#define	ComplexProgramTarget(program)					@@\
+        PROGRAM = ProgramTargetName(program)				@@\
+									@@\
+AllTarget(ProgramTargetName(program))					@@\
+									@@\
+ProgramTargetHelper(program,SRCS,OBJS,DEPLIBS,$(LOCAL_LIBRARIES),NullParameter) @@\
+									@@\
+DependTarget()								@@\
+LintTarget()								@@\
+									@@\
+clean::									@@\
+	RemoveFile(ProgramTargetName(program))
+#endif /* ComplexProgramTarget */
+
+#ifndef ComplexCplusplusProgramTarget
+#define	ComplexCplusplusProgramTarget(program)				@@\
+        PROGRAM = ProgramTargetName(program)				@@\
+									@@\
+AllTarget(ProgramTargetName(program))					@@\
+									@@\
+CplusplusProgramTargetHelper(program,SRCS,OBJS,DEPLIBS,$(LOCAL_LIBRARIES),NullParameter) @@\
+									@@\
+DependTarget()								@@\
+LintTarget()								@@\
+									@@\
+clean::									@@\
+	RemoveFile(ProgramTargetName(program))
+#endif /* ComplexCplusplusProgramTarget */
+
+/*
+ * ComplexProgramTargetNoMan - generate rules for compiling and linking
+ * the program specified by $(OBJS) and $(SRCS), installing the program
+ * and generating dependencies.  It should only be used in Imakefiles
+ * that describe a single program, and have no manual page.
+ */
+#ifndef ComplexProgramTargetNoMan
+#define ComplexProgramTargetNoMan(program)				@@\
+        PROGRAM = ProgramTargetName(program)				@@\
+									@@\
+AllTarget(ProgramTargetName(program))					@@\
+									@@\
+ProgramTargetHelperNoMan(program,SRCS,OBJS,DEPLIBS,$(LOCAL_LIBRARIES),NullParameter) @@\
+									@@\
+DependTarget()								@@\
+LintTarget()								@@\
+									@@\
+clean::									@@\
+	RemoveFile(ProgramTargetName(program))
+#endif /* ComplexProgramTargetNoMan */
+
+#ifndef ComplexCplusplusProgramTarget
+#define	ComplexCplusplusProgramTarget(program)				@@\
+        PROGRAM = program						@@\
+									@@\
+AllTarget(program)							@@\
+									@@\
+CplusplusProgramTargetHelperNoMan(program,SRCS,OBJS,DEPLIBS,$(LOCAL_LIBRARIES),NullParameter) @@\
+									@@\
+DependTarget()								@@\
+LintTarget()								@@\
+									@@\
+clean::									@@\
+	RemoveFile(ProgramTargetName(program))
+#endif /* ComplexCplusplusProgramTarget */
+
+/*
+ * ComplexProgramTarget_1 - generate rules for compiling and linking the
+ * program specified by $(OBJS1) and $(SRCS1), installing the program and its
+ * man page, and generating dependencies for it and any programs described
+ * by $(SRCS2) through $(SRCS10).  It should be used to build the primary
+ * program in Imakefiles that describe multiple programs.
+ */
+#ifndef ComplexProgramTarget_1
+#define	ComplexProgramTarget_1(program,locallib,syslib)			@@\
+  OBJS = $(OBJS1) $(OBJS2) $(OBJS3) $(OBJS4) $(OBJS5) \			@@\
+         $(OBJS6) $(OBJS7) $(OBJS8) $(OBJS9) $(OBJS10)			@@\
+  SRCS = $(SRCS1) $(SRCS2) $(SRCS3) $(SRCS4) $(SRCS5) \			@@\
+         $(SRCS6) $(SRCS7) $(SRCS8) $(SRCS9) $(SRCS10)			@@\
+									@@\
+AllTarget($(PROGRAMS))							@@\
+									@@\
+ProgramTargetHelper(program,SRCS1,OBJS1,DEPLIBS1,locallib,syslib)	@@\
+									@@\
+DependTarget()								@@\
+LintTarget()								@@\
+									@@\
+clean::									@@\
+	RemoveFiles($(PROGRAMS))
+#endif /* ComplexProgramTarget_1 */
+
+#ifndef ComplexCplusplusProgramTarget_1
+#define	ComplexCplusplusProgramTarget_1(program,locallib,syslib)	@@\
+  OBJS = $(OBJS1) $(OBJS2) $(OBJS3) $(OBJS4) $(OBJS5) \			@@\
+         $(OBJS6) $(OBJS7) $(OBJS8) $(OBJS9) $(OBJS10)			@@\
+  SRCS = $(SRCS1) $(SRCS2) $(SRCS3) $(SRCS4) $(SRCS5) \			@@\
+         $(SRCS6) $(SRCS7) $(SRCS8) $(SRCS9) $(SRCS10)			@@\
+									@@\
+AllTarget($(PROGRAMS))							@@\
+									@@\
+CplusplusProgramTargetHelper(program,SRCS1,OBJS1,DEPLIBS1,locallib,syslib)@@\
+									@@\
+DependTarget()								@@\
+LintTarget()								@@\
+									@@\
+clean::									@@\
+	RemoveFiles($(PROGRAMS))
+#endif /* ComplexCplusplusProgramTarget_1 */
+
+/*
+ * ComplexProgramTarget_2 - generate rules for compiling and linking the
+ * program specified by $(OBJS2) and $(SRCS2) and installing the program and
+ * man page.  It should be used to build the second program in Imakefiles
+ * describing more than one program.
+ */
+#ifndef ComplexProgramTarget_2
+#define	ComplexProgramTarget_2(program,locallib,syslib)			@@\
+ProgramTargetHelper(program,SRCS2,OBJS2,DEPLIBS2,locallib,syslib)
+#endif /* ComplexProgramTarget_2 */
+
+#ifndef ComplexCplusplusProgramTarget_2
+#define	ComplexCplusplusProgramTarget_2(program,locallib,syslib)	@@\
+CplusplusProgramTargetHelper(program,SRCS2,OBJS2,DEPLIBS2,locallib,syslib)
+#endif /* ComplexCplusplusProgramTarget_2 */
+
+/*
+ * ComplexProgramTarget_3 - generate rules for compiling and linking the
+ * program specified by $(OBJS3) and $(SRCS3) and installing the program and
+ * man page.  It should be used to build the third program in Imakefiles
+ * describing more than one program.
+ */
+#ifndef ComplexProgramTarget_3
+#define	ComplexProgramTarget_3(program,locallib,syslib)			@@\
+ProgramTargetHelper(program,SRCS3,OBJS3,DEPLIBS3,locallib,syslib)
+#endif /* ComplexProgramTarget_3 */
+
+#ifndef ComplexCplusplusProgramTarget_3
+#define	ComplexCplusplusProgramTarget_3(program,locallib,syslib)	@@\
+CplusplusProgramTargetHelper(program,SRCS3,OBJS3,DEPLIBS3,locallib,syslib)
+#endif /* ComplexCplusplusProgramTarget_3 */
+
+/*
+ * ComplexProgramTarget_4 - generate rules for compiling and linking the
+ * program specified by $(OBJS4) and $(SRCS4) and installing the program and
+ * man page.  It should be used to build the third program in Imakefiles
+ * describing more than one program.
+ */
+#ifndef ComplexProgramTarget_4
+#define	ComplexProgramTarget_4(program,locallib,syslib)			@@\
+ProgramTargetHelper(program,SRCS4,OBJS4,DEPLIBS4,locallib,syslib)
+#endif /* ComplexProgramTarget_4 */
+
+#ifndef ComplexCplusplusProgramTarget_4
+#define	ComplexCplusplusProgramTarget_4(program,locallib,syslib)	@@\
+CplusplusProgramTargetHelper(program,SRCS4,OBJS4,DEPLIBS4,locallib,syslib)
+#endif /* ComplexCplusplusProgramTarget_4 */
+
+/*
+ * ComplexProgramTarget_5 - generate rules for compiling and linking the
+ * program specified by $(OBJS5) and $(SRCS5) and installing the program and
+ * man page.  It should be used to build the third program in Imakefiles
+ * describing more than one program.
+ */
+#ifndef ComplexProgramTarget_5
+#define	ComplexProgramTarget_5(program,locallib,syslib)			@@\
+ProgramTargetHelper(program,SRCS5,OBJS5,DEPLIBS5,locallib,syslib)
+#endif /* ComplexProgramTarget_5 */
+
+#ifndef ComplexCplusplusProgramTarget_5
+#define	ComplexCplusplusProgramTarget_5(program,locallib,syslib)	@@\
+CplusplusProgramTargetHelper(program,SRCS5,OBJS5,DEPLIBS5,locallib,syslib)
+#endif /* ComplexCplusplusProgramTarget_5 */
+
+/*
+ * ComplexProgramTarget_6 - generate rules for compiling and linking the
+ * program specified by $(OBJS6) and $(SRCS6) and installing the program and
+ * man page.  It should be used to build the third program in Imakefiles
+ * describing more than one program.
+ */
+#ifndef ComplexProgramTarget_6
+#define	ComplexProgramTarget_6(program,locallib,syslib)			@@\
+ProgramTargetHelper(program,SRCS6,OBJS6,DEPLIBS6,locallib,syslib)
+#endif /* ComplexProgramTarget_6 */
+
+#ifndef ComplexCplusplusProgramTarget_6
+#define	ComplexCplusplusProgramTarget_6(program,locallib,syslib)	@@\
+CplusplusProgramTargetHelper(program,SRCS6,OBJS6,DEPLIBS6,locallib,syslib)
+#endif /* ComplexCplusplusProgramTarget_6 */
+
+/*
+ * ComplexProgramTarget_7 - generate rules for compiling and linking the
+ * program specified by $(OBJS7) and $(SRCS7) and installing the program and
+ * man page.  It should be used to build the third program in Imakefiles
+ * describing more than one program.
+ */
+#ifndef ComplexProgramTarget_7
+#define	ComplexProgramTarget_7(program,locallib,syslib)			@@\
+ProgramTargetHelper(program,SRCS7,OBJS7,DEPLIBS7,locallib,syslib)
+#endif /* ComplexProgramTarget_7 */
+
+#ifndef ComplexCplusplusProgramTarget_7
+#define	ComplexCplusplusProgramTarget_7(program,locallib,syslib)	@@\
+CplusplusProgramTargetHelper(program,SRCS7,OBJS7,DEPLIBS7,locallib,syslib)
+#endif /* ComplexCplusplusProgramTarget_7 */
+
+/*
+ * ComplexProgramTarget_8 - generate rules for compiling and linking the
+ * program specified by $(OBJS8) and $(SRCS8) and installing the program and
+ * man page.  It should be used to build the third program in Imakefiles
+ * describing more than one program.
+ */
+#ifndef ComplexProgramTarget_8
+#define	ComplexProgramTarget_8(program,locallib,syslib)			@@\
+ProgramTargetHelper(program,SRCS8,OBJS8,DEPLIBS8,locallib,syslib)
+#endif /* ComplexProgramTarget_8 */
+
+#ifndef ComplexCplusplusProgramTarget_8
+#define	ComplexCplusplusProgramTarget_8(program,locallib,syslib)	@@\
+CplusplusProgramTargetHelper(program,SRCS8,OBJS8,DEPLIBS8,locallib,syslib)
+#endif /* ComplexCplusplusProgramTarget_8 */
+
+/*
+ * ComplexProgramTarget_9 - generate rules for compiling and linking the
+ * program specified by $(OBJS9) and $(SRCS9) and installing the program and
+ * man page.  It should be used to build the third program in Imakefiles
+ * describing more than one program.
+ */
+#ifndef ComplexProgramTarget_9
+#define	ComplexProgramTarget_9(program,locallib,syslib)			@@\
+ProgramTargetHelper(program,SRCS9,OBJS9,DEPLIBS9,locallib,syslib)
+#endif /* ComplexProgramTarget_9 */
+
+#ifndef ComplexCplusplusProgramTarget_9
+#define	ComplexCplusplusProgramTarget_9(program,locallib,syslib)	@@\
+CplusplusProgramTargetHelper(program,SRCS9,OBJS9,DEPLIBS9,locallib,syslib)
+#endif /* ComplexCplusplusProgramTarget_9 */
+
+/*
+ * ComplexProgramTarget_10 - generate rules for compiling and linking the
+ * program specified by $(OBJS10) and $(SRCS10) and installing the program and
+ * man page.  It should be used to build the third program in Imakefiles
+ * describing more than one program.
+ */
+#ifndef ComplexProgramTarget_10
+#define	ComplexProgramTarget_10(program,locallib,syslib)		@@\
+ProgramTargetHelper(program,SRCS10,OBJS10,DEPLIBS10,locallib,syslib)
+#endif /* ComplexProgramTarget_10 */
+
+#ifndef ComplexCplusplusProgramTarget_10
+#define	ComplexCplusplusProgramTarget_10(program,locallib,syslib)	@@\
+CplusplusProgramTargetHelper(program,SRCS10,OBJS10,DEPLIBS10,locallib,syslib)
+#endif /* ComplexCplusplusProgramTarget_10 */
+
+#ifndef MoveToBakFile
+#define MoveToBakFile(file) -@if [ -f file ]; then set -x; \		@@\
+	$(MV) file file.bak; else exit 0; fi
+#endif /* MoveToBakFile */
+
+#ifndef RMoveToBakFile
+#define RMoveToBakFile(file) -@if [ -f file ]; then set -x; \		@@\
+	RemoveFile(file.bak); $(MV) file file.bak; \			@@\
+	else exit 0; fi
+#endif /* RMoveToBakFile */
+
+/*
+ * ServerTargetWithFlags - generate rules to compile, link, and relink a server
+ */
+#ifndef ServerTargetWithFlags
+#define	ServerTargetWithFlags(server,subdirs,objects,libs,syslibs,flags) @@\
+AllTarget(ProgramTargetName(server))					@@\
+ProgramTargetName(server): subdirs objects libs				@@\
+	MoveToBakFile($@)						@@\
+	LinkRule($@,$(LDOPTIONS),objects,libs $(LDLIBS) syslibs) @@\
+									@@\
+Concat(load,server):							@@\
+	MoveToBakFile(ProgramTargetName(server))			@@\
+	LinkRule(ProgramTargetName(server),$(LDOPTIONS),objects,libs $(LDLIBS) syslibs) @@\
+									@@\
+loadX:: Concat(load,server)						@@\
+									@@\
+SentinelProgramTarget(server,subdirs objects libs,objects libs $(LDLIBS) syslibs) @@\
+SentinelLinkTarget(Concat(load,server),server,objects libs $(LDLIBS) syslibs) @@\
+PurifyProgramTarget(server,subdirs objects libs,objects libs $(LDLIBS) syslibs) @@\
+PurifyLinkTarget(Concat(load,server),server,objects libs $(LDLIBS) syslibs) @@\
+ProofProgramTarget(server,subdirs objects libs,objects libs $(LDLIBS) syslibs) @@\
+ProofLinkTarget(Concat(load,server),server,objects libs $(LDLIBS) syslibs) @@\
+									@@\
+InstallProgramWithFlags(server,$(BINDIR),flags)				@@\
+									@@\
+clean::									@@\
+	RemoveFile(ProgramTargetName(server))
+#endif /* ServerTargetWithFlags */
+
+/*
+ * ServerTarget - rules to compile, link, and relink a normal server
+ */
+#ifndef ServerTarget
+#define	ServerTarget(server,subdirs,objects,libs,syslibs)		@@\
+ServerTargetWithFlags(server,subdirs,objects,libs,syslibs,$(_NOOP_))
+#endif /* ServerTarget */
+
+#if DoRanlibCmd
+#define RanLibrary(args) $(RANLIB) args
+#else
+#define RanLibrary(args) $(_NULLCMD_)
+#endif
+
+#ifndef LibraryTargetName
+#define LibraryTargetName(libname)Concat(lib,libname.a)
+#endif
+
+/* This rule is used for libs in Xserver/Imakefile which are loaded, not
+ * linked into the core module. Since modules are called libXXXX.a,
+ * this rule mustn't be overriden by .cf files.
+ */
+#ifndef ModuleLibraryTargetName
+#define ModuleLibraryTargetName(libname)Concat(lib,libname.a)
+#endif
+
+#ifndef LibraryTargetNameSuffix
+#define LibraryTargetNameSuffix(libname,suffix)Concat3(lib,libname,suffix.a)
+#endif
+
+#ifndef InstallNamedInline
+#define InstallNamedInline(srcname,flags,dest,dstname) $(INSTALL) $(INSTALLFLAGS) flags srcname $(DESTDIR)dest/dstname
+#endif
+
+#ifndef InstallNamedTarget
+#define InstallNamedTarget(step,srcname,flags,dest,dstname)		@@\
+step:: srcname								@@\
+	MakeDir($(DESTDIR)dest)						@@\
+	InstallNamedInline(srcname,flags,dest,dstname)
+#endif /* InstallNamedTarget */
+
+/*
+ * InstallNamedTargetNoClobber - Like InstallNamedTarget, but doesn't
+ * do the install if an installed version already exists.  Useful
+ * for files that might have local customizations that you don't
+ * want to clobber.  Config files are good candidates for this.
+ */
+#ifndef InstallNamedTargetNoClobber
+#define InstallNamedTargetNoClobber(step,srcname,flags,dest,dstname)	@@\
+step:: srcname								@@\
+	MakeDir($(DESTDIR)dest)						@@\
+	@if [ -f $(DESTDIR)dest/dstname ]; then \			@@\
+	 echo "Not overwriting existing" $(DESTDIR)dest/dstname; \	@@\
+	else set -x; \							@@\
+	 $(INSTALL) $(INSTALLFLAGS) flags srcname $(DESTDIR)dest/dstname; fi
+#endif /* InstallNamedTargetNoClobber */
+
+#ifndef InstallTarget
+#define InstallTarget(step,file,flags,dest)				@@\
+InstallNamedTarget(step,file,flags,dest,file)
+#endif /* InstallTarget */
+
+#ifndef InstallInline
+#define InstallInline(file,flags,dest) InstallNamedInline(file,flags,dest,file)
+#endif
+
+/*
+ * InstallLibrary - generate rules to install the indicated library.
+ */
+#ifndef InstallLibrary
+#define	InstallLibrary(libname,dest)					@@\
+install:: LibraryTargetName(libname)					@@\
+	MakeDir($(DESTDIR)dest)						@@\
+	$(INSTALL) $(INSTALLFLAGS) $(INSTLIBFLAGS) LibraryTargetName(libname) $(DESTDIR)dest @@\
+	RanLibrary($(RANLIBINSTFLAGS) $(DESTDIR)dest/LibraryTargetName(libname))
+#endif /* InstallLibrary */
+
+
+/*
+ * InstallDriverSDKLibrary - rule to install Driver SDK library.
+ *                           (only used for XFree86). This is a no-op
+ *                           rule so that Imakefiles on non-XFree86 systems
+ *                           continue to build Makefiles correctly.
+ */
+#ifndef InstallDriverSDKLibrary
+#define InstallDriverSDKLibrary(lib,dir)
+#endif
+
+
+/*
+ * InstallDriverSDKNamedLibrary - rule to install Driver SDK library.
+ *                         (only used for XFree86). This is a no-op
+ *                         rule so that Imakefiles on non-XFree86 systems
+ *                         continue to build Makefiles correctly.
+ */
+#ifndef InstallDriverSDKNamedLibrary
+#define InstallDriverSDKNamedLibrary(lib,dlib,dir)
+#endif
+
+
+/*
+ * InstallDriverSDKLibraryModule - rule to install Driver SDK library module.
+ *                           (only used for XFree86). This is a no-op
+ *                           rule so that Imakefiles on non-XFree86 systems
+ *                           continue to build Makefiles correctly.
+ */
+#ifndef InstallDriverSDKLibraryModule
+#define InstallDriverSDKLibraryModule(lib,dlib,dir)
+#endif
+
+
+/*
+ * MergeIntoInstalledLibrary - generate rules to merge one library into another
+ */
+#ifndef MergeIntoInstalledLibrary
+#define MergeIntoInstalledLibrary(tolib,fromlib)			@@\
+install::  fromlib							@@\
+	$(SCRIPTSRC)/mergelib $(DESTDIR)tolib fromlib
+#endif /* MergeIntoInstalledLibrary */
+
+/*
+ * InstallLibraryAlias - generate rules to create a link from one library name
+ * to another for the purposes of aliasing.
+ */
+#ifndef InstallLibraryAlias
+#define	InstallLibraryAlias(libname,alias,dest)				@@\
+install::								@@\
+	-(cd $(DESTDIR)dest && ( \					@@\
+		RemoveFile(LibraryTargetName(alias)); \			@@\
+		$(LN) LibraryTargetName(libname) LibraryTargetName(alias)))
+#endif /* InstallLibraryAlias */
+
+
+/*
+ * InstallLintLibrary - generate rules to install the indicated lint library.
+ */
+#ifndef InstallLintLibrary
+#define	InstallLintLibrary(libname,dest)				@@\
+InstallTarget(install.ln,Concat(llib-l,libname.ln),$(INSTLIBFLAGS),dest)
+#endif /* InstallLintLibrary */
+
+
+#if !CompressManPages
+/*
+ * InstallManPageLong - generate rules to install the indicated manual page,
+ * giving it an alternate name.  This is used for installing man pages whose
+ * base name without the .man suffix would normally be longer than 8 characters
+ * (the limit for using source code control systems on files systems with
+ * short file names).
+ */
+#ifndef InstallManPageLong
+#define	InstallManPageLong(file,destdir,dest)				@@\
+BuildInstallHtmlManPage(file,dest,$(MANSUFFIX))				@@\
+									@@\
+CppManTarget(file,$(EXTRAMANDEFS))					@@\
+									@@\
+InstallNamedTarget(install.man,file.$(MANNEWSUFFIX),$(INSTMANFLAGS),destdir,dest.$(MANSUFFIX))
+#endif /* InstallManPageLong */
+
+
+/*
+ * InstallManPageAliases - generate rules to install manual page aliases.
+ */
+#ifndef InstallManPageAliases
+#define	InstallManPageAliases(file,destdir,aliases)			@@\
+InstallHtmlManPageAliases(file,aliases,$(MANSUFFIX))			@@\
+									@@\
+install.man::								@@\
+	@(TMP="#tmp.$$$$"; \						@@\
+	RemoveFile($${TMP}); \						@@\
+	echo .so `basename destdir`/file.$(MANSUFFIX) > $${TMP}; \	@@\
+	for i in aliases; do (set -x; \					@@\
+	$(INSTALL) $(INSTALLFLAGS) $(INSTMANFLAGS) $${TMP} $(DESTDIR)destdir/$$i.$(MANSUFFIX)); \ @@\
+	done; \								@@\
+	RemoveFile($${TMP}))
+#endif /* InstallManPageAliases */
+
+
+/*
+ * InstallGenManPageLong - More general rules for installing manual pages --
+ * doesn't assume MANSUFFIX.
+ */
+#ifndef InstallGenManPageLong
+#define	InstallGenManPageLong(file,destdir,dest,suffix)			@@\
+BuildInstallHtmlManPage(file,dest,suffix)				@@\
+									@@\
+CppManTarget(file, $(EXTRAMANDEFS))					@@\
+									@@\
+install.man:: file.$(MANNEWSUFFIX)					@@\
+	MakeDir($(DESTDIR)destdir)					@@\
+	$(INSTALL) -c $(INSTMANFLAGS) file.$(MANNEWSUFFIX) \		@@\
+		$(DESTDIR)destdir/dest.suffix
+#endif /* InstallGenManPageLong */
+
+
+/*
+ * InstallGenManPageAliases - general equivalent of InstallManPageAliases
+ */
+#ifndef InstallGenManPageAliases
+#define	InstallGenManPageAliases(file,destdir,suffix,aliases)		@@\
+InstallHtmlManPageAliases(file,aliases,suffix)				@@\
+									@@\
+install.man::								@@\
+	@(TMP="#tmp.$$$$"; \						@@\
+	RemoveFile($${TMP}); \						@@\
+	echo .so `basename destdir`/file.suffix > $${TMP}; \		@@\
+	for i in aliases; do (set -x; \					@@\
+	$(INSTALL) $(INSTALLFLAGS) $(INSTMANFLAGS) $${TMP} $(DESTDIR)destdir/$$i.suffix); \ @@\
+	done; \								@@\
+	RemoveFile($${TMP}))
+#endif /* InstallGenManPageAliases */
+
+#else /* CompressManPages */
+
+#ifndef InstallManPageLong
+#define InstallManPageLong(file,destdir,dest)				@@\
+BuildInstallHtmlManPage(file,dest,$(MANSUFFIX))				@@\
+									@@\
+CppManTarget(file, $(EXTRAMANDEFS))					@@\
+									@@\
+install.man:: file.$(MANNEWSUFFIX)					@@\
+	MakeDir($(DESTDIR)destdir)					@@\
+	$(RM) $(DESTDIR)destdir/dest.$(MANSUFFIX)*			@@\
+	$(INSTALL) -c $(INSTMANFLAGS) file.$(MANNEWSUFFIX) \		@@\
+	  $(DESTDIR)destdir/dest.$(MANSUFFIX)				@@\
+	-$(COMPRESSMANCMD) $(DESTDIR)destdir/dest.$(MANSUFFIX)
+#endif
+
+#ifndef InstallGenManPageLong
+#define InstallGenManPageLong(file,destdir,dest,suffix)			@@\
+BuildInstallHtmlManPage(file,dest,suffix)				@@\
+									@@\
+CppManTarget(file, $(EXTRAMANDEFS))					@@\
+									@@\
+install.man:: file.$(MANNEWSUFFIX)					@@\
+	MakeDir($(DESTDIR)destdir)					@@\
+	$(RM) $(DESTDIR)destdir/dest.suffix*				@@\
+	$(INSTALL) -c $(INSTMANFLAGS) file.$(MANNEWSUFFIX) \		@@\
+	  $(DESTDIR)destdir/dest.suffix					@@\
+	-$(COMPRESSMANCMD) $(DESTDIR)destdir/dest.suffix
+#endif
+
+#ifndef InstallMultipleMan
+#define InstallMultipleMan(list,dest)					@@\
+install.man:: list							@@\
+	MakeDir($(DESTDIR)dest)						@@\
+	@case '${MFLAGS}' in *[i]*) set +e;; esac; \			@@\
+	for i in list; do \						@@\
+		(MNAME=`echo $$i | cut -f1 -d.`; \			@@\
+		set -x;	\						@@\
+		$(RM) $(DESTDIR)dest/$${MNAME}*; \			@@\
+		$(INSTALL) -c $(INSTMANFLAGS) $$i \			@@\
+		  $(DESTDIR)dest/$${MNAME}.$(MANSUFFIX); \		@@\
+		$(COMPRESSMANCMD) $(DESTDIR)dest/$${MNAME}.$(MANSUFFIX)); \ @@\
+	done
+#endif
+
+/*
+ * InstallManPageAliases - install soft links for aliases.
+ */
+#ifndef InstallManPageAliasesBase
+#define InstallManPageAliasesBase(file,destdir,aliases)			@@\
+install.man::								@@\
+	@(SUFFIX=`echo $(DESTDIR)destdir/file.* | sed -e 's,.*/[^\.]*.,,'`; \ @@\
+	for i in aliases; do (set -x; \					@@\
+	$(RM) $(DESTDIR)destdir/$$i.*; \				@@\
+	(cd $(DESTDIR)destdir; $(LN) file.$${SUFFIX} \			@@\
+	$$i.$${SUFFIX})); \						@@\
+	done)
+#endif
+
+#ifndef InstallManPageAliases
+#define InstallManPageAliases(file,destdir,aliases)			@@\
+InstallHtmlManPageAliases(file,aliases,$(MANSUFFIX))			@@\
+									@@\
+InstallManPageAliasesBase(file,destdir,aliases)
+#endif
+
+
+/*
+ * InstallGenManPageAliases - install soft links for aliases.
+ */
+#ifndef InstallGenManPageAliases
+#define InstallGenManPageAliases(file,destdir,suffix,aliases)		@@\
+InstallHtmlManPageAliases(file,aliases,suffix)				@@\
+									@@\
+InstallManPageAliasesBase(file,destdir,aliases)
+#endif
+
+#endif /* CompressManPages */
+
+
+/*
+ * InstallManPage - generate rules to install the indicated manual page.
+ */
+#ifndef InstallManPage
+#define	InstallManPage(file,destdir)					@@\
+InstallManPageLong(file,destdir,file)
+#endif /* InstallManPage */
+
+
+/*
+ * InstallGenManPage - general equivalent of InstallManPage
+ */
+#ifndef InstallGenManPage
+#define	InstallGenManPage(file,destdir,suffix)				@@\
+InstallGenManPageLong(file,destdir,file,suffix)
+#endif /* InstallGenManPage */
+
+
+/*
+ * RmanDependency - generate rules to build the rman program if
+ * this Imakefile is within the source tree.
+ */
+#ifndef RmanDependency
+#ifdef UseInstalled
+#define RmanDependency() /**/
+#else
+#define RmanDependency()						@@\
+NoCmpScript(ProgramTargetName($(RMAN)))					@@\
+									@@\
+ProgramTargetName($(RMAN)):						@@\
+	@echo "checking $(RMANBASENAME) over in $(TOP)/config/util first..."; \	@@\
+	cd $(TOP)/config/util && $(MAKE) rmanonly; \			@@\
+	echo "okay, continuing in $(CURRENT_DIR)"
+
+#endif /* UseInstalled */
+#endif /* RmanDependency */
+
+#ifndef RmanCmdDependency
+#ifdef UseInstalled
+#define RmanCmdDependency	/**/
+#else
+#define RmanCmdDependency	ProgramTargetName($(RMAN))
+#endif
+#endif
+
+#ifndef BuildInstallHtmlManPage
+#if BuildHtmlManPages
+#define BuildInstallHtmlManPage(file,dest,suffix)			@@\
+AllTarget(dest.suffix.html)						@@\
+									@@\
+dest.suffix.html: file.$(MANNEWSUFFIX) RmanCmdDependency		@@\
+	RemoveFiles(dest.suffix.html dest.suffix-html)			@@\
+	RunProgram(RMAN,$(RMANOPTIONS) < file.$(MANNEWSUFFIX) \		@@\
+	  > dest.suffix-html) && $(MV) dest.suffix-html $@		@@\
+									@@\
+install.man:: dest.suffix.html						@@\
+	MakeDir($(DESTDIR)$(DOCHTMLDIR))				@@\
+	@(SUF=`expr suffix \: '\(.\)'`; \				@@\
+	 set -x; \							@@\
+	 $(INSTALL) $(INSTALLFLAGS) $(INSTMANFLAGS) dest.suffix.html $(DESTDIR)$(DOCHTMLDIR)/dest.$$SUF.html)	@@\
+									@@\
+clean::									@@\
+	RemoveFiles(dest.suffix.html dest.suffix-html)
+#else
+#define BuildInstallHtmlManPage(file,dest,suffix) /**/
+#endif
+#endif
+
+#ifndef InstallHtmlManPageAliases
+#if BuildHtmlManPages
+#define InstallHtmlManPageAliases(file,aliases,suffix)			@@\
+install.man:: file.suffix.html						@@\
+	MakeDir($(DESTDIR)$(DOCHTMLDIR))				@@\
+	@SUF=`expr suffix \: '\(.\)'`; \				@@\
+	for i in aliases; do (set -x; \					@@\
+	  RemoveFile($(DESTDIR)$(DOCHTMLDIR)/$$i.$$SUF.html); \		@@\
+	  (cd $(DESTDIR)$(DOCHTMLDIR); \				@@\
+	    $(LN) file.$$SUF.html $$i.$$SUF.html)); \			@@\
+	done
+#else
+#define InstallHtmlManPageAliases(file,aliases,suffix) /**/
+#endif
+#endif
+
+#ifndef HtmlManIndex
+#if BuildHtmlManPages
+#define HtmlManIndex							@@\
+html_index::								@@\
+	MakeDir($(DESTDIR)$(DOCHTMLDIR))				@@\
+	$(HTMLINDEXCMD) $(DESTDIR)$(DOCHTMLDIR)
+#else
+#define HtmlManIndex	html_index::
+#endif
+#endif
+
+
+/*
+ * ManKeywordsTarget - generate the database used by "man -k".
+ * This rule updates the index in the directory "manpath", which
+ * indexes all the manual pages in the section subdirectories under
+ * it.  An update command is defined only on systems that have a
+ * per MANPATH element index.  If the OS supports only one system-wide
+ * database, we don't update it, because then we can't do cross
+ * installations or use a non-empty DESTDIR for testing.
+ */
+#ifndef ManKeywordsTarget
+#define ManKeywordsTarget(manpath) man_keywords::
+#endif
+
+/*
+ * InstallNamedNonExec - generate rules to install a data file
+ */
+#ifndef InstallNamedNonExec
+#define	InstallNamedNonExec(srcname,dstname,dest)			@@\
+InstallNamedTarget(install,srcname,$(INSTDATFLAGS),dest,dstname)
+#endif /* InstallNamedNonExec */
+
+
+/*
+ * InstallDriverSDKNamedNonExec - rule for installing server Driver SDK files.
+ *                         (only used for XFree86). This is a no-op
+ *                         rule so that Imakefiles on non-XFree86 systems
+ *                         continue to build Makefiles correctly.
+ */
+#ifndef InstallDriverSDKNamedNonExec
+#define InstallDriverSDKNamedNonExec(srcname,dstname,dest)
+#endif
+
+
+/*
+ * InstallNonExecFile - generate rules to install a data file
+ */
+#ifndef InstallNonExecFile
+#define InstallNonExecFile(file,dest)					@@\
+InstallTarget(install,file,$(INSTDATFLAGS),dest)
+#endif /* InstallNonExecFile */
+
+
+/*
+ * InstallNonExecFileNoClobber - install a data file once
+ */
+#ifndef InstallNonExecFileNoClobber
+#define InstallNonExecFileNoClobber(file,dest)				@@\
+InstallNamedTargetNoClobber(install,file,$(INSTDATFLAGS),dest,file)
+#endif /* InstallNonExecFileNoClobber */
+
+
+/*
+ * InstallDriverSDKNonExecFile - rule for installing server Driver SDK files.
+ *                         (only used for XFree86). This is a no-op
+ *                         rule so that Imakefiles on non-XFree86 systems
+ *                         continue to build Makefiles correctly.
+ */
+#ifndef InstallDriverSDKNonExecFile
+#define InstallDriverSDKNonExecFile(file,dir)
+#endif
+
+
+/*
+ * InstallNonExec - generate rules to install a data file, but does not
+ * try to create the destination directory (deprecated)
+ */
+#ifndef InstallNonExec
+#define	InstallNonExec(file,dest)					@@\
+install:: file								@@\
+	$(INSTALL) $(INSTALLFLAGS) $(INSTDATFLAGS) file $(DESTDIR)dest
+#endif /* InstallNonExec */
+
+
+/*
+ * InstallProgramWithFlags - generate rules to install an executable program
+ * using given install flags.
+ */
+#ifndef InstallProgramWithFlags
+#if StripInstalledPrograms && CrossCompiling
+#define InstallProgramWithFlags(program,dest,flags)			@@\
+InstallTarget(install,ProgramTargetName(program),$(INSTPGMFLAGS) flags,dest) @@\
+	CrossStripCmd $(DESTDIR)dest/ProgramTargetName(program)
+#else
+#define InstallProgramWithFlags(program,dest,flags)			@@\
+InstallTarget(install,ProgramTargetName(program),$(INSTPGMFLAGS) flags,dest)
+#endif /* StripInstalledPrograms && CrossCompiling */
+#endif /* InstallProgramWithFlags */
+
+
+/*
+ * InstallProgram - generate rules to install an executable program using any
+ * special install flags set in $(INSTALLFLAGS).
+ */
+#ifndef InstallProgram
+#define	InstallProgram(program,dest)					@@\
+InstallProgramWithFlags(program,dest,NullParameter)
+#endif /* InstallProgram */
+
+
+
+/*
+ * InstallScript - install a shell script.
+ */
+#ifndef InstallScript
+#define	InstallScript(program,dest)					@@\
+InstallNamedTarget(install,program.script,$(INSTBINFLAGS),dest,program)
+#endif /* InstallScript */
+
+
+/*
+ * InstallNamedProg - install a program with renaming and no stripping.
+ */
+#ifndef InstallNamedProg
+#define InstallNamedProg(srcname,dstname,dest)				@@\
+InstallNamedTarget(install,srcname,$(INSTBINFLAGS),dest,dstname)
+#endif /* InstallNamedProg */
+
+
+/*
+ * InstallNamedProgNoClobber - Like InstallNamedProg, but doesn't
+ * do the install if an installed version already exists.
+ */
+#ifndef InstallNamedProgNoClobber
+#define InstallNamedProgNoClobber(srcname,dstname,dest)			@@\
+InstallNamedTargetNoClobber(install,srcname,$(INSTBINFLAGS),dest,dstname)
+#endif /* InstallNamedProgNoClobber */
+
+
+/*
+ * InstallDriverSDKNamedProg - rule for installing server Driver SDK files.
+ *                         (only used for XFree86). This is a no-op
+ *                         rule so that Imakefiles on non-XFree86 systems
+ *                         continue to build Makefiles correctly.
+ */
+#ifndef InstallDriverSDKNamedProg
+#define InstallDriverSDKNamedProg(srcname,dstname,dest)
+#endif
+
+
+/*
+ * MakeFlagsToShellFlags - set variables before starting a loop.
+ * makeflags is the set of "make" flags to check.
+ * shellcmd is the shell command to execute if any of the flags are set.
+ *
+ * The usual use of this rule is to translate make's "don't quit on error"
+ * flags into the equivalent for the shell.  To do this, "make -i" always
+ * becomes "set +e".  "make -k" should also turn on "set +e" if the target
+ * is building subdirectories.  That is, subdirectories are independent
+ * and should appear to be multiple targets, even though they are
+ * implemented in a loop in a single target.
+ */
+#ifndef MakeFlagsToShellFlags
+#define MakeFlagsToShellFlags(makeflags,shellcmd)\
+	for flag in ${MAKEFLAGS} ''; do \				@@\
+	  case "$$flag" in *=*) ;; --*) ;; *[makeflags]*) shellcmd;; esac; done
+#endif
+
+/*
+ * MakeNamedTargetSubdir - do make in a subdir.
+ */
+#ifndef MakeNamedTargetSubdir
+#define MakeNamedTargetSubdir(dir,flags,subname)\
+		(cd dir && $(MAKE) $(MFLAGS) $(PARALLELMFLAGS) \	@@\
+			flags subname)
+#endif
+
+/*
+ * LinkFileList - link a list of files from one place to another
+ */
+#ifndef LinkFileList
+#define LinkFileList(step,list,dir,sub)					@@\
+step::									@@\
+	@MakeFlagsToShellFlags(i,set +e); \				@@\
+	echo "	cd" dir; cd dir && \					@@\
+	for i in list; do (set -x; $(LN) -f sub/$$i .); done
+#endif
+
+
+/*
+ * LinkConfDirectoryLong
+ *
+ * Make links from opath (usually <ProjectRoot>/lib/X11) to npath
+ * For example /usr/X11R6/lib/X11/xdm ==> /etc/X11/xdm so that X
+ * binaries can be mounted from a read-only volume like a CD-ROM;
+ * but files that may need to be edited can be stored locally on
+ * read-write media. If someone has an existing installation, be
+ * careful and move existing files to the new location in /etc.
+ * XXX Need to make the installation script do this when installing
+ * binary distributions.
+ *
+ * Since the link is used in the installation process, we need to
+ * make the link relative in order to honor $(DESTDIR) if it is set.
+ *
+ * Note: The sed script used here is not completely general.  It assumes
+ * that no elements of the path are '..', and that none start with '.'
+ * that aren't just '.'.
+ *
+ * For a more general solution $(REVPATH) could be used.  Even though
+ * it was intended for something a little different, it does do what is
+ * required here.
+ *
+ */
+#ifndef LinkConfDirectoryLong
+#if UseSeparateConfDir && HasSymLinks
+#define LinkConfDirectoryLong(mdir,cdir,rdir,ldir,opath,npath)		@@\
+install::								@@\
+	@MakeFlagsToShellFlags(i,set +e); \				@@\
+	if [ -h Concat($(DESTDIR),npath/mdir) ]; then \			@@\
+	  $(RM) Concat($(DESTDIR),npath/mdir); \			@@\
+	fi								@@\
+	MakeDir(Concat($(DESTDIR),opath/cdir))				@@\
+	MakeDir(Concat($(DESTDIR),npath/mdir))				@@\
+	@MakeFlagsToShellFlags(i,set +e); \				@@\
+	if [ -d Concat($(DESTDIR),opath/cdir) ]; then \			@@\
+	  RELPATH=`echo opath/cdir | \					@@\
+		sed -e 's:^/::' -e 's:[^/.][^/]*:..:'g -e 's:/\.$$::'`; \ @@\
+	  cd Concat($(DESTDIR),opath/cdir); \				@@\
+	  if [ -d rdir -a ! -h rdir ]; then \				@@\
+	    (cd rdir; tar cf - . | \					@@\
+		(cd Concat($(DESTDIR),npath/mdir); \			@@\
+		 tar xf -; exit 0); exit 0); \				@@\
+	  fi; \								@@\
+	  $(RM) -r rdir; \						@@\
+	  $(LN) Concat($${RELPATH},npath/mdir) ldir; \			@@\
+	fi
+#else
+#define LinkConfDirectoryLong(mdir,cdir,rdir,ldir,opath,npath)
+#endif
+#endif
+
+#ifndef LinkConfDirectory
+#define LinkConfDirectory(mdir,cdir,rdir,ldir) LinkConfDirectoryLong(mdir,cdir,rdir,ldir,$(LIBDIR),$(CONFDIR))
+#endif
+
+#ifndef LinkVarDirectory
+#define LinkVarDirectory(mdir,cdir,rdir,ldir) LinkConfDirectoryLong(mdir,cdir,rdir,ldir,$(LIBDIR),$(VARDIR))
+#endif
+
+/*
+ * LinkConfFileLong
+ *
+ * Make links from opath (<ProjectRoot>/lib/X11) to npath
+ * For example /usr/X11R6/lib/X11/xxx ==> /etc/X11/xxx so that X binaries
+ * can be mounted from a read-only volume like a CD-ROM;
+ * but files that may need to be edited can be stored locally on
+ * read-write media. If someone has an existing installation, be
+ * careful and move existing files to the new location in /etc.
+ * XXX Need to make the installation script do this when installing
+ * binary distributions.
+ *
+ * Since the link is used in the installation process, we need to
+ * make the link relative in order to honor $(DESTDIR) if it is set.
+ */
+#ifndef LinkConfFileLong
+#if UseSeparateConfDir && HasSymLinks
+#define LinkConfFileLong(cfile,lfile,opath,npath)			@@\
+install::								@@\
+	MakeDir(Concat($(DESTDIR),opath))				@@\
+	MakeDir(Concat($(DESTDIR),npath))				@@\
+	@MakeFlagsToShellFlags(i,set +e); \				@@\
+	if [ -d Concat($(DESTDIR),opath) ]; then \			@@\
+	  RELPATH=`echo opath | \					@@\
+		sed -e 's:^.::' -e 's:[^/.][^/]*:..:'g`; \		@@\
+	  cd Concat($(DESTDIR),opath); \				@@\
+	  if [ -f lfile -a ! -h lfile ]; then \				@@\
+	    cp -p lfile Concat($(DESTDIR),npath/cfile); \		@@\
+	  fi; \								@@\
+	  $(RM) -r lfile; \						@@\
+	  $(LN) Concat($${RELPATH},npath/cfile) lfile; \		@@\
+	fi
+#else
+#define LinkConfFileLong(cfile,lfile,opath,npath)
+#endif
+#endif
+
+
+#ifndef LinkConfFile
+#define LinkConfFile(cfile,lfile) LinkConfFileLong(cfile,lfile,$(LIBDIR),$(CONFDIR))
+#endif
+
+/*
+ * InstallMultipleDestFlags - generate rules to install multiple files at
+ * once during a particular step in the build using a specific set of install
+ * flags.
+ */
+#ifndef InstallMultipleDestFlags
+#define InstallMultipleDestFlags(step,list,dest,flags)			@@\
+step:: list								@@\
+	MakeDir($(DESTDIR)dest)						@@\
+	@MakeFlagsToShellFlags(i,set +e); \				@@\
+	for i in list; do \						@@\
+		(set -x; $(INSTALL) $(INSTALLFLAGS) flags $$i $(DESTDIR)dest); \	@@\
+	done
+#endif /* InstallMultipleDestFlags */
+
+
+/*
+ * InstallDriverSDKMultipleDestFlags - rule for installing server Driver SDK
+ *                         files. (only used for XFree86). This is a no-op
+ *                         rule so that Imakefiles on non-XFree86 systems
+ *                         continue to build Makefiles correctly.
+ */
+#ifndef InstallDriverSDKMultipleDestFlags
+#define InstallDriverSDKMultipleDestFlags(list,dest,flags)
+#endif
+
+
+/*
+ * InstallMultipleDest - generate rules to install multiple files at once
+ * during a particular step in the build using any install flags set in
+ * $(INSTDATFLAGS).
+ */
+#ifndef InstallMultipleDest
+#define InstallMultipleDest(step,list,dest)				@@\
+InstallMultipleDestFlags(step,list,dest,$(INSTDATFLAGS))
+#endif /* InstallMultipleDest */
+
+/*
+ * InstallMultiple - generate rules to install multiple files at once
+ * during the install step of the build using any install flags set in
+ * $(INSTALLFLAGS).
+ */
+#ifndef InstallMultiple
+#define	InstallMultiple(list,dest)					@@\
+InstallMultipleDest(install,list,dest)
+#endif /* InstallMultiple */
+
+
+/*
+ * InstallMultipleFlags - generate rules to install multiple files at once
+ * during the install step of the build using the given install flags.
+ */
+#ifndef InstallMultipleFlags
+#define InstallMultipleFlags(list,dest,flags)				@@\
+InstallMultipleDestFlags(install,list,dest,flags)
+#endif /* InstallMultipleFlags */
+
+
+/*
+ * InstallMultipleMan - generate rules to install a variety of manual pages
+ * during the install.man step of the build.
+ */
+#ifndef InstallMultipleMan
+#define InstallMultipleMan(list,dest)					@@\
+InstallMultipleDestFlags(install.man,list,dest,$(INSTMANFLAGS))
+#endif /* InstallMultipleMan */
+
+/*
+ * InstallMultipleManSuffix - generate rules to install multiple manual
+ * pages dufing the install.man step of the build, where
+ * the target files have the suffix given.
+ */
+#ifndef InstallMultipleManSuffix
+#define InstallMultipleManSuffix(list,dest,suffix)			@@\
+install.man::								@@\
+	MakeDir($(DESTDIR)dest)						@@\
+	@MakeFlagsToShellFlags(i,set +e); \				@@\
+	for i in list; do \						@@\
+	  (set -x; $(INSTALL) $(INSTALLFLAGS) $(INSTMANFLAGS) $$i.suffix $(DESTDIR)dest/$$i.$(MANSUFFIX)); \	@@\
+	done
+#endif /* InstallMultipleManSuffix */
+
+
+/*
+ * IncludeMakefile - rule to include another Makefile.
+ * Must not generate an error or even a warning if the named file
+ * is not present, since we use this to include Makefile.dep, which
+ * may not be built yet.
+ * This is defined non-null iff HasMakefileSafeInclude is YES.
+ * The double-@ is to ensure no leading spaces on the line.
+ */
+#ifndef IncludeMakefile
+#if HasClearmake
+#define IncludeMakefile(file) @@sinclude file
+#else
+#if HasBsdMake
+#define IncludeMakefile(file) @@# dependencies are in .depend
+#else
+#define IncludeMakefile(file) /**/
+#endif
+#endif
+#endif
+
+/*
+ * DependDependencyStatement - Used by DependDependency to set up the
+ * most specific dependency, which differs based on whether we support
+ * a separate Makefile.dep on this platform.
+ */
+#ifndef DependDependencyStatement
+#if HasMakefileSafeInclude
+#define DependDependencyStatement()					@@\
+DependFileName:: ProgramTargetName($(DEPEND))
+#else
+#define DependDependencyStatement()					@@\
+depend:: ProgramTargetName($(DEPEND))
+#endif
+#endif
+
+/*
+ * DependDependency - generate rules to build the makedepend program if
+ * this Imakefile is within the source tree.
+ */
+#ifndef DependDependency
+#ifdef UseInstalled
+#define DependDependency() /**/
+#else
+#define DependDependency()						@@\
+DependDependencyStatement()						@@\
+									@@\
+NoCmpScript(ProgramTargetName($(DEPEND)))				@@\
+									@@\
+ProgramTargetName($(DEPEND)):						@@\
+	@echo "checking $@ over in $(DEPENDSRC) first..."; \		@@\
+	cd $(DEPENDSRC) && $(MAKE) makedependonly; \			@@\
+	echo "okay, continuing in $(CURRENT_DIR)"
+
+#endif /* UseInstalled */
+#endif /* DependDependency */
+
+
+/*
+ * DependTarget - generate rules to compute dependencies for all files listed
+ * in $(SRCS).
+ */
+#ifndef DependTarget
+#if HasMakefileSafeInclude
+#define DependTarget()							@@\
+DependDependency()							@@\
+									@@\
+depend:: DependFileName							@@\
+									@@\
+DependFileName::							@@\
+	RemoveFile($@)							@@\
+	RunProgram(DEPEND,-f- $(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- $(SRCS)) > $@
+#else /* HasMakefileSafeInclude */
+#define	DependTarget()							@@\
+DependDependency()							@@\
+									@@\
+depend::								@@\
+	RunProgram(DEPEND,$(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- $(SRCS))
+#endif /* HasMakefileSafeInclude else */
+#endif /* DependTarget */
+
+/*
+ * DependTarget3 - generate rules to compute dependencies for all files given.
+ */
+#ifndef DependTarget3
+#if HasMakefileSafeInclude
+#define DependTarget3(srcs1,srcs2,srcs3)				@@\
+DependDependency()							@@\
+									@@\
+depend:: DependFileName							@@\
+									@@\
+DependFileName::							@@\
+	RemoveFile($@)							@@\
+	RunProgram(DEPEND,-f- $(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- srcs1) > $@	@@\
+	RunProgram(DEPEND,-f- $(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- srcs2) >> $@	@@\
+	RunProgram(DEPEND,-f- $(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- srcs3) >> $@
+#else /* HasMakefileSafeInclude */
+#define	DependTarget3(srcs1,srcs2,srcs3)				@@\
+DependDependency()							@@\
+									@@\
+depend::								@@\
+	RunProgram(DEPEND,$(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- srcs1)	@@\
+	RunProgram(DEPEND,-a $(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- srcs2)	@@\
+	RunProgram(DEPEND,-a $(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- srcs3)
+#endif /* HasMakefileSafeInclude else */
+#endif /* DependTarget3 */
+
+
+/*
+ * CleanTarget - generate rules to remove any garbage files
+ */
+#ifndef CleanTarget
+#define	CleanTarget()							@@\
+clean::									@@\
+	$(RM) FilesToClean ExtraFilesToClean DocFilesToClean "#"*	@@\
+									@@\
+ProofCleanTarget()
+#endif /* CleanTarget */
+
+
+/*
+ * TagsTarget - generate rules to compute tags files for C source code.
+ */
+#ifndef TagsTarget
+#define	TagsTarget()							@@\
+tags::									@@\
+	$(TAGS) -w *.[ch]						@@\
+	$(TAGS) -xw *.[ch] > TAGS
+#endif /* TagsTarget */
+
+
+/*
+ * ImakeDependency - generate rules to compile imake if this Imakefile is
+ * within the source tree.
+ */
+#ifndef ImakeDependency
+#ifdef UseInstalled
+#define ImakeDependency(target) /**/
+#else
+#define ImakeDependency(target)						@@\
+target:: ProgramTargetName($(IMAKE))					@@\
+									@@\
+NoCmpScript(ProgramTargetName($(IMAKE)) $(IMAKE).Osuf)			@@\
+									@@\
+ProgramTargetName($(IMAKE)) $(IMAKE).Osuf:				@@\
+	-@(cd $(IMAKESRC) && if [ -f Makefile ]; then \			@@\
+	echo "checking $@ in $(IMAKESRC) first..."; $(MAKE) imakeonly; else \	@@\
+	echo "bootstrapping $@ from Makefile.ini in $(IMAKESRC) first..."; \	@@\
+	$(MAKE) -f Makefile.ini BOOTSTRAPCFLAGS="$(BOOTSTRAPCFLAGS)"; fi; \	@@\
+	echo "okay, continuing in $(CURRENT_DIR)")
+#endif /* UseInstalled */
+#endif /* ImakeDependency */
+
+
+/*
+ * BuildMakefileTarget - generate rules to build a Makefile from an Imakefile
+ * and any special imake flags.  This is generally done automatically by the
+ * template or by any special Imakefiles.  The first argument exists just
+ * because imakeflags is usually empty and some preprocessors will complain
+ * if an empty argument is passed as the sole argument to a macro.
+ */
+#ifndef BuildMakefileTarget
+#define	BuildMakefileTarget(notused,imakeflags)				@@\
+ImakeDependency(Makefile)						@@\
+									@@\
+Makefile::								@@\
+	RMoveToBakFile(Makefile)					@@\
+	$(IMAKE_CMD) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR) imakeflags
+
+#endif /* BuildMakefileTarget */
+
+
+/*
+ * MakefileTarget - generate rules to build a normal Makefile.
+ */
+#ifndef MakefileTarget
+#define MakefileTarget()						@@\
+BuildMakefileTarget(Imakefile,NullParameter)
+#endif /* MakefileTarget */
+
+
+/*
+ * LibMkdir - helper for creating library object subdirectories
+ */
+#ifndef LibMkdir
+#define LibMkdir(dir) DirFailPrefix@if [ -d dir ]; then exit 0; else set -x; mkdir dir; fi
+#endif
+
+#ifndef LibMkdirLinkSubdirs
+#define LibMkdirLinkSubdirs(dir) DirFailPrefix@if [ -d dir ]; then \	@@\
+	    exit 0; \							@@\
+	else \								@@\
+	    echo "mkdir dir"; mkdir dir; \				@@\
+	    for i in $(SUBDIRS); do \					@@\
+	      j=`echo "$$i" | sed -e 's;[^/]\{1,\};..;g'`; \		@@\
+	      if [ ! -d "dir/`dirname $$i`" ]; then \			@@\
+		$(MKDIRHIER) "dir/`dirname $$i`"; \			@@\
+	      fi; \							@@\
+	      echo $(LN) "$$j/$$i/dir" "dir/$$i"; \			@@\
+	      $(LN) "$$j/$$i/dir" "dir/$$i"; \				@@\
+	    done; \							@@\
+	fi
+#endif
+
+/*
+ * LibCleanDir - helper for cleaning library object subdirectories
+ */
+#ifndef LibCleanDir
+#define LibCleanDir(dir) -@if [ -d dir ]; then \			@@\
+		set -x; $(RM) -r dir; else exit 0; fi
+#endif
+
+/*
+ * LintLibReferences - variables for lint libraries
+ */
+#ifndef LintLibReferences
+#define LintLibReferences(varname,libname,libsource)			@@\
+Concat(LINT,varname) = _UseCat($(LINTLIBDIR)/llib-l,libsource/llib-,libname.ln)
+#endif
+
+
+/*
+ * UnsharedLibReferences - variables for unshared libraries
+ */
+#ifndef UnsharedLibReferences
+#define UnsharedLibReferences(varname,libname,libsource)		@@\
+ProjectUnsharedLibReferences(varname,libname,libsource,$(BUILDLIBDIR))
+#endif
+
+/*
+ * ProjectUnsharedLibReferences - variables for unshared libraries
+ */
+#ifndef ProjectUnsharedLibReferences
+#define ProjectUnsharedLibReferences(varname,libname,libsource,buildlibdir)	@@\
+Concat3(DEP,varname,LIB) = _UseCat($(USRLIBDIR)/,buildlibdir/,LibraryTargetName(libname))	@@\
+Concat(varname,LIB) = LoaderLibPrefix Concat(-l,libname)		@@\
+LintLibReferences(varname,libname,libsource)
+#endif
+
+ /*
+ * ProjectUnsharedFontLibReferences - unshared font libraries
+ */
+#ifndef ProjectUnsharedFontLibReferences
+#define ProjectUnsharedFontLibReferences()					@@\
+DEPFONTLIB = _UseCat($(USRLIBDIR)/,XBuildLibDir/,LibraryTargetName(Xfont))	@@\
+FONTLIB = -L$(FREETYPELIBDIR) -L$(FONTLIBSRC) LoaderLibPrefix -lXfont		@@\
+LintLibReferences(XFONT,Xfont,$(FONTLIBSRC))
+#endif
+
+/*
+ * SharedLibDependencies - shared library dependencies
+ */
+#ifndef SharedLibDependencies
+#define SharedLibDependencies(libname,libsource,revname) /**/
+#endif
+
+/*
+ * SharedFontLibReferences - shared font libraries
+ */
+#ifndef SharedFontLibReferences
+#define SharedFontLibReferences()					@@\
+SOFONTREV = SharedFontRev						@@\
+DEPFONTLIB = SharedLibDependencies(Xfont,$(FONTLIBSRC),SOFONTREV)	@@\
+FONTLIB = -L$(FREETYPELIBDIR) -L$(FONTLIBSRC) LoaderLibPrefix -lXfont	@@\
+LintLibReferences(XFONT,Xfont,$(FONTLIBSRC))
+#endif
+
+/*
+ * SharedDSLibDependencies - shared library dependencies with data separation
+ */
+#ifndef SharedDSLibDependencies
+#define SharedDSLibDependencies(libname,libsource,revname) /**/
+#endif
+
+/*
+ * SharedLibReferences - variables for shared libraries
+ */
+#ifndef SharedLibReferences
+#define SharedLibReferences(varname,libname,libsource,revname,rev)	@@\
+revname = rev								@@\
+Concat3(DEP,varname,LIB) = SharedLibDependencies(libname,libsource,revname) @@\
+Concat(varname,LIB) = LoaderLibPrefix Concat(-l,libname)		@@\
+LintLibReferences(varname,libname,libsource)
+#endif
+
+/*
+ * SharedDSLibReferences - variables for shared libraries with data separation
+ */
+#ifndef SharedDSLibReferences
+#define SharedDSLibReferences(varname,libname,libsource,revname,rev)	@@\
+revname = rev								@@\
+Concat3(DEP,varname,LIB) = SharedDSLibDependencies(libname,libsource,revname) @@\
+Concat(varname,LIB) = LoaderLibPrefix Concat(-l,libname)		@@\
+LintLibReferences(varname,libname,libsource)
+#endif
+
+/*
+ * CPPOnlyCompile - run C compiler's preprocessor only
+ */
+#ifndef CPPOnlyCompile
+#define CPPOnlyCompile(src,options) RemoveFile($@)			@@\
+	ClearmakeOSName \
+	$(CC) -E $(CFLAGS) options src > $@
+#endif
+
+/*
+ * ObjectCompile - compile fragment for a normal object file
+ */
+#ifndef ObjectCompile
+#define ObjectCompile(options) RemoveFile($@)				@@\
+	ClearmakeOSName \
+	$(CC) -c $(CFLAGS) options $*.c
+#endif
+
+/*
+ * CompileCToAsm - compile C file to assembler
+ */
+#ifndef CompileCToAsm
+#define CompileCToAsm(options) RemoveFile($@)				@@\
+	ClearmakeOSName \
+	$(CC) -S $(CFLAGS) options $*.c
+#endif
+
+
+/*
+ * CompileCplusplusToAsm - compile C++ file to assembler
+ */
+#ifndef CompileCplusplusToAsm
+#define CompileCplusplusToAsm(options) RemoveFile($@)			@@\
+	ClearmakeOSName \
+	$(CC) -S $(CFLAGS) options $*.cc
+#endif
+
+
+#ifndef ObjectCplusplusCompile
+#define ObjectCplusplusCompile(options) RemoveFile($@)			@@\
+	ClearmakeOSName \
+	$(CXX) -c $(CXXFLAGS) options $*.CCsuf
+#endif
+
+/*
+ * NormalLibObjCompile - compile fragment for a normal library object file
+ */
+#ifndef NormalLibObjCompile
+#define NormalLibObjCompile(options) ObjectCompile(options)
+#endif
+
+#ifndef NormalRelocLibObjCompile
+# if !StaticNeedsPicForShared
+#  define NormalRelocLibObjCompile(options) NormalLibObjCompile(options)
+# else
+#  define NormalRelocLibObjCompile(options) NormalLibObjCompile(options $(PICFLAGS))
+# endif
+#endif
+
+#ifndef NormalLibObjCplusplusCompile
+#define NormalLibObjCplusplusCompile(options) ObjectCplusplusCompile(options)
+#endif
+
+/*
+ * NormalSharedLibObjCompile - compile fragment for shared objects
+ */
+#ifndef NormalSharedLibObjCompile
+#define NormalSharedLibObjCompile(options) NormalLibObjCompile(options $(SHLIBDEF) $(SHAREDCODEDEF) $(PICFLAGS))
+#endif
+
+#ifndef NormalSharedLibObjCplusplusCompile
+#define NormalSharedLibObjCplusplusCompile(options) NormalLibObjCplusplusCompile(options $(SHLIBDEF) $(SHAREDCODEDEF) $(CXXPICFLAGS))
+#endif
+
+/*
+ * LibObjCompile - compile fragment for unshared/profiled/debugged objects
+ */
+#ifndef LibObjCompile
+#if HasGcc || HasGcc2
+#define LibObjCompile(dir,options) RemoveFiles($@ dir/$@)		@@\
+	ClearmakeOSName \
+	$(CC) -c $(CCOPTIONS) $(THREADS_CFLAGS) $(ALLDEFINES) \
+	options $*.c -o dir/$@
+#else
+#define LibObjCompile(dir,options) RemoveFiles($@ dir/$@)		@@\
+	ClearmakeOSName \
+	$(CC) -c $(CCOPTIONS) $(THREADS_CFLAGS) $(ALLDEFINES) \
+	options $*.c							@@\
+	$(MV) $@ dir/$@
+#endif
+#endif
+
+#ifndef LibObjCplusplusCompile
+#if HasGcc || HasGcc2
+#define LibObjCplusplusCompile(dir,options) RemoveFiles($@ dir/$@)	@@\
+	ClearmakeOSName \
+	$(CXX) -c $(CXXOPTIONS) $(THREADS_CXXFLAGS) $(CXXDEFINES) \
+	options $*.CCsuf -o dir/$@
+#else
+#define LibObjCplusplusCompile(dir,options) RemoveFiles($@ dir/$@)	@@\
+	ClearmakeOSName \
+	$(CXX) -c $(CXXOPTIONS) $(THREADS_CXXFLAGS) $(CXXDEFINES) \
+	options $*.CCsuf						@@\
+	$(MV) $@ dir/$@
+#endif
+#endif
+
+/*
+ * DebuggedLibObjCompile - compile fragment for debugged objects
+ */
+#ifndef DebuggedLibObjCompile
+#define DebuggedLibObjCompile(options) LibObjCompile(debugger,DebuggableCDebugFlags options)
+#endif
+
+#ifndef DebuggedLibObjCplusplusCompile
+#define DebuggedLibObjCplusplusCompile(options) LibObjCplusplusCompile(debugger,DebuggableCplusplusDebugFlags options)
+#endif
+
+/*
+ * ProfiledLibObjCompile - compile fragment for profiled objects
+ */
+#ifndef ProfiledLibObjCompile
+#define ProfiledLibObjCompile(options) LibObjCompile(profiled,ProfiledCDebugFlags options)
+#endif
+
+#ifndef ProfiledLibObjCplusplusCompile
+#define ProfiledLibObjCplusplusCompile(options) LibObjCplusplusCompile(profiled,ProfiledCplusplusDebugFlags options)
+#endif
+
+/*
+ * UnsharedLibObjCompile - compile fragment for unshared objects
+ */
+#ifndef UnsharedLibObjCompile
+#define UnsharedLibObjCompile(options) LibObjCompile(unshared,$(CDEBUGFLAGS) $(CLIBDEBUGFLAGS) options)
+#endif
+
+#ifndef UnsharedLibObjCplusplusCompile
+#define UnsharedLibObjCplusplusCompile(options) LibObjCplusplusCompile(unshared,$(CXXDEBUGFLAGS) $(CXXLIBDEBUGFLAGS) options)
+#endif
+
+/*
+ * SharedLibObjCompile - compile fragment for shared objects
+ */
+#ifndef SharedLibObjCompile
+#define SharedLibObjCompile(options) LibObjCompile(shared,options $(SHLIBDEF) $(SHAREDCODEDEF) $(PICFLAGS) $(CDEBUGFLAGS) $(CLIBDEBUGFLAGS))
+#endif
+
+/*
+ * NormalLibraryObjectRule - for simple libraries
+ */
+#ifndef NormalLibraryObjectRule
+#define	NormalLibraryObjectRule()					@@\
+.c.Osuf:								@@\
+	NormalLibObjCompile($(_NOOP_))
+#endif /* NormalLibraryObjectRule */
+
+#ifndef NormalCplusplusObjectRule
+#define NormalCplusplusObjectRule()					@@\
+.CCsuf.Osuf:								@@\
+	NormalLibObjCplusplusCompile($(_NOOP_))
+#endif
+
+#ifndef NormalFortranObjectRule
+#define NormalFortranObjectRule()					@@\
+.f.Osuf:								@@\
+	RemoveFile($@)							@@\
+	ClearmakeOSName \
+	$(FC) -c $(FCFLAGS) $*.f
+#endif
+
+/*
+ * SpecialObjectRule - generate rules to compile a file with special flags.
+ */
+#ifndef SpecialObjectRule
+#define SpecialObjectRule(objs,depends,options)				@@\
+objs:	depends								@@\
+	ObjectCompile(options)
+#endif /* SpecialObjectRule */
+
+#ifndef SpecialCplusplusObjectRule
+#define SpecialCplusplusObjectRule(baseobj,basedep,options)		@@\
+baseobj.Osuf:	basedep.CCsuf						@@\
+	ObjectCplusplusCompile(options)
+#endif /* SpecialCplusplusObjectRule */
+
+/*
+ * SpecialCObjectRule - generate rules to compile a C file with special flags.
+ *			also handles CodeCenter rules
+ */
+#ifndef SpecialCObjectRule
+#define SpecialCObjectRule(basename,depends,options)			@@\
+SpecialObjectRule(basename.Osuf,basename.c depends,options)		@@\
+									@@\
+basename.i: basename.c depends						@@\
+	CPPOnlyCompile(basename.c,options)				@@\
+									@@\
+basename.s: basename.c depends						@@\
+	CompileCToAsm(options)						@@\
+									@@\
+CenterLoadTarget(debug_src,basename.c,NullParameter,$(ALLDEFINES) options)
+#endif /* SpecialCObjectRule */
+
+
+#ifndef ObjectFromSpecialSource
+#define ObjectFromSpecialSource(dst,src,flags)				@@\
+NoConfigRec(dst.c)							@@\
+									@@\
+dst.c:  src.c								@@\
+	RemoveFile($@)							@@\
+	$(LN) $? $@							@@\
+									@@\
+SpecialCObjectRule(dst,NullParameter,flags)				@@\
+									@@\
+includes:: dst.c							@@\
+									@@\
+depend::  dst.c								@@\
+									@@\
+clean::									@@\
+	RemoveFile(dst.c)
+#endif /* ObjectFromSpecialSource */
+
+#ifndef CPPOnlyAsm
+#define CPPOnlyAsm(basename,options) RemoveFile(basename.i)		@@\
+	$(CPP) AsmDefines $(DEFINES) $(INCLUDES) options basename.S | \	@@\
+		grep -v '^\#' > basename.i
+#endif
+
+#ifndef AssembleObject
+#define AssembleObject(basename,flags) CPPOnlyAsm(basename,flags)	@@\
+	RemoveFile(basename.o)						@@\
+	$(AS) -o basename.o basename.i					@@\
+	RemoveFile(basename.i)
+#endif
+
+#ifndef NormalAsmObjectRule
+#define NormalAsmObjectRule()						@@\
+.S.o:									@@\
+	AssembleObject($*,$(_NOOP_))					@@\
+									@@\
+.S.i:									@@\
+	CPPOnlyAsm($*,$(_NOOP_))
+#endif
+
+#ifndef ObjectFromSpecialAsmSource
+#define ObjectFromSpecialAsmSource(dst,src,flags)			@@\
+dst.S:  src.S								@@\
+	RemoveFile($@)							@@\
+	$(LN) $? $@							@@\
+									@@\
+dst.o:  dst.S								@@\
+	AssembleObject(dst,flags)					@@\
+									@@\
+dst.i:  dst.S								@@\
+	CPPOnlyAsm(dst,flags)						@@\
+									@@\
+depend:: dst.S								@@\
+									@@\
+clean::									@@\
+	RemoveFile(dst.S)
+#endif
+
+#ifndef ObjectFromAsmSource
+#define ObjectFromAsmSource(src,flags)					@@\
+									@@\
+src.o:  src.S								@@\
+	AssembleObject(src,flags)					@@\
+									@@\
+src.i:  src.S								@@\
+	CPPOnlyAsm(src,flags)						@@\
+									@@\
+depend:: src.S
+#endif
+
+#ifndef SwitchYYPrefix
+#define SwitchYYPrefix(in,out,prefix) \
+	sed 's/yy/prefix/g' in | sed 's/__REALLY_YY__/yy/' > out && RemoveFile(in)
+#endif
+
+#ifndef LexFilePrefix
+#define LexFilePrefix(file,prefix)					@@\
+file.c: file.l								@@\
+	ClearmakeOSName \
+	$(LEX) $(LFLAGS) file.l						@@\
+	SwitchYYPrefix(lex.yy.c,file.c,prefix)				@@\
+									@@\
+depend:: file.c								@@\
+									@@\
+clean::									@@\
+	RemoveFiles(lex.yy.c file.c)
+#endif
+
+#ifndef LexFileExplicit
+#if HasClearmake		/* provide a place to hang ClearmakeOSName */
+#define LexFileExplicit(file)						@@\
+file.c: file.l								@@\
+	ClearmakeOSName \
+	$(LEX) $(LFLAGS) file.l						@@\
+	$(MV) lex.yy.c file.c
+#else
+#define LexFileExplicit(file) /* the default rule is fine */
+#endif
+#endif
+
+#ifndef LexFile
+#define LexFile(file)							@@\
+LexFileExplicit(file)							@@\
+									@@\
+depend:: file.c								@@\
+									@@\
+clean::									@@\
+	RemoveFiles(lex.yy.c file.c)
+#endif /* LexFile */
+
+
+#ifndef M4File
+#define M4File(file,includes)						@@\
+file: file.m4 includes							@@\
+	RemoveFile(file)						@@\
+	$(M4) $(M4FLAGS) file.m4 >file					@@\
+									@@\
+depend:: file								@@\
+									@@\
+clean::									@@\
+	RemoveFile(file)
+#endif /* M4File */
+
+#ifndef YaccFilePrefix
+#if HasGnuMake
+#define YaccFilePrefix(file,flags,prefix)				@@\
+depend:: file.c								@@\
+									@@\
+file.h: file.c								@@\
+									@@\
+file.c: file.y								@@\
+	ClearmakeOSName \
+	$(YACC) flags file.y						@@\
+	SwitchYYPrefix(y.tab.c,file.c,prefix)				@@\
+	@if [ -f y.tab.h ]; then set -x; SwitchYYPrefix(y.tab.h,file.h,prefix); \@@\
+	else exit 0; fi							@@\
+									@@\
+clean::									@@\
+	RemoveFiles(y.tab.c y.tab.h file.h file.c)
+#else
+#define YaccFilePrefix(file,flags,prefix)				@@\
+depend:: file.c								@@\
+									@@\
+file.h file.c: file.y							@@\
+	ClearmakeOSName \
+	$(YACC) flags file.y						@@\
+	SwitchYYPrefix(y.tab.c,file.c,prefix)				@@\
+	@if [ -f y.tab.h ]; then set -x; SwitchYYPrefix(y.tab.h,file.h,prefix); \	@@\
+	else exit 0; fi							@@\
+									@@\
+clean::									@@\
+	RemoveFiles(y.tab.c y.tab.h file.h file.c)
+#endif
+#endif /* YaccFile */
+
+#ifndef YaccFile
+#if HasGnuMake
+#define YaccFile(file,flags)						@@\
+depend:: file.c								@@\
+									@@\
+file.h: file.c								@@\
+									@@\
+file.c: file.y								@@\
+	ClearmakeOSName \
+	$(YACC) flags file.y						@@\
+	$(MV) y.tab.c file.c						@@\
+	@if [ -f y.tab.h ]; then set -x; $(MV) y.tab.h file.h; \	@@\
+	else exit 0; fi							@@\
+									@@\
+clean::									@@\
+	RemoveFiles(y.tab.c y.tab.h file.h file.c)
+#else
+#define YaccFile(file,flags)						@@\
+depend:: file.c								@@\
+									@@\
+file.h file.c: file.y							@@\
+	ClearmakeOSName \
+	$(YACC) flags file.y						@@\
+	$(MV) y.tab.c file.c						@@\
+	@if [ -f y.tab.h ]; then set -x; $(MV) y.tab.h file.h; \	@@\
+	else exit 0; fi							@@\
+									@@\
+clean::									@@\
+	RemoveFiles(y.tab.c y.tab.h file.h file.c)
+#endif
+#endif /* YaccFile */
+
+#ifndef YaccFileNoFlags
+#define YaccFileNoFlags(file)						@@\
+depend:: file.c								@@\
+									@@\
+file.c: file.y								@@\
+	ClearmakeOSName \
+	$(YACC) file.y							@@\
+	$(MV) y.tab.c file.c						@@\
+									@@\
+clean::									@@\
+	RemoveFiles(y.tab.c file.c)
+#endif /* YaccFileNoFlags */
+
+
+#ifndef MakeLibrary
+#define MakeLibrary(libname,objlist) $(AR) libname objlist
+#endif
+
+#ifndef LinkBuildLibrary
+#ifdef UseInstalled
+#define LinkBuildLibrary(lib) $(_NULLCMD_)
+#else
+#define LinkBuildLibrary(lib) MakeDir($(BUILDLIBDIR))			@@\
+	RemoveFile($(BUILDLIBDIR)/lib)					@@\
+	cd $(BUILDLIBDIR) && $(LN) $(BUILDLIBTOP)/$(CURRENT_DIR)/lib .
+#endif
+#endif /* LinkBuildLibrary */
+
+#ifndef LinkBuildLibraryMaybe
+#ifdef UseInstalled
+#define LinkBuildLibraryMaybe(lib,doit) $(_NULLCMD_)
+#else
+#define LinkBuildLibraryMaybe(lib,doit) MakeDir($(BUILDLIBDIR))		@@\
+	@if doit; then (set -x; \					@@\
+	  RemoveFile($(BUILDLIBDIR)/lib); \				@@\
+	  cd $(BUILDLIBDIR) && $(LN) $(BUILDLIBTOP)/$(CURRENT_DIR)/lib .); fi
+#endif
+#endif /* LinkBuildLibraryMaybe */
+
+#ifndef _LinkBuildLibrary /* will get redefined elsewhere */
+#define _LinkBuildLibrary(lib) $(_NULLCMD_)
+#endif /* _LinkBuildLibrary */
+
+#ifndef LinkBuildSonameLibrary
+#ifdef UseInstalled
+#define LinkBuildSonameLibrary(lib) true
+#else
+#define LinkBuildSonameLibrary(lib) MakeDirInline($(BUILDLIBDIR));\	@@\
+	(set -x; RemoveFile($(BUILDLIBDIR)/lib);\			@@\
+	(cd $(BUILDLIBDIR) && $(LN) $(BUILDLIBTOP)/$(CURRENT_DIR)/lib .))
+#endif
+#endif /* LinkBuildSonameLibrary */
+
+#ifndef LinkBuildLibraryInline
+#define LinkBuildLibraryInline(lib) LinkBuildSonameLibrary(lib)
+#endif /* LinkBuildLibraryInline */
+
+/*
+ * NormalLibraryTarget - generate rules to create a library.
+ */
+#ifndef NormalLibraryTarget
+#define	NormalLibraryTarget(libname,objlist)				@@\
+AllTarget(LibraryTargetName(libname))					@@\
+									@@\
+LibraryTargetName(libname): objlist $(EXTRALIBRARYDEPS)			@@\
+	RemoveFile($@)							@@\
+	MakeLibrary($@,objlist)						@@\
+	RanLibrary($@)							@@\
+	_LinkBuildLibrary($@)
+#endif /* NormalLibraryTarget */
+
+
+/*
+ * NormalLibraryTarget2 - generate rules to create a library in two steps.
+ * This is used to create libraries with large numbers of files.
+ */
+#ifndef NormalLibraryTarget2
+#define	NormalLibraryTarget2(libname,objlist1,objlist2)			@@\
+AllTarget(LibraryTargetName(libname))					@@\
+									@@\
+LibraryTargetName(libname): objlist1 objlist2 $(EXTRALIBRARYDEPS)	@@\
+	RemoveFile($@)							@@\
+	MakeLibrary($@,objlist1)					@@\
+	MakeLibrary($@,objlist2)					@@\
+	RanLibrary($@)							@@\
+	_LinkBuildLibrary($@)
+#endif /* NormalLibraryTarget2 */
+
+
+/*
+ * NormalLibraryTarget3 - generate rules to create a library in three steps.
+ * This is used to create libraries with very large numbers of files.
+ */
+#ifndef NormalLibraryTarget3
+#define	NormalLibraryTarget3(libname,objlist1,objlist2,objlist3)	@@\
+AllTarget(LibraryTargetName(libname))					@@\
+									@@\
+LibraryTargetName(libname): objlist1 objlist2 objlist3 $(EXTRALIBRARYDEPS)	@@\
+	RemoveFile($@)							@@\
+	MakeLibrary($@,objlist1)					@@\
+	MakeLibrary($@,objlist2)					@@\
+	MakeLibrary($@,objlist3)					@@\
+	RanLibrary($@)							@@\
+	_LinkBuildLibrary($@)
+#endif /* NormalLibraryTarget3 */
+
+
+/*
+ * NormalDepLibraryTarget - generate rules to create a library.
+ */
+#ifndef NormalDepLibraryTarget
+#define	NormalDepLibraryTarget(libname,deplist,objlist)			@@\
+AllTarget(LibraryTargetName(libname))					@@\
+									@@\
+LibraryTargetName(libname): deplist $(EXTRALIBRARYDEPS)			@@\
+	RemoveFile($@)							@@\
+	MakeLibrary($@,objlist)						@@\
+	RanLibrary($@)							@@\
+	_LinkBuildLibrary($@)
+#endif /* NormalDepLibraryTarget */
+
+
+/*
+ * UnsharedLibraryTarget - generate rules to create a library.
+ */
+#ifndef UnsharedLibraryTarget
+#define	UnsharedLibraryTarget(libname,objlist,down,up)			@@\
+AllTarget(LibraryTargetName(libname))					@@\
+									@@\
+LibraryTargetName(libname): objlist $(EXTRALIBRARYDEPS)			@@\
+	RemoveFile($@)							@@\
+	@(set -x; cd down && MakeLibrary(up/$@,objlist)) || exit 1;	@@\
+	RanLibrary($@)							@@\
+	_LinkBuildLibrary($@)
+#endif /* UnsharedLibraryTarget */
+
+
+/*
+ * UnsharedLibraryTarget3 - generate rules to create a library in three steps.
+ * This is used to create libraries with very large numbers of files.
+ */
+#ifndef UnsharedLibraryTarget3
+#define	UnsharedLibraryTarget3(libname,objlist1,objlist2,objlist3,down,up) @@\
+AllTarget(LibraryTargetName(libname))					@@\
+									@@\
+LibraryTargetName(libname): objlist1 objlist2 objlist3 $(EXTRALIBRARYDEPS)	@@\
+	RemoveFile($@)							@@\
+	(cd down && MakeLibrary(up/$@,objlist1))			@@\
+	(cd down && MakeLibrary(up/$@,objlist2))			@@\
+	(cd down && MakeLibrary(up/$@,objlist3))			@@\
+	RanLibrary($@)							@@\
+	_LinkBuildLibrary($@)
+#endif /* UnsharedLibraryTarget3 */
+
+
+/*
+ * SubdirLibraryRule -
+ */
+#ifndef SubdirLibraryRule
+#define	SubdirLibraryRule(objlist)					@@\
+all:: DONE								@@\
+									@@\
+DONE: objlist								@@\
+	RemoveFile($@)							@@\
+	touch $@							@@\
+									@@\
+clean::									@@\
+	RemoveFile(DONE)
+#endif /* SubdirLibraryRule */
+
+
+/*
+ * ProfiledLibraryTarget - generate rules to create a profiled library.
+ */
+#ifndef ProfiledLibraryTarget
+#define	ProfiledLibraryTarget(libname,objlist)				@@\
+AllTarget(LibraryTargetNameSuffix(libname,_p))				@@\
+									@@\
+LibraryTargetNameSuffix(libname,_p): objlist $(EXTRALIBRARYDEPS)	@@\
+	RemoveFile($@)							@@\
+	cd profiled && MakeLibrary(../$@,objlist)			@@\
+	RanLibrary($@)
+
+#endif /* ProfiledLibraryTarget */
+
+
+/*
+ * ProfiledDepLibraryTarget - generate rules to create a profiled library.
+ */
+#ifndef ProfiledDepLibraryTarget
+#define	ProfiledDepLibraryTarget(libname,deplist,objlist)		@@\
+AllTarget(LibraryTargetNameSuffix(libname,_p))				@@\
+									@@\
+LibraryTargetNameSuffix(libname,_p): deplist $(EXTRALIBRARYDEPS)	@@\
+	RemoveFile($@)							@@\
+	MakeLibrary($@,objlist)						@@\
+	RanLibrary($@)
+
+#endif /* ProfiledDepLibraryTarget */
+
+
+/*
+ * DebuggedLibraryTarget - generate rules to create a debuggable library.
+ */
+#ifndef DebuggedLibraryTarget
+#define	DebuggedLibraryTarget(libname,objlist)				@@\
+AllTarget(LibraryTargetNameSuffix(libname,_d))				@@\
+									@@\
+LibraryTargetNameSuffix(libname,_d): objlist $(EXTRALIBRARYDEPS)	@@\
+	RemoveFile($@)							@@\
+	cd debugger && MakeLibrary(../$@,objlist)			@@\
+	RanLibrary($@)
+
+#endif /* DebuggedLibraryTarget */
+
+
+/*
+ * DebuggedDepLibraryTarget - generate rules to create a debuggable library.
+ */
+#ifndef DebuggedDepLibraryTarget
+#define	DebuggedDepLibraryTarget(libname,deplist,objlist)		@@\
+AllTarget(LibraryTargetNameSuffix(libname,_d))				@@\
+									@@\
+LibraryTargetNameSuffix(libname,_d): deplist $(EXTRALIBRARYDEPS)	@@\
+	RemoveFile($@)							@@\
+	MakeLibrary($@,objlist)						@@\
+	RanLibrary($@)
+
+#endif /* DebuggedDepLibraryTarget */
+
+
+/*
+ * AliasedLibraryTarget - generate rules to link one library to another.
+ */
+#ifndef AliasedLibraryTarget
+#define	AliasedLibraryTarget(libname,alias)				@@\
+AllTarget(LibraryTargetName(alias))					@@\
+									@@\
+LibraryTargetName(alias): LibraryTargetName(libname)			@@\
+	RemoveFile($@)							@@\
+	$(LN) LibraryTargetName(libname) $@				@@\
+									@@\
+clean::									@@\
+	RemoveFile(LibraryTargetName(alias))
+#endif /* AliasedLibraryTarget */
+
+
+/*
+ * NormalRelocatableTarget - generate rules to produce a relocatable object
+ * file instead of a library.
+ */
+#ifndef NormalRelocatableTarget
+#define	NormalRelocatableTarget(objname,objlist)			@@\
+AllTarget(objname.Osuf)							@@\
+									@@\
+objname.Osuf: objlist $(EXTRALIBRARYDEPS)				@@\
+	RemoveFile($@)							@@\
+	$(LD) $(LDCOMBINEFLAGS) objlist -o $@
+#endif /* NormalRelocatableTarget */
+
+
+/*
+ * NormalDepRelocatableTarget - generate rules to produce a relocatable object
+ * file instead of a library.
+ */
+#ifndef NormalDepRelocatableTarget
+#define	NormalDepRelocatableTarget(objname,deplist,objlist)		@@\
+AllTarget(objname.Osuf)							@@\
+									@@\
+objname.Osuf: deplist $(EXTRALIBRARYDEPS)				@@\
+	RemoveFile($@)							@@\
+	$(LD) $(LDCOMBINEFLAGS) objlist -o $@
+#endif /* NormalDepRelocatableTarget */
+
+
+/*
+ * ProfiledRelocatableTarget - generate rules to produce a profiled relocatable
+ * object file instead of a library.
+ */
+#ifndef ProfiledRelocatableTarget
+#define	ProfiledRelocatableTarget(objname,objlist)			@@\
+AllTarget(Concat(objname,_p.Osuf))					@@\
+									@@\
+Concat(objname,_p.Osuf): objlist $(EXTRALIBRARYDEPS)			@@\
+	RemoveFile($@)							@@\
+	$(LD) -X -r objlist -o $@
+
+#endif /* ProfiledRelocatableTarget */
+
+
+/*
+ * DebuggedRelocatableTarget - generate rules to produce a debuggable
+ * relocatable object file instead of a library.
+ */
+#ifndef DebuggedRelocatableTarget
+#define	DebuggedRelocatableTarget(objname,objlist)			@@\
+AllTarget(Concat(objname,_d.Osuf))					@@\
+									@@\
+Concat(objname,_d.Osuf): objlist $(EXTRALIBRARYDEPS)			@@\
+	RemoveFile($@)							@@\
+	$(LD) -X -r objlist -o $@
+
+#endif /* DebuggedRelocatableTarget */
+
+
+/*
+ * LintLibraryTarget - generate rules to create a lint library.  Note that the
+ * lint library is always forced to be newer than the library itself.
+ */
+#ifndef LintLibraryTarget
+#define	LintLibraryTarget(libname,srclist)				@@\
+lintlib:: Concat(llib-l,libname.ln)					@@\
+									@@\
+Concat(llib-l,libname.ln): srclist $(EXTRALIBRARYDEPS)			@@\
+	RemoveFile($@)							@@\
+	$(LINT) Concat($(LINTLIBFLAG),libname) $(LINTFLAGS) srclist
+#endif /* LintLibraryTarget */
+
+
+/*
+ * NormalLintTarget - generate rules to lint a set of sources.
+ */
+#ifndef NormalLintTarget
+#define NormalLintTarget(srclist)					@@\
+lint:									@@\
+	$(LINT) $(LINTFLAGS) srclist $(LINTLIBS)			@@\
+lint1:									@@\
+	$(LINT) $(LINTFLAGS) $(FILE) $(LINTLIBS)
+#endif /* NormalLintTarget */
+
+
+/*
+ * LintTarget - generate rules to lint $(SRCS)
+ */
+#ifndef LintTarget
+#define LintTarget()							@@\
+NormalLintTarget($(SRCS))
+#endif
+
+
+/*
+ * LinkSourceFile - snag source file from some other directory
+ */
+#ifndef LinkSourceFile
+#define LinkSourceFile(src,dir)						@@\
+src:  dir/src								@@\
+	RemoveFile($@)							@@\
+	$(LN) $? $@							@@\
+									@@\
+NoConfigRec(src)							@@\
+									@@\
+includes:: src								@@\
+									@@\
+depend:: src								@@\
+									@@\
+clean::									@@\
+	RemoveFile(src)
+#endif
+
+
+/*
+ * LinkFile - link a file
+ */
+#ifndef LinkFile
+#define LinkFile(tofile,fromfile)					@@\
+tofile:: fromfile							@@\
+	RemoveFile($@)							@@\
+	$(LN) $? $@							@@\
+									@@\
+NoConfigRec(tofile)							@@\
+									@@\
+includes:: tofile							@@\
+									@@\
+depend:: tofile								@@\
+									@@\
+clean::									@@\
+	RemoveFile(tofile)
+#endif
+
+
+#ifndef MakeSubincludesForBuild
+#define MakeSubincludesForBuild(step,dir,srclist)			@@\
+step::  dir srclist							@@\
+	@-(list=`echo srclist | sed -e 's/[^ ]*\///g'`; \		@@\
+		set -x; cd dir && RemoveFiles($$list))			@@\
+	@for i in srclist; do \						@@\
+		(set -x; cd dir && $(LN) ../$$i .); \			@@\
+	done								@@\
+									@@\
+dir::									@@\
+	$(MKDIRHIER) dir						@@\
+									@@\
+clean::									@@\
+	@-(if [ -d dir ]; then \					@@\
+		list=`echo srclist | sed -e 's/[^ ]*\///g'`; \		@@\
+		set -x; cd dir && RemoveFile($$list); else exit 0; fi)
+#endif
+
+
+/*
+ * LangNamedTargetSubdirs - recursively make a series of steps
+ */
+#ifndef LangNamedTargetSubdirs
+#define LangNamedTargetSubdirs(lang,name,dirs,verb,flags,subname)	@@\
+name::									@@\
+	@MakeFlagsToShellFlags(ik,set +e); \				@@\
+	for i in dirs ;\						@@\
+	do \								@@\
+		echo verb "in $(CURRENT_DIR)/$$i..."; \			@@\
+		(cd $$i && LANG=lang $(MAKE) $(MFLAGS) flags subname);\ @@\
+	done
+#endif
+
+
+/*
+ * NamedMakeSubdirs - generate rules to do makes in the given subdirectories.
+ * If you want CDEBUGFLAGS passed along to subdirectories, provide a line like
+ * the following in the appropriate Imakefile
+ *
+ *         #define PassCDebugFlags 'CDEBUGFLAGS=$(CDEBUGFLAGS)'
+ */
+#ifndef LangNamedMakeSubdirs
+#define LangNamedMakeSubdirs(lang,name,dirs) \
+LangNamedTargetSubdirs(lang,name,dirs,"making" name,PassCDebugFlags,all)
+#endif /* LangNamedMakeSubdirs */
+
+#ifndef LangMakeSubdirs
+#define LangMakeSubdirs(lang,dirs)					@@\
+LangNamedMakeSubdirs(lang,all,dirs)
+#endif /* LangMakeSubdirs */
+
+
+
+/*
+ * NamedTargetSubdirs - recursively make a series of steps
+ */
+#ifndef NamedTargetSubdirs
+#define NamedTargetSubdirs(name,dirs,verb,flags,subname)		@@\
+name::									@@\
+	@MakeFlagsToShellFlags(ik,set +e); \				@@\
+	for i in dirs ;\						@@\
+	do \								@@\
+		echo verb "in $(CURRENT_DIR)/$$i..."; \			@@\
+		MakeNamedTargetSubdir($$i,flags,subname); \		@@\
+	done
+#endif
+
+
+/*
+ * NamedMakeSubdirs - generate rules to do makes in the given subdirectories.
+ * If you want CDEBUGFLAGS passed along to subdirectories, provide a line like
+ * the following in the appropriate Imakefile
+ *
+ *         #define PassCDebugFlags 'CDEBUGFLAGS=$(CDEBUGFLAGS)'
+ */
+#ifndef NamedMakeSubdirs
+#define NamedMakeSubdirs(name,dirs) \
+NamedTargetSubdirs(name,dirs,"making" name,PassCDebugFlags,all)
+#endif /* NamedMakeSubdirs */
+
+#ifndef MakeSubdirs
+#define MakeSubdirs(dirs)						@@\
+NamedMakeSubdirs(all,dirs)
+#endif /* MakeSubdirs */
+
+
+/*
+ * DependSubdirs - generate rules to recursively compute dependencies as
+ * part of the make depend step.
+ */
+#ifndef DependSubdirs
+#define DependSubdirs(dirs) \
+NamedTargetSubdirs(depend,dirs,"depending",NullParameter,depend)
+#endif /* DependSubdirs */
+
+
+/*
+ * ForceSubdirs - force make to build subdirectories
+ */
+#ifndef ForceSubdirs
+#if !HasBsdMake
+#define ForceSubdirs(dirs)						@@\
+dirs: FRC								@@\
+	@echo "making all in $(CURRENT_DIR)/$@..."			@@\
+	@MakeNamedTargetSubdir($@,PassCDebugFlags,all)			@@\
+									@@\
+FRC:
+#else
+/* For BSD 4.4 make */
+#define ForceSubdirs(dirs)						@@\
+dirs:	.EXEC								@@\
+	@cd $@ ; echo "making all in $(CURRENT_DIR)/$@..."; \		@@\
+	$(MAKE) $(MFLAGS) PassCDebugFlags all				@@\
+									@@\
+.EXEC:
+#endif
+
+#endif /* ForceSubdirs */
+
+/*
+ * InstallSubdirs - generate rules to recursively install programs and files.
+ */
+#ifndef InstallSubdirs
+#define InstallSubdirs(dirs) \
+NamedTargetSubdirs(install,dirs,"installing",DESTDIR=$(DESTDIR),install)
+#endif /* InstallSubdirs */
+
+
+/*
+ * InstallManSubdirs - generate rules to recursively install manual pages.
+ */
+#ifndef InstallManSubdirs
+#define InstallManSubdirs(dirs) \
+NamedTargetSubdirs(install.man,dirs,"installing man pages",DESTDIR=$(DESTDIR),install.man)
+#endif /* InstallManSubdirs */
+
+
+/*
+ * IncludesSubdirs - generate rules to recursively put include files in build
+ */
+#ifndef IncludesSubdirs
+#define IncludesSubdirs(dirs) \
+NamedTargetSubdirs(includes,dirs,including,NullParameter,includes)
+#endif
+
+
+/*
+ * InstallDriverSDKSubdirs - generate rules to recursively install Driver
+ *                         SDK (only used for XFree86). This is a no-op
+ *                         rule so that Imakefiles on non-XFree86 systems
+ *                         continue to build Makefiles correctly.
+ */
+#ifndef InstallDriverSDKSubdirs
+#define InstallDriverSDKSubdirs(dirs)
+#endif
+
+/*
+ * InstallDriverSDKObjectModule - generate rules to recursively install Driver
+ *                         SDK (only used for XFree86). This is a no-op
+ *                         rule so that Imakefiles on non-XFree86 systems
+ *                         continue to build Makefiles correctly.
+ */
+#ifndef InstallDriverSDKObjectModule
+#define InstallDriverSDKObjectModule(module,dest,subdir)
+#endif
+#ifndef InstallDriverSDKObjectSubModule
+#define InstallDriverSDKObjectSubModule(module,dest,subdir)
+#endif
+
+
+
+/*
+ * CleanSubdirs - generate rules to recursively clean out garbage files.
+ */
+#define BootstrapCleanSubdirs /**/	/* used at top-level */
+#ifndef NamedCleanSubdirs
+#define NamedCleanSubdirs(name,dirs) \
+NamedTargetSubdirs(name,dirs,"cleaning",BootstrapCleanSubdirs,clean)
+#endif /* NamedCleanSubdirs */
+
+#ifndef CleanSubdirs
+#define CleanSubdirs(dirs) \
+NamedCleanSubdirs(clean,dirs)
+#endif
+
+
+/*
+ * TagSubdirs - generate rules to recursively create tags files.
+ */
+#ifndef NamedTagSubdirs
+#define NamedTagSubdirs(name,dirs) \
+NamedTargetSubdirs(name,dirs,"tagging",TAGS='$(TAGS)',tags)
+#endif /* TagSubdirs */
+
+#ifndef TagSubdirs
+#define TagSubdirs(dirs) \
+NamedTagSubdirs(tags,dirs)
+#endif
+
+/*
+ * MakeLintSubdirs - generate rules to recursively lint directories as part
+ * of the named step.
+ */
+#ifndef MakeLintSubdirs
+#define MakeLintSubdirs(dirs,target,subtarget) \
+NamedTargetSubdirs(target,dirs,"linting" for target and subtarget,DESTDIR=$(DESTDIR) LINTOPTS='$(LINTOPTS)',subtarget)
+#endif /* MakeLintSubdirs */
+
+
+/*
+ * LintSubdirs - generate rules to recursively lint directories as part of
+ * the make lint step.
+ */
+#ifndef LintSubdirs
+#define LintSubdirs(dirs)						@@\
+MakeLintSubdirs(dirs,lint,lint)
+#endif /* LintSubdirs */
+
+
+/*
+ * MakeLintLibSubdirs - generate rules to recursively create lint libraries.
+ */
+#ifndef MakeLintLibSubdirs
+#define MakeLintLibSubdirs(dirs)					@@\
+MakeLintSubdirs(dirs,lintlib,lintlib)
+#endif /* MakeLintLibSubdirs */
+
+
+/*
+ * MakeMakeSubdirs - generate rules to recursively recreate Makefiles as part
+ * of the specified step in the build.  If $(TOP) is set to an absolute path,
+ * do not prepend the ../ prefix.  This makes running things outside of the
+ * source tree much easier.
+ * $(ONESUBDIR)/Makefile exists as a separate, explicit target so that
+ * clearmake will know what its goal is and do wink-in.
+ */
+#ifndef MakeMakeSubdirs
+#define MakeMakeSubdirs(dirs,target)					@@\
+$(ONESUBDIR)/Makefile:							@@\
+	@MakeFlagsToShellFlags(n,executeit="no"); \			@@\
+	cd $(ONESUBDIR) && \						@@\
+	if [ "$$executeit" != "no" ]; then \				@@\
+		ImakeSubCmdHelper -DTOPDIR=$(IMAKETOP) -DCURDIR=$(ONECURDIR)$(ONESUBDIR); \ @@\
+	fi;								@@\
+									@@\
+target::								@@\
+	-@MakeFlagsToShellFlags(ik,set +e); \				@@\
+	MakeFlagsToShellFlags(n,executeit="no"); \			@@\
+	for i in dirs ;\						@@\
+	do \								@@\
+		case "$(CURRENT_DIR)" in \				@@\
+		.) curdir= ;; \						@@\
+		*) curdir=$(CURRENT_DIR)/ ;; \				@@\
+		esac; \							@@\
+		echo "making Makefiles in $$curdir$$i..."; \		@@\
+		itmp=`echo $$i | sed -e 's;^\./;;g' -e 's;/\./;/;g'`; \	@@\
+		curtmp="$(CURRENT_DIR)" \				@@\
+		toptmp=""; \						@@\
+		case "$$itmp" in \					@@\
+		    ../?*) \						@@\
+			while echo "$$itmp" | grep '^\.\./' > /dev/null;\	@@\
+			  do \						@@\
+			     toptmp="/`basename $$curtmp`$$toptmp"; \	@@\
+			     curtmp="`dirname $$curtmp`"; \		@@\
+			     itmp="`echo $$itmp | sed 's;\.\./;;'`"; \	@@\
+			  done \					@@\
+		    ;; \						@@\
+		esac; \							@@\
+		case "$$itmp" in \					@@\
+		*/?*/?*/?*/?*)	newtop=../../../../..;; \		@@\
+		*/?*/?*/?*)	newtop=../../../..;; \			@@\
+		*/?*/?*)	newtop=../../..;; \			@@\
+		*/?*)		newtop=../..;; \			@@\
+		*)		newtop=..;; \				@@\
+		esac; \							@@\
+		newtop="$$newtop$$toptmp"; \				@@\
+		case "$(TOP)" in \					@@\
+		/?*) imaketop=$(TOP) \					@@\
+		     imakeprefix= ;; \					@@\
+		.) imaketop=$$newtop \					@@\
+		   imakeprefix=$$newtop/ ;; \				@@\
+		*) imaketop=$$newtop/$(TOP) \				@@\
+		   imakeprefix=$$newtop/ ;; \				@@\
+		esac; \							@@\
+		RemoveFile($$i/Makefile.bak); \				@@\
+		if [ -f $$i/Makefile ]; then \				@@\
+			echo "	$(MV) Makefile Makefile.bak"; \		@@\
+			if [ "$$executeit" != "no" ]; then \		@@\
+				$(MV) $$i/Makefile $$i/Makefile.bak; \	@@\
+			fi; \						@@\
+		fi; \							@@\
+		$(MAKE) $(MFLAGS) $(MAKE_OPTS) ONESUBDIR=$$i ONECURDIR=$$curdir IMAKETOP=$$imaketop IMAKEPREFIX=$$imakeprefix $$i/Makefile; \	@@\
+		if [ -d $$i ] ; then \					@@\
+			cd $$i; \					@@\
+			$(MAKE) $(MFLAGS) Makefiles; \			@@\
+			cd $$newtop; \					@@\
+		else \							@@\
+			exit 1; \					@@\
+		fi; \							@@\
+	done
+
+#ifdef UseInstalled
+#define ImakeSubCmdHelper $(IMAKE_CMD)
+#else
+#define ImakeSubCmdHelper $(IMAKEPREFIX)$(IMAKE) -I$(IMAKEPREFIX)$(IRULESRC) \
+			  $(IMAKE_DEFINES) $(IMAKE_WARNINGS)
+#endif
+
+#endif /* MakeMakeSubdirs */
+
+
+/*
+ * MakefileSubdirs - generate rules to create Makefiles.
+ */
+#ifndef MakefileSubdirs
+#define MakefileSubdirs(dirs)						@@\
+MakeMakeSubdirs(dirs,Makefiles)
+#endif /* MakefileSubdirs */
+
+/*
+ * Translate XCOMM into pound sign with sed, rather than passing -DXCOMM=XCOMM
+ * to cpp, because that trick does not work on all ANSI C preprocessors.
+ * Delete line numbers from the cpp output (-P is not portable, I guess).
+ * Allow XCOMM to be preceded by whitespace and provide a means of generating
+ * output lines with trailing backslashes.
+ * Allow XHASH to always be substituted, even in cases where XCOMM isn't.
+ */
+#ifndef CppSedMagic
+#define CppSedMagic sed -e '/^#  *[0-9][0-9]*  *.*$$/d' \
+			-e '/^#line  *[0-9][0-9]*  *.*$$/d' \
+			-e '/^[ 	]*XCOMM$$/s/XCOMM/#/' \
+			-e '/^[ 	]*XCOMM[^a-zA-Z0-9_]/s/XCOMM/#/' \
+			-e '/^[ 	]*XHASH/s/XHASH/#/' \
+			-e '/\@\@$$/s/\@\@$$/\\/'
+#endif /* CppSedMagic */
+
+#ifndef CppFileTarget
+#define CppFileTarget(dst,src,defs,deplist)				@@\
+dst::  src deplist							@@\
+	RemoveFile($@)							@@\
+	ClearmakeOSName \
+	$(CPP) CppNoLineInfoOption defs <src | CppSedMagic >$@		@@\
+									@@\
+clean::									@@\
+	RemoveFiles(dst)
+#endif /* CppFileTarget */
+
+/*
+ * CppScriptTarget - generate rules to create a shell script by running the
+ * input through cpp.  If the ExecableScripts configuration parameter is not
+ * set, then make sure that the first line begins with a colon.
+ */
+#ifndef CppScriptTarget
+#if ExecableScripts		/* can use #! instead of colon */
+#define CppScriptTarget(dst,src,defs,deplist)				@@\
+dst::	src deplist							@@\
+	RemoveFile($@)							@@\
+	ClearmakeOSName \
+	$(CPP) CppNoLineInfoOption defs <src | CppSedMagic >$@		@@\
+	chmod a+x $@							@@\
+									@@\
+clean::									@@\
+	RemoveFiles(dst)
+#else
+#define CppScriptTarget(dst,src,defs,deplist)				@@\
+dst::  src deplist							@@\
+	RemoveFile($@)							@@\
+	ClearmakeOSName \
+	echo \: >$@							@@\
+	sed '1d' src | $(CPP) CppNoLineInfoOption defs | CppSedMagic >>$@	@@\
+	chmod a+x $@							@@\
+									@@\
+clean::									@@\
+	RemoveFile(dst)
+#endif /* ExecableScripts */
+#endif /* CppScriptTarget */
+
+
+/*
+ * MakeScriptFromCpp - generate rules to create a script from a file with a
+ * .cpp suffix.
+ */
+#ifndef MakeScriptFromCpp
+#define MakeScriptFromCpp(name,defs)					@@\
+CppScriptTarget(name,name.cpp,defs,NullParameter)
+#endif /* MakeScriptFromCpp */
+
+#ifndef CppSourceFile
+#define CppSourceFile(dst,src,defs,deplist)				@@\
+CppFileTarget(dst,src,defs,deplist)					@@\
+									@@\
+includes:: dst								@@\
+									@@\
+depend:: dst
+#endif /* CppSourceFile */
+
+/* Like CppFileTarget, but don't add any default defines */
+#ifndef CppRawFileTarget
+#define CppRawFileTarget(dst,src,defs,deplist)				@@\
+dst::  src deplist							@@\
+	RemoveFile($@)							@@\
+	ClearmakeOSName \
+	$(RAWCPP) CppNoLineInfoOption defs <src | CppSedMagic >$@	@@\
+									@@\
+clean::									@@\
+	RemoveFiles(dst)
+#endif /* CppFileTarget */
+
+/*
+ * CppManTarget - preprocess man pages.  OS-specific man sections are replaced.
+ */
+#ifndef CppManTarget
+#define CppManTarget(name,defs)						@@\
+AllTarget(name.$(MANNEWSUFFIX))						@@\
+									@@\
+name.$(MANNEWSUFFIX): name.$(MANSRCSUFFIX)				@@\
+	RemoveFile($@)							@@\
+	if test -z "$(PREPROCESSMANPAGES)" ; then \			@@\
+	   cd `dirname name` && \					@@\
+	   $(LN) `basename name.$(MANSRCSUFFIX)` `basename $@`; \	@@\
+	else \								@@\
+	     ClearmakeOSName \
+	     $(RAWCPP) CppNoLineInfoOption $(MANDEFS) defs \		@@\
+	     < name.$(MANSRCSUFFIX) | CppSedMagic >$@; \		@@\
+	fi								@@\
+									@@\
+clean::									@@\
+	RemoveFile(name.$(MANNEWSUFFIX))
+#endif /* CppManTarget */
+
+/*
+ * MakeDirectories - generate rules to create a hierarchy of directories.
+ */
+#ifndef MakeDirectories
+#define MakeDirectories(step,dirs)					@@\
+step::									@@\
+	DirFailPrefix@MakeFlagsToShellFlags(i,set +e); \		@@\
+	for i in dirs; do if [ -d $(DESTDIR)$$i ]; then \		@@\
+		set +x; else (set -x; $(MKDIRHIER) $(DESTDIR)$$i); fi; \ @@\
+	done
+#endif /* MakeDirectories */
+
+
+/*
+ * AllTarget - generate rules to build necessary things during make all.
+ */
+#ifndef AllTarget
+#define AllTarget(depends)						@@\
+all:: depends
+#endif /* AllTarget */
+
+#ifdef DefineOldLibraryRules
+#include <oldlib.rules>
+#endif
+
+#ifndef StaticLibrary
+#define StaticLibrary(libpath,libname) Concat3(libpath,/,LibraryTargetName(libname))
+#endif
+
+/*
+ * MakeMutex - generate mutex rules for parallel make
+ */
+#ifndef MakeMutex
+#ifdef MutexDirective
+#define MakeMutex(targets)						@@\
+MutexDirective:	targets
+#endif /* MutexDirective */
+#endif /* MakeMutex */
+
+/*
+ * Rules for dynamic modules.  These are primarily used by XFree86
+ */
+
+#ifndef LinkBuildModule
+#ifdef UseInstalled
+#define LinkBuildModule(module,subdir) $(_NULLCMD_)
+#else
+#define LinkBuildModule(module,subdir)\
+	MakeDir($(BUILDMODULEDIR)/subdir)				@@\
+	RemoveFile($(BUILDMODULEDIR)/subdir/module)			@@\
+	@(UP="`$(REVPATH) subdir`"; set -x; \				@@\
+	  cd $(BUILDMODULEDIR)/subdir && \				@@\
+		$(LN) $(BUILDMODULETOP)/$${UP}$(CURRENT_DIR)/module .)
+#endif
+#endif /* LinkBuildModule */
+
+#ifndef LinkBuildNamedModule
+#ifdef UseInstalled
+#define LinkBuildNamedModule(module,name,subdir) $(_NULLCMD_)
+#else
+#define LinkBuildNamedModule(module,name,subdir)\
+	MakeDir($(BUILDMODULEDIR)/subdir)				@@\
+	RemoveFile($(BUILDMODULEDIR)/subdir/name)			@@\
+	@(UP="`$(REVPATH) subdir`"; set -x; \				@@\
+	  cd $(BUILDMODULEDIR)/subdir && \				@@\
+		$(LN) $(BUILDMODULETOP)/$${UP}$(CURRENT_DIR)/module name)
+#endif
+#endif /* LinkBuildNamedModule */
+
+/*
+ * ModuleObjectRule
+ */
+#ifndef ModuleObjectRule
+#define ModuleObjectRule() NormalLibraryObjectRule()
+#endif
+
+/*
+ * ObjectModuleTarget - build a module as a single object file
+ */
+#ifndef ObjectModuleTarget
+#if MakeDllModules && DoLoadableServer
+#define ObjectModuleTarget(module,objects)				@@\
+DynamicModuleTarget(Concat(module,_drv.so), objects)
+#else
+#define ObjectModuleTarget(module,objects)				@@\
+NormalRelocatableTarget(Concat(module,_drv), objects)
+#endif
+#endif
+
+/*
+ * LibraryModuleTarget
+ */
+#ifndef LibraryModuleTarget
+#if MakeDllModules && DoLoadableServer
+#define LibraryModuleTarget(module,objects)				@@\
+NormalLibraryTarget(module, objects)					@@\
+DynamicModuleTarget(Concat3(lib,module,.so), objects)
+#else
+#define LibraryModuleTarget(module, objects)				@@\
+NormalLibraryTarget(module, objects)
+#endif
+#endif
+
+/*
+ * DepLibraryModuleTarget
+ */
+#ifndef DepLibraryModuleTarget
+#if MakeDllModules && DoLoadableServer
+#define DepLibraryModuleTarget(module,deplist,objects)			@@\
+NormalDepLibraryTarget(module, deplist, objects)			@@\
+DepDynamicModuleTarget(Concat3(lib,module,.so), deplist, objects)
+#else
+#define DepLibraryModuleTarget(module,deplist,objects)			@@\
+NormalDepLibraryTarget(module, deplist, objects)
+#endif
+#endif
+
+/*
+ * DynamicModuleTarget - build a module to be dynamically loaded
+ */
+#ifndef DynamicModuleTarget
+#define DynamicModuleTarget(module,modlist)				@@\
+AllTarget(module)							@@\
+									@@\
+module: modlist								@@\
+	RemoveFile($@)							@@\
+	$(CC) -o $@ $(SHLIBLDFLAGS) $(NOSTDLIB) modlist $(POSTNOSTDLIB) @@\
+									@@\
+clean::									@@\
+	RemoveFile(module)
+#endif /* DynamicModuleTarget */
+
+/*
+ * DepDynamicModuleTarget - build a module to be dynamically loaded
+ */
+#ifndef DepDynamicModuleTarget
+#define DepDynamicModuleTarget(module,deplist,modlist)			@@\
+AllTarget(module)							@@\
+									@@\
+module: deplist								@@\
+	RemoveFile($@)							@@\
+	$(CC) -o $@ $(SHLIBLDFLAGS) $(NOSTDLIB) modlist $(POSTNOSTDLIB) @@\
+									@@\
+clean::									@@\
+	RemoveFile(module)
+#endif /* DepDynamicModuleTarget */
+
+/*
+ * InstallDynamicModule - install a dynamic module
+ */
+#ifndef InstallDynamicModule
+#define InstallDynamicModule(module,dest,subdir)			@@\
+AllTarget(module)							@@\
+	LinkBuildModule(module,subdir)					@@\
+									@@\
+install:: module							@@\
+	MakeDir($(DESTDIR)dest/subdir)					@@\
+	$(INSTALL) -c $(INSTDATFLAGS) module $(DESTDIR)dest/subdir
+#endif
+
+#ifndef InstallDynamicNamedModule
+#define InstallDynamicNamedModule(module,instname,dest,subdir)		@@\
+AllTarget(module)							@@\
+	LinkBuildNamedModule(module,instname,subdir)			@@\
+									@@\
+install:: module							@@\
+	MakeDir($(DESTDIR)dest/subdir)					@@\
+	$(INSTALL) -c $(INSTDATFLAGS) module $(DESTDIR)dest/subdir/instname
+#endif
+
+/* Shortcuts for installing driver module, one per class */
+#ifndef InstallVideoObjectModule
+#define InstallVideoObjectModule(module,dest)                          @@\
+InstallObjectModule(module,dest,drivers)
+#endif
+#ifndef InstallInputObjectModule
+#define InstallInputObjectModule(module,dest)                          @@\
+InstallObjectModule(module,dest,input)
+#endif
+#ifndef InstallExtensionsObjectModule
+#define InstallExtensionsObjectModule(module,dest)                     @@\
+InstallObjectModule(module,dest,extensions)
+#endif
+#ifndef InstallFontsObjectModule
+#define InstallFontsObjectModule(module,dest)                          @@\
+InstallObjectModule(module,dest,fonts)
+#endif
+#ifndef InstallMultimediaObjectModule
+#define InstallMultimediaObjectModule(module,dest)                     @@\
+InstallObjectModule(module,dest,multimedia)
+#endif
+
+#ifndef InstallObjectModule
+#if !DoLoadableServer
+#define InstallObjectModule(module,dest,subdir)	/**/
+#else
+#if MakeDllModules
+#define InstallObjectModule(module,dest,subdir)				@@\
+InstallDynamicModule(Concat(module,_drv.so),dest,subdir)
+#else
+#define InstallObjectModule(module,dest,subdir)				@@\
+InstallDynamicModule(Concat(module,_drv.o),dest,subdir)
+#endif
+#endif
+#endif
+
+#ifndef InstallLibraryModule
+#if !DoLoadableServer
+#define InstallLibraryModule(module,dest,subdir)	/**/
+#else
+#if MakeDllModules
+#define InstallLibraryModule(module,dest,subdir)			@@\
+InstallDynamicModule(Concat3(lib,module,.so),dest,subdir)
+#else
+#define InstallLibraryModule(module,dest,subdir)			@@\
+InstallDynamicModule(ModuleLibraryTargetName(module),dest,subdir)
+#endif
+#endif
+#endif
+
+#ifndef InstallModuleManPage
+#define InstallModuleManPage(module)					@@\
+InstallGenManPage(module,$(DRIVERMANDIR),$(DRIVERMANSUFFIX))
+#endif
+
+#ifndef BuildObjectFromLibraryWithPath
+#define BuildObjectFromLibraryWithPath(libpath,libname,objname)		@@\
+AllTarget(objname.Osuf)							@@\
+									@@\
+objname.Osuf: Concat3(libpath,/lib,libname.a)				@@\
+	@$(MKDIRHIER) tmp						@@\
+	@$(CP) Concat3(libpath,/lib,libname.a) tmp			@@\
+	@(cd tmp; set -x; ArExtCmd Concat(lib,libname.a); \		@@\
+	  $(LD) $(LDCOMBINEFLAGS) *.Osuf -o ../$@; \			@@\
+	  RemoveFiles(*.Osuf))						@@\
+	@$(RM) -r tmp							@@\
+									@@\
+clean::									@@\
+	RemoveFile(objname.Osuf)
+#endif
+
+#ifndef BuildObjectFromLibrary
+#define BuildObjectFromLibrary(libname,objname) BuildObjectFromLibraryWithPath(.,libname,objname)
+#endif
+
+/*
+ * LinkerRuntimeLibraryPathFlag - defined here to be a no-op for systems that
+ * don't need it.   Overridden in system-specific config files for systems that
+ * need it, usually with something like "Concat(-R,path)"
+ */
+#ifndef LinkerRuntimeLibraryPathFlag
+# define LinkerRuntimeLibraryPathFlag(path)  /* */
+#endif
+
+/* Phony targets - GNU make has a feature to mark a target as phony,
+ * which means that it wont consider that target to be the name of a
+ * file.  In general this speeds up make, since it doesn't have to
+ * look for those files when it sets out to create a phony target.
+ * However, on cygwin, this is actually required for correct
+ * operation, since the Win32 filesystems are case insensitive and the
+ * install target conflicts with the INSTALL file present in some
+ * (autotooled) directories.
+ *
+ * We probably don't need the #ifdef protection, since other make
+ * implementations would just consider this a normal rule.  Better
+ * safe than sorry, though.
+ */
+#if HasGnuMake
+.PHONY: all interfaces install install.man install.lib install.sdk \
+	depend includes clean
+#endif
--- a/XORG_NV/sun-src/xc/config/cf/host.def	Tue Oct 24 16:13:31 2006 -0700
+++ b/XORG_NV/sun-src/xc/config/cf/host.def	Tue Oct 24 18:42:11 2006 -0700
@@ -29,7 +29,7 @@
 XCOMM
 XCOMM #########################################################################
 XCOMM
-XCOMM ident "@(#)host.def 1.46     06/03/28 SMI"
+XCOMM ident	"@(#)host.def	1.47	06/10/25 SMI"
 XCOMM
 
 /* Settings for official Solaris package builds */
@@ -65,6 +65,9 @@
 #define BuildXDriInfo		NO
 #endif
 
+#define BuildGlxExt		YES
+#define BuildXF86DRI		YES
+
 /* Used in error messages in the form "send the error log to ____" */
 #define BuilderEmailAddr	"your technical support contact"
 /* Used in error messages in the form "check ____  for latest version" */
@@ -99,7 +102,7 @@
 #endif
 
 /* Set optimizer flags for correct Sun cc version */
-#if HasSunC 
+#if HasSunC
 /* # define UseCCMakeDepend	YES  XXX: FIXME
 # define DependFlags		-cc $(CC) -d -xM */
 # ifndef OSServerExtraDefines
@@ -119,7 +122,7 @@
 /* Too long of a string breaks builds on Solaris 9 for some reason */
       MCS_BUILD_ID = Sun Xorg Release SunXOrgVersionNumber (X.Org X11R/**/XorgVersionString - `date +'%e %B %Y'`)
 #else
-#if OSTeenyVersion != 0 
+#if OSTeenyVersion != 0
       SOLARIS_VERSION:sh = printf "%s.%s" OSMinorVersion OSTeenyVersion
 #else
       SOLARIS_VERSION = OSMinorVersion
@@ -140,7 +143,7 @@
 # ifdef SparcArchitecture
 #  if OSMinorVersion == 9
 XCOMM Solaris 9 sparc linker causes build failures when used with normal
-XCOMM mapfile_pga_sparc so we just use this one for S9 sparc builds 
+XCOMM mapfile_pga_sparc so we just use this one for S9 sparc builds
 #   define MapFilePGA /usr/lib/ld/map.noexstk
 #  else
 #   define MapFilePGA $(CONFIGSRC)/mapfiles/mapfile_pga_sparc
@@ -157,7 +160,7 @@
 
 /* Make loadable modules link to their own symbols first to avoid cross-module
    symbol clashes */
-#if HasSunC 
+#if HasSunC
 MODULE_GCC_FLAGS = -xldscope=symbolic
 #endif
 
@@ -275,3 +278,21 @@
 									@@\
 InstallGenManPage(module,$(DRIVERMANDIR),$(DRIVERMANSUFFIX))
 #endif
+
+#define DriDrivers i915
+
+# ifndef SharedDriModuleTarget
+#  define SharedDriModuleTarget(name,deps,solist)			@@\
+AllTarget(name)								@@\
+									@@\
+name: deps								@@\
+	$(RM) $@~ [email protected]						@@\
+	$(CC) -o $@~ $(SHLIBLDFLAGS) solist $(REQUIREDLIBS)		@@\
+	$(RM) $@ [email protected]							@@\
+	$(MV) $@~ $@							@@\
+									@@\
+clean::									@@\
+	$(RM) name							@@\
+	$(RM) name.map
+
+# endif /* SharedDriModuleTarget */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/extras/Mesa/src/glx/x11/Makefile	Tue Oct 24 18:42:11 2006 -0700
@@ -0,0 +1,97 @@
+TOP = ../../..
+include $(TOP)/configs/current
+
+DEFINES += -DXF86VIDMODE -D_REENTRANT -UIN_DRI_DRIVER
+
+C_SOURCES = \
+	  $(TOP)/src/mesa/glapi/glapi.c \
+	  $(TOP)/src/mesa/glapi/glthread.c \
+	  $(TOP)/src/mesa/main/dispatch.c \
+	  glcontextmodes.c \
+	  clientattrib.c \
+	  compsize.c \
+	  eval.c \
+	  glxcmds.c \
+	  glxext.c \
+	  glxextensions.c \
+	  indirect.c \
+	  indirect_init.c \
+	  indirect_size.c \
+	  indirect_window_pos.c \
+	  indirect_transpose_matrix.c \
+	  indirect_vertex_array.c \
+	  indirect_vertex_program.c \
+	  pixel.c \
+	  pixelstore.c \
+	  render2.c \
+	  renderpix.c \
+	  single2.c \
+	  singlepix.c \
+	  vertarr.c \
+	  xfont.c \
+	  glx_pbuffer.c \
+	  glx_query.c \
+	  glx_texture_compression.c \
+	  dri_glx.c \
+	  XF86dri.c \
+
+X86_SOURCES = $(TOP)/src/mesa/x86/glapi_x86.S
+X86-64_SOURCES = $(TOP)/src/mesa/x86-64/glapi_x86-64.S
+
+# ASM_SOURCES = $(X86_SOURCES)
+
+OBJECTS = $(C_SOURCES:.c=.o) \
+	  $(ASM_SOURCES:.S=.o)
+
+INCLUDES = -I. \
+	-I$(TOP)/include \
+	-I$(TOP)/include/X11 \
+	-I$(TOP)/include/GL/internal \
+	-I$(TOP)/src/mesa/main \
+	-I$(TOP)/src/mesa/glapi \
+	-I$(TOP)/src/mesa/drivers/dri/common \
+	-I$(DRM_SOURCE_PATH)/libdrm \
+	-I$(DRM_SOURCE_PATH)/shared \
+	-I/usr/include \
+	$(X11_INCLUDES)
+
+
+##### RULES #####
+
+.c.o:
+	$(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
+
+.S.o:
+	$(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES)  $< -o $@
+
+##### TARGETS #####
+
+default: depend $(LIB_DIR)/$(GL_LIB_NAME)
+
+glcontextmodes.c:
+	ln -s $(TOP)/src/mesa/drivers/dri/common/glcontextmodes.c .
+
+# Make libGL
+$(LIB_DIR)/$(GL_LIB_NAME):  $(OBJECTS) Makefile
+	$(TOP)/bin/mklib -o $(GL_LIB) -linker '$(CC)' \
+		-major 1 -minor 2 $(MKLIB_OPTIONS) \
+		-install $(LIB_DIR) $(GL_LIB_DEPS) $(OBJECTS)
+
+
+depend: $(C_SOURCES) $(ASM_SOURCES) Makefile
+	touch depend
+	$(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(C_SOURCES) $(ASM_SOURCES) 
+
+
+# Emacs tags
+tags:
+	etags `find . -name \*.[ch]` `find ../include`
+
+
+# Remove .o and backup files
+clean:
+	-rm -f $(LIB_DIR)/libGL.so*
+	-rm -f *.o *~
+	-rm -f depend
+
+include depend
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/extras/Mesa/src/mesa/drivers/dri/Makefile.template	Tue Oct 24 18:42:11 2006 -0700
@@ -0,0 +1,95 @@
+# -*-makefile-*-
+
+MESA_MODULES = $(TOP)/src/mesa/mesa.a
+
+COMMON_SOURCES = \
+        ../../common/driverfuncs.c \
+        ../common/utils.c \
+        ../common/texmem.c \
+        ../common/vblank.c \
+        ../common/dri_util.c \
+        ../common/xmlconfig.c \
+        ../common/drirenderbuffer.c
+
+WINOBJ=
+WINLIB=
+INCLUDES = $(SHARED_INCLUDES) $(EXPAT_INCLUDES) \
+	   -I$(DRM_SOURCE_PATH)/shared-core \
+	   -I$(DRM_SOURCE_PATH)/libdrm \
+
+OBJECTS = $(C_SOURCES:.c=.o) \
+	  $(ASM_SOURCES:.S=.o) 
+
+
+### Include directories
+SHARED_INCLUDES = \
+	-I. \
+	-I$(TOP)/src/mesa/drivers/dri/common \
+	-Iserver \
+	-I$(DRM_SOURCE_PATH)/shared-core \
+	-I$(TOP)/include \
+	-I$(TOP)/include/GL/internal \
+	-I$(TOP)/src/mesa \
+	-I$(TOP)/src/mesa/main \
+	-I$(TOP)/src/mesa/glapi \
+	-I$(TOP)/src/mesa/math \
+	-I$(TOP)/src/mesa/transform \
+	-I$(TOP)/src/mesa/shader \
+	-I$(TOP)/src/mesa/swrast \
+	-I$(TOP)/src/mesa/swrast_setup \
+	-I$(TOP)/src/egl/main \
+	-I$(TOP)/src/egl/drivers/dri
+
+##### RULES #####
+
+.c.o:
+	$(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
+
+.S.o:
+	$(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES)  $< -o $@
+
+
+##### TARGETS #####
+
+default: depend symlinks $(LIBNAME) $(LIB_DIR)/$(LIBNAME)
+
+
+#$(LIB_DIR)/$(LIBNAME): $(OBJECTS) $(MESA_MODULES) $(WINOBJ) Makefile
+#	@echo BUILDING FOR: $(WINDOW_SYSTEM)
+#	$(TOP)/bin/mklib -o $(LIBNAME) -noprefix -install $(LIB_DIR) \
+#		$(WINLIB) $(LIB_DEPS) $(WINOBJ) $(MESA_MODULES) $(OBJECTS)
+
+# XXX we should use the mklib script here
+$(LIBNAME):  $(OBJECTS) $(MESA_MODULES) $(WINOBJ) Makefile $(TOP)/src/mesa/drivers/dri/Makefile.template
+	rm -f $@ 
+	$(CC) $(ARCH_FLAGS) -o $@ -shared $(OBJECTS) $(MESA_MODULES) $(WINOBJ) $(DRI_LIB_DEPS)
+
+
+$(LIB_DIR)/$(LIBNAME): $(LIBNAME)
+	/usr/ucb/install  $(LIBNAME) $(LIB_DIR)
+
+
+
+# Run 'make depend' to update the dependencies if you change
+# what's included by any source file.
+.PHONY: depend
+depend: $(C_SOURCES) $(ASM_SOURCES) $(SYMLINKS)
+	touch depend
+	$(MKDEP) $(MKDEP_OPTIONS) $(DEFINES) $(INCLUDES) $(C_SOURCES) $(ASM_SOURCES) \
+		> /dev/null 
+
+
+# Emacs tags
+tags:
+	etags `find . -name \*.[ch]` `find ../include`
+
+
+# Remove .o and backup files
+clean:
+	-rm -f *.o */*.o *~ *.so *~ server/*.o $(SYMLINKS)
+	-rm -f depend depend.bak
+
+install: $(LIBNAME)
+	install $(LIBNAME) /usr/X11R6/lib/modules/dri/$(LIBNAME)
+
+include depend
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/extras/Mesa/src/mesa/drivers/dri/common/dri_util.h	Tue Oct 24 18:42:11 2006 -0700
@@ -0,0 +1,559 @@
+/* $XFree86: xc/lib/GL/dri/dri_util.h,v 1.1 2002/02/22 21:32:52 dawes Exp $ */
+/**
+ * \file dri_util.h
+ * DRI utility functions definitions.
+ *
+ * This module acts as glue between GLX and the actual hardware driver.  A DRI
+ * driver doesn't really \e have to use any of this - it's optional.  But, some
+ * useful stuff is done here that otherwise would have to be duplicated in most
+ * drivers.
+ * 
+ * Basically, these utility functions take care of some of the dirty details of
+ * screen initialization, context creation, context binding, DRM setup, etc.
+ *
+ * These functions are compiled into each DRI driver so libGL.so knows nothing
+ * about them.
+ *
+ * \sa dri_util.c.
+ * 
+ * \author Kevin E. Martin <[email protected]>
+ * \author Brian Paul <[email protected]>
+ */
+
+/*
+ * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+ * 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, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#ifndef _DRI_UTIL_H_
+#define _DRI_UTIL_H_
+
+#define CAPI  /* XXX this should be globally defined somewhere */
+
+#include <GL/gl.h>
+#include "drm.h"
+#include "drm_sarea.h"
+#include "xf86drm.h"
+#include "GL/internal/glcore.h"
+#include "GL/internal/dri_interface.h"
+
+#define GLX_BAD_CONTEXT                    5
+
+#define u_int64_t uint64_t
+#define u_int32_t uint32_t
+#define u_int8_t uint8_t
+
+typedef struct __DRIdisplayPrivateRec  __DRIdisplayPrivate;
+typedef struct __DRIscreenPrivateRec   __DRIscreenPrivate;
+typedef struct __DRIcontextPrivateRec  __DRIcontextPrivate;
+typedef struct __DRIdrawablePrivateRec __DRIdrawablePrivate;
+typedef struct __DRIswapInfoRec        __DRIswapInfo;
+typedef struct __DRIutilversionRec2    __DRIutilversion2;
+
+
+/**
+ * Used by DRI_VALIDATE_DRAWABLE_INFO
+ */
+#define DRI_VALIDATE_DRAWABLE_INFO_ONCE(pDrawPriv)              \
+    do {                                                        \
+	if (*(pDrawPriv->pStamp) != pDrawPriv->lastStamp) {     \
+	    __driUtilUpdateDrawableInfo(pDrawPriv);             \
+	}                                                       \
+    } while (0)
+
+
+/**
+ * Utility macro to validate the drawable information.
+ *
+ * See __DRIdrawablePrivate::pStamp and __DRIdrawablePrivate::lastStamp.
+ */
+#define DRI_VALIDATE_DRAWABLE_INFO(psp, pdp)                            \
+do {                                                                    \
+    while (*(pdp->pStamp) != pdp->lastStamp) {                          \
+	DRM_UNLOCK(psp->fd, &psp->pSAREA->lock,                         \
+		   pdp->driContextPriv->hHWContext);                    \
+                                                                        \
+	DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);     \
+	DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp);                           \
+	DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);   \
+                                                                        \
+	DRM_LIGHT_LOCK(psp->fd, &psp->pSAREA->lock,                     \
+		       pdp->driContextPriv->hHWContext);                \
+    }                                                                   \
+} while (0)
+
+
+/**
+ * Driver callback functions.
+ *
+ * Each DRI driver must have one of these structures with all the pointers set
+ * to appropriate functions within the driver.
+ * 
+ * When glXCreateContext() is called, for example, it'll call a helper function
+ * dri_util.c which in turn will jump through the \a CreateContext pointer in
+ * this structure.
+ */
+struct __DriverAPIRec {
+    /** 
+     * Driver initialization callback
+     */
+    GLboolean (*InitDriver)(__DRIscreenPrivate *driScrnPriv);
+    
+    /**
+     * Screen destruction callback
+     */
+    void (*DestroyScreen)(__DRIscreenPrivate *driScrnPriv);
+
+    /**
+     * Context creation callback
+     */	    	    
+    GLboolean (*CreateContext)(const __GLcontextModes *glVis,
+                               __DRIcontextPrivate *driContextPriv,
+                               void *sharedContextPrivate);
+
+    /**
+     * Context destruction callback
+     */
+    void (*DestroyContext)(__DRIcontextPrivate *driContextPriv);
+
+    /**
+     * Buffer (drawable) creation callback
+     */
+    GLboolean (*CreateBuffer)(__DRIscreenPrivate *driScrnPriv,
+                              __DRIdrawablePrivate *driDrawPriv,
+                              const __GLcontextModes *glVis,
+                              GLboolean pixmapBuffer);
+    
+    /**
+     * Buffer (drawable) destruction callback
+     */
+    void (*DestroyBuffer)(__DRIdrawablePrivate *driDrawPriv);
+
+    /**
+     * Buffer swapping callback 
+     */
+    void (*SwapBuffers)(__DRIdrawablePrivate *driDrawPriv);
+
+    /**
+     * Context activation callback
+     */
+    GLboolean (*MakeCurrent)(__DRIcontextPrivate *driContextPriv,
+                             __DRIdrawablePrivate *driDrawPriv,
+                             __DRIdrawablePrivate *driReadPriv);
+
+    /**
+     * Context unbinding callback
+     */
+    GLboolean (*UnbindContext)(__DRIcontextPrivate *driContextPriv);
+  
+    /**
+     * Retrieves statistics about buffer swap operations.  Required if
+     * GLX_OML_sync_control or GLX_MESA_swap_frame_usage is supported.
+     */
+    int (*GetSwapInfo)( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo );
+
+
+    /**
+     * Required if GLX_SGI_video_sync or GLX_OML_sync_control is
+     * supported.
+     */
+    int (*GetMSC)( __DRIscreenPrivate * priv, int64_t * count );
+
+    /**
+     * These are required if GLX_OML_sync_control is supported.
+     */
+    /*@{*/
+    int (*WaitForMSC)( __DRIdrawablePrivate *priv, int64_t target_msc, 
+		       int64_t divisor, int64_t remainder,
+		       int64_t * msc );
+    int (*WaitForSBC)( __DRIdrawablePrivate *priv, int64_t target_sbc,
+		       int64_t * msc, int64_t * sbc );
+
+    int64_t (*SwapBuffersMSC)( __DRIdrawablePrivate *priv, int64_t target_msc,
+			       int64_t divisor, int64_t remainder );
+    /*@}*/
+};
+
+
+struct __DRIswapInfoRec {
+    /** 
+     * Number of swapBuffers operations that have been *completed*. 
+     */
+    u_int64_t swap_count;
+
+    /**
+     * Unadjusted system time of the last buffer swap.  This is the time
+     * when the swap completed, not the time when swapBuffers was called.
+     */
+    int64_t   swap_ust;
+
+    /**
+     * Number of swap operations that occurred after the swap deadline.  That
+     * is if a swap happens more than swap_interval frames after the previous
+     * swap, it has missed its deadline.  If swap_interval is 0, then the
+     * swap deadline is 1 frame after the previous swap.
+     */
+    u_int64_t swap_missed_count;
+
+    /**
+     * Amount of time used by the last swap that missed its deadline.  This
+     * is calculated as (__glXGetUST() - swap_ust) / (swap_interval * 
+     * time_for_single_vrefresh)).  If the actual value of swap_interval is
+     * 0, then 1 is used instead.  If swap_missed_count is non-zero, this
+     * should be greater-than 1.0.
+     */
+    float     swap_missed_usage;
+};
+
+
+/**
+ * Per-drawable private DRI driver information.
+ */
+struct __DRIdrawablePrivateRec {
+    /**
+     * Kernel drawable handle
+     */
+    drm_drawable_t hHWDrawable;
+
+    /**
+     * Driver's private drawable information.  
+     *
+     * This structure is opaque.
+     */
+    void *driverPrivate;
+
+    /**
+     * X's drawable ID associated with this private drawable.
+     */
+    __DRIid draw;
+    __DRIdrawable *pdraw;
+
+    /**
+     * Reference count for number of context's currently bound to this
+     * drawable.  
+     *
+     * Once it reaches zero, the drawable can be destroyed.
+     *
+     * \note This behavior will change with GLX 1.3.
+     */
+    int refcount;
+
+    /**
+     * Index of this drawable information in the SAREA.
+     */
+    unsigned int index;
+
+    /**
+     * Pointer to the "drawable has changed ID" stamp in the SAREA.
+     */
+    unsigned int *pStamp;
+
+    /**
+     * Last value of the stamp.
+     *
+     * If this differs from the value stored at __DRIdrawablePrivate::pStamp,
+     * then the drawable information has been modified by the X server, and the
+     * drawable information (below) should be retrieved from the X server.
+     */
+    unsigned int lastStamp;
+
+    /**
+     * \name Drawable 
+     *
+     * Drawable information used in software fallbacks.
+     */
+    /*@{*/
+    int x;
+    int y;
+    int w;
+    int h;
+    int numClipRects;
+    drm_clip_rect_t *pClipRects;
+    /*@}*/
+
+    /**
+     * \name Back and depthbuffer
+     *
+     * Information about the back and depthbuffer where different from above.
+     */
+    /*@{*/
+    int backX;
+    int backY;
+    int backClipRectType;
+    int numBackClipRects;
+    drm_clip_rect_t *pBackClipRects;
+    /*@}*/
+
+    /**
+     * Pointer to context to which this drawable is currently bound.
+     */
+    __DRIcontextPrivate *driContextPriv;
+
+    /**
+     * Pointer to screen on which this drawable was created.
+     */
+    __DRIscreenPrivate *driScreenPriv;
+
+    /**
+     * \name Display and screen information.
+     * 
+     * Basically just need these for when the locking code needs to call
+     * \c __driUtilUpdateDrawableInfo.
+     */
+    /*@{*/
+    __DRInativeDisplay *display;
+    int screen;
+    /*@}*/
+
+    /**
+     * Called via glXSwapBuffers().
+     */
+    void (*swapBuffers)( __DRIdrawablePrivate *dPriv );
+};
+
+/**
+ * Per-context private driver information.
+ */
+struct __DRIcontextPrivateRec {
+    /**
+     * Kernel context handle used to access the device lock.
+     */
+    __DRIid contextID;
+
+    /**
+     * Kernel context handle used to access the device lock.
+     */
+    drm_context_t hHWContext;
+
+    /**
+     * Device driver's private context data.  This structure is opaque.
+     */
+    void *driverPrivate;
+
+    /**
+     * This context's display pointer.
+     */
+    __DRInativeDisplay *display;
+
+    /**
+     * Pointer to drawable currently bound to this context.
+     */
+    __DRIdrawablePrivate *driDrawablePriv;
+
+    /**
+     * Pointer to screen on which this context was created.
+     */
+    __DRIscreenPrivate *driScreenPriv;
+};
+
+/**
+ * Per-screen private driver information.
+ */
+struct __DRIscreenPrivateRec {
+    /**
+     * Display for this screen
+     */
+    __DRInativeDisplay *display;
+
+    /**
+     * Current screen's number
+     */
+    int myNum;
+
+    /**
+     * Callback functions into the hardware-specific DRI driver code.
+     */
+    struct __DriverAPIRec DriverAPI;
+
+    /**
+     * \name DDX version
+     * DDX / 2D driver version information.
+     * \todo Replace these fields with a \c __DRIversionRec.
+     */
+    /*@{*/
+    int ddxMajor;
+    int ddxMinor;
+    int ddxPatch;
+    /*@}*/
+
+    /**
+     * \name DRI version
+     * DRI X extension version information.
+     * \todo Replace these fields with a \c __DRIversionRec.
+     */
+    /*@{*/
+    int driMajor;
+    int driMinor;
+    int driPatch;
+    /*@}*/
+
+    /**
+     * \name DRM version
+     * DRM (kernel module) version information.
+     * \todo Replace these fields with a \c __DRIversionRec.
+     */
+    /*@{*/
+    int drmMajor;
+    int drmMinor;
+    int drmPatch;
+    /*@}*/
+
+    /**
+     * ID used when the client sets the drawable lock.
+     *
+     * The X server uses this value to detect if the client has died while
+     * holding the drawable lock.
+     */
+    int drawLockID;
+
+    /**
+     * File descriptor returned when the kernel device driver is opened.
+     * 
+     * Used to:
+     *   - authenticate client to kernel
+     *   - map the frame buffer, SAREA, etc.
+     *   - close the kernel device driver
+     */
+    int fd;
+
+    /**
+     * SAREA pointer 
+     *
+     * Used to access:
+     *   - the device lock
+     *   - the device-independent per-drawable and per-context(?) information
+     */
+    drm_sarea_t *pSAREA;
+
+    /**
+     * \name Direct frame buffer access information 
+     * Used for software fallbacks.
+     */
+    /*@{*/
+    unsigned char *pFB;
+    int fbSize;
+    int fbOrigin;
+    int fbStride;
+    int fbWidth;
+    int fbHeight;
+    int fbBPP;
+    /*@}*/
+
+    /**
+     * \name Device-dependent private information (stored in the SAREA).
+     *
+     * This data is accessed by the client driver only.
+     */
+    /*@{*/
+    void *pDevPriv;
+    int devPrivSize;
+    /*@}*/
+
+    /**
+     * Dummy context to which drawables are bound when not bound to any
+     * other context. 
+     *
+     * A dummy hHWContext is created for this context, and is used by the GL
+     * core when a hardware lock is required but the drawable is not currently
+     * bound (e.g., potentially during a SwapBuffers request).  The dummy
+     * context is created when the first "real" context is created on this
+     * screen.
+     */
+    __DRIcontextPrivate dummyContextPriv;
+
+    /**
+     * Hash table to hold the drawable information for this screen.
+     */
+    void *drawHash;
+
+    /**
+     * Device-dependent private information (not stored in the SAREA).
+     * 
+     * This pointer is never touched by the DRI layer.
+     */
+    void *private;
+
+    /**
+     * GLX visuals / FBConfigs for this screen.  These are stored as a
+     * linked list.
+     * 
+     * \note
+     * This field is \b only used in conjunction with the old interfaces.  If
+     * the new interfaces are used, this field will be set to \c NULL and will
+     * not be dereferenced.
+     */
+    __GLcontextModes *modes;
+
+    /**
+     * Pointer back to the \c __DRIscreen that contains this structure.
+     */
+
+    __DRIscreen *psc;
+};
+
+
+/**
+ * Used to store a version which includes a major range instead of a single
+ * major version number.
+ */
+struct __DRIutilversionRec2 {
+    int    major_min;    /** min allowed Major version number. */
+    int    major_max;    /** max allowed Major version number. */
+    int    minor;        /**< Minor version number. */
+    int    patch;        /**< Patch-level. */
+};
+
+
+extern void
+__driUtilMessage(const char *f, ...);
+
+
+extern void
+__driUtilUpdateDrawableInfo(__DRIdrawablePrivate *pdp);
+
+
+extern __DRIscreenPrivate * __driUtilCreateNewScreen( __DRInativeDisplay *dpy,
+    int scrn, __DRIscreen *psc, __GLcontextModes * modes,
+    const __DRIversion * ddx_version, const __DRIversion * dri_version,
+    const __DRIversion * drm_version, const __DRIframebuffer * frame_buffer,
+    drm_sarea_t *pSAREA, int fd, int internal_api_version,
+    const struct __DriverAPIRec *driverAPI );
+
+/* Test the version of the internal GLX API.  Returns a value like strcmp. */
+extern int
+driCompareGLXAPIVersion( GLint required_version );
+
+extern float
+driCalculateSwapUsage( __DRIdrawablePrivate *dPriv,
+		       int64_t last_swap_ust, int64_t current_ust );
+
+/**
+ * Pointer to the \c __DRIinterfaceMethods passed to the driver by the loader.
+ * 
+ * This pointer is set in the driver's \c __driCreateNewScreen function and
+ * is defined in dri_util.c.
+ */
+extern const __DRIinterfaceMethods * dri_interface;
+
+#endif /* _DRI_UTIL_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/extras/Mesa/src/mesa/drivers/dri/i915/intel_context.h	Tue Oct 24 18:42:11 2006 -0700
@@ -0,0 +1,560 @@
+/**************************************************************************
+ * 
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS 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.
+ * 
+ **************************************************************************/
+
+#ifndef INTELCONTEXT_INC
+#define INTELCONTEXT_INC
+
+
+
+#include "mtypes.h"
+#include "drm.h"
+#include "mm.h"
+#include "texmem.h"
+
+#include "intel_screen.h"
+#include "i830_common.h"
+#include "tnl/t_vertex.h"
+
+#define TAG(x) intel##x
+#include "tnl_dd/t_dd_vertex.h"
+#undef TAG
+
+#if defined(sun)
+extern void _sigoff(void);
+extern void _sigon(void);
+#endif
+
+#define DV_PF_555  (1<<8)
+#define DV_PF_565  (2<<8)
+#define DV_PF_8888 (3<<8)
+
+#define INTEL_CONTEXT(ctx)	((intelContextPtr)(ctx))
+
+typedef struct intel_context intelContext;
+typedef struct intel_context *intelContextPtr;
+typedef struct intel_texture_object *intelTextureObjectPtr;
+
+typedef void (*intel_tri_func)(intelContextPtr, intelVertex *, intelVertex *,
+							  intelVertex *);
+typedef void (*intel_line_func)(intelContextPtr, intelVertex *, intelVertex *);
+typedef void (*intel_point_func)(intelContextPtr, intelVertex *);
+
+#define INTEL_FALLBACK_DRAW_BUFFER	 0x1
+#define INTEL_FALLBACK_READ_BUFFER	 0x2
+#define INTEL_FALLBACK_USER		 0x4
+#define INTEL_FALLBACK_NO_BATCHBUFFER	 0x8
+#define INTEL_FALLBACK_NO_TEXMEM	 0x10
+#define INTEL_FALLBACK_RENDERMODE	 0x20
+
+extern void intelFallback( intelContextPtr intel, GLuint bit, GLboolean mode );
+#define FALLBACK( intel, bit, mode ) intelFallback( intel, bit, mode )
+
+
+#define INTEL_TEX_MAXLEVELS 10
+
+
+struct intel_texture_object
+{
+   driTextureObject    base;	/* the parent class */
+
+   GLuint texelBytes;
+   GLuint age;
+   GLuint Pitch;
+   GLuint Height;
+   GLuint TextureOffset;
+   GLubyte *BufAddr;   
+
+   GLuint min_level;
+   GLuint max_level;
+   GLuint depth_pitch;
+
+   struct {
+      const struct gl_texture_image *image;
+      GLuint offset;       /* into BufAddr */
+      GLuint height;
+      GLuint internalFormat;
+   } image[6][INTEL_TEX_MAXLEVELS];
+
+   GLuint dirty;
+   GLuint firstLevel,lastLevel;
+};
+
+
+struct intel_context
+{
+   GLcontext ctx;		/* the parent class */
+
+   struct {
+      void (*destroy)( intelContextPtr intel ); 
+      void (*emit_state)( intelContextPtr intel );
+      void (*emit_invarient_state)( intelContextPtr intel );
+      void (*lost_hardware)( intelContextPtr intel );
+      void (*update_texture_state)( intelContextPtr intel );
+
+      void (*render_start)( intelContextPtr intel );
+      void (*set_draw_offset)( intelContextPtr intel, int offset );
+      void (*emit_flush)( intelContextPtr intel );
+
+      void (*reduced_primitive_state)( intelContextPtr intel, GLenum rprim );
+
+      GLboolean (*check_vertex_size)( intelContextPtr intel, GLuint expected );
+
+      void (*clear_with_tris)( intelContextPtr intel, GLbitfield mask,
+			       GLboolean all, 
+			       GLint cx, GLint cy, GLint cw, GLint ch);
+
+      intelTextureObjectPtr (*alloc_tex_obj)( struct gl_texture_object *tObj );
+
+   } vtbl;
+
+   GLint refcount;   
+   GLuint Fallback;
+   GLuint NewGLState;
+   
+   struct {
+      GLuint start_offset;
+      GLint size;
+      GLint space;
+      GLubyte *ptr;
+   } batch;
+      
+   struct {
+      void *ptr;
+      GLint size;
+      GLuint offset;
+      GLuint active_buf;
+      GLuint irq_emitted;
+   } alloc;
+
+   struct {
+      GLuint primitive;
+      GLubyte *start_ptr;      
+      void (*flush)( GLcontext * );
+   } prim;
+
+   GLboolean locked;
+
+   GLubyte clear_red;
+   GLubyte clear_green;
+   GLubyte clear_blue;
+   GLubyte clear_alpha;
+   GLuint ClearColor;
+   GLuint ClearDepth;
+
+   GLuint coloroffset;
+   GLuint specoffset;
+
+   /* Support for duplicating XYZW as WPOS parameter (crutch for I915).
+    */
+   GLuint wpos_offset;
+   GLuint wpos_size;
+
+   struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
+   GLuint vertex_attr_count;
+
+   GLfloat depth_scale;
+   GLfloat polygon_offset_scale; /* dependent on depth_scale, bpp */
+   GLuint depth_clear_mask;
+   GLuint stencil_clear_mask;
+
+   GLboolean hw_stencil;
+   GLboolean hw_stipple;
+   
+   /* Texture object bookkeeping
+    */
+   GLuint                nr_heaps;
+   driTexHeap          * texture_heaps[1];
+   driTextureObject      swapped;
+   GLuint                lastStamp;
+
+   struct intel_texture_object *CurrentTexObj[MAX_TEXTURE_UNITS];
+
+   /* State for intelvb.c and inteltris.c.
+    */
+   GLuint RenderIndex;
+   GLmatrix ViewportMatrix;
+   GLenum render_primitive;
+   GLenum reduced_primitive;
+   GLuint vertex_size;
+   char *verts;			/* points to tnl->clipspace.vertex_buf */
+
+
+   /* Fallback rasterization functions 
+    */
+   intel_point_func draw_point;
+   intel_line_func draw_line;
+   intel_tri_func draw_tri;
+
+   /* These refer to the current draw (front vs. back) buffer:
+    */
+   char *drawMap;		/* draw buffer address in virtual mem */
+   char *readMap;	
+   GLuint drawOffset;		/* agp offset of drawbuffer */
+   int drawX;			/* origin of drawable in draw buffer */
+   int drawY;
+   GLuint numClipRects;		/* cliprects for that buffer */
+   drm_clip_rect_t *pClipRects;
+
+   int dirtyAge;
+   int perf_boxes;
+   int do_irqs;
+
+   GLboolean scissor;
+   drm_clip_rect_t draw_rect;
+   drm_clip_rect_t scissor_rect;
+
+   drm_context_t hHWContext;
+   drmLock *driHwLock;
+   int driFd;
+
+   __DRIdrawablePrivate *driDrawable;
+   __DRIscreenPrivate *driScreen;
+   intelScreenPrivate *intelScreen; 
+   drmI830Sarea *sarea; 
+
+   /**
+    * Configuration cache
+    */
+   driOptionCache optionCache;
+};
+
+
+#define DEBUG_LOCKING	1
+
+#if DEBUG_LOCKING
+extern char *prevLockFile;
+extern int prevLockLine;
+
+#define DEBUG_LOCK()							\
+   do {									\
+      prevLockFile = (__FILE__);					\
+      prevLockLine = (__LINE__);					\
+   } while (0)
+
+#define DEBUG_RESET()							\
+   do {									\
+      prevLockFile = 0;							\
+      prevLockLine = 0;							\
+   } while (0)
+
+/* Slightly less broken way of detecting recursive locking in a
+ * threaded environment.  The right way to do this would be to make
+ * prevLockFile, prevLockLine thread-local.
+ *
+ * This technique instead checks to see if the same context is
+ * requesting the lock twice -- this will not catch application
+ * breakages where the same context is active in two different threads
+ * at once, but it will catch driver breakages (recursive locking) in
+ * threaded apps.
+ */
+#define DEBUG_CHECK_LOCK()						\
+   do {									\
+      if ( *((volatile int *)intel->driHwLock) == 			\
+	   (DRM_LOCK_HELD | intel->hHWContext) ) {			\
+	 fprintf( stderr,						\
+		  "LOCK SET!\n\tPrevious %s:%d\n\tCurrent: %s:%d\n",	\
+		  prevLockFile, prevLockLine, __FILE__, __LINE__ );	\
+	 abort();							\
+      }									\
+   } while (0)
+
+#else
+
+#define DEBUG_LOCK()
+#define DEBUG_RESET()
+#define DEBUG_CHECK_LOCK()
+
+#endif
+
+
+
+
+/* Lock the hardware and validate our state.  
+ */
+#if defined(sun)
+#define LOCK_HARDWARE( intel )				\
+do {							\
+    char __ret=0;					\
+    DEBUG_CHECK_LOCK();					\
+    assert(!(intel)->locked);				\
+    _sigoff();                                          \
+    DRM_CAS((intel)->driHwLock, (intel)->hHWContext,	\
+        (DRM_LOCK_HELD|(intel)->hHWContext), __ret);	\
+    if (__ret)						\
+        intelGetLock( (intel), 0 );			\
+      DEBUG_LOCK();					\
+    (intel)->locked = 1;				\
+}while (0)
+
+#else
+
+#define LOCK_HARDWARE( intel )				\
+do {							\
+    char __ret=0;					\
+    DEBUG_CHECK_LOCK();					\
+    assert(!(intel)->locked);				\
+    DRM_CAS((intel)->driHwLock, (intel)->hHWContext,	\
+        (DRM_LOCK_HELD|(intel)->hHWContext), __ret);	\
+    if (__ret)						\
+        intelGetLock( (intel), 0 );			\
+      DEBUG_LOCK();					\
+    (intel)->locked = 1;				\
+}while (0)
+
+#endif
+ 
+  
+  /* Unlock the hardware using the global current context 
+   */
+#if defined(sun)
+#define UNLOCK_HARDWARE(intel)						\
+do {									\
+   intel->locked = 0;							\
+   if (0) { 								\
+      intel->perf_boxes |= intel->sarea->perf_boxes;  			\
+      intel->sarea->perf_boxes = 0;					\
+   }									\
+   DRM_UNLOCK((intel)->driFd, (intel)->driHwLock, (intel)->hHWContext);	\
+   DEBUG_RESET();							\
+   _sigon();                                                            \
+} while (0)
+
+#else
+
+#define UNLOCK_HARDWARE(intel)						\
+do {									\
+   intel->locked = 0;							\
+   if (0) { 								\
+      intel->perf_boxes |= intel->sarea->perf_boxes;  			\
+      intel->sarea->perf_boxes = 0;					\
+   }									\
+   DRM_UNLOCK((intel)->driFd, (intel)->driHwLock, (intel)->hHWContext);	\
+   DEBUG_RESET();							\
+} while (0)
+
+#endif
+
+
+#define SUBPIXEL_X 0.125
+#define SUBPIXEL_Y 0.125
+
+#define INTEL_FIREVERTICES(intel)		\
+do {						\
+   if ((intel)->prim.flush)			\
+      (intel)->prim.flush(&(intel)->ctx);		\
+} while (0)
+
+/* ================================================================
+ * Color packing:
+ */
+
+#define INTEL_PACKCOLOR4444(r,g,b,a) \
+  ((((a) & 0xf0) << 8) | (((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4))
+
+#define INTEL_PACKCOLOR1555(r,g,b,a) \
+  ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
+    ((a) ? 0x8000 : 0))
+
+#define INTEL_PACKCOLOR565(r,g,b) \
+  ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
+
+#define INTEL_PACKCOLOR8888(r,g,b,a) \
+  ((a<<24) | (r<<16) | (g<<8) | b)
+
+
+#define INTEL_PACKCOLOR(format, r,  g,  b, a)		\
+(format == DV_PF_555 ? INTEL_PACKCOLOR1555(r,g,b,a) :	\
+ (format == DV_PF_565 ? INTEL_PACKCOLOR565(r,g,b) :	\
+  (format == DV_PF_8888 ? INTEL_PACKCOLOR8888(r,g,b,a) :	\
+   0)))
+
+
+
+/* ================================================================
+ * From linux kernel i386 header files, copes with odd sizes better
+ * than COPY_DWORDS would:
+ */
+#if (defined(i386) || defined(__i386__)) && !(defined(__SOLARIS__) || defined(sun))
+static __inline__ void * __memcpy(void * to, const void * from, size_t n)
+{
+   int d0, d1, d2;
+   __asm__ __volatile__(
+      "rep ; movsl\n\t"
+      "testb $2,%b4\n\t"
+      "je 1f\n\t"
+      "movsw\n"
+      "1:\ttestb $1,%b4\n\t"
+      "je 2f\n\t"
+      "movsb\n"
+      "2:"
+      : "=&c" (d0), "=&D" (d1), "=&S" (d2)
+      :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from)
+      : "memory");
+   return (to);
+}
+#else
+#define __memcpy(a,b,c) memcpy(a,b,c)
+#endif
+
+
+
+/* ================================================================
+ * Debugging:
+ */
+#define DO_DEBUG		1
+#if DO_DEBUG
+extern int INTEL_DEBUG;
+#else
+#define INTEL_DEBUG		0
+#endif
+
+#define DEBUG_TEXTURE	0x1
+#define DEBUG_STATE	0x2
+#define DEBUG_IOCTL	0x4
+#define DEBUG_PRIMS	0x8
+#define DEBUG_VERTS	0x10
+#define DEBUG_FALLBACKS	0x20
+#define DEBUG_VERBOSE	0x40
+#define DEBUG_DRI       0x80
+#define DEBUG_DMA       0x100
+#define DEBUG_SANITY    0x200
+#define DEBUG_SYNC      0x400
+#define DEBUG_SLEEP     0x800
+#define DEBUG_PIXEL     0x1000
+
+
+#define PCI_CHIP_845_G			0x2562
+#define PCI_CHIP_I830_M			0x3577
+#define PCI_CHIP_I855_GM		0x3582
+#define PCI_CHIP_I865_G			0x2572
+#define PCI_CHIP_I915_G			0x2582
+#define PCI_CHIP_I915_GM		0x2592
+#define PCI_CHIP_I945_G			0x2772
+
+
+/* ================================================================
+ * intel_context.c:
+ */
+
+extern void intelInitDriverFunctions( struct dd_function_table *functions );
+
+extern GLboolean intelInitContext( intelContextPtr intel, 
+				   const __GLcontextModes *mesaVis,
+				   __DRIcontextPrivate *driContextPriv,
+				   void *sharedContextPrivate,
+				   struct dd_function_table *functions );
+
+extern void intelGetLock(intelContextPtr intel, GLuint flags);
+extern void intelSetBackClipRects(intelContextPtr intel);
+extern void intelSetFrontClipRects(intelContextPtr intel);
+extern void intelWindowMoved( intelContextPtr intel );
+
+extern void intelInitState( GLcontext *ctx );
+extern const GLubyte *intelGetString( GLcontext *ctx, GLenum name );
+
+
+/* ================================================================
+ * intel_state.c:
+ */
+extern void intelInitStateFuncs( struct dd_function_table *functions );
+
+#define COMPAREFUNC_ALWAYS		0
+#define COMPAREFUNC_NEVER		0x1
+#define COMPAREFUNC_LESS		0x2
+#define COMPAREFUNC_EQUAL		0x3
+#define COMPAREFUNC_LEQUAL		0x4
+#define COMPAREFUNC_GREATER		0x5
+#define COMPAREFUNC_NOTEQUAL		0x6
+#define COMPAREFUNC_GEQUAL		0x7
+
+#define STENCILOP_KEEP			0
+#define STENCILOP_ZERO			0x1
+#define STENCILOP_REPLACE		0x2
+#define STENCILOP_INCRSAT		0x3
+#define STENCILOP_DECRSAT		0x4
+#define STENCILOP_INCR			0x5
+#define STENCILOP_DECR			0x6
+#define STENCILOP_INVERT		0x7
+
+#define LOGICOP_CLEAR			0
+#define LOGICOP_NOR			0x1
+#define LOGICOP_AND_INV 		0x2
+#define LOGICOP_COPY_INV		0x3
+#define LOGICOP_AND_RVRSE		0x4
+#define LOGICOP_INV			0x5
+#define LOGICOP_XOR			0x6
+#define LOGICOP_NAND			0x7
+#define LOGICOP_AND			0x8
+#define LOGICOP_EQUIV			0x9
+#define LOGICOP_NOOP			0xa
+#define LOGICOP_OR_INV			0xb
+#define LOGICOP_COPY			0xc
+#define LOGICOP_OR_RVRSE		0xd
+#define LOGICOP_OR			0xe
+#define LOGICOP_SET			0xf
+
+#define BLENDFACT_ZERO			0x01
+#define BLENDFACT_ONE			0x02
+#define BLENDFACT_SRC_COLR		0x03
+#define BLENDFACT_INV_SRC_COLR 		0x04
+#define BLENDFACT_SRC_ALPHA		0x05
+#define BLENDFACT_INV_SRC_ALPHA 	0x06
+#define BLENDFACT_DST_ALPHA		0x07
+#define BLENDFACT_INV_DST_ALPHA 	0x08
+#define BLENDFACT_DST_COLR		0x09
+#define BLENDFACT_INV_DST_COLR		0x0a
+#define BLENDFACT_SRC_ALPHA_SATURATE	0x0b
+#define BLENDFACT_CONST_COLOR		0x0c
+#define BLENDFACT_INV_CONST_COLOR	0x0d
+#define BLENDFACT_CONST_ALPHA		0x0e
+#define BLENDFACT_INV_CONST_ALPHA	0x0f
+#define BLENDFACT_MASK          	0x0f
+
+
+extern int intel_translate_compare_func( GLenum func );
+extern int intel_translate_stencil_op( GLenum op );
+extern int intel_translate_blend_factor( GLenum factor );
+extern int intel_translate_logic_op( GLenum opcode );
+
+
+/* ================================================================
+ * intel_ioctl.c:
+ */
+extern void intel_dump_batchbuffer( long offset,
+				    int *ptr,
+				    int count );
+
+
+/* ================================================================
+ * intel_pixel.c:
+ */	
+extern void intelInitPixelFuncs( struct dd_function_table *functions );
+
+
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/extras/Mesa/src/mesa/drivers/dri/i915/intel_screen.c	Tue Oct 24 18:42:11 2006 -0700
@@ -0,0 +1,529 @@
+/**************************************************************************
+ * 
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS 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 <unistd.h>
+#include <signal.h>
+#include "glheader.h"
+#include "context.h"
+#include "framebuffer.h"
+#include "matrix.h"
+#include "renderbuffer.h"
+#include "simple_list.h"
+#include "utils.h"
+#include "xmlpool.h"
+
+
+#include "intel_screen.h"
+
+#include "intel_tex.h"
+#include "intel_span.h"
+#include "intel_tris.h"
+#include "intel_ioctl.h"
+
+
+
+#include "i830_dri.h"
+
+static void stop_handler(int sig)
+{
+	kill(getpid(), SIGSTOP);
+}
+static void exit_handler(int sig)
+{
+	_exit(1);
+}
+
+PUBLIC const char __driConfigOptions[] =
+DRI_CONF_BEGIN
+    DRI_CONF_SECTION_PERFORMANCE
+       DRI_CONF_FORCE_S3TC_ENABLE(false)
+    DRI_CONF_SECTION_END
+DRI_CONF_END;
+const GLuint __driNConfigOptions = 1;
+
+extern const struct dri_extension card_extensions[];
+
+static void intelPrintDRIInfo(intelScreenPrivate *intelScreen,
+			     __DRIscreenPrivate *sPriv,
+			    I830DRIPtr gDRIPriv)
+{
+   fprintf(stderr, "Front size : 0x%x\n", sPriv->fbSize);
+   fprintf(stderr, "Front offset : 0x%x\n", intelScreen->frontOffset);
+   fprintf(stderr, "Back size : 0x%x\n", intelScreen->back.size);
+   fprintf(stderr, "Back offset : 0x%x\n", intelScreen->backOffset);
+   fprintf(stderr, "Depth size : 0x%x\n", intelScreen->depth.size);
+   fprintf(stderr, "Depth offset : 0x%x\n", intelScreen->depthOffset);
+   fprintf(stderr, "Texture size : 0x%x\n", intelScreen->textureSize);
+   fprintf(stderr, "Texture offset : 0x%x\n", intelScreen->textureOffset);
+   fprintf(stderr, "Memory : 0x%x\n", gDRIPriv->mem);
+}
+
+static GLboolean intelInitDriver(__DRIscreenPrivate *sPriv)
+{
+   intelScreenPrivate *intelScreen;
+   I830DRIPtr         gDRIPriv = (I830DRIPtr)sPriv->pDevPriv;
+   PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension =
+     (PFNGLXSCRENABLEEXTENSIONPROC) (*dri_interface->getProcAddress("glxEnableExtension"));
+   void * const psc = sPriv->psc->screenConfigs;
+
+   if (sPriv->devPrivSize != sizeof(I830DRIRec)) {
+      fprintf(stderr,"\nERROR!  sizeof(I830DRIRec) does not match passed size from device driver\n");
+      return GL_FALSE;
+   }
+
+   /* Allocate the private area */
+   intelScreen = (intelScreenPrivate *)CALLOC(sizeof(intelScreenPrivate));
+   if (!intelScreen) {
+      fprintf(stderr,"\nERROR!  Allocating private area failed\n");
+      return GL_FALSE;
+   }
+   /* parse information in __driConfigOptions */
+   driParseOptionInfo (&intelScreen->optionCache,
+		       __driConfigOptions, __driNConfigOptions);
+
+   intelScreen->driScrnPriv = sPriv;
+   sPriv->private = (void *)intelScreen;
+
+   intelScreen->deviceID = gDRIPriv->deviceID;
+   intelScreen->width = gDRIPriv->width;
+   intelScreen->height = gDRIPriv->height;
+   intelScreen->mem = gDRIPriv->mem;
+   intelScreen->cpp = gDRIPriv->cpp;
+   intelScreen->frontPitch = gDRIPriv->fbStride;
+   intelScreen->frontOffset = gDRIPriv->fbOffset;
+			 
+   switch (gDRIPriv->bitsPerPixel) {
+   case 15: intelScreen->fbFormat = DV_PF_555; break;
+   case 16: intelScreen->fbFormat = DV_PF_565; break;
+   case 32: intelScreen->fbFormat = DV_PF_8888; break;
+   }
+			 
+   intelScreen->backOffset = gDRIPriv->backOffset;
+   intelScreen->backPitch = gDRIPriv->backPitch;
+   intelScreen->depthOffset = gDRIPriv->depthOffset;
+   intelScreen->depthPitch = gDRIPriv->depthPitch;
+   intelScreen->textureOffset = gDRIPriv->textureOffset;
+   intelScreen->textureSize = gDRIPriv->textureSize;
+   intelScreen->logTextureGranularity = gDRIPriv->logTextureGranularity;
+   intelScreen->back.handle = gDRIPriv->backbuffer;
+   intelScreen->back.size = gDRIPriv->backbufferSize;
+			 
+   if (drmMap(sPriv->fd,
+	      intelScreen->back.handle,
+	      intelScreen->back.size,
+	      (drmAddress *)&intelScreen->back.map) != 0) {
+      fprintf(stderr, "\nERROR: line %d, Function %s, File %s\n",
+	      __LINE__, __FUNCTION__, __FILE__);
+      FREE(intelScreen);
+      sPriv->private = NULL;
+      return GL_FALSE;
+   }
+
+   intelScreen->depth.handle = gDRIPriv->depthbuffer;
+   intelScreen->depth.size = gDRIPriv->depthbufferSize;
+
+   if (drmMap(sPriv->fd, 
+	      intelScreen->depth.handle,
+	      intelScreen->depth.size,
+	      (drmAddress *)&intelScreen->depth.map) != 0) {
+      fprintf(stderr, "\nERROR: line %d, Function %s, File %s\n", 
+	      __LINE__, __FUNCTION__, __FILE__);
+      FREE(intelScreen);
+      drmUnmap(intelScreen->back.map, intelScreen->back.size);
+      sPriv->private = NULL;
+      return GL_FALSE;
+   }
+
+   intelScreen->tex.handle = gDRIPriv->textures;
+   intelScreen->tex.size = gDRIPriv->textureSize;
+
+   if (drmMap(sPriv->fd,
+	      intelScreen->tex.handle,
+	      intelScreen->tex.size,
+	      (drmAddress *)&intelScreen->tex.map) != 0) {
+      fprintf(stderr, "\nERROR: line %d, Function %s, File %s\n",
+	      __LINE__, __FUNCTION__, __FILE__);
+      FREE(intelScreen);
+      drmUnmap(intelScreen->back.map, intelScreen->back.size);
+      drmUnmap(intelScreen->depth.map, intelScreen->depth.size);
+      sPriv->private = NULL;
+      return GL_FALSE;
+   }
+			 
+   intelScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset;
+   
+   if (0) intelPrintDRIInfo(intelScreen, sPriv, gDRIPriv);
+
+   intelScreen->drmMinor = sPriv->drmMinor;
+
+   {
+      int ret;
+      drmI830GetParam gp;
+
+      gp.param = I830_PARAM_IRQ_ACTIVE;
+      gp.value = &intelScreen->irq_active;
+
+      ret = drmCommandWriteRead( sPriv->fd, DRM_I830_GETPARAM,
+				 &gp, sizeof(gp));
+      if (ret) {
+	 fprintf(stderr, "drmI830GetParam: %d\n", ret);
+	 return GL_FALSE;
+      }
+   }
+
+   {
+      int ret;
+      drmI830GetParam gp;
+
+      gp.param = I830_PARAM_ALLOW_BATCHBUFFER;
+      gp.value = &intelScreen->allow_batchbuffer;
+
+      ret = drmCommandWriteRead( sPriv->fd, DRM_I830_GETPARAM,
+				 &gp, sizeof(gp));
+      if (ret) {
+	 fprintf(stderr, "drmI830GetParam: (%d) %d\n", gp.param, ret);
+	 return GL_FALSE;
+      }
+   }
+
+   if (glx_enable_extension != NULL) {
+      (*glx_enable_extension)( psc, "GLX_SGI_make_current_read" );
+      (*glx_enable_extension)( psc, "GLX_MESA_allocate_memory" );
+   }
+   
+   sPriv->psc->allocateMemory = (void *) intelAllocateMemoryMESA;
+   sPriv->psc->freeMemory     = (void *) intelFreeMemoryMESA;
+   sPriv->psc->memoryOffset   = (void *) intelGetMemoryOffsetMESA;
+
+   (void) sigset(SIGTSTP, stop_handler);
+   (void) sigset(SIGTTIN, stop_handler);
+   (void) sigset(SIGTTOU, stop_handler);
+   (void) sigset(SIGINT, exit_handler);
+   (void) sigset(SIGTERM, exit_handler);
+
+
+   return GL_TRUE;
+}
+		
+		
+static void intelDestroyScreen(__DRIscreenPrivate *sPriv)
+{
+   intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
+
+   /* Need to unmap all the bufs and maps here:
+    */
+   drmUnmap(intelScreen->back.map, intelScreen->back.size);
+   drmUnmap(intelScreen->depth.map, intelScreen->depth.size);
+   drmUnmap(intelScreen->tex.map, intelScreen->tex.size);
+   FREE(intelScreen);
+   sPriv->private = NULL;
+}
+
+
+static GLboolean intelCreateBuffer( __DRIscreenPrivate *driScrnPriv,
+				    __DRIdrawablePrivate *driDrawPriv,
+				    const __GLcontextModes *mesaVis,
+				    GLboolean isPixmap )
+{
+   intelScreenPrivate *screen = (intelScreenPrivate *) driScrnPriv->private;
+
+   if (isPixmap) {
+      return GL_FALSE; /* not implemented */
+   } else {
+      GLboolean swStencil = (mesaVis->stencilBits > 0 && 
+			     mesaVis->depthBits != 24);
+
+#if 0
+      driDrawPriv->driverPrivate = (void *) 
+	 _mesa_create_framebuffer(mesaVis,
+				  GL_FALSE,  /* software depth buffer? */
+				  swStencil,
+				  mesaVis->accumRedBits > 0,
+				  GL_FALSE /* s/w alpha planes */);
+#else
+      struct gl_framebuffer *fb = _mesa_create_framebuffer(mesaVis);
+
+      {
+         driRenderbuffer *frontRb
+            = driNewRenderbuffer(GL_RGBA, screen->cpp,
+                                 screen->frontOffset, screen->frontPitch);
+         intelSetSpanFunctions(frontRb, mesaVis);
+         _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontRb->Base);
+      }
+
+      if (mesaVis->doubleBufferMode) {
+         driRenderbuffer *backRb
+            = driNewRenderbuffer(GL_RGBA, screen->cpp,
+                                 screen->backOffset, screen->backPitch);
+         intelSetSpanFunctions(backRb, mesaVis);
+         _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backRb->Base);
+      }
+
+      if (mesaVis->depthBits == 16) {
+         driRenderbuffer *depthRb
+            = driNewRenderbuffer(GL_DEPTH_COMPONENT16, screen->cpp,
+                                 screen->depthOffset, screen->depthPitch);
+         intelSetSpanFunctions(depthRb, mesaVis);
+         _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
+      }
+      else if (mesaVis->depthBits == 24) {
+         driRenderbuffer *depthRb
+            = driNewRenderbuffer(GL_DEPTH_COMPONENT24, screen->cpp,
+                                 screen->depthOffset, screen->depthPitch);
+         intelSetSpanFunctions(depthRb, mesaVis);
+         _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
+      }
+
+      if (mesaVis->stencilBits > 0 && !swStencil) {
+         driRenderbuffer *stencilRb
+            = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT, screen->cpp,
+                                 screen->depthOffset, screen->depthPitch);
+         intelSetSpanFunctions(stencilRb, mesaVis);
+         _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &stencilRb->Base);
+      }
+
+      _mesa_add_soft_renderbuffers(fb,
+                                   GL_FALSE, /* color */
+                                   GL_FALSE, /* depth */
+                                   swStencil,
+                                   mesaVis->accumRedBits > 0,
+                                   GL_FALSE, /* alpha */
+                                   GL_FALSE /* aux */);
+      driDrawPriv->driverPrivate = (void *) fb;
+#endif
+      return (driDrawPriv->driverPrivate != NULL);
+   }
+}
+
+static void intelDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
+{
+   _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
+}
+
+
+/* There are probably better ways to do this, such as an
+ * init-designated function to register chipids and createcontext
+ * functions.
+ */
+extern GLboolean i830CreateContext( const __GLcontextModes *mesaVis,
+				    __DRIcontextPrivate *driContextPriv,
+				    void *sharedContextPrivate);
+
+extern GLboolean i915CreateContext( const __GLcontextModes *mesaVis,
+				   __DRIcontextPrivate *driContextPriv,
+				   void *sharedContextPrivate);
+
+
+
+
+static GLboolean intelCreateContext( const __GLcontextModes *mesaVis,
+				   __DRIcontextPrivate *driContextPriv,
+				   void *sharedContextPrivate)
+{
+   __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
+   intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
+
+   switch (intelScreen->deviceID) {
+   case PCI_CHIP_845_G:
+   case PCI_CHIP_I830_M:
+   case PCI_CHIP_I855_GM:
+   case PCI_CHIP_I865_G:
+      return i830CreateContext( mesaVis, driContextPriv, 
+				sharedContextPrivate );
+
+   case PCI_CHIP_I915_G:
+   case PCI_CHIP_I915_GM:
+   case PCI_CHIP_I945_G:
+      return i915CreateContext( mesaVis, driContextPriv, 
+			       sharedContextPrivate );
+ 
+   default:
+      fprintf(stderr, "Unrecognized deviceID %x\n", intelScreen->deviceID);
+      return GL_FALSE;
+   }
+}
+
+
+static const struct __DriverAPIRec intelAPI = {
+   intelInitDriver,
+   intelDestroyScreen,
+   intelCreateContext,
+   intelDestroyContext,
+   intelCreateBuffer,
+   intelDestroyBuffer,
+   intelSwapBuffers,
+   intelMakeCurrent,
+   intelUnbindContext,
+   NULL,
+   NULL,
+   NULL,
+   NULL,
+   NULL
+};
+
+
+static __GLcontextModes *
+intelFillInModes( unsigned pixel_bits, unsigned depth_bits,
+		 unsigned stencil_bits, GLboolean have_back_buffer )
+{
+   __GLcontextModes * modes;
+   __GLcontextModes * m;
+   unsigned num_modes;
+   unsigned depth_buffer_factor;
+   unsigned back_buffer_factor;
+   GLenum fb_format;
+   GLenum fb_type;
+
+   /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
+    * support pageflipping at all.
+    */
+   static const GLenum back_buffer_modes[] = {
+      GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
+   };
+
+   u_int8_t depth_bits_array[3];
+   u_int8_t stencil_bits_array[3];
+
+
+   depth_bits_array[0] = 0;
+   depth_bits_array[1] = depth_bits;
+   depth_bits_array[2] = depth_bits;
+
+   /* Just like with the accumulation buffer, always provide some modes
+    * with a stencil buffer.  It will be a sw fallback, but some apps won't
+    * care about that.
+    */
+   stencil_bits_array[0] = 0;
+   stencil_bits_array[1] = 0;
+   stencil_bits_array[2] = (stencil_bits == 0) ? 8 : stencil_bits;
+
+   depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1;
+   back_buffer_factor  = (have_back_buffer) ? 3 : 1;
+
+   num_modes = depth_buffer_factor * back_buffer_factor * 4;
+
+    if ( pixel_bits == 16 ) {
+        fb_format = GL_RGB;
+        fb_type = GL_UNSIGNED_SHORT_5_6_5;
+    }
+    else {
+        fb_format = GL_BGRA;
+        fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
+    }
+
+   modes = (*dri_interface->createContextModes)( num_modes, sizeof( __GLcontextModes ) );
+   m = modes;
+   if ( ! driFillInModes( & m, fb_format, fb_type,
+			  depth_bits_array, stencil_bits_array, depth_buffer_factor,
+			  back_buffer_modes, back_buffer_factor,
+			  GLX_TRUE_COLOR ) ) {
+	fprintf( stderr, "[%s:%u] Error creating FBConfig!\n",
+		 __func__, __LINE__ );
+	return NULL;
+   }
+   if ( ! driFillInModes( & m, fb_format, fb_type,
+			  depth_bits_array, stencil_bits_array, depth_buffer_factor,
+			  back_buffer_modes, back_buffer_factor,
+			  GLX_DIRECT_COLOR ) ) {
+	fprintf( stderr, "[%s:%u] Error creating FBConfig!\n",
+		 __func__, __LINE__ );
+	return NULL;
+   }
+
+   /* Mark the visual as slow if there are "fake" stencil bits.
+    */
+   for ( m = modes ; m != NULL ; m = m->next ) {
+      if ( (m->stencilBits != 0) && (m->stencilBits != stencil_bits) ) {
+	 m->visualRating = GLX_SLOW_CONFIG;
+      }
+   }
+
+   return modes;
+}
+
+
+/**
+ * This is the bootstrap function for the driver.  libGL supplies all of the
+ * requisite information about the system, and the driver initializes itself.
+ * This routine also fills in the linked list pointed to by \c driver_modes
+ * with the \c __GLcontextModes that the driver can support for windows or
+ * pbuffers.
+ * 
+ * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on 
+ *         failure.
+ */
+PUBLIC
+void * __driCreateNewScreen_20050727( __DRInativeDisplay *dpy, int scrn, __DRIscreen *psc,
+			     const __GLcontextModes * modes,
+			     const __DRIversion * ddx_version,
+			     const __DRIversion * dri_version,
+			     const __DRIversion * drm_version,
+			     const __DRIframebuffer * frame_buffer,
+			     drmAddress pSAREA, int fd, 
+			     int internal_api_version,
+			     const __DRIinterfaceMethods * interface,
+			     __GLcontextModes ** driver_modes )
+			     
+{
+   __DRIscreenPrivate *psp;
+   static const __DRIversion ddx_expected = { 1, 4, 0 };
+   static const __DRIversion dri_expected = { 4, 0, 0 };
+   static const __DRIversion drm_expected = { 1, 1, 0 };
+
+   dri_interface = interface;
+
+   if ( ! driCheckDriDdxDrmVersions2( "i915",
+				      dri_version, & dri_expected,
+				      ddx_version, & ddx_expected,
+				      drm_version, & drm_expected ) ) {
+      return NULL;
+   }
+
+   psp = __driUtilCreateNewScreen(dpy, scrn, psc, NULL,
+				  ddx_version, dri_version, drm_version,
+				  frame_buffer, pSAREA, fd,
+				  internal_api_version, &intelAPI);
+   if ( psp != NULL ) {
+      I830DRIPtr dri_priv = (I830DRIPtr) psp->pDevPriv;
+      *driver_modes = intelFillInModes( dri_priv->cpp * 8,
+					(dri_priv->cpp == 2) ? 16 : 24,
+					(dri_priv->cpp == 2) ? 0  : 8,
+					(dri_priv->backOffset != dri_priv->depthOffset) );
+
+      /* Calling driInitExtensions here, with a NULL context pointer, does not actually
+       * enable the extensions.  It just makes sure that all the dispatch offsets for all
+       * the extensions that *might* be enables are known.  This is needed because the
+       * dispatch offsets need to be known when _mesa_context_create is called, but we can't
+       * enable the extensions until we have a context pointer.
+       *
+       * Hello chicken.  Hello egg.  How are you two today?
+       */
+      driInitExtensions( NULL, card_extensions, GL_FALSE );
+   }
+
+   return (void *) psp;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/extras/Mesa/src/mesa/drivers/dri/i915/intel_tris.c	Tue Oct 24 18:42:11 2006 -0700
@@ -0,0 +1,920 @@
+/**************************************************************************
+ * 
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS 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 "glheader.h"
+#include "context.h"
+#include "macros.h"
+#include "enums.h"
+#include "dd.h"
+
+#include "swrast/swrast.h"
+#include "swrast_setup/swrast_setup.h"
+#include "tnl/t_context.h"
+#include "tnl/t_pipeline.h"
+#include "tnl/t_vertex.h"
+
+#include "intel_screen.h"
+#include "intel_tris.h"
+#include "intel_batchbuffer.h"
+#include "intel_reg.h"
+#include "intel_span.h"
+
+static void intelRenderPrimitive( GLcontext *ctx, GLenum prim );
+static void intelRasterPrimitive( GLcontext *ctx, GLenum rprim, GLuint hwprim );
+
+/***********************************************************************
+ *                    Emit primitives as inline vertices               *
+ ***********************************************************************/
+
+#if (defined(i386) || defined(__i386__)) && !(defined(__SOLARIS__) || defined(sun))
+#define COPY_DWORDS( j, vb, vertsize, v )			\
+do {								\
+   int __tmp;							\
+   __asm__ __volatile__( "rep ; movsl"				\
+			 : "=%c" (j), "=D" (vb), "=S" (__tmp)	\
+			 : "0" (vertsize),			\
+			 "D" ((long)vb),			\
+			 "S" ((long)v) );			\
+} while (0)
+#else
+#define COPY_DWORDS( j, vb, vertsize, v )	\
+do {						\
+   if (0) fprintf(stderr, "\n");	\
+   for ( j = 0 ; j < vertsize ; j++ ) {		\
+      if (0) fprintf(stderr, "   -- v(%d): %x/%f\n",j,	\
+	      ((GLuint *)v)[j],			\
+	      ((GLfloat *)v)[j]);		\
+      vb[j] = ((GLuint *)v)[j];			\
+   }						\
+   vb += vertsize;				\
+} while (0)
+#endif
+
+static void __inline__ intel_draw_quad( intelContextPtr intel,
+					intelVertexPtr v0,
+					intelVertexPtr v1,
+					intelVertexPtr v2,
+					intelVertexPtr v3 )
+{
+   GLuint vertsize = intel->vertex_size;
+   GLuint *vb = intelExtendInlinePrimitive( intel, 6 * vertsize );
+   int j;
+
+   COPY_DWORDS( j, vb, vertsize, v0 );
+   COPY_DWORDS( j, vb, vertsize, v1 );
+   COPY_DWORDS( j, vb, vertsize, v3 );
+   COPY_DWORDS( j, vb, vertsize, v1 );
+   COPY_DWORDS( j, vb, vertsize, v2 );
+   COPY_DWORDS( j, vb, vertsize, v3 );
+}
+
+static void __inline__ intel_draw_triangle( intelContextPtr intel,
+					    intelVertexPtr v0,
+					    intelVertexPtr v1,
+					    intelVertexPtr v2 )
+{
+   GLuint vertsize = intel->vertex_size;
+   GLuint *vb = intelExtendInlinePrimitive( intel, 3 * vertsize );
+   int j;
+   
+   COPY_DWORDS( j, vb, vertsize, v0 );
+   COPY_DWORDS( j, vb, vertsize, v1 );
+   COPY_DWORDS( j, vb, vertsize, v2 );
+}
+
+
+static __inline__ void intel_draw_line( intelContextPtr intel,
+					intelVertexPtr v0,
+					intelVertexPtr v1 )
+{
+   GLuint vertsize = intel->vertex_size;
+   GLuint *vb = intelExtendInlinePrimitive( intel, 2 * vertsize );
+   int j;
+
+   COPY_DWORDS( j, vb, vertsize, v0 );
+   COPY_DWORDS( j, vb, vertsize, v1 );
+}
+
+
+static __inline__ void intel_draw_point( intelContextPtr intel,
+					 intelVertexPtr v0 )
+{
+   GLuint vertsize = intel->vertex_size;
+   GLuint *vb = intelExtendInlinePrimitive( intel, vertsize );
+   int j;
+
+   /* Adjust for sub pixel position -- still required for conform. */
+   *(float *)&vb[0] = v0->v.x - 0.125;
+   *(float *)&vb[1] = v0->v.y - 0.125;
+   for (j = 2 ; j < vertsize ; j++)
+     vb[j] = v0->ui[j];
+}
+
+
+
+/***********************************************************************
+ *                Fixup for ARB_point_parameters                       *
+ ***********************************************************************/
+
+static void intel_atten_point( intelContextPtr intel, intelVertexPtr v0 )
+{
+   GLcontext *ctx = &intel->ctx;
+   GLfloat psz[4], col[4], restore_psz, restore_alpha;
+
+   _tnl_get_attr( ctx, v0, _TNL_ATTRIB_POINTSIZE, psz );
+   _tnl_get_attr( ctx, v0, _TNL_ATTRIB_COLOR0, col );
+
+   restore_psz = psz[0];
+   restore_alpha = col[3];
+
+   if (psz[0] >= ctx->Point.Threshold) {
+      psz[0] = MIN2(psz[0], ctx->Point.MaxSize);
+   }
+   else {
+      GLfloat dsize = psz[0] / ctx->Point.Threshold;
+      psz[0] = MAX2(ctx->Point.Threshold, ctx->Point.MinSize);
+      col[3] *= dsize * dsize;
+   }
+
+   if (psz[0] < 1.0)
+      psz[0] = 1.0;
+
+   if (restore_psz != psz[0] || restore_alpha != col[3]) {
+      _tnl_set_attr( ctx, v0, _TNL_ATTRIB_POINTSIZE, psz);
+      _tnl_set_attr( ctx, v0, _TNL_ATTRIB_COLOR0, col);
+   
+      intel_draw_point( intel, v0 );
+
+      psz[0] = restore_psz;
+      col[3] = restore_alpha;
+
+      _tnl_set_attr( ctx, v0, _TNL_ATTRIB_POINTSIZE, psz);
+      _tnl_set_attr( ctx, v0, _TNL_ATTRIB_COLOR0, col);
+   }
+   else
+      intel_draw_point( intel, v0 );
+}
+
+
+
+
+
+/***********************************************************************
+ *                Fixup for I915 WPOS texture coordinate                *
+ ***********************************************************************/
+
+
+
+static void intel_wpos_triangle( intelContextPtr intel,
+				 intelVertexPtr v0,
+				 intelVertexPtr v1,
+				 intelVertexPtr v2 )
+{
+   GLuint offset = intel->wpos_offset;
+   GLuint size = intel->wpos_size;
+   
+   __memcpy( ((char *)v0) + offset, v0, size );
+   __memcpy( ((char *)v1) + offset, v1, size );
+   __memcpy( ((char *)v2) + offset, v2, size );
+
+   intel_draw_triangle( intel, v0, v1, v2 );
+}
+
+
+static void intel_wpos_line( intelContextPtr intel,
+			     intelVertexPtr v0,
+			     intelVertexPtr v1 )
+{
+   GLuint offset = intel->wpos_offset;
+   GLuint size = intel->wpos_size;
+
+   __memcpy( ((char *)v0) + offset, v0, size );
+   __memcpy( ((char *)v1) + offset, v1, size );
+
+   intel_draw_line( intel, v0, v1 );
+}
+
+
+static void intel_wpos_point( intelContextPtr intel,
+			      intelVertexPtr v0 )
+{
+   GLuint offset = intel->wpos_offset;
+   GLuint size = intel->wpos_size;
+
+   __memcpy( ((char *)v0) + offset, v0, size );
+
+   intel_draw_point( intel, v0 );
+}
+
+
+
+
+
+
+/***********************************************************************
+ *          Macros for t_dd_tritmp.h to draw basic primitives          *
+ ***********************************************************************/
+
+#define TRI( a, b, c )				\
+do { 						\
+   if (DO_FALLBACK)				\
+      intel->draw_tri( intel, a, b, c );	\
+   else						\
+      intel_draw_triangle( intel, a, b, c );	\
+} while (0)
+
+#define QUAD( a, b, c, d )			\
+do { 						\
+   if (DO_FALLBACK) {				\
+      intel->draw_tri( intel, a, b, d );	\
+      intel->draw_tri( intel, b, c, d );	\
+   } else					\
+      intel_draw_quad( intel, a, b, c, d );	\
+} while (0)
+
+#define LINE( v0, v1 )				\
+do { 						\
+   if (DO_FALLBACK)				\
+      intel->draw_line( intel, v0, v1 );	\
+   else						\
+      intel_draw_line( intel, v0, v1 );		\
+} while (0)
+
+#define POINT( v0 )				\
+do { 						\
+   if (DO_FALLBACK)				\
+      intel->draw_point( intel, v0 );		\
+   else						\
+      intel_draw_point( intel, v0 );		\
+} while (0)
+
+
+/***********************************************************************
+ *              Build render functions from dd templates               *
+ ***********************************************************************/
+
+#define INTEL_OFFSET_BIT 	0x01
+#define INTEL_TWOSIDE_BIT	0x02
+#define INTEL_UNFILLED_BIT	0x04
+#define INTEL_FALLBACK_BIT	0x08
+#define INTEL_MAX_TRIFUNC	0x10
+
+
+static struct {
+   tnl_points_func	        points;
+   tnl_line_func		line;
+   tnl_triangle_func	triangle;
+   tnl_quad_func		quad;
+} rast_tab[INTEL_MAX_TRIFUNC];
+
+
+#define DO_FALLBACK (IND & INTEL_FALLBACK_BIT)
+#define DO_OFFSET   (IND & INTEL_OFFSET_BIT)
+#define DO_UNFILLED (IND & INTEL_UNFILLED_BIT)
+#define DO_TWOSIDE  (IND & INTEL_TWOSIDE_BIT)
+#define DO_FLAT      0
+#define DO_TRI       1
+#define DO_QUAD      1
+#define DO_LINE      1
+#define DO_POINTS    1
+#define DO_FULL_QUAD 1
+
+#define HAVE_RGBA         1
+#define HAVE_SPEC         1
+#define HAVE_BACK_COLORS  0
+#define HAVE_HW_FLATSHADE 1
+#define VERTEX            intelVertex
+#define TAB               rast_tab
+
+/* Only used to pull back colors into vertices (ie, we know color is
+ * floating point).
+ */
+#define INTEL_COLOR( dst, src )				\
+do {							\
+   UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]);	\
+   UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]);	\
+   UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]);	\
+   UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]);	\
+} while (0)
+
+#define INTEL_SPEC( dst, src )				\
+do {							\
+   UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]);	\
+   UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]);	\
+   UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]);	\
+} while (0)
+
+
+#define DEPTH_SCALE intel->polygon_offset_scale
+#define UNFILLED_TRI unfilled_tri
+#define UNFILLED_QUAD unfilled_quad
+#define VERT_X(_v) _v->v.x
+#define VERT_Y(_v) _v->v.y
+#define VERT_Z(_v) _v->v.z
+#define AREA_IS_CCW( a ) (a > 0)
+#define GET_VERTEX(e) (intel->verts + (e * intel->vertex_size * sizeof(GLuint)))
+
+#define VERT_SET_RGBA( v, c )    if (coloroffset) INTEL_COLOR( v->ub4[coloroffset], c )
+#define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
+#define VERT_SAVE_RGBA( idx )    if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
+#define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
+
+#define VERT_SET_SPEC( v, c )    if (specoffset) INTEL_SPEC( v->ub4[specoffset], c )
+#define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
+#define VERT_SAVE_SPEC( idx )    if (specoffset) spec[idx] = v[idx]->ui[specoffset]
+#define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
+
+#define LOCAL_VARS(n)							\
+   intelContextPtr intel = INTEL_CONTEXT(ctx);				\
+   GLuint color[n], spec[n];						\
+   GLuint coloroffset = intel->coloroffset;		\
+   GLboolean specoffset = intel->specoffset;			\
+   (void) color; (void) spec; (void) coloroffset; (void) specoffset;
+
+
+/***********************************************************************
+ *                Helpers for rendering unfilled primitives            *
+ ***********************************************************************/
+
+static const GLuint hw_prim[GL_POLYGON+1] = {
+   PRIM3D_POINTLIST,
+   PRIM3D_LINELIST,
+   PRIM3D_LINELIST,
+   PRIM3D_LINELIST,
+   PRIM3D_TRILIST,
+   PRIM3D_TRILIST,
+   PRIM3D_TRILIST,
+   PRIM3D_TRILIST,
+   PRIM3D_TRILIST,
+   PRIM3D_TRILIST
+};
+
+#define RASTERIZE(x) intelRasterPrimitive( ctx, x, hw_prim[x] )
+#define RENDER_PRIMITIVE intel->render_primitive
+#define TAG(x) x
+#define IND INTEL_FALLBACK_BIT
+#include "tnl_dd/t_dd_unfilled.h"
+#undef IND
+
+/***********************************************************************
+ *                      Generate GL render functions                   *
+ ***********************************************************************/
+
+#define IND (0)
+#define TAG(x) x
+#include "tnl_dd/t_dd_tritmp.h"
+
+#define IND (INTEL_OFFSET_BIT)
+#define TAG(x) x##_offset
+#include "tnl_dd/t_dd_tritmp.h"
+
+#define IND (INTEL_TWOSIDE_BIT)
+#define TAG(x) x##_twoside
+#include "tnl_dd/t_dd_tritmp.h"
+
+#define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT)
+#define TAG(x) x##_twoside_offset
+#include "tnl_dd/t_dd_tritmp.h"
+
+#define IND (INTEL_UNFILLED_BIT)
+#define TAG(x) x##_unfilled
+#include "tnl_dd/t_dd_tritmp.h"
+
+#define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
+#define TAG(x) x##_offset_unfilled
+#include "tnl_dd/t_dd_tritmp.h"
+
+#define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT)
+#define TAG(x) x##_twoside_unfilled
+#include "tnl_dd/t_dd_tritmp.h"
+
+#define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
+#define TAG(x) x##_twoside_offset_unfilled
+#include "tnl_dd/t_dd_tritmp.h"
+
+#define IND (INTEL_FALLBACK_BIT)
+#define TAG(x) x##_fallback
+#include "tnl_dd/t_dd_tritmp.h"
+
+#define IND (INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
+#define TAG(x) x##_offset_fallback
+#include "tnl_dd/t_dd_tritmp.h"
+
+#define IND (INTEL_TWOSIDE_BIT|INTEL_FALLBACK_BIT)
+#define TAG(x) x##_twoside_fallback
+#include "tnl_dd/t_dd_tritmp.h"
+
+#define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
+#define TAG(x) x##_twoside_offset_fallback
+#include "tnl_dd/t_dd_tritmp.h"
+
+#define IND (INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
+#define TAG(x) x##_unfilled_fallback
+#include "tnl_dd/t_dd_tritmp.h"
+
+#define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
+#define TAG(x) x##_offset_unfilled_fallback
+#include "tnl_dd/t_dd_tritmp.h"
+
+#define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
+#define TAG(x) x##_twoside_unfilled_fallback
+#include "tnl_dd/t_dd_tritmp.h"
+
+#define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT| \
+	     INTEL_FALLBACK_BIT)
+#define TAG(x) x##_twoside_offset_unfilled_fallback
+#include "tnl_dd/t_dd_tritmp.h"
+
+
+static void init_rast_tab( void )
+{
+   init();
+   init_offset();
+   init_twoside();
+   init_twoside_offset();
+   init_unfilled();
+   init_offset_unfilled();
+   init_twoside_unfilled();
+   init_twoside_offset_unfilled();
+   init_fallback();
+   init_offset_fallback();
+   init_twoside_fallback();
+   init_twoside_offset_fallback();
+   init_unfilled_fallback();
+   init_offset_unfilled_fallback();
+   init_twoside_unfilled_fallback();
+   init_twoside_offset_unfilled_fallback();
+}
+
+
+/***********************************************************************
+ *                    Rasterization fallback helpers                   *
+ ***********************************************************************/
+
+
+/* This code is hit only when a mix of accelerated and unaccelerated
+ * primitives are being drawn, and only for the unaccelerated
+ * primitives.
+ */
+static void
+intel_fallback_tri( intelContextPtr intel,
+		   intelVertex *v0,
+		   intelVertex *v1,
+		   intelVertex *v2 )
+{
+   GLcontext *ctx = &intel->ctx;
+   SWvertex v[3];
+
+   if (0)
+      fprintf(stderr, "\n%s\n", __FUNCTION__);
+
+   _swsetup_Translate( ctx, v0, &v[0] );
+   _swsetup_Translate( ctx, v1, &v[1] );
+   _swsetup_Translate( ctx, v2, &v[2] );
+   intelSpanRenderStart( ctx );
+   _swrast_Triangle( ctx, &v[0], &v[1], &v[2] );
+   intelSpanRenderFinish( ctx );
+}
+
+
+static void
+intel_fallback_line( intelContextPtr intel,
+		    intelVertex *v0,
+		    intelVertex *v1 )
+{
+   GLcontext *ctx = &intel->ctx;
+   SWvertex v[2];
+
+   if (0)
+      fprintf(stderr, "\n%s\n", __FUNCTION__);
+
+   _swsetup_Translate( ctx, v0, &v[0] );
+   _swsetup_Translate( ctx, v1, &v[1] );
+   intelSpanRenderStart( ctx );
+   _swrast_Line( ctx, &v[0], &v[1] );
+   intelSpanRenderFinish( ctx );
+}
+
+
+static void
+intel_fallback_point( intelContextPtr intel,
+		     intelVertex *v0 )
+{
+   GLcontext *ctx = &intel->ctx;
+   SWvertex v[1];
+
+   if (0)
+      fprintf(stderr, "\n%s\n", __FUNCTION__);
+
+   _swsetup_Translate( ctx, v0, &v[0] );
+   intelSpanRenderStart( ctx );
+   _swrast_Point( ctx, &v[0] );
+   intelSpanRenderFinish( ctx );
+}
+
+
+
+/**********************************************************************/
+/*               Render unclipped begin/end objects                   */
+/**********************************************************************/
+
+#define IND 0
+#define V(x) (intelVertex *)(vertptr + ((x)*vertsize*sizeof(GLuint)))
+#define RENDER_POINTS( start, count )	\
+   for ( ; start < count ; start++) POINT( V(ELT(start)) );
+#define RENDER_LINE( v0, v1 )         LINE( V(v0), V(v1) )
+#define RENDER_TRI(  v0, v1, v2 )     TRI(  V(v0), V(v1), V(v2) )
+#define RENDER_QUAD( v0, v1, v2, v3 ) QUAD( V(v0), V(v1), V(v2), V(v3) )
+#define INIT(x) intelRenderPrimitive( ctx, x )
+#undef LOCAL_VARS
+#define LOCAL_VARS						\
+    intelContextPtr intel = INTEL_CONTEXT(ctx);			\
+    GLubyte *vertptr = (GLubyte *)intel->verts;			\
+    const GLuint vertsize = intel->vertex_size;       	\
+    const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts;	\
+    (void) elt;
+#define RESET_STIPPLE
+#define RESET_OCCLUSION
+#define PRESERVE_VB_DEFS
+#define ELT(x) x
+#define TAG(x) intel_##x##_verts
+#include "tnl/t_vb_rendertmp.h"
+#undef ELT
+#undef TAG
+#define TAG(x) intel_##x##_elts
+#define ELT(x) elt[x]
+#include "tnl/t_vb_rendertmp.h"
+
+/**********************************************************************/
+/*                   Render clipped primitives                        */
+/**********************************************************************/
+
+
+
+static void intelRenderClippedPoly( GLcontext *ctx, const GLuint *elts,
+				   GLuint n )
+{
+   intelContextPtr intel = INTEL_CONTEXT(ctx);
+   TNLcontext *tnl = TNL_CONTEXT(ctx);
+   struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
+   GLuint prim = intel->render_primitive;
+
+   /* Render the new vertices as an unclipped polygon.
+    */
+   {
+      GLuint *tmp = VB->Elts;
+      VB->Elts = (GLuint *)elts;
+      tnl->Driver.Render.PrimTabElts[GL_POLYGON]( ctx, 0, n, 
+						  PRIM_BEGIN|PRIM_END );
+      VB->Elts = tmp;
+   }
+
+   /* Restore the render primitive
+    */
+   if (prim != GL_POLYGON)
+      tnl->Driver.Render.PrimitiveNotify( ctx, prim );
+}
+
+static void intelRenderClippedLine( GLcontext *ctx, GLuint ii, GLuint jj )
+{
+   TNLcontext *tnl = TNL_CONTEXT(ctx);
+
+   tnl->Driver.Render.Line( ctx, ii, jj );
+}
+
+static void intelFastRenderClippedPoly( GLcontext *ctx, const GLuint *elts,
+				       GLuint n )
+{
+   intelContextPtr intel = INTEL_CONTEXT( ctx );
+   const GLuint vertsize = intel->vertex_size;
+   GLuint *vb = intelExtendInlinePrimitive( intel, (n-2) * 3 * vertsize );
+   GLubyte *vertptr = (GLubyte *)intel->verts;
+   const GLuint *start = (const GLuint *)V(elts[0]);
+   int i,j;
+
+   for (i = 2 ; i < n ; i++) {
+      COPY_DWORDS( j, vb, vertsize, V(elts[i-1]) );
+      COPY_DWORDS( j, vb, vertsize, V(elts[i]) );
+      COPY_DWORDS( j, vb, vertsize, start );
+   }
+}
+
+/**********************************************************************/
+/*                    Choose render functions                         */
+/**********************************************************************/
+
+
+
+
+#define POINT_FALLBACK (0)
+#define LINE_FALLBACK (DD_LINE_STIPPLE)
+#define TRI_FALLBACK (0)
+#define ANY_FALLBACK_FLAGS (POINT_FALLBACK|LINE_FALLBACK|TRI_FALLBACK|\
+                            DD_TRI_STIPPLE|DD_POINT_ATTEN)
+#define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE|DD_TRI_OFFSET|DD_TRI_UNFILLED)
+
+void intelChooseRenderState(GLcontext *ctx)
+{
+   TNLcontext *tnl = TNL_CONTEXT(ctx);
+   intelContextPtr intel = INTEL_CONTEXT(ctx);
+   GLuint flags = ctx->_TriangleCaps;
+   struct fragment_program *program = ctx->FragmentProgram._Current;
+   GLboolean have_wpos = (program && (program->InputsRead & FRAG_BIT_WPOS));
+   GLuint index = 0;
+
+   if (INTEL_DEBUG & DEBUG_STATE)
+     fprintf(stderr,"\n%s\n",__FUNCTION__);
+
+   if ((flags & (ANY_FALLBACK_FLAGS|ANY_RASTER_FLAGS)) || have_wpos) {
+
+      if (flags & ANY_RASTER_FLAGS) {
+	 if (flags & DD_TRI_LIGHT_TWOSIDE)    index |= INTEL_TWOSIDE_BIT;
+	 if (flags & DD_TRI_OFFSET)	      index |= INTEL_OFFSET_BIT;
+	 if (flags & DD_TRI_UNFILLED)	      index |= INTEL_UNFILLED_BIT;
+      }
+
+      if (have_wpos) {
+	 intel->draw_point = intel_wpos_point;
+	 intel->draw_line = intel_wpos_line;
+	 intel->draw_tri = intel_wpos_triangle;
+
+	 /* Make sure these get called:
+	  */
+	 index |= INTEL_FALLBACK_BIT;
+      }
+      else {
+	 intel->draw_point = intel_draw_point;
+	 intel->draw_line = intel_draw_line;
+	 intel->draw_tri = intel_draw_triangle;
+      }
+
+      /* Hook in fallbacks for specific primitives.
+       */
+      if (flags & ANY_FALLBACK_FLAGS)
+      {
+	 if (flags & POINT_FALLBACK)
+	    intel->draw_point = intel_fallback_point;
+
+	 if (flags & LINE_FALLBACK)
+	    intel->draw_line = intel_fallback_line;
+
+	 if (flags & TRI_FALLBACK)
+	    intel->draw_tri = intel_fallback_tri;
+
+	 if ((flags & DD_TRI_STIPPLE) && !intel->hw_stipple) 
+	    intel->draw_tri = intel_fallback_tri;
+
+	 if (flags & DD_POINT_ATTEN)
+	    intel->draw_point = intel_atten_point;
+
+	 index |= INTEL_FALLBACK_BIT;
+      }
+   }
+
+   if (intel->RenderIndex != index) {
+      intel->RenderIndex = index;
+
+      tnl->Driver.Render.Points = rast_tab[index].points;
+      tnl->Driver.Render.Line = rast_tab[index].line;
+      tnl->Driver.Render.Triangle = rast_tab[index].triangle;
+      tnl->Driver.Render.Quad = rast_tab[index].quad;
+
+      if (index == 0) {
+	 tnl->Driver.Render.PrimTabVerts = intel_render_tab_verts;
+	 tnl->Driver.Render.PrimTabElts = intel_render_tab_elts;
+	 tnl->Driver.Render.ClippedLine = line; /* from tritmp.h */
+	 tnl->Driver.Render.ClippedPolygon = intelFastRenderClippedPoly;
+      } else {
+	 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
+	 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
+	 tnl->Driver.Render.ClippedLine = intelRenderClippedLine;
+	 tnl->Driver.Render.ClippedPolygon = intelRenderClippedPoly;
+      }
+   }
+}
+
+static const GLenum reduced_prim[GL_POLYGON+1] = {
+   GL_POINTS,
+   GL_LINES,
+   GL_LINES,
+   GL_LINES,
+   GL_TRIANGLES,
+   GL_TRIANGLES,
+   GL_TRIANGLES,
+   GL_TRIANGLES,
+   GL_TRIANGLES,
+   GL_TRIANGLES
+};
+
+
+/**********************************************************************/
+/*                 High level hooks for t_vb_render.c                 */
+/**********************************************************************/
+
+
+
+
+static void intelRunPipeline( GLcontext *ctx )
+{
+   intelContextPtr intel = INTEL_CONTEXT(ctx);
+
+   if (intel->NewGLState) {
+      if (intel->NewGLState & _NEW_TEXTURE) {
+	 intel->vtbl.update_texture_state( intel ); 
+      }
+
+      if (!intel->Fallback) {
+	 if (intel->NewGLState & _INTEL_NEW_RENDERSTATE)
+	    intelChooseRenderState( ctx );
+      }
+
+      intel->NewGLState = 0;
+   }
+
+   _tnl_run_pipeline( ctx );
+}
+
+static void intelRenderStart( GLcontext *ctx )
+{
+   INTEL_CONTEXT(ctx)->vtbl.render_start( INTEL_CONTEXT(ctx) );
+}
+
+static void intelRenderFinish( GLcontext *ctx )
+{
+   if (INTEL_CONTEXT(ctx)->RenderIndex & INTEL_FALLBACK_BIT)
+      _swrast_flush( ctx );
+}
+
+
+
+
+ /* System to flush dma and emit state changes based on the rasterized
+  * primitive.
+  */
+static void intelRasterPrimitive( GLcontext *ctx, GLenum rprim, GLuint hwprim )
+{
+   intelContextPtr intel = INTEL_CONTEXT(ctx);
+
+   if (0)
+      fprintf(stderr, "%s %s %x\n", __FUNCTION__, 
+	      _mesa_lookup_enum_by_nr(rprim), hwprim);
+
+   intel->vtbl.reduced_primitive_state( intel, rprim );
+    
+   /* Start a new primitive.  Arrange to have it flushed later on.
+    */
+   if (hwprim != intel->prim.primitive) 
+      intelStartInlinePrimitive( intel, hwprim );
+}
+
+
+ /* 
+  */
+ static void intelRenderPrimitive( GLcontext *ctx, GLenum prim )
+ {
+    intelContextPtr intel = INTEL_CONTEXT(ctx);
+
+    if (0)
+       fprintf(stderr, "%s %s\n", __FUNCTION__, _mesa_lookup_enum_by_nr(prim));
+
+    /* Let some clipping routines know which primitive they're dealing
+     * with.
+     */
+    intel->render_primitive = prim;
+
+    /* Shortcircuit this when called from t_dd_rendertmp.h for unfilled
+     * triangles.  The rasterized primitive will always be reset by
+     * lower level functions in that case, potentially pingponging the
+     * state:
+     */
+    if (reduced_prim[prim] == GL_TRIANGLES && 
+	(ctx->_TriangleCaps & DD_TRI_UNFILLED))
+       return;
+
+    /* Set some primitive-dependent state and Start? a new primitive.
+     */
+    intelRasterPrimitive( ctx, reduced_prim[prim], hw_prim[prim] );
+ }
+
+
+ /**********************************************************************/
+ /*           Transition to/from hardware rasterization.               */
+ /**********************************************************************/
+
+ static char *fallbackStrings[] = {
+    "Texture",
+    "Draw buffer",
+    "Read buffer",
+    "Color mask",
+    "Render mode",
+    "Stencil",
+    "Stipple",
+    "User disable"
+ };
+
+
+ static char *getFallbackString(GLuint bit)
+ {
+    int i = 0;
+    while (bit > 1) {
+       i++;
+       bit >>= 1;
+    }
+    return fallbackStrings[i];
+ }
+
+
+
+ void intelFallback( intelContextPtr intel, GLuint bit, GLboolean mode )
+ {
+    GLcontext *ctx = &intel->ctx;
+    TNLcontext *tnl = TNL_CONTEXT(ctx);
+    GLuint oldfallback = intel->Fallback;
+
+    if (mode) {
+       intel->Fallback |= bit;
+       if (oldfallback == 0) {
+	  intelFlush(ctx);
+	  if (INTEL_DEBUG & DEBUG_FALLBACKS) 
+	     fprintf(stderr, "ENTER FALLBACK %x: %s\n",
+		     bit, getFallbackString( bit ));
+	  _swsetup_Wakeup( ctx );
+	  intel->RenderIndex = ~0;
+       }
+    }
+    else {
+       intel->Fallback &= ~bit;
+       if (oldfallback == bit) {
+	  _swrast_flush( ctx );
+	  if (INTEL_DEBUG & DEBUG_FALLBACKS) 
+	     fprintf(stderr, "LEAVE FALLBACK %s\n", getFallbackString( bit ));
+	  tnl->Driver.Render.Start = intelRenderStart;
+	  tnl->Driver.Render.PrimitiveNotify = intelRenderPrimitive;
+	  tnl->Driver.Render.Finish = intelRenderFinish;
+	  tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
+	  tnl->Driver.Render.CopyPV = _tnl_copy_pv;
+	  tnl->Driver.Render.Interp = _tnl_interp;
+
+	  _tnl_invalidate_vertex_state( ctx, ~0 );
+	  _tnl_invalidate_vertices( ctx, ~0 );
+	  _tnl_install_attrs( ctx, 
+			      intel->vertex_attrs, 
+			      intel->vertex_attr_count,
+			      intel->ViewportMatrix.m, 0 ); 
+
+	  intel->NewGLState |= _INTEL_NEW_RENDERSTATE;
+       }
+    }
+ }
+
+
+
+
+/**********************************************************************/
+/*                            Initialization.                         */
+/**********************************************************************/
+
+
+void intelInitTriFuncs( GLcontext *ctx )
+{
+   TNLcontext *tnl = TNL_CONTEXT(ctx);
+   static int firsttime = 1;
+
+   if (firsttime) {
+      init_rast_tab();
+      firsttime = 0;
+   }
+
+   tnl->Driver.RunPipeline = intelRunPipeline;
+   tnl->Driver.Render.Start = intelRenderStart;
+   tnl->Driver.Render.Finish = intelRenderFinish;
+   tnl->Driver.Render.PrimitiveNotify = intelRenderPrimitive;
+   tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple;
+   tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
+   tnl->Driver.Render.CopyPV = _tnl_copy_pv;
+   tnl->Driver.Render.Interp = _tnl_interp;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/extras/Mesa/src/mesa/main/glheader.h	Tue Oct 24 18:42:11 2006 -0700
@@ -0,0 +1,320 @@
+/**
+ * \file glheader.h
+ * Top-most include file.
+ *
+ * This is the top-most include file of the Mesa sources.
+ * It includes gl.h and all system headers which are needed.
+ * Other Mesa source files should \e not directly include any system
+ * headers.  This allows Mesa to be integrated into XFree86 and
+ * allows system-dependent hacks/workarounds to be collected in one place.
+ *
+ * \note Actually, a lot of system-dependent stuff is now in imports.[ch].
+ *
+ * If you touch this file, everything gets recompiled!
+ *
+ * This file should be included before any other header in the .c files.
+ *
+ * Put compiler/OS/assembly pragmas and macros here to avoid
+ * cluttering other source files.
+ */
+
+/*
+ * Mesa 3-D graphics library
+ * Version:  6.4.1
+ *
+ * Copyright (C) 1999-2005  Brian Paul   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 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
+ * BRIAN PAUL 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.
+ */
+
+
+#ifndef GLHEADER_H
+#define GLHEADER_H
+
+
+#if defined(XFree86LOADER) && defined(IN_MODULE)
+#include "xf86_ansic.h"
+#else
+#include <assert.h>
+#include <ctype.h>
+/* If we can use Compaq's Fast Math Library on Alpha */
+#if defined(__alpha__) && defined(CCPML)
+#include <cpml.h>
+#else
+#include <math.h>
+#endif
+#include <limits.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#if defined(__linux__) && defined(__i386__)
+#include <fpu_control.h>
+#endif
+#endif
+#include <float.h>
+#include <stdarg.h>
+
+/* Get typedefs for uintptr_t and friends */
+#if defined(__MINGW32__) || defined(__NetBSD__)
+#  include <stdint.h>
+#elif defined(_WIN32)
+#  include <BaseTsd.h>
+#  if _MSC_VER == 1200
+     typedef UINT_PTR uintptr_t;
+#  endif 
+#else
+#  include <inttypes.h>
+#endif
+
+#if defined(_WIN32) && !defined(__WIN32__) && !defined(__CYGWIN__) && !defined(BUILD_FOR_SNAP)
+#  define __WIN32__
+#  define finite _finite
+#endif
+
+#if defined(__WATCOMC__)
+#  define finite _finite
+#  pragma disable_message(201) /* Disable unreachable code warnings */
+#endif
+
+
+#if !defined(OPENSTEP) && (defined(__WIN32__) && !defined(__CYGWIN__)) && !defined(BUILD_FOR_SNAP)
+#  if !defined(__GNUC__) /* mingw environment */
+#    pragma warning( disable : 4068 ) /* unknown pragma */
+#    pragma warning( disable : 4710 ) /* function 'foo' not inlined */
+#    pragma warning( disable : 4711 ) /* function 'foo' selected for automatic inline expansion */
+#    pragma warning( disable : 4127 ) /* conditional expression is constant */
+#    if defined(MESA_MINWARN)
+#      pragma warning( disable : 4244 ) /* '=' : conversion from 'const double ' to 'float ', possible loss of data */
+#      pragma warning( disable : 4018 ) /* '<' : signed/unsigned mismatch */
+#      pragma warning( disable : 4305 ) /* '=' : truncation from 'const double ' to 'float ' */
+#      pragma warning( disable : 4550 ) /* 'function' undefined; assuming extern returning int */
+#      pragma warning( disable : 4761 ) /* integral size mismatch in argument; conversion supplied */
+#    endif
+#  endif
+#  if (defined(_MSC_VER) || defined(__MINGW32__)) && defined(BUILD_GL32) /* tag specify we're building mesa as a DLL */
+#    define WGLAPI __declspec(dllexport)
+#  elif (defined(_MSC_VER) || defined(__MINGW32__)) && defined(_DLL) /* tag specifying we're building for DLL runtime support */
+#    define WGLAPI __declspec(dllimport)
+#  else /* for use with static link lib build of Win32 edition only */
+#    define WGLAPI __declspec(dllimport)
+#  endif /* _STATIC_MESA support */
+#endif /* WIN32 / CYGWIN bracket */
+
+
+#ifndef __MINGW32__
+/* XXX why is this here?
+ * It should probaby be somewhere in src/mesa/drivers/windows/
+ */
+#if defined(_WIN32) && !defined(_WINGDI_) && !defined(_WINGDI_H) && !defined(_GNU_H_WINDOWS32_DEFINES) && !defined(OPENSTEP) && !defined(BUILD_FOR_SNAP) 
+#	define WGL_FONT_LINES      0
+#	define WGL_FONT_POLYGONS   1
+#ifndef _GNU_H_WINDOWS32_FUNCTIONS
+#	ifdef UNICODE
+#		define wglUseFontBitmaps  wglUseFontBitmapsW
+#		define wglUseFontOutlines  wglUseFontOutlinesW
+#	else
+#		define wglUseFontBitmaps  wglUseFontBitmapsA
+#		define wglUseFontOutlines  wglUseFontOutlinesA
+#	endif /* !UNICODE */
+#endif /* _GNU_H_WINDOWS32_FUNCTIONS */
+typedef struct tagLAYERPLANEDESCRIPTOR LAYERPLANEDESCRIPTOR, *PLAYERPLANEDESCRIPTOR, *LPLAYERPLANEDESCRIPTOR;
+typedef struct _GLYPHMETRICSFLOAT GLYPHMETRICSFLOAT, *PGLYPHMETRICSFLOAT, *LPGLYPHMETRICSFLOAT;
+typedef struct tagPIXELFORMATDESCRIPTOR PIXELFORMATDESCRIPTOR, *PPIXELFORMATDESCRIPTOR, *LPPIXELFORMATDESCRIPTOR;
+#if !defined(GLX_USE_MESA)
+#include <GL/mesa_wgl.h>
+#endif
+#endif
+#endif /* !__MINGW32__ */
+
+
+/*
+ * Either define MESA_BIG_ENDIAN or MESA_LITTLE_ENDIAN.
+ * Do not use them unless absolutely necessary!
+ * Try to use a runtime test instead.
+ * For now, only used by some DRI hardware drivers for color/texel packing.
+ */
+#if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN
+#if defined(__linux__)
+#include <byteswap.h>
+#define CPU_TO_LE32( x )	bswap_32( x )
+#else /*__linux__*/
+#define CPU_TO_LE32( x )	( x )  /* fix me for non-Linux big-endian! */
+#endif /*__linux__*/
+#define MESA_BIG_ENDIAN 1
+#else
+#define CPU_TO_LE32( x )	( x )
+#define MESA_LITTLE_ENDIAN 1
+#endif
+#define LE32_TO_CPU( x )	CPU_TO_LE32( x )
+
+
+#define GL_GLEXT_PROTOTYPES
+#include "GL/gl.h"
+#include "GL/glext.h"
+
+
+#if !defined(CAPI) && defined(WIN32) && !defined(BUILD_FOR_SNAP)
+#define CAPI _cdecl
+#endif
+#include <GL/internal/glcore.h>
+
+
+/* This is a macro on IRIX */
+#ifdef _P
+#undef _P
+#endif
+
+
+/* Turn off macro checking systems used by other libraries */
+#ifdef CHECK
+#undef CHECK
+#endif
+
+
+/* Create a macro so that asm functions can be linked into compilers other
+ * than GNU C
+ */
+#ifndef _ASMAPI
+#if defined(WIN32) && !defined(BUILD_FOR_SNAP)/* was: !defined( __GNUC__ ) && !defined( VMS ) && !defined( __INTEL_COMPILER )*/
+#define _ASMAPI __cdecl
+#else
+#define _ASMAPI
+#endif
+#ifdef	PTR_DECL_IN_FRONT
+#define	_ASMAPIP * _ASMAPI
+#else
+#define	_ASMAPIP _ASMAPI *
+#endif
+#endif
+
+#ifdef USE_X86_ASM
+#define _NORMAPI _ASMAPI
+#define _NORMAPIP _ASMAPIP
+#else
+#define _NORMAPI
+#define _NORMAPIP *
+#endif
+
+
+/* Function inlining */
+#if defined(__GNUC__)
+#  define INLINE __inline__
+#elif defined(__MSC__)
+#  define INLINE __inline
+#elif defined(_MSC_VER)
+#  define INLINE __inline
+#elif defined(__ICL)
+#  define INLINE __inline
+#elif defined(__INTEL_COMPILER)
+#  define INLINE inline
+#elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100)
+#  define INLINE __inline
+#else
+#  define INLINE
+#endif
+
+/* for Sun CC compiler */
+#if defined(__SOLARIS__) || defined(sun)
+#define __inline inline
+#define __inline__ inline
+#endif
+
+/* If we build the library with gcc's -fvisibility=hidden flag, we'll
+ * use the PUBLIC macro to mark functions that are to be exported.
+ *
+ * We also need to define a USED attribute, so the optimizer doesn't 
+ * inline a static function that we later use in an alias. - ajax
+ */
+#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303
+#  define PUBLIC __attribute__((visibility("default")))
+#  define USED __attribute__((used))
+#else
+#  define PUBLIC
+#  define USED
+#endif
+
+
+/* Some compilers don't like some of Mesa's const usage */
+#ifdef NO_CONST
+#  define CONST
+#else
+#  define CONST const
+#endif
+
+
+#if defined(BUILD_FOR_SNAP) && defined(CHECKED)
+#  define ASSERT(X)   _CHECK(X) 
+#elif defined(DEBUG)
+#  define ASSERT(X)   assert(X)
+#else
+#  define ASSERT(X)
+#endif
+
+
+#if !defined __GNUC__ || __GNUC__ < 3
+#  define __builtin_expect(x, y) x
+#endif
+
+/* Windows does not have the ffs() function */
+#if defined(_WIN32)
+static int INLINE
+ffs(register int value)
+{
+    register int bit = 0;
+    if (value != 0)
+    {
+        if ((value & 0xffff) == 0)
+        {
+            bit += 16;
+            value >>= 16;
+        }
+        if ((value & 0xff) == 0)
+        {
+            bit += 8;
+            value >>= 8;
+        }
+        if ((value & 0xf) == 0)
+        {
+            bit += 4;
+            value >>= 4;
+        }
+        while ((value & 1) == 0)
+        {
+            bit++;
+            value >>= 1;
+        }
+    }
+    return bit;
+}
+#endif
+
+
+/* The __FUNCTION__ gcc variable is generally only used for debugging.
+ * If we're not using gcc, define __FUNCTION__ as a cpp symbol here.
+ * Don't define it if using a newer Windows compiler.
+ */
+#if defined(__VMS)
+#define __FUNCTION__ "VMS$NL:"
+#elif !(defined(__GNUC__) && __GNUC__ >= 2) && !(defined(_MSC_VER) && _MSC_VER >= 1300)
+#define __FUNCTION__ "unknown"
+#endif
+
+
+#include "config.h"
+
+#endif /* GLHEADER_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/extras/Mesa/src/mesa/tnl_dd/t_dd_tritmp.h	Tue Oct 24 18:42:11 2006 -0700
@@ -0,0 +1,833 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  6.3
+ *
+ * Copyright (C) 1999-2005  Brian Paul   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 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
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Keith Whitwell <[email protected]>
+ */
+
+
+/* Template for building functions to plug into the driver interface
+ * of t_vb_render.c:
+ *     ctx->Driver.QuadFunc
+ *     ctx->Driver.TriangleFunc
+ *     ctx->Driver.LineFunc
+ *     ctx->Driver.PointsFunc
+ *
+ * DO_TWOSIDE:   Plug back-color values from the VB into backfacing triangles,
+ *               and restore vertices afterwards.
+ * DO_OFFSET:    Calculate offset for triangles and adjust vertices.  Restore
+ *               vertices after rendering.
+ * DO_FLAT:      For hardware without native flatshading, copy provoking colors
+ *               into the other vertices.  Restore after rendering.
+ * DO_UNFILLED:  Decompose triangles to lines and points where appropriate.
+ * DO_TWOSTENCIL:Gross hack for two-sided stencil.
+ *
+ * HAVE_RGBA: Vertices have rgba values (otherwise index values).
+ * HAVE_SPEC: Vertices have secondary rgba values.
+ *
+ * VERT_X(v): Alias for vertex x value.
+ * VERT_Y(v): Alias for vertex y value.
+ * VERT_Z(v): Alias for vertex z value.
+ * DEPTH_SCALE: Scale for constant offset.
+ * REVERSE_DEPTH: Viewport depth range reversed.
+ *
+ * VERTEX: Hardware vertex type.
+ * GET_VERTEX(n): Retreive vertex with index n.
+ * AREA_IS_CCW(a): Return true if triangle with signed area a is ccw.
+ *
+ * VERT_SET_RGBA: Assign vertex rgba from VB color.
+ * VERT_COPY_RGBA: Copy vertex rgba another vertex.
+ * VERT_SAVE_RGBA: Save vertex rgba to a local variable.
+ * VERT_RESTORE_RGBA: Restore vertex rgba from a local variable.
+ *   --> Similar for IND and SPEC.
+ *
+ * LOCAL_VARS(n): (At least) define local vars for save/restore rgba.
+ *
+ */
+
+#if HAVE_RGBA
+#define VERT_SET_IND( v, c ) (void) c
+#define VERT_COPY_IND( v0, v1 )
+#define VERT_SAVE_IND( idx )
+#define VERT_RESTORE_IND( idx )
+#if HAVE_BACK_COLORS
+#define VERT_SET_RGBA( v, c )
+#endif
+#else
+#define VERT_SET_RGBA( v, c ) (void) c
+#define VERT_COPY_RGBA( v0, v1 )
+#define VERT_SAVE_RGBA( idx )
+#define VERT_RESTORE_RGBA( idx )
+#if HAVE_BACK_COLORS
+#define VERT_SET_IND( v, c )
+#endif
+#endif
+
+#if !HAVE_SPEC
+#define VERT_SET_SPEC( v, c ) (void) c
+#define VERT_COPY_SPEC( v0, v1 )
+#define VERT_SAVE_SPEC( idx )
+#define VERT_RESTORE_SPEC( idx )
+#if HAVE_BACK_COLORS
+#define VERT_COPY_SPEC1( v )
+#endif
+#else
+#if HAVE_BACK_COLORS
+#define VERT_SET_SPEC( v, c )
+#endif
+#endif
+
+#if !HAVE_BACK_COLORS
+#define VERT_COPY_SPEC1( v )
+#define VERT_COPY_IND1( v )
+#define VERT_COPY_RGBA1( v )
+#endif
+
+#ifndef INSANE_VERTICES
+#define VERT_SET_Z(v,val) VERT_Z(v) = val
+#define VERT_Z_ADD(v,val) VERT_Z(v) += val
+#endif
+
+#ifndef REVERSE_DEPTH
+#define REVERSE_DEPTH 0
+#endif
+
+/* disable twostencil for un-aware drivers */
+#ifndef HAVE_STENCIL_TWOSIDE
+#define HAVE_STENCIL_TWOSIDE 0
+#endif
+#ifndef DO_TWOSTENCIL
+#define DO_TWOSTENCIL 0
+#endif
+#ifndef SETUP_STENCIL
+#define SETUP_STENCIL(f)
+#endif
+#ifndef UNSET_STENCIL
+#define UNSET_STENCIL(f)
+#endif
+
+#if DO_TRI
+static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
+{
+   struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
+   VERTEX *v[3];
+   GLfloat offset = 0;
+   GLfloat z[3];
+   GLenum mode = GL_FILL;
+   GLuint facing = 0;
+   LOCAL_VARS(3);
+
+/*     fprintf(stderr, "%s\n", __FUNCTION__); */
+
+   v[0] = (VERTEX *)GET_VERTEX(e0);
+   v[1] = (VERTEX *)GET_VERTEX(e1);
+   v[2] = (VERTEX *)GET_VERTEX(e2);
+
+   if (DO_TWOSIDE || DO_OFFSET || DO_UNFILLED || DO_TWOSTENCIL)
+   {
+      GLfloat ex = VERT_X(v[0]) - VERT_X(v[2]);
+      GLfloat ey = VERT_Y(v[0]) - VERT_Y(v[2]);
+      GLfloat fx = VERT_X(v[1]) - VERT_X(v[2]);
+      GLfloat fy = VERT_Y(v[1]) - VERT_Y(v[2]);
+      GLfloat cc = ex*fy - ey*fx;
+
+      if (DO_TWOSIDE || DO_UNFILLED || DO_TWOSTENCIL)
+      {
+	 facing = AREA_IS_CCW( cc ) ^ ctx->Polygon._FrontBit;
+
+         if (DO_TWOSTENCIL && ctx->Stencil.TestTwoSide) {
+            ctx->_Facing = facing; /* mixed mode rendering: for 2-sided stencil test */
+         }
+
+	 if (DO_UNFILLED) {
+	    if (facing) {
+	       mode = ctx->Polygon.BackMode;
+	       if (ctx->Polygon.CullFlag &&
+		   ctx->Polygon.CullFaceMode != GL_FRONT) {
+		  return;
+	       }
+	    } else {
+	       mode = ctx->Polygon.FrontMode;
+	       if (ctx->Polygon.CullFlag &&
+		   ctx->Polygon.CullFaceMode != GL_BACK) {
+		  return;
+	       }
+	    }
+	 }
+
+	 if (DO_TWOSIDE && facing == 1)
+	 {
+	    if (HAVE_RGBA) {
+	       if (HAVE_BACK_COLORS) {
+		  if (!DO_FLAT) {
+		     VERT_SAVE_RGBA( 0 );
+		     VERT_SAVE_RGBA( 1 );
+		     VERT_COPY_RGBA1( v[0] );
+		     VERT_COPY_RGBA1( v[1] );
+		  }
+		  VERT_SAVE_RGBA( 2 );
+		  VERT_COPY_RGBA1( v[2] );
+		  if (HAVE_SPEC) {
+		     if (!DO_FLAT) {
+			VERT_SAVE_SPEC( 0 );
+			VERT_SAVE_SPEC( 1 );
+			VERT_COPY_SPEC1( v[0] );
+			VERT_COPY_SPEC1( v[1] );
+		     }
+		     VERT_SAVE_SPEC( 2 );
+		     VERT_COPY_SPEC1( v[2] );
+		  }
+	       }
+	       else {
+		  GLfloat (*vbcolor)[4] = VB->ColorPtr[1]->data;
+		  (void) vbcolor;
+
+		  if (!DO_FLAT) {
+		     VERT_SAVE_RGBA( 0 );
+		     VERT_SAVE_RGBA( 1 );
+		  }
+		  VERT_SAVE_RGBA( 2 );
+
+		  if (VB->ColorPtr[1]->stride) {
+		     ASSERT(VB->ColorPtr[1]->stride == 4*sizeof(GLfloat));
+
+		     if (!DO_FLAT) {		  
+			VERT_SET_RGBA( v[0], vbcolor[e0] );
+			VERT_SET_RGBA( v[1], vbcolor[e1] );
+		     }
+		     VERT_SET_RGBA( v[2], vbcolor[e2] );
+		  }
+		  else {
+		     if (!DO_FLAT) {		  
+			VERT_SET_RGBA( v[0], vbcolor[0] );
+			VERT_SET_RGBA( v[1], vbcolor[0] );
+		     }
+		     VERT_SET_RGBA( v[2], vbcolor[0] );
+		  }
+
+		  if (HAVE_SPEC && VB->SecondaryColorPtr[1]) {
+		     GLfloat (*vbspec)[4] = VB->SecondaryColorPtr[1]->data;
+		     ASSERT(VB->SecondaryColorPtr[1]->stride == 4*sizeof(GLfloat));
+
+		     if (!DO_FLAT) {
+			VERT_SAVE_SPEC( 0 );
+			VERT_SAVE_SPEC( 1 );
+			VERT_SET_SPEC( v[0], vbspec[e0] );
+			VERT_SET_SPEC( v[1], vbspec[e1] );
+		     }
+		     VERT_SAVE_SPEC( 2 );
+		     VERT_SET_SPEC( v[2], vbspec[e2] );
+		  }
+	       }
+	    }
+	    else {
+	       GLfloat (*vbindex) = (GLfloat *)VB->IndexPtr[1]->data;
+	       if (!DO_FLAT) {
+		  VERT_SAVE_IND( 0 );
+		  VERT_SAVE_IND( 1 );
+		  VERT_SET_IND( v[0], vbindex[e0] );
+		  VERT_SET_IND( v[1], vbindex[e1] );
+	       }
+	       VERT_SAVE_IND( 2 );
+	       VERT_SET_IND( v[2], vbindex[e2] );
+	    }
+	 }
+      }
+
+
+      if (DO_OFFSET)
+      {
+	 offset = ctx->Polygon.OffsetUnits * DEPTH_SCALE;
+	 z[0] = VERT_Z(v[0]);
+	 z[1] = VERT_Z(v[1]);
+	 z[2] = VERT_Z(v[2]);
+	 if (cc * cc > 1e-16) {
+	    GLfloat ic	= 1.0 / cc;
+	    GLfloat ez	= z[0] - z[2];
+	    GLfloat fz	= z[1] - z[2];
+	    GLfloat a	= ey*fz - ez*fy;
+	    GLfloat b	= ez*fx - ex*fz;
+	    GLfloat ac	= a * ic;
+	    GLfloat bc	= b * ic;
+	    if ( ac < 0.0f ) ac = -ac;
+	    if ( bc < 0.0f ) bc = -bc;
+	    offset += MAX2( ac, bc ) * ctx->Polygon.OffsetFactor;
+	 }
+	 offset *= ctx->DrawBuffer->_MRD * (REVERSE_DEPTH ? -1.0 : 1.0);
+      }
+   }
+
+   if (DO_FLAT) {
+      if (HAVE_RGBA) {
+	 VERT_SAVE_RGBA( 0 );
+	 VERT_SAVE_RGBA( 1 );
+	 VERT_COPY_RGBA( v[0], v[2] );
+	 VERT_COPY_RGBA( v[1], v[2] );
+	 if (HAVE_SPEC && VB->SecondaryColorPtr[0]) {
+	    VERT_SAVE_SPEC( 0 );
+	    VERT_SAVE_SPEC( 1 );
+	    VERT_COPY_SPEC( v[0], v[2] );
+	    VERT_COPY_SPEC( v[1], v[2] );
+	 }
+      }
+      else {
+	 VERT_SAVE_IND( 0 );
+	 VERT_SAVE_IND( 1 );
+	 VERT_COPY_IND( v[0], v[2] );
+	 VERT_COPY_IND( v[1], v[2] );
+      }
+   }
+
+   if (mode == GL_POINT) {
+      if (DO_OFFSET && ctx->Polygon.OffsetPoint) {
+	 VERT_Z_ADD(v[0], offset);
+	 VERT_Z_ADD(v[1], offset);
+	 VERT_Z_ADD(v[2], offset);
+      }
+      if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
+         SETUP_STENCIL(facing);
+         UNFILLED_TRI( ctx, GL_POINT, e0, e1, e2 );
+         UNSET_STENCIL(facing);
+      } else {
+         UNFILLED_TRI( ctx, GL_POINT, e0, e1, e2 );
+      }
+   } else if (mode == GL_LINE) {
+      if (DO_OFFSET && ctx->Polygon.OffsetLine) {
+	 VERT_Z_ADD(v[0], offset);
+	 VERT_Z_ADD(v[1], offset);
+	 VERT_Z_ADD(v[2], offset);
+      }
+      if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
+         SETUP_STENCIL(facing);
+         UNFILLED_TRI( ctx, GL_LINE, e0, e1, e2 );
+         UNSET_STENCIL(facing);
+      } else {
+         UNFILLED_TRI( ctx, GL_LINE, e0, e1, e2 );
+      }
+   } else {
+      if (DO_OFFSET && ctx->Polygon.OffsetFill) {
+	 VERT_Z_ADD(v[0], offset);
+	 VERT_Z_ADD(v[1], offset);
+	 VERT_Z_ADD(v[2], offset);
+      }
+      if (DO_UNFILLED)
+	 RASTERIZE( GL_TRIANGLES );
+      if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
+         SETUP_STENCIL(facing);
+         TRI( v[0], v[1], v[2] );
+         UNSET_STENCIL(facing);
+      } else {
+         TRI( v[0], v[1], v[2] );
+      }
+   }
+
+   if (DO_OFFSET)
+   {
+      VERT_SET_Z(v[0], z[0]);
+      VERT_SET_Z(v[1], z[1]);
+      VERT_SET_Z(v[2], z[2]);
+   }
+
+   if (DO_TWOSIDE && facing == 1)
+   {
+      if (HAVE_RGBA) {
+	 if (!DO_FLAT) {
+	    VERT_RESTORE_RGBA( 0 );
+	    VERT_RESTORE_RGBA( 1 );
+	 }
+	 VERT_RESTORE_RGBA( 2 );
+	 if (HAVE_SPEC) {
+	    if (!DO_FLAT) {
+	       VERT_RESTORE_SPEC( 0 );
+	       VERT_RESTORE_SPEC( 1 );
+	    }
+	    VERT_RESTORE_SPEC( 2 );
+	 }
+      }
+      else {
+	 if (!DO_FLAT) {
+	    VERT_RESTORE_IND( 0 );
+	    VERT_RESTORE_IND( 1 );
+	 }
+	 VERT_RESTORE_IND( 2 );
+      }
+   }
+
+
+   if (DO_FLAT) {
+      if (HAVE_RGBA) {
+	 VERT_RESTORE_RGBA( 0 );
+	 VERT_RESTORE_RGBA( 1 );
+	 if (HAVE_SPEC && VB->SecondaryColorPtr[0]) {
+	    VERT_RESTORE_SPEC( 0 );
+	    VERT_RESTORE_SPEC( 1 );
+	 }
+      }
+      else {
+	 VERT_RESTORE_IND( 0 );
+	 VERT_RESTORE_IND( 1 );
+      }
+   }
+}
+#endif
+
+#if DO_QUAD
+#if DO_FULL_QUAD
+static void TAG(quadr)( GLcontext *ctx,
+		       GLuint e0, GLuint e1, GLuint e2, GLuint e3 )
+{
+   struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
+   VERTEX *v[4];
+   GLfloat offset = 0;
+   GLfloat z[4];
+   GLenum mode = GL_FILL;
+   GLuint facing = 0;
+   LOCAL_VARS(4);
+
+   v[0] = (VERTEX *)GET_VERTEX(e0);
+   v[1] = (VERTEX *)GET_VERTEX(e1);
+   v[2] = (VERTEX *)GET_VERTEX(e2);
+   v[3] = (VERTEX *)GET_VERTEX(e3);
+
+   if (DO_TWOSIDE || DO_OFFSET || DO_UNFILLED || DO_TWOSTENCIL)
+   {
+      GLfloat ex = VERT_X(v[2]) - VERT_X(v[0]);
+      GLfloat ey = VERT_Y(v[2]) - VERT_Y(v[0]);
+      GLfloat fx = VERT_X(v[3]) - VERT_X(v[1]);
+      GLfloat fy = VERT_Y(v[3]) - VERT_Y(v[1]);
+      GLfloat cc = ex*fy - ey*fx;
+
+      if (DO_TWOSIDE || DO_UNFILLED || DO_TWOSTENCIL)
+      {
+	 facing = AREA_IS_CCW( cc ) ^ ctx->Polygon._FrontBit;
+
+         if (DO_TWOSTENCIL && ctx->Stencil.TestTwoSide) {
+            ctx->_Facing = facing; /* mixed mode rendering: for 2-sided stencil test */
+         }
+
+	 if (DO_UNFILLED) {
+	    if (facing) {
+	       mode = ctx->Polygon.BackMode;
+	       if (ctx->Polygon.CullFlag &&
+		   ctx->Polygon.CullFaceMode != GL_FRONT) {
+		  return;
+	       }
+	    } else {
+	       mode = ctx->Polygon.FrontMode;
+	       if (ctx->Polygon.CullFlag &&
+		   ctx->Polygon.CullFaceMode != GL_BACK) {
+		  return;
+	       }
+	    }
+	 }
+
+	 if (DO_TWOSIDE && facing == 1)
+	 {
+	    if (HAVE_RGBA) {
+	       GLfloat (*vbcolor)[4] = VB->ColorPtr[1]->data;
+	       (void)vbcolor;
+
+	       if (HAVE_BACK_COLORS) {
+                  if (!DO_FLAT) {
+                     VERT_SAVE_RGBA( 0 );
+                     VERT_SAVE_RGBA( 1 );
+                     VERT_SAVE_RGBA( 2 );
+		     VERT_COPY_RGBA1( v[0] );
+		     VERT_COPY_RGBA1( v[1] );
+		     VERT_COPY_RGBA1( v[2] );
+		  }
+		  VERT_SAVE_RGBA( 3 );
+		  VERT_COPY_RGBA1( v[3] );
+		  if (HAVE_SPEC) {
+                     if (!DO_FLAT) {
+                        VERT_SAVE_SPEC( 0 );
+                        VERT_SAVE_SPEC( 1 );
+                        VERT_SAVE_SPEC( 2 );
+			VERT_COPY_SPEC1( v[0] );
+			VERT_COPY_SPEC1( v[1] );
+			VERT_COPY_SPEC1( v[2] );
+		     }
+		     VERT_SAVE_SPEC( 3 );
+		     VERT_COPY_SPEC1( v[3] );
+		  }
+	       }
+	       else {
+	          if (!DO_FLAT) {
+		     VERT_SAVE_RGBA( 0 );
+		     VERT_SAVE_RGBA( 1 );
+		     VERT_SAVE_RGBA( 2 );
+		  }
+	          VERT_SAVE_RGBA( 3 );
+
+		  if (VB->ColorPtr[1]->stride) {
+		     if (!DO_FLAT) {
+			VERT_SET_RGBA( v[0], vbcolor[e0] );
+			VERT_SET_RGBA( v[1], vbcolor[e1] );
+			VERT_SET_RGBA( v[2], vbcolor[e2] );
+		     }
+		     VERT_SET_RGBA( v[3], vbcolor[e3] );
+		  }
+		  else {
+		     if (!DO_FLAT) {
+			VERT_SET_RGBA( v[0], vbcolor[0] );
+			VERT_SET_RGBA( v[1], vbcolor[0] );
+			VERT_SET_RGBA( v[2], vbcolor[0] );
+		     }
+		     VERT_SET_RGBA( v[3], vbcolor[0] );
+		  }
+
+	          if (HAVE_SPEC && VB->SecondaryColorPtr[1]) {
+		     GLfloat (*vbspec)[4] = VB->SecondaryColorPtr[1]->data;
+		     ASSERT(VB->SecondaryColorPtr[1]->stride==4*sizeof(GLfloat));
+
+		     if (!DO_FLAT) {
+		        VERT_SAVE_SPEC( 0 );
+		        VERT_SAVE_SPEC( 1 );
+		        VERT_SAVE_SPEC( 2 );
+		        VERT_SET_SPEC( v[0], vbspec[e0] );
+		        VERT_SET_SPEC( v[1], vbspec[e1] );
+		        VERT_SET_SPEC( v[2], vbspec[e2] );
+		     }
+		     VERT_SAVE_SPEC( 3 );
+		     VERT_SET_SPEC( v[3], vbspec[e3] );
+	          }
+	       }
+	    }
+	    else {
+	       GLfloat *vbindex = (GLfloat *)VB->IndexPtr[1]->data;
+	       if (!DO_FLAT) {
+		  VERT_SAVE_IND( 0 );
+		  VERT_SAVE_IND( 1 );
+		  VERT_SAVE_IND( 2 );
+		  VERT_SET_IND( v[0], vbindex[e0] );
+		  VERT_SET_IND( v[1], vbindex[e1] );
+		  VERT_SET_IND( v[2], vbindex[e2] );
+	       }
+	       VERT_SAVE_IND( 3 );
+	       VERT_SET_IND( v[3], vbindex[e3] );
+	    }
+	 }
+      }
+
+
+      if (DO_OFFSET)
+      {
+	 offset = ctx->Polygon.OffsetUnits * DEPTH_SCALE;
+	 z[0] = VERT_Z(v[0]);
+	 z[1] = VERT_Z(v[1]);
+	 z[2] = VERT_Z(v[2]);
+	 z[3] = VERT_Z(v[3]);
+	 if (cc * cc > 1e-16) {
+	    GLfloat ez = z[2] - z[0];
+	    GLfloat fz = z[3] - z[1];
+	    GLfloat a	= ey*fz - ez*fy;
+	    GLfloat b	= ez*fx - ex*fz;
+	    GLfloat ic	= 1.0 / cc;
+	    GLfloat ac	= a * ic;
+	    GLfloat bc	= b * ic;
+	    if ( ac < 0.0f ) ac = -ac;
+	    if ( bc < 0.0f ) bc = -bc;
+	    offset += MAX2( ac, bc ) * ctx->Polygon.OffsetFactor;
+	 }
+	 offset *= ctx->DrawBuffer->_MRD * (REVERSE_DEPTH ? -1.0 : 1.0);
+      }
+   }
+
+   if (DO_FLAT) {
+      if (HAVE_RGBA) {
+	 VERT_SAVE_RGBA( 0 );
+	 VERT_SAVE_RGBA( 1 );
+	 VERT_SAVE_RGBA( 2 );
+	 VERT_COPY_RGBA( v[0], v[3] );
+	 VERT_COPY_RGBA( v[1], v[3] );
+	 VERT_COPY_RGBA( v[2], v[3] );
+	 if (HAVE_SPEC && VB->SecondaryColorPtr[0]) {
+	    VERT_SAVE_SPEC( 0 );
+	    VERT_SAVE_SPEC( 1 );
+	    VERT_SAVE_SPEC( 2 );
+	    VERT_COPY_SPEC( v[0], v[3] );
+	    VERT_COPY_SPEC( v[1], v[3] );
+	    VERT_COPY_SPEC( v[2], v[3] );
+	 }
+      }
+      else {
+	 VERT_SAVE_IND( 0 );
+	 VERT_SAVE_IND( 1 );
+	 VERT_SAVE_IND( 2 );
+	 VERT_COPY_IND( v[0], v[3] );
+	 VERT_COPY_IND( v[1], v[3] );
+	 VERT_COPY_IND( v[2], v[3] );
+      }
+   }
+
+   if (mode == GL_POINT) {
+      if (( DO_OFFSET) && ctx->Polygon.OffsetPoint) {
+	 VERT_Z_ADD(v[0], offset);
+	 VERT_Z_ADD(v[1], offset);
+	 VERT_Z_ADD(v[2], offset);
+	 VERT_Z_ADD(v[3], offset);
+      }
+      if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
+         SETUP_STENCIL(facing);
+         UNFILLED_QUAD( ctx, GL_POINT, e0, e1, e2, e3 );
+         UNSET_STENCIL(facing);
+      } else {
+         UNFILLED_QUAD( ctx, GL_POINT, e0, e1, e2, e3 );
+      }
+   } else if (mode == GL_LINE) {
+      if (DO_OFFSET && ctx->Polygon.OffsetLine) {
+	 VERT_Z_ADD(v[0], offset);
+	 VERT_Z_ADD(v[1], offset);
+	 VERT_Z_ADD(v[2], offset);
+	 VERT_Z_ADD(v[3], offset);
+      }
+      if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
+         SETUP_STENCIL(facing);
+         UNFILLED_QUAD( ctx, GL_LINE, e0, e1, e2, e3 );
+         UNSET_STENCIL(facing);
+      } else {
+         UNFILLED_QUAD( ctx, GL_LINE, e0, e1, e2, e3 );
+      }
+   } else {
+      if (DO_OFFSET && ctx->Polygon.OffsetFill) {
+	 VERT_Z_ADD(v[0], offset);
+	 VERT_Z_ADD(v[1], offset);
+	 VERT_Z_ADD(v[2], offset);
+	 VERT_Z_ADD(v[3], offset);
+      }
+      RASTERIZE( GL_QUADS );
+      if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
+         SETUP_STENCIL(facing);
+         QUAD( (v[0]), (v[1]), (v[2]), (v[3]) );
+         UNSET_STENCIL(facing);
+      } else {
+         QUAD( (v[0]), (v[1]), (v[2]), (v[3]) );
+      }
+   }
+
+   if (DO_OFFSET)
+   {
+      VERT_SET_Z(v[0], z[0]);
+      VERT_SET_Z(v[1], z[1]);
+      VERT_SET_Z(v[2], z[2]);
+      VERT_SET_Z(v[3], z[3]);
+   }
+
+   if (DO_TWOSIDE && facing == 1)
+   {
+      if (HAVE_RGBA) {
+	 if (!DO_FLAT) {
+	    VERT_RESTORE_RGBA( 0 );
+	    VERT_RESTORE_RGBA( 1 );
+	    VERT_RESTORE_RGBA( 2 );
+	 }
+	 VERT_RESTORE_RGBA( 3 );
+	 if (HAVE_SPEC) {
+	    if (!DO_FLAT) {
+	       VERT_RESTORE_SPEC( 0 );
+	       VERT_RESTORE_SPEC( 1 );
+	       VERT_RESTORE_SPEC( 2 );
+	    }
+	    VERT_RESTORE_SPEC( 3 );
+	 }
+      }
+      else {
+	 if (!DO_FLAT) {
+	    VERT_RESTORE_IND( 0 );
+	    VERT_RESTORE_IND( 1 );
+	    VERT_RESTORE_IND( 2 );
+	 }
+	 VERT_RESTORE_IND( 3 );
+      }
+   }
+
+
+   if (DO_FLAT) {
+      if (HAVE_RGBA) {
+	 VERT_RESTORE_RGBA( 0 );
+	 VERT_RESTORE_RGBA( 1 );
+	 VERT_RESTORE_RGBA( 2 );
+	 if (HAVE_SPEC && VB->SecondaryColorPtr[0]) {
+	    VERT_RESTORE_SPEC( 0 );
+	    VERT_RESTORE_SPEC( 1 );
+	    VERT_RESTORE_SPEC( 2 );
+	 }
+      }
+      else {
+	 VERT_RESTORE_IND( 0 );
+	 VERT_RESTORE_IND( 1 );
+	 VERT_RESTORE_IND( 2 );
+      }
+   }
+}
+#else
+static void TAG(quadr)( GLcontext *ctx, GLuint e0,
+		       GLuint e1, GLuint e2, GLuint e3 )
+{
+   if (DO_UNFILLED) {
+      struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
+      GLubyte ef1 = VB->EdgeFlag[e1];
+      GLubyte ef3 = VB->EdgeFlag[e3];
+      VB->EdgeFlag[e1] = 0;
+      TAG(triangle)( ctx, e0, e1, e3 );
+      VB->EdgeFlag[e1] = ef1;
+      VB->EdgeFlag[e3] = 0;
+      TAG(triangle)( ctx, e1, e2, e3 );
+      VB->EdgeFlag[e3] = ef3;
+   } else {
+      TAG(triangle)( ctx, e0, e1, e3 );
+      TAG(triangle)( ctx, e1, e2, e3 );
+   }
+}
+#endif
+#endif
+
+#if DO_LINE
+static void TAG(line)( GLcontext *ctx, GLuint e0, GLuint e1 )
+{
+   struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
+   VERTEX *v[2];
+   LOCAL_VARS(2);
+
+   v[0] = (VERTEX *)GET_VERTEX(e0);
+   v[1] = (VERTEX *)GET_VERTEX(e1);
+
+   if (DO_FLAT) {
+      if (HAVE_RGBA) {
+	 VERT_SAVE_RGBA( 0 );
+	 VERT_COPY_RGBA( v[0], v[1] );
+	 if (HAVE_SPEC && VB->SecondaryColorPtr[0]) {
+	    VERT_SAVE_SPEC( 0 );
+	    VERT_COPY_SPEC( v[0], v[1] );
+	 }
+      }
+      else {
+	 VERT_SAVE_IND( 0 );
+	 VERT_COPY_IND( v[0], v[1] );
+      }
+   }
+
+   LINE( v[0], v[1] );
+
+   if (DO_FLAT) {
+      if (HAVE_RGBA) {
+	 VERT_RESTORE_RGBA( 0 );
+
+	 if (HAVE_SPEC && VB->SecondaryColorPtr[0]) {
+	    VERT_RESTORE_SPEC( 0 );
+	 }
+      }
+      else {
+	 VERT_RESTORE_IND( 0 );
+      }
+   }
+}
+#endif
+
+#if DO_POINTS
+static void TAG(points)( GLcontext *ctx, GLuint first, GLuint last )
+{
+   struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
+   GLuint i;
+   LOCAL_VARS(1);
+
+   if (VB->Elts == 0) {
+      for ( i = first ; i < last ; i++ ) {
+	 if ( VB->ClipMask[i] == 0 ) {
+	    VERTEX *v = (VERTEX *)GET_VERTEX(i);
+	    POINT( v );
+	 }
+      }
+   } else {
+      for ( i = first ; i < last ; i++ ) {
+	 GLuint e = VB->Elts[i];
+	 if ( VB->ClipMask[e] == 0 ) {
+	    VERTEX *v = (VERTEX *)GET_VERTEX(e);
+	    POINT( v );
+	 }
+      }
+   }
+}
+#endif
+
+static void TAG(init)( void )
+{
+#if DO_QUAD
+   TAB[IND].quad = TAG(quadr);
+#endif
+#if DO_TRI
+   TAB[IND].triangle = TAG(triangle);
+#endif
+#if DO_LINE
+   TAB[IND].line = TAG(line);
+#endif
+#if DO_POINTS
+   TAB[IND].points = TAG(points);
+#endif
+}
+
+#undef IND
+#undef TAG
+
+#if HAVE_RGBA
+#undef VERT_SET_IND
+#undef VERT_COPY_IND
+#undef VERT_SAVE_IND
+#undef VERT_RESTORE_IND
+#if HAVE_BACK_COLORS
+#undef VERT_SET_RGBA
+#endif
+#else
+#undef VERT_SET_RGBA
+#undef VERT_COPY_RGBA
+#undef VERT_SAVE_RGBA
+#undef VERT_RESTORE_RGBA
+#if HAVE_BACK_COLORS
+#undef VERT_SET_IND
+#endif
+#endif
+
+#if !HAVE_SPEC
+#undef VERT_SET_SPEC
+#undef VERT_COPY_SPEC
+#undef VERT_SAVE_SPEC
+#undef VERT_RESTORE_SPEC
+#if HAVE_BACK_COLORS
+#undef VERT_COPY_SPEC1
+#endif
+#else
+#if HAVE_BACK_COLORS
+#undef VERT_SET_SPEC
+#endif
+#endif
+
+#if !HAVE_BACK_COLORS
+#undef VERT_COPY_SPEC1
+#undef VERT_COPY_IND1
+#undef VERT_COPY_RGBA1
+#endif
+
+#ifndef INSANE_VERTICES
+#undef VERT_SET_Z
+#undef VERT_Z_ADD
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/extras/drm/libdrm/xf86drm.c	Tue Oct 24 18:42:11 2006 -0700
@@ -0,0 +1,2340 @@
+/**
+ * \file xf86drm.c
+ * User-level interface to DRM device
+ *
+ * \author Rickard E. (Rik) Faith <[email protected]>
+ * \author Kevin E. Martin <[email protected]>
+ */
+
+/*
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drm.c,v 1.36 2003/08/24 17:35:35 tsi Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifdef XFree86Server
+# include "xf86.h"
+# include "xf86_OSproc.h"
+# include "drm.h"
+# include "xf86_ansic.h"
+# define _DRM_MALLOC xalloc
+# define _DRM_FREE   xfree
+# ifndef XFree86LOADER
+#  include <sys/mman.h>
+# endif
+#else
+# include <stdio.h>
+# include <stdlib.h>
+# include <unistd.h>
+# include <string.h>
+# include <ctype.h>
+# include <fcntl.h>
+# include <errno.h>
+# include <signal.h>
+# include <sys/types.h>
+# include <sys/stat.h>
+# define stat_t struct stat
+# include <sys/ioctl.h>
+# include <sys/mman.h>
+# include <sys/time.h>
+# include <stdarg.h>
+# ifdef DRM_USE_MALLOC
+#  define _DRM_MALLOC malloc
+#  define _DRM_FREE   free
+# else
+#  define _DRM_MALLOC malloc
+#  define _DRM_FREE   free
+# endif
+# include "drm.h"
+#endif
+
+/* No longer needed with CVS kernel modules on alpha
+#if defined(__alpha__) && defined(__linux__)
+extern unsigned long _bus_base(void);
+#define BUS_BASE _bus_base()
+#endif
+*/
+
+/* Not all systems have MAP_FAILED defined */
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *)-1)
+#endif
+
+#include "xf86drm.h"
+
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#define DRM_MAJOR 145
+#endif
+
+#ifdef __NetBSD__
+#define DRM_MAJOR 34
+#endif
+
+# ifdef __OpenBSD__
+#  define DRM_MAJOR 81
+# endif
+
+#ifndef DRM_MAJOR
+#define DRM_MAJOR 226		/* Linux */
+#endif
+
+#ifndef DRM_MAX_MINOR
+#define DRM_MAX_MINOR 16
+#endif
+
+#ifndef makedev
+				/* This definition needs to be changed on
+                                   some systems if dev_t is a structure.
+                                   If there is a header file we can get it
+                                   from, there would be best. */
+#define makedev(x,y)    ((dev_t)(((x) << 8) | (y)))
+#endif
+
+#define DRM_MSG_VERBOSITY 3
+
+/**
+ * Output a message to stderr.
+ *
+ * \param format printf() like format string.
+ *
+ * \internal
+ * This function is a wrapper around vfprintf().
+ */
+static void
+drmMsg(const char *format, ...)
+{
+    va_list	ap;
+
+#ifndef XFree86Server
+    const char *env;
+    if ((env = getenv("LIBGL_DEBUG")) && strstr(env, "verbose"))
+#endif
+    {
+	va_start(ap, format);
+#ifdef XFree86Server
+	xf86VDrvMsgVerb(-1, X_NONE, DRM_MSG_VERBOSITY, format, ap);
+#else
+	vfprintf(stderr, format, ap);
+#endif
+	va_end(ap);
+    }
+}
+
+static void *drmHashTable = NULL; /* Context switch callbacks */
+
+typedef struct drmHashEntry {
+    int      fd;
+    void     (*f)(int, void *, void *);
+    void     *tagTable;
+} drmHashEntry;
+
+void *drmMalloc(int size)
+{
+    void *pt;
+    if ((pt = _DRM_MALLOC(size))) memset(pt, 0, size);
+    return pt;
+}
+
+void drmFree(void *pt)
+{
+    if (pt) _DRM_FREE(pt);
+}
+
+/* drmStrdup can't use strdup(3), since it doesn't call _DRM_MALLOC... */
+static char *drmStrdup(const char *s)
+{
+    char *retval = NULL;
+
+    if (s) {
+	retval = _DRM_MALLOC(strlen(s)+1);
+	strcpy(retval, s);
+    }
+    return retval;
+}
+
+
+static unsigned long drmGetKeyFromFd(int fd)
+{
+    stat_t     st;
+
+    st.st_rdev = 0;
+    fstat(fd, &st);
+    return st.st_rdev;
+}
+
+static drmHashEntry *drmGetEntry(int fd)
+{
+    unsigned long key = drmGetKeyFromFd(fd);
+    void          *value;
+    drmHashEntry  *entry;
+
+    if (!drmHashTable) drmHashTable = drmHashCreate();
+
+    if (drmHashLookup(drmHashTable, key, &value)) {
+	entry           = drmMalloc(sizeof(*entry));
+	entry->fd       = fd;
+	entry->f        = NULL;
+	entry->tagTable = drmHashCreate();
+	drmHashInsert(drmHashTable, key, entry);
+    } else {
+	entry = value;
+    }
+    return entry;
+}
+
+/**
+ * Compare two busid strings
+ *
+ * \param first
+ * \param second
+ *
+ * \return 1 if matched.
+ *
+ * \internal
+ * This function compares two bus ID strings.  It understands the older
+ * PCI:b:d:f format and the newer pci:oooo:bb:dd.f format.  In the format, o is
+ * domain, b is bus, d is device, f is function.
+ */
+static int drmMatchBusID(const char *id1, const char *id2)
+{
+    /* First, check if the IDs are exactly the same */
+    if (strcasecmp(id1, id2) == 0)
+	return 1;
+
+    /* Try to match old/new-style PCI bus IDs. */
+    if (strncasecmp(id1, "pci", 3) == 0) {
+	int o1, b1, d1, f1;
+	int o2, b2, d2, f2;
+	int ret;
+
+	ret = sscanf(id1, "pci:%04x:%02x:%02x.%d", &o1, &b1, &d1, &f1);
+	if (ret != 4) {
+	    o1 = 0;
+	    ret = sscanf(id1, "PCI:%d:%d:%d", &b1, &d1, &f1);
+	    if (ret != 3)
+		return 0;
+	}
+
+	ret = sscanf(id2, "pci:%04x:%02x:%02x.%d", &o2, &b2, &d2, &f2);
+	if (ret != 4) {
+	    o2 = 0;
+	    ret = sscanf(id2, "PCI:%d:%d:%d", &b2, &d2, &f2);
+	    if (ret != 3)
+		return 0;
+	}
+
+	if ((o1 != o2) || (b1 != b2) || (d1 != d2) || (f1 != f2))
+	    return 0;
+	else
+	    return 1;
+    }
+    return 0;
+}
+
+/**
+ * Open the DRM device, creating it if necessary.
+ *
+ * \param dev major and minor numbers of the device.
+ * \param minor minor number of the device.
+ *
+ * \return a file descriptor on success, or a negative value on error.
+ *
+ * \internal
+ * Assembles the device name from \p minor and opens it, creating the device
+ * special file node with the major and minor numbers specified by \p dev and
+ * parent directory if necessary and was called by root.
+ */
+static int drmOpenDevice(long dev, int minor)
+{
+    stat_t          st;
+    char            buf[64];
+    int             fd;
+    mode_t          devmode = DRM_DEV_MODE;
+    int             isroot  = !geteuid();
+#if defined(XFree86Server)
+    uid_t           user    = DRM_DEV_UID;
+    gid_t           group   = DRM_DEV_GID;
+#endif
+
+    sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, minor);
+    drmMsg("drmOpenDevice: node name is %s\n", buf);
+
+#if defined(XFree86Server)
+    devmode  = xf86ConfigDRI.mode ? xf86ConfigDRI.mode : DRM_DEV_MODE;
+    devmode &= ~(S_IXUSR|S_IXGRP|S_IXOTH);
+    group = (xf86ConfigDRI.group >= 0) ? xf86ConfigDRI.group : DRM_DEV_GID;
+#endif
+
+    if (stat(DRM_DIR_NAME, &st)) {
+	if (!isroot) return DRM_ERR_NOT_ROOT;
+	mkdir(DRM_DIR_NAME, DRM_DEV_DIRMODE);
+	chown(DRM_DIR_NAME, 0, 0); /* root:root */
+	chmod(DRM_DIR_NAME, DRM_DEV_DIRMODE);
+    }
+
+    /* Check if the device node exists and create it if necessary. */
+    if (stat(buf, &st)) {
+	if (!isroot) return DRM_ERR_NOT_ROOT;
+	remove(buf);
+	mknod(buf, S_IFCHR | devmode, dev);
+    }
+#if defined(XFree86Server)
+    chown(buf, user, group);
+    chmod(buf, devmode);
+#endif
+
+    fd = open(buf, O_RDWR, 0);
+    drmMsg("drmOpenDevice: open result is %d, (%s)\n",
+		fd, fd < 0 ? strerror(errno) : "OK");
+    if (fd >= 0) return fd;
+
+    /* Check if the device node is not what we expect it to be, and recreate it
+     * and try again if so.
+     */
+    if (st.st_rdev != dev) {
+	if (!isroot) return DRM_ERR_NOT_ROOT;
+	remove(buf);
+	mknod(buf, S_IFCHR | devmode, dev);
+#if defined(XFree86Server)
+	chown(buf, user, group);
+	chmod(buf, devmode);
+#endif
+    }
+    fd = open(buf, O_RDWR, 0);
+    drmMsg("drmOpenDevice: open result is %d, (%s)\n",
+		fd, fd < 0 ? strerror(errno) : "OK");
+    if (fd >= 0) return fd;
+
+    drmMsg("drmOpenDevice: Open failed\n");
+    remove(buf);
+    return -errno;
+}
+
+
+/**
+ * Open the DRM device
+ *
+ * \param minor device minor number.
+ * \param create allow to create the device if set.
+ *
+ * \return a file descriptor on success, or a negative value on error.
+ *
+ * \internal
+ * Calls drmOpenDevice() if \p create is set, otherwise assembles the device
+ * name from \p minor and opens it.
+ */
+static int drmOpenMinor(int minor, int create)
+{
+    int  fd;
+    char buf[64];
+
+    if (create) return drmOpenDevice(makedev(DRM_MAJOR, minor), minor);
+
+    sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, minor);
+    if ((fd = open(buf, O_RDWR, 0)) >= 0) return fd;
+    return -errno;
+}
+
+
+/**
+ * Determine whether the DRM kernel driver has been loaded.
+ *
+ * \return 1 if the DRM driver is loaded, 0 otherwise.
+ *
+ * \internal
+ * Determine the presence of the kernel driver by attempting to open the 0
+ * minor and get version information.  For backward compatibility with older
+ * Linux implementations, /proc/dri is also checked.
+ */
+int drmAvailable(void)
+{
+    drmVersionPtr version;
+    int           retval = 0;
+    int           fd;
+
+    if ((fd = drmOpenMinor(0, 1)) < 0) {
+#ifdef __linux__
+				/* Try proc for backward Linux compatibility */
+	if (!access("/proc/dri/0", R_OK)) return 1;
+#endif
+	return 0;
+    }
+
+    if ((version = drmGetVersion(fd))) {
+	retval = 1;
+	drmFreeVersion(version);
+    }
+    close(fd);
+
+    return retval;
+}
+
+
+/**
+ * Open the device by bus ID.
+ *
+ * \param busid bus ID.
+ *
+ * \return a file descriptor on success, or a negative value on error.
+ *
+ * \internal
+ * This function attempts to open every possible minor (up to DRM_MAX_MINOR),
+ * comparing the device bus ID with the one supplied.
+ *
+ * \sa drmOpenMinor() and drmGetBusid().
+ */
+static int drmOpenByBusid(const char *busid)
+{
+    int        i;
+    int        fd;
+    const char *buf;
+    drmSetVersion sv;
+
+    drmMsg("drmOpenByBusid: Searching for BusID %s\n", busid);
+    for (i = 0; i < DRM_MAX_MINOR; i++) {
+	fd = drmOpenMinor(i, 1);
+	drmMsg("drmOpenByBusid: drmOpenMinor returns %d\n", fd);
+	if (fd >= 0) {
+	    sv.drm_di_major = 1;
+	    sv.drm_di_minor = 1;
+	    sv.drm_dd_major = -1;	/* Don't care */
+	    drmSetInterfaceVersion(fd, &sv);
+	    buf = drmGetBusid(fd);
+	    drmMsg("drmOpenByBusid: drmGetBusid reports %s\n", buf);
+	    if (buf && drmMatchBusID(buf, busid)) {
+		drmFreeBusid(buf);
+		return fd;
+	    }
+	    if (buf) drmFreeBusid(buf);
+	    close(fd);
+	}
+    }
+    return -1;
+}
+
+
+/**
+ * Open the device by name.
+ *
+ * \param name driver name.
+ *
+ * \return a file descriptor on success, or a negative value on error.
+ *
+ * \internal
+ * This function opens the first minor number that matches the driver name and
+ * isn't already in use.  If it's in use it then it will already have a bus ID
+ * assigned.
+ *
+ * \sa drmOpenMinor(), drmGetVersion() and drmGetBusid().
+ */
+static int drmOpenByName(const char *name)
+{
+    int           i;
+    int           fd;
+    drmVersionPtr version;
+    char *        id;
+
+    if (!drmAvailable()) {
+#if !defined(XFree86Server)
+	return -1;
+#else
+        /* try to load the kernel module now */
+        if (!xf86LoadKernelModule(name)) {
+            ErrorF("[drm] failed to load kernel module \"%s\"\n",
+		   name);
+            return -1;
+        }
+#endif
+    }
+
+    /*
+     * Open the first minor number that matches the driver name and isn't
+     * already in use.  If it's in use it will have a busid assigned already.
+     */
+    for (i = 0; i < DRM_MAX_MINOR; i++) {
+	if ((fd = drmOpenMinor(i, 1)) >= 0) {
+	    if ((version = drmGetVersion(fd))) {
+		if (!strcmp(version->name, name)) {
+		    drmFreeVersion(version);
+		    id = drmGetBusid(fd);
+		    drmMsg("drmGetBusid returned '%s'\n", id ? id : "NULL");
+		    if (!id || !*id) {
+			if (id) {
+			    drmFreeBusid(id);
+			}
+			return fd;
+		    } else {
+			drmFreeBusid(id);
+		    }
+		} else {
+		    drmFreeVersion(version);
+		}
+	    }
+	    close(fd);
+	}
+    }
+
+#ifdef __linux__
+				/* Backward-compatibility /proc support */
+    for (i = 0; i < 8; i++) {
+	char proc_name[64], buf[512];
+	char *driver, *pt, *devstring;
+	int  retcode;
+
+	sprintf(proc_name, "/proc/dri/%d/name", i);
+	if ((fd = open(proc_name, 0, 0)) >= 0) {
+	    retcode = read(fd, buf, sizeof(buf)-1);
+	    close(fd);
+	    if (retcode) {
+		buf[retcode-1] = '\0';
+		for (driver = pt = buf; *pt && *pt != ' '; ++pt)
+		    ;
+		if (*pt) {	/* Device is next */
+		    *pt = '\0';
+		    if (!strcmp(driver, name)) { /* Match */
+			for (devstring = ++pt; *pt && *pt != ' '; ++pt)
+			    ;
+			if (*pt) { /* Found busid */
+			    return drmOpenByBusid(++pt);
+			} else {	/* No busid */
+			    return drmOpenDevice(strtol(devstring, NULL, 0),i);
+			}
+		    }
+		}
+	    }
+	}
+    }
+#endif
+
+    return -1;
+}
+
+
+/**
+ * Open the DRM device.
+ *
+ * Looks up the specified name and bus ID, and opens the device found.  The
+ * entry in /dev/dri is created if necessary and if called by root.
+ *
+ * \param name driver name. Not referenced if bus ID is supplied.
+ * \param busid bus ID. Zero if not known.
+ *
+ * \return a file descriptor on success, or a negative value on error.
+ *
+ * \internal
+ * It calls drmOpenByBusid() if \p busid is specified or drmOpenByName()
+ * otherwise.
+ */
+int drmOpen(const char *name, const char *busid)
+{
+#ifdef XFree86Server
+    if (!drmAvailable() && name != NULL) {
+	/* try to load the kernel */
+	if (!xf86LoadKernelModule(name)) {
+	    ErrorF("[drm] failed to load kernel module \"%s\"\n",
+	           name);
+	    return -1;
+	}
+    }
+#endif
+
+    if (busid) {
+	int fd;
+
+	fd = drmOpenByBusid(busid);
+	if (fd >= 0)
+	    return fd;
+    }
+    if (name)
+	return drmOpenByName(name);
+    return -1;
+}
+
+
+/**
+ * Free the version information returned by drmGetVersion().
+ *
+ * \param v pointer to the version information.
+ *
+ * \internal
+ * It frees the memory pointed by \p %v as well as all the non-null strings
+ * pointers in it.
+ */
+void drmFreeVersion(drmVersionPtr v)
+{
+    if (!v) return;
+    if (v->name) drmFree(v->name);
+    if (v->date) drmFree(v->date);
+    if (v->desc) drmFree(v->desc);
+    drmFree(v);
+}
+
+
+/**
+ * Free the non-public version information returned by the kernel.
+ *
+ * \param v pointer to the version information.
+ *
+ * \internal
+ * Used by drmGetVersion() to free the memory pointed by \p %v as well as all
+ * the non-null strings pointers in it.
+ */
+static void drmFreeKernelVersion(drm_version_t *v)
+{
+    if (!v) return;
+    if (v->name) drmFree(v->name);
+    if (v->date) drmFree(v->date);
+    if (v->desc) drmFree(v->desc);
+    drmFree(v);
+}
+
+
+/**
+ * Copy version information.
+ *
+ * \param d destination pointer.
+ * \param s source pointer.
+ *
+ * \internal
+ * Used by drmGetVersion() to translate the information returned by the ioctl
+ * interface in a private structure into the public structure counterpart.
+ */
+static void drmCopyVersion(drmVersionPtr d, const drm_version_t *s)
+{
+    d->version_major      = s->version_major;
+    d->version_minor      = s->version_minor;
+    d->version_patchlevel = s->version_patchlevel;
+    d->name_len           = s->name_len;
+    d->name               = drmStrdup(s->name);
+    d->date_len           = s->date_len;
+    d->date               = drmStrdup(s->date);
+    d->desc_len           = s->desc_len;
+    d->desc               = drmStrdup(s->desc);
+}
+
+
+/**
+ * Query the driver version information.
+ *
+ * \param fd file descriptor.
+ *
+ * \return pointer to a drmVersion structure which should be freed with
+ * drmFreeVersion().
+ *
+ * \note Similar information is available via /proc/dri.
+ *
+ * \internal
+ * It gets the version information via successive DRM_IOCTL_VERSION ioctls,
+ * first with zeros to get the string lengths, and then the actually strings.
+ * It also null-terminates them since they might not be already.
+ */
+drmVersionPtr drmGetVersion(int fd)
+{
+    drmVersionPtr retval;
+    drm_version_t *version = drmMalloc(sizeof(*version));
+
+				/* First, get the lengths */
+    version->name_len    = 0;
+    version->name        = NULL;
+    version->date_len    = 0;
+    version->date        = NULL;
+    version->desc_len    = 0;
+    version->desc        = NULL;
+
+    if (ioctl(fd, DRM_IOCTL_VERSION, version)) {
+	drmFreeKernelVersion(version);
+	return NULL;
+    }
+
+				/* Now, allocate space and get the data */
+    if (version->name_len)
+	version->name    = drmMalloc(version->name_len + 1);
+    if (version->date_len)
+	version->date    = drmMalloc(version->date_len + 1);
+    if (version->desc_len)
+	version->desc    = drmMalloc(version->desc_len + 1);
+
+    if (ioctl(fd, DRM_IOCTL_VERSION, version)) {
+	drmMsg("DRM_IOCTL_VERSION: %s\n", strerror(errno));
+	drmFreeKernelVersion(version);
+	return NULL;
+    }
+
+				/* The results might not be null-terminated
+                                   strings, so terminate them. */
+
+    if (version->name_len) version->name[version->name_len] = '\0';
+    if (version->date_len) version->date[version->date_len] = '\0';
+    if (version->desc_len) version->desc[version->desc_len] = '\0';
+
+				/* Now, copy it all back into the
+                                   client-visible data structure... */
+    retval = drmMalloc(sizeof(*retval));
+    drmCopyVersion(retval, version);
+    drmFreeKernelVersion(version);
+    return retval;
+}
+
+
+/**
+ * Get version information for the DRM user space library.
+ *
+ * This version number is driver independent.
+ *
+ * \param fd file descriptor.
+ *
+ * \return version information.
+ *
+ * \internal
+ * This function allocates and fills a drm_version structure with a hard coded
+ * version number.
+ */
+drmVersionPtr drmGetLibVersion(int fd)
+{
+    drm_version_t *version = drmMalloc(sizeof(*version));
+
+    /* Version history:
+     *   revision 1.0.x = original DRM interface with no drmGetLibVersion
+     *                    entry point and many drm<Device> extensions
+     *   revision 1.1.x = added drmCommand entry points for device extensions
+     *                    added drmGetLibVersion to identify libdrm.a version
+     *   revision 1.2.x = added drmSetInterfaceVersion
+     *                    modified drmOpen to handle both busid and name
+     */
+    version->version_major      = 1;
+    version->version_minor      = 2;
+    version->version_patchlevel = 0;
+
+    return (drmVersionPtr)version;
+}
+
+
+/**
+ * Free the bus ID information.
+ *
+ * \param busid bus ID information string as given by drmGetBusid().
+ *
+ * \internal
+ * This function is just frees the memory pointed by \p busid.
+ */
+void drmFreeBusid(const char *busid)
+{
+    drmFree((void *)busid);
+}
+
+
+/**
+ * Get the bus ID of the device.
+ *
+ * \param fd file descriptor.
+ *
+ * \return bus ID string.
+ *
+ * \internal
+ * This function gets the bus ID via successive DRM_IOCTL_GET_UNIQUE ioctls to
+ * get the string length and data, passing the arguments in a drm_unique
+ * structure.
+ */
+char *drmGetBusid(int fd)
+{
+    drm_unique_t u;
+
+    u.unique_len = 0;
+    u.unique     = NULL;
+
+    if (ioctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) return NULL;
+    u.unique = drmMalloc(u.unique_len + 1);
+    if (ioctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) return NULL;
+    u.unique[u.unique_len] = '\0';
+
+    return u.unique;
+}
+
+
+/**
+ * Set the bus ID of the device.
+ *
+ * \param fd file descriptor.
+ * \param busid bus ID string.
+ *
+ * \return zero on success, negative on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_SET_UNIQUE ioctl, passing
+ * the arguments in a drm_unique structure.
+ */
+int drmSetBusid(int fd, const char *busid)
+{
+    drm_unique_t u;
+
+    u.unique     = (char *)busid;
+    u.unique_len = strlen(busid);
+
+    if (ioctl(fd, DRM_IOCTL_SET_UNIQUE, &u)) {
+	return -errno;
+    }
+    return 0;
+}
+
+int drmGetMagic(int fd, drm_magic_t * magic)
+{
+    drm_auth_t auth;
+
+    *magic = 0;
+    if (ioctl(fd, DRM_IOCTL_GET_MAGIC, &auth)) return -errno;
+    *magic = auth.magic;
+    return 0;
+}
+
+int drmAuthMagic(int fd, drm_magic_t magic)
+{
+    drm_auth_t auth;
+
+    auth.magic = magic;
+    if (ioctl(fd, DRM_IOCTL_AUTH_MAGIC, &auth)) return -errno;
+    return 0;
+}
+
+/**
+ * Specifies a range of memory that is available for mapping by a
+ * non-root process.
+ *
+ * \param fd file descriptor.
+ * \param offset usually the physical address. The actual meaning depends of
+ * the \p type parameter. See below.
+ * \param size of the memory in bytes.
+ * \param type type of the memory to be mapped.
+ * \param flags combination of several flags to modify the function actions.
+ * \param handle will be set to a value that may be used as the offset
+ * parameter for mmap().
+ *
+ * \return zero on success or a negative value on error.
+ *
+ * \par Mapping the frame buffer
+ * For the frame buffer
+ * - \p offset will be the physical address of the start of the frame buffer,
+ * - \p size will be the size of the frame buffer in bytes, and
+ * - \p type will be DRM_FRAME_BUFFER.
+ *
+ * \par
+ * The area mapped will be uncached. If MTRR support is available in the
+ * kernel, the frame buffer area will be set to write combining.
+ *
+ * \par Mapping the MMIO register area
+ * For the MMIO register area,
+ * - \p offset will be the physical address of the start of the register area,
+ * - \p size will be the size of the register area bytes, and
+ * - \p type will be DRM_REGISTERS.
+ * \par
+ * The area mapped will be uncached.
+ *
+ * \par Mapping the SAREA
+ * For the SAREA,
+ * - \p offset will be ignored and should be set to zero,
+ * - \p size will be the desired size of the SAREA in bytes,
+ * - \p type will be DRM_SHM.
+ *
+ * \par
+ * A shared memory area of the requested size will be created and locked in
+ * kernel memory. This area may be mapped into client-space by using the handle
+ * returned.
+ *
+ * \note May only be called by root.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_ADD_MAP ioctl, passing
+ * the arguments in a drm_map structure.
+ */
+int drmAddMap(int fd,
+	      drm_handle_t offset,
+	      drmSize size,
+	      drmMapType type,
+	      drmMapFlags flags,
+	      drm_handle_t * handle)
+{
+    drm_map_t map;
+
+    map.offset  = offset;
+/* No longer needed with CVS kernel modules on alpha
+#ifdef __alpha__
+    if (type != DRM_SHM)
+	map.offset += BUS_BASE;
+#endif
+*/
+    map.size    = size;
+    map.handle  = 0;
+    map.type    = type;
+    map.flags   = flags;
+    if (ioctl(fd, DRM_IOCTL_ADD_MAP, &map)) return -errno;
+    if (handle) *handle = (drm_handle_t)map.handle;
+    return 0;
+}
+
+int drmRmMap(int fd, drm_handle_t handle)
+{
+    drm_map_t map;
+
+    map.handle = (drm_handle_t)handle;
+
+    if(ioctl(fd, DRM_IOCTL_RM_MAP, &map)) return -errno;
+    return 0;
+}
+
+/**
+ * Make buffers available for DMA transfers.
+ *
+ * \param fd file descriptor.
+ * \param count number of buffers.
+ * \param size size of each buffer.
+ * \param flags buffer allocation flags.
+ * \param agp_offset offset in the AGP aperture
+ *
+ * \return number of buffers allocated, negative on error.
+ *
+ * \internal
+ * This function is a wrapper around DRM_IOCTL_ADD_BUFS ioctl.
+ *
+ * \sa drm_buf_desc.
+ */
+int drmAddBufs(int fd, int count, int size, drmBufDescFlags flags,
+	       int agp_offset)
+{
+    drm_buf_desc_t request;
+
+    request.count     = count;
+    request.size      = size;
+    request.low_mark  = 0;
+    request.high_mark = 0;
+    request.flags     = flags;
+    request.agp_start = agp_offset;
+
+    if (ioctl(fd, DRM_IOCTL_ADD_BUFS, &request)) return -errno;
+    return request.count;
+}
+
+int drmMarkBufs(int fd, double low, double high)
+{
+    drm_buf_info_t info;
+    int            i;
+
+    info.count = 0;
+    info.list  = NULL;
+
+    if (ioctl(fd, DRM_IOCTL_INFO_BUFS, &info)) return -EINVAL;
+
+    if (!info.count) return -EINVAL;
+
+    if (!(info.list = drmMalloc(info.count * sizeof(*info.list))))
+	return -ENOMEM;
+
+    if (ioctl(fd, DRM_IOCTL_INFO_BUFS, &info)) {
+	int retval = -errno;
+	drmFree(info.list);
+	return retval;
+    }
+
+    for (i = 0; i < info.count; i++) {
+	info.list[i].low_mark  = low  * info.list[i].count;
+	info.list[i].high_mark = high * info.list[i].count;
+	if (ioctl(fd, DRM_IOCTL_MARK_BUFS, &info.list[i])) {
+	    int retval = -errno;
+	    drmFree(info.list);
+	    return retval;
+	}
+    }
+    drmFree(info.list);
+
+    return 0;
+}
+
+/**
+ * Free buffers.
+ *
+ * \param fd file descriptor.
+ * \param count number of buffers to free.
+ * \param list list of buffers to be freed.
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \note This function is primarily used for debugging.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_FREE_BUFS ioctl, passing
+ * the arguments in a drm_buf_free structure.
+ */
+int drmFreeBufs(int fd, int count, int *list)
+{
+    drm_buf_free_t request;
+
+    request.count = count;
+    request.list  = list;
+    if (ioctl(fd, DRM_IOCTL_FREE_BUFS, &request)) return -errno;
+    return 0;
+}
+
+
+/**
+ * Close the device.
+ *
+ * \param fd file descriptor.
+ *
+ * \internal
+ * This function closes the file descriptor.
+ */
+int drmClose(int fd)
+{
+    unsigned long key    = drmGetKeyFromFd(fd);
+    drmHashEntry  *entry = drmGetEntry(fd);
+
+    drmHashDestroy(entry->tagTable);
+    entry->fd       = 0;
+    entry->f        = NULL;
+    entry->tagTable = NULL;
+
+    drmHashDelete(drmHashTable, key);
+    drmFree(entry);
+
+    return close(fd);
+}
+
+
+/**
+ * Map a region of memory.
+ *
+ * \param fd file descriptor.
+ * \param handle handle returned by drmAddMap().
+ * \param size size in bytes. Must match the size used by drmAddMap().
+ * \param address will contain the user-space virtual address where the mapping
+ * begins.
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \internal
+ * This function is a wrapper for mmap().
+ */
+int drmMap(int fd,
+	   drm_handle_t handle,
+	   drmSize size,
+	   drmAddressPtr address)
+{
+    static unsigned long pagesize_mask = 0;
+
+    if (fd < 0) return -EINVAL;
+
+    if (!pagesize_mask)
+	pagesize_mask = getpagesize() - 1;
+
+    size = (size + pagesize_mask) & ~pagesize_mask;
+
+    *address = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, handle);
+    if (*address == MAP_FAILED) return -errno;
+    return 0;
+}
+
+
+/**
+ * Unmap mappings obtained with drmMap().
+ *
+ * \param address address as given by drmMap().
+ * \param size size in bytes. Must match the size used by drmMap().
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \internal
+ * This function is a wrapper for unmap().
+ */
+int drmUnmap(drmAddress address, drmSize size)
+{
+    return munmap(address, size);
+}
+
+drmBufInfoPtr drmGetBufInfo(int fd)
+{
+    drm_buf_info_t info;
+    drmBufInfoPtr  retval;
+    int            i;
+
+    info.count = 0;
+    info.list  = NULL;
+
+    if (ioctl(fd, DRM_IOCTL_INFO_BUFS, &info)) return NULL;
+
+    if (info.count) {
+	if (!(info.list = drmMalloc(info.count * sizeof(*info.list))))
+	    return NULL;
+
+	if (ioctl(fd, DRM_IOCTL_INFO_BUFS, &info)) {
+	    drmFree(info.list);
+	    return NULL;
+	}
+				/* Now, copy it all back into the
+                                   client-visible data structure... */
+	retval = drmMalloc(sizeof(*retval));
+	retval->count = info.count;
+	retval->list  = drmMalloc(info.count * sizeof(*retval->list));
+	for (i = 0; i < info.count; i++) {
+	    retval->list[i].count     = info.list[i].count;
+	    retval->list[i].size      = info.list[i].size;
+	    retval->list[i].low_mark  = info.list[i].low_mark;
+	    retval->list[i].high_mark = info.list[i].high_mark;
+	}
+	drmFree(info.list);
+	return retval;
+    }
+    return NULL;
+}
+
+/**
+ * Map all DMA buffers into client-virtual space.
+ *
+ * \param fd file descriptor.
+ *
+ * \return a pointer to a ::drmBufMap structure.
+ *
+ * \note The client may not use these buffers until obtaining buffer indices
+ * with drmDMA().
+ *
+ * \internal
+ * This function calls the DRM_IOCTL_MAP_BUFS ioctl and copies the returned
+ * information about the buffers in a drm_buf_map structure into the
+ * client-visible data structures.
+ */
+drmBufMapPtr drmMapBufs(int fd)
+{
+    drm_buf_map_t bufs;
+    drmBufMapPtr  retval;
+    int           i;
+
+    bufs.count = 0;
+    bufs.list  = NULL;
+    bufs.virtual = NULL;
+    if (ioctl(fd, DRM_IOCTL_MAP_BUFS, &bufs)) return NULL;
+
+    if (!bufs.count) return NULL;
+
+	if (!(bufs.list = drmMalloc(bufs.count * sizeof(*bufs.list))))
+	    return NULL;
+
+	if (ioctl(fd, DRM_IOCTL_MAP_BUFS, &bufs)) {
+	    drmFree(bufs.list);
+	    return NULL;
+	}
+				/* Now, copy it all back into the
+                                   client-visible data structure... */
+	retval = drmMalloc(sizeof(*retval));
+	retval->count = bufs.count;
+	retval->list  = drmMalloc(bufs.count * sizeof(*retval->list));
+	for (i = 0; i < bufs.count; i++) {
+	    retval->list[i].idx     = bufs.list[i].idx;
+	    retval->list[i].total   = bufs.list[i].total;
+	    retval->list[i].used    = 0;
+	    retval->list[i].address = bufs.list[i].address;
+	}
+
+	drmFree(bufs.list);
+
+	return retval;
+}
+
+
+/**
+ * Unmap buffers allocated with drmMapBufs().
+ *
+ * \return zero on success, or negative value on failure.
+ *
+ * \internal
+ * Calls munmap() for every buffer stored in \p bufs and frees the
+ * memory allocated by drmMapBufs().
+ */
+int drmUnmapBufs(drmBufMapPtr bufs)
+{
+    int i;
+
+    for (i = 0; i < bufs->count; i++) {
+	munmap(bufs->list[i].address, bufs->list[i].total);
+    }
+
+    drmFree(bufs->list);
+    drmFree(bufs);
+
+    return 0;
+}
+
+
+#define DRM_DMA_RETRY		16
+
+/**
+ * Reserve DMA buffers.
+ *
+ * \param fd file descriptor.
+ * \param request
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \internal
+ * Assemble the arguments into a drm_dma structure and keeps issuing the
+ * DRM_IOCTL_DMA ioctl until success or until maximum number of retries.
+ */
+int drmDMA(int fd, drmDMAReqPtr request)
+{
+    drm_dma_t dma;
+    int ret, i = 0;
+
+				/* Copy to hidden structure */
+    dma.context         = request->context;
+    dma.send_count      = request->send_count;
+    dma.send_indices    = request->send_list;
+    dma.send_sizes      = request->send_sizes;
+    dma.flags           = request->flags;
+    dma.request_count   = request->request_count;
+    dma.request_size    = request->request_size;
+    dma.request_indices = request->request_list;
+    dma.request_sizes   = request->request_sizes;
+    dma.granted_count   = 0;
+
+    do {
+	ret = ioctl( fd, DRM_IOCTL_DMA, &dma );
+    } while ( ret && errno == EAGAIN && i++ < DRM_DMA_RETRY );
+
+    if ( ret == 0 ) {
+	request->granted_count = dma.granted_count;
+	return 0;
+    } else {
+	return -errno;
+    }
+}
+
+
+/**
+ * Obtain heavyweight hardware lock.
+ *
+ * \param fd file descriptor.
+ * \param context context.
+ * \param flags flags that determine the sate of the hardware when the function
+ * returns.
+ *
+ * \return always zero.
+ *
+ * \internal
+ * This function translates the arguments into a drm_lock structure and issue
+ * the DRM_IOCTL_LOCK ioctl until the lock is successfully acquired.
+ */
+int drmGetLock(int fd, drm_context_t context, drmLockFlags flags)
+{
+    drm_lock_t lock;
+
+    lock.context = context;
+    lock.flags   = 0;
+    if (flags & DRM_LOCK_READY)      lock.flags |= _DRM_LOCK_READY;
+    if (flags & DRM_LOCK_QUIESCENT)  lock.flags |= _DRM_LOCK_QUIESCENT;
+    if (flags & DRM_LOCK_FLUSH)      lock.flags |= _DRM_LOCK_FLUSH;
+    if (flags & DRM_LOCK_FLUSH_ALL)  lock.flags |= _DRM_LOCK_FLUSH_ALL;
+    if (flags & DRM_HALT_ALL_QUEUES) lock.flags |= _DRM_HALT_ALL_QUEUES;
+    if (flags & DRM_HALT_CUR_QUEUES) lock.flags |= _DRM_HALT_CUR_QUEUES;
+
+    while (ioctl(fd, DRM_IOCTL_LOCK, &lock))
+	;
+    return 0;
+}
+
+/**
+ * Release the hardware lock.
+ *
+ * \param fd file descriptor.
+ * \param context context.
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_UNLOCK ioctl, passing the
+ * argument in a drm_lock structure.
+ */
+int drmUnlock(int fd, drm_context_t context)
+{
+    drm_lock_t lock;
+
+    lock.context = context;
+    lock.flags   = 0;
+    return ioctl(fd, DRM_IOCTL_UNLOCK, &lock);
+}
+
+drm_context_t * drmGetReservedContextList(int fd, int *count)
+{
+    drm_ctx_res_t res;
+    drm_ctx_t     *list;
+    drm_context_t * retval;
+    int           i;
+
+    res.count    = 0;
+    res.contexts = NULL;
+    if (ioctl(fd, DRM_IOCTL_RES_CTX, &res)) return NULL;
+
+    if (!res.count) return NULL;
+
+    if (!(list   = drmMalloc(res.count * sizeof(*list)))) return NULL;
+    if (!(retval = drmMalloc(res.count * sizeof(*retval)))) {
+	drmFree(list);
+	return NULL;
+    }
+
+    res.contexts = list;
+    if (ioctl(fd, DRM_IOCTL_RES_CTX, &res)) return NULL;
+
+    for (i = 0; i < res.count; i++) retval[i] = list[i].handle;
+    drmFree(list);
+
+    *count = res.count;
+    return retval;
+}
+
+void drmFreeReservedContextList(drm_context_t * pt)
+{
+    drmFree(pt);
+}
+
+/**
+ * Create context.
+ *
+ * Used by the X server during GLXContext initialization. This causes
+ * per-context kernel-level resources to be allocated.
+ *
+ * \param fd file descriptor.
+ * \param handle is set on success. To be used by the client when requesting DMA
+ * dispatch with drmDMA().
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \note May only be called by root.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_ADD_CTX ioctl, passing the
+ * argument in a drm_ctx structure.
+ */
+int drmCreateContext(int fd, drm_context_t * handle)
+{
+    drm_ctx_t ctx;
+
+    ctx.flags = 0;	/* Modified with functions below */
+    if (ioctl(fd, DRM_IOCTL_ADD_CTX, &ctx)) return -errno;
+    *handle = ctx.handle;
+    return 0;
+}
+
+int drmSwitchToContext(int fd, drm_context_t context)
+{
+    drm_ctx_t ctx;
+
+    ctx.handle = context;
+    if (ioctl(fd, DRM_IOCTL_SWITCH_CTX, &ctx)) return -errno;
+    return 0;
+}
+
+int drmSetContextFlags(int fd, drm_context_t context, drm_context_tFlags flags)
+{
+    drm_ctx_t ctx;
+
+				/* Context preserving means that no context
+                                   switched are done between DMA buffers
+                                   from one context and the next.  This is
+                                   suitable for use in the X server (which
+                                   promises to maintain hardware context,
+                                   or in the client-side library when
+                                   buffers are swapped on behalf of two
+                                   threads. */
+    ctx.handle = context;
+    ctx.flags  = 0;
+    if (flags & DRM_CONTEXT_PRESERVED) ctx.flags |= _DRM_CONTEXT_PRESERVED;
+    if (flags & DRM_CONTEXT_2DONLY)    ctx.flags |= _DRM_CONTEXT_2DONLY;
+    if (ioctl(fd, DRM_IOCTL_MOD_CTX, &ctx)) return -errno;
+    return 0;
+}
+
+int drmGetContextFlags(int fd, drm_context_t context, drm_context_tFlagsPtr flags)
+{
+    drm_ctx_t ctx;
+
+    ctx.handle = context;
+    if (ioctl(fd, DRM_IOCTL_GET_CTX, &ctx)) return -errno;
+    *flags = 0;
+    if (ctx.flags & _DRM_CONTEXT_PRESERVED) *flags |= DRM_CONTEXT_PRESERVED;
+    if (ctx.flags & _DRM_CONTEXT_2DONLY)    *flags |= DRM_CONTEXT_2DONLY;
+    return 0;
+}
+
+/**
+ * Destroy context.
+ *
+ * Free any kernel-level resources allocated with drmCreateContext() associated
+ * with the context.
+ *
+ * \param fd file descriptor.
+ * \param handle handle given by drmCreateContext().
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \note May only be called by root.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_RM_CTX ioctl, passing the
+ * argument in a drm_ctx structure.
+ */
+int drmDestroyContext(int fd, drm_context_t handle)
+{
+    drm_ctx_t ctx;
+    ctx.handle = handle;
+    if (ioctl(fd, DRM_IOCTL_RM_CTX, &ctx)) return -errno;
+    return 0;
+}
+
+int drmCreateDrawable(int fd, drm_drawable_t * handle)
+{
+    drm_draw_t draw;
+    if (ioctl(fd, DRM_IOCTL_ADD_DRAW, &draw)) return -errno;
+    *handle = draw.handle;
+    return 0;
+}
+
+int drmDestroyDrawable(int fd, drm_drawable_t handle)
+{
+    drm_draw_t draw;
+    draw.handle = handle;
+    if (ioctl(fd, DRM_IOCTL_RM_DRAW, &draw)) return -errno;
+    return 0;
+}
+
+/**
+ * Acquire the AGP device.
+ *
+ * Must be called before any of the other AGP related calls.
+ *
+ * \param fd file descriptor.
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_AGP_ACQUIRE ioctl.
+ */
+int drmAgpAcquire(int fd)
+{
+    if (ioctl(fd, DRM_IOCTL_AGP_ACQUIRE, NULL)) return -errno;
+    return 0;
+}
+
+
+/**
+ * Release the AGP device.
+ *
+ * \param fd file descriptor.
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_AGP_RELEASE ioctl.
+ */
+int drmAgpRelease(int fd)
+{
+    if (ioctl(fd, DRM_IOCTL_AGP_RELEASE, NULL)) return -errno;
+    return 0;
+}
+
+
+/**
+ * Set the AGP mode.
+ *
+ * \param fd file descriptor.
+ * \param mode AGP mode.
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_AGP_ENABLE ioctl, passing the
+ * argument in a drm_agp_mode structure.
+ */
+int drmAgpEnable(int fd, unsigned long mode)
+{
+    drm_agp_mode_t m;
+
+    m.mode = mode;
+    if (ioctl(fd, DRM_IOCTL_AGP_ENABLE, &m)) return -errno;
+    return 0;
+}
+
+
+/**
+ * Allocate a chunk of AGP memory.
+ *
+ * \param fd file descriptor.
+ * \param size requested memory size in bytes. Will be rounded to page boundary.
+ * \param type type of memory to allocate.
+ * \param address if not zero, will be set to the physical address of the
+ * allocated memory.
+ * \param handle on success will be set to a handle of the allocated memory.
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_AGP_ALLOC ioctl, passing the
+ * arguments in a drm_agp_buffer structure.
+ */
+int drmAgpAlloc(int fd, unsigned long size, unsigned long type,
+		unsigned long *address, drm_handle_t *handle)
+{
+    drm_agp_buffer_t b;
+
+    *handle = DRM_AGP_NO_HANDLE;
+    b.size   = size;
+    b.handle = 0;
+    b.type   = type;
+    if (ioctl(fd, DRM_IOCTL_AGP_ALLOC, &b)) return -errno;
+    if (address != 0UL) *address = b.physical;
+    *handle = b.handle;
+    return 0;
+}
+
+
+/**
+ * Free a chunk of AGP memory.
+ *
+ * \param fd file descriptor.
+ * \param handle handle to the allocated memory, as given by drmAgpAllocate().
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_AGP_FREE ioctl, passing the
+ * argument in a drm_agp_buffer structure.
+ */
+int drmAgpFree(int fd, drm_handle_t handle)
+{
+    drm_agp_buffer_t b;
+
+    b.size   = 0;
+    b.handle = handle;
+    if (ioctl(fd, DRM_IOCTL_AGP_FREE, &b)) return -errno;
+    return 0;
+}
+
+
+/**
+ * Bind a chunk of AGP memory.
+ *
+ * \param fd file descriptor.
+ * \param handle handle to the allocated memory, as given by drmAgpAllocate().
+ * \param offset offset in bytes. It will round to page boundary.
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_AGP_BIND ioctl, passing the
+ * argument in a drm_agp_binding structure.
+ */
+int drmAgpBind(int fd, drm_handle_t handle, unsigned long offset)
+{
+    drm_agp_binding_t b;
+
+    b.handle = handle;
+    b.offset = offset;
+    if (ioctl(fd, DRM_IOCTL_AGP_BIND, &b)) return -errno;
+    return 0;
+}
+
+
+/**
+ * Unbind a chunk of AGP memory.
+ *
+ * \param fd file descriptor.
+ * \param handle handle to the allocated memory, as given by drmAgpAllocate().
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_AGP_UNBIND ioctl, passing
+ * the argument in a drm_agp_binding structure.
+ */
+int drmAgpUnbind(int fd, drm_handle_t handle)
+{
+    drm_agp_binding_t b;
+
+    b.handle = handle;
+    b.offset = 0;
+    if (ioctl(fd, DRM_IOCTL_AGP_UNBIND, &b)) return -errno;
+    return 0;
+}
+
+
+/**
+ * Get AGP driver major version number.
+ *
+ * \param fd file descriptor.
+ *
+ * \return major version number on success, or a negative value on failure..
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the
+ * necessary information in a drm_agp_info structure.
+ */
+int drmAgpVersionMajor(int fd)
+{
+    drm_agp_info_t i;
+
+    if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return -errno;
+    return i.agp_version_major;
+}
+
+
+/**
+ * Get AGP driver minor version number.
+ *
+ * \param fd file descriptor.
+ *
+ * \return minor version number on success, or a negative value on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the
+ * necessary information in a drm_agp_info structure.
+ */
+int drmAgpVersionMinor(int fd)
+{
+    drm_agp_info_t i;
+
+    if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return -errno;
+    return i.agp_version_minor;
+}
+
+
+/**
+ * Get AGP mode.
+ *
+ * \param fd file descriptor.
+ *
+ * \return mode on success, or zero on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the
+ * necessary information in a drm_agp_info structure.
+ */
+unsigned long drmAgpGetMode(int fd)
+{
+    drm_agp_info_t i;
+
+    if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0;
+    return i.mode;
+}
+
+
+/**
+ * Get AGP aperture base.
+ *
+ * \param fd file descriptor.
+ *
+ * \return aperture base on success, zero on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the
+ * necessary information in a drm_agp_info structure.
+ */
+unsigned long drmAgpBase(int fd)
+{
+    drm_agp_info_t i;
+
+    if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0;
+    return i.aperture_base;
+}
+
+
+/**
+ * Get AGP aperture size.
+ *
+ * \param fd file descriptor.
+ *
+ * \return aperture size on success, zero on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the
+ * necessary information in a drm_agp_info structure.
+ */
+unsigned long drmAgpSize(int fd)
+{
+    drm_agp_info_t i;
+
+    if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0;
+    return i.aperture_size;
+}
+
+
+/**
+ * Get used AGP memory.
+ *
+ * \param fd file descriptor.
+ *
+ * \return memory used on success, or zero on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the
+ * necessary information in a drm_agp_info structure.
+ */
+unsigned long drmAgpMemoryUsed(int fd)
+{
+    drm_agp_info_t i;
+
+    if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0;
+    return i.memory_used;
+}
+
+
+/**
+ * Get available AGP memory.
+ *
+ * \param fd file descriptor.
+ *
+ * \return memory available on success, or zero on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the
+ * necessary information in a drm_agp_info structure.
+ */
+unsigned long drmAgpMemoryAvail(int fd)
+{
+    drm_agp_info_t i;
+
+    if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0;
+    return i.memory_allowed;
+}
+
+
+/**
+ * Get hardware vendor ID.
+ *
+ * \param fd file descriptor.
+ *
+ * \return vendor ID on success, or zero on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the
+ * necessary information in a drm_agp_info structure.
+ */
+unsigned int drmAgpVendorId(int fd)
+{
+    drm_agp_info_t i;
+
+    if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0;
+    return i.id_vendor;
+}
+
+
+/**
+ * Get hardware device ID.
+ *
+ * \param fd file descriptor.
+ *
+ * \return zero on success, or zero on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the
+ * necessary information in a drm_agp_info structure.
+ */
+unsigned int drmAgpDeviceId(int fd)
+{
+    drm_agp_info_t i;
+
+    if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0;
+    return i.id_device;
+}
+
+int drmScatterGatherAlloc(int fd, unsigned long size, drm_handle_t *handle)
+{
+    drm_scatter_gather_t sg;
+
+    *handle = 0;
+    sg.size   = size;
+    sg.handle = 0;
+    if (ioctl(fd, DRM_IOCTL_SG_ALLOC, &sg)) return -errno;
+    *handle = sg.handle;
+    return 0;
+}
+
+int drmScatterGatherFree(int fd, drm_handle_t handle)
+{
+    drm_scatter_gather_t sg;
+
+    sg.size   = 0;
+    sg.handle = handle;
+    if (ioctl(fd, DRM_IOCTL_SG_FREE, &sg)) return -errno;
+    return 0;
+}
+
+/**
+ * Wait for VBLANK.
+ *
+ * \param fd file descriptor.
+ * \param vbl pointer to a drmVBlank structure.
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_WAIT_VBLANK ioctl.
+ */
+int drmWaitVBlank(int fd, drmVBlankPtr vbl)
+{
+    int ret;
+
+    do {
+       ret = ioctl(fd, DRM_IOCTL_WAIT_VBLANK, vbl);
+       vbl->request.type &= ~DRM_VBLANK_RELATIVE;
+    } while (ret && errno == EINTR);
+
+    return ret;
+}
+
+int drmError(int err, const char *label)
+{
+    switch (err) {
+    case DRM_ERR_NO_DEVICE: fprintf(stderr, "%s: no device\n", label);   break;
+    case DRM_ERR_NO_ACCESS: fprintf(stderr, "%s: no access\n", label);   break;
+    case DRM_ERR_NOT_ROOT:  fprintf(stderr, "%s: not root\n", label);    break;
+    case DRM_ERR_INVALID:   fprintf(stderr, "%s: invalid args\n", label);break;
+    default:
+	if (err < 0) err = -err;
+	fprintf( stderr, "%s: error %d (%s)\n", label, err, strerror(err) );
+	break;
+    }
+
+    return 1;
+}
+
+/**
+ * Install IRQ handler.
+ *
+ * \param fd file descriptor.
+ * \param irq IRQ number.
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_CONTROL ioctl, passing the
+ * argument in a drm_control structure.
+ */
+int drmCtlInstHandler(int fd, int irq)
+{
+    drm_control_t ctl;
+
+    ctl.func  = DRM_INST_HANDLER;
+    ctl.irq   = irq;
+    if (ioctl(fd, DRM_IOCTL_CONTROL, &ctl)) return -errno;
+    return 0;
+}
+
+
+/**
+ * Uninstall IRQ handler.
+ *
+ * \param fd file descriptor.
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_CONTROL ioctl, passing the
+ * argument in a drm_control structure.
+ */
+int drmCtlUninstHandler(int fd)
+{
+    drm_control_t ctl;
+
+    ctl.func  = DRM_UNINST_HANDLER;
+    ctl.irq   = 0;
+    if (ioctl(fd, DRM_IOCTL_CONTROL, &ctl)) return -errno;
+    return 0;
+}
+
+int drmFinish(int fd, int context, drmLockFlags flags)
+{
+    drm_lock_t lock;
+
+    lock.context = context;
+    lock.flags   = 0;
+    if (flags & DRM_LOCK_READY)      lock.flags |= _DRM_LOCK_READY;
+    if (flags & DRM_LOCK_QUIESCENT)  lock.flags |= _DRM_LOCK_QUIESCENT;
+    if (flags & DRM_LOCK_FLUSH)      lock.flags |= _DRM_LOCK_FLUSH;
+    if (flags & DRM_LOCK_FLUSH_ALL)  lock.flags |= _DRM_LOCK_FLUSH_ALL;
+    if (flags & DRM_HALT_ALL_QUEUES) lock.flags |= _DRM_HALT_ALL_QUEUES;
+    if (flags & DRM_HALT_CUR_QUEUES) lock.flags |= _DRM_HALT_CUR_QUEUES;
+    if (ioctl(fd, DRM_IOCTL_FINISH, &lock)) return -errno;
+    return 0;
+}
+
+/**
+ * Get IRQ from bus ID.
+ *
+ * \param fd file descriptor.
+ * \param busnum bus number.
+ * \param devnum device number.
+ * \param funcnum function number.
+ *
+ * \return IRQ number on success, or a negative value on failure.
+ *
+ * \internal
+ * This function is a wrapper around the DRM_IOCTL_IRQ_BUSID ioctl, passing the
+ * arguments in a drm_irq_busid structure.
+ */
+int drmGetInterruptFromBusID(int fd, int busnum, int devnum, int funcnum)
+{
+    drm_irq_busid_t p;
+
+    p.busnum  = busnum;
+    p.devnum  = devnum;
+    p.funcnum = funcnum;
+    if (ioctl(fd, DRM_IOCTL_IRQ_BUSID, &p)) return -errno;
+    return p.irq;
+}
+
+int drmAddContextTag(int fd, drm_context_t context, void *tag)
+{
+    drmHashEntry  *entry = drmGetEntry(fd);
+
+    if (drmHashInsert(entry->tagTable, context, tag)) {
+	drmHashDelete(entry->tagTable, context);
+	drmHashInsert(entry->tagTable, context, tag);
+    }
+    return 0;
+}
+
+int drmDelContextTag(int fd, drm_context_t context)
+{
+    drmHashEntry  *entry = drmGetEntry(fd);
+
+    return drmHashDelete(entry->tagTable, context);
+}
+
+void *drmGetContextTag(int fd, drm_context_t context)
+{
+    drmHashEntry  *entry = drmGetEntry(fd);
+    void          *value;
+
+    if (drmHashLookup(entry->tagTable, context, &value)) return NULL;
+
+    return value;
+}
+
+int drmAddContextPrivateMapping(int fd, drm_context_t ctx_id, drm_handle_t handle)
+{
+    drm_ctx_priv_map_t map;
+
+    map.ctx_id = ctx_id;
+    map.handle = (void *)(unsigned long)handle;
+
+    if (ioctl(fd, DRM_IOCTL_SET_SAREA_CTX, &map)) return -errno;
+    return 0;
+}
+
+int drmGetContextPrivateMapping(int fd, drm_context_t ctx_id, drm_handle_t * handle)
+{
+    drm_ctx_priv_map_t map;
+
+    map.ctx_id = ctx_id;
+
+    if (ioctl(fd, DRM_IOCTL_GET_SAREA_CTX, &map)) return -errno;
+    if (handle) *handle = (drm_handle_t)(unsigned long)map.handle;
+
+    return 0;
+}
+
+int drmGetMap(int fd, int idx, drm_handle_t *offset, drmSize *size,
+	      drmMapType *type, drmMapFlags *flags, drm_handle_t *handle,
+	      int *mtrr)
+{
+    drm_map_t map;
+
+    map.offset = idx;
+    if (ioctl(fd, DRM_IOCTL_GET_MAP, &map)) return -errno;
+    *offset = map.offset;
+    *size   = map.size;
+    *type   = map.type;
+    *flags  = map.flags;
+    *handle = (drm_handle_t)(unsigned long)map.handle;
+    *mtrr   = map.mtrr;
+    return 0;
+}
+
+int drmGetClient(int fd, int idx, int *auth, int *pid, int *uid,
+		 unsigned long *magic, unsigned long *iocs)
+{
+    drm_client_t client;
+
+    client.idx = idx;
+    if (ioctl(fd, DRM_IOCTL_GET_CLIENT, &client)) return -errno;
+    *auth      = client.auth;
+    *pid       = client.pid;
+    *uid       = client.uid;
+    *magic     = client.magic;
+    *iocs      = client.iocs;
+    return 0;
+}
+
+int drmGetStats(int fd, drmStatsT *stats)
+{
+    drm_stats_t s;
+    unsigned int i;
+
+    if (ioctl(fd, DRM_IOCTL_GET_STATS, &s)) return -errno;
+
+    stats->count = 0;
+    memset(stats, 0, sizeof(*stats));
+    if (s.count > sizeof(stats->data)/sizeof(stats->data[0]))
+	return -1;
+
+#define SET_VALUE                              \
+    stats->data[i].long_format = "%-20.20s";   \
+    stats->data[i].rate_format = "%8.8s";      \
+    stats->data[i].isvalue     = 1;            \
+    stats->data[i].verbose     = 0
+
+#define SET_COUNT                              \
+    stats->data[i].long_format = "%-20.20s";   \
+    stats->data[i].rate_format = "%5.5s";      \
+    stats->data[i].isvalue     = 0;            \
+    stats->data[i].mult_names  = "kgm";        \
+    stats->data[i].mult        = 1000;         \
+    stats->data[i].verbose     = 0
+
+#define SET_BYTE                               \
+    stats->data[i].long_format = "%-20.20s";   \
+    stats->data[i].rate_format = "%5.5s";      \
+    stats->data[i].isvalue     = 0;            \
+    stats->data[i].mult_names  = "KGM";        \
+    stats->data[i].mult        = 1024;         \
+    stats->data[i].verbose     = 0
+
+
+    stats->count = s.count;
+    for (i = 0; i < s.count; i++) {
+	stats->data[i].value = s.data[i].value;
+	switch (s.data[i].type) {
+	case _DRM_STAT_LOCK:
+	    stats->data[i].long_name = "Lock";
+	    stats->data[i].rate_name = "Lock";
+	    SET_VALUE;
+	    break;
+	case _DRM_STAT_OPENS:
+	    stats->data[i].long_name = "Opens";
+	    stats->data[i].rate_name = "O";
+	    SET_COUNT;
+	    stats->data[i].verbose   = 1;
+	    break;
+	case _DRM_STAT_CLOSES:
+	    stats->data[i].long_name = "Closes";
+	    stats->data[i].rate_name = "Lock";
+	    SET_COUNT;
+	    stats->data[i].verbose   = 1;
+	    break;
+	case _DRM_STAT_IOCTLS:
+	    stats->data[i].long_name = "Ioctls";
+	    stats->data[i].rate_name = "Ioc/s";
+	    SET_COUNT;
+	    break;
+	case _DRM_STAT_LOCKS:
+	    stats->data[i].long_name = "Locks";
+	    stats->data[i].rate_name = "Lck/s";
+	    SET_COUNT;
+	    break;
+	case _DRM_STAT_UNLOCKS:
+	    stats->data[i].long_name = "Unlocks";
+	    stats->data[i].rate_name = "Unl/s";
+	    SET_COUNT;
+	    break;
+	case _DRM_STAT_IRQ:
+	    stats->data[i].long_name = "IRQs";
+	    stats->data[i].rate_name = "IRQ/s";
+	    SET_COUNT;
+	    break;
+	case _DRM_STAT_PRIMARY:
+	    stats->data[i].long_name = "Primary Bytes";
+	    stats->data[i].rate_name = "PB/s";
+	    SET_BYTE;
+	    break;
+	case _DRM_STAT_SECONDARY:
+	    stats->data[i].long_name = "Secondary Bytes";
+	    stats->data[i].rate_name = "SB/s";
+	    SET_BYTE;
+	    break;
+	case _DRM_STAT_DMA:
+	    stats->data[i].long_name = "DMA";
+	    stats->data[i].rate_name = "DMA/s";
+	    SET_COUNT;
+	    break;
+	case _DRM_STAT_SPECIAL:
+	    stats->data[i].long_name = "Special DMA";
+	    stats->data[i].rate_name = "dma/s";
+	    SET_COUNT;
+	    break;
+	case _DRM_STAT_MISSED:
+	    stats->data[i].long_name = "Miss";
+	    stats->data[i].rate_name = "Ms/s";
+	    SET_COUNT;
+	    break;
+	case _DRM_STAT_VALUE:
+	    stats->data[i].long_name = "Value";
+	    stats->data[i].rate_name = "Value";
+	    SET_VALUE;
+	    break;
+	case _DRM_STAT_BYTE:
+	    stats->data[i].long_name = "Bytes";
+	    stats->data[i].rate_name = "B/s";
+	    SET_BYTE;
+	    break;
+	case _DRM_STAT_COUNT:
+	default:
+	    stats->data[i].long_name = "Count";
+	    stats->data[i].rate_name = "Cnt/s";
+	    SET_COUNT;
+	    break;
+	}
+    }
+    return 0;
+}
+
+/**
+ * Issue a set-version ioctl.
+ *
+ * \param fd file descriptor.
+ * \param drmCommandIndex command index
+ * \param data source pointer of the data to be read and written.
+ * \param size size of the data to be read and written.
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \internal
+ * It issues a read-write ioctl given by
+ * \code DRM_COMMAND_BASE + drmCommandIndex \endcode.
+ */
+int drmSetInterfaceVersion(int fd, drmSetVersion *version )
+{
+    int retcode = 0;
+    drm_set_version_t sv;
+
+    sv.drm_di_major = version->drm_di_major;
+    sv.drm_di_minor = version->drm_di_minor;
+    sv.drm_dd_major = version->drm_dd_major;
+    sv.drm_dd_minor = version->drm_dd_minor;
+
+    if (ioctl(fd, DRM_IOCTL_SET_VERSION, &sv)) {
+	retcode = -errno;
+    }
+
+    version->drm_di_major = sv.drm_di_major;
+    version->drm_di_minor = sv.drm_di_minor;
+    version->drm_dd_major = sv.drm_dd_major;
+    version->drm_dd_minor = sv.drm_dd_minor;
+
+    return retcode;
+}
+
+/**
+ * Send a device-specific command.
+ *
+ * \param fd file descriptor.
+ * \param drmCommandIndex command index
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \internal
+ * It issues a ioctl given by
+ * \code DRM_COMMAND_BASE + drmCommandIndex \endcode.
+ */
+int drmCommandNone(int fd, unsigned long drmCommandIndex)
+{
+    void *data = NULL; /* dummy */
+    unsigned long request;
+
+    request = DRM_IO( DRM_COMMAND_BASE + drmCommandIndex);
+
+    if (ioctl(fd, request, data)) {
+	return -errno;
+    }
+    return 0;
+}
+
+
+/**
+ * Send a device-specific read command.
+ *
+ * \param fd file descriptor.
+ * \param drmCommandIndex command index
+ * \param data destination pointer of the data to be read.
+ * \param size size of the data to be read.
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \internal
+ * It issues a read ioctl given by
+ * \code DRM_COMMAND_BASE + drmCommandIndex \endcode.
+ */
+int drmCommandRead(int fd, unsigned long drmCommandIndex,
+                   void *data, unsigned long size )
+{
+    unsigned long request;
+
+    request = DRM_IOC( DRM_IOC_READ, DRM_IOCTL_BASE,
+	DRM_COMMAND_BASE + drmCommandIndex, size);
+
+    if (ioctl(fd, request, data)) {
+	return -errno;
+    }
+    return 0;
+}
+
+
+/**
+ * Send a device-specific write command.
+ *
+ * \param fd file descriptor.
+ * \param drmCommandIndex command index
+ * \param data source pointer of the data to be written.
+ * \param size size of the data to be written.
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \internal
+ * It issues a write ioctl given by
+ * \code DRM_COMMAND_BASE + drmCommandIndex \endcode.
+ */
+int drmCommandWrite(int fd, unsigned long drmCommandIndex,
+                   void *data, unsigned long size )
+{
+    unsigned long request;
+
+    request = DRM_IOC( DRM_IOC_WRITE, DRM_IOCTL_BASE,
+	DRM_COMMAND_BASE + drmCommandIndex, size);
+
+    if (ioctl(fd, request, data)) {
+	return -errno;
+    }
+    return 0;
+}
+
+
+/**
+ * Send a device-specific read-write command.
+ *
+ * \param fd file descriptor.
+ * \param drmCommandIndex command index
+ * \param data source pointer of the data to be read and written.
+ * \param size size of the data to be read and written.
+ *
+ * \return zero on success, or a negative value on failure.
+ *
+ * \internal
+ * It issues a read-write ioctl given by
+ * \code DRM_COMMAND_BASE + drmCommandIndex \endcode.
+ */
+int drmCommandWriteRead(int fd, unsigned long drmCommandIndex,
+                   void *data, unsigned long size )
+{
+    unsigned long request;
+
+    request = DRM_IOC( DRM_IOC_READ|DRM_IOC_WRITE, DRM_IOCTL_BASE,
+	DRM_COMMAND_BASE + drmCommandIndex, size);
+
+    if (ioctl(fd, request, data)) {
+	return -errno;
+    }
+    return 0;
+}
+
+#if defined(XFree86Server)
+static void drmSIGIOHandler(int interrupt, void *closure)
+{
+    unsigned long key;
+    void          *value;
+    ssize_t       count;
+    drm_ctx_t     ctx;
+    typedef void  (*_drmCallback)(int, void *, void *);
+    char          buf[256];
+    drm_context_t    old;
+    drm_context_t    new;
+    void          *oldctx;
+    void          *newctx;
+    char          *pt;
+    drmHashEntry  *entry;
+
+    if (!drmHashTable) return;
+    if (drmHashFirst(drmHashTable, &key, &value)) {
+	entry = value;
+	do {
+#if 0
+	    fprintf(stderr, "Trying %d\n", entry->fd);
+#endif
+	    if ((count = read(entry->fd, buf, sizeof(buf))) > 0) {
+		buf[count] = '\0';
+#if 0
+		fprintf(stderr, "Got %s\n", buf);
+#endif
+
+		for (pt = buf; *pt != ' '; ++pt); /* Find first space */
+		++pt;
+		old    = strtol(pt, &pt, 0);
+		new    = strtol(pt, NULL, 0);
+		oldctx = drmGetContextTag(entry->fd, old);
+		newctx = drmGetContextTag(entry->fd, new);
+#if 0
+		fprintf(stderr, "%d %d %p %p\n", old, new, oldctx, newctx);
+#endif
+		((_drmCallback)entry->f)(entry->fd, oldctx, newctx);
+		ctx.handle = new;
+		ioctl(entry->fd, DRM_IOCTL_NEW_CTX, &ctx);
+	    }
+	} while (drmHashNext(drmHashTable, &key, &value));
+    }
+}
+
+int drmInstallSIGIOHandler(int fd, void (*f)(int, void *, void *))
+{
+    drmHashEntry     *entry;
+
+    entry     = drmGetEntry(fd);
+    entry->f  = f;
+
+#if defined(sun)
+    return 1;
+#else
+    return xf86InstallSIGIOHandler(fd, drmSIGIOHandler, 0);
+#endif
+}
+
+int drmRemoveSIGIOHandler(int fd)
+{
+    drmHashEntry     *entry = drmGetEntry(fd);
+
+    entry->f = NULL;
+
+#if defined(sun)
+    return 1;
+#else
+    return xf86RemoveSIGIOHandler(fd);
+#endif
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/extras/drm/libdrm/xf86drm.h	Tue Oct 24 18:42:11 2006 -0700
@@ -0,0 +1,655 @@
+/**
+ * \file xf86drm.h 
+ * OS-independent header for DRM user-level library interface.
+ *
+ * \author Rickard E. (Rik) Faith <[email protected]>
+ */
+ 
+/*
+ * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86drm.h,v 1.26 2003/08/16 19:26:37 dawes Exp $ */
+
+#ifndef _XF86DRM_H_
+#define _XF86DRM_H_
+
+#include <drm.h>
+
+#if defined(sun)
+#define STRINGIZE(x) #x
+#define STRINGIZE_EVAL(x) STRINGIZE(x)
+#define __FUNCTION__    STRINGIZE_EVAL(__FILE__)",line"STRINGIZE_EVAL(__LINE__)
+#endif
+				/* Defaults, if nothing set in xf86config */
+#define DRM_DEV_UID	 0
+#define DRM_DEV_GID	 0
+/* Default /dev/dri directory permissions 0755 */
+#define DRM_DEV_DIRMODE	 	\
+	(S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
+#define DRM_DEV_MODE	 (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
+
+#define DRM_DIR_NAME  "/dev/dri"
+#define DRM_DEV_NAME  "%s/card%d"
+#define DRM_PROC_NAME "/proc/dri/" /* For backward Linux compatibility */
+
+#define DRM_ERR_NO_DEVICE  (-1001)
+#define DRM_ERR_NO_ACCESS  (-1002)
+#define DRM_ERR_NOT_ROOT   (-1003)
+#define DRM_ERR_INVALID    (-1004)
+#define DRM_ERR_NO_FD      (-1005)
+
+#define DRM_AGP_NO_HANDLE 0
+
+typedef unsigned int  drmSize,     *drmSizePtr;	    /**< For mapped regions */
+typedef void          *drmAddress, **drmAddressPtr; /**< For mapped regions */
+
+/**
+ * Driver version information.
+ *
+ * \sa drmGetVersion() and drmSetVersion().
+ */
+typedef struct _drmVersion {
+    int     version_major;        /**< Major version */
+    int     version_minor;        /**< Minor version */
+    int     version_patchlevel;   /**< Patch level */
+    int     name_len; 	          /**< Length of name buffer */
+    char    *name;	          /**< Name of driver */
+    int     date_len;             /**< Length of date buffer */
+    char    *date;                /**< User-space buffer to hold date */
+    int     desc_len;	          /**< Length of desc buffer */
+    char    *desc;                /**< User-space buffer to hold desc */
+} drmVersion, *drmVersionPtr;
+
+typedef struct _drmStats {
+    unsigned long count;	     /**< Number of data */
+    struct {
+	unsigned long value;	     /**< Value from kernel */
+	const char    *long_format;  /**< Suggested format for long_name */
+	const char    *long_name;    /**< Long name for value */
+	const char    *rate_format;  /**< Suggested format for rate_name */
+	const char    *rate_name;    /**< Short name for value per second */
+	int           isvalue;       /**< True if value (vs. counter) */
+	const char    *mult_names;   /**< Multiplier names (e.g., "KGM") */
+	int           mult;          /**< Multiplier value (e.g., 1024) */
+	int           verbose;       /**< Suggest only in verbose output */
+    } data[15];
+} drmStatsT;
+
+
+				/* All of these enums *MUST* match with the
+                                   kernel implementation -- so do *NOT*
+                                   change them!  (The drmlib implementation
+                                   will just copy the flags instead of
+                                   translating them.) */
+typedef enum {
+    DRM_FRAME_BUFFER    = 0,      /**< WC, no caching, no core dump */
+    DRM_REGISTERS       = 1,      /**< no caching, no core dump */
+    DRM_SHM             = 2,      /**< shared, cached */
+    DRM_AGP             = 3,	  /**< AGP/GART */
+    DRM_SCATTER_GATHER  = 4,	  /**< PCI scatter/gather */
+    DRM_CONSISTENT      = 5,	  /**< PCI consistent */
+    DRM_AGP_UMEM	= 8
+} drmMapType;
+
+typedef enum {
+    DRM_RESTRICTED      = 0x0001, /**< Cannot be mapped to client-virtual */
+    DRM_READ_ONLY       = 0x0002, /**< Read-only in client-virtual */
+    DRM_LOCKED          = 0x0004, /**< Physical pages locked */
+    DRM_KERNEL          = 0x0008, /**< Kernel requires access */
+    DRM_WRITE_COMBINING = 0x0010, /**< Use write-combining, if available */
+    DRM_CONTAINS_LOCK   = 0x0020, /**< SHM page that contains lock */
+    DRM_REMOVABLE	= 0x0040  /**< Removable mapping */
+} drmMapFlags;
+
+/**
+ * \warning These values *MUST* match drm.h
+ */
+typedef enum {
+    /** \name Flags for DMA buffer dispatch */
+    /*@{*/
+    DRM_DMA_BLOCK        = 0x01, /**< 
+				  * Block until buffer dispatched.
+				  * 
+				  * \note the buffer may not yet have been
+				  * processed by the hardware -- getting a
+				  * hardware lock with the hardware quiescent
+				  * will ensure that the buffer has been
+				  * processed.
+				  */
+    DRM_DMA_WHILE_LOCKED = 0x02, /**< Dispatch while lock held */
+    DRM_DMA_PRIORITY     = 0x04, /**< High priority dispatch */
+    /*@}*/
+
+    /** \name Flags for DMA buffer request */
+    /*@{*/
+    DRM_DMA_WAIT         = 0x10, /**< Wait for free buffers */
+    DRM_DMA_SMALLER_OK   = 0x20, /**< Smaller-than-requested buffers OK */
+    DRM_DMA_LARGER_OK    = 0x40  /**< Larger-than-requested buffers OK */
+    /*@}*/
+} drmDMAFlags;
+
+typedef enum {
+    DRM_PAGE_ALIGN       = 0x01,
+    DRM_AGP_BUFFER       = 0x02,
+    DRM_SG_BUFFER        = 0x04,
+    DRM_FB_BUFFER        = 0x08
+} drmBufDescFlags;
+
+typedef enum {
+    DRM_LOCK_READY      = 0x01, /**< Wait until hardware is ready for DMA */
+    DRM_LOCK_QUIESCENT  = 0x02, /**< Wait until hardware quiescent */
+    DRM_LOCK_FLUSH      = 0x04, /**< Flush this context's DMA queue first */
+    DRM_LOCK_FLUSH_ALL  = 0x08, /**< Flush all DMA queues first */
+				/* These *HALT* flags aren't supported yet
+                                   -- they will be used to support the
+                                   full-screen DGA-like mode. */
+    DRM_HALT_ALL_QUEUES = 0x10, /**< Halt all current and future queues */
+    DRM_HALT_CUR_QUEUES = 0x20  /**< Halt all current queues */
+} drmLockFlags;
+
+typedef enum {
+    DRM_CONTEXT_PRESERVED = 0x01, /**< This context is preserved and
+				     never swapped. */
+    DRM_CONTEXT_2DONLY    = 0x02  /**< This context is for 2D rendering only. */
+} drm_context_tFlags, *drm_context_tFlagsPtr;
+
+typedef struct _drmBufDesc {
+    int              count;	  /**< Number of buffers of this size */
+    int              size;	  /**< Size in bytes */
+    int              low_mark;	  /**< Low water mark */
+    int              high_mark;	  /**< High water mark */
+} drmBufDesc, *drmBufDescPtr;
+
+typedef struct _drmBufInfo {
+    int              count;	  /**< Number of buffers described in list */
+    drmBufDescPtr    list;	  /**< List of buffer descriptions */
+} drmBufInfo, *drmBufInfoPtr;
+
+typedef struct _drmBuf {
+    int              idx;	  /**< Index into the master buffer list */
+    int              total;	  /**< Buffer size */
+    int              used;	  /**< Amount of buffer in use (for DMA) */
+    drmAddress       address;	  /**< Address */
+} drmBuf, *drmBufPtr;
+
+/**
+ * Buffer mapping information.
+ *
+ * Used by drmMapBufs() and drmUnmapBufs() to store information about the
+ * mapped buffers.
+ */
+typedef struct _drmBufMap {
+    int              count;	  /**< Number of buffers mapped */
+    drmBufPtr        list;	  /**< Buffers */
+} drmBufMap, *drmBufMapPtr;
+
+typedef struct _drmLock {
+    volatile unsigned int lock;
+    char                      padding[60];
+    /* This is big enough for most current (and future?) architectures:
+       DEC Alpha:              32 bytes
+       Intel Merced:           ?
+       Intel P5/PPro/PII/PIII: 32 bytes
+       Intel StrongARM:        32 bytes
+       Intel i386/i486:        16 bytes
+       MIPS:                   32 bytes (?)
+       Motorola 68k:           16 bytes
+       Motorola PowerPC:       32 bytes
+       Sun SPARC:              32 bytes
+    */
+} drmLock, *drmLockPtr;
+
+/**
+ * Indices here refer to the offset into
+ * list in drmBufInfo
+ */
+typedef struct _drmDMAReq {
+    drm_context_t    context;  	  /**< Context handle */
+    int           send_count;     /**< Number of buffers to send */
+    int           *send_list;     /**< List of handles to buffers */
+    int           *send_sizes;    /**< Lengths of data to send, in bytes */
+    drmDMAFlags   flags;          /**< Flags */
+    int           request_count;  /**< Number of buffers requested */
+    int           request_size;	  /**< Desired size of buffers requested */
+    int           *request_list;  /**< Buffer information */
+    int           *request_sizes; /**< Minimum acceptable sizes */
+    int           granted_count;  /**< Number of buffers granted at this size */
+} drmDMAReq, *drmDMAReqPtr;
+
+typedef struct _drmRegion {
+    drm_handle_t     handle;
+    unsigned int  offset;
+    drmSize       size;
+    drmAddress    map;
+} drmRegion, *drmRegionPtr;
+
+typedef struct _drmTextureRegion {
+    unsigned char next;
+    unsigned char prev;
+    unsigned char in_use;
+    unsigned char padding;	/**< Explicitly pad this out */
+    unsigned int  age;
+} drmTextureRegion, *drmTextureRegionPtr;
+
+
+typedef enum {
+    DRM_VBLANK_ABSOLUTE = 0x0,	/**< Wait for specific vblank sequence number */
+    DRM_VBLANK_RELATIVE = 0x1,	/**< Wait for given number of vblanks */
+    DRM_VBLANK_SIGNAL   = 0x40000000	/* Send signal instead of blocking */
+} drmVBlankSeqType;
+
+typedef struct _drmVBlankReq {
+	drmVBlankSeqType type;
+	unsigned int sequence;
+	unsigned long signal;
+} drmVBlankReq, *drmVBlankReqPtr;
+
+typedef struct _drmVBlankReply {
+	drmVBlankSeqType type;
+	unsigned int sequence;
+	long tval_sec;
+	long tval_usec;
+} drmVBlankReply, *drmVBlankReplyPtr;
+
+typedef union _drmVBlank {
+	drmVBlankReq request;
+	drmVBlankReply reply;
+} drmVBlank, *drmVBlankPtr;
+
+typedef struct _drmSetVersion {
+	int drm_di_major;
+	int drm_di_minor;
+	int drm_dd_major;
+	int drm_dd_minor;
+} drmSetVersion, *drmSetVersionPtr;
+
+
+#define __drm_dummy_lock(lock) (*(__volatile__ unsigned int *)lock)
+
+#define DRM_LOCK_HELD  0x80000000U /**< Hardware lock is held */
+#define DRM_LOCK_CONT  0x40000000U /**< Hardware lock is contended */
+
+#if defined(__GNUC__) && (__GNUC__ >= 2)
+# if defined(__i386) || defined(__AMD64__) || defined(__x86_64__) || defined(__amd64__)
+				/* Reflect changes here to drmP.h */
+#define DRM_CAS(lock,old,new,__ret)                                    \
+	do {                                                           \
+                int __dummy;	/* Can't mark eax as clobbered */      \
+		__asm__ __volatile__(                                  \
+			"lock ; cmpxchg %4,%1\n\t"                     \
+                        "setnz %0"                                     \
+			: "=d" (__ret),                                \
+   			  "=m" (__drm_dummy_lock(lock)),               \
+                          "=a" (__dummy)                               \
+			: "2" (old),                                   \
+			  "r" (new));                                  \
+	} while (0)
+
+#elif defined(__alpha__)
+
+#define	DRM_CAS(lock, old, new, ret) 		\
+ 	do {					\
+ 		int old32;                      \
+ 		int cur32;			\
+ 		__asm__ __volatile__(		\
+ 		"       mb\n"			\
+ 		"       zap   %4, 0xF0, %0\n"   \
+ 		"       ldl_l %1, %2\n"		\
+ 		"       zap   %1, 0xF0, %1\n"   \
+                "       cmpeq %0, %1, %1\n"	\
+                "       beq   %1, 1f\n"		\
+ 		"       bis   %5, %5, %1\n"	\
+                "       stl_c %1, %2\n"		\
+                "1:     xor   %1, 1, %1\n"	\
+                "       stl   %1, %3"		\
+                : "=r" (old32),                 \
+		  "=&r" (cur32),		\
+                   "=m" (__drm_dummy_lock(lock)),\
+                   "=m" (ret)			\
+ 		: "r" (old),			\
+ 		  "r" (new));			\
+ 	} while(0)
+
+#elif defined(__sparc__)
+
+#define DRM_CAS(lock,old,new,__ret)				\
+do {	register unsigned int __old __asm("o0");		\
+	register unsigned int __new __asm("o1");		\
+	register volatile unsigned int *__lock __asm("o2");	\
+	__old = old;						\
+	__new = new;						\
+	__lock = (volatile unsigned int *)lock;			\
+	__asm__ __volatile__(					\
+		/*"cas [%2], %3, %0"*/				\
+		".word 0xd3e29008\n\t"				\
+		/*"membar #StoreStore | #StoreLoad"*/		\
+		".word 0x8143e00a"				\
+		: "=&r" (__new)					\
+		: "0" (__new),					\
+		  "r" (__lock),					\
+		  "r" (__old)					\
+		: "memory");					\
+	__ret = (__new != __old);				\
+} while(0)
+
+#elif defined(__ia64__)
+
+#ifdef __INTEL_COMPILER
+/* this currently generates bad code (missing stop bits)... */
+#include <ia64intrin.h>
+
+#define DRM_CAS(lock,old,new,__ret)					      \
+	do {								      \
+		unsigned long __result, __old = (old) & 0xffffffff;		\
+		__mf();							      	\
+		__result = _InterlockedCompareExchange_acq(&__drm_dummy_lock(lock), (new), __old);\
+		__ret = (__result) != (__old);					\
+/*		__ret = (__sync_val_compare_and_swap(&__drm_dummy_lock(lock), \
+						     (old), (new))	      \
+			 != (old));					      */\
+	} while (0)
+
+#else
+#define DRM_CAS(lock,old,new,__ret)					  \
+	do {								  \
+		unsigned int __result, __old = (old);			  \
+		__asm__ __volatile__(					  \
+			"mf\n"						  \
+			"mov ar.ccv=%2\n"				  \
+			";;\n"						  \
+			"cmpxchg4.acq %0=%1,%3,ar.ccv"			  \
+			: "=r" (__result), "=m" (__drm_dummy_lock(lock))  \
+			: "r" ((unsigned long)__old), "r" (new)			  \
+			: "memory");					  \
+		__ret = (__result) != (__old);				  \
+	} while (0)
+
+#endif
+
+#elif defined(__powerpc__)
+
+#define DRM_CAS(lock,old,new,__ret)			\
+	do {						\
+		__asm__ __volatile__(			\
+			"sync;"				\
+			"0:    lwarx %0,0,%1;"		\
+			"      xor. %0,%3,%0;"		\
+			"      bne 1f;"			\
+			"      stwcx. %2,0,%1;"		\
+			"      bne- 0b;"		\
+			"1:    "			\
+			"sync;"				\
+		: "=&r"(__ret)				\
+		: "r"(lock), "r"(new), "r"(old)		\
+		: "cr0", "memory");			\
+	} while (0)
+
+#endif /* architecture */
+#endif /* __GNUC__ >= 2 */
+
+#if defined(sun)
+extern char atomic_cmpset_int(void *, unsigned int, unsigned int);
+#define DRM_CAS(lock,old,new,__ret)             \
+	        do {                                    \
+			                unsigned int __result, __old = (old);   \
+			                __result = !atomic_cmpset_int(lock,old,new); \
+			                __ret = __result;          \
+			        } while(0)
+#endif
+
+
+#ifndef DRM_CAS
+#define DRM_CAS(lock,old,new,ret) do { ret=1; } while (0) /* FAST LOCK FAILS */
+#endif
+
+#if defined(__alpha__) || defined(__powerpc__)
+#define DRM_CAS_RESULT(_result)		int _result
+#else
+#define DRM_CAS_RESULT(_result)		char _result
+#endif
+
+#define DRM_LIGHT_LOCK(fd,lock,context)                                \
+	do {                                                           \
+                DRM_CAS_RESULT(__ret);                                 \
+		DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret);     \
+                if (__ret) drmGetLock(fd,context,0);                   \
+        } while(0)
+
+				/* This one counts fast locks -- for
+                                   benchmarking only. */
+#define DRM_LIGHT_LOCK_COUNT(fd,lock,context,count)                    \
+	do {                                                           \
+                DRM_CAS_RESULT(__ret);                                 \
+		DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret);     \
+                if (__ret) drmGetLock(fd,context,0);                   \
+                else       ++count;                                    \
+        } while(0)
+
+#define DRM_LOCK(fd,lock,context,flags)                                \
+	do {                                                           \
+		if (flags) drmGetLock(fd,context,flags);               \
+		else       DRM_LIGHT_LOCK(fd,lock,context);            \
+	} while(0)
+
+#define DRM_UNLOCK(fd,lock,context)                                    \
+	do {                                                           \
+                DRM_CAS_RESULT(__ret);                                 \
+		DRM_CAS(lock,DRM_LOCK_HELD|context,context,__ret);     \
+                if (__ret) drmUnlock(fd,context);                      \
+        } while(0)
+
+				/* Simple spin locks */
+#define DRM_SPINLOCK(spin,val)                                         \
+	do {                                                           \
+            DRM_CAS_RESULT(__ret);                                     \
+	    do {                                                       \
+		DRM_CAS(spin,0,val,__ret);                             \
+		if (__ret) while ((spin)->lock);                       \
+	    } while (__ret);                                           \
+	} while(0)
+
+#define DRM_SPINLOCK_TAKE(spin,val)                                    \
+	do {                                                           \
+            DRM_CAS_RESULT(__ret);                                     \
+            int  cur;                                                  \
+	    do {                                                       \
+                cur = (*spin).lock;                                    \
+		DRM_CAS(spin,cur,val,__ret);                           \
+	    } while (__ret);                                           \
+	} while(0)
+
+#define DRM_SPINLOCK_COUNT(spin,val,count,__ret)                       \
+	do {                                                           \
+            int  __i;                                                  \
+            __ret = 1;                                                 \
+            for (__i = 0; __ret && __i < count; __i++) {               \
+		DRM_CAS(spin,0,val,__ret);                             \
+		if (__ret) for (;__i < count && (spin)->lock; __i++);  \
+	    }                                                          \
+	} while(0)
+
+#define DRM_SPINUNLOCK(spin,val)                                       \
+	do {                                                           \
+            DRM_CAS_RESULT(__ret);                                     \
+            if ((*spin).lock == val) { /* else server stole lock */    \
+	        do {                                                   \
+		    DRM_CAS(spin,val,0,__ret);                         \
+	        } while (__ret);                                       \
+            }                                                          \
+	} while(0)
+
+/* General user-level programmer's API: unprivileged */
+extern int           drmAvailable(void);
+extern int           drmOpen(const char *name, const char *busid);
+extern int           drmClose(int fd);
+extern drmVersionPtr drmGetVersion(int fd);
+extern drmVersionPtr drmGetLibVersion(int fd);
+extern void          drmFreeVersion(drmVersionPtr);
+extern int           drmGetMagic(int fd, drm_magic_t * magic);
+extern char          *drmGetBusid(int fd);
+extern int           drmGetInterruptFromBusID(int fd, int busnum, int devnum,
+					      int funcnum);
+extern int           drmGetMap(int fd, int idx, drm_handle_t *offset,
+			       drmSize *size, drmMapType *type,
+			       drmMapFlags *flags, drm_handle_t *handle,
+			       int *mtrr);
+extern int           drmGetClient(int fd, int idx, int *auth, int *pid,
+				  int *uid, unsigned long *magic,
+				  unsigned long *iocs);
+extern int           drmGetStats(int fd, drmStatsT *stats);
+extern int           drmSetInterfaceVersion(int fd, drmSetVersion *version);
+extern int           drmCommandNone(int fd, unsigned long drmCommandIndex);
+extern int           drmCommandRead(int fd, unsigned long drmCommandIndex,
+                                    void *data, unsigned long size);
+extern int           drmCommandWrite(int fd, unsigned long drmCommandIndex,
+                                     void *data, unsigned long size);
+extern int           drmCommandWriteRead(int fd, unsigned long drmCommandIndex,
+                                         void *data, unsigned long size);
+
+/* General user-level programmer's API: X server (root) only  */
+extern void          drmFreeBusid(const char *busid);
+extern int           drmSetBusid(int fd, const char *busid);
+extern int           drmAuthMagic(int fd, drm_magic_t magic);
+extern int           drmAddMap(int fd,
+			       drm_handle_t offset,
+			       drmSize size,
+			       drmMapType type,
+			       drmMapFlags flags,
+			       drm_handle_t * handle);
+extern int	     drmRmMap(int fd, drm_handle_t handle);
+extern int	     drmAddContextPrivateMapping(int fd, drm_context_t ctx_id,
+						 drm_handle_t handle);
+
+extern int           drmAddBufs(int fd, int count, int size,
+				drmBufDescFlags flags,
+				int agp_offset);
+extern int           drmMarkBufs(int fd, double low, double high);
+extern int           drmCreateContext(int fd, drm_context_t * handle);
+extern int           drmSetContextFlags(int fd, drm_context_t context,
+					drm_context_tFlags flags);
+extern int           drmGetContextFlags(int fd, drm_context_t context,
+					drm_context_tFlagsPtr flags);
+extern int           drmAddContextTag(int fd, drm_context_t context, void *tag);
+extern int           drmDelContextTag(int fd, drm_context_t context);
+extern void          *drmGetContextTag(int fd, drm_context_t context);
+extern drm_context_t * drmGetReservedContextList(int fd, int *count);
+extern void          drmFreeReservedContextList(drm_context_t *);
+extern int           drmSwitchToContext(int fd, drm_context_t context);
+extern int           drmDestroyContext(int fd, drm_context_t handle);
+extern int           drmCreateDrawable(int fd, drm_drawable_t * handle);
+extern int           drmDestroyDrawable(int fd, drm_drawable_t handle);
+extern int           drmCtlInstHandler(int fd, int irq);
+extern int           drmCtlUninstHandler(int fd);
+extern int           drmInstallSIGIOHandler(int fd,
+					    void (*f)(int fd,
+						      void *oldctx,
+						      void *newctx));
+extern int           drmRemoveSIGIOHandler(int fd);
+
+/* General user-level programmer's API: authenticated client and/or X */
+extern int           drmMap(int fd,
+			    drm_handle_t handle,
+			    drmSize size,
+			    drmAddressPtr address);
+extern int           drmUnmap(drmAddress address, drmSize size);
+extern drmBufInfoPtr drmGetBufInfo(int fd);
+extern drmBufMapPtr  drmMapBufs(int fd);
+extern int           drmUnmapBufs(drmBufMapPtr bufs);
+extern int           drmDMA(int fd, drmDMAReqPtr request);
+extern int           drmFreeBufs(int fd, int count, int *list);
+extern int           drmGetLock(int fd,
+			        drm_context_t context,
+			        drmLockFlags flags);
+extern int           drmUnlock(int fd, drm_context_t context);
+extern int           drmFinish(int fd, int context, drmLockFlags flags);
+extern int	     drmGetContextPrivateMapping(int fd, drm_context_t ctx_id, 
+						 drm_handle_t * handle);
+
+/* AGP/GART support: X server (root) only */
+extern int           drmAgpAcquire(int fd);
+extern int           drmAgpRelease(int fd);
+extern int           drmAgpEnable(int fd, unsigned long mode);
+extern int           drmAgpAlloc(int fd, unsigned long size,
+				 unsigned long type, unsigned long *address,
+				 drm_handle_t *handle);
+extern int           drmAgpFree(int fd, drm_handle_t handle);
+extern int 	     drmAgpBind(int fd, drm_handle_t handle,
+				unsigned long offset);
+extern int           drmAgpUnbind(int fd, drm_handle_t handle);
+
+/* AGP/GART info: authenticated client and/or X */
+extern int           drmAgpVersionMajor(int fd);
+extern int           drmAgpVersionMinor(int fd);
+extern unsigned long drmAgpGetMode(int fd);
+extern unsigned long drmAgpBase(int fd); /* Physical location */
+extern unsigned long drmAgpSize(int fd); /* Bytes */
+extern unsigned long drmAgpMemoryUsed(int fd);
+extern unsigned long drmAgpMemoryAvail(int fd);
+extern unsigned int  drmAgpVendorId(int fd);
+extern unsigned int  drmAgpDeviceId(int fd);
+
+/* PCI scatter/gather support: X server (root) only */
+extern int           drmScatterGatherAlloc(int fd, unsigned long size,
+					   drm_handle_t *handle);
+extern int           drmScatterGatherFree(int fd, drm_handle_t handle);
+
+extern int           drmWaitVBlank(int fd, drmVBlankPtr vbl);
+
+/* Support routines */
+extern int           drmError(int err, const char *label);
+extern void          *drmMalloc(int size);
+extern void          drmFree(void *pt);
+
+/* Hash table routines */
+extern void *drmHashCreate(void);
+extern int  drmHashDestroy(void *t);
+extern int  drmHashLookup(void *t, unsigned long key, void **value);
+extern int  drmHashInsert(void *t, unsigned long key, void *value);
+extern int  drmHashDelete(void *t, unsigned long key);
+extern int  drmHashFirst(void *t, unsigned long *key, void **value);
+extern int  drmHashNext(void *t, unsigned long *key, void **value);
+
+/* PRNG routines */
+extern void          *drmRandomCreate(unsigned long seed);
+extern int           drmRandomDestroy(void *state);
+extern unsigned long drmRandom(void *state);
+extern double        drmRandomDouble(void *state);
+
+/* Skip list routines */
+
+extern void *drmSLCreate(void);
+extern int  drmSLDestroy(void *l);
+extern int  drmSLLookup(void *l, unsigned long key, void **value);
+extern int  drmSLInsert(void *l, unsigned long key, void *value);
+extern int  drmSLDelete(void *l, unsigned long key);
+extern int  drmSLNext(void *l, unsigned long *key, void **value);
+extern int  drmSLFirst(void *l, unsigned long *key, void **value);
+extern void drmSLDump(void *l);
+extern int  drmSLLookupNeighbors(void *l, unsigned long key,
+				 unsigned long *prev_key, void **prev_value,
+				 unsigned long *next_key, void **next_value);
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/extras/drm/shared-core/drm.h	Tue Oct 24 18:42:11 2006 -0700
@@ -0,0 +1,925 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* BEGIN CSTYLED */
+
+/**
+ * \file drm.h
+ * Header for the Direct Rendering Manager
+ *
+ * \author Rickard E. (Rik) Faith <[email protected]>
+ *
+ * \par Acknowledgments:
+ * Dec 1999, Richard Henderson <[email protected]>, move to generic \c cmpxchg.
+ */
+
+/*
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS 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.
+ */
+
+/**
+ * \mainpage
+ *
+ * The Direct Rendering Manager (DRM) is a device-independent kernel-level
+ * device driver that provides support for the XFree86 Direct Rendering
+ * Infrastructure (DRI).
+ *
+ * The DRM supports the Direct Rendering Infrastructure (DRI) in four major
+ * ways:
+ *     -# The DRM provides synchronized access to the graphics hardware via
+ *        the use of an optimized two-tiered lock.
+ *     -# The DRM enforces the DRI security policy for access to the graphics
+ *        hardware by only allowing authenticated X11 clients access to
+ *        restricted regions of memory.
+ *     -# The DRM provides a generic DMA engine, complete with multiple
+ *        queues and the ability to detect the need for an OpenGL context
+ *        switch.
+ *     -# The DRM is extensible via the use of small device-specific modules
+ *        that rely extensively on the API exported by the DRM module.
+ *
+ */
+
+#ifndef _DRM_H_
+#define _DRM_H_
+
+#pragma ident	"@(#)drm.h	1.8	06/09/14 SMI"
+
+#include <sys/types32.h>
+
+#ifndef __user
+#define __user
+#endif
+
+#ifdef __GNUC__
+# define DEPRECATED  __attribute__ ((deprecated))
+#else
+# define DEPRECATED
+# define __volatile__ volatile
+#endif
+
+#if defined(__linux__)
+#if defined(__KERNEL__)
+#include <linux/config.h>
+#endif
+#include <asm/ioctl.h>		/* For _IO* macros */
+#define DRM_IOCTL_NR(n)		_IOC_NR(n)
+#define DRM_IOC_VOID		_IOC_NONE
+#define DRM_IOC_READ		_IOC_READ
+#define DRM_IOC_WRITE		_IOC_WRITE
+#define DRM_IOC_READWRITE	_IOC_READ|_IOC_WRITE
+#define DRM_IOC(dir, group, nr, size) _IOC(dir, group, nr, size)
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+#if defined(__FreeBSD__) && defined(IN_MODULE)
+/* Prevent name collision when including sys/ioccom.h */
+#undef ioctl
+#include <sys/ioccom.h>
+#define ioctl(a,b,c)		xf86ioctl(a,b,c)
+#else
+#include <sys/ioccom.h>
+#endif				/* __FreeBSD__ && xf86ioctl */
+#define DRM_IOCTL_NR(n)		((n) & 0xff)
+#define DRM_IOC_VOID		IOC_VOID
+#define DRM_IOC_READ		IOC_OUT
+#define DRM_IOC_WRITE		IOC_IN
+#define DRM_IOC_READWRITE	IOC_INOUT
+#define DRM_IOC(dir, group, nr, size) _IOC(dir, group, nr, size)
+#endif
+
+/* Solaris-specific. */
+#if defined(__SOLARIS__) || defined(sun)
+#define	_IOC_NR(nr)	(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
+
+#define	_IOC_NRBITS	8
+#define	_IOC_TYPEBITS   8
+#define	_IOC_SIZEBITS   14
+#define	_IOC_DIRBITS    2
+
+#define	_IOC_NRMASK	((1 << _IOC_NRBITS)-1)
+#define	_IOC_TYPEMASK   ((1 << _IOC_TYPEBITS)-1)
+#define	_IOC_SIZEMASK   ((1 << _IOC_SIZEBITS)-1)
+#define	_IOC_DIRMASK    ((1 << _IOC_DIRBITS)-1)
+
+#define	_IOC_NRSHIFT    0
+#define	_IOC_TYPESHIFT  (_IOC_NRSHIFT+_IOC_NRBITS)
+#define	_IOC_SIZESHIFT  (_IOC_TYPESHIFT+_IOC_TYPEBITS)
+#define	_IOC_DIRSHIFT   (_IOC_SIZESHIFT+_IOC_SIZEBITS)
+
+#define	_IOC_NONE	0U
+#define	_IOC_WRITE	1U
+#define	_IOC_READ	2U
+
+#define	_IOC(dir, type, nr, size) \
+	(((dir)  << _IOC_DIRSHIFT) | \
+	((type) << _IOC_TYPESHIFT) | \
+	((nr)   << _IOC_NRSHIFT) | \
+	((size) << _IOC_SIZESHIFT))
+
+/* used for X server compile */
+#if !defined(_KERNEL)
+#define	_IO(type, nr)		_IOC(_IOC_NONE, (type), (nr), 0)
+#define	_IOR(type, nr, size)	_IOC(_IOC_READ, (type), (nr), sizeof (size))
+#define	_IOW(type, nr, size)	_IOC(_IOC_WRITE, (type), (nr), sizeof (size))
+#define	_IOWR(type, nr, size)	_IOC(_IOC_READ|_IOC_WRITE, \
+				(type), (nr), sizeof (size))
+
+#define	_IOC_DIR(nr)		(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
+#define	_IOC_TYPE(nr)		(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
+#define	_IOC_NR(nr)		(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
+#define	_IOC_SIZE(nr)		(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
+
+#define	IOC_IN			(_IOC_WRITE << _IOC_DIRSHIFT)
+#define	IOC_OUT			(_IOC_READ << _IOC_DIRSHIFT)
+#define	IOC_INOUT		((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
+#define	IOCSIZE_MASK		(_IOC_SIZEMASK << _IOC_SIZESHIFT)
+#define	IOCSIZE_SHIFT		(_IOC_SIZESHIFT)
+#endif /* _KERNEL */
+
+#define	DRM_IOCTL_NR(n)		_IOC_NR(n)
+#define	DRM_IOC_VOID		IOC_VOID
+#define	DRM_IOC_READ		IOC_OUT
+#define	DRM_IOC_WRITE		IOC_IN
+#define	DRM_IOC_READWRITE	IOC_INOUT
+#define	DRM_IOC(dir, group, nr, size) _IOC(dir, group, nr, size)
+
+#endif /* __Solaris__ or sun */
+#define XFREE86_VERSION(major,minor,patch,snap) \
+		((major << 16) | (minor << 8) | patch)
+
+#ifndef CONFIG_XFREE86_VERSION
+#define CONFIG_XFREE86_VERSION XFREE86_VERSION(4,1,0,0)
+#endif
+
+#if CONFIG_XFREE86_VERSION < XFREE86_VERSION(4,1,0,0)
+#define DRM_PROC_DEVICES "/proc/devices"
+#define DRM_PROC_MISC	 "/proc/misc"
+#define DRM_PROC_DRM	 "/proc/drm"
+#define DRM_DEV_DRM	 "/dev/drm"
+#define DRM_DEV_MODE	 (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
+#define DRM_DEV_UID	 0
+#define DRM_DEV_GID	 0
+#endif
+
+#if CONFIG_XFREE86_VERSION >= XFREE86_VERSION(4,1,0,0)
+#ifdef __OpenBSD__
+#define DRM_MAJOR       81
+#endif
+#if defined(__linux__) || defined(__NetBSD__)
+#define DRM_MAJOR       226
+#endif
+#define DRM_MAX_MINOR   255
+#endif
+#define DRM_NAME	"drm"	  /**< Name in kernel, /dev, and /proc */
+#define DRM_MIN_ORDER	5	  /**< At least 2^5 bytes = 32 bytes */
+#define DRM_MAX_ORDER	22	  /**< Up to 2^22 bytes = 4MB */
+#define DRM_RAM_PERCENT 10	  /**< How much system ram can we lock? */
+
+#define _DRM_LOCK_HELD	0x80000000U /**< Hardware lock is held */
+#define _DRM_LOCK_CONT	0x40000000U /**< Hardware lock is contended */
+#define _DRM_LOCK_IS_HELD(lock)	   ((lock) & _DRM_LOCK_HELD)
+#define _DRM_LOCK_IS_CONT(lock)	   ((lock) & _DRM_LOCK_CONT)
+#define _DRM_LOCKING_CONTEXT(lock) ((lock) & ~(_DRM_LOCK_HELD|_DRM_LOCK_CONT))
+
+#if defined(__linux__)
+typedef unsigned int drm_handle_t;
+#else
+typedef unsigned long long drm_handle_t;	/**< To mapped regions */
+#endif
+typedef unsigned int drm_context_t;	/**< GLXContext handle */
+typedef unsigned int drm_drawable_t;
+typedef unsigned int drm_magic_t;	/**< Magic for authentication */
+
+/**
+ * Cliprect.
+ *
+ * \warning If you change this structure, make sure you change
+ * XF86DRIClipRectRec in the server as well
+ *
+ * \note KW: Actually it's illegal to change either for
+ * backwards-compatibility reasons.
+ */
+typedef struct drm_clip_rect {
+	unsigned short x1;
+	unsigned short y1;
+	unsigned short x2;
+	unsigned short y2;
+} drm_clip_rect_t;
+
+/**
+ * Texture region,
+ */
+typedef struct drm_tex_region {
+	unsigned char next;
+	unsigned char prev;
+	unsigned char in_use;
+	unsigned char padding;
+	unsigned int age;
+} drm_tex_region_t;
+
+/**
+ * Hardware lock.
+ *
+ * The lock structure is a simple cache-line aligned integer.  To avoid
+ * processor bus contention on a multiprocessor system, there should not be any
+ * other data stored in the same cache line.
+ */
+typedef struct drm_hw_lock {
+	__volatile__ unsigned int lock;		/**< lock variable */
+	char padding[60];			/**< Pad to cache line */
+} drm_hw_lock_t;
+
+/* This is beyond ugly, and only works on GCC.  However, it allows me to use
+ * drm.h in places (i.e., in the X-server) where I can't use size_t.  The real
+ * fix is to use uint32_t instead of size_t, but that fix will break existing
+ * LP64 (i.e., PowerPC64, SPARC64, IA-64, Alpha, etc.) systems.  That *will*
+ * eventually happen, though.  I chose 'unsigned long' to be the fallback type
+ * because that works on all the platforms I know about.  Hopefully, the
+ * real fix will happen before that bites us.
+ */
+
+#ifdef __SIZE_TYPE__
+# define DRM_SIZE_T __SIZE_TYPE__
+#else
+#if !defined(__SOLARIS__) && !defined(sun)
+# warning "__SIZE_TYPE__ not defined.  Assuming sizeof(size_t) == sizeof(unsigned long)!"
+#endif
+# define DRM_SIZE_T unsigned long
+#endif
+
+/**
+ * DRM_IOCTL_VERSION ioctl argument type.
+ *
+ * \sa drmGetVersion().
+ */
+typedef struct drm_version {
+	int version_major;	  /**< Major version */
+	int version_minor;	  /**< Minor version */
+	int version_patchlevel;	  /**< Patch level */
+	DRM_SIZE_T name_len;	  /**< Length of name buffer */
+	char __user *name;		  /**< Name of driver */
+	DRM_SIZE_T date_len;	  /**< Length of date buffer */
+	char __user *date;		  /**< User-space buffer to hold date */
+	DRM_SIZE_T desc_len;	  /**< Length of desc buffer */
+	char __user *desc;		  /**< User-space buffer to hold desc */
+} drm_version_t;
+
+#if defined(__sun) && defined(_KERNEL)
+typedef struct drm_version32 {
+	int version_major;		/* Major version */
+	int version_minor;		/* Minor version */
+	int version_patchlevel;	  	/* Patch level */
+	uint32_t name_len;		/* Length of name buffer */
+	caddr32_t name;			/* Name of driver */
+	uint32_t date_len;		/* Length of date buffer */
+	caddr32_t date;			/* User-space buffer to hold date */
+	uint32_t desc_len;		/* Length of desc buffer */
+	caddr32_t desc;			/* User-space buffer to hold desc */
+} drm_version32_t;
+#endif
+
+/**
+ * DRM_IOCTL_GET_UNIQUE ioctl argument type.
+ *
+ * \sa drmGetBusid() and drmSetBusId().
+ */
+typedef struct drm_unique {
+	DRM_SIZE_T unique_len;	  /**< Length of unique */
+	char __user *unique;	  /**< Unique name for driver instantiation */
+} drm_unique_t;
+
+#if defined(__sun) && defined(_KERNEL)
+typedef struct drm_unique32 {
+	uint32_t unique_len;	/* Length of unique */
+	caddr32_t unique;	/* Unique name for driver instantiation */
+} drm_unique32_t;
+#endif
+
+#undef DRM_SIZE_T
+
+typedef struct drm_list {
+	int count;		  /**< Length of user-space structures */
+	drm_version_t __user *version;
+} drm_list_t;
+
+typedef struct drm_block {
+	int unused;
+} drm_block_t;
+
+/**
+ * DRM_IOCTL_CONTROL ioctl argument type.
+ *
+ * \sa drmCtlInstHandler() and drmCtlUninstHandler().
+ */
+typedef struct drm_control {
+	enum {
+		DRM_ADD_COMMAND,
+		DRM_RM_COMMAND,
+		DRM_INST_HANDLER,
+		DRM_UNINST_HANDLER
+	} func;
+	int irq;
+} drm_control_t;
+
+/**
+ * Type of memory to map.
+ */
+typedef enum drm_map_type {
+	_DRM_FRAME_BUFFER = 0,	  /**< WC (no caching), no core dump */
+	_DRM_REGISTERS = 1,	  /**< no caching, no core dump */
+	_DRM_SHM = 2,		  /**< shared, cached */
+	_DRM_AGP = 3,		  /**< AGP/GART */
+	_DRM_SCATTER_GATHER = 4,  /**< Scatter/gather memory for PCI DMA */
+	_DRM_CONSISTENT = 5,	  /**< Consistent memory for PCI DMA */
+	_DRM_AGP_UMEM	= 6
+} drm_map_type_t;
+
+/**
+ * Memory mapping flags.
+ */
+typedef enum drm_map_flags {
+	_DRM_RESTRICTED = 0x01,	     /**< Cannot be mapped to user-virtual */
+	_DRM_READ_ONLY = 0x02,
+	_DRM_LOCKED = 0x04,	     /**< shared, cached, locked */
+	_DRM_KERNEL = 0x08,	     /**< kernel requires access */
+	_DRM_WRITE_COMBINING = 0x10, /**< use write-combining if available */
+	_DRM_CONTAINS_LOCK = 0x20,   /**< SHM page that contains lock */
+	_DRM_REMOVABLE = 0x40	     /**< Removable mapping */
+} drm_map_flags_t;
+
+typedef struct drm_ctx_priv_map {
+	unsigned int ctx_id;	 /**< Context requesting private mapping */
+	void *handle;		 /**< Handle of map */
+} drm_ctx_priv_map_t;
+
+#if defined(__sun) && defined(_KERNEL)
+typedef struct drm_ctx_priv_map32 {
+	unsigned int ctx_id;	 /* Context requesting private mapping */
+	caddr32_t handle;	 /* Handle of map */
+} drm_ctx_priv_map32_t;
+#endif
+
+/**
+ * DRM_IOCTL_GET_MAP, DRM_IOCTL_ADD_MAP and DRM_IOCTL_RM_MAP ioctls
+ * argument type.
+ *
+ * \sa drmAddMap().
+ */
+typedef struct drm_map {
+	unsigned long long offset;	 /**< Requested physical address (0 for SAREA)*/
+	unsigned long long handle;
+				/**< User-space: "Handle" to pass to mmap() */
+				/**< Kernel-space: kernel-virtual address */
+	unsigned long size;	 /**< Requested physical size (bytes) */
+	drm_map_type_t type;	 /**< Type of memory to map */
+	drm_map_flags_t flags;	 /**< Flags */
+	int mtrr;		 /**< MTRR slot used */
+	/*   Private data */
+} drm_map_t;
+
+#if defined(__sun) && defined(_KERNEL)
+typedef struct drm_map32 {
+	unsigned long long offset;
+	unsigned long long handle;
+	uint32_t size;
+	drm_map_type_t type;
+	drm_map_flags_t flags;
+	int mtrr;
+} drm_map32_t;
+#endif
+
+/**
+ * DRM_IOCTL_GET_CLIENT ioctl argument type.
+ */
+typedef struct drm_client {
+	int idx;		/**< Which client desired? */
+	int auth;		/**< Is client authenticated? */
+	unsigned long pid;	/**< Process ID */
+	unsigned long uid;	/**< User ID */
+	unsigned long magic;	/**< Magic */
+	unsigned long iocs;	/**< Ioctl count */
+} drm_client_t;
+
+#if defined(__sun) && defined(_KERNEL)
+typedef struct drm_client32 {
+	int idx;		/**< Which client desired? */
+	int auth;		/**< Is client authenticated? */
+	uint32_t pid;	/**< Process ID */
+	uint32_t uid;	/**< User ID */
+	uint32_t magic;	/**< Magic */
+	uint32_t iocs;	/**< Ioctl count */
+} drm_client32_t;
+#endif
+
+typedef enum {
+	_DRM_STAT_LOCK,
+	_DRM_STAT_OPENS,
+	_DRM_STAT_CLOSES,
+	_DRM_STAT_IOCTLS,
+	_DRM_STAT_LOCKS,
+	_DRM_STAT_UNLOCKS,
+	_DRM_STAT_VALUE,	/**< Generic value */
+	_DRM_STAT_BYTE,		/**< Generic byte counter (1024bytes/K) */
+	_DRM_STAT_COUNT,	/**< Generic non-byte counter (1000/k) */
+
+	_DRM_STAT_IRQ,		/**< IRQ */
+	_DRM_STAT_PRIMARY,	/**< Primary DMA bytes */
+	_DRM_STAT_SECONDARY,	/**< Secondary DMA bytes */
+	_DRM_STAT_DMA,		/**< DMA */
+	_DRM_STAT_SPECIAL,	/**< Special DMA (e.g., priority or polled) */
+	_DRM_STAT_MISSED	/**< Missed DMA opportunity */
+	    /* Add to the *END* of the list */
+} drm_stat_type_t;
+
+/**
+ * DRM_IOCTL_GET_STATS ioctl argument type.
+ */
+typedef struct drm_stats {
+	unsigned long count;
+	struct {
+		unsigned long value;
+		drm_stat_type_t type;
+	} data[15];
+} drm_stats_t;
+
+#if defined(__sun) && defined(_KERNEL)
+typedef struct drm_stats32 {
+	uint32_t count;
+	struct {
+		uint32_t value;
+		drm_stat_type_t type;
+	} data[15];
+} drm_stats32_t;
+#endif
+
+/**
+ * Hardware locking flags.
+ */
+typedef enum drm_lock_flags {
+	_DRM_LOCK_READY = 0x01,	     /**< Wait until hardware is ready for DMA */
+	_DRM_LOCK_QUIESCENT = 0x02,  /**< Wait until hardware quiescent */
+	_DRM_LOCK_FLUSH = 0x04,	     /**< Flush this context's DMA queue first */
+	_DRM_LOCK_FLUSH_ALL = 0x08,  /**< Flush all DMA queues first */
+	/* These *HALT* flags aren't supported yet
+	   -- they will be used to support the
+	   full-screen DGA-like mode. */
+	_DRM_HALT_ALL_QUEUES = 0x10, /**< Halt all current and future queues */
+	_DRM_HALT_CUR_QUEUES = 0x20  /**< Halt all current queues */
+} drm_lock_flags_t;
+
+/**
+ * DRM_IOCTL_LOCK, DRM_IOCTL_UNLOCK and DRM_IOCTL_FINISH ioctl argument type.
+ *
+ * \sa drmGetLock() and drmUnlock().
+ */
+typedef struct drm_lock {
+	int context;
+	drm_lock_flags_t flags;
+} drm_lock_t;
+
+/**
+ * DMA flags
+ *
+ * \warning
+ * These values \e must match xf86drm.h.
+ *
+ * \sa drm_dma.
+ */
+typedef enum drm_dma_flags {
+	/* Flags for DMA buffer dispatch */
+	_DRM_DMA_BLOCK = 0x01,	      /**<
+				       * Block until buffer dispatched.
+				       *
+				       * \note The buffer may not yet have
+				       * been processed by the hardware --
+				       * getting a hardware lock with the
+				       * hardware quiescent will ensure
+				       * that the buffer has been
+				       * processed.
+				       */
+	_DRM_DMA_WHILE_LOCKED = 0x02, /**< Dispatch while lock held */
+	_DRM_DMA_PRIORITY = 0x04,     /**< High priority dispatch */
+
+	/* Flags for DMA buffer request */
+	_DRM_DMA_WAIT = 0x10,	      /**< Wait for free buffers */
+	_DRM_DMA_SMALLER_OK = 0x20,   /**< Smaller-than-requested buffers OK */
+	_DRM_DMA_LARGER_OK = 0x40     /**< Larger-than-requested buffers OK */
+} drm_dma_flags_t;
+
+/**
+ * DRM_IOCTL_ADD_BUFS and DRM_IOCTL_MARK_BUFS ioctl argument type.
+ *
+ * \sa drmAddBufs().
+ */
+typedef enum {
+	_DRM_PAGE_ALIGN = 0x01,	/**< Align on page boundaries for DMA */
+	_DRM_AGP_BUFFER = 0x02,	/**< Buffer is in AGP space */
+	_DRM_SG_BUFFER  = 0x04,	/**< Scatter/gather memory buffer */
+	_DRM_FB_BUFFER  = 0x08  /**< Buffer is in frame buffer */
+} drm_buf_flag;
+typedef struct drm_buf_desc {
+	int count;		 /**< Number of buffers of this size */
+	int size;		 /**< Size in bytes */
+	int low_mark;		 /**< Low water mark */
+	int high_mark;		 /**< High water mark */
+	drm_buf_flag flags;
+	unsigned long agp_start; /**<
+				  * Start address of where the AGP buffers are
+				  * in the AGP aperture
+				  */
+} drm_buf_desc_t;
+
+#if defined(__sun) && defined(_KERNEL)
+typedef struct drm_buf_desc32 {
+	int count;		 /**< Number of buffers of this size */
+	int size;		 /**< Size in bytes */
+	int low_mark;		 /**< Low water mark */
+	int high_mark;		 /**< High water mark */
+	drm_buf_flag flags;
+	uint32_t agp_start; /**<
+				  * Start address of where the AGP buffers are
+				  * in the AGP aperture
+				  */
+} drm_buf_desc32_t;
+#endif
+
+/**
+ * DRM_IOCTL_INFO_BUFS ioctl argument type.
+ */
+typedef struct drm_buf_info {
+	int count;		  /**< Number of buffers described in list */
+	drm_buf_desc_t __user *list;	  /**< List of buffer descriptions */
+} drm_buf_info_t;
+
+/**
+ * DRM_IOCTL_FREE_BUFS ioctl argument type.
+ */
+typedef struct drm_buf_free {
+	int count;
+	int __user *list;
+} drm_buf_free_t;
+
+#if defined(__sun) && defined(_KERNEL)
+typedef struct drm_buf_free32 {
+	int count;
+	caddr32_t list;
+} drm_buf_free32_t;
+#endif
+
+/**
+ * Buffer information
+ *
+ * \sa drm_buf_map.
+ */
+typedef struct drm_buf_pub {
+	int idx;		       /**< Index into the master buffer list */
+	int total;		       /**< Buffer size */
+	int used;		       /**< Amount of buffer in use (for DMA) */
+	void __user *address;	       /**< Address of buffer */
+} drm_buf_pub_t;
+
+/**
+ * DRM_IOCTL_MAP_BUFS ioctl argument type.
+ */
+typedef struct drm_buf_map {
+	int count;		/**< Length of the buffer list */
+#if defined(__cplusplus)
+	void __user *c_virtual;
+#else
+	void __user *virtual;		/**< Mmap'd area in user-virtual */
+#endif
+	drm_buf_pub_t __user *list;	/**< Buffer information */
+} drm_buf_map_t;
+
+#if defined(__sun) && defined(_KERNEL)
+typedef struct drm_buf_map32 {
+	int count;		/**< Length of the buffer list */
+#if defined(__cplusplus)
+	caddr32_t c_virtual;
+#else
+	caddr32_t virtual;		/**< Mmap'd area in user-virtual */
+#endif
+	caddr32_t list;	/**< Buffer information */
+} drm_buf_map32_t;
+#endif
+
+/**
+ * DRM_IOCTL_DMA ioctl argument type.
+ *
+ * Indices here refer to the offset into the buffer list in drm_buf_get.
+ *
+ * \sa drmDMA().
+ */
+typedef struct drm_dma {
+	int context;			  /**< Context handle */
+	int send_count;			  /**< Number of buffers to send */
+	int __user *send_indices;	  /**< List of handles to buffers */
+	int __user *send_sizes;		  /**< Lengths of data to send */
+	drm_dma_flags_t flags;		  /**< Flags */
+	int request_count;		  /**< Number of buffers requested */
+	int request_size;		  /**< Desired size for buffers */
+	int __user *request_indices;	 /**< Buffer information */
+	int __user *request_sizes;
+	int granted_count;		  /**< Number of buffers granted */
+} drm_dma_t;
+
+typedef enum {
+	_DRM_CONTEXT_PRESERVED = 0x01,
+	_DRM_CONTEXT_2DONLY = 0x02
+} drm_ctx_flags_t;
+
+/**
+ * DRM_IOCTL_ADD_CTX ioctl argument type.
+ *
+ * \sa drmCreateContext() and drmDestroyContext().
+ */
+typedef struct drm_ctx {
+	drm_context_t handle;
+	drm_ctx_flags_t flags;
+} drm_ctx_t;
+
+/**
+ * DRM_IOCTL_RES_CTX ioctl argument type.
+ */
+typedef struct drm_ctx_res {
+	int count;
+	drm_ctx_t __user *contexts;
+} drm_ctx_res_t;
+
+#if defined(__sun) && defined(_KERNEL)
+typedef struct drm_ctx_res32 {
+	int count;
+	caddr32_t contexts;
+} drm_ctx_res32_t;
+#endif
+
+/**
+ * DRM_IOCTL_ADD_DRAW and DRM_IOCTL_RM_DRAW ioctl argument type.
+ */
+typedef struct drm_draw {
+	drm_drawable_t handle;
+} drm_draw_t;
+
+/**
+ * DRM_IOCTL_GET_MAGIC and DRM_IOCTL_AUTH_MAGIC ioctl argument type.
+ */
+typedef struct drm_auth {
+	drm_magic_t magic;
+} drm_auth_t;
+
+/**
+ * DRM_IOCTL_IRQ_BUSID ioctl argument type.
+ *
+ * \sa drmGetInterruptFromBusID().
+ */
+typedef struct drm_irq_busid {
+	int irq;	/**< IRQ number */
+	int busnum;	/**< bus number */
+	int devnum;	/**< device number */
+	int funcnum;	/**< function number */
+} drm_irq_busid_t;
+
+typedef enum {
+	_DRM_VBLANK_ABSOLUTE = 0x0,	/**< Wait for specific vblank sequence number */
+	_DRM_VBLANK_RELATIVE = 0x1,	/**< Wait for given number of vblanks */
+	_DRM_VBLANK_SIGNAL = 0x40000000	/**< Send signal instead of blocking */
+} drm_vblank_seq_type_t;
+
+#define _DRM_VBLANK_FLAGS_MASK _DRM_VBLANK_SIGNAL
+
+struct drm_wait_vblank_request {
+	drm_vblank_seq_type_t type;
+	unsigned int sequence;
+	unsigned long signal;
+};
+
+struct drm_wait_vblank_reply {
+	drm_vblank_seq_type_t type;
+	unsigned int sequence;
+	long tval_sec;
+	long tval_usec;
+};
+
+/**
+ * DRM_IOCTL_WAIT_VBLANK ioctl argument type.
+ *
+ * \sa drmWaitVBlank().
+ */
+typedef union drm_wait_vblank {
+	struct drm_wait_vblank_request request;
+	struct drm_wait_vblank_reply reply;
+} drm_wait_vblank_t;
+
+/**
+ * DRM_IOCTL_AGP_ENABLE ioctl argument type.
+ *
+ * \sa drmAgpEnable().
+ */
+typedef struct drm_agp_mode {
+	unsigned long mode;	/**< AGP mode */
+} drm_agp_mode_t;
+
+#if defined(__sun) && defined(_KERNEL)
+typedef struct drm_agp_mode32 {
+	uint32_t mode;	/**< AGP mode */
+} drm_agp_mode32_t;
+#endif
+
+/**
+ * DRM_IOCTL_AGP_ALLOC and DRM_IOCTL_AGP_FREE ioctls argument type.
+ *
+ * \sa drmAgpAlloc() and drmAgpFree().
+ */
+typedef struct drm_agp_buffer {
+	unsigned long size;	/**< In bytes -- will round to page boundary */
+	unsigned long handle;	/**< Used for binding / unbinding */
+	unsigned long type;	/**< Type of memory to allocate */
+	unsigned long physical;	/**< Physical used by i810 */
+} drm_agp_buffer_t;
+
+#if defined(__sun) && defined(_KERNEL)
+typedef struct drm_agp_buffer32 {
+	uint32_t size;	/**< In bytes -- will round to page boundary */
+	uint32_t handle;	/**< Used for binding / unbinding */
+	uint32_t type;	/**< Type of memory to allocate */
+	uint32_t physical;	/**< Physical used by i810 */
+} drm_agp_buffer32_t;
+#endif
+
+/**
+ * DRM_IOCTL_AGP_BIND and DRM_IOCTL_AGP_UNBIND ioctls argument type.
+ *
+ * \sa drmAgpBind() and drmAgpUnbind().
+ */
+typedef struct drm_agp_binding {
+	unsigned long handle;	/**< From drm_agp_buffer */
+	unsigned long offset;	/**< In bytes -- will round to page boundary */
+} drm_agp_binding_t;
+
+#if defined(__sun) && defined(_KERNEL)
+typedef struct drm_agp_binding32 {
+	uint32_t handle;	/**< From drm_agp_buffer */
+	uint32_t offset;	/**< In bytes -- will round to page boundary */
+} drm_agp_binding32_t;
+#endif
+
+/**
+ * DRM_IOCTL_AGP_INFO ioctl argument type.
+ *
+ * \sa drmAgpVersionMajor(), drmAgpVersionMinor(), drmAgpGetMode(),
+ * drmAgpBase(), drmAgpSize(), drmAgpMemoryUsed(), drmAgpMemoryAvail(),
+ * drmAgpVendorId() and drmAgpDeviceId().
+ */
+typedef struct drm_agp_info {
+	int agp_version_major;
+	int agp_version_minor;
+	unsigned long mode;
+	unsigned long aperture_base;   /**< physical address */
+	unsigned long aperture_size;   /**< bytes */
+	unsigned long memory_allowed;  /**< bytes */
+	unsigned long memory_used;
+
+	/** \name PCI information */
+	/*@{ */
+	unsigned short id_vendor;
+	unsigned short id_device;
+	/*@} */
+} drm_agp_info_t;
+
+#if defined(__sun) && defined(_KERNEL)
+typedef struct drm_agp_info32 {
+	int agp_version_major;
+	int agp_version_minor;
+	uint32_t mode;
+	uint32_t aperture_base;
+	uint32_t aperture_size;
+	uint32_t memory_allowed;
+	uint32_t memory_used;
+	unsigned short id_vendor;
+	unsigned short id_device;
+} drm_agp_info32_t;
+#endif
+
+/**
+ * DRM_IOCTL_SG_ALLOC ioctl argument type.
+ */
+typedef struct drm_scatter_gather {
+	unsigned long size;	/**< In bytes -- will round to page boundary */
+	unsigned long handle;	/**< Used for mapping / unmapping */
+} drm_scatter_gather_t;
+
+#if defined(__sun) && defined(_KERNEL)
+typedef struct drm_scatter_gather32 {
+	uint32_t size;		/* In bytes -- will round to page boundary */
+	uint32_t handle;	/* Used for mapping / unmapping */
+} drm_scatter_gather32_t;
+#endif
+
+/**
+ * DRM_IOCTL_SET_VERSION ioctl argument type.
+ */
+typedef struct drm_set_version {
+	int drm_di_major;
+	int drm_di_minor;
+	int drm_dd_major;
+	int drm_dd_minor;
+} drm_set_version_t;
+
+/**
+ * \name Ioctls Definitions
+ */
+/*@{*/
+
+#define DRM_IOCTL_BASE			'd'
+#define DRM_IO(nr)			_IO(DRM_IOCTL_BASE,nr)
+#define DRM_IOR(nr,type)		_IOR(DRM_IOCTL_BASE,nr,type)
+#define DRM_IOW(nr,type)		_IOW(DRM_IOCTL_BASE,nr,type)
+#define DRM_IOWR(nr,type)		_IOWR(DRM_IOCTL_BASE,nr,type)
+
+#define DRM_IOCTL_VERSION		DRM_IOWR(0x00, drm_version_t)
+#define DRM_IOCTL_GET_UNIQUE		DRM_IOWR(0x01, drm_unique_t)
+#define DRM_IOCTL_GET_MAGIC		DRM_IOR( 0x02, drm_auth_t)
+#define DRM_IOCTL_IRQ_BUSID		DRM_IOWR(0x03, drm_irq_busid_t)
+#define DRM_IOCTL_GET_MAP               DRM_IOWR(0x04, drm_map_t)
+#define DRM_IOCTL_GET_CLIENT            DRM_IOWR(0x05, drm_client_t)
+#define DRM_IOCTL_GET_STATS             DRM_IOR( 0x06, drm_stats_t)
+#define DRM_IOCTL_SET_VERSION		DRM_IOWR(0x07, drm_set_version_t)
+
+#define DRM_IOCTL_SET_UNIQUE		DRM_IOW( 0x10, drm_unique_t)
+#define DRM_IOCTL_AUTH_MAGIC		DRM_IOW( 0x11, drm_auth_t)
+#define DRM_IOCTL_BLOCK			DRM_IOWR(0x12, drm_block_t)
+#define DRM_IOCTL_UNBLOCK		DRM_IOWR(0x13, drm_block_t)
+#define DRM_IOCTL_CONTROL		DRM_IOW( 0x14, drm_control_t)
+#define DRM_IOCTL_ADD_MAP		DRM_IOWR(0x15, drm_map_t)
+#define DRM_IOCTL_ADD_BUFS		DRM_IOWR(0x16, drm_buf_desc_t)
+#define DRM_IOCTL_MARK_BUFS		DRM_IOW( 0x17, drm_buf_desc_t)
+#define DRM_IOCTL_INFO_BUFS		DRM_IOWR(0x18, drm_buf_info_t)
+#define DRM_IOCTL_MAP_BUFS		DRM_IOWR(0x19, drm_buf_map_t)
+#define DRM_IOCTL_FREE_BUFS		DRM_IOW( 0x1a, drm_buf_free_t)
+
+#define DRM_IOCTL_RM_MAP		DRM_IOW( 0x1b, drm_map_t)
+
+#define DRM_IOCTL_SET_SAREA_CTX		DRM_IOW( 0x1c, drm_ctx_priv_map_t)
+#define DRM_IOCTL_GET_SAREA_CTX 	DRM_IOWR(0x1d, drm_ctx_priv_map_t)
+
+#define DRM_IOCTL_ADD_CTX		DRM_IOWR(0x20, drm_ctx_t)
+#define DRM_IOCTL_RM_CTX		DRM_IOWR(0x21, drm_ctx_t)
+#define DRM_IOCTL_MOD_CTX		DRM_IOW( 0x22, drm_ctx_t)
+#define DRM_IOCTL_GET_CTX		DRM_IOWR(0x23, drm_ctx_t)
+#define DRM_IOCTL_SWITCH_CTX		DRM_IOW( 0x24, drm_ctx_t)
+#define DRM_IOCTL_NEW_CTX		DRM_IOW( 0x25, drm_ctx_t)
+#define DRM_IOCTL_RES_CTX		DRM_IOWR(0x26, drm_ctx_res_t)
+#define DRM_IOCTL_ADD_DRAW		DRM_IOWR(0x27, drm_draw_t)
+#define DRM_IOCTL_RM_DRAW		DRM_IOWR(0x28, drm_draw_t)
+#define DRM_IOCTL_DMA			DRM_IOWR(0x29, drm_dma_t)
+#define DRM_IOCTL_LOCK			DRM_IOW( 0x2a, drm_lock_t)
+#define DRM_IOCTL_UNLOCK		DRM_IOW( 0x2b, drm_lock_t)
+#define DRM_IOCTL_FINISH		DRM_IOW( 0x2c, drm_lock_t)
+
+#define DRM_IOCTL_AGP_ACQUIRE		DRM_IO(  0x30)
+#define DRM_IOCTL_AGP_RELEASE		DRM_IO(  0x31)
+#define DRM_IOCTL_AGP_ENABLE		DRM_IOW( 0x32, drm_agp_mode_t)
+#define DRM_IOCTL_AGP_INFO		DRM_IOR( 0x33, drm_agp_info_t)
+#define DRM_IOCTL_AGP_ALLOC		DRM_IOWR(0x34, drm_agp_buffer_t)
+#define DRM_IOCTL_AGP_FREE		DRM_IOW( 0x35, drm_agp_buffer_t)
+#define DRM_IOCTL_AGP_BIND		DRM_IOW( 0x36, drm_agp_binding_t)
+#define DRM_IOCTL_AGP_UNBIND		DRM_IOW( 0x37, drm_agp_binding_t)
+
+#define DRM_IOCTL_SG_ALLOC		DRM_IOW( 0x38, drm_scatter_gather_t)
+#define DRM_IOCTL_SG_FREE		DRM_IOW( 0x39, drm_scatter_gather_t)
+
+#define DRM_IOCTL_WAIT_VBLANK		DRM_IOWR(0x3a, drm_wait_vblank_t)
+
+/*@}*/
+
+/**
+ * Device specific ioctls should only be in their respective headers
+ * The device specific ioctl range is from 0x40 to 0x79.
+ *
+ * \sa drmCommandNone(), drmCommandRead(), drmCommandWrite(), and
+ * drmCommandReadWrite().
+ */
+#define DRM_COMMAND_BASE                0x40
+
+#endif /* _DRM_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/extras/drm/sunos-core/xf86drm-solaris.S	Tue Oct 24 18:42:11 2006 -0700
@@ -0,0 +1,75 @@
+/* Copyright 2006 Sun Microsystems, Inc.  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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+ * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */ 
+
+#pragma ident	"@(#)xf86drm-solaris.S	1.2	06/08/21 SMI"
+
+#if defined(lint) || defined(__lint)
+#include <sys/types.h>
+#else
+#include <sys/asm_linkage.h>
+#endif
+
+#if defined(lint) || defined(__lint)
+
+/*ARGSUSED*/
+int
+atomic_cmpset_int(volatile unsigned int *dst,
+		  unsigned int exp, unsigned int src)
+{
+	return (0);
+}
+
+#else	/* lint */
+
+#if defined(__amd64)
+
+	ENTRY(atomic_cmpset_int)
+	movl	%esi, %eax
+	lock
+	cmpxchgl	%edx, (%rdi)
+	sete	%al
+	movzbl	%al, %eax
+	ret
+	SET_SIZE(atomic_cmpset_int)
+
+#elif defined(__i386)
+
+	ENTRY(atomic_cmpset_int)
+	movl	0x4(%esp), %edx
+	movl	0x8(%esp), %eax
+	movl	0xc(%esp), %ecx
+	lock
+	cmpxchgl	%ecx, (%edx)
+	sete	%al
+	movzbl	%al, %eax
+	ret
+	SET_SIZE(atomic_cmpset_int)
+
+#endif	/* __i386 */
+
+#endif /* lint */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/lib/GL/mesa/drivers/dri/common/Imakefile.inc	Tue Oct 24 18:42:11 2006 -0700
@@ -0,0 +1,106 @@
+XCOMM $XFree86: xc/lib/GL/mesa/src/drv/common/Imakefile.inc,v 1.3 2003/05/27 16:34:32 tsi Exp $
+
+#ifndef MesaDrvSrcDir
+#define MesaDrvSrcDir $(MESASRCDIR)/src/mesa/drivers/dri
+#endif
+
+MESADRVSRCDIR = MesaDrvSrcDir
+
+#ifndef MesaDrvCommonBuildDir
+#define MesaDrvCommonBuildDir $(MESADRVSRCDIR)/common/
+#endif
+
+MESADRVCOMMONBUILDDIR = MesaDrvCommonBuildDir
+
+#if Malloc0ReturnsNull
+ALLOC_DEFINES = -DMALLOC_0_RETURNS_NULL
+#endif
+
+#if BuildXF86DRI
+ COMMON_DRI_DEFINES = GlxDefines -DX_BYTE_ORDER=$(X_BYTE_ORDER) -DIN_DRI_DRIVER
+ COMMON_DRI_INCLUDES = -I$(GLXLIBSRC)/dri \
+		-I$(XINCLUDESRC) \
+		-I$(GLXLIBSRC)/glx \
+		-I$(GLXLIBSRC)/include \
+		-I$(SERVERSRC)/GL/dri \
+		-I$(XF86OSSRC) \
+		-I$(XF86COMSRC) \
+		-I$(GLXLIBSRC)/dri/drm \
+		-I$(GLXLIBSRC)/include \
+		-I$(DRMSRCDIR)/shared-core \
+		-I$(DRMSRCDIR)/libdrm \
+                -I$(MESASRCDIR)/include/GL/internal
+#endif
+
+COMMON_MESA_INCLUDES = -I$(MESASRCDIR)/src/mesa \
+		-I$(MESASRCDIR)/src/mesa/main \
+		-I$(MESASRCDIR)/src/mesa/shader \
+		-I$(MESASRCDIR)/src/mesa/glapi \
+		-I$(MESADRVSRCDIR)/common \
+		-I$(MESADRVSRCDIR)/../common \
+		-I$(MESASRCDIR)/include
+   COMMON_X_INCLUDES = -I$(XINCLUDESRC) -I$(EXTINCSRC)
+
+    COMMONSRCS = $(MESADRVCOMMONBUILDDIR)utils.c \
+                 $(MESADRVCOMMONBUILDDIR)vblank.c \
+                 $(MESADRVCOMMONBUILDDIR)texmem.c \
+                 $(MESADRVCOMMONBUILDDIR)xmlconfig.c \
+                 $(MESADRVCOMMONBUILDDIR)driverfuncs.c \
+                 $(MESADRVCOMMONBUILDDIR)dri_util.c \
+                 $(MESADRVCOMMONBUILDDIR)glcontextmodes.c \
+                 $(MESADRVCOMMONBUILDDIR)drirenderbuffer.c
+
+    COMMONOBJS = $(MESADRVCOMMONBUILDDIR)utils.o \
+                 $(MESADRVCOMMONBUILDDIR)vblank.o \
+                 $(MESADRVCOMMONBUILDDIR)texmem.o \
+                 $(MESADRVCOMMONBUILDDIR)xmlconfig.o \
+                 $(MESADRVCOMMONBUILDDIR)driverfuncs.o \
+                 $(MESADRVCOMMONBUILDDIR)dri_util.o \
+                 $(MESADRVCOMMONBUILDDIR)glcontextmodes.o \
+                 $(MESADRVCOMMONBUILDDIR)drirenderbuffer.o
+
+    COMMONUOBJS = $(MESADRVCOMMONBUILDDIR)unshared/utils.o \
+                 $(MESADRVCOMMONBUILDDIR)unshared/vblank.o \
+                 $(MESADRVCOMMONBUILDDIR)unshared/texmem.o \
+                 $(MESADRVCOMMONBUILDDIR)unshared/xmlconfig.o \
+                 $(MESADRVCOMMONBUILDDIR)unshared/driverfuncs.o \
+                 $(MESADRVCOMMONBUILDDIR)unshared/dri_util.o \
+                 $(MESADRVCOMMONBUILDDIR)unshared/glcontextmodes.o \
+                 $(MESADRVCOMMONBUILDDIR)unshared/drirenderbuffer.o
+
+    COMMONDOBJS = $(MESADRVCOMMONBUILDDIR)debugger/utils.o \
+                 $(MESADRVCOMMONBUILDDIR)debugger/vblank.o \
+                 $(MESADRVCOMMONBUILDDIR)debugger/texmem.o \
+                 $(MESADRVCOMMONBUILDDIR)debugger/xmlconfig.o \
+                 $(MESADRVCOMMONBUILDDIR)debugger/driverfuncs.o \
+                 $(MESADRVCOMMONBUILDDIR)debugger/dri_util.o \
+                 $(MESADRVCOMMONBUILDDIR)debugger/glcontextmodes.o \
+                 $(MESADRVCOMMONBUILDDIR)debugger/drirenderbuffer.o
+
+    COMMONPOBJS = $(MESADRVCOMMONBUILDDIR)profiled/utils.o \
+                 $(MESADRVCOMMONBUILDDIR)profiled/vblank.o \
+                 $(MESADRVCOMMONBUILDDIR)profiled/texmem.o \
+                 $(MESADRVCOMMONBUILDDIR)profiled/xmlconfig.o \
+                 $(MESADRVCOMMONBUILDDIR)profiled/driverfuncs.o \
+                 $(MESADRVCOMMONBUILDDIR)profiled/dri_util.o \
+                 $(MESADRVCOMMONBUILDDIR)profiled/glcontextmodes.o \
+                 $(MESADRVCOMMONBUILDDIR)profiled/drirenderbuffer.o
+
+#ifdef NeedToLinkMesaSrc
+LinkSourceFile(texmem.c, $(MESADRVSRCDIR)/common)
+LinkSourceFile(texmem.h, $(MESADRVSRCDIR)/common)
+LinkSourceFile(utils.c, $(MESADRVSRCDIR)/common)
+LinkSourceFile(utils.h, $(MESADRVSRCDIR)/common)
+LinkSourceFile(vblank.c, $(MESADRVSRCDIR)/common)
+LinkSourceFile(vblank.h, $(MESADRVSRCDIR)/common)
+LinkSourceFile(xmlconfig.c, $(MESADRVSRCDIR)/common)
+LinkSourceFile(xmlconfig.h, $(MESADRVSRCDIR)/common)
+LinkSourceFile(driverfuncs.c, $(MESADRVSRCDIR)/../common)
+LinkSourceFile(driverfuncs.h, $(MESADRVSRCDIR)/../common)
+LinkSourceFile(dri_util.c, $(MESADRVSRCDIR)/common)
+LinkSourceFile(dri_util.h, $(MESADRVSRCDIR)/common)
+LinkSourceFile(glcontextmodes.c, $(MESADRVSRCDIR)/common)
+LinkSourceFile(glcontextmodes.h, $(MESADRVSRCDIR)/common)
+LinkSourceFile(drirenderbuffer.c, $(MESADRVSRCDIR)/common)
+LinkSourceFile(drirenderbuffer.h, $(MESADRVSRCDIR)/common)
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/lib/GL/mesa/drivers/dri/i915/Imakefile	Tue Oct 24 18:42:11 2006 -0700
@@ -0,0 +1,82 @@
+#include <Threads.tmpl>
+
+#if GlxUseBuiltInDRIDriver
+#define DoNormalLib (NormalLibGlx || SharedLibGlxWithoutPIC)
+#define DoSharedLib (SharedLibGlx && !SharedLibGlxWithoutPIC)
+#define DoExtraLib SharedLibGlx
+#define DoDebugLib DebugLibGlx
+#define DoProfileLib ProfileLibGlx
+#else
+#define DoNormalLib SharedLibGlxWithoutPIC
+#define DoSharedLib !SharedLibGlxWithoutPIC
+#define DoExtrasLib NO
+#define DoDebugLib NO
+#define DoProfileLib NO
+#endif
+
+#define MesaDrvCommonBuildDir ../common/
+#include "../common/Imakefile.inc"
+#include "../../../array_cache/Imakefile.inc"
+#include "../../../main/Imakefile.inc"
+#include "../../../math/Imakefile.inc"
+#include "../../../shader/Imakefile.inc"
+#include "../../../shader/grammar/Imakefile.inc"
+#include "../../../shader/slang/Imakefile.inc"
+#include "../../../shader/slang/library/Imakefile.inc"
+#include "../../../swrast/Imakefile.inc"
+#include "../../../swrast_setup/Imakefile.inc"
+#include "../../../tnl/Imakefile.inc"
+#include "../../../tnl_dd/Imakefile.inc"
+#include "../../../Imakefile.inc"
+#if defined(i386Architecture) && MesaUseX86Asm
+#include "../../../x86/Imakefile.inc"
+#endif
+#define NeedToLinkMesaSrc
+#include "Imakefile.inc"
+
+ASM_SOLARIS_SRC = xf86drm-solaris.S
+ASM_SOLARIS_OBJ = xf86drm-solaris.o
+
+$(ASM_SOLARIS_OBJ): $(ASM_SOLARIS_SRC)
+	$(AS) DefaultXArchOptions -P -D_ASM -o $@  $(ASM_SOLARIS_SRC)
+
+      DEFINES = $(ALLOC_DEFINES) $(DRI_DEFINES) $(MESA_ASM_DEFINES)
+
+     INCLUDES = $(X_INCLUDES) $(MESA_INCLUDES) $(COMMON_DRI_INCLUDES) $(DRI_INCLUDES) $(EXPATINCLUDES)
+
+      DRMOBJS = $(GLXLIBSRC)/dri/drm/xf86drm.o \
+		$(GLXLIBSRC)/dri/drm/xf86drmHash.o \
+		$(GLXLIBSRC)/dri/drm/xf86drmRandom.o \
+		$(ASM_SOLARIS_OBJ) \
+		$(GLXLIBSRC)/dri/drm/xf86drmSL.o
+
+         SRCS = $(I915SRCS)
+         OBJS = $(DRMOBJS) $(COREMESAOBJS) \
+		$(MESA_ASM_OBJS) $(COMMONOBJS) $(I915OBJS)
+
+REQUIREDLIBS = MathLibrary $(LDPRELIB) $(LDLIBS) $(GLXLIB) $(XONLYLIB) $(EXPATLIB) -lrt -pthread
+
+DRMASM_DIR = $(TOP)/extras/drm/sunos-core
+LinkSourceFile($(ASM_SOLARIS_SRC),$(DRMASM_DIR))
+
+#include <Library.tmpl>
+
+LibraryObjectRule()
+
+SubdirLibraryRule($(I915OBJS))
+NormalLintTarget($(SRCS))
+
+#if !GlxUseBuiltInDRIDriver
+LIBNAME = i915_dri.so
+SharedDriModuleTarget($(LIBNAME),DONE $(OBJS),$(OBJS))
+InstallDynamicModule($(LIBNAME),$(MODULEDIR),dri)
+
+#ifdef GlxSoProf
+SOPROF_LIBNAME = _i915_dri_p
+NormalDepLibraryTarget($(SOPROF_LIBNAME),DONE $(OBJS),$(OBJS))
+InstallLibrary($(SOPROF_LIBNAME),$(MODULEDIR)/dri)
+#endif
+#endif
+
+DependTarget()
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/programs/Xserver/hw/xfree86/drivers/i810/i830.h	Tue Oct 24 18:42:11 2006 -0700
@@ -0,0 +1,487 @@
+
+/**************************************************************************
+
+Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+Copyright © 2002 David Dawes
+
+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, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/i810/i830.h,v 1.12 2004/01/07 03:43:19 dawes Exp $ */
+
+/*
+ * Authors:
+ *   Keith Whitwell <[email protected]>
+ *   David Dawes <[email protected]>
+ *
+ */
+
+#if 0
+#define I830DEBUG
+#endif
+
+#ifndef REMAP_RESERVED
+#define REMAP_RESERVED 0
+#endif
+
+#ifndef _I830_H_
+#define _I830_H_
+
+#include "xf86_ansic.h"
+#include "compiler.h"
+#include "xf86PciInfo.h"
+#include "xf86Pci.h"
+#include "i810_reg.h"
+#include "xaa.h"
+#include "xf86Cursor.h"
+#include "xf86xv.h"
+#include "xf86int10.h"
+#include "vbe.h"
+#include "vgaHW.h"
+
+#ifdef XF86DRI
+#include "xf86drm.h"
+#include "sarea.h"
+#define _XF86DRI_SERVER_
+#include "dri.h"
+#include "GL/glxint.h"
+#include "i830_dri.h"
+#endif
+
+#include "common.h"
+
+/* I830 Video BIOS support */
+
+/*
+ * The mode handling is based upon the VESA driver written by
+ * Paulo César Pereira de Andrade <[email protected]>.
+ */
+
+#define PIPE_NONE	0<<0
+#define PIPE_CRT	1<<0
+#define PIPE_TV		1<<1
+#define PIPE_DFP	1<<2
+#define PIPE_LFP	1<<3
+#define PIPE_CRT2	1<<4
+#define PIPE_TV2	1<<5
+#define PIPE_DFP2	1<<6
+#define PIPE_LFP2	1<<7
+
+typedef struct _VESARec {
+   /* SVGA state */
+   pointer state, pstate;
+   int statePage, stateSize, stateMode, stateRefresh;
+   CARD32 *savedPal;
+   int savedScanlinePitch;
+   xf86MonPtr monitor;
+   /* Don't try to set the refresh rate for any modes. */
+   Bool useDefaultRefresh;
+   /* display start */
+   int x, y;
+} VESARec, *VESAPtr;
+
+
+typedef struct _I830Rec *I830Ptr;
+
+typedef void (*I830WriteIndexedByteFunc)(I830Ptr pI830, IOADDRESS addr,
+                                         CARD8 index, CARD8 value);
+typedef CARD8(*I830ReadIndexedByteFunc)(I830Ptr pI830, IOADDRESS addr,
+                                        CARD8 index);
+typedef void (*I830WriteByteFunc)(I830Ptr pI830, IOADDRESS addr, CARD8 value);
+typedef CARD8(*I830ReadByteFunc)(I830Ptr pI830, IOADDRESS addr);
+
+/* Linear region allocated in framebuffer. */
+typedef struct _I830MemPool *I830MemPoolPtr;
+typedef struct _I830MemRange *I830MemRangePtr;
+typedef struct _I830MemRange {
+   long Start;
+   long End;
+   long Size;
+   unsigned long Physical;
+   unsigned long Offset;		/* Offset of AGP-allocated portion */
+   unsigned long Alignment;
+   int Key;
+   I830MemPoolPtr Pool;
+} I830MemRange;
+
+typedef struct _I830MemPool {
+   I830MemRange Total;
+   I830MemRange Free;
+   I830MemRange Fixed;
+   I830MemRange Allocated;
+} I830MemPool;
+
+typedef struct {
+   int tail_mask;
+   I830MemRange mem;
+   unsigned char *virtual_start;
+   int head;
+   int tail;
+   int space;
+} I830RingBuffer;
+
+typedef struct {
+   unsigned int Fence[8];
+} I830RegRec, *I830RegPtr;
+
+typedef struct {
+   int            lastInstance;
+   int            refCount;
+   ScrnInfoPtr    pScrn_1;
+   ScrnInfoPtr    pScrn_2;
+   int            RingRunning;
+#ifdef I830_XV
+   int            XvInUse;
+#endif
+} I830EntRec, *I830EntPtr;
+
+typedef struct _I830Rec {
+   unsigned char *MMIOBase;
+   unsigned char *FbBase;
+   int cpp;
+
+   unsigned int bios_version;
+
+   Bool newPipeSwitch;
+
+   Bool fakeSwitch;
+   
+   int fixedPipe;
+
+   Bool Clone;
+   int CloneRefresh;
+   int CloneHDisplay;
+   int CloneVDisplay;
+
+   I830EntPtr entityPrivate;	
+   int pipe, origPipe;
+   int init;
+
+   unsigned int bufferOffset;		/* for I830SelectBuffer */
+   BoxRec FbMemBox;
+   BoxRec FbMemBox2;
+   int CacheLines;
+
+   /* These are set in PreInit and never changed. */
+   long FbMapSize;
+   long TotalVideoRam;
+   I830MemRange StolenMemory;		/* pre-allocated memory */
+   long BIOSMemorySize;			/* min stolen pool size */
+   int BIOSMemSizeLoc;
+
+   /* These change according to what has been allocated. */
+   long FreeMemory;
+   I830MemRange MemoryAperture;
+   I830MemPool StolenPool;
+   long allocatedMemory;
+
+   /* Regions allocated either from the above pools, or from agpgart. */
+   /* for single and dual head configurations */
+   I830MemRange FrontBuffer;
+   I830MemRange FrontBuffer2;
+   I830MemRange Scratch;
+   I830MemRange Scratch2;
+
+   /* Regions allocated either from the above pools, or from agpgart. */
+   I830MemRange	*CursorMem;
+   I830MemRange	*CursorMemARGB;
+   I830RingBuffer *LpRing;
+
+#if REMAP_RESERVED
+   I830MemRange Dummy;
+#endif
+
+#ifdef I830_XV
+   /* For Xvideo */
+   I830MemRange *OverlayMem;
+#endif
+
+#ifdef XF86DRI
+   I830MemRange BackBuffer;
+   I830MemRange DepthBuffer;
+   I830MemRange TexMem;
+   I830MemRange ContextMem;
+   int TexGranularity;
+   int drmMinor;
+   Bool have3DWindows;
+#endif
+
+   Bool NeedRingBufferLow;
+   Bool allowPageFlip;
+   Bool disableTiling;
+
+   int backPitch;
+
+   Bool CursorNeedsPhysical;
+   Bool CursorIsARGB;
+
+   int MonType1;
+   int MonType2;
+   Bool specifiedMonitor;
+
+   DGAModePtr DGAModes;
+   int numDGAModes;
+   Bool DGAactive;
+   int DGAViewportStatus;
+
+   int Chipset;
+   unsigned long LinearAddr;
+   unsigned long MMIOAddr;
+   IOADDRESS ioBase;
+   EntityInfoPtr pEnt;
+   pciVideoPtr PciInfo;
+   PCITAG PciTag;
+   CARD8 variant;
+
+   unsigned int BR[20];
+
+   int GttBound;
+
+   unsigned char **ScanlineColorExpandBuffers;
+   int NumScanlineColorExpandBuffers;
+   int nextColorExpandBuf;
+
+   I830RegRec SavedReg;
+   I830RegRec ModeReg;
+
+   Bool noAccel;
+   Bool SWCursor;
+   Bool cursorOn;
+   XAAInfoRecPtr AccelInfoRec;
+   xf86CursorInfoPtr CursorInfoRec;
+   CloseScreenProcPtr CloseScreen;
+
+   I830WriteIndexedByteFunc writeControl;
+   I830ReadIndexedByteFunc readControl;
+   I830WriteByteFunc writeStandard;
+   I830ReadByteFunc readStandard;
+
+   Bool XvDisabled;			/* Xv disabled in PreInit. */
+   Bool XvEnabled;			/* Xv enabled for this generation. */
+
+#ifdef I830_XV
+   int colorKey;
+   XF86VideoAdaptorPtr adaptor;
+   ScreenBlockHandlerProcPtr BlockHandler;
+   Bool *overlayOn;
+#endif
+
+   Bool directRenderingDisabled;	/* DRI disabled in PreInit. */
+   Bool directRenderingEnabled;		/* DRI enabled this generation. */
+
+#ifdef XF86DRI
+   Bool directRenderingOpen;
+   int LockHeld;
+   DRIInfoPtr pDRIInfo;
+   int drmSubFD;
+   int numVisualConfigs;
+   __GLXvisualConfig *pVisualConfigs;
+   I830ConfigPrivPtr pVisualConfigsPriv;
+   drm_handle_t buffer_map;
+   drm_handle_t ring_map;
+#endif
+
+   /* Broken-out options. */
+   OptionInfoPtr Options;
+   int rotate;
+   Bool shadowFB;
+
+   /* Support for shadowFB and rotation. */
+   unsigned char *shadowPtr;
+   int shadowPitch;
+   void (*PointerMoved)(int, int, int);
+
+   /* Stolen memory support */
+   Bool StolenOnly;
+
+   /* Video BIOS support. */
+   vbeInfoPtr pVbe;
+   VbeInfoBlock *vbeInfo;
+   VESAPtr vesa;
+
+   Bool overrideBIOSMemSize;
+   int saveBIOSMemSize;
+   int newBIOSMemSize;
+   Bool useSWF1;
+   int saveSWF1;
+
+   Bool swfSaved;
+   CARD32 saveSWF0;
+   CARD32 saveSWF4;
+
+   /* Use BIOS call 0x5f05 to set the refresh rate. */
+   Bool useExtendedRefresh;
+
+   Bool checkDevices;
+   int monitorSwitch;
+   int operatingDevices;
+   int savedDevices;
+   int lastDevice1, lastDevice2;
+
+   /* These are indexed by the display types */
+   Bool displayAttached[NumDisplayTypes];
+   Bool displayPresent[NumDisplayTypes];
+   BoxRec displaySize[NumDisplayTypes];
+
+   /* [0] is Pipe A, [1] is Pipe B. */
+   int availablePipes;
+   int pipeDevices[MAX_DISPLAY_PIPES];
+   /* [0] is display plane A, [1] is display plane B. */
+   Bool pipeEnabled[MAX_DISPLAY_PIPES];
+   BoxRec pipeDisplaySize[MAX_DISPLAY_PIPES];
+   int planeEnabled[MAX_DISPLAY_PIPES];
+
+   /* Driver phase/state information */
+   Bool preinit;
+   Bool starting;
+   Bool closing;
+   Bool suspended;
+   Bool leaving;
+
+   /* fbOffset converted to (x, y). */
+   int xoffset;
+   int yoffset;
+
+   unsigned int SaveGeneration;
+   Bool vbeRestoreWorkaround;
+   Bool displayInfo;
+   Bool devicePresence;
+
+   OsTimerPtr devicesTimer;
+} I830Rec;
+
+#define I830PTR(p) ((I830Ptr)((p)->driverPrivate))
+#define I830REGPTR(p) (&(I830PTR(p)->ModeReg))
+
+#define I830_SELECT_FRONT	0
+#define I830_SELECT_BACK	1
+#define I830_SELECT_DEPTH	2
+
+/* I830 specific functions */
+extern int I830WaitLpRing(ScrnInfoPtr pScrn, int n, int timeout_millis);
+extern void I830SetPIOAccess(I830Ptr pI830);
+extern void I830SetMMIOAccess(I830Ptr pI830);
+extern void I830PrintErrorState(ScrnInfoPtr pScrn);
+extern void I830Sync(ScrnInfoPtr pScrn);
+extern void I830InitHWCursor(ScrnInfoPtr pScrn);
+extern Bool I830CursorInit(ScreenPtr pScreen);
+extern void I830EmitInvarientState(ScrnInfoPtr pScrn);
+extern void I830SelectBuffer(ScrnInfoPtr pScrn, int buffer);
+
+extern void I830RefreshRing(ScrnInfoPtr pScrn);
+extern void I830EmitFlush(ScrnInfoPtr pScrn);
+
+extern Bool I830DGAInit(ScreenPtr pScreen);
+
+#ifdef I830_XV
+extern void I830InitVideo(ScreenPtr pScreen);
+extern void I830VideoSwitchModeBefore(ScrnInfoPtr pScrn, DisplayModePtr mode);
+extern void I830VideoSwitchModeAfter(ScrnInfoPtr pScrn, DisplayModePtr mode);
+#endif
+
+#ifdef XF86DRI
+extern Bool I830Allocate3DMemory(ScrnInfoPtr pScrn, const int flags);
+extern void I830SetupMemoryTiling(ScrnInfoPtr pScrn);
+extern Bool I830DRIScreenInit(ScreenPtr pScreen);
+extern Bool I830DRIDoMappings(ScreenPtr pScreen);
+extern Bool I830DRIResume(ScreenPtr pScreen);
+extern void I830DRICloseScreen(ScreenPtr pScreen);
+extern Bool I830DRIFinishScreenInit(ScreenPtr pScreen);
+#endif
+extern Bool I830AccelInit(ScreenPtr pScreen);
+extern void I830SetupForScreenToScreenCopy(ScrnInfoPtr pScrn, int xdir,
+					   int ydir, int rop,
+					   unsigned int planemask,
+					   int trans_color);
+extern void I830SubsequentScreenToScreenCopy(ScrnInfoPtr pScrn, int srcX,
+					     int srcY, int dstX, int dstY,
+					     int w, int h);
+extern void I830SetupForSolidFill(ScrnInfoPtr pScrn, int color, int rop,
+				  unsigned int planemask);
+extern void I830SubsequentSolidFillRect(ScrnInfoPtr pScrn, int x, int y,
+					int w, int h);
+
+extern void I830ResetAllocations(ScrnInfoPtr pScrn, const int flags);
+extern long I830CheckAvailableMemory(ScrnInfoPtr pScrn);
+extern long I830GetExcessMemoryAllocations(ScrnInfoPtr pScrn);
+extern Bool I830Allocate2DMemory(ScrnInfoPtr pScrn, const int flags);
+extern Bool I830DoPoolAllocation(ScrnInfoPtr pScrn, I830MemPool *pool);
+extern Bool I830FixupOffsets(ScrnInfoPtr pScrn);
+extern Bool I830BindGARTMemory(ScrnInfoPtr pScrn);
+extern Bool I830UnbindGARTMemory(ScrnInfoPtr pScrn);
+extern unsigned long I830AllocVidMem(ScrnInfoPtr pScrn, I830MemRange *result,
+				     I830MemPool *pool, long size,
+				     unsigned long alignment, int flags);
+
+extern void I830PrintAllRegisters(I830RegPtr i830Reg);
+extern void I830ReadAllRegisters(I830Ptr pI830, I830RegPtr i830Reg);
+
+extern void I830ChangeFrontbuffer(ScrnInfoPtr pScrn,int buffer);
+
+extern DisplayModePtr I830GetModePool(ScrnInfoPtr pScrn, vbeInfoPtr pVbe,
+					VbeInfoBlock *vbe);
+extern void I830SetModeParameters(ScrnInfoPtr pScrn, vbeInfoPtr pVbe);
+extern void I830UnsetModeParameters(ScrnInfoPtr pScrn, vbeInfoPtr pVbe);
+extern void I830PrintModes(ScrnInfoPtr pScrn);
+extern int I830GetBestRefresh(ScrnInfoPtr pScrn, int refresh);
+extern Bool I830CheckModeSupport(ScrnInfoPtr pScrn, int x, int y, int mode);
+extern void I830PointerMoved(int index, int x, int y);
+extern void I830RefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
+extern void I830RefreshArea8(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
+extern void I830RefreshArea16(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
+extern void I830RefreshArea24(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
+extern void I830RefreshArea32(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
+
+/*
+ * 12288 is set as the maximum, chosen because it is enough for
+ * 1920x1440@32bpp with a 2048 pixel line pitch with some to spare.
+ */
+#define I830_MAXIMUM_VBIOS_MEM		12288
+#define I830_DEFAULT_VIDEOMEM_2D	(MB(32) / 1024)
+#define I830_DEFAULT_VIDEOMEM_3D	(MB(64) / 1024)
+
+/* Flags for memory allocation function */
+#define FROM_ANYWHERE			0x00000000
+#define FROM_POOL_ONLY			0x00000001
+#define FROM_NEW_ONLY			0x00000002
+#define FROM_MASK			0x0000000f
+
+#define ALLOCATE_AT_TOP			0x00000010
+#define ALLOCATE_AT_BOTTOM		0x00000020
+#define FORCE_GAPS			0x00000040
+
+#define NEED_PHYSICAL_ADDR		0x00000100
+#define ALIGN_BOTH_ENDS			0x00000200
+#define FORCE_LOW			0x00000400
+
+#define ALLOC_NO_TILING			0x00001000
+#define ALLOC_INITIAL			0x00002000
+
+#define ALLOCATE_DRY_RUN		0x80000000
+
+/* Chipset registers for VIDEO BIOS memory RW access */
+#define _855_DRAM_RW_CONTROL 0x58
+#define _845_DRAM_RW_CONTROL 0x90
+#define DRAM_WRITE    0x33330000
+
+#endif /* _I830_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/programs/Xserver/hw/xfree86/drivers/via/via_drmclient.h	Tue Oct 24 18:42:11 2006 -0700
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2005 The Unichrome Project, 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, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) 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.
+ */
+
+#ifndef _VIA_DRMCLIENT_H
+#define _VIA_DRMCLIENT_H
+
+#include "drm.h"
+#include "xf86drm.h"
+
+#ifdef LONG64
+typedef CARD32 uint32_t;
+#endif
+
+#define UNICHROME_LOCK(fd, lockNo, saPriv, context, lastcontext, ret)	\
+    do {								\
+	volatile drm_hw_lock_t *lockPtr = XVMCLOCKPTR((saPriv), (lockNo));	\
+	unsigned lockVal;						\
+        DRM_CAS_RESULT(__ret);						\
+									\
+	ret = 0;							\
+	lockVal = lockPtr->lock & ~(DRM_LOCK_HELD | DRM_LOCK_CONT);	\
+	DRM_CAS(lockPtr, lockVal, (context) | DRM_LOCK_HELD, __ret);	\
+	if (__ret) {							\
+	    drm_via_futex_t fx;						\
+									\
+            lockVal = lockPtr->lock;					\
+	    if (! (lockVal & DRM_LOCK_HELD)) continue;			\
+	    if ((lockVal & ~(DRM_LOCK_HELD | DRM_LOCK_CONT) )		\
+		== (context)) {						\
+	      lastcontext = lockVal & ~(DRM_LOCK_HELD | DRM_LOCK_CONT);	\
+		break;							\
+	    }								\
+	    fx.val = lockVal | DRM_LOCK_CONT;				\
+	    DRM_CAS( lockPtr, lockVal, fx.val, __ret);			\
+	    lockVal = lockPtr->lock;					\
+	    if (__ret) continue;					\
+	    fx.func = VIA_FUTEX_WAIT;					\
+	    fx.lock = (lockNo);						\
+	    fx.ms = 10;							\
+	    ret = drmCommandWrite((fd), DRM_VIA_DEC_FUTEX,		\
+				  &fx,sizeof(fx));			\
+	    lastcontext = lockVal;					\
+	    if (ret) break;						\
+	    continue;							\
+	} else {							\
+	    lastcontext = lockVal;					\
+	    break;							\
+	}								\
+    } while (1)								\
+    
+#define UNICHROME_UNLOCK(fd, lockNo, saPriv, context)			\
+    do {								\
+      	volatile drm_hw_lock_t *lockPtr = XVMCLOCKPTR((saPriv), (lockNo)); 	\
+									\
+	if ((lockPtr->lock & ~DRM_LOCK_CONT) ==				\
+	    ((context) | DRM_LOCK_HELD)) {				\
+	    DRM_CAS_RESULT(__ret);					\
+	    DRM_CAS(lockPtr,(context) | DRM_LOCK_HELD, context, __ret); \
+	    if (__ret) {						\
+		drm_via_futex_t fx;					\
+		fx.func = VIA_FUTEX_WAKE;				\
+		fx.lock = lockNo;					\
+		DRM_CAS(lockPtr, (context) | DRM_LOCK_HELD |		\
+			DRM_LOCK_CONT,					\
+			context, __ret);				\
+		drmCommandWrite((fd), DRM_VIA_DEC_FUTEX, &fx,		\
+				sizeof(fx));				\
+	    }								\
+	    }								\
+    } while (0)								\
+
+#define UNICHROME_LOCK_DECODER1 0
+#define UNICHROME_LOCK_DECODER2 1
+#define UNICHROME_LOCK_HQV      4
+      
+#endif
--- a/XORG_NV/sun-src/xc/programs/Xserver/hw/xfree86/os-support/sunos/Imakefile	Tue Oct 24 16:13:31 2006 -0700
+++ b/XORG_NV/sun-src/xc/programs/Xserver/hw/xfree86/os-support/sunos/Imakefile	Tue Oct 24 18:42:11 2006 -0700
@@ -32,7 +32,7 @@
 
 #include <Server.tmpl>
 
-#if !HasGcc 
+#if !HasGcc
 # if HasSunC
 #  if !defined(AsmArch) || !defined(AsmFlags)
 #   error "Unsupported Architecture for building Xorg server with Sun compilers."
@@ -92,16 +92,19 @@
 SYSVIPCDEFINES = -DHAVE_SYSV_IPC
 #endif
 
+DRI_SRC = sigiostubs.c
+DRI_OBJ = sigiostubs.o
+
 SRCS = sun_bios.c sun_init.c $(IO_SRC) $(KBD_SRCS) $(PROWORKS_INOUT_SRC) \
        sun_mouse.c sun_vid.c $(AGP_SRC) libc_wrapper.c kmod_noop.c sun_apm.c \
-       posix_tty.c sigiostubs.c stdPci.c stdResource.c $(VTSW_SRC)
+       posix_tty.c sigiostubs.c stdPci.c stdResource.c $(VTSW_SRC) $(DRI_SRC)
 OBJS = sun_bios.o sun_init.o $(IO_OBJ) $(KBD_OBJS) $(PROWORKS_INOUT_OBJ) \
        sun_mouse.o sun_vid.o $(AGP_OBJ) libc_wrapper.o kmod_noop.o sun_apm.o \
-       posix_tty.o sigiostubs.o stdPci.o stdResource.o $(VTSW_OBJ)
+       posix_tty.o sigiostubs.o stdPci.o stdResource.o $(VTSW_OBJ) $(DRI_OBJ)
 
 INCLUDES = -I. -I$(XF86OSSRC) -I$(XF86COMSRC) \
 	   -I$(SERVERSRC)/mi -I$(SERVERSRC)/include -I$(SERVERSRC)/Xext \
-	   -I$(XINCLUDESRC) -I$(EXTINCSRC)
+	   -I$(XINCLUDESRC) -I$(EXTINCSRC) -I$(DRMSRCDIR)/shared-core
 
 DEFINES = -DUSESTDRES $(VENDOR_DEFINES) $(SYSVIPCDEFINES)
 
@@ -109,6 +112,19 @@
 NormalLibraryObjectRule()
 NormalAsmObjectRule()
 
+#if BuildXF86DRI
+DRISUBDIR = drm
+#endif
+
+#if XF86INT10_BUILD > X86EMU_GENERIC
+INT10SUBDIR = int10
+#endif
+
+#if BuildXF86DRI || (XF86INT10_BUILD > X86EMU_GENERIC)
+#define IHaveSubdirs
+SUBDIRS = $(DRISUBDIR) $(INT10SUBDIR)
+#endif
+
 LinkSourceFile($(VTSW_SRC),../shared)
 LinkSourceFile(agp_noop.c,../shared)
 LinkSourceFile(libc_wrapper.c,../shared)
@@ -122,5 +138,7 @@
 LinkSourceFile(sysv_io.c,../sysv)
 LinkSourceFile(sysv_kbd.c,../shared)
 
+LinkSourceFile($(DRI_SRC),../shared)
+
 DependTarget()
 LintTarget()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/programs/Xserver/hw/xfree86/os-support/sunos/agpgart.h	Tue Oct 24 18:42:11 2006 -0700
@@ -0,0 +1,155 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/sunos/agpgart.h,v 1.2 2005/07/01 22:43:25 daniels Exp $ */
+/*
+ * AGPGART module version 0.99
+ * Copyright (C) 1999 Jeff Hartmann
+ * Copyright (C) 1999 Precision Insight, Inc.
+ * Copyright (C) 1999 Xi Graphics, Inc.
+ *
+ * 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 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
+ * JEFF HARTMANN, OR ANY OTHER CONTRIBUTORS 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.
+ */
+/*
+ * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+ * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#ifndef	_AGPGART_H
+#define	_AGPGART_H
+
+#pragma ident	"@(#)agpgart.h	1.2	06/10/25 SMI"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define	AGP_NORMAL	0	/* mapped to user land, no cache */
+
+typedef struct _agp_version {
+	uint16_t	agpv_major;
+	uint16_t	agpv_minor;
+} agp_version_t;
+
+typedef struct	_agp_info {
+	agp_version_t	agpi_version;
+	uint32_t	agpi_devid;	/* bridge vendor + device */
+	uint32_t	agpi_mode;	/* mode of bridge */
+	ulong_t		agpi_aperbase;	/* base of aperture */
+	size_t		agpi_apersize;	/* aperture range size */
+	uint32_t	agpi_pgtotal;	/* max number of pages in aperture */
+	uint32_t	agpi_pgsystem;	/* same as pg_total */
+	uint32_t	agpi_pgused;	/* NUMBER of currently used pages */
+} agp_info_t;
+
+typedef struct _agp_setup {
+	uint32_t	agps_mode;
+} agp_setup_t;
+
+typedef struct _agp_allocate {
+	int32_t		agpa_key;
+	uint32_t	agpa_pgcount;
+	uint32_t	agpa_type;
+	uint32_t	agpa_physical;	/* for i810 only, private */
+} agp_allocate_t;
+
+typedef struct _agp_bind {
+	int32_t		agpb_key;
+	uint32_t	agpb_pgstart;
+} agp_bind_t;
+
+typedef struct _agp_unbind {
+	int32_t		agpu_key;
+	uint32_t	agpu_pri;	/* no use in solaris */
+} agp_unbind_t;
+
+#define	AGPIOC_BASE		'G'
+#define	AGPIOC_INFO		_IOR(AGPIOC_BASE, 0, 100)
+#define	AGPIOC_ACQUIRE		_IO(AGPIOC_BASE, 1)
+#define	AGPIOC_RELEASE		_IO(AGPIOC_BASE, 2)
+#define	AGPIOC_SETUP		_IOW(AGPIOC_BASE, 3, agp_setup_t)
+#define	AGPIOC_ALLOCATE		_IOWR(AGPIOC_BASE, 4, agp_allocate_t)
+#define	AGPIOC_DEALLOCATE	_IOW(AGPIOC_BASE, 5, int)
+#define	AGPIOC_BIND		_IOW(AGPIOC_BASE, 6, agp_bind_t)
+#define	AGPIOC_UNBIND		_IOW(AGPIOC_BASE, 7, agp_unbind_t)
+#define	AGPIOC_IOREMAP		_IO(AGPIOC_BASE, 8)
+#define	AGPIOC_IOREMAP_FREE	_IO(AGPIOC_BASE, 9)
+#define	AGPIOC_READ		_IO(AGPIOC_BASE, 10)
+#define	AGPIOC_WRITE		_IO(AGPIOC_BASE, 11)
+
+/* AGP status register bits definition */
+#define	AGPSTAT_RQ_MASK		0xff000000	/* target only */
+#define	AGPSTAT_SBA		(0x1 << 9)	/* always 1 for 3.0 */
+#define	AGPSTAT_OVER4G		(0x1 << 5)
+#define	AGPSTAT_FW		(0x1 << 4)
+#define	AGPSTAT_RATE_MASK	0x7
+/* rate for 2.0 mode */
+#define	AGP2_RATE_1X		0x1
+#define	AGP2_RATE_2X		0x2
+#define	AGP2_RATE_4X		0x4
+/* AGP 3.0 only bits */
+#define	AGPSTAT_ARQSZ_MASK	(0x7 << 13)	/* target only */
+#define	AGPSTAT_CAL_MASK	(0x7 << 10)
+#define	AGPSTAT_GART64B		(0x1 << 7)	/* target only */
+#define	AGPSTAT_MODE3		(0x1 << 3)
+/* Rate for 3.0 mode */
+#define	AGP3_RATE_4X		0x1
+#define	AGP3_RATE_8X		0x2
+
+/* AGP command register bits definition */
+#define	AGPCMD_RQ_MASK		0xff000000	/* master only */
+#define	AGPCMD_SBAEN		(0x1 << 9)	/* must be 1 for 3.0 */
+#define	AGPCMD_AGPEN		(0x1 << 8)
+#define	AGPCMD_OVER4GEN		(0x1 << 5)
+#define	AGPCMD_FWEN		(0x1 << 4)
+#define	AGPCMD_RATE_MASK	0x7
+/* AGP 3.0 only bits */
+#define	AGP3_CMD_ARQSZ_MASK	(0x7 << 13)	/* master only */
+#define	AGP3_CMD_CAL_MASK	(0x7 << 10)	/* target only */
+#define	AGP3_CMD_GART64BEN	(0x1 << 7)	/* target only */
+
+#define	AGP_DEVICE	"/dev/agpgart"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _AGPGART_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/programs/Xserver/hw/xfree86/os-support/sunos/drm/Imakefile	Tue Oct 24 18:42:11 2006 -0700
@@ -0,0 +1,69 @@
+XCOMM $XFree86: Imakefile,v 1.13 2002/10/30 12:52:32 alanh Exp $
+
+#define IHaveModules
+#include <Server.tmpl>
+
+#if DoLoadableServer
+MSRC = drmmodule.c
+MOBJ = drmmodule.o
+#endif
+ASM_SOLARIS_SRC = xf86drm-solaris.S
+ASM_SOLARIS_OBJ = xf86drm-solaris.o
+
+$(ASM_SOLARIS_OBJ): $(ASM_SOLARIS_SRC)
+	$(AS) DefaultXArchOptions -P -D_ASM -o $@  $(ASM_SOLARIS_SRC)
+
+#if BuildXF86DRI
+#if HasMTRRSupport
+MTRR_DEFINES = -DHAS_MTRR_SUPPORT
+#endif
+
+OS_SUBDIR = extensions
+ SRCS = xf86drm.c \
+	xf86drmHash.c \
+	xf86drmRandom.c \
+	xf86drmSL.c \
+	$(MSRC)
+
+ OBJS = xf86drm.o \
+	xf86drmHash.o \
+	xf86drmRandom.o \
+	xf86drmSL.o \
+	$(ASM_SOLARIS_OBJ) \
+	$(MOBJ)
+
+INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \
+           -I$(XINCLUDESRC) -I$(EXTINCSRC) -I../.. -I$(DRMSRCDIR)/sunos-core \
+	   -I$(DRMSRCDIR)/shared-core
+
+DEFINES = $(MTRR_DEFINES) $(GLX_DEFINES)
+
+LIBDRM_DIR = $(TOP)/extras/drm/libdrm
+
+LinkSourceFile(xf86drm.c,$(LIBDRM_DIR))
+LinkSourceFile(xf86drmHash.c,$(LIBDRM_DIR))
+LinkSourceFile(xf86drmRandom.c,$(LIBDRM_DIR))
+LinkSourceFile(xf86drmSL.c,$(LIBDRM_DIR))
+
+DRMASM_DIR = $(TOP)/extras/drm/sunos-core
+LinkSourceFile($(ASM_SOLARIS_SRC),$(DRMASM_DIR))
+
+#if DoLoadableServer
+
+ModuleObjectRule()
+LibraryModuleTarget(drm,$(OBJS))
+NormalLintTarget($(SRCS))
+
+InstallLibraryModule(drm,$(MODULEDIR),$(OS_SUBDIR))
+
+#else
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+
+#endif
+
+DependTarget()
+#endif
+
+InstallDriverSDKLibraryModule(drm,$(DRIVERSDKMODULEDIR),$(OS_SUBDIR))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XORG_NV/sun-src/xc/programs/Xserver/hw/xfree86/os-support/sunos/drm/drmmodule.c	Tue Oct 24 18:42:11 2006 -0700
@@ -0,0 +1,60 @@
+/* drmmodule.c -- Module initialization
+ * Created: Fri Jun  4 09:05:48 1999 by [email protected]
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ * 
+ * Authors: Rickard E. (Rik) Faith <[email protected]>
+ *
+ * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sunos/drm/drmmodule.c,v 1.2 2000/02/23 04:47:22 martin Exp $
+ * 
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86Module.h"
+
+static MODULESETUPPROTO(drmSetup);
+
+static XF86ModuleVersionInfo VersRec =
+{
+        "drm",
+        MODULEVENDORSTRING,
+        MODINFOSTRING1,
+        MODINFOSTRING2,
+        XORG_VERSION_CURRENT,
+        1, 0, 0,
+        ABI_CLASS_EXTENSION,
+        ABI_EXTENSION_VERSION,
+        MOD_CLASS_NONE,
+        {0,0,0,0}
+};
+
+XF86ModuleData drmModuleData = { &VersRec, drmSetup, NULL };
+
+static pointer
+drmSetup(pointer module, pointer opts, int *errmaj, int *errmin)
+{
+    return (void *)1;
+}
--- a/XORG_NV/sun-src/xc/programs/Xserver/hw/xfree86/xf86cfg/Imakefile	Tue Oct 24 16:13:31 2006 -0700
+++ b/XORG_NV/sun-src/xc/programs/Xserver/hw/xfree86/xf86cfg/Imakefile	Tue Oct 24 18:42:11 2006 -0700
@@ -184,6 +184,7 @@
 
 DEFINES        = -DXF86CONFIG=\"$(XF86CONFIGFILE)\" $(MODULEDEFINES) \
 		 $(CURSESDEFINES) \
+		 -DXF86DRI \
 		 -DPROJECT_ROOT=\"$(PROJECTROOT)\" \
 		 -DXF86CONFIGDIR=\"$(XF86CONFIGDIR)\" $(XF86CONSOLEDEFS) \
 		 $(CONFIG_DEFINES) $(XKBDEFRULESDEFS)