7039328 Move SPARC Graphics utilities to X consolidation nv_165
authorAlan Coopersmith <Alan.Coopersmith@Oracle.COM>
Mon, 25 Apr 2011 14:22:03 -0700
changeset 1117 629ac4b133bc
parent 1116 605549b491ac
child 1118 d86fb06ccda8
7039328 Move SPARC Graphics utilities to X consolidation
open-src/app/Makefile
open-src/app/gfx-utils/COPYING
open-src/app/gfx-utils/COPYING.ast
open-src/app/gfx-utils/COPYING.efb
open-src/app/gfx-utils/Makefile
open-src/app/gfx-utils/sun-src/Makefile
open-src/app/gfx-utils/sun-src/fbconf_xorg/Makefile
open-src/app/gfx-utils/sun-src/fbconf_xorg/Makefile.ast
open-src/app/gfx-utils/sun-src/fbconf_xorg/Makefile.common
open-src/app/gfx-utils/sun-src/fbconf_xorg/Makefile.efb
open-src/app/gfx-utils/sun-src/fbconf_xorg/Makefile.fbc
open-src/app/gfx-utils/sun-src/fbconf_xorg/Makefile.gfx
open-src/app/gfx-utils/sun-src/fbconf_xorg/Makefile.xf86
open-src/app/gfx-utils/sun-src/fbconf_xorg/README
open-src/app/gfx-utils/sun-src/fbconf_xorg/ast/ast_prconf.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/ast/ast_prconf.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/ast/ast_predid.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/ast/ast_predid.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/ast/ast_properties.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/ast/ast_properties.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/ast/ast_query_device.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/ast/ast_query_device.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/ast/ast_res_try_now.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/ast/ast_res_try_now.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/data/SunModes_xorg.conf
open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efb_prconf.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efb_prconf.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efb_predid.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efb_predid.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efb_properties.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efb_properties.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efb_query_device.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efb_query_device.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efb_res_try_now.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efb_res_try_now.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efbio.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_Device.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_Device.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_Modes.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_Modes.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_Monitor.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_Monitor.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_Option.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_Option.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_Screen.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_Screen.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_append_config.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_append_config.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_ask.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_ask.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_dev.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_dev.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_edid_test_data.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_edit_config.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_edit_config.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_error.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_error.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_fields.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_fields.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_gamma_table.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_gamma_table.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_get_properties.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_get_properties.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_getargs.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_getargs.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_help.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_help.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_keywds.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_keywds.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_line_er.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_line_er.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_mode_list.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_mode_list.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_open_device.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_open_device.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_open_master.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_open_master.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_prconf.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_prconf.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_predid.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_predid.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_predid_ceaext.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_predid_ceaext.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_predid_diext.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_predid_diext.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_predid_vtbext.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_predid_vtbext.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_properties.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_properties.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_propt.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_propt.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_query_device.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_query_device.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_res.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_res.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_res_compatible.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_res_compatible.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_write_config.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_write_config.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_xorg.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbconf_xorg.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/resolutions.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/resolutions.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/sun_edid.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/sun_edid.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Configint.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/DRI.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Device.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Extensions.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Files.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Flags.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Input.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Keyboard.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Layout.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Module.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Monitor.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Pointer.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Screen.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Vendor.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Video.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/configProcs.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/fields.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/fields.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/read.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/scan.c
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/xf86Optrec.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/xf86Parser.h
open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/xf86tokens.h
open-src/app/gfx-utils/sun-src/fbconfig/Makefile
open-src/app/gfx-utils/sun-src/fbconfig/fbconfig.c
open-src/app/gfx-utils/sun-src/gfx_common/config/gfx_gamma_pack.c
open-src/app/gfx-utils/sun-src/gfx_common/config/gfx_res_util.c
open-src/app/gfx-utils/sun-src/gfx_common/include/gfx_common.h
open-src/app/gfx-utils/sun-src/gfx_common/include/gfx_gamma_pack.h
open-src/app/gfx-utils/sun-src/gfx_common/include/gfx_list_util.h
open-src/app/gfx-utils/sun-src/gfx_common/include/gfx_res_util.h
open-src/app/gfx-utils/sun-src/gfx_common/vts/gfx_vts.c
open-src/app/gfx-utils/sun-src/gfx_common/vts/include/gfx_vts.h
open-src/app/gfx-utils/sun-src/gfx_common/vts/include/graphicstest.h
open-src/app/gfx-utils/sun-src/gfx_common/vts/include/libvtsSUNWxfb.h
open-src/app/gfx-utils/sun-src/vts/Makefile.common
open-src/app/gfx-utils/sun-src/vts/ast/Makefile
open-src/app/gfx-utils/sun-src/vts/ast/ast.h
open-src/app/gfx-utils/sun-src/vts/ast/astio.h
open-src/app/gfx-utils/sun-src/vts/ast/chip.c
open-src/app/gfx-utils/sun-src/vts/ast/chip.h
open-src/app/gfx-utils/sun-src/vts/ast/dma.c
open-src/app/gfx-utils/sun-src/vts/ast/libvtsSUNWast.c
open-src/app/gfx-utils/sun-src/vts/ast/libvtsSUNWast.h
open-src/app/gfx-utils/sun-src/vts/ast/mapfile
open-src/app/gfx-utils/sun-src/vts/ast/mapper.c
open-src/app/gfx-utils/sun-src/vts/ast/memory.c
open-src/app/gfx-utils/sun-src/vts/ast/tools.c
open-src/app/gfx-utils/sun-src/vts/efb/Makefile
open-src/app/gfx-utils/sun-src/vts/efb/chip.c
open-src/app/gfx-utils/sun-src/vts/efb/chip.h
open-src/app/gfx-utils/sun-src/vts/efb/efb.h
open-src/app/gfx-utils/sun-src/vts/efb/efb_reg.h
open-src/app/gfx-utils/sun-src/vts/efb/libvtsSUNWefb.c
open-src/app/gfx-utils/sun-src/vts/efb/libvtsSUNWefb.h
open-src/app/gfx-utils/sun-src/vts/efb/mapfile
open-src/app/gfx-utils/sun-src/vts/efb/mapper.c
open-src/app/gfx-utils/sun-src/vts/efb/memory.c
open-src/app/gfx-utils/sun-src/vts/efb/radeon_reg.h
open-src/app/gfx-utils/sun-src/vts/efb/tools.c
pkg/legacy/SUNWastfbcf.p5m
pkg/legacy/SUNWefbcf.p5m
pkg/legacy/SUNWfbc.p5m
pkg/manifests/system-graphics-fbconfig-fbconfig-ast.p5m
pkg/manifests/system-graphics-fbconfig-fbconfig-efb.p5m
pkg/manifests/system-graphics-fbconfig.p5m
--- a/open-src/app/Makefile	Mon Apr 25 13:38:53 2011 -0700
+++ b/open-src/app/Makefile	Mon Apr 25 14:22:03 2011 -0700
@@ -124,7 +124,8 @@
 	xwininfo \
 	xwud \
 
-OS_SUBDIRS_sparc = $(OS_SUBDIRS_common)
+OS_SUBDIRS_sparc = $(OS_SUBDIRS_common) \
+	gfx-utils
 
 OS_SUBDIRS_i386 = $(OS_SUBDIRS_common)
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/COPYING	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,20 @@
+Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice (including the next
+paragraph) shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS 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.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/COPYING.ast	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,1 @@
+Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/COPYING.efb	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,1 @@
+Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/Makefile	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,89 @@
+###############################################################################
+#
+# SPARC graphics utilities modules (fbconfig & VTS) Makefile
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS 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.
+#
+#
+
+# Package name used in tarballs
+MODULE_NAME=fbconfig
+
+# pkg(5) name we deliver the files in (override default)
+MODULE_PKGNAME=system/graphics/fbconfig
+MODULE_PKGNAME_SET=yes
+
+# Package classification (override default)
+MODULE_PKGCLASS=Drivers/Display
+MODULE_PKGCLASS_SET=yes
+
+# No upstream sources, only local sources
+MODULE_VERSION=src
+SOURCE_TARBALL_NAME=NONE
+SOURCE_TARBALL_NAME_SET=yes
+ADDITIONAL_SOURCE_DIR=sun-src
+
+# Haven't made sure it's 64-bit clean yet, so continue building 32-bit for now
+BUILD_TYPES_SET=yes
+BUILD_TYPES=32
+
+# Man pages to apply Sun footer to & attributes to list
+SUNTOUCHED_MANPAGES= # None
+MODULE_STABILITY=Committed
+
+# No configure script to run
+CONFIGURE_TARGETS=
+CONFIGURE_TARGETS_SET=yes
+
+# Since we don't have a configure script, pass configure flags to make
+MODULE_BUILD_MAKEFLAGS=$(CONFIG_ENV)
+MODULE_INSTALL_MAKEFLAGS=$(CONFIG_ENV)
+
+include ../Makefile.inc
+
+# Install metadata for fb-specific packages too
+FB_MODULES = ast efb
+
+EXTRA_METADATA_DIRS = $(FB_MODULES:%=$(MODULE_PKG_METADATA_DIR)-fbconfig-%)
+
+EXTRA_ATTRDATA_FILES	= $(EXTRA_METADATA_DIRS:%=%/$(ATTRDATA_FILE_NAME))
+EXTRA_LICENSE_FILES	= $(EXTRA_METADATA_DIRS:%=%/$(LICENSE_FILE_NAME))
+EXTRA_METADATA_TARGETS	= $(EXTRA_METADATA_DIRS) \
+                          $(EXTRA_ATTRDATA_FILES) \
+                          $(EXTRA_LICENSE_FILES)
+
+install_metadata: $(EXTRA_METADATA_TARGETS)
+
+$(EXTRA_ATTRDATA_FILES) $(EXTRA_LICENSE_FILES): $(EXTRA_METADATA_DIRS)
+
+$(EXTRA_METADATA_DIRS):
+	mkdir -p $@
+
+# Modules for specific frame buffers are covered only by Oracle copyright
+AST_LICENSE_FILE = $(MODULE_PKG_METADATA_DIR)-fbconfig-ast/$(LICENSE_FILE_NAME)
+EFB_LICENSE_FILE = $(MODULE_PKG_METADATA_DIR)-fbconfig-efb/$(LICENSE_FILE_NAME)
+
+$(AST_LICENSE_FILE):=		LICENSE_FILE	= COPYING.ast
+$(EFB_LICENSE_FILE):=		LICENSE_FILE	= COPYING.efb
+
+$(EXTRA_LICENSE_FILES):=      	LICENSE_NAME    = $(ORACLE_LICENSE_NAME)
+$(EXTRA_LICENSE_FILES):= 	LICENSE_APPEND  = $(ORACLE_LICENSE_APPEND)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/Makefile	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,42 @@
+# Makefile for gfx-util sub-modules
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS 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.
+#
+#
+###############################################################################
+
+default_target: all
+
+OS_SUBDIRS_sparc = \
+	fbconfig \
+	fbconf_xorg \
+	vts/ast \
+	vts/efb
+
+# Dependencies needed for parallel make:
+
+PWD:sh=pwd
+TOP=$(PWD)/../../../../..
+
+### Include common definitions
+DIRNAME="app/gfx-utils/build_sparc/"
+include $(TOP)/open-src/common/Makefile.subdirs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/Makefile	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,157 @@
+#
+# Makefile for fbconf_xorg(1M)
+#
+
+#
+# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS 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 Makefile.common
+
+VPATH	=$(FBC_SRC_DIR)
+
+
+#
+# Preprocessor flags
+#
+
+PROG_NAME = -DFBC_PROG_NAME=\"$(BIN)\"
+
+XF86_DEFINE = -DSMI_FBCONFIG
+FBC_DEFINE = $(DEFINE) $(XF86_DEFINE)
+
+FBC_INC	= -I$(FBC_SRC_DIR) -I$(XF86_SRC_DIR) -I$(GFX_COMMON)/include
+
+#
+# Linker flags
+#
+
+LIBS	= -L$(BIN_DIR) -l$(L_FBC) -L$(GFX_BIN_DIR) -lgfx -lm
+
+#
+# Code modules
+#
+
+BIN_HDRS = \
+	fbc.h \
+	  fbc_dev.h \
+	  fbc_get_properties.h \
+	    fbc_properties.h \
+	  fbc_getargs.h \
+	    fbc_keywds.h \
+	  fbc_help.h \
+	  fbc_open_device.h \
+	  fbc_gamma_table.h \
+	  fbc_line_er.h \
+	  fbc_xorg.h \
+	  fbc_edit_config.h \
+	    fbc_Device.h \
+	    fbc_Screen.h \
+	    fbc_Monitor.h \
+	    fbc_ModeLine.h \
+	      fbc_Option.h \
+	    fbc_fields.h \
+	      fbc_open_master.h \
+	  fbc_prconf.h \
+	  fbc_propt.h \
+	  fbc_res.h \
+	    sun_edid.h \
+	    fbc_mode_list.h \
+	  fbc_ask.h \
+	  fbc_error.h
+
+BIN_CSRCS = \
+	$(BIN).c \
+	  fbc_dev.c \
+	  fbc_get_properties.c \
+	  fbc_help.c \
+	  fbc_open_device.c \
+	  fbc_line_er.c
+
+BIN_OBJ_FILES = $(BIN_CSRCS:.c=.o)
+BIN_OBJS = $(BIN_OBJ_FILES:%=$(FBC_BIN_DIR)/%)
+
+.NO_PARALLEL:	clean clobber
+
+TARGETS	= \
+	$(BIN_DIR) \
+	$(BIN_DIR)/$(LIB_EFB_SO)$(VERS) \
+	$(BIN_DIR)/$(LIB_AST_SO)$(VERS) \
+	$(BIN_DIR)/$(BIN)
+
+all:		init $(TARGETS) 
+
+$(BIN_DIR)/$(BIN): $(BIN_OBJS) $(BIN_DIR)/$(LIB_FBC_SO)$(VERS) $(GFX_BIN_DIR)/$(LIB_GFX_A)
+	$(CC) -o $@ $(BIN_OBJS) $(LIBS) $(DYNFLAGS)
+
+$(GFX_BIN_DIR)/$(LIB_GFX_A): Makefile.gfx
+	$(MAKE) -f Makefile.gfx all
+
+$(BIN_DIR)/$(LIB_FBC_SO)$(VERS): Makefile.fbc
+	$(MAKE) -f Makefile.fbc all
+
+$(BIN_DIR)/$(LIB_EFB_SO)$(VERS): $(BIN_DIR)/$(LIB_FBC_SO)$(VERS) Makefile.efb
+	$(MAKE) -f Makefile.efb all
+
+$(BIN_DIR)/$(LIB_AST_SO)$(VERS): $(BIN_DIR)/$(LIB_FBC_SO)$(VERS) Makefile.ast
+	$(MAKE) -f Makefile.ast all
+
+# Component-specific compilation rule
+
+$(FBC_BIN_DIR)/%.o: $(FBC_SRC_DIR)/%.c $(FBC_HDRS)
+	$(CC) $(FBC_DEFINE) $(FBC_INC) $(CFLAGS) -c -o $@ $<
+
+
+install: $(INSTALL_BIN_DIR)/$(BIN) $(INSTALL_LIB_DIR)/SunModes_xorg.conf
+	$(MAKE) -f Makefile.fbc install
+	$(MAKE) -f Makefile.efb install
+	$(MAKE) -f Makefile.ast install
+
+$(INSTALL_BIN_DIR)/$(BIN): $(BIN)
+	$(INSTALL) -m 0555 $? $@
+
+$(INSTALL_LIB_DIR)/SunModes_xorg.conf: data/SunModes_xorg.conf
+	$(INSTALL) -m 0444 $? $@
+
+init:
+	$(MKDIR) -p $(BIN_DIR)
+
+clean:
+	$(MAKE) -f Makefile.gfx clean
+	$(MAKE) -f Makefile.xf86 clean
+	$(MAKE) -f Makefile.fbc clean
+	$(MAKE) -f Makefile.efb clean
+	$(MAKE) -f Makefile.ast clean
+	-rm -f $(BIN_OBJS) $(FBC_SRC_DIR)/*~ *~
+
+clobber: clean
+	$(MAKE) -f Makefile.gfx clobber
+	$(MAKE) -f Makefile.xf86 clobber
+	$(MAKE) -f Makefile.fbc clobber
+	$(MAKE) -f Makefile.efb clobber
+	$(MAKE) -f Makefile.ast clobber
+	rm -f $(BIN_DIR)/$(BIN)
+	rm -rf $(BIN_DIR)
+
+
+# End of Makefile
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/Makefile.ast	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,141 @@
+#
+# Makefile for libSUNWast_conf.so
+#
+
+#
+# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS 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 Makefile.common
+
+VPATH	=$(FBC_SRC_DIR):$(AST_SRC_DIR)
+
+
+#
+# Preprocessor flags
+#
+
+AST_DEFINE = $DEFINE
+
+#AST_INC = -I$(COMMON)/include -I$(COMMON)/lib -I$(OPENWINHOME)/include
+
+AST_INC	= -I$(FBC_SRC_DIR) -I$(XF86_SRC_DIR) -I$(AST_SRC_DIR)
+AST_INC += -I$(GFX_COMMON)/include
+# AST_INC += -I../../staging/ast/common/include -I../../common/lib
+
+
+#
+# Linker flags
+#
+
+LIBS	= -L$(BIN_DIR) -l$(L_FBC) -lm
+
+
+#
+# Code modules
+#
+
+FBC_HDRS = \
+	fbc.h \
+	  fbc_dev.h \
+	  fbc_properties.h \
+	  fbc_getargs.h \
+	    fbc_keywds.h \
+	  fbc_help.h \
+	  fbc_open_device.h \
+	  fbc_gamma_table.h \
+	  fbc_line_er.h \
+	  fbc_xorg.h \
+	  fbc_edit_config.h \
+	    fbc_Device.h \
+	    fbc_Screen.h \
+	    fbc_Monitor.h \
+	    fbc_Option.h \
+	    fbc_fields.h \
+	      fbc_open_master.h \
+	  fbc_prconf.h \
+	  fbc_predid.h \
+	  fbc_propt.h \
+	  fbc_res.h \
+	    sun_edid.h \
+	    fbc_mode_list.h \
+	  fbc_ask.h \
+	  fbc_error.h
+
+AST_HDRS = \
+	    ast_properties.h \
+	  ast_query_device.h \
+	  ast_res_try_now.h \
+	    ast_prconf.h \
+	    ast_predid.h
+
+AST_CSRCS = \
+	    ast_properties.c \
+	  ast_query_device.c \
+	  ast_res_try_now.c \
+	    ast_prconf.c \
+	    ast_predid.c
+
+AST_OBJ_FILES = $(AST_CSRCS:.c=.o)
+AST_OBJS = $(AST_OBJ_FILES:%=$(AST_BIN_DIR)/%)
+
+
+all:	$(AST_BIN_DIR) $(BIN_DIR)/$(LIB_AST_SO)$(VERS)
+
+
+# Library build rules
+
+$(BIN_DIR)/$(LIB_AST_SO)$(VERS): $(AST_OBJS) $(BIN_DIR)/$(LIB_FBC_SO)$(VERS)
+	rm -f $(BIN_DIR)/$(LIB_AST_SO)
+	$(CC) $(LDFLAGS) $(AST_OBJS) $(LIBS) $(DYNLIBFLAGS) -o $@
+	ln -s $@ $(BIN_DIR)/$(LIB_AST_SO)
+
+$(BIN_DIR)/$(LIB_FBC_SO)$(VERS):
+	$(MAKE) -f Makefile.fbc all
+
+# Component-specific compilation rules
+
+$(AST_BIN_DIR)/%.o: $(AST_SRC_DIR)/%.c $(FBC_HDRS) $(AST_HDRS)
+	$(CC) $(AST_INC) $(CFLAGS) -c -o $@ $<
+
+
+# Directories
+
+$(AST_BIN_DIR):
+	[ -d $@ ] || mkdir -p $@
+
+
+#install: all $(INSTALL_LIB_DIR)/$(LIB_AST_SO) $(INSTALL_LIB_DIR)/$(LIB_AST_SO)$(VERS)
+install: $(INSTALL_LIB_DIR)/$(LIB_AST_SO)$(VERS)
+
+$(INSTALL_LIB_DIR)/$(LIB_AST_SO)$(VERS): $(LIB_AST_SO)$(VERS)
+	$(INSTALL) -m 0555 $? $@
+
+clean:
+	rm -f $(AST_OBJS) $(AST_SRC_DIR)/*~
+
+clobber: clean
+	rm -f $(BIN_DIR)/$(LIB_AST_SO)$(VERS) $(BIN_DIR)/$(LIB_AST_SO)
+
+
+# End of Makefile.ast
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/Makefile.common	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,126 @@
+#
+# Makefile containing common definitions for fbconf_xorg(1M)
+#
+
+#
+# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS 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.
+#
+
+
+#
+# Tools
+#
+
+AR	= ar
+MKDIR	= mkdir
+
+#
+# Targets
+#
+
+BIN	= fbconf_xorg
+
+VERS	= .1
+
+L_GFX      = gfx
+LIB_GFX_A  = libgfx.a
+
+L_XF86     = xf86conf
+LIB_XF86_A = libxf86conf.a
+
+L_FBC      = $(BIN)
+LIB_FBC    = lib$(L_FBC)
+LIB_FBC_SO = $(LIB_FBC).so
+
+L_EFB      = SUNWefb_conf
+LIB_EFB    = lib$(L_EFB)
+LIB_EFB_SO = $(LIB_EFB).so
+
+L_AST      = SUNWast_conf
+LIB_AST    = lib$(L_AST)
+LIB_AST_SO = $(LIB_AST).so
+
+
+#
+# Environment pathnames
+#
+
+GFX_COMMON = ../gfx_common
+
+PROJ_DIR = .
+SRC_DIR	= $(PROJ_DIR)
+BIN_DIR	= $(PROJ_DIR)
+
+GFX_SRC_DIR  = $(GFX_COMMON)/config
+GFX_BIN_DIR  = $(BIN_DIR)/gfx
+
+XF86_SRC_DIR = $(SRC_DIR)/xf86
+XF86_BIN_DIR = $(BIN_DIR)/xf86
+
+FBC_SRC_DIR  = $(SRC_DIR)/fbc
+FBC_BIN_DIR  = $(BIN_DIR)/fbc
+
+KFB_SRC_DIR  = $(SRC_DIR)/kfb
+KFB_BIN_DIR  = $(BIN_DIR)/kfb
+
+EFB_SRC_DIR  = $(SRC_DIR)/efb
+EFB_BIN_DIR  = $(BIN_DIR)/efb
+
+AST_SRC_DIR  = $(SRC_DIR)/ast
+AST_BIN_DIR  = $(BIN_DIR)/ast
+
+
+INSTALL_BIN_DIR = $(DESTDIR)/usr/lib/fbconfig
+INSTALL_LIB_DIR = $(DESTDIR)/usr/lib/fbconfig
+
+
+#
+# Preprocessor flags
+#
+
+#DEFINE	+= -DDEBUG
+
+
+#
+# Compiler flags
+#
+
+#DEBUG_FLAG= -g
+DEBUG_FLAG= 
+PIC_FLAG = -xcode=pic32				# Needed with dynamic linking
+CFLAGS	+= $(DEBUG_FLAG) $(PIC_FLAG)
+
+
+#
+# Linker flags
+#
+
+DYNFLAGS  = -lc
+DYNFLAGS += -Wl,-R$(INSTALL_LIB_DIR)
+
+DYNLIBFLAGS  = -lc
+DYNLIBFLAGS += -G
+DYNLIBFLAGS += -Wl,-L$(INSTALL_LIB_DIR)
+DYNLIBFLAGS += -Wl,-R$(INSTALL_LIB_DIR)
+
+
+# End of Makefile.common
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/Makefile.efb	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,139 @@
+#
+# Makefile for libSUNWefb_conf.so
+#
+
+#
+# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS 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 Makefile.common
+
+VPATH	=$(FBC_SRC_DIR):$(EFB_SRC_DIR)
+
+
+#
+# Preprocessor flags
+#
+
+EFB_DEFINE = $DEFINE
+
+EFB_INC	= -I$(FBC_SRC_DIR) -I$(XF86_SRC_DIR) -I$(EFB_SRC_DIR)
+EFB_INC += -I$(GFX_COMMON)/include
+# EFB_INC += -I../../staging/efb/common/include -I../../common/lib
+
+
+#
+# Linker flags
+#
+
+LIBS	= -L$(BIN_DIR) -l$(L_FBC) -lm
+
+
+#
+# Code modules
+#
+
+FBC_HDRS = \
+	fbc.h \
+	  fbc_dev.h \
+	  fbc_properties.h \
+	  fbc_getargs.h \
+	    fbc_keywds.h \
+	  fbc_help.h \
+	  fbc_open_device.h \
+	  fbc_gamma_table.h \
+	  fbc_line_er.h \
+	  fbc_xorg.h \
+	  fbc_edit_config.h \
+	    fbc_Device.h \
+	    fbc_Screen.h \
+	    fbc_Monitor.h \
+	    fbc_Option.h \
+	    fbc_fields.h \
+	      fbc_open_master.h \
+	  fbc_prconf.h \
+	  fbc_predid.h \
+	  fbc_propt.h \
+	  fbc_res.h \
+	    sun_edid.h \
+	    fbc_mode_list.h \
+	  fbc_ask.h \
+	  fbc_error.h
+
+EFB_HDRS = \
+	    efb_properties.h \
+	  efb_query_device.h \
+	  efb_res_try_now.h \
+	    efb_prconf.h \
+	    efb_predid.h
+
+EFB_CSRCS = \
+	    efb_properties.c \
+	  efb_query_device.c \
+	  efb_res_try_now.c \
+	    efb_prconf.c \
+	    efb_predid.c
+
+EFB_OBJ_FILES = $(EFB_CSRCS:.c=.o)
+EFB_OBJS = $(EFB_OBJ_FILES:%=$(EFB_BIN_DIR)/%)
+
+
+all:	$(EFB_BIN_DIR) $(BIN_DIR)/$(LIB_EFB_SO)$(VERS)
+
+
+# Library build rules
+
+$(BIN_DIR)/$(LIB_EFB_SO)$(VERS): $(EFB_OBJS) $(BIN_DIR)/$(LIB_FBC_SO)$(VERS)
+	rm -f $(BIN_DIR)/$(LIB_EFB_SO)
+	$(CC) $(LDFLAGS) $(EFB_OBJS) $(LIBS) $(DYNLIBFLAGS) -o $@
+	ln -s $@ $(BIN_DIR)/$(LIB_EFB_SO)
+
+$(BIN_DIR)/$(LIB_FBC_SO)$(VERS):
+	$(MAKE) -f Makefile.fbc all
+
+# Component-specific compilation rules
+
+$(EFB_BIN_DIR)/%.o: $(EFB_SRC_DIR)/%.c $(FBC_HDRS) $(EFB_HDRS)
+	$(CC) $(EFB_INC) $(CFLAGS) -c -o $@ $<
+
+
+# Directories
+
+$(EFB_BIN_DIR):
+	[ -d $@ ] || mkdir -p $@
+
+
+#install: all $(INSTALL_LIB_DIR)/$(LIB_EFB_SO) $(INSTALL_LIB_DIR)/$(LIB_EFB_SO)$(VERS)
+install: $(INSTALL_LIB_DIR)/$(LIB_EFB_SO)$(VERS)
+
+$(INSTALL_LIB_DIR)/$(LIB_EFB_SO)$(VERS): $(LIB_EFB_SO)$(VERS)
+	$(INSTALL) -m 0555 $? $@
+
+clean:
+	rm -f $(EFB_OBJS) $(EFB_SRC_DIR)/*~
+
+clobber: clean
+	rm -f $(BIN_DIR)/$(LIB_EFB_SO)$(VERS) $(BIN_DIR)/$(LIB_EFB_SO)
+
+
+# End of Makefile.efb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/Makefile.fbc	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,188 @@
+#
+# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS 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.
+#
+
+#
+# Makefile for libSUNWfbconf_xorg.so
+#
+
+include Makefile.common
+
+VPATH	=$(FBC_SRC_DIR):$(XF86_SRC_DIR)
+
+
+#
+# Preprocessor flags
+#
+
+XF86_DEFINE = -DSMI_FBCONFIG
+FBC_DEFINE = $(DEFINE) $(XF86_DEFINE)
+
+FBC_INC	= -I$(FBC_SRC_DIR) -I$(XF86_SRC_DIR)
+FBC_INC	+= -I$(GFX_COMMON)/include
+FBC_INC	+= -I$(COMMON) -I$(COMMON)/include
+
+
+#
+# Linker flags
+#
+
+LIBS	= -L$(XF86_BIN_DIR) -l$(L_XF86) -L$(GFX_BIN_DIR) -lgfx -lm
+
+
+#
+# Code modules
+#
+
+FBC_HDRS = \
+	fbc.h \
+	  fbc_dev.h \
+	    fbc_properties.h \
+	      fbc_query_device.h \
+	  fbc_getargs.h \
+	    fbc_keywds.h \
+	  fbc_help.h \
+	  fbc_open_device.h \
+	  fbc_gamma_table.h \
+	  fbc_line_er.h \
+	  fbc_xorg.h \
+	  fbc_edit_config.h \
+	    fbc_Device.h \
+	    fbc_Screen.h \
+	    fbc_Monitor.h \
+	    fbc_Modes.h \
+	    fbc_Option.h \
+	    fbc_open_master.h \
+	  fbc_prconf.h \
+	  fbc_predid.h \
+	    fbc_predid_ceaext.h \
+	    fbc_predid_diext.h \
+	    fbc_predid_vtbext.h \
+	  fbc_propt.h \
+	  fbc_res.h \
+	    fbc_res_compatible.h \
+	    sun_edid.h \
+	    fbc_mode_list.h \
+	    fbc_append_config.h \
+	    resolutions.h \
+	  fbc_ask.h \
+	  fbc_write_config.h \
+	    fbc_fields.h \
+	  fbc_error.h \
+	fbc_edid_test_data.h
+
+FBC_CSRCS = \
+	    fbc_properties.c \
+	      fbc_query_device.c \
+	  fbc_getargs.c \
+	    fbc_keywds.c \
+	  fbc_help.c \
+	  fbc_open_device.c \
+	  fbc_gamma_table.c \
+	  fbc_line_er.c \
+	  fbc_edit_config.c \
+	    fbc_Device.c \
+	    fbc_Screen.c \
+	    fbc_Monitor.c \
+	    fbc_Modes.c \
+	    fbc_Option.c \
+	    fbc_open_master.c \
+	  fbc_prconf.c \
+	  fbc_predid.c \
+	    fbc_predid_ceaext.c \
+	    fbc_predid_diext.c \
+	    fbc_predid_vtbext.c \
+	  fbc_propt.c \
+	  fbc_res.c \
+	    fbc_res_compatible.c \
+	    sun_edid.c \
+	    fbc_mode_list.c \
+	    fbc_append_config.c \
+	    resolutions.c \
+	  fbc_ask.c \
+	  fbc_write_config.c \
+	    fbc_fields.c \
+	  fbc_error.c
+
+FBC_OBJ_FILES = $(FBC_CSRCS:.c=.o)
+FBC_OBJS = $(FBC_OBJ_FILES:%=$(FBC_BIN_DIR)/%)
+
+
+XF86_HDRS = \
+	xf86Optrec.h \
+	xf86Parser.h \
+	Configint.h \
+	configProcs.h \
+	xf86tokens.h
+
+
+all:	$(FBC_BIN_DIR) $(BIN_DIR)/$(LIB_FBC_SO)$(VERS)
+
+
+# Library build rules
+
+$(BIN_DIR)/$(LIB_FBC_SO)$(VERS): $(FBC_OBJS) $(GFX_BIN_DIR)/$(LIB_GFX_A) $(XF86_BIN_DIR)/$(LIB_XF86_A)
+	rm -f $(BIN_DIR)/$(LIB_FBC_SO)
+	$(CC) $(LDFLAGS) $(FBC_OBJS) $(LIBS) $(DYNLIBFLAGS) -o $@
+	ln -s $@ $(BIN_DIR)/$(LIB_FBC_SO)
+
+$(GFX_BIN_DIR)/$(LIB_GFX_A): Makefile.gfx
+	$(MAKE) -f Makefile.gfx all
+
+$(XF86_BIN_DIR)/$(LIB_XF86_A): Makefile.xf86
+	$(MAKE) -f Makefile.xf86 all
+
+# Component-specific compilation rule
+
+$(FBC_BIN_DIR)/%.o: $(FBC_SRC_DIR)/%.c $(FBC_HDRS)
+	$(CC) $(FBC_DEFINE) $(FBC_INC) $(CFLAGS) -c -o $@ $<
+
+
+# Directories
+
+$(FBC_BIN_DIR):
+	[ -d $@ ] || mkdir -p $@
+
+
+#install: all $(INSTALL_LIB_DIR)/$(LIB_FBC_SO) $(INSTALL_LIB_DIR)/$(LIB_FBC_SO)$(VERS)
+install: $(INSTALL_LIB_DIR)/$(LIB_FBC_SO) $(INSTALL_LIB_DIR)/$(LIB_FBC_SO)$(VERS)
+
+$(INSTALL_LIB_DIR)/$(LIB_FBC_SO)$(VERS): $(LIB_FBC_SO)$(VERS)
+	$(INSTALL) -m 0555 $? $@
+
+$(INSTALL_LIB_DIR)/$(LIB_FBC_SO): $(LIB_FBC_SO)$(VERS)
+	-rm -f $@
+	ln -s $(LIB_FBC_SO)$(VERS) $@
+
+
+clean:
+	-rm -f $(FBC_OBJS) $(FBC_SRC_DIR)/*~
+	$(MAKE) -f Makefile.xf86 clean
+	$(MAKE) -f Makefile.gfx clean
+
+clobber: clean
+	-rm -f $(BIN_DIR)/$(LIB_FBC_SO)$(VERS) $(BIN_DIR)/$(LIB_FBC_SO)
+	$(MAKE) -f Makefile.xf86 clobber
+	$(MAKE) -f Makefile.gfx clobber
+
+
+# End of Makefile.fbc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/Makefile.gfx	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,90 @@
+#
+# Makefile for libgfx.a (Xorg version)
+#
+
+#
+# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS 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 Makefile.common
+
+VPATH	=$(GFX_COMMON)/include:$(GFX_SRC_DIR)
+
+
+#
+# Preprocessor flags
+#
+
+GFX_DEFINE=
+
+GFX_INC = -I$(GFX_COMMON)/include
+
+
+#
+# Code modules
+#
+
+GFX_HDRS = \
+	gfx_gamma_pack.h
+
+GFX_CSRCS = \
+	gfx_gamma_pack.c \
+	gfx_res_util.c
+
+GFX_OBJ_FILES = $(GFX_CSRCS:.c=.o)
+GFX_OBJS = $(GFX_OBJ_FILES:%=$(GFX_BIN_DIR)/%)
+
+
+.KEEP_STATE:
+.NO_PARALLEL:	clean clobber
+
+
+all:	$(GFX_BIN_DIR) $(GFX_BIN_DIR)/$(LIB_GFX_A)
+
+
+# Archive library build rule
+
+$(GFX_BIN_DIR)/$(LIB_GFX_A): $(GFX_OBJS)
+	$(AR) -r $@ $^
+
+
+# Component-specific compilation rule
+
+$(GFX_BIN_DIR)/%.o: $(GFX_SRC_DIR)/%.c $(GFX_HDRS)
+	$(CC) $(GFX_DEFINE) $(GFX_INC) $(CFLAGS) -c -o $@ $<
+
+
+# Directories
+
+$(GFX_BIN_DIR):
+	[ -d $@ ] || mkdir -p $@
+
+
+clean:
+	-rm -f $(GFX_OBJS)
+
+clobber: clean
+	-rm -f $(GFX_BIN_DIR)/$(LIB_GFX_A)
+
+
+# End of Makefile.gfx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/Makefile.xf86	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,113 @@
+#
+# Makefile for libxf86config.a
+#
+
+#
+# Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS 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 Makefile.common
+
+VPATH	=$(FBC_SRC_DIR):$(XF86_SRC_DIR)
+
+
+#
+# Preprocessor flags
+#
+
+XF86_DEFINE= -DSMI_FBCONFIG \
+	-DHAS_SAVED_IDS_AND_SETEUID -DPROJROOT="/tmp/Xorg-KEM"
+
+XF86_INC = -I$(XF86_SRC_DIR) -I$(FBC_SRC_DIR)
+
+
+#
+# Code modules
+#
+
+FBC_HDRS = \
+	fbc_edit_config.h \
+	fbc_line_er.h
+
+XF86_HDRS = \
+	xf86Optrec.h \
+	xf86Parser.h \
+	Configint.h \
+	configProcs.h \
+	xf86tokens.h
+
+XF86_CSRCS = \
+	Device.c \
+	Files.c \
+	Flags.c \
+	Input.c \
+	Keyboard.c \
+	Layout.c \
+	Module.c \
+	Video.c \
+	Monitor.c \
+	Pointer.c \
+	Screen.c \
+	Vendor.c \
+	read.c \
+	scan.c \
+	DRI.c \
+	Extensions.c \
+	fields.c
+
+#	Omitting write.c
+
+
+XF86_OBJ_FILES = $(XF86_CSRCS:.c=.o)
+XF86_OBJS = $(XF86_OBJ_FILES:%=$(XF86_BIN_DIR)/%)
+
+
+all:	$(XF86_BIN_DIR) $(XF86_BIN_DIR)/$(LIB_XF86_A)
+
+
+# Archive library build rule
+
+$(XF86_BIN_DIR)/$(LIB_XF86_A): $(XF86_OBJS)
+	$(AR) -r $@ $^
+
+
+# Component-specific compilation rule
+
+$(XF86_BIN_DIR)/%.o: $(XF86_SRC_DIR)/%.c $(XF86_HDRS) $(FBC_HDRS)
+	$(CC) $(XF86_DEFINE) $(XF86_INC) $(CFLAGS) -c -o $@ $<
+
+
+# Directories
+
+$(XF86_BIN_DIR):
+	[ -d $@ ] || mkdir -p $@
+
+
+clean:
+	-rm -f $(XF86_OBJS) $(XF86_SRC_DIR)/*~
+
+clobber: clean
+	-rm -f $(XF86_BIN_DIR)/$(LIB_XF86_A)
+
+
+# End of Makefile.xf86
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/README	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,49 @@
+
+The fbconf_xorg/src directory contains these Makefiles:
+
+    Makefile        Master Makefile, builds fbconf_xorg(1M), et. al.
+    Makefile.common Common definitions, included by all other Makefile.* files
+    Makefile.fbc    Builds libfbconf_xorg.so.1 for fbconf_xorg(1M)
+    Makefile.gfx    Builds gfx/libgfx.a as a stripped-down, PIC version
+    Makefile.xf86   Builds xf86/libxf86conf.a, the open source XFree86 parser
+
+    Makefile.<xfb>  Builds libSUNW<xfb>_conf.so.1 for <xfb>
+
+
+To implement a new libSUNW<xfb>_conf.so.1 shared library for a new <xfb>
+frame buffer device:
+
+    Create the fbconf_xorg/<xfb> source directory.
+
+    Start populating the new source directory by creating
+        fbconf_xorg/<xfb>/<xfb>_properties.c
+    and
+        fbconf_xorg/<xfb>/<xfb>_properties.h,
+    based on existing examples, such as in fbconf_xorg/efb.
+    Prominent details will be:
+        SUNW<xfb>_api_version
+                API version number (prominent but trivial)
+        <xfb>_option[]
+                Command line option descriptors
+                (see fbopt_descr_t, etc. in fbc_getargs.h)
+        <xfb>_propt_fn[]
+                -propt display function addresses
+                (see fbc_propt.c)
+        SUNW<xfb>_get_properties()
+                Initialization function for the <xfb> varient of
+                fbconfig_xorg(1M)
+                (see fbc_varient_t in fbc_properties.h)
+
+    Repeat the process with other fbconf_xorg/<xfb>/*.[ch] sources
+    as needed, until all of the anticipated symbols have been defined
+    and the intended <xfb> functionality has been implemented.
+
+    When it makes sense, move sufficiently common code into
+    fbconf_xorg/fbc to be incorporated into libfbconf_xorg.so.1 (or
+    into fbconf_xorg, if the code isn't referenced from a shared
+    library).
+
+    Create a fbconf_xorg/Makefile.<xfb> makefile.  Invoke it from
+    fbconf_xorg/Makefile, following existing examples.  Update
+    fbconf_xorg/Makefile.common as necessary.
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/ast/ast_prconf.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * ast_prconf - Display current ast hardware configuration
+ */
+
+#include <sys/int_types.h>	/* uint8_t */
+#include <stdio.h>		/* printf(), puts() */
+#include <stdlib.h>		/* free() */
+
+#include "xf86Parser.h"		/* Public function, etc. declarations */
+
+#include "sun_edid.h"		/* EDID data parsing */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_prconf.h"		/* Display current hardware configuration */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+
+#include "ast_prconf.h"		/* Display current ast hardware config */
+
+
+/*
+ * ast_prconf_stream()
+ *
+ *    Display the monitor and resolution information for the indicated
+ *    video stream (stream_bit), unless we determine that this stream
+ *    isn't in the set of streams (stream_set) the user wants displayed.
+ */
+
+static
+void
+ast_prconf_stream(
+	const fbc_dev_t *device,	/* Frame buffer device info (-dev) */
+	int		stream_index,	/* Video stream index (zero-based) */
+	fbc_mode_elem_t	*mode_list)	/* Modes from Monitor section of cfg */
+{
+	const int	stream_bit[2] = {
+		GFX_EDID_HEAD_ONE,		/* Video stream 1 bit */
+		GFX_EDID_HEAD_TWO		/* Video stream 2 bit */
+	};
+	gfx_edid_t	edid;		/* EDID data, etc. */
+	uint8_t		edid_data[128]; /* EDID blocks (128 bytes each) */
+
+	/*
+	 * Get and display the EDID data for this stream's display device
+	 */
+	edid.head = stream_bit[stream_index];
+	edid.length = sizeof(edid_data);
+	edid.data   = (caddr_t)edid_data;
+	ast_get_edid_data(device->fd, &edid);
+
+	fbc_prconf_edid((uint8_t *)edid.data, edid.length, mode_list);
+
+	/*
+	 * Display the current video mode setting
+	 */
+	fbc_prconf_cur_mode(device->fd);
+
+}	/* ast_prconf_stream() */
+
+
+/*
+ * ast_prconf()
+ *
+ *    Display the current hardware configuration (-prconf).
+ */
+
+void
+ast_prconf(
+	const fbc_dev_t *device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar,		/* fbconf_xorg(1M) varient data */
+	XF86ConfigPtr	configIR)	/* Config file Internal Rep */
+{
+	fbc_mode_elem_t	*mode_list;	/* Modes from Monitor section of cfg */
+	int		stream_index;	/* Video stream index (zero-based) */
+
+	/*
+	 * Display the frame buffer model name and part number
+	 */
+	fbc_prconf_model(device->fd);
+
+	/*
+	 * Get the Modes declared by the active Monitor section of the config
+	 *
+	 *    This is an "unintrusive" linked list.  Each list element
+	 *    points to, rather than contains, a ModeLine /
+	 *    Mode-EndMode entry.  The mode entries are independent of
+	 *    the list.
+	 */
+	mode_list = fbc_get_mode_list(configIR,
+					fbvar->active.monitor_sectn,
+					device->type);
+
+	/*
+	 * Display the monitor info for each of the indicated streams (-dev)
+	 */
+	printf("\nMonitor/Resolution Information:\n");
+
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+		printf("Monitor %d:\n", stream_index + 1);
+		ast_prconf_stream(device, stream_index, mode_list);
+	}
+
+	fbc_free_mode_list(mode_list);	/* Free the list but not the Modes */
+
+}	/* ast_prconf() */
+
+
+/* End of ast_prconf.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/ast/ast_prconf.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * ast_prconf - Display ast hardware configuration
+ */
+
+
+#ifndef	_AST_PRCONF_H
+#define	_AST_PRCONF_H
+
+
+#include "xf86Parser.h"		/* Public function, etc. declarations */
+
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+
+#include "ast_query_device.h"	/* Query the ast graphics device */
+
+
+void ast_prconf(
+	const fbc_dev_t *device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar,		/* fbconf_xorg(1M) varient data */
+	XF86ConfigPtr	configIR);	/* Config file Internal Rep */
+
+
+#endif	/* _AST_PRCONF_H */
+
+
+/* End of ast_prconf.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/ast/ast_predid.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * ast_predid - Display EDID data
+ */
+
+#include <sys/int_types.h>	/* uint8_t */
+#include <stdio.h>		/* printf() */
+
+#if 0
+#include "astio.h"		/* ast I/O, including ioctl() stuff */
+#endif
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_predid.h"		/* Display EDID data */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+#include "fbc_query_device.h"	/* Query a frame buffer device */
+
+#include "ast_predid.h"		/* Display EDID data */
+#include "ast_query_device.h"	/* Query the ast graphics device */
+
+
+/*
+ * ast_predid_stream()
+ *
+ *    Display the EDID data for the display device specified by video
+ *    stream index (which corresponds to the device name's stream suffix
+ *    letter).
+ */
+
+static
+void
+ast_predid_stream(
+	int 		device_fd,	/* Device file descriptor */
+	int		stream_index,	/* Video stream index (zero-based) */
+	int		predid_raw,	/* TRUE => Display raw EDID data */
+	int		predid_parsed)	/* TRUE => Display parsed EDID data */
+{
+	const int	edid_stream[2] = {
+		GFX_EDID_HEAD_ONE,		/* Video stream 1 bit */
+		GFX_EDID_HEAD_TWO		/* Video stream 2 bit */
+	};
+	gfx_edid_t	edid;		/* EDID data, etc. */
+	uint8_t		edid_data[128]; /* EDID blocks (128 bytes each) */
+
+	/*
+	 * Get the EDID data for this video stream's display device
+	 */
+	edid.head = edid_stream[stream_index];
+	edid.length = sizeof(edid_data);
+	edid.data   = (caddr_t)edid_data;
+	ast_get_edid_data(device_fd, &edid);
+
+	/*
+	 * Display the EDID information for this display device
+	 */
+	fbc_predid((uint8_t *)edid.data, edid.length, predid_raw, predid_parsed);
+
+}	/* ast_predid_stream() */
+
+
+/*
+ * ast_predid()
+ *
+ *    Display EDID data for each video stream (-predid [raw] [parsed]).
+ */
+
+void
+ast_predid(
+	const fbc_dev_t *device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar)		/* fbconf_xorg(1M) varient data */
+{
+	int		stream_index;	/* Video stream index (zero-based) */
+
+	/*
+	 * Display the EDID data for each of the indicated streams (-dev)
+	 */
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+		printf("Monitor %d:\n", stream_index + 1);
+		ast_predid_stream(device->fd,
+				stream_index,
+				fbvar->option_set.predid_raw,
+				fbvar->option_set.predid_parsed);
+	}
+
+}	/* ast_predid() */
+
+
+/* End of ast_predid.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/ast/ast_predid.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * ast_predid - Display EDID data
+ */
+
+
+#ifndef	_AST_PREDID_H
+#define	_AST_PREDID_H
+
+
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+
+
+void ast_predid(
+	const fbc_dev_t *device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar);	/* fbconf_xorg(1M) varient data */
+
+
+#endif	/* _AST_PREDID_H */
+
+
+/* End of ast_predid.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/ast/ast_properties.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,266 @@
+/*
+ * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * ast_properties - ast device-specific properties
+ *
+ *    AST2100
+ */
+
+#include <stdlib.h>		/* free() */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_getargs.h"	/* Program command line processing */
+#include "fbc_help.h"		/* Program usage and help messages */
+#include "fbc_properties.h"	/* Establish fbconf_xorg program properties */
+#include "fbc_propt.h"		/* Display the current option settings */
+#include "fbc_query_device.h"	/* Query a frame buffer device */
+#include "fbc_xorg.h"		/* Edit config file data representations */
+
+#include "ast_prconf.h"		/* Display ast hardware configuration */
+#include "ast_predid.h"		/* Display EDID data */
+#include "ast_properties.h"	/* ast device-specific properties */
+#include "ast_query_device.h"	/* Query the ast graphics device */
+#include "ast_res_try_now.h"	/* Video mode setting (-res try now) */
+
+
+/*
+ * Tell fbconf_xorg(1M) what API version libSUNWast_conf is using
+ */
+fbc_api_ver_t SUNWast_api_version = FBC_API_VERSION;
+
+
+/*
+ * Usage (error) message text
+ */
+static const char	*ast_usage_text_body =
+	" [-dev device-filename]\n"
+	"\t\t  [-file machine | system | config-path]\n"
+	"\t\t  [-res video-mode [nocheck | noconfirm] ]\n"
+	"\t\t  [-rscreen enable | disable]\n"
+	"\t\t  [-defaults]\n"
+	"\t\t  [-help]\n"
+	"\t\t  [-res \\?]\n"
+	"\t\t  [-prconf] [-predid [raw] [parsed]] [-propt]\n"
+	"\n";
+
+
+/*
+ * Command line option descriptors for fbconf_xorg(1M) and ast devices
+ *
+ *    These table entries must be in -help display order.
+ *
+ *    When fbc_Option_keyword() is the "Option handler function"
+ *    (fbopt_descr_t.fbc_getopt_fn member), the "Config Option entry
+ *    name(s)" string (fbopt_descr_t.conf_name member) is composed of
+ *    contiguous Nul-terminated Option names that are terminated by an
+ *    additional Nul, e.g.:
+ *        FBC_KEYWD_DoubleWide "\0" FBC_KEYWD_DoubleHigh "\0"
+ *    or (nominally):
+ *        "DoubleWide\0DoubleHigh\0\0"
+ *
+ *    See fbc_getopt.h for the relevant declarations and definitions.
+ */
+
+static fbopt_descr_t	ast_option[] = {
+	{
+	/* -defaults */
+		"defaults",		/* Command line option name	*/
+		fbc_help_defaults,	/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		fbc_opt_defaults,	/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL		/* *** POSITIVELY NO RECURSIVE DEFAULTS! *** */
+	},
+	{
+	/* -dev <device> */
+		"dev",			/* Command line option name	*/
+		fbc_help_dev,		/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_opt_dev,		/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTN_Device,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -file machine|system|<config-path> */
+		"file",			/* Command line option name	*/
+		fbc_help_file,		/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_opt_file,		/* Option handler function	*/
+		fbc_keywds_file,	/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -help */
+		"help",			/* Command line option name	*/
+		fbc_help_help,		/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		fbc_opt_help,		/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -prconf */
+		"prconf",		/* Command line option name	*/
+		fbc_help_prconf,	/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		fbc_opt_prconf,		/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -predid [raw] [parsed] */
+		"predid",		/* Command line option name	*/
+		fbc_help_predid,	/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		fbc_opt_predid,		/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -propt */
+		"propt",		/* Command line option name	*/
+		fbc_help_propt,		/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		fbc_opt_propt,		/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -res ? */
+	/* -res <video-mode> [nocheck|noconfirm] [try] [now] */
+		"res",			/* Command line option name	*/
+		fbc_help_res_nntn,	/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_opt_res,		/* Option handler function	*/
+		fbc_keywds_res_nntn,	/* Command line option keywords	*/
+		FBC_SECTN_Res,		/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -rscreen enable|disable */
+		"rscreen",		/* Command line option name	*/
+		fbc_help_rscreen,	/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_Option_keyword,	/* Option handler function	*/
+		fbc_keywds_xable,	/* Command line option keywords	*/
+		FBC_SECTN_RScreen,	/* Config section code		*/
+		FBC_KEYWD_RScreen "\0",	/* Config Option entry name(s)	*/
+		fbc_defargv_rscreen	/* argv[] invoked by -defaults	*/
+	},
+
+	{
+	/* End-of-table marker */
+		NULL,			/* Command line option name	*/
+		NULL,			/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		NULL,			/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	}
+};
+
+
+/*
+ * List of functions to display the current option settings (-propt)
+ */
+static fbc_propt_fn_t	*ast_propt_fn[] = {
+	fbc_propt_file,			/* Configuration file */
+	fbc_propt_video_mode,		/* Current video mode name: -res */
+	fbc_propt_screen_title,		/* Screen settings title */
+	fbc_propt_rscreen,		/* Remote console setting: -rscreen */
+	NULL				/* End of table */
+};
+
+
+/*
+ * SUNWast_get_properties()
+ *
+ *    Return the fbconf_xorg(1M) properties for the ast frame buffer
+ *    device type.
+ */
+
+int
+SUNWast_get_properties(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar)		/* Updated fbconf_xorg properties */
+{
+
+	/*
+	 * Provide some more frame buffer device information
+	 */
+	device->max_streams = 1;	/* No 'a'|'b' suffixes */
+
+	/*
+	 * Establish the device properties and the fbconf_xorg(1M) behavior
+	 */
+	fbvar->usage_text_body   = ast_usage_text_body;
+
+	fbvar->gamma_default     = FBC_GAMMA_DEFAULT; /* No gamma correction */
+
+	fbvar->lut_size          = 0;	/* No gamma look-up table w/ ast */
+	fbvar->fbc_option        = &ast_option[0];
+
+	fbvar->xf86_entry_mods.Option_mods_size =
+				sizeof (ast_option) / sizeof (fbopt_descr_t);
+
+	fbvar->get_edid_res_info = &ast_get_edid_res_info;
+	fbvar->revise_settings   = NULL;
+	fbvar->init_device       = NULL;
+	fbvar->prconf            = &ast_prconf;
+	fbvar->predid            = &ast_predid;
+	fbvar->propt_fn          = &ast_propt_fn[0];
+
+#if defined(RES_TRY_NOW)
+	fbvar->res_mode_try      = &ast_res_mode_try;
+	fbvar->res_mode_now      = &ast_res_mode_now;
+#else
+	fbvar->res_mode_try      = NULL;
+	fbvar->res_mode_now      = NULL;
+#endif
+
+	return (FBC_SUCCESS);
+
+}	/* SUNWast_get_properties() */
+
+
+/* End of ast_properties.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/ast/ast_properties.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * ast_properties - ast device-specific properties
+ */
+
+
+#ifndef	_AST_PROPERTIES_H
+#define	_AST_PROPERTIES_H
+
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+
+
+extern fbc_api_ver_t SUNWast_api_version; /* libSUNWast_conf API version */
+
+
+int SUNWast_get_properties(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar);	/* Updated fbconf_xorg properties */
+
+
+#endif	/* _AST_PROPERTIES_H */
+
+
+/* End of ast_properties.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/ast/ast_query_device.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * ast_query_device - Query the ast frame buffer device
+ */
+
+#include <sys/int_types.h>	/* uint8_t, uint32_t */
+#include <errno.h>		/* errno */
+#include <stdio.h>		/* NULL */
+#include <stdlib.h>		/* malloc() */
+#include <string.h>		/* memset(), strdup(), strerror() */
+#include <unistd.h>		/* ioctl(), sleep() */
+
+#include <sys/fbio.h>		/* cg6_info, fbgattr */
+
+#include "gfx_common.h"		/* Model name, part number, cur video mode */
+
+#include "sun_edid.h"		/* EDID data parsing */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_mode_list.h"	/* List of Modes from the config file */
+#include "fbc_query_device.h"	/* Query a frame buffer device */
+
+#include "ast_query_device.h"	/* Query the ast frame buffer device */
+
+
+/*
+ * ast_get_edid_data()
+ *
+ *    Query the frame buffer device for EDID data.  Return zero upon
+ *    success, along with the EDID data, etc.  In the event of an error,
+ *    display an error message and return the errno code and a NULL
+ *    data pointer.
+ */
+
+int
+ast_get_edid_data(
+	int		device_fd,	/* Device file descriptor number */
+	gfx_edid_t	*edid)		/* EDID data, etc. */
+{
+	int		i;		/* Retry loop counter */
+
+	/*
+	 * Get the EDID data for this video stream's display device
+	 *
+	 *    If the display device had been powered down, it may take a
+	 *    few seconds to come up (Bug 4962976).
+	 */
+#define	GET_EDID_RETRIES 3		/* # of ioctl(AST_GET_EDID) retries */
+	for (i = GET_EDID_RETRIES; ; i -= 1) {
+	        if (ioctl(device_fd, GFX_IOCTL_GET_EDID, edid) >= 0) {
+			break;
+		}
+		if (i <= 0) {
+			edid->length = 0;
+			edid->data   = NULL;
+			return (errno);	/* EDID data is unavailable */
+		}
+		sleep(1);
+	}
+
+	return (0);
+
+}	/* ast_get_edid_data() */
+
+
+/*
+ * ast_get_edid_res_info()
+ *
+ *    For each video stream indicated by the effective -dev option,
+ *    retrieve the EDID data from the display device and return the
+ *    following information:
+ *      * Manufacturer ID
+ *      * Product Code
+ *      * Pointer to a dynamically allocated array of supported video
+ *        mode name strings w/ preferred video mode in first element
+ *    The display device information is returned in the
+ *    edid_res_info[FBC_MAX_STREAMS] array.
+ */
+
+void
+ast_get_edid_res_info(
+	const fbc_dev_t *device,	/* Frame buffer device info (-dev) */
+	fbc_mode_elem_t	*mode_list,	/* Modes from Monitor section of cfg */
+	fbc_edid_res_t	edid_res_info[]) /* Returned display device info */
+{
+	const int	ast_stream[2] = {
+		GFX_EDID_HEAD_ONE,		/* Video stream 1 bit */
+		GFX_EDID_HEAD_TWO		/* Video stream 2 bit */
+	};
+	gfx_edid_t	edid;		/* EDID data, etc. */
+	uint8_t		edid_data[128]; /* EDID blocks (128 bytes each) */
+	uint32_t	serial_num;	/* ID Serial Number (ignored) */
+	int		stream_index;	/* Video stream index (zero-based) */
+
+	memset(edid_res_info, 0, sizeof (fbc_edid_res_t) * FBC_MAX_STREAMS);
+
+	/*
+	 * Get the EDID -res information for the indicated streams (-dev)
+	 */
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+		/*
+		 * Get the EDID data for this video stream's display device
+		 */
+		edid.head = ast_stream[stream_index];
+		edid.length = sizeof (edid_data);
+		edid.data   = (caddr_t)edid_data;
+		if ((ast_get_edid_data(device->fd, &edid) != 0)
+		    || (sun_edid_check_base((uint8_t *)edid.data, edid.length) != 0)) {
+			continue;
+		}
+
+		/*
+		 * Extract the -res related data for this display device
+		 */
+		sun_edid_vendor((uint8_t *)edid.data,
+				edid_res_info[stream_index].manufacturer_id,
+				&edid_res_info[stream_index].product_code,
+				&serial_num);
+		edid_res_info[stream_index].video_mode =
+		    sun_edid_video_modes((uint8_t *)edid.data, edid.length, mode_list);
+	}
+
+}	/* ast_get_edid_res_info() */
+
+
+/* End of ast_query_device.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/ast/ast_query_device.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * ast_query_device - Query the ast frame buffer device
+ */
+
+
+#ifndef _AST_QUERY_DEVICE_H
+#define	_AST_QUERY_DEVICE_H
+
+
+#if 0
+#include "astio.h"		/* ast I/O, including ioctl() stuff */
+#endif
+
+#include "gfx_common.h"
+
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_mode_list.h"	/* List of Modes from Monitor section of cfg */
+#include "fbc_query_device.h"	/* Query a frame buffer device */
+
+
+int ast_get_edid_data(
+	int		device_fd,	/* Device file descriptor number */
+	gfx_edid_t	*edid);		/* EDID data, etc. */
+
+void ast_get_edid_res_info(
+	const fbc_dev_t *device,	/* Frame buffer device info (-dev) */
+	fbc_mode_elem_t	*mode_list,	/* Modes from Monitor section of cfg */
+	fbc_edid_res_t	edid_res_info[]); /* Returned display device info */
+
+
+#endif	/* _AST_QUERY_DEVICE_H */
+
+
+/* End of ast_query_device.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/ast/ast_res_try_now.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,413 @@
+/*
+ * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * ast_res_try_now - Video mode setting (-res try now)
+ */
+
+#include <sys/types.h>		/* u_char, uint32_t */
+#include <ctype.h>		/* toupper() */
+#include <stdio.h>		/* printf(), sscanf() */
+#include <signal.h>		/* signal() */
+#include <termios.h>		/* tcgetattr(), tcsetattr() */
+#include <unistd.h>		/* alarm(), read() */
+
+#include "gfx_common.h"
+
+#if TRY_RES_NOW
+#include "astio.h"		/* ast I/O, including ioctl() stuff */
+#include "regdef.h"		/* CRTC*_PITCH, ... */
+
+#if (0)	/* Preferred implementation */
+#include "libast_int.h"		/* Radeon_*(), regr*(), regw*(), ... */
+#else	/* Sufficient implementation */
+/* n-bit register read/write (offset, value) */
+#define	regr(o)		(*(volatile uint32_t *)(registers + (o)))
+#define	regr16(o)	(*(volatile uint16_t *)(registers + (o)))
+#define	regr8(o)	(*(volatile uint8_t *)(registers + (o)))
+#define	regw(o,v)	(regr(o) = (v))
+#define	regw16(o,v)	(regr16(o) = (v))
+#define	regw8(o,v)	(regr8(o) = (v))
+/* Radeon API functions */
+#include "libast.h"		/* Radeon_*(), ... */
+#endif	/* Prefficient, suferred implementation */
+#endif /* TRY_RES_NOW */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_ask.h"		/* User interaction */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_res.h"		/* Video modes/resolutions (-res option) */
+
+#include "ast_res_try_now.h"	/* Video mode setting (-res try now) */
+
+
+#define	AST_MAX_STREAMS	2
+
+#define	_LIVE_		0	/* Live run */
+
+
+static const int	ast_stream_bit[AST_MAX_STREAMS] = {
+	GFX_EDID_HEAD_ONE,		/* Video stream 1 bit */
+	GFX_EDID_HEAD_TWO		/* Video stream 2 bit */
+};
+
+
+/*
+ * ast_res_mode_try_stop()
+ *
+ *    Signal handler for the duration of the video mode trial.
+ */
+
+static
+void
+ast_res_mode_try_stop(
+	int		signum)		/* Signal number */
+{
+
+	/* Void */
+
+}	/* ast_res_mode_try_stop() */
+
+
+/*
+ * ast_res_mode_try()
+ *
+ *    Conduct a 10-second trial of the new video mode for the user's
+ *    approval (-res <video_mode> try).  Return TRUE iff the trial is
+ *    successful.
+ */
+
+int
+ast_res_mode_try(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_video_mode_t *video_mode)	/* Video mode (-res <video_mode>) */
+{
+	int rval = TRUE;
+
+#if TRY_RES_NOW
+	const int	crtc_pitch_off[AST_MAX_STREAMS] = {
+		CRTC_PITCH,		/* Stream 1 pitch register offset */
+		CRTC2_PITCH		/* Stream 2 pitch register offset */
+	};
+	const int	crtc_offset_off[AST_MAX_STREAMS] = {
+		CRTC_OFFSET,		/* Stream 1 offset register offset */
+		CRTC2_OFFSET		/* Stream 2 offset register offset */
+	};
+	AstInfo		*fb_info; 	/* Frame buffer information */
+	void		(*orig_disp[NSIG])(int); /* Original signal disp's */
+	struct termios	tparm_old;	/* Original terminal parameters */
+	struct termios	tparm_new;	/* Video trial terminal parameters */
+	int		input_size;	/* Stdin keystroke count (0 or 1) */
+	char		input_buf[4];	/* Stdin keystroke buffer */
+	int		rval = TRUE;	/* TRUE => Successful trial so far */
+	CRTCInfoBlock	video[AST_MAX_STREAMS];
+	int		depth[AST_MAX_STREAMS];
+	uint32_t	crtc_pitch_val[AST_MAX_STREAMS];
+	uint32_t	crtc_offset_val[AST_MAX_STREAMS];
+	volatile u_char	*registers;	/* Ptr to registers (regr(), regw()) */
+
+	uint32_t	offset[AST_MAX_STREAMS];
+	int		stream_index;	/* Video stream index (zero-based) */
+
+	/*
+	 * Get the frame buffer information
+	 */
+#if (_LIVE_)	// ???
+	fb_info = ast_openfd(device->fd);
+	if (fb_info == NULL) {
+		return (FALSE);
+	}
+
+	/*
+	 * Point to the (volatle) registers
+	 */
+	registers = fb_info->registers;
+
+	/*
+	 * Get the current hardware video mode for each applicable stream
+	 */
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+		Radeon_GetMode(fb_info,
+				ast_stream_bit[stream_index],
+				&video[stream_index],
+				&depth[stream_index]);
+		crtc_pitch_val[stream_index]  =
+				regr(crtc_pitch_off[stream_index]);
+		crtc_offset_val[stream_index] =
+				regr(crtc_offset_off[stream_index]);
+	}
+
+#endif	// ???
+	/*
+	 * Ask whether the user is ready to try the new video mode
+	 */
+	printf("About to change video resolution to \"%s\" for %d seconds\n",
+		video_mode->name, FBC_TRIAL_TIME);
+	if (!fbc_ask_yes_no("Continue (yes/no) ? ")) {
+		return (FALSE);
+	}
+
+	/*
+	 * Set a new signal handler, saving the original signal dispositions
+	 *
+	 *    SIGHUP     Hangup
+	 *    SIGINT     Interrupt
+	 *    SIGQUIT    Quit
+	 *    SIGBUS     Bus Error
+	 *    SIGSEGV    Segmentation Fault
+	 *    SIGPIPE    Broken Pipe
+	 *    SIGALRM    Alarm Clock
+	 *    SIGTERM    Terminated
+	 *    SIGVTALRM  Virtual Timer Expired
+	 */
+	orig_disp[SIGHUP]    = signal(SIGHUP,    ast_res_mode_try_stop);
+	orig_disp[SIGINT]    = signal(SIGINT,    ast_res_mode_try_stop);
+	orig_disp[SIGQUIT]   = signal(SIGQUIT,   ast_res_mode_try_stop);
+	orig_disp[SIGBUS]    = signal(SIGBUS,    ast_res_mode_try_stop);
+	orig_disp[SIGSEGV]   = signal(SIGSEGV,   ast_res_mode_try_stop);
+	orig_disp[SIGPIPE]   = signal(SIGPIPE,   ast_res_mode_try_stop);
+	orig_disp[SIGALRM]   = signal(SIGALRM,   ast_res_mode_try_stop);
+	orig_disp[SIGTERM]   = signal(SIGTERM,   ast_res_mode_try_stop);
+	orig_disp[SIGVTALRM] = signal(SIGVTALRM, ast_res_mode_try_stop);
+
+	/*
+	 * Set the new video mode for all applicable display devices
+	 */
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+#if (_LIVE_)	// ???
+		fb_info->stream = ast_stream_bit[stream_index];
+		offset[stream_index] = Radeon_GetMemory(device->fd,
+							video_mode->width,
+							video_mode->height,
+							depth[stream_index],
+							0);
+		if (offset[stream_index] == (uint32_t)-1) {
+			offset[stream_index] = 0;
+		}
+		if (ast_set_named_mode(fb_info,
+					video_mode->name,
+					depth[stream_index],
+					offset[stream_index]) != 0) {
+			char monitor_id[FBC_MAX_MONITOR_ID_LEN];
+
+			fbc_get_monitor_id(
+					device, stream_index, &monitor_id[0]);
+			fbc_errormsg("Cannot set video mode for monitor%s!\n",
+					monitor_id);
+			rval = FALSE;
+		}
+#endif	// ???
+	}
+
+	if (rval) {
+		/*
+		 * Clear each screen after changing the video mode
+		 */
+		for (stream_index = device->stream_lo;
+		    stream_index <= device->stream_hi;
+		    stream_index += 1) {
+			int pitch;
+#if (_LIVE_)	// ???
+			pitch = regr(crtc_pitch_off[stream_index]) * 8;
+			if (offset[stream_index] == 0) {
+				offset[stream_index] =
+						crtc_offset_val[stream_index];
+			}
+			memset((void *)(fb_info->fb_mem + offset[0]/*???*/),
+				0,
+				pitch * video_mode->height);
+#endif	// ???
+		}
+
+		/*
+		 * Put the terminal's standard input into raw mode
+		 */
+		tcgetattr(0, &tparm_old);
+		tparm_new = tparm_old;
+		tparm_new.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE |
+					ECHOK | ECHONL | ECHOCTL | ECHOPRT |
+					ECHOKE);
+		tparm_new.c_cc[VMIN]  = 0;
+		tparm_new.c_cc[VTIME] = (FBC_TRIAL_TIME * 10);
+		tcsetattr(0, TCSANOW, &tparm_new);
+
+		/*
+		 * Wait for a user keystroke or for the timer to expire
+		 */
+		alarm(FBC_TRIAL_TIME + 1);  /* In case VTIME doesn't work */
+		input_size = read(0, input_buf, 1);
+		alarm(0);
+
+		/*
+		 * Restore the terminal's original standard input parameters
+		 */
+		tcsetattr(0, TCSANOW, &tparm_old);
+	}
+
+	/*
+	 * Restore the original signal dispositions
+	 */
+	signal(SIGHUP,    orig_disp[SIGHUP]);
+	signal(SIGINT,    orig_disp[SIGINT]);
+	signal(SIGQUIT,   orig_disp[SIGQUIT]);
+	signal(SIGBUS,    orig_disp[SIGBUS]);
+	signal(SIGSEGV,   orig_disp[SIGSEGV]);
+	signal(SIGPIPE,   orig_disp[SIGPIPE]);
+	signal(SIGALRM,   orig_disp[SIGALRM]);
+	signal(SIGTERM,   orig_disp[SIGTERM]);
+	signal(SIGVTALRM, orig_disp[SIGVTALRM]);
+
+	/*
+	 * Restore the original video mode for the applicable display devices
+	 */
+#if (_LIVE_)	// ???
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+		/* For Radeon_SetModeNB*() declarations, see libast.h */
+		typedef int Radeon_SetModeNBi_t(
+					AstInfo		*fb_info,
+					int		xres,
+					int		yres,
+					int		depth,
+					const CRTCInfoBlock *paramtable,
+					uint32_t	offset);
+		Radeon_SetModeNBi_t *Radeon_SetModeNBi[] = {
+			&Radeon_SetModeNB1,
+			&Radeon_SetModeNB2
+		};
+
+		(void) Radeon_SetModeNBi[stream_index](
+					    fb_info,
+					    video[stream_index].width,
+					    video[stream_index].height,
+					    depth[stream_index],
+					    &video[stream_index],
+					    crtc_offset_val[stream_index]);
+		regw(crtc_pitch_off[0], crtc_pitch_val[0]);
+	}
+
+	ast_closefd(fb_info);
+#endif	// ???
+
+	if (rval) {
+		/*
+		 * Interpret the user input character or absence thereof
+		 *
+		 *    Treat the absence of user input as noncommittal.
+		 *    Treat Newline or Carriage Return (but not Space,
+		 *    etc. by historical precedent) as noncommittal.
+		 *    Treat 'Y' or 'y' as affirmative.
+		 *    Treat 'N' or 'n' or anything else (by historical
+		 *    precedent) as negative.
+		 */
+		if ((input_size == 0) ||
+		    (input_buf[0] == '\n') || (input_buf[0] == '\r')) {
+			/*
+			 * Still need a Yes/No response from the user
+			 */
+			rval = fbc_ask_yes_no(
+			"Do you want %s to become the new setting (yes/no) ? ",
+						video_mode->name);
+		} else
+		if (toupper(input_buf[0]) != 'Y') {
+			rval = FALSE;		/* Treat as 'N' or 'n' */
+		}
+	}
+
+	/*
+	 * Return, indicating whether the trial was successful
+	 */
+#endif /* TRY_RES_NOW */
+
+	return (rval);
+
+}	/* ast_res_mode_try() */
+
+
+/*
+ * ast_res_mode_now()
+ *
+ *    Set the new video mode now (-res <video_mode> now).
+ */
+
+int
+ast_res_mode_now(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_video_mode_t *video_mode)	/* Video mode (-res <video_mode>) */
+{
+/*???*/	const unsigned int depth = 24;	/* From nfb & pfb for Solaris 8 & 9 */
+
+#if TRY_RES_NOW
+	AstInfo		*fb_info;	/* Frame buffer information */
+	int		error_code;	/* Error code (FBC_ERR_xxxxx) */
+	int		stream_index;	/* Video stream index (zero-based) */
+
+	error_code = FBC_SUCCESS;
+
+	fb_info = ast_openfd(device->fd);
+	if (fb_info == NULL) {
+		return (FBC_ERR_OPEN);
+	}
+
+	printf("Setting \"%s\"\n", video_mode->name);
+
+	/*
+	 * Let the driver know (??? that we've begun setting this mode ???)
+	 */
+	(void) ioctl(device->fd, AST_BEGIN_SETVIDEOMODE, 0);
+
+	/*
+	 * Set the video mode for each applicable display device
+	 */
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+		fb_info->stream = ast_stream_bit[stream_index];
+		if (ast_set_named_mode(fb_info, video_mode->name, depth, 0)
+					!= 0) {
+			error_code = FBC_ERR_IOCTL;
+		}
+	}
+
+	/*
+	 * Let the driver know (??? that we're finished setting this mode ???)
+	 */
+	(void) ioctl(device->fd, AST_SETVIDEOMODE, 0);
+
+	ast_closefd(fb_info);
+
+	return (error_code);
+#endif /* TRY_RES_NOW */
+
+	return (FBC_SUCCESS);
+
+}	/* ast_res_mode_now() */
+
+
+/* End of ast_res_try_now.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/ast/ast_res_try_now.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * ast_res_try_now - Video mode setting (-res try now)
+ */
+
+#ifndef _AST_RES_TRY_NOW_H
+#define	_AST_RES_TRY_NOW_H
+
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+
+
+int ast_res_mode_try(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_video_mode_t *video_mode);	/* Video mode (-res <video_mode>) */
+
+int ast_res_mode_now(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_video_mode_t *video_mode);	/* Video mode (-res <video_mode>) */
+
+
+#endif	/* _AST_RES_TRY_NOW_H */
+
+
+/* End of ast_res_try_now.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/data/SunModes_xorg.conf	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,207 @@
+Section "Modes"
+    Identifier "SunModes"
+
+    Mode "VESA_STD_640x480x60"
+         DotClock 25.159
+         HTimings 640 656 752 800
+         VTimings 480 490 492 525
+         Flags "-HSync" "-VSync"
+    EndMode
+
+    Mode "VESA_STD_640x480x72"
+         DotClock 31.5
+         HTimings 640 664 704 832
+         VTimings 480 489 492 520
+         Flags "-HSync" "-VSync"
+    EndMode
+
+    Mode "VESA_STD_640x480x75"
+         DotClock 31.5
+         HTimings 640 656 720 840
+         VTimings 480 481 484 500
+         Flags "-HSync" "-VSync"
+    EndMode
+
+    Mode "VESA_STD_800x600x75"
+         DotClock 49.5
+         HTimings 800 816 896 1056
+         VTimings 600 601 604 625
+         Flags "+HSync" "+VSync"
+    EndMode
+
+    Mode "SUNW_STEREO_1024x692x100"
+         DotClock 113.665
+         HTimings 1024 1040 1168 1358
+         VTimings 692 711 717 837
+         Flags "-HSync" "-VSync"
+    EndMode
+
+    Mode "VESA_STD_1024x768x60"
+         DotClock 65
+         HTimings 1024 1048 1184 1344
+         VTimings 768 771 777 806
+         Flags "-HSync" "-VSync"
+    EndMode
+
+    Mode "VESA_STD_1024x768x70"
+         DotClock 75
+         HTimings 1024 1048 1184 1328
+         VTimings 768 771 777 806
+         Flags "-HSync" "-VSync"
+    EndMode
+
+    Mode "VESA_STD_1024x768x75"
+         DotClock 78.75
+         HTimings 1024 1040 1136 1312
+         VTimings 768 769 772 800
+         Flags "+HSync" "+VSync"
+    EndMode
+
+    Mode "SUNW_STEREO_1152x900x120"
+         DotClock 180
+         HTimings 1152 1216 1352 1568
+         VTimings 900 902 912 956
+         Flags "+HSync" "+VSync"
+    EndMode
+
+    Mode "SUNW_STD_1280x768x56"
+         DotClock 76.179
+         HTimings 1280 1328 1440 1688
+         VTimings 768 769 772 802
+         Flags "-HSync" "-VSync"
+    EndMode
+
+    Mode "SUNW_STEREO_1280x800x112"
+         DotClock 164.7
+         HTimings 1280 1296 1472 1736
+         VTimings 800 802 810 846
+         Flags "+HSync" "+VSync"
+    EndMode
+
+    Mode "VESA_STD_1280x1024x60"
+         DotClock 108
+         HTimings 1280 1328 1440 1688
+         VTimings 1024 1025 1028 1066
+         Flags "+HSync" "+VSync"
+    EndMode
+
+    Mode "VESA_STD_1280x1024x75"
+         DotClock 135
+         HTimings 1280 1296 1440 1688
+         VTimings 1024 1025 1028 1066
+         Flags "+HSync" "+VSync"
+    EndMode
+
+    Mode "VESA_STD_1280x1024x85"
+         DotClock 157.5
+         HTimings 1280 1344 1504 1728
+         VTimings 1024 1025 1028 1072
+         Flags "+HSync" "+VSync"
+    EndMode
+
+    Mode "SUNW_STEREO_1280x1024x96"
+         DotClock 163.28
+         HTimings 1280 1300 1460 1600
+         VTimings 1024 1027 1033 1063
+         Flags "-HSync" "-VSync"
+    EndMode
+
+    Mode "SUNW_STEREO-DIG_1280x1024x108"
+         DotClock 159.3
+         HTimings 1280 1288 1368 1424
+         VTimings 1024 1026 1030 1036
+         Flags "-HSync" "-VSync"
+    EndMode
+
+    Mode "SUNW_STEREO_1280x1024x112"
+         DotClock 216
+         HTimings 1280 1306 1466 1786
+         VTimings 1024 1025 1033 1080
+         Flags "+HSync" "+VSync"
+    EndMode
+
+    Mode "VESA_STD_1440x900x60"
+         DotClock 106.5
+         HTimings 1440 1520 1672 1904
+         VTimings 900 903 909 934
+         Flags "-HSync" "+VSync"
+    EndMode
+
+    Mode "SUNW_DIG_1600x1024x60"
+         DotClock 107
+         HTimings 1600 1616 1672 1708
+         VTimings 1024 1026 1027 1053
+         Flags "-HSync" "-VSync"
+    EndMode
+
+    Mode "VESA_STD_1680x1050x60"
+         DotClock 146.25
+         HTimings 1680 1784 1960 2240
+         VTimings 1050 1053 1059 1089
+         Flags "-HSync" "+VSync"
+    EndMode
+
+    Mode "VESA_RB_1680x1050x60"
+         DotClock 119
+         HTimings 1680 1728 1760 1840
+         VTimings 1050 1053 1059 1080
+         Flags "+HSync" "-VSync"
+    EndMode
+
+    Mode "VESA_STD_1600x1200x60"
+         DotClock 162
+         HTimings 1600 1664 1856 2160
+         VTimings 1200 1201 1204 1250
+         Flags "+HSync" "+VSync"
+    EndMode
+
+    Mode "SUNW_DIG_1600x1200x60"
+         DotClock 132.3
+         HTimings 1600 1604 1668 1774
+         VTimings 1200 1205 1215 1239
+         Flags "+HSync" "+VSync"
+    EndMode
+
+    Mode "SI-LMT_RFE_1600x1200x73"
+         DotClock 200.46
+         HTimings 1600 1688 1904 2200
+         VTimings 1200 1200 1205 1248
+         Flags "+HSync" "+VSync"
+    EndMode
+
+    Mode "VESA_STD_1600x1200x75"
+         DotClock 202.5
+         HTimings 1600 1664 1856 2160
+         VTimings 1200 1201 1204 1250
+         Flags "+HSync" "+VSync"
+    EndMode
+
+    Mode "VESA_STD_1792x1344x60"
+         DotClock 204.75
+         HTimings 1792 1920 2120 2448
+         VTimings 1344 1345 1348 1394
+         Flags "-HSync" "+VSync"
+    EndMode
+
+    Mode "VESA_STD_1792x1344x75"
+         DotClock 261
+         HTimings 1792 1888 2104 2456
+         VTimings 1344 1345 1348 1417
+         Flags "-HSync" "+VSync"
+    EndMode
+
+    Mode "SUNW_DIG_1920x1080x60"
+         DotClock 137.7
+         HTimings 1920 1924 1988 2056
+         VTimings 1080 1082 1086 1112
+         Flags "+HSync" "+VSync"
+    EndMode
+
+    Mode "SUNW_DIG_1920x1200x60"
+         DotClock 151.2
+         HTimings 1920 1924 1988 2056
+         VTimings 1200 1202 1206 1234
+         Flags "+HSync" "+VSync"
+    EndMode
+
+EndSection
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efb_prconf.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * efb_prconf - Display current efb hardware configuration
+ */
+
+#include <sys/int_types.h>	/* uint8_t */
+#include <stdio.h>		/* printf(), puts() */
+#include <stdlib.h>		/* free() */
+
+#include "xf86Parser.h"		/* Public function, etc. declarations */
+
+#include "sun_edid.h"		/* EDID data parsing */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_prconf.h"		/* Display current hardware configuration */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+#include "fbc_query_device.h"	/* Query a frame buffer device */
+
+#include "efb_prconf.h"		/* Display current efb hardware config */
+
+
+/*
+ * efb_prconf_stream()
+ *
+ *    Display the monitor and resolution information for the indicated
+ *    video stream (stream_bit), unless we determine that this stream
+ *    isn't in the set of streams (stream_set) the user wants displayed.
+ */
+
+static
+void
+efb_prconf_stream(
+	int		device_fd,	/* Device file descriptor number */
+	int		stream_index,	/* Video stream index (zero-based) */
+	fbc_mode_elem_t	*mode_list)	/* Modes from Monitor section of cfg */
+{
+	uint8_t		*edid_data;	/* EDID Base block, etc. */
+	size_t		edid_length;	/* EDID data length */
+
+	/*
+	 * Get and display the EDID data for this stream's display device
+	 */
+	fbc_get_edid_data(device_fd, stream_index, &edid_data, &edid_length);
+	fbc_prconf_edid(edid_data, edid_length, mode_list);
+	free(edid_data);
+
+	/*
+	 * Display the current video mode setting
+	 */
+	fbc_prconf_cur_mode(device_fd);
+
+}	/* efb_prconf_stream() */
+
+
+/*
+ * efb_prconf()
+ *
+ *    Display the current hardware configuration (-prconf).
+ */
+
+void
+efb_prconf(
+	const fbc_dev_t *device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar,		/* fbconf_xorg(1M) varient data */
+	XF86ConfigPtr	configIR)	/* Config file Internal Rep */
+{
+	fbc_mode_elem_t	*mode_list;	/* Modes from Monitor section of cfg */
+	int		stream_index;	/* Video stream index (zero-based) */
+
+	/*
+	 * Display the frame buffer model name and part number
+	 */
+	fbc_prconf_model(device->fd);
+
+	/*
+	 * Get the Modes declared by the active Monitor section of the config
+	 *
+	 *    This is an "unintrusive" linked list.  Each list element
+	 *    points to, rather than contains, a ModeLine /
+	 *    Mode-EndMode entry.  The mode entries are independent of
+	 *    the list.
+	 */
+	mode_list = fbc_get_mode_list(configIR,
+					fbvar->active.monitor_sectn,
+					device->type);
+
+	/*
+	 * Display the monitor info for each of the indicated streams (-dev)
+	 */
+	printf("\nMonitor/Resolution Information:\n");
+
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+		printf("Monitor %d:\n", stream_index + 1);
+		efb_prconf_stream(device->fd, stream_index, mode_list);
+	}
+
+	fbc_free_mode_list(mode_list);	/* Free the list but not the Modes */
+
+}	/* efb_prconf() */
+
+
+/* End of efb_prconf.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efb_prconf.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * efb_prconf - Display efb hardware configuration
+ */
+
+
+#ifndef	_EFB_PRCONF_H
+#define	_EFB_PRCONF_H
+
+
+#include "xf86Parser.h"		/* Public function, etc. declarations */
+
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+
+#include "efb_query_device.h"	/* Query the efb graphics device */
+
+
+void efb_prconf(
+	const fbc_dev_t *device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar,		/* fbconf_xorg(1M) varient data */
+	XF86ConfigPtr	configIR);	/* Config file Internal Rep */
+
+
+#endif	/* _EFB_PRCONF_H */
+
+
+/* End of efb_prconf.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efb_predid.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * efb_predid - Display EDID data
+ */
+
+#pragma ident	"@(#)efb_predid.c	1.1	09/02/18 15:22:49 SMI"
+
+#include <sys/int_types.h>	/* uint8_t */
+#include <stdio.h>		/* printf() */
+#include <stdlib.h>		/* free() */
+
+#include "efbio.h"		/* efb I/O, including ioctl() stuff */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_predid.h"		/* Display EDID data */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+#include "fbc_query_device.h"	/* Query a frame buffer device */
+
+#include "efb_predid.h"		/* Display EDID data */
+#include "efb_query_device.h"	/* Query the efb graphics device */
+
+
+/*
+ * efb_predid_stream()
+ *
+ *    Display the EDID data for the display device specified by video
+ *    stream index (which corresponds to the device name's stream suffix
+ *    letter).
+ */
+
+static
+void
+efb_predid_stream(
+	int		device_fd,	/* Device file descriptor number */
+	int		stream_index,	/* Video stream index (zero-based) */
+	int		predid_raw,	/* TRUE => Display raw EDID data */
+	int		predid_parsed)	/* TRUE => Display parsed EDID data */
+{
+	uint8_t		*edid_data;	/* EDID Base block, etc. */
+	size_t		edid_length;	/* EDID data length */
+
+	/*
+	 * Get and display the EDID data for this stream's display device
+	 */
+	fbc_get_edid_data(device_fd, stream_index, &edid_data, &edid_length);
+	fbc_predid(edid_data, edid_length, predid_raw, predid_parsed);
+	free(edid_data);
+
+}	/* efb_predid_stream() */
+
+
+/*
+ * efb_predid()
+ *
+ *    Display EDID data for each video stream (-predid [raw] [parsed]).
+ */
+
+void
+efb_predid(
+	const fbc_dev_t *device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar)		/* fbconf_xorg(1M) varient data */
+{
+	int		stream_index;	/* Video stream index (zero-based) */
+
+	/*
+	 * Display the EDID data for each of the indicated streams (-dev)
+	 */
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+		printf("Monitor %d:\n", stream_index + 1);
+		efb_predid_stream(device->fd,
+				stream_index,
+				fbvar->option_set.predid_raw,
+				fbvar->option_set.predid_parsed);
+	}
+
+}	/* efb_predid() */
+
+
+/* End of efb_predid.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efb_predid.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * efb_predid - Display EDID data
+ */
+
+
+#ifndef	_EFB_PREDID_H
+#define	_EFB_PREDID_H
+
+
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+
+
+void efb_predid(
+	const fbc_dev_t *device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar);	/* fbconf_xorg(1M) varient data */
+
+
+#endif	/* _EFB_PREDID_H */
+
+
+/* End of efb_predid.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efb_properties.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,740 @@
+/*
+ * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * efb_properties - efb device-specific properties
+ *
+ *    XVR-50    (pfb w/ Xsun)
+ *    XVR-100   (pfb w/ Xsun)
+ *    XVR-300   (nfb w/ Xsun)
+ *    XVR-300x8 (nfb w/ Xsun)
+ */
+
+#include <stdlib.h>		/* free() */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_getargs.h"	/* Program command line processing */
+#include "fbc_help.h"		/* Program usage and help messages */
+#include "fbc_properties.h"	/* Establish fbconf_xorg program properties */
+#include "fbc_propt.h"		/* Display the current option settings */
+#include "fbc_query_device.h"	/* Query a frame buffer device */
+#include "fbc_xorg.h"		/* Edit config file data representations */
+
+#include "efb_prconf.h"		/* Display efb hardware configuration */
+#include "efb_predid.h"		/* Display EDID data */
+#include "efb_properties.h"	/* efb device-specific properties */
+#include "efb_query_device.h"	/* Query the efb graphics device */
+#include "efb_res_try_now.h"	/* Video mode setting (-res try now) */
+
+
+/*
+ * Tell fbconf_xorg(1M) what API version libSUNWefb_conf is using
+ */
+fbc_api_ver_t SUNWefb_api_version = FBC_API_VERSION;
+
+
+/*
+ * Usage (error) message text
+ */
+static const char	*efb_usage_text_body_xvr_50 =
+	" [-dev device-filename]\n"
+	"\t\t  [-file machine | system | config-path]\n"
+	"\t\t  [-res video-mode [nocheck | noconfirm] [try] [now]]\n"
+	"\t\t  [-g gamma-value]\n"
+	"\t\t  [-rscreen enable | disable]\n"
+	"\t\t  [-defaults]\n"
+	"\t\t  [-help]\n"
+	"\t\t  [-res \\?]\n"
+	"\t\t  [-prconf] [-predid [raw] [parsed]] [-propt]\n"
+	"\n";
+
+static const char	*efb_usage_text_body_xvr_100 =
+	" [-dev device-filename]\n"
+	"\t\t  [-file machine | system | config-path]\n"
+	"\t\t  [-res video-mode [nocheck | noconfirm] [try] [now]]\n"
+	"\t\t  [-clone enable | disable]\n"
+	"\t\t  [-doublewide enable | disable]\n"
+	"\t\t  [-doublehigh enable | disable]\n"
+	"\t\t  [-g gamma-value]\n"
+	"\t\t  [-offset xoff-value yoff-value]\n"
+	"\t\t  [-outputs swapped | direct]\n"
+	"\t\t  [-defaults]\n"
+	"\t\t  [-help]\n"
+	"\t\t  [-res \\?]\n"
+	"\t\t  [-prconf] [-predid [raw] [parsed]] [-propt]\n"
+	"\n";
+
+static const char	*efb_usage_text_body_xvr_300 =
+	" [-dev devname] [-file machine | system | config-path]\n"
+	"\t\t  [-res video-mode [nocheck | noconfirm] [try] [now]]\n"
+	"\t\t  [-clone enable | disable]\n"
+	"\t\t  [-doublewide enable | disable]\n"
+	"\t\t  [-doublehigh enable | disable]\n"
+	"\t\t  [-g gamma-value]\n"
+	"\t\t  [-offset xoff-value yoff-value]\n"
+	"\t\t  [-outputs swapped | direct]\n"
+	"\t\t  [-defaults]\n"
+	"\t\t  [-help]\n"
+	"\t\t  [-res \\?]\n"
+	"\t\t  [-prconf] [-predid [raw] [parsed]] [-propt]\n"
+	"\n";
+
+
+/*
+ * Help (-help) message text
+ */
+static const char efb_help_offset[] =		/* For XVR-100 & XVR-300 */
+"	-offset		Adjusts the position of the secondary stream.\n"
+"			Currently only implemented in -doublewide and\n"
+"			-doublehigh modes.\n"
+"			With -doublewide, the xoff-value is used to position\n"
+"			the secondary DVI stream.  With -doublehigh, the\n"
+"			yoff-value is used instead.  The secondary stream is\n"
+"			2 if the -outputs setting is direct, and 1 if it is\n"
+"			swapped.  A negative value specifies the overlapped\n"
+"			region with the primary stream.  A positive value is\n"
+"			treated as 0.\n"
+"			Default: [0,0]\n";
+
+
+/*
+ * Command line option descriptors for fbconf_xorg(1M) and efb devices
+ *
+ *    These table entries must be in -help display order.
+ *
+ *    When fbc_Option_keyword() is the "Option handler function"
+ *    (fbopt_descr_t.fbc_getopt_fn member), the "Config Option entry
+ *    name(s)" string (fbopt_descr_t.conf_name member) is composed of
+ *    contiguous Nul-terminated Option names that are terminated by an
+ *    additional Nul, e.g.:
+ *        FBC_KEYWD_DoubleWide "\0" FBC_KEYWD_DoubleHigh "\0"
+ *    or (nominally):
+ *        "DoubleWide\0DoubleHigh\0\0"
+ *
+ *    See fbc_getopt.h for the relevant declarations and definitions.
+ */
+
+static fbopt_descr_t	efb_option_xvr_50[] = {
+	{
+	/* -defaults */
+		"defaults",		/* Command line option name	*/
+		fbc_help_defaults,	/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		fbc_opt_defaults,	/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL		/* *** POSITIVELY NO RECURSIVE DEFAULTS! *** */
+	},
+	{
+	/* -dev <device> */
+		"dev",			/* Command line option name	*/
+		fbc_help_dev,		/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_opt_dev,		/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTN_Device,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -file machine|system|<config-path> */
+		"file",			/* Command line option name	*/
+		fbc_help_file,		/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_opt_file,		/* Option handler function	*/
+		fbc_keywds_file,	/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -g <gamma-value> */
+		"g",			/* Command line option name	*/
+		fbc_help_g,		/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_opt_Gamma,		/* Option handler function	*/
+		fbc_keywds_xable,	/* Command line option keywords	*/
+		FBC_SECTN_Gamma,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		fbc_defargv_g		/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -help */
+		"help",			/* Command line option name	*/
+		fbc_help_help,		/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		fbc_opt_help,		/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -prconf */
+		"prconf",		/* Command line option name	*/
+		fbc_help_prconf,	/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		fbc_opt_prconf,		/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -predid [raw] [parsed] */
+		"predid",		/* Command line option name	*/
+		fbc_help_predid,	/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		fbc_opt_predid,		/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -propt */
+		"propt",		/* Command line option name	*/
+		fbc_help_propt,		/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		fbc_opt_propt,		/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -res ? */
+	/* -res <video-mode> [nocheck|noconfirm] [try] [now] */
+		"res",			/* Command line option name	*/
+		fbc_help_res_nntn,	/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_opt_res,		/* Option handler function	*/
+		fbc_keywds_res_nntn,	/* Command line option keywords	*/
+		FBC_SECTN_Res,		/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -rscreen enable|disable */
+		"rscreen",		/* Command line option name	*/
+		fbc_help_rscreen,	/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_Option_keyword,	/* Option handler function	*/
+		fbc_keywds_xable,	/* Command line option keywords	*/
+		FBC_SECTN_RScreen,	/* Config section code		*/
+		FBC_KEYWD_RScreen "\0",	/* Config Option entry name(s)	*/
+		fbc_defargv_rscreen	/* argv[] invoked by -defaults	*/
+	},
+
+	{
+	/* End-of-table marker */
+		NULL,			/* Command line option name	*/
+		NULL,			/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		NULL,			/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	}
+};
+
+
+static fbopt_descr_t	efb_option_xvr_100[] = {
+	{
+	/* -clone enable|disable */
+		"clone",		/* Command line option name	*/
+		fbc_help_clone,		/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_Option_keyword,	/* Option handler function	*/
+		fbc_keywds_xable,	/* Command line option keywords	*/
+		FBC_SECTN_Clone,	/* Config section code		*/
+		FBC_KEYWD_Clone "\0",	/* Config Option entry name(s)	*/
+		fbc_defargv_clone	/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -defaults */
+		"defaults",		/* Command line option name	*/
+		fbc_help_defaults,	/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		fbc_opt_defaults,	/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL		/* *** POSITIVELY NO RECURSIVE DEFAULTS! *** */
+	},
+	{
+	/* -dev <device> */
+		"dev",			/* Command line option name	*/
+		fbc_help_dev,		/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_opt_dev,		/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTN_Device,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -doublewide enable|disable */
+		"doublewide",		/* Command line option name	*/
+		fbc_help_doublewide,	/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_Option_keyword,	/* Option handler function	*/
+		fbc_keywds_xable,	/* Command line option keywords	*/
+		FBC_SECTN_DoubleWide,	/* Config section code		*/
+		FBC_KEYWD_DoubleWide "\0"
+			FBC_KEYWD_DoubleHigh "\0",
+		fbc_defargv_doublewide	/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -doublehigh enable|disable */
+		"doublehigh",		/* Command line option name	*/
+		fbc_help_doublehigh,	/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_Option_keyword,	/* Option handler function	*/
+		fbc_keywds_xable,	/* Command line option keywords	*/
+		FBC_SECTN_DoubleHigh,	/* Config section code		*/
+		FBC_KEYWD_DoubleHigh "\0"
+			FBC_KEYWD_DoubleWide "\0",
+		fbc_defargv_doublehigh	/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -file machine|system|<config-path> */
+		"file",			/* Command line option name	*/
+		fbc_help_file,		/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_opt_file,		/* Option handler function	*/
+		fbc_keywds_file,	/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -g <gamma-value> */
+		"g",			/* Command line option name	*/
+		fbc_help_g,		/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_opt_Gamma,		/* Option handler function	*/
+		fbc_keywds_xable,	/* Command line option keywords	*/
+		FBC_SECTN_Gamma,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		fbc_defargv_g		/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -help */
+		"help",			/* Command line option name	*/
+		fbc_help_help,		/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		fbc_opt_help,		/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -offset <xoff> <yoff> */
+		"offset",		/* Command line option name	*/
+		fbc_help_offset,	/* Help text			*/
+		2,			/* Min # of option arguments	*/
+		fbc_Option_Stream_Offset, /* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTN_StreamXOffset, /* Config section code		*/
+		FBC_KEYWD_StreamXOffset "\0" FBC_KEYWD_StreamYOffset "\0",
+		fbc_defargv_offset	/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -outputs swapped|direct */
+		"outputs",		/* Command line option name	*/
+		fbc_help_outputs,	/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_Option_keyword,	/* Option handler function	*/
+		fbc_keywds_swappedirect, /* Command line option keywords */
+		FBC_SECTN_Outputs,	/* Config section code		*/
+		FBC_KEYWD_Outputs "\0",	/* Config Option entry name(s)	*/
+		fbc_defargv_outputs	/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -prconf */
+		"prconf",		/* Command line option name	*/
+		fbc_help_prconf,	/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		fbc_opt_prconf,		/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -predid [raw] [parsed] */
+		"predid",		/* Command line option name	*/
+		fbc_help_predid,	/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		fbc_opt_predid,		/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -propt */
+		"propt",		/* Command line option name	*/
+		fbc_help_propt,		/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		fbc_opt_propt,		/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -res ? */
+	/* -res <video-mode> [nocheck|noconfirm] [try] [now] */
+		"res",			/* Command line option name	*/
+		fbc_help_res_nntn,	/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_opt_res,		/* Option handler function	*/
+		fbc_keywds_res_nntn,	/* Command line option keywords	*/
+		FBC_SECTN_Res,		/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+
+	{
+	/* End-of-table marker */
+		NULL,			/* Command line option name	*/
+		NULL,			/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		NULL,			/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	}
+};
+
+
+static fbopt_descr_t	efb_option_xvr_300[] = {
+	{
+	/* -clone enable|disable */
+		"clone",		/* Command line option name	*/
+		fbc_help_clone,		/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_Option_keyword,	/* Option handler function	*/
+		fbc_keywds_xable,	/* Command line option keywords	*/
+		FBC_SECTN_Clone,	/* Config section code		*/
+		FBC_KEYWD_Clone "\0",	/* Config Option entry name(s)	*/
+		fbc_defargv_clone	/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -defaults */
+		"defaults",		/* Command line option name	*/
+		fbc_help_defaults,	/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		fbc_opt_defaults,	/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL		/* *** POSITIVELY NO RECURSIVE DEFAULTS! *** */
+	},
+	{
+	/* -dev <device> */
+		"dev",			/* Command line option name	*/
+		fbc_help_dev,		/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_opt_dev,		/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTN_Device,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -doublehigh enable|disable */
+		"doublehigh",		/* Command line option name	*/
+		fbc_help_doublehigh,	/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_Option_keyword,	/* Option handler function	*/
+		fbc_keywds_xable,	/* Command line option keywords	*/
+		FBC_SECTN_DoubleHigh,	/* Config section code		*/
+		FBC_KEYWD_DoubleHigh "\0"
+			FBC_KEYWD_DoubleWide "\0",
+		fbc_defargv_doublehigh	/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -doublewide enable|disable */
+		"doublewide",		/* Command line option name	*/
+		fbc_help_doublewide,	/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_Option_keyword,	/* Option handler function	*/
+		fbc_keywds_xable,	/* Command line option keywords	*/
+		FBC_SECTN_DoubleWide,	/* Config section code		*/
+		FBC_KEYWD_DoubleWide "\0"
+			FBC_KEYWD_DoubleHigh "\0",
+		fbc_defargv_doublewide	/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -file machine|system|<config-path> */
+		"file",			/* Command line option name	*/
+		fbc_help_file,		/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_opt_file,		/* Option handler function	*/
+		fbc_keywds_file,	/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -g <gamma-value> */
+		"g",			/* Command line option name	*/
+		fbc_help_g,		/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_opt_Gamma,		/* Option handler function	*/
+		fbc_keywds_xable,	/* Command line option keywords	*/
+		FBC_SECTN_Gamma,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		fbc_defargv_g		/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -help */
+		"help",			/* Command line option name	*/
+		fbc_help_help,		/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		fbc_opt_help,		/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -offset <xoff> <yoff> */
+		"offset",		/* Command line option name	*/
+		efb_help_offset,	/* Help text			*/
+		2,			/* Min # of option arguments	*/
+		fbc_Option_Stream_Offset, /* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTN_StreamXOffset, /* Config section code		*/
+		FBC_KEYWD_StreamXOffset "\0" FBC_KEYWD_StreamYOffset "\0",
+		fbc_defargv_offset	/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -outputs swapped|direct */
+		"outputs",		/* Command line option name	*/
+		fbc_help_outputs,	/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_Option_keyword,	/* Option handler function	*/
+		fbc_keywds_swappedirect, /* Command line option keywords */
+		FBC_SECTN_Outputs,	/* Config section code		*/
+		FBC_KEYWD_Outputs "\0",	/* Config Option entry name(s)	*/
+		fbc_defargv_outputs	/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -prconf */
+		"prconf",		/* Command line option name	*/
+		fbc_help_prconf,	/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		fbc_opt_prconf,		/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -predid [raw] [parsed] */
+		"predid",		/* Command line option name	*/
+		fbc_help_predid,	/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		fbc_opt_predid,		/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -propt */
+		"propt",		/* Command line option name	*/
+		fbc_help_propt,		/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		fbc_opt_propt,		/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+	{
+	/* -res ? */
+	/* -res <video_mode> [nocheck|noconfirm] [try] [now] */
+		"res",			/* Command line option name	*/
+		fbc_help_res_nntn,	/* Help text			*/
+		1,			/* Min # of option arguments	*/
+		fbc_opt_res,		/* Option handler function	*/
+		fbc_keywds_res_nntn,	/* Command line option keywords	*/
+		FBC_SECTN_Res,		/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	},
+
+	{
+	/* End-of-table marker */
+		NULL,			/* Command line option name	*/
+		NULL,			/* Help text			*/
+		0,			/* Min # of option arguments	*/
+		NULL,			/* Option handler function	*/
+		NULL,			/* Command line option keywords	*/
+		FBC_SECTION_NONE,	/* Config section code		*/
+		NULL,			/* Config Option entry name(s)	*/
+		NULL			/* argv[] invoked by -defaults	*/
+	}
+};
+
+
+/*
+ * List of functions to display the current option settings (-propt)
+ */
+static fbc_propt_fn_t	*efb_propt_fn_xvr_50[] = {
+	fbc_propt_file,			/* Configuration file */
+	fbc_propt_video_mode,		/* Current video mode name: -res */
+	fbc_propt_screen_title,		/* Screen settings title */
+	fbc_propt_rscreen,		/* Remote console setting: -rscreen */
+	fbc_propt_visual_title,		/* Visual Information title */
+	fbc_propt_g,			/* Gamma setting: -g only */
+	NULL				/* End of table */
+};
+
+static fbc_propt_fn_t	*efb_propt_fn_xvr_100[] = {
+	fbc_propt_file,			/* Configuration file */
+	fbc_propt_video_mode,		/* Current video mode name: -res */
+	fbc_propt_screen_title,		/* Screen settings title */
+	fbc_propt_dual_screen,		/* Dual-screen: -doublexxxxx */
+	fbc_propt_clone,		/* Clone setting */
+	fbc_propt_offset,		/* Screen offset settings */
+	fbc_propt_outputs,		/* Outputs setting */
+	fbc_propt_visual_title,		/* Visual Information title */
+	fbc_propt_g,			/* Gamma setting: -g only */
+	NULL				/* End of table */
+};
+
+static fbc_propt_fn_t	*efb_propt_fn_xvr_300[] = {
+	fbc_propt_file,			/* Configuration file */
+	fbc_propt_video_mode,		/* Current video mode name: -res */
+	fbc_propt_screen_title,		/* Screen settings title */
+	fbc_propt_dual_screen,		/* Dual-screen: -doublexxxxx */
+	fbc_propt_clone,		/* Clone setting */
+	fbc_propt_offset,		/* Screen offset settings */
+	fbc_propt_outputs,		/* Outputs setting */
+	fbc_propt_visual_title,		/* Visual Information title */
+	fbc_propt_default_visual,	/* Default visual: -defxxxxx" */
+	fbc_propt_g,			/* Gamma setting: -g only */
+	NULL				/* End of table */
+};
+
+
+/*
+ * SUNWefb_get_properties()
+ *
+ *    Return the fbconf_xorg(1M) properties for the efb frame buffer
+ *    device type.
+ */
+
+int
+SUNWefb_get_properties(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar)		/* Updated fbconf_xorg properties */
+{
+	char		*full_model_name; /* Frame buf full name w/ "SUNW," */
+	char		*simple_model_name; /* Frame buf simple model name */
+
+	/*
+	 * Provide some more frame buffer device information
+	 */
+	device->max_streams = 1;	/* XVR-50 has no 'a'|'b' suffixes */
+
+	/*
+	 * Establish the device properties and the fbconf_xorg(1M) behavior
+	 */
+	fbvar->usage_text_body   = efb_usage_text_body_xvr_300;
+
+	fbvar->gamma_default     = FBC_GAMMA_DEFAULT;
+
+	fbvar->lut_size          = 0;	/* No gamma look-up table w/ efb */
+	fbvar->fbc_option        = &efb_option_xvr_300[0];
+
+	fbvar->xf86_entry_mods.Option_mods_size =
+			sizeof (efb_option_xvr_300) / sizeof (fbopt_descr_t)
+			+ 1;		/* StreamYOffset */
+
+	fbvar->get_edid_res_info = &efb_get_edid_res_info;
+	fbvar->revise_settings   = NULL;
+	fbvar->init_device       = NULL;
+	fbvar->prconf            = &efb_prconf;
+	fbvar->predid            = &efb_predid;
+	fbvar->propt_fn          = &efb_propt_fn_xvr_300[0];
+	fbvar->res_mode_try      = &efb_res_mode_try;
+	fbvar->res_mode_now      = &efb_res_mode_now;
+
+	/*
+	 * Distinguish between the various frame buffer models
+	 */
+	full_model_name =
+		fbc_get_fb_model_name(device->fd, &simple_model_name);
+	if (full_model_name != NULL) {
+		if (strcmp(full_model_name, "SUNW,XVR-50") == 0) {
+			fbvar->usage_text_body = efb_usage_text_body_xvr_50;
+			fbvar->fbc_option      = &efb_option_xvr_50[0];
+			fbvar->xf86_entry_mods.Option_mods_size =
+				sizeof (efb_option_xvr_50)
+						/ sizeof (fbopt_descr_t);
+			fbvar->propt_fn        = &efb_propt_fn_xvr_50[0];
+		} else
+		if (strcmp(full_model_name, "SUNW,XVR-100") == 0) {
+			device->max_streams    = 2;  /* 'a'|'b' suffixes */
+
+			fbvar->usage_text_body = efb_usage_text_body_xvr_100;
+			fbvar->fbc_option      = &efb_option_xvr_100[0];
+			fbvar->xf86_entry_mods.Option_mods_size =
+				sizeof (efb_option_xvr_100)
+						/ sizeof (fbopt_descr_t);
+			fbvar->propt_fn        = &efb_propt_fn_xvr_100[0];
+		} else {
+			/*
+			 * XVR-300[x8]
+			 */
+			device->max_streams    = 2;  /* 'a'|'b' suffixes */
+
+			fbvar->usage_text_body = efb_usage_text_body_xvr_300;
+			fbvar->fbc_option      = &efb_option_xvr_300[0];
+			fbvar->xf86_entry_mods.Option_mods_size =
+				sizeof (efb_option_xvr_300)
+						/ sizeof (fbopt_descr_t);
+			fbvar->propt_fn        = &efb_propt_fn_xvr_300[0];
+		}
+		free(full_model_name);
+	}
+
+	return (FBC_SUCCESS);
+
+}	/* SUNWefb_get_properties() */
+
+
+/* End of efb_properties.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efb_properties.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * efb_properties - efb device-specific properties
+ */
+
+
+#ifndef	_EFB_PROPERTIES_H
+#define	_EFB_PROPERTIES_H
+
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+
+
+extern fbc_api_ver_t SUNWefb_api_version; /* libSUNWefb_conf API version */
+
+
+int SUNWefb_get_properties(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar);	/* Updated fbconf_xorg properties */
+
+
+#endif	/* _EFB_PROPERTIES_H */
+
+
+/* End of efb_properties.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efb_query_device.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * efb_query_device - Query the efb frame buffer device
+ */
+
+#include <sys/int_types.h>	/* uint8_t, uint32_t */
+#include <errno.h>		/* errno */
+#include <stdio.h>		/* NULL */
+#include <stdlib.h>		/* malloc() */
+#include <string.h>		/* memset(), strdup(), strerror() */
+#include <unistd.h>		/* ioctl(), sleep() */
+
+#include <sys/fbio.h>		/* cg6_info, fbgattr */
+
+#include "gfx_common.h"		/* Model name, part number, cur video mode */
+
+#include "sun_edid.h"		/* EDID data parsing */
+
+#if 0
+#include "efbio.h"		/* efb I/O, including ioctl() stuff */
+#endif
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_mode_list.h"	/* List of Modes from the config file */
+#include "fbc_query_device.h"	/* Query a frame buffer device */
+
+#include "efb_query_device.h"	/* Query the efb frame buffer device */
+
+
+/*
+ * efb_get_edid_data()
+ *
+ *    Query the frame buffer device for EDID data.  Return zero upon
+ *    success, along with the EDID data, etc.  In the event of an error,
+ *    display an error message and return the errno code and a NULL
+ *    data pointer.
+ */
+
+int
+efb_get_edid_data(
+	int		device_fd,	/* Device file descriptor number */
+	gfx_edid_t	*edid)		/* EDID data, etc. */
+{
+	int		i;		/* Retry loop counter */
+
+	/*
+	 * Get the EDID data for this video stream's display device
+	 *
+	 *    If the display device had been powered down, it may take a
+	 *    few seconds to come up (Bug 4962976).
+	 */
+#define	GET_EDID_RETRIES 3		/* # of ioctl(EFB_GET_EDID) retries */
+	for (i = GET_EDID_RETRIES; ; i -= 1) {
+	        if (ioctl(device_fd, GFX_IOCTL_GET_EDID, edid) >= 0) {
+			break;
+		}
+		if (i <= 0) {
+			edid->length = 0;
+			edid->data   = NULL;
+			return (errno);	/* EDID data is unavailable */
+		}
+		sleep(1);
+	}
+
+	return (0);
+
+}	/* efb_get_edid_data() */
+
+
+/*
+ * efb_get_edid_res_info()
+ *
+ *    For each video stream indicated by the effective -dev option,
+ *    retrieve the EDID data from the display device and return the
+ *    following information:
+ *      * Manufacturer ID
+ *      * Product Code
+ *      * Pointer to a dynamically allocated array of supported video
+ *        mode name strings w/ preferred video mode in first element
+ *    The display device information is returned in the
+ *    edid_res_info[FBC_MAX_STREAMS] array.
+ */
+
+void
+efb_get_edid_res_info(
+	const fbc_dev_t *device,	/* Frame buffer device info (-dev) */
+	fbc_mode_elem_t	*mode_list,	/* Modes from Monitor section of cfg */
+	fbc_edid_res_t	edid_res_info[]) /* Returned display device info */
+{
+	const int	efb_stream[2] = {
+		GFX_EDID_HEAD_ONE,		/* Video stream 1 bit */
+		GFX_EDID_HEAD_TWO		/* Video stream 2 bit */
+	};
+	gfx_edid_t	edid;		/* EDID data, etc. */
+	uint8_t		edid_data[4096]; /* EDID blocks (128 bytes each) */
+	uint32_t	serial_num;	/* ID Serial Number (ignored) */
+	int		stream_index;	/* Video stream index (zero-based) */
+
+	memset(edid_res_info, 0, sizeof (fbc_edid_res_t) * FBC_MAX_STREAMS);
+
+	/*
+	 * Get the EDID -res information for the indicated streams (-dev)
+	 */
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+		/*
+		 * Get the EDID data for this video stream's display device
+		 */
+		edid.head = efb_stream[stream_index];
+		edid.length = sizeof (edid_data);
+		edid.data   = (caddr_t)edid_data;
+		if ((efb_get_edid_data(device->fd, &edid) != 0)
+		    || (sun_edid_check_base((uint8_t *)edid.data, edid.length) != 0)) {
+			continue;
+		}
+
+		/*
+		 * Extract the -res related data for this display device
+		 */
+		sun_edid_vendor((uint8_t *)edid.data,
+				edid_res_info[stream_index].manufacturer_id,
+				&edid_res_info[stream_index].product_code,
+				&serial_num);
+		edid_res_info[stream_index].video_mode =
+		    sun_edid_video_modes((uint8_t *)edid.data, edid.length, mode_list);
+	}
+
+}	/* efb_get_edid_res_info() */
+
+
+/* End of efb_query_device.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efb_query_device.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * efb_query_device - Query the efb frame buffer device
+ */
+
+
+#ifndef _EFB_QUERY_DEVICE_H
+#define	_EFB_QUERY_DEVICE_H
+
+
+#include "efbio.h"		/* efb I/O, including ioctl() stuff */
+
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_mode_list.h"	/* List of Modes from Monitor section of cfg */
+#include "fbc_query_device.h"	/* Query a frame buffer device */
+
+
+int efb_get_edid_data(
+	int		device_fd,	/* Device file descriptor number */
+	efb_edid_t	*edid);		/* EDID data, etc. */
+
+void efb_get_edid_res_info(
+	const fbc_dev_t *device,	/* Frame buffer device info (-dev) */
+	fbc_mode_elem_t	*mode_list,	/* Modes from Monitor section of cfg */
+	fbc_edid_res_t	edid_res_info[]); /* Returned display device info */
+
+
+#endif	/* _EFB_QUERY_DEVICE_H */
+
+
+/* End of efb_query_device.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efb_res_try_now.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,422 @@
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * efb_res_try_now - Video mode setting (-res try now)
+ */
+
+#pragma ident	"@(#)efb_res_try_now.c	1.2	09/02/18 15:41:28 SMI"
+
+#include <sys/types.h>		/* u_char, uint32_t */
+#include <ctype.h>		/* toupper() */
+#include <stdio.h>		/* printf(), sscanf() */
+#include <signal.h>		/* signal() */
+#include <termios.h>		/* tcgetattr(), tcsetattr() */
+#include <unistd.h>		/* alarm(), read() */
+
+#include "gfx_common.h"
+
+#if TRY_RES_NOW
+#if (0)	/* Preferred implementation */
+#include "efbio.h"		/* efb I/O, including ioctl() stuff */
+#include "regdef.h"		/* CRTC*_PITCH, ... */
+
+#include "libefb_int.h"		/* Radeon_*(), regr*(), regw*(), ... */
+#else	/* Sufficient implementation */
+/* n-bit register read/write (offset, value) */
+#define	regr(o)		(*(volatile uint32_t *)(registers + (o)))
+#define	regr16(o)	(*(volatile uint16_t *)(registers + (o)))
+#define	regr8(o)	(*(volatile uint8_t *)(registers + (o)))
+#define	regw(o,v)	(regr(o) = (v))
+#define	regw16(o,v)	(regr16(o) = (v))
+#define	regw8(o,v)	(regr8(o) = (v))
+/* Radeon API functions */
+#include "libefb.h"		/* Radeon_*(), ... */
+#endif	/* Prefficient, suferred implementation */
+#endif /* TRY_RES_NOW */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_ask.h"		/* User interaction */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_res.h"		/* Video modes/resolutions (-res option) */
+
+#include "efb_res_try_now.h"	/* Video mode setting (-res try now) */
+
+
+#define	EFB_MAX_STREAMS	2
+
+#define	_LIVE_		0	/* Live run */
+
+
+static const int	efb_stream_bit[EFB_MAX_STREAMS] = {
+	GFX_EDID_HEAD_ONE,		/* Video stream 1 bit */
+	GFX_EDID_HEAD_TWO		/* Video stream 2 bit */
+};
+
+
+/*
+ * efb_res_mode_try_stop()
+ *
+ *    Signal handler for the duration of the video mode trial.
+ */
+
+static
+void
+efb_res_mode_try_stop(
+	int		signum)		/* Signal number */
+{
+
+	/* Void */
+
+}	/* efb_res_mode_try_stop() */
+
+
+/*
+ * efb_res_mode_try()
+ *
+ *    Conduct a 10-second trial of the new video mode for the user's
+ *    approval (-res <video_mode> try).  Return TRUE iff the trial is
+ *    successful.
+ */
+
+int
+efb_res_mode_try(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_video_mode_t *video_mode)	/* Video mode (-res <video_mode>) */
+{
+	int rval = TRUE;
+
+#if TRY_RES_NOW
+#if _LIVE_
+	const int	crtc_pitch_off[EFB_MAX_STREAMS] = {
+		CRTC_PITCH,		/* Stream 1 pitch register offset */
+		CRTC2_PITCH		/* Stream 2 pitch register offset */
+	};
+	const int	crtc_offset_off[EFB_MAX_STREAMS] = {
+		CRTC_OFFSET,		/* Stream 1 offset register offset */
+		CRTC2_OFFSET		/* Stream 2 offset register offset */
+	};
+#endif
+
+	EfbInfo		*fb_info; 	/* Frame buffer information */
+	void		(*orig_disp[NSIG])(int); /* Original signal disp's */
+	struct termios	tparm_old;	/* Original terminal parameters */
+	struct termios	tparm_new;	/* Video trial terminal parameters */
+	int		input_size;	/* Stdin keystroke count (0 or 1) */
+	char		input_buf[4];	/* Stdin keystroke buffer */
+	int		rval = TRUE;	/* TRUE => Successful trial so far */
+	CRTCInfoBlock	video[EFB_MAX_STREAMS];
+	int		depth[EFB_MAX_STREAMS];
+	uint32_t	crtc_pitch_val[EFB_MAX_STREAMS];
+	uint32_t	crtc_offset_val[EFB_MAX_STREAMS];
+	volatile u_char	*registers;	/* Ptr to registers (regr(), regw()) */
+
+	uint32_t	offset[EFB_MAX_STREAMS];
+	int		stream_index;	/* Video stream index (zero-based) */
+
+	/*
+	 * Get the frame buffer information
+	 */
+#if (_LIVE_)	// ???
+	fb_info = efb_openfd(device->fd);
+	if (fb_info == NULL) {
+		return (FALSE);
+	}
+
+	/*
+	 * Point to the (volatle) registers
+	 */
+	registers = fb_info->registers;
+
+	/*
+	 * Get the current hardware video mode for each applicable stream
+	 */
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+		Radeon_GetMode(fb_info,
+				efb_stream_bit[stream_index],
+				&video[stream_index],
+				&depth[stream_index]);
+		crtc_pitch_val[stream_index]  =
+				regr(crtc_pitch_off[stream_index]);
+		crtc_offset_val[stream_index] =
+				regr(crtc_offset_off[stream_index]);
+	}
+
+#endif	// ???
+	/*
+	 * Ask whether the user is ready to try the new video mode
+	 */
+	printf("About to change video resolution to \"%s\" for %d seconds\n",
+		video_mode->name, FBC_TRIAL_TIME);
+	if (!fbc_ask_yes_no("Continue (yes/no) ? ")) {
+		return (FALSE);
+	}
+
+	/*
+	 * Set a new signal handler, saving the original signal dispositions
+	 *
+	 *    SIGHUP     Hangup
+	 *    SIGINT     Interrupt
+	 *    SIGQUIT    Quit
+	 *    SIGBUS     Bus Error
+	 *    SIGSEGV    Segmentation Fault
+	 *    SIGPIPE    Broken Pipe
+	 *    SIGALRM    Alarm Clock
+	 *    SIGTERM    Terminated
+	 *    SIGVTALRM  Virtual Timer Expired
+	 */
+	orig_disp[SIGHUP]    = signal(SIGHUP,    efb_res_mode_try_stop);
+	orig_disp[SIGINT]    = signal(SIGINT,    efb_res_mode_try_stop);
+	orig_disp[SIGQUIT]   = signal(SIGQUIT,   efb_res_mode_try_stop);
+	orig_disp[SIGBUS]    = signal(SIGBUS,    efb_res_mode_try_stop);
+	orig_disp[SIGSEGV]   = signal(SIGSEGV,   efb_res_mode_try_stop);
+	orig_disp[SIGPIPE]   = signal(SIGPIPE,   efb_res_mode_try_stop);
+	orig_disp[SIGALRM]   = signal(SIGALRM,   efb_res_mode_try_stop);
+	orig_disp[SIGTERM]   = signal(SIGTERM,   efb_res_mode_try_stop);
+	orig_disp[SIGVTALRM] = signal(SIGVTALRM, efb_res_mode_try_stop);
+
+	/*
+	 * Set the new video mode for all applicable display devices
+	 */
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+#if (_LIVE_)	// ???
+		fb_info->stream = efb_stream_bit[stream_index];
+		offset[stream_index] = Radeon_GetMemory(device->fd,
+							video_mode->width,
+							video_mode->height,
+							depth[stream_index],
+							0);
+		if (offset[stream_index] == (uint32_t)-1) {
+			offset[stream_index] = 0;
+		}
+		if (efb_set_named_mode(fb_info,
+					video_mode->name,
+					depth[stream_index],
+					offset[stream_index]) != 0) {
+			char monitor_id[FBC_MAX_MONITOR_ID_LEN];
+
+			fbc_get_monitor_id(
+					device, stream_index, &monitor_id[0]);
+			fbc_errormsg("Cannot set video mode for monitor%s!\n",
+					monitor_id);
+			rval = FALSE;
+		}
+#endif	// ???
+	}
+
+	if (rval) {
+		/*
+		 * Clear each screen after changing the video mode
+		 */
+		for (stream_index = device->stream_lo;
+		    stream_index <= device->stream_hi;
+		    stream_index += 1) {
+			int pitch;
+#if (_LIVE_)	// ???
+			pitch = regr(crtc_pitch_off[stream_index]) * 8;
+			if (offset[stream_index] == 0) {
+				offset[stream_index] =
+						crtc_offset_val[stream_index];
+			}
+			memset((void *)(fb_info->fb_mem + offset[0]/*???*/),
+				0,
+				pitch * video_mode->height);
+#endif	// ???
+		}
+
+		/*
+		 * Put the terminal's standard input into raw mode
+		 */
+		tcgetattr(0, &tparm_old);
+		tparm_new = tparm_old;
+		tparm_new.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE |
+					ECHOK | ECHONL | ECHOCTL | ECHOPRT |
+					ECHOKE);
+		tparm_new.c_cc[VMIN]  = 0;
+		tparm_new.c_cc[VTIME] = (FBC_TRIAL_TIME * 10);
+		tcsetattr(0, TCSANOW, &tparm_new);
+
+		/*
+		 * Wait for a user keystroke or for the timer to expire
+		 */
+		alarm(FBC_TRIAL_TIME + 1);  /* In case VTIME doesn't work */
+		input_size = read(0, input_buf, 1);
+		alarm(0);
+
+		/*
+		 * Restore the terminal's original standard input parameters
+		 */
+		tcsetattr(0, TCSANOW, &tparm_old);
+	}
+
+	/*
+	 * Restore the original signal dispositions
+	 */
+	signal(SIGHUP,    orig_disp[SIGHUP]);
+	signal(SIGINT,    orig_disp[SIGINT]);
+	signal(SIGQUIT,   orig_disp[SIGQUIT]);
+	signal(SIGBUS,    orig_disp[SIGBUS]);
+	signal(SIGSEGV,   orig_disp[SIGSEGV]);
+	signal(SIGPIPE,   orig_disp[SIGPIPE]);
+	signal(SIGALRM,   orig_disp[SIGALRM]);
+	signal(SIGTERM,   orig_disp[SIGTERM]);
+	signal(SIGVTALRM, orig_disp[SIGVTALRM]);
+
+	/*
+	 * Restore the original video mode for the applicable display devices
+	 */
+#if (_LIVE_)	// ???
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+		/* For Radeon_SetModeNB*() declarations, see libefb.h */
+		typedef int Radeon_SetModeNBi_t(
+					EfbInfo		*fb_info,
+					int		xres,
+					int		yres,
+					int		depth,
+					const CRTCInfoBlock *paramtable,
+					uint32_t	offset);
+		Radeon_SetModeNBi_t *Radeon_SetModeNBi[] = {
+			&Radeon_SetModeNB1,
+			&Radeon_SetModeNB2
+		};
+
+		(void) Radeon_SetModeNBi[stream_index](
+					    fb_info,
+					    video[stream_index].width,
+					    video[stream_index].height,
+					    depth[stream_index],
+					    &video[stream_index],
+					    crtc_offset_val[stream_index]);
+		regw(crtc_pitch_off[0], crtc_pitch_val[0]);
+	}
+
+	efb_closefd(fb_info);
+#endif	// ???
+
+	if (rval) {
+		/*
+		 * Interpret the user input character or absence thereof
+		 *
+		 *    Treat the absence of user input as noncommittal.
+		 *    Treat Newline or Carriage Return (but not Space,
+		 *    etc. by historical precedent) as noncommittal.
+		 *    Treat 'Y' or 'y' as affirmative.
+		 *    Treat 'N' or 'n' or anything else (by historical
+		 *    precedent) as negative.
+		 */
+		if ((input_size == 0) ||
+		    (input_buf[0] == '\n') || (input_buf[0] == '\r')) {
+			/*
+			 * Still need a Yes/No response from the user
+			 */
+			rval = fbc_ask_yes_no(
+			"Do you want %s to become the new setting (yes/no) ? ",
+						video_mode->name);
+		} else
+		if (toupper(input_buf[0]) != 'Y') {
+			rval = FALSE;		/* Treat as 'N' or 'n' */
+		}
+	}
+
+	/*
+	 * Return, indicating whether the trial was successful
+	 */
+	return (rval);
+
+#endif /* TRY_RES_NOW */
+
+	return (rval);
+
+}	/* efb_res_mode_try() */
+
+
+/*
+ * efb_res_mode_now()
+ *
+ *    Set the new video mode now (-res <video_mode> now).
+ */
+
+int
+efb_res_mode_now(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_video_mode_t *video_mode)	/* Video mode (-res <video_mode>) */
+{
+/*???*/	const unsigned int depth = 24;	/* From nfb & pfb for Solaris 8 & 9 */
+
+#if TRY_RES_NOW
+
+	EfbInfo		*fb_info;	/* Frame buffer information */
+	int		error_code;	/* Error code (FBC_ERR_xxxxx) */
+	int		stream_index;	/* Video stream index (zero-based) */
+
+	error_code = FBC_SUCCESS;
+
+	fb_info = efb_openfd(device->fd);
+	if (fb_info == NULL) {
+		return (FBC_ERR_OPEN);
+	}
+
+	printf("Setting \"%s\"\n", video_mode->name);
+
+	/*
+	 * Let the driver know (??? that we've begun setting this mode ???)
+	 */
+	(void) ioctl(device->fd, EFB_BEGIN_SETVIDEOMODE, 0);
+
+	/*
+	 * Set the video mode for each applicable display device
+	 */
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+		fb_info->stream = efb_stream_bit[stream_index];
+		if (efb_set_named_mode(fb_info, video_mode->name, depth, 0)
+					!= 0) {
+			error_code = FBC_ERR_IOCTL;
+		}
+	}
+
+	/*
+	 * Let the driver know (??? that we're finished setting this mode ???)
+	 */
+	(void) ioctl(device->fd, EFB_SETVIDEOMODE, 0);
+
+	efb_closefd(fb_info);
+
+	return (error_code);
+
+#endif /* TRY_RES_NOW */
+
+	return (FBC_SUCCESS);
+
+}	/* efb_res_mode_now() */
+
+
+/* End of efb_res_try_now.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efb_res_try_now.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * efb_res_try_now - Video mode setting (-res try now)
+ */
+
+#ifndef _EFB_RES_TRY_NOW_H
+#define	_EFB_RES_TRY_NOW_H
+
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+
+
+int efb_res_mode_try(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_video_mode_t *video_mode);	/* Video mode (-res <video_mode>) */
+
+int efb_res_mode_now(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_video_mode_t *video_mode);	/* Video mode (-res <video_mode>) */
+
+
+#endif	/* _EFB_RES_TRY_NOW_H */
+
+
+/* End of efb_res_try_now.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/efb/efbio.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 _EFBIO_H
+#define _EFBIO_H
+
+#include "gfx_common.h"
+
+#define EFB_GET_EDID_LENGTH	GFX_IOCTL_GET_EDID_LENGTH
+#define EFB_GET_EDID		GFX_IOCTL_GET_EDID
+
+#define EFB_STREAM_ONE		GFX_EDID_HEAD_ONE
+#define EFB_STREAM_TWO		GFX_EDID_HEAD_TWO
+
+typedef gfx_edid_t efb_edid_t;
+
+#endif /* _EFBIO_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc - Common fbconf_xorg(1M) definitions
+ */
+
+#ifndef	_FBC_H
+#define	_FBC_H
+
+
+/*
+ * Boolean data type  (mapped onto int)
+ */
+#ifndef	FALSE
+#define	FALSE	(0 != 0)	/* Boolean False */
+#endif
+#ifndef	TRUE
+#define	TRUE	(!FALSE)	/* Boolean True */
+#endif
+
+/*
+ * Current API version used between fbconf_xorg(1M) and libSUNW*_conf.so
+ */
+typedef	unsigned long fbc_api_ver_t;	/* fbconf_xorg(1M) API version type */
+
+#define	FBC_API_VERSION	((fbc_api_ver_t)(1)) /* fbconf_xorg(1M) API version */
+
+#define	FBC_API_VERSION_FMT "%s_api_version" /* API version symbol format */
+
+/*
+ * Home directory for fbconfig software
+ */
+#define	FBC_LIB_DIR	"/usr/lib/fbconfig"	/* fbconfig software dir */
+#define	FBC_LIB_NAME_FMT "lib%s_conf.so"
+#define	FBC_LIB_PATH_FMT FBC_LIB_DIR "/" FBC_LIB_NAME_FMT
+
+/*
+ * Frame buffer device file names  (/dev/fb, /dev/fbs/[a-z]fb[0-9][ab]?)
+ */
+#define	FBC_DEVICE_SYMLINK_DIR	"/dev"		/* Device symlink directory */
+#define	FBC_DEVICE_SYMLINK_NAME	"fb"		/* Device symlink name */
+#define	FBC_DEVICE_SYMLINK_NAME_0 \
+			FBC_DEVICE_SYMLINK_NAME "0"
+#define	FBC_DEVICE_SYMLINK_PATH	\
+			FBC_DEVICE_SYMLINK_DIR "/" FBC_DEVICE_SYMLINK_NAME
+#define	FBC_DEVICE_SYMLINK_PATH_0 \
+			FBC_DEVICE_SYMLINK_DIR "/" FBC_DEVICE_SYMLINK_NAME_0
+
+#define	FBC_DEVICE_DIR		"/dev/fbs"	/* Graphics device directory */
+
+#define	FBC_MAX_DEV_PATH_LEN	128	/* Max device pathname length */
+
+#define	FBC_STREAM_SUFFIX_CHARS	"ab"	/* Device name stream suffix chars */
+#define	FBC_MAX_STREAMS		2	/* Max streams supported */
+
+/*
+ * Masks for stat_buf.st_rdev member  (fbc_open_device(), fbc_open_master())
+ */
+#define	FBC_CLONE_MASK	0xFF00		/* Inverted to discard clone bits */
+#define	FBC_MINOR_MASK	0xFFFF		/* Inverted to get major/type bits */
+
+/*
+ * Configuration file location  (-file machine|system|<pathname>)
+ */
+#define	FBC_FILE_KEYWD_MACHINE	"machine"
+#define	FBC_FILE_PATH_MACHINE	"/etc/X11/xorg.conf"
+
+#define	FBC_FILE_KEYWD_SYSTEM	"system"
+#define	FBC_FILE_PATH_SYSTEM	"/usr/X11/xorg.conf"
+
+#define	FBC_DEFAULT_CONFIG_LOC	FBC_FILE_KEYWD_MACHINE	/* "machine" */
+
+/*
+ * New configuration file modes (644) and ownership (root.root)
+ */
+#define	FBC_CONFIG_FILE_MODE	(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+#define	FBC_CONFIG_FILE_UID	(0)	/* root */
+#define	FBC_CONFIG_FILE_GID	(0)	/* root */
+
+/*
+ * Default gamma (-g) value
+ */
+#define	FBC_GAMMA_DEFAULT	2.22	/* ??? Officially defined where ??? */
+#define	FBC_GAMMA_DEFAULT_STR "2.22"
+
+#define	GAMMA_TABLE_EXT	".gamma"	/* Packed gamma table file extension */
+
+
+/*
+ * Video mode properties (from -res <video_mode>, xorg.conf, and/or EDID)
+ */
+#define	FBC_MAX_MODE_NAME_LEN	256	/* Max mode name length (arbitrary) */
+
+typedef struct {
+	const char	*name;		/* Ptr to video mode name string */
+	int		width;		/* Horizontal addressable pixels */
+	int		height;		/* Vertical addressable lines */
+	int		frequency;	/* Vertical frequency */
+} fbc_video_mode_t;
+
+
+/*
+ * Seconds of new video mode trial for the "-res <video-mode> try" option
+ */
+#define	FBC_TRIAL_TIME	10
+
+
+/*
+ * Line indentation used with -prconf and -propt
+ */
+#define	FBC_PR_INDENT	"    "		/* Four Spaces (columns) */
+#define	FBC_PR_INDENT_LEN (sizeof(FBC_PR_INDENT) - 1) /* Columns (w/o Nul) */
+
+
+#endif	/* _FBC_H */
+
+
+/* End of fbc.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_Device.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,436 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_Device - Edit Device sections
+ */
+
+
+#include <assert.h>		/* assert() */
+#include <stdio.h>		/* NULL */
+#include <stdlib.h>		/* free() */
+#include <string.h>		/* strcmp(), strlen() */
+
+#include "xf86Parser.h"		/* Public function, etc. declatations */
+#include "configProcs.h"	/* Private function, etc. declarations */
+
+#include "fbc_xorg.h"		/* Edit config file data representations */
+#include "fbc_Device.h"		/* Edit Device sections */
+#include "fbc_Option.h"		/* Edit Option lists */
+#include "fbc_Screen.h"		/* Edit Screen sections */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+#include "fbc_query_device.h"	/* Query a frame buffer device */
+#include "fbc_write_config.h"	/* Write an updated config file */
+
+
+/*
+ * fbc_find_active_Device_section()
+ *
+ *    Find the first Device section that refers to the specified device.
+ *
+ *    This Device section must have a matching driver name and screen
+ *    number.  It should have a matching device pathname, unless the
+ *    pathname is not contained in any Device section.  In that case,
+ *    the Device section must be the first qualifying one that has no
+ *    device pathname ("Device" Option entry).
+ *
+ *        Driver      "<driver>"
+ *        Screen      <number>
+ *        Option      "Device" "<device_pathname>"
+ *
+ *    According to the XF86Config(5) (and xorg.conf(4)) man page, "A
+ *    Device section is considered active if it is referenced by an
+ *    active Screen section."  This reflects a top-down analysis of
+ *    "activeness."  Because fbconf_xorg(1M) is given a device name as a
+ *    starting point for the analysis, we start with the matching Device
+ *    section and go bottom-up.
+ *
+ *    We can't know whether a given Device section will become active
+ *    at execution time.  Even if we could guess which ServerLayout
+ *    section and Screen section are likely to be active, the -screen
+ *    command line option could still be used to override our best
+ *    guess.
+ *
+ *    (Compare this function with xf86findDevice() in Device.c.)
+ */
+
+XF86ConfDevicePtr
+fbc_find_active_Device_section(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	XF86ConfDevicePtr conf_device_lst, /* Head of Device section list */
+	int		stream_num)	/* Device stream/screen number */
+{
+	XF86ConfDevicePtr blank_dev_sectn_ptr; /* Matching sect w/o "Device" */
+	XF86ConfDevicePtr dev_sectn_ptr; /* Ptr to current Device section */
+	XF86OptionPtr	option_ptr;	/* Ptr to current Option entry */
+
+	/*
+	 * Search each Device section for the specified device
+	 *
+	 *    Ideally we'll find a Device section containing the
+	 *    matching device pathname in a "Device" Option.  Failing
+	 *    that, we'll settle for the first Device section having a
+	 *    matching driver name and stream/screen number and no
+	 *    "Device" option.
+	 */
+	blank_dev_sectn_ptr = NULL;
+	for (dev_sectn_ptr = conf_device_lst;
+	    dev_sectn_ptr != NULL;
+	    dev_sectn_ptr = dev_sectn_ptr->list.next) {
+		/*
+		 * Compare the device driver name and stream/screen numbers
+		 *
+		 *    If the Screen entry has been omitted, the value of
+		 *    the dev_screen member defaults to zero.
+		 */
+		if ((strcmp(device->type, dev_sectn_ptr->dev_driver) != 0) ||
+		    (stream_num != dev_sectn_ptr->dev_screen)) {
+			continue;
+		}
+
+		/*
+		 * Search this section's Option list for a "Device" entry
+		 */
+		for (option_ptr = dev_sectn_ptr->dev_option_lst;
+		    ;
+		    option_ptr = option_ptr->list.next) {
+			/*
+			 * Remember first Device section w/o a "Device" entry
+			 */
+			if (option_ptr == NULL) {
+				if (blank_dev_sectn_ptr == NULL) {
+					blank_dev_sectn_ptr = dev_sectn_ptr;
+				}
+				break;	/* Reached end of Option list */
+			}
+
+			/*
+			 * See if this is a "Device" Option w/ a matching path
+			 */
+			if (xf86nameCompare(option_ptr->opt_name,
+					    FBC_KEYWD_Device) == 0) {
+				if (strcmp(option_ptr->opt_val, device->path)
+						== 0) {
+					/*
+					 * This section has the device pathname
+					 */
+					return (dev_sectn_ptr);
+				}
+				break;	/* Can have only one "Device" entry */
+			}
+		}
+	}
+
+	/*
+	 * A matching Device section with no "Device" Option should have one
+	 *
+	 *    No active sections have been recorded yet, so it's early
+	 *    to be inserting a "Device" Option into the active Device
+	 *    section.  We'll just cobble a temporary xf86_active_t
+	 *    structure, check sanity, and charge the windmill.
+	 *
+	 *    By intent, this change to the in-memory configuration will
+	 *    be discarded unless the user has provided a command line
+	 *    option that causes the configuration file to be updated.
+	 */
+	if (blank_dev_sectn_ptr != NULL) {
+		xf86_active_t	active;	/* Active config sections for device */
+
+		assert(FBC_SECTN_Device == FBC_SECTION_Device);
+
+		active.device_sectn = blank_dev_sectn_ptr;
+		fbc_set_Option_value(&active,
+					FBC_SECTN_Device,
+					FBC_KEYWD_Device,
+					device->path);
+	}
+
+	/*
+	 * Return with a matching Device section, else NULL
+	 */
+	return (blank_dev_sectn_ptr);
+
+}	/* fbc_find_active_Device_section() */
+
+
+/*
+ * fbc_insert_new_Device_section()
+ *
+ *    Insert a new, mostly empty Device section in the configuration at
+ *    the specified location.
+ *
+ *        Section "Device"
+ *            Identifier  "<device_identifier>"
+ *            Driver      "<driver>"
+ *            VendorName  "Sun Microsystems, Inc."
+ *            BoardName   "Sun <board> Graphics Accelerator"
+ *            Option      "Device" "<device_pathname>"
+ *        EndSection
+ *        <blank line>
+ *
+ *    Note that the Device section identifier string, dev_identifier,
+ *    has been dynamically allocated by our caller.
+ */
+
+static
+int
+fbc_insert_new_Device_section(
+	XF86ConfigPtr	configIR,	/* Config Internal Representation */
+	fbc_line_elem_t *next_line_er,	/* Line ER following insertion point */
+	char		*dev_identifier, /* Device section identifier */
+	const char	*dev_driver,	/* Device Driver value */
+	const char	*dev_vendor,	/* Device VendorName, else NULL */
+	const char	*dev_board,	/* Device BoardName, else NULL */
+	const char	*device_path,	/* Device pathname value */
+	XF86ConfDevicePtr *device_ptr)	/* Ptr to new Device section IR */
+{
+
+	/*
+	 * Allocate and initialize the Internal Rep for a new Device section
+	 *
+	 *    The dev_identifier string has been allocated already.
+	 */
+	*device_ptr = xf86confcalloc(1, sizeof (XF86ConfDeviceRec));
+	if (*device_ptr == NULL) {
+		return (FBC_ERR_NOMEM);
+	}
+
+	(*device_ptr)->dev_identifier = dev_identifier;
+	(*device_ptr)->dev_driver = xf86configStrdup(dev_driver);
+	if (dev_vendor != NULL) {
+		(*device_ptr)->dev_vendor = xf86configStrdup(dev_vendor);
+	}
+	if (dev_board != NULL) {
+		(*device_ptr)->dev_board = xf86configStrdup(dev_board);
+	}
+	if ((*device_ptr)->dev_driver == NULL) {
+		xf86conffree(device_ptr);
+		return (FBC_ERR_NOMEM);
+	}
+
+	/*
+	 * Insert the External Representation data for the Device section
+	 */
+	/*  Section "Device"  */
+	(void) fbc_insert_line_ER(
+			next_line_er,
+			*device_ptr,
+			(xf86_print_fn_t *)&xf86printDeviceSectionSection,
+			FBC_INDENT_0);
+
+	/*  Identifier "<device_identifier>"  */
+	(void) fbc_insert_line_ER(
+			next_line_er,
+			*device_ptr,
+			(xf86_print_fn_t *)&xf86printDeviceSectionIdentifier,
+			FBC_INDENT_1);
+
+	/*  Driver "<driver>"  */
+	(void) fbc_insert_line_ER(
+			next_line_er,
+			*device_ptr,
+			(xf86_print_fn_t *)&xf86printDeviceSectionDriver,
+			FBC_INDENT_1);
+
+	/*  VendorName "Sun Microsystems, Inc."  */
+	if ((*device_ptr)->dev_vendor != NULL) {
+		(void) fbc_insert_line_ER(
+			next_line_er,
+			*device_ptr,
+			(xf86_print_fn_t *)&xf86printDeviceSectionVendorName,
+			FBC_INDENT_1);
+	}
+
+	/*  BoardName "Sun <board> Graphics Accelerator"  */
+	if ((*device_ptr)->dev_board != NULL) {
+		(void) fbc_insert_line_ER(
+			next_line_er,
+			*device_ptr,
+			(xf86_print_fn_t *)&xf86printDeviceSectionBoardName,
+			FBC_INDENT_1);
+	}
+
+	/*  EndSection  */
+	(*device_ptr)->dev_end_line_er =
+		fbc_insert_line_ER(
+			next_line_er,
+			*device_ptr,
+			(xf86_print_fn_t *)&xf86printDeviceSectionEndSection,
+			FBC_INDENT_0);
+
+	/*  <blank line>  */
+	(void) fbc_insert_line_ER(
+			next_line_er,
+			"\n",
+			(xf86_print_fn_t *)&fbc_print_config_text,
+			FBC_INDENT_0);
+
+	/*
+	 * Add the new Device section to the in-memory configuration
+	 */
+	configIR->conf_device_lst =
+		(XF86ConfDevicePtr) xf86addListItem(
+			(glp)configIR->conf_device_lst, (glp)configIR);
+
+	/*
+	 * Insert the Device Option entry  (see fbc_set_Option_value())
+	 */
+	(*device_ptr)->dev_option_lst = xf86addNewOptionOrValue(
+					(*device_ptr)->dev_option_lst,
+//??? xf86configStrdup() ???
+					"Device",
+//??? xf86configStrdup() ???
+					(char *)device_path,
+					0,	/* The "used" arg is unused */
+					(*device_ptr)->dev_end_line_er);
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_insert_new_Device_section() */
+
+
+/*
+ * fbc_insert_Device_section()
+ *
+ *    Insert a new, empty Device section in the configuration at the
+ *    specified location.
+ */
+
+int
+fbc_insert_Device_section(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar,		/* fbconf_xorg(1M) varient data */
+	XF86ConfigPtr	configIR,	/* Config Internal Representation */
+	fbc_line_elem_t *next_line_er,	/* Line ER following insertion point */
+	XF86ConfDevicePtr *device_ptr)	/* Ptr to new Device section IR */
+{
+	char		boardname_buf[1024]; /* BoardName entry value buffer */
+	char		*dev_boardname;	/* BoardName entry value string */
+	char		*dev_identifier; /* Device section identifier */
+	const char	*dev_vendor;	/* Device VendorName, else NULL */
+	int		error_code;	/* Error code */
+	const char	*format;	/* Format for sprintf() */
+	char		*full_model_name; /* Model name w/ "SUNW," prefix */
+	unsigned int	i;		/* Loop counter / uniqueness factor */
+
+	/*
+	 * Allocate memory for the new Device identifier string
+	 *
+	 *    Allocate space for the intended name and any extra
+	 *    underscore and decimal digits needed to make it unique.
+	 *    The number of digits will never be greater than the byte
+	 *    size of the loop counter, i, multiplied by three decimal
+	 *    digits per byte.
+	 */
+	dev_identifier = xf86confmalloc(strlen(device->name)
+					+ 1			/* "_" */
+					+ 3 * sizeof (i)	/* Digits */
+					+ 1);			/* Nul */
+	if (dev_identifier == NULL) {
+		return (FBC_ERR_NOMEM);
+	}
+
+	/*
+	 * Insure that the new Device section identifier will be unique
+	 */
+	format = "%s";
+	for (i = 0; ; ) {
+		XF86ConfDevicePtr dev_ptr; /* Ptr to existing Device section */
+
+		/*
+		 * Try the name alone and then the name with a numeric suffix
+		 */
+		sprintf(dev_identifier, format, device->name, i);
+		format = "%s_%u";
+
+		/*
+		 * Search for this name among the existing Device sections
+		 */
+		for (dev_ptr = configIR->conf_device_lst;
+		     dev_ptr != NULL;
+		     dev_ptr = dev_ptr->list.next) {
+			if (xf86nameCompare(dev_identifier,
+					    dev_ptr->dev_identifier) == 0) {
+				break;	/* Not unique */
+			}
+		}
+
+		/*
+		 * Stop when the name is unique (or if the loop counter wraps)
+		 */
+		i += 1;
+		if ((dev_ptr == NULL) || (i == 0)) {
+			break;		/* The name is unique enough */
+		}
+	}
+
+	/*
+	 * Generate the Device VendorName (and BoardName fmt), else NULL
+	 *
+	 *    If the full model name begins with a "SUNW," prefix (e.g.,
+	 *    "SUNW,XVR-2500") such that the simple board name occurs
+	 *    later in the string, we'll conclude that Sun Microsystems
+	 *    is indeed the vendor.
+	 */
+	full_model_name = fbc_get_fb_model_name(device->fd, &dev_boardname);
+
+	dev_vendor = NULL;
+	format     = "%s Graphics Accelerator";
+
+	if (dev_boardname > full_model_name) {
+		dev_vendor = "Sun Microsystems, Inc.";
+		format     = "Sun %s Graphics Accelerator";
+	}
+
+	/*
+	 * Generate the BoardName entry value string (else a NULL pointer)
+	 */
+	if (dev_boardname != NULL) {
+		snprintf(boardname_buf, sizeof (boardname_buf),
+			format, dev_boardname);
+		dev_boardname = &boardname_buf[0];
+	}
+
+	/*
+	 * Insert a new Device section into the in-memory configuration
+	 */
+	error_code = fbc_insert_new_Device_section(configIR,
+						    next_line_er,
+						    dev_identifier,
+						    device->type, /* Driver */
+						    dev_vendor,
+						    dev_boardname,
+						    device->path,
+						    device_ptr);
+	if (error_code != FBC_SUCCESS) {
+		xf86conffree(dev_identifier);
+	}
+	free (full_model_name);
+
+	return (error_code);
+
+}	/* fbc_insert_Device_section() */
+
+
+/* End of fbc_Device.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_Device.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_Device - Edit Device sections
+ */
+
+#ifndef	_FBC_DEVICE_H
+#define	_FBC_DEVICE_H
+
+
+#include "xf86Parser.h"		/* XF86ConfigPtr */
+
+#include "fbc_xorg.h"		/* Edit config file data representations */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+
+
+XF86ConfDevicePtr fbc_find_active_Device_section(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	XF86ConfDevicePtr conf_device_lst, /* Head of Device section list */
+	int		stream_num);	/* Device stream/screen number */
+
+int fbc_insert_Device_section(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar,		/* fbconf_xorg(1M) varient data */
+	XF86ConfigPtr	configIR,	/* Config Internal Representation */
+	fbc_line_elem_t *next_line_er,	/* Line ER following insertion point */
+	XF86ConfDevicePtr *device_ptr);	/* Ptr to new Device section IR */
+
+
+#endif	/* _FBC_DEVICE_H */
+
+
+/* End of fbc_Device.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_Modes.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,265 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_Modes - Edit Modes sections
+ */
+
+
+#include <stdio.h>		/* snprintf() */
+#include <stdlib.h>		/* exit() */
+
+#include "xf86Parser.h"		/* Public function, etc. declarations */
+#include "Configint.h"          /* xf86conffree(), xf86confmalloc() */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_Monitor.h"	/* Edit Monitor sections */
+#include "fbc_append_config.h"	/* Append configuration file supplement */
+#include "fbc_error.h"		/* Error reporting */
+
+
+/*
+ * fbc_append_Modes_sections()
+ *
+ *    Given a Monitor section and the name of a frame buffer device
+ *    type, try to provide the Monitor section with one or more Modes
+ *    sections, general and/or device-specific.  This may involve
+ *    reading sections from canned files and appending them to the
+ *    configuration.
+ *
+ *    Modes sections and supplemental config file pathnames might be:
+ *        "SunModes"    /usr/lib/fbconfig/SunModes_xorg.conf
+ *        "efbModes"    /usr/lib/fbconfig/efbModes_xorg.conf
+ *        "kfbModes"    /usr/lib/fbconfig/kfbModes_xorg.conf
+ *           ...           ...
+ *    Currently only SunModes is implemented.  Device-specific Modes
+ *    aren't felt to be necessary.
+ */
+
+int
+fbc_append_Modes_sections(
+	XF86ConfigPtr	configIR,	/* Ptr to configuration Internal Rep */
+	XF86ConfMonitorPtr monitor_sectn_ptr, /* Ptr to Monitor section IR */
+	const char	*device_type)	/* Device type name (e.g. "kfb") */
+{
+#if (0)	/* This is used to handle a device-specific Modes section */
+	char		dev_mode_name_buf[FBC_MAX_DEV_PATH_LEN]; /* Spacious */
+#endif
+	const char	**modes_name;	/* Current Modes section name */
+	const char	*modes_section_name[4]; /* Modes section names */
+	XF86ConfModesPtr modes_sectn_ptr; /* Ptr to Modes section IR */
+	XF86ConfModesPtr usemodes_sectn_ptr; /* Ptr to Modes section IR */
+
+	char		 *usemodes_name = "SunModes";
+	char		 device_modes_name[80];
+	int		 done = 0;
+
+	/*
+	 * Think of some well-known Modes sections that might be nice to have
+	 */
+
+	sprintf(device_modes_name, "%sSunModes", device_type);
+	modes_section_name[0] = device_modes_name;
+	modes_section_name[1] = "SunModes";
+	modes_section_name[2] = NULL;	/* End-of-table marker */
+
+#if (0)	/* This is how to implement a device-specific Modes section */
+	if (snprintf(dev_mode_name_buf, sizeof (dev_mode_name_buf), "%sModes",
+			device_type) < sizeof (dev_mode_name_buf)) {
+		modes_section_name[1] = dev_mode_name_buf;
+		modes_section_name[2] = NULL;	/* End-of-table marker */
+	}
+
+#endif	/* That was how to implement a device-specific Modes section */
+	/*
+	 * Search for each of the Modes section(s) named in our wish list
+	 */
+	modes_sectn_ptr =
+			xf86findModes(usemodes_name, configIR->conf_modes_lst);
+
+	for (modes_name = &modes_section_name[0];
+	    !done && *modes_name != NULL;
+	    modes_name += 1) {
+		/*
+		 * Search the existing configuration for the Modes section
+		 *
+		 *    A Modes section might already be present (e.g.
+		 *    "SunModes") because it's used with some other
+		 *    monitor.
+		 *
+		 *    The section may be present because it too is
+		 *    contained by the supplemental config file read
+		 *    during a previous iteration of this loop.
+		 *    Putting more than one section into a supplemental
+		 *    config file could be made to work for certain
+		 *    purposes, but currently that's not our intent.
+		 */
+		if (modes_sectn_ptr == NULL) 
+{
+			/*
+			 * Try a well-known file containing the Modes section
+			 */
+			if (fbc_append_config(configIR,	*modes_name) !=
+					FBC_SUCCESS) {
+				continue;	/* No Modes supplement file */
+			}
+
+			/*
+			 * Find the Modes section that was just appended
+			 */
+			modes_sectn_ptr = xf86findModes(usemodes_name,
+						    configIR->conf_modes_lst);
+			if (modes_sectn_ptr == NULL) {
+				/*
+				 * Something evil has been read into the config
+				 */
+				fbc_errormsg(
+		"Supplemental file does not contain Modes \"%s\" section\n",
+						*usemodes_name);
+				exit(FBC_EXIT_FAILURE);
+			}
+		}
+
+		/*
+		 * Insert the UseModes entry into the Monitor section
+		 */
+		usemodes_sectn_ptr = xf86findModes(usemodes_name, monitor_sectn_ptr->mon_modes_sect_lst);
+		if (usemodes_sectn_ptr == NULL) 
+		{
+			(void) fbc_insert_UseModes_entry(monitor_sectn_ptr,
+						modes_sectn_ptr);
+		}
+		done = 1;
+	}
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_append_Modes_sections() */
+
+
+/*
+ * fbc_trim_Modes_sections()
+ *
+ * remove all the modes in the SunModes section except the one specified in -res
+ *
+ * return TRUE if the specified mode is defined in the SunModes section
+ * else return FALSE
+ */
+int
+fbc_trim_Modes_sections(
+	XF86ConfigPtr	configIR,	/* Ptr to configuration Internal Rep */
+	char		*mode
+	)
+{
+	XF86ConfModesPtr modes_sectn_ptr; /* Ptr to Modes section IR */
+	XF86ConfModeLinePtr modes, ptr, next_mode_ptr, mode_ptr;
+	int status = FALSE;
+
+	modes_sectn_ptr = xf86findModes("SunModes", configIR->conf_modes_lst);
+	if (modes_sectn_ptr == NULL) 
+		return;
+
+	modes = modes_sectn_ptr->mon_modeline_lst;
+	ptr = modes;
+	mode_ptr = NULL;
+
+	while (ptr != NULL) {
+		next_mode_ptr = ptr->list.next;
+                if (xf86nameCompare(mode, ptr->ml_identifier) == 0) {
+			mode_ptr = ptr;
+		} else {
+                	TestFree (ptr->ml_identifier);
+                	TestFree (ptr->ml_comment);
+                	xf86conffree (ptr);
+		}
+		ptr = next_mode_ptr;
+	}
+
+	modes_sectn_ptr->mon_modeline_lst = mode_ptr;
+	if (mode_ptr) {
+		mode_ptr->list.next = NULL;
+		status = TRUE;
+	}
+
+	return status;
+}
+
+
+/*
+ * fbc_remove_monitor_sunmodes_section_ER()
+ *
+ * removes the external representation of the device specific SunModes section
+ */
+
+int
+fbc_remove_monitor_sunmodes_section_ER(
+	XF86ConfigPtr		configIR,
+        XF86ConfMonitorPtr 	monitor_sectn_ptr  /* Ptr to Monitor section IR */
+	)
+{
+	char modes_name[80];
+	XF86ConfModesPtr modes_sectn_ptr;
+        fbc_line_elem_t *line_er;                  /* Ptr to Extnl Rep of config line */
+
+	sprintf(modes_name, "SunModes_%s", monitor_sectn_ptr->mon_identifier);
+        modes_sectn_ptr = xf86findModes(modes_name, configIR->conf_modes_lst);
+	if (modes_sectn_ptr == NULL)
+		return;
+
+	/*
+	 * Remove the external representation of this mode section
+	 */
+	line_er = modes_sectn_ptr->begin_line_er;
+	while (line_er != modes_sectn_ptr->end_line_er) {
+		fbc_delete_line_ER(line_er);
+		line_er = line_er->next_ptr;
+	}
+	if (modes_sectn_ptr->end_line_er != NULL)
+		fbc_delete_line_ER(line_er);
+}
+
+
+/*
+ * fbc_remove_monitor_usemodes_entry_ER()
+ *
+ * removes the device specific use SunModes entry from the external representation
+ */
+
+int
+fbc_remove_monitor_usemodes_entry_ER(
+	XF86ConfigPtr		configIR,
+        XF86ConfMonitorPtr 	monitor_sectn_ptr  /* Ptr to Monitor section IR */
+	)
+{
+	char modes_name[80];
+	XF86ConfModesLinkPtr usemodes_ptr;
+
+	sprintf(modes_name, "SunModes_%s", monitor_sectn_ptr->mon_identifier);
+
+        usemodes_ptr = xf86findModes(modes_name, monitor_sectn_ptr->mon_modes_sect_lst);
+
+	if (usemodes_ptr != NULL) {
+		fbc_delete_line_ER(usemodes_ptr->line_er);
+	}
+}
+/* End of fbc_Modes.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_Modes.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_Modes - Edit Modes sections
+ */
+
+#ifndef	_FBC_MODES_H
+#define	_FBC_MODES_H
+
+
+#include "xf86Parser.h"		/* Public function, etc. declatations */
+
+
+int fbc_append_Modes_sections(
+	XF86ConfigPtr	configIR,	/* Ptr to configuration Internal Rep */
+	XF86ConfMonitorPtr monitor_sectn_ptr, /* Ptr to Monitor section IR */
+	const char	*device_type);	/* Device type name (e.g. "nfb") */
+
+int fbc_trim_Modes_sections(
+        XF86ConfigPtr   configIR,       /* Ptr to configuration Internal Rep */
+        char            *mode
+        );
+
+int
+fbc_remove_monitor_sunmodes_section_ER(
+        XF86ConfigPtr           configIR,
+        XF86ConfMonitorPtr      monitor_sectn_ptr  /* Ptr to Monitor section IR */
+        );
+
+int
+fbc_remove_monitor_sunmodes_section_ER(
+        XF86ConfigPtr           configIR,
+        XF86ConfMonitorPtr      monitor_sectn_ptr  /* Ptr to Monitor section IR */
+        );
+#endif	/* _FBC_MODES_H */
+
+
+/* End of fbc_Modes.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_Monitor.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,398 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_Monitor - Edit Monitor sections
+ */
+
+
+#include <stdio.h>		/* NULL */
+
+#include "xf86Parser.h"		/* Public function, etc. declarations */
+#include "Configint.h"		/* xf86conffree(), xf86confmalloc() */
+#include "configProcs.h"	/* Private function, etc. declarations */
+
+#include "fbc_xorg.h"		/* Edit config file data representations */
+#include "fbc_Monitor.h"	/* Edit Monitor sections */
+#include "fbc_Option.h"		/* Edit Option lists */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_line_er.h"	/* External Representation of config lines */
+#include "fbc_write_config.h"	/* Write an updated config file */
+
+
+/*
+ * fbc_find_Monitor_Mode()
+ *
+ *    Given a Monitor section pointer and the name of a ModeLine /
+ *    Mode-EndMode entry, return a pointer to the matching entry that is
+ *    available to this Monitor section.  "Available" means the entry is
+ *    contained either within the Monitor section or within a Modes
+ *    section named by a UseModes entry in the Monitor section.  Return
+ *    NULL if no available ModeLine / Mode-EndMode entry has that name.
+ *
+ *    Compare this function with xf86validateMonitor() in Monitor.c.
+ */
+
+XF86ConfModeLinePtr
+fbc_find_Monitor_Mode(
+	XF86ConfMonitorPtr monitor_sectn_ptr, /* Ptr to Monitor section IR */
+	const char	*mode_name)	/* ModeLine / Mode-EndMode name */
+{
+	XF86ConfModeLinePtr mlptr;	/* Ptr to ModeLine list entry */
+	XF86ConfModesLinkPtr modeslink;	/* Ptr to UseModes list entry */
+
+	/*
+	 * Search Monitior section for the named ModeLine / Mode-EndMode entry
+	 */
+	mlptr = xf86findModeLine(
+			mode_name, monitor_sectn_ptr->mon_modeline_lst);
+	if (mlptr != NULL) {
+		return (mlptr);		/* Found ModeLine / Mode-EndMode */
+	}
+
+	/*
+	 * Traverse the list of Modes sectns specified by any UseModes entries
+	 */
+	for (modeslink = monitor_sectn_ptr->mon_modes_sect_lst;
+	    modeslink != NULL;
+	    modeslink = modeslink->list.next) {
+		/*
+		 * Search Modes section for ModeLine / Mode-EndMode entry
+		 *
+		 *    Note that xf86validateMonitor() should already
+		 *    have translated the UseModes names to Modes
+		 *    sections links (modeslink->ml_modes), which is why
+		 *    we don't have to call xf86findModes().
+		 */
+		mlptr = xf86findModeLine(mode_name,
+				    modeslink->ml_modes->mon_modeline_lst);
+		if (mlptr != NULL) {
+			break;
+		}
+	}
+
+	return (mlptr);
+
+}	/* fbc_find_Monitor_Mode() */
+
+
+/*
+ * fbc_edit_Monitor_section()
+ *
+ *    Modify or insert Monitor section values to the Internal
+ *    Representation of the configuration file.
+ *        Gamma       <gamma_value>                   # -g <gamma_value>
+ *    #   Gamma       <gamma_red> <gamma_green> <gamma_blue>
+ */
+
+int
+fbc_edit_Monitor_section(
+	XF86ConfMonitorPtr monitor_sectn_ptr, /* Ptr to Monitor section IR */
+	xf86_ent_mod_t	*xf86_entry_mods) /* Config entry modifications */
+{
+
+	/*
+	 * Make any Gamma entry modification
+	 */
+	if (xf86_entry_mods->mon_gamma_red != FBC_NO_Gamma) {
+		monitor_sectn_ptr->mon_gamma_red   =
+					xf86_entry_mods->mon_gamma_red;
+		monitor_sectn_ptr->mon_gamma_green =
+					xf86_entry_mods->mon_gamma_green;
+		monitor_sectn_ptr->mon_gamma_blue  =
+					xf86_entry_mods->mon_gamma_blue;
+
+		/*
+		 * Edit the External Representation of the Gamma entry
+		 */
+		if (monitor_sectn_ptr->mon_gamma_red > 0.) {
+			/*
+			 * Insert or modify the line's External Representation
+			 */
+			fbc_edit_line_ER(&monitor_sectn_ptr->mon_gamma_line_er,
+					monitor_sectn_ptr->mon_end_line_er,
+					monitor_sectn_ptr,
+					(xf86_print_fn_t *)
+						&xf86printMonitorSectionGamma,
+					FBC_INDENT_1);
+		} else {
+			/*
+			 * Delete the Gamma line's External Representation
+			 */
+			fbc_delete_line_ER(
+					monitor_sectn_ptr->mon_gamma_line_er);
+		}
+	}
+
+	return (0);
+
+}	/* fbc_edit_Monitor_section() */
+
+
+/*
+ * fbc_insert_new_Monitor_section()
+ *
+ *    Insert a new, mostly empty Monitor section in the configuration at
+ *    the specified location.
+ *
+ *        Section "Monitor"
+ *            Identifier  "<monitor_identifier>"
+ *        EndSection
+ *        <blank line>
+ *
+ *    Note that the Monitor section identifier string, mon_identifier,
+ *    has been dynamically allocated by our caller.
+ */
+
+static
+int
+fbc_insert_new_Monitor_section(
+	XF86ConfigPtr	configIR,	/* Config Internal Representation */
+	fbc_line_elem_t *next_line_er,	/* Line ER following insertion point */
+	char		*mon_identifier, /* Monitor section identifier */
+	XF86ConfMonitorPtr *monitor_ptr) /* Ptr to new Monitor section IR */
+{
+
+	/*
+	 * Allocate and initialize the Internal Rep for a new Monitor section
+	 */
+	*monitor_ptr = xf86confcalloc(1, sizeof (XF86ConfMonitorRec));
+	if (*monitor_ptr == NULL) {
+		xf86conffree(mon_identifier);
+		return (FBC_ERR_NOMEM);
+	}
+	(*monitor_ptr)->mon_identifier = mon_identifier;
+
+	/*
+	 * Insert the External Representation data for the Monitor section
+	 */
+	/*  Section "Monitor"  */
+	(void) fbc_insert_line_ER(
+			next_line_er,
+			*monitor_ptr,
+			(xf86_print_fn_t *)&xf86printMonitorSectionSection,
+			FBC_INDENT_0);
+
+	/*  Identifier "<monitor_identifier>"  */
+	(void) fbc_insert_line_ER(
+			next_line_er,
+			*monitor_ptr,
+			(xf86_print_fn_t *)&xf86printMonitorSectionIdentifier,
+			FBC_INDENT_1);
+
+	/*  EndSection  */
+	(*monitor_ptr)->mon_end_line_er =
+		fbc_insert_line_ER(
+			next_line_er,
+			*monitor_ptr,
+			(xf86_print_fn_t *)&xf86printMonitorSectionEndSection,
+			FBC_INDENT_0);
+
+	/*  <blank line>  */
+	(void) fbc_insert_line_ER(
+			next_line_er,
+			"\n",
+			(xf86_print_fn_t *)&fbc_print_config_text,
+			FBC_INDENT_0);
+
+	/*
+	 * Add the new Monitor section to the in-memory configuration
+	 */
+	configIR->conf_monitor_lst =
+		(XF86ConfMonitorPtr) xf86addListItem(
+			(glp)configIR->conf_monitor_lst, (glp)configIR);
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_insert_new_Monitor_section() */
+
+
+/*
+ * fbc_insert_Monitor_section()
+ *
+ *    Insert a new, empty Monitor section in the configuration at the
+ *    specified location.
+ */
+
+int
+fbc_insert_Monitor_section(
+	XF86ConfigPtr	configIR,	/* Config Internal Representation */
+	fbc_line_elem_t *next_line_er,	/* Line ER following insertion point */
+	const char	*mon_ident_tmpl, /* Monitor section ident template */
+	XF86ConfMonitorPtr *monitor_ptr) /* Ptr to new Monitor section IR */
+{
+	int		error_code;	/* Error code */
+	unsigned int	i;		/* Loop counter / uniqueness factor */
+	const char	*ident_format;	/* Format for unique identifier */
+	char		*mon_identifier; /* Monitor section identifier */
+
+	/*
+	 * Allocate memory for the new Monitor identifier string
+	 *
+	 *    Allocate space for the intended name and any extra
+	 *    underscore and decimal digits needed to make it unique.
+	 *    The number of digits will never be greater than the byte
+	 *    size of the loop counter, i, multiplied by three decimal
+	 *    digits per byte.
+	 */
+	mon_identifier = xf86confmalloc(strlen(mon_ident_tmpl)
+					+ 1			/* "_" */
+					+ 3 * sizeof (i)	/* Digits */
+					+ 1);			/* Nul */
+	if (mon_identifier == NULL) {
+		return (FBC_ERR_NOMEM);
+	}
+
+	/*
+	 * Insure that the new Monitor section identifier will be unique
+	 */
+	ident_format = "%s";
+	for (i = 0; ; ) {
+		XF86ConfMonitorPtr mon_ptr; /* Ptr to existing Monitor sectn */
+
+		/*
+		 * Try the name alone and then the name with a numeric suffix
+		 */
+		sprintf(mon_identifier, ident_format, mon_ident_tmpl, i);
+		ident_format = "%s_%u";
+
+		/*
+		 * Search for this name among the existing Monitor sections
+		 */
+		for (mon_ptr = configIR->conf_monitor_lst;
+		     mon_ptr != NULL;
+		     mon_ptr = mon_ptr->list.next) {
+			if (xf86nameCompare(mon_identifier,
+					    mon_ptr->mon_identifier) == 0) {
+				break;	/* Not unique */
+			}
+		}
+
+		/*
+		 * Stop when the name is unique (or if the loop counter wraps)
+		 */
+		i += 1;
+		if ((mon_ptr == NULL) || (i == 0)) {
+			break;		/* The name is unique enough */
+		}
+	}
+
+	/*
+	 * Insert a new Monitor section into the in-memory configuration
+	 */
+	error_code = fbc_insert_new_Monitor_section(
+			configIR, next_line_er, mon_identifier, monitor_ptr);
+	if (error_code != FBC_SUCCESS) {
+		xf86conffree(mon_identifier);
+		return (error_code);
+	}
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_insert_Monitor_section() */
+
+
+/*
+ * fbc_insert_UseModes_entry()
+ *
+ *    Insert the specified UseModes entry into the specified Monitor
+ *    section.
+ *
+ *    It is assumed that this function is called when no such UseModes
+ *    entry can be found in the Monitor section.
+ */
+
+int
+fbc_insert_UseModes_entry(
+	XF86ConfMonitorPtr monitor_sectn_ptr, /* Ptr to Monitor section IR */
+	XF86ConfModesPtr modes_sectn_ptr) /* Ptr to Modes section IR */
+{
+	XF86ConfModesLinkPtr usemodes_ptr; /* Ptr to UseModes entry element */
+	XF86ConfModesLinkPtr usemodes_er_ptr; /* Ptr to UseModes entry element */
+	char usemodes_name[80];
+
+	/*
+	 * Allocate, zero, and further initialize the generic UseModes entry element
+	 */
+	usemodes_ptr = xf86confcalloc(1, sizeof (XF86ConfModesLinkRec));
+	if (usemodes_ptr == NULL) {
+		return (FBC_ERR_NOMEM);
+	}
+	usemodes_ptr->ml_modes_str =
+			xf86configStrdup(modes_sectn_ptr->modes_identifier);
+	if (usemodes_ptr->ml_modes_str == NULL) {
+		xf86conffree(usemodes_ptr);
+		return (FBC_ERR_NOMEM);
+	}
+	usemodes_ptr->ml_modes = modes_sectn_ptr;
+
+	/*
+	 * Append the new UseModes entry element to the (empty) list
+	 */
+	monitor_sectn_ptr->mon_modes_sect_lst =
+		(XF86ConfModesLinkPtr)xf86addListItem(
+				(glp)monitor_sectn_ptr->mon_modes_sect_lst,
+				(glp)usemodes_ptr);
+
+	/*
+	 * Insert the device specific UseModes entry
+	 */
+	sprintf(usemodes_name, "%s_%s", modes_sectn_ptr->modes_identifier, monitor_sectn_ptr->mon_identifier);
+	usemodes_er_ptr = xf86findModes(usemodes_name, monitor_sectn_ptr->mon_modes_sect_lst);
+
+	if (usemodes_er_ptr == NULL) {
+
+		/*
+	 	 * Allocate, zero, and further initialize the UseModes entry element
+	 	 */
+		usemodes_er_ptr = xf86confcalloc(1, sizeof (XF86ConfModesLinkRec));
+		if (usemodes_er_ptr == NULL) {
+			return (FBC_ERR_NOMEM);
+		}
+
+		usemodes_er_ptr->ml_modes_str = xf86configStrdup(usemodes_name);
+		usemodes_er_ptr->ml_modes = modes_sectn_ptr;
+
+		/*
+	 	 * Append the new UseModes entry element to the (empty) list
+		 */
+		monitor_sectn_ptr->mon_modes_sect_lst =
+			(XF86ConfModesLinkPtr)xf86addListItem(
+				(glp)monitor_sectn_ptr->mon_modes_sect_lst,
+				(glp)usemodes_er_ptr);
+
+		usemodes_er_ptr->line_er = fbc_insert_line_ER(
+			monitor_sectn_ptr->mon_end_line_er,
+			(void *)usemodes_er_ptr,
+			(xf86_print_fn_t *)&xf86printMonitorSectionUseModes,
+			FBC_INDENT_1);
+	}
+
+	monitor_sectn_ptr->mon_usemodes_line_er = usemodes_er_ptr->line_er;
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_insert_UseModes_entry() */
+
+
+/* End of fbc_Monitor.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_Monitor.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_Monitor - Edit Monitor sections
+ */
+
+
+
+#ifndef	_FBC_MONITOR_H
+#define	_FBC_MONITOR_H
+
+
+#include "xf86Parser.h"		/* Public function, etc. declarations */
+
+#include "fbc_xorg.h"		/* Edit config file data representations */
+
+
+XF86ConfModeLinePtr fbc_find_Monitor_Mode(
+	XF86ConfMonitorPtr monitor_sectn_ptr, /* Ptr to Monitor section IR */
+	const char	*mode_name);	/* ModeLine / Mode-EndMode name */
+
+int fbc_edit_Monitor_section(
+	XF86ConfMonitorPtr monitor_sectn_ptr, /* Ptr to Monitor section IR */
+	xf86_ent_mod_t	*xf86_entry_mods); /* Config entry modifications */
+
+int fbc_insert_Monitor_section(
+	XF86ConfigPtr	configIR,	/* Config Internal Representation */
+	fbc_line_elem_t *next_line_er,	/* Line ER following insertion point */
+	const char	*mon_ident_tmpl, /* Monitor section ident template */
+	XF86ConfMonitorPtr *monitor_ptr); /* Ptr to new Monitor section IR */
+
+int fbc_insert_UseModes_entry(
+	XF86ConfMonitorPtr monitor_sectn_ptr, /* Ptr to Monitor section IR */
+	XF86ConfModesPtr modes_sectn_ptr); /* Ptr to Modes section IR */
+
+
+#endif	/* _FBC_MONITOR_H */
+
+
+/* End of fbc_Monitor.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_Option.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,415 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_Option - Edit Option lists
+ */
+
+
+#include "xf86Optrec.h"		/* Option list definitions and declarations */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_xorg.h"		/* Edit config file data representations */
+#include "fbc_Option.h"		/* Edit Option lists */
+#include "fbc_error.h"		/* Error reporting */
+
+
+/*
+ * fbc_get_Option_list()
+ *
+ *    Return a pointer to the head of the Option entry list for the
+ *    specified active configuration (sub)section.  Also return a
+ *    pointer to the External Represention of the (sub)section's
+ *    End[Sub]Section line, needed when inserting a new Option entry.
+ */
+
+static
+XF86OptionPtr *
+fbc_get_Option_list(
+	xf86_active_t	*active,	/* Active config sections for device */
+	sectn_mask_t	section,	/* Section containing Option entry */
+	void		**end_line_er)	/* End[Sub]Section line External Rep */
+{
+
+	/*
+	 * Get the Option list, etc. for the specified config (sub)section
+	 */
+	switch (section) {
+	case FBC_SECTION_NONE:
+	default:
+		break;			/* Inappropriate (sub)section code */
+	case FBC_SECTION_Screen:
+		if (active->screen_sectn != NULL) {
+			*end_line_er = active->screen_sectn->scrn_end_line_er;
+			return (&active->screen_sectn->scrn_option_lst);
+		}
+		break;
+	case FBC_SUBSCTN_Display:
+		if (active->display_subsectn != NULL) {
+			*end_line_er =
+				active->display_subsectn->disp_end_line_er;
+			return (&active->display_subsectn->disp_option_lst);
+		}
+		break;
+	case FBC_SECTION_Monitor:
+		if (active->monitor_sectn != NULL) {
+			*end_line_er = active->monitor_sectn->mon_end_line_er;
+			return (&active->monitor_sectn->mon_option_lst);
+		}
+		break;
+	case FBC_SECTION_Device:
+		if (active->device_sectn != NULL) {
+			*end_line_er = active->device_sectn->dev_end_line_er;
+			return (&active->device_sectn->dev_option_lst);
+		}
+		break;
+	}
+
+	/*
+	 * The specified active (sub)section was not found
+	 */
+	*end_line_er = NULL;
+	return (NULL);
+
+}	/* fbc_get_Option_list() */
+
+
+/*
+ * fbc_set_Option_value()
+ *
+ *    Modify or insert an Option entry in the specified configuration
+ *    section.
+ */
+
+void
+fbc_set_Option_value(
+	xf86_active_t	*active,	/* Active config sections for device */
+	sectn_mask_t	section,	/* Section containing Option entry */
+	const char	*option_name,	/* Option name */
+	const char	*option_value)	/* Option value string */
+{
+	void		*end_line_er;	/* End[Sub]Section line External Rep */
+	XF86OptionPtr	*option_list;	/* Head of Option list */
+
+	/*
+	 * Retrieve the Option list for the specified config section
+	 */
+	option_list = fbc_get_Option_list(active, section, &end_line_er);
+	if (option_list == NULL) {
+		const char *section_type;
+
+		switch (section) {
+		case FBC_SECTION_Screen:
+			section_type = "Screen section";
+			break;
+		case FBC_SUBSCTN_Display:
+			section_type = "Display subsection";
+			break;
+		case FBC_SECTION_Monitor:
+			section_type = "Monitor section";
+			break;
+		case FBC_SECTION_Device:
+			section_type = "Device section";
+			break;
+		default:
+			section_type = "section";
+			break;
+		}
+		fbc_errormsg("No active %s to contain \"%s\" Option\n",
+			    section_type, option_name);
+		return;
+	}
+
+	/*
+	 * Modify or insert this Option entry
+	 *
+	 *    (type casting to discard "const" qualifiers)
+	 */
+	*option_list = xf86addNewOptionOrValue(
+					*option_list,
+//??? xf86configStrdup() ???
+					(char *)option_name,
+//??? xf86configStrdup() ???
+					(char *)option_value,
+					0,	/* The "used" arg is unused */
+					end_line_er);
+
+}	/* fbc_set_Option_value() */
+
+
+/*
+ * fbc_get_Option_string_value()
+ *
+ *    Retrieve the specified Option entry value from the specified config
+ *    section.  Return the value string or else the "not found" or "value
+ *    empty" string.
+ */
+
+const char *
+fbc_get_Option_string_value(
+	xf86_active_t	*active,	/* Active config sections for device */
+	sectn_mask_t	section,	/* Section containing Option entry */
+	const char	*option_name,	/* Option name */
+	const char	*option_not_found, /* Case if Option isn't found */
+	const char	*option_value_empty) /* Case if Option has no value */
+{
+	void		*end_line_er;	/* End[Sub]Section line External Rep */
+	XF86OptionPtr	*option_list;	/* Ptr to head of Option list */
+	XF86OptionPtr	option_entry;	/* Ptr to Option entry, else NULL */
+
+	/*
+	 * Retrieve the Option entry, else return the not-found string
+	 */
+	option_list = fbc_get_Option_list(active, section, &end_line_er);
+	if (option_list == NULL) {
+		return (option_not_found); /* No active section */
+	}
+	option_entry = xf86findOption(*option_list, option_name);
+	if (option_entry == NULL) {
+		return (option_not_found); /* Option not found in section */
+	}
+
+	/*
+	 * Return the Option value string, else the value-empty string
+	 */
+	if (option_entry->opt_val == NULL) {
+		return (option_value_empty);
+	}
+	return (option_entry->opt_val);
+
+}	/* fbc_get_Option_string_value() */
+
+
+/*
+ * fbc_get_Option_keywd_value()
+ *
+ *    Retrieve the specified Option entry value from the specified config
+ *    section.  Evaluate the value string as a keyword and return the
+ *    corresponding ordinal value.
+ */
+
+int
+fbc_get_Option_keywd_value(
+	xf86_active_t	*active,	/* Active config sections for device */
+	sectn_mask_t	section,	/* Section containing Option entry */
+	const char	*option_name,	/* Option name */
+	int		option_not_found, /* Case if Option isn't found */
+	int		option_value_bad, /* Case if Option value is bad */
+	const fbc_Optkeywd_t *keywd_table) /* Table of Option value keywds */
+{
+	int		i;		/* Loop counter / array index */
+	const char	*opt_val;	/* Option value string, else NULL */
+
+	/*
+	 * Retrieve the Option value string
+	 *
+	 *    Specify that a NULL should be used to indicate Option not
+	 *    found, and that an empty string should be used to indicate
+	 *    no Option value.
+	 */
+	opt_val = fbc_get_Option_string_value(
+				active, section, option_name, NULL, "");
+	if (opt_val == NULL) {
+		return (option_not_found);
+	}
+
+	/*
+	 * Convert the value string to an ordinal value
+	 */
+	for (i = 0; keywd_table[i].name != NULL; i += 1) {
+		if (xf86nameCompare(keywd_table[i].name, opt_val) == 0) {
+			return (keywd_table[i].value);
+		}
+	}
+	return (option_value_bad);
+
+}	/* fbc_get_Option_keywd_value() */
+
+
+/*
+ * fbc_get_Option_bool_value()
+ *
+ *    Retrieve the specified Option entry from the specified config
+ *    section.  Evaluate the Option as a Boolean.
+ *
+ *    The argument field of Boolean Option entry may be omitted,
+ *    implying "True".  The Option name may have a "No" prefix, which
+ *    negates the value.  "False" is implied (in all fbconf_xorg(1M)
+ *    cases to date) if the Option does not occur in the configuration,
+ *    or if the value is garbage.
+ *
+ *    Sequitur:
+ *        An empty string is equivalent to an omitted argument
+ *        (according to xf86findOptionValue()).  A string consisting
+ *        only of whitespace and underscores is equivalent to an
+ *        empty string, and therefore to "True", rather than to
+ *        garbage.
+ *
+ *    Return the actual or implied value of the Option as TRUE or FALSE.
+ */
+
+int
+fbc_get_Option_bool_value(
+	xf86_active_t	*active,	/* Active config sections for device */
+	sectn_mask_t	section,	/* Section containing Option entry */
+	const char	*option_name)	/* Boolean Option name */
+{
+	/*
+	 * Boolean argument strings, as per the XFree86 man page
+	 *
+	 *    Compare with fbc_keywds_boolean[].  It is suitable for
+	 *    unidirectional rather than bidirectional translation.
+	 */
+	const fbc_Optkeywd_t keywd_boolean[] = {
+		{ "false", FALSE },	/* Preferred Boolean keyword */
+		{ "true",  TRUE  },	/* Preferred Boolean keyword */
+		{ "off",   FALSE },
+		{ "on",    TRUE  },
+		{ "no",    FALSE },
+		{ "yes",   TRUE  },
+		{ "0",     FALSE },
+		{ "1",     TRUE  },
+		{ "",      TRUE  },	/* Omitted argument or empty string */
+		{ NULL,    FALSE }	/* End of table */
+	};
+
+	void		*end_line_er;	/* End[Sub]Section line External Rep */
+	int		i;		/* Loop counter / array index */
+	const char	*opt_val;	/* Option value string, else NULL */
+	XF86OptionPtr	option_entry;	/* Ptr to matching Option entry */
+	XF86OptionPtr	*option_list;	/* Ptr to head of Option list */
+	int		value;		/* Boolean Option value */
+
+	/*
+	 * Retrieve the Option value string, else return FALSE
+	 *
+???	 *    Unlike other Option names, Boolean Option names can have a
+	 *    "No" prefix.  A partial argument could be made that a new
+	 *    function, other than xf86findOption(), is needed.  That or
+	 *    the function must be called once without the "No" prefix
+	 *    and once with it.  This would be reasonable for retrieving
+	 *    an Option but less so for setting it.  Our
+	 *    xf86findOption() function has been provided with a list of
+	 *    known Boolean Option names.  This is used to prevent
+	 *    duplicate Options, no matter how a name is spelled, from
+	 *    being added to a list.
+	 */
+	option_list = fbc_get_Option_list(active, section, &end_line_er);
+	if (option_list == NULL) {
+		return (FALSE);		/* No active section */
+	}
+	option_entry = xf86findOption(*option_list, option_name);
+	if (option_entry == NULL) {
+		return (FALSE);		/* Option not found in section */
+	}
+
+	/*
+	 * Evaluate the Option argument string as a keyword
+	 */
+	value = FALSE;			/* Accept garbage as FALSE */
+	opt_val = option_entry->opt_val;
+	if (opt_val == NULL) {
+		opt_val = "";		/* Accept NULL as "" */
+	}
+	for (i = 0; keywd_boolean[i].name != NULL; i += 1) {
+		if (xf86nameCompare(keywd_boolean[i].name, opt_val) == 0) {
+			value = keywd_boolean[i].value;
+			break;
+		}
+	}
+
+	/*
+	 * A "No" prefix on a Boolean Option name compliments the value
+	 *
+???	 *    The xf86findOption() function found the named Option entry
+	 *    by searching both with and without the "No" prefix.
+	 *    Therefore if the found name doesn't match the specified
+	 *    Option name, we can conclude that the found name has a
+	 *    "No" prefix.
+	 */
+	if (xf86nameCompare(option_name, option_entry->opt_name) != 0) {
+		value = !value;
+	}
+
+	return (value);
+
+}	/* fbc_get_Option_bool_value() */
+
+
+/*
+ * fbc_edit_Options()
+ *
+ *    Modify or insert configuration Option entries, based on program
+ *    command line options reflected in the Option_mods[] array.
+ *
+ *    Screen section
+ *        Option  "DoubleWide" "Enable"|"Disable"
+ *        Option  "DoubleHigh" "Enable"|"Disable"
+ *        Option  "Multisample" "Disable"|"Available"|"ForceOn"
+ *        Option  "Samples" "1"|"4"|"8"|"16"
+ *        Option  "MultiviewMode" "Disable"|"Multiview" # -slave <arg>
+ *        Option  "StreamXOffset" "<integer>"
+ *        Option  "StreamYOffset" "<integer>"
+ *    Display subsection
+ *        Option  "DefLinear" "True"|"False"
+ *        Option  "DefOverlay" "True"|"False"
+ *        Option  "DefTransparent" "True"|"False"
+ *    Monitor section
+ *        Option  "GFile" "[<filename>]"        # -gfile "[<filename>]"
+ */
+
+void
+fbc_edit_Options(
+	xf86_active_t	*active,	/* Active config sections for device */
+	xf86_opt_mod_t	Option_mods[])	/* Config Option modifications */
+{
+	int		i;		/* Loop counter / array index */
+
+	/*
+	 * Repeat for each config Option entry to be modified or added
+	 */
+	for (i = 0; Option_mods[i].name != NULL; i += 1) {
+		/*
+		 * Ignore pseudo-Options (e.g., "#Gamma")
+		 *
+		 *    Pseudo-Options are left over from program command
+		 *    line processing and should not be inserted into
+		 *    the configuration.
+		 */
+		if (*Option_mods[i].name == FBC_PSEUDO_PREFIX[0]) {
+			continue;
+		}
+
+		/*
+		 * Modify or insert this Option entry
+		 */
+		fbc_set_Option_value(active,
+				    Option_mods[i].section,
+				    Option_mods[i].name,
+				    Option_mods[i].value);
+	}
+
+}	/* fbc_edit_Options() */
+
+
+/* End of fbc_Option.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_Option.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_Option - Edit Option lists
+ */
+
+
+
+#ifndef	_FBC_OPTION_H
+#define	_FBC_OPTION_H
+
+
+#include "xf86Optrec.h"		/* Option list definitions and declarations */
+
+#include "fbc_xorg.h"		/* Edit config file data representations */
+
+
+void fbc_set_Option_value(
+	xf86_active_t	*active,	/* Active config sections for device */
+	sectn_mask_t	section,	/* Section containing Option entry */
+	const char	*option_name,	/* Option name */
+	const char	*option_value);	/* Option value string */
+
+const char *fbc_get_Option_string_value(
+	xf86_active_t	*active,	/* Active config sections for device */
+	sectn_mask_t	section,	/* Section containing Option entry */
+	const char	*option_name,	/* Option name */
+	const char	*option_not_found, /* Case if Option isn't found */
+	const char	*option_value_empty); /* Case if Option has no value */
+
+typedef struct {
+	const char * const name;	/* Option value keyword */
+	int		value;		/* Option keyword's ordinal value */
+} fbc_Optkeywd_t;
+
+int fbc_get_Option_keywd_value(
+	xf86_active_t	*active,	/* Active config sections for device */
+	sectn_mask_t	section,	/* Section containing Option entry */
+	const char	*option_name,	/* Option name */
+	int		option_not_found, /* Case if Option isn't found */
+	int		option_value_bad, /* Case if Option value is bad */
+	const fbc_Optkeywd_t *keywd_table); /* Table of Option value keywds */
+
+int fbc_get_Option_bool_value(
+	xf86_active_t	*active,	/* Active config sections for device */
+	sectn_mask_t	section,	/* Section containing Option entry */
+	const char	*option_name);	/* Boolean Option name */
+
+void fbc_edit_Options(
+	xf86_active_t	*active,	/* Active config sections for device */
+	xf86_opt_mod_t	Option_mods[]);	/* Config Option modifications */
+
+
+#endif	/* _FBC_OPTION_H */
+
+
+/* End of fbc_Option.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_Screen.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,734 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_Screen - Edit Screen sections
+ */
+
+
+#include <stdio.h>		/* NULL */
+
+#include "xf86Parser.h"		/* Public function, etc. declarations */
+#include "Configint.h"		/* Private definitions, etc. */
+#include "configProcs.h"	/* Private function, etc. declarations */
+#include "xf86Optrec.h"		/* Option lists, memory management, etc. */
+
+#include "fbc_Monitor.h"	/* Edit Monitor sections */
+#include "fbc_Option.h"		/* Edit Option lists */
+#include "fbc_Screen.h"		/* Edit Screen sections */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_line_er.h"	/* External Representation of config lines */
+#include "fbc_write_config.h"	/* Write an updated config file */
+
+
+/*
+ * fbc_find_active_Monitor_entry()
+ *
+ *    Find the first Monitor entry within a list of Monitor section
+ *    identifiers.
+ * ???    The man pages don't seem to have said which is the active
+ * ???    Monitor section when there is more than one Monitor entry.
+ *    The list of Monitor sections comes from an active Screen section.
+ *    The list may be empty, which means a default configuration is to
+ *    be used.
+ *
+ * ???
+ *    Monitor entries within a Screen section are optional.  Currently
+ *    we don't support omitted Monitor sections and default
+ *    configurations ...
+ *
+ *    Note that the syntax and data structures being traversed by this
+ *    function belong to the Screen section, which is why this function
+ *    is in fbc_Screen.c rather than a fbc_Monitor.c.
+ */
+
+XF86ConfScrnMonitorEntryPtr
+fbc_find_active_Monitor_entry(
+	XF86ConfScrnMonitorEntryPtr scrn_monitor_lst) /* Monitor entry list */
+{
+
+	/*
+	 * Return the first Monitor section entry in the list, else NULL
+	 */
+	return (scrn_monitor_lst);
+
+}	/* fbc_find_active_Monitor_entry() */
+
+
+/*
+ * fbc_insert_Monitor_entry()
+ *
+ *    Insert the specified Monitor entry line into the specified Screen
+ *    section.
+ *
+ *    It is assumed that this function is called when no active Monitor
+ *    section was found by fbc_find_active_Monitor_entry(), i.e. the
+ *    list of Monitor entries is empty.  In any case, this function must
+ *    not cause:
+ *      * Omitted Monitor numbers when there are muliple Monitor entries
+ *      * Duplicate Monitor numbers
+ *      * Duplicate Monitor names
+ *    See xf86parseScrnMonitor() in Screen.c.
+ */
+
+int
+fbc_insert_Monitor_entry(
+	XF86ConfScreenPtr screen_sectn_ptr, /* Ptr to current Screen section */
+	XF86ConfMonitorPtr monitor_sectn_ptr, /* Ptr to cur Monitor section */
+	XF86ConfScrnMonitorEntryPtr *mon_ptr) /* Ptr to Monitor entry */
+{
+
+	/*
+	 * Allocate, zero, and further initialize the new Monitor entry element
+	 */
+	*mon_ptr = xf86confcalloc(1, sizeof (XF86ConfScrnMonitorEntryRec));
+	if (*mon_ptr == NULL) {
+		return (FBC_ERR_NOMEM);
+	}
+	(*mon_ptr)->scrn_monitor      = monitor_sectn_ptr;
+	(*mon_ptr)->scrn_monitor_name =
+			xf86configStrdup(monitor_sectn_ptr->mon_identifier);
+	if ((*mon_ptr)->scrn_monitor_name == NULL) {
+		xf86conffree(*mon_ptr);
+		*mon_ptr = NULL;
+		return (FBC_ERR_NOMEM);
+	}
+
+	/*
+	 * Append new the Monitor entry element to the (empty) list
+	 */
+	screen_sectn_ptr->scrn_monitor_lst =
+		(XF86ConfScrnMonitorEntryPtr)xf86addListItem(
+				(glp)screen_sectn_ptr->scrn_monitor_lst,
+				(glp)*mon_ptr);
+
+	/*
+	 * Insert the External Representation data for the Monitor entry line
+	 */
+	(void) fbc_insert_line_ER(
+			screen_sectn_ptr->scrn_end_line_er,
+			(void *)*mon_ptr,
+			(xf86_print_fn_t *)&xf86printScreenSectionMonitor,
+			FBC_INDENT_1);
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_insert_Monitor_entry() */
+
+
+/*
+ * fbc_find_active_Mode_name()
+ *
+ *    Return a pointer to the name of the first ModeLine / Mode-EndMode
+ *    entry, if any, referenced by this Display subsection.  Otherwise
+ *    return NULL.
+ *
+ *    This function supports the -propt functionality.
+ */
+
+const char *
+fbc_find_active_Mode_name(
+	XF86ConfDisplayPtr display_subsectn_ptr) /* Ptr to Display subsectn */
+{
+
+	if (display_subsectn_ptr->disp_mode_lst != NULL) {
+		return (display_subsectn_ptr->disp_mode_lst->mode_name);
+	}
+	return (NULL);
+
+}	/* fbc_find_active_Mode_name() */
+
+
+/*
+ * fbc_find_active_Display_subsection()
+ *
+ *    Find the active Display subsection in this Screen section that
+ *    matches the specified active Monitor entry.
+ *
+ *    "The 'active' Display subsections are the first for each monitor
+ *    number that match the depth and/or fbbpp values being used, or
+ *    failing that, the first for each monitor number that has neither a
+ *    depth or fbbpp value specified.  ...  The Display subsections are
+ *    optional.  ..."  - XF86Config(5)
+ */
+
+XF86ConfDisplayPtr
+fbc_find_active_Display_subsection(
+	XF86ConfScreenPtr screen_sectn_ptr, /* Ptr to active Screen section */
+	XF86ConfScrnMonitorEntryPtr mon_ptr, /* Ptr to active Monitor entry */
+	XF86ConfDisplayPtr scrn_display_lst) /* Display subsection list */
+
+{
+	XF86ConfDisplayPtr display_subsectn_ptr; /* Ptr to Display subsectn */
+
+	/*
+	 * Find any Display subsection referencing this Monitor section
+	 */
+	for (display_subsectn_ptr = scrn_display_lst;
+	    display_subsectn_ptr != NULL;
+	    display_subsectn_ptr = (XF86ConfDisplayPtr)
+					(display_subsectn_ptr->list.next)) {
+		/*
+		 * Check for matching monitor numbers
+		 *
+		 *    There is no match if one entity (Display
+		 *    subsection or Monitor entry) specifies a monitor
+		 *    number and the other doesn't.
+		 *
+		 *    Considering only monitor numbers, there is a match
+		 *    if both entities have the same monitor number.
+		 *    There is a match if both entities have no monitor
+		 *    number.
+		 */
+		if (display_subsectn_ptr->disp_monitor_seen !=
+					mon_ptr->scrn_monitor_num_seen) {
+			continue;	/* Not a match */
+		}
+		if (display_subsectn_ptr->disp_monitor_seen &&
+			(display_subsectn_ptr->disp_monitor_num
+					!= mon_ptr->scrn_monitor_num)) {
+			continue;	/* Not a match */
+		}
+
+		/*
+		 * Check for matching depth and/or fbbpp values
+		 *
+		 *    Note that the XF86Config(5) man page says "and/or"
+		 *    rather than "and."  This seems to allow for the
+		 *    possibility that only one of the two values is
+		 *    specified.  If both values are specified, we'll
+		 *    require a match on both.
+		 *
+???		 *    Though the parser code does not check for this, it
+???		 *    is assumed that zero is not a valid value for
+???		 *    depth nor [fb]bpp, and further assumed that a zero
+???		 *    in the Display subsection data structure indicates
+???		 *    that the value was not specified.
+		 */
+#define	NO_DEPTH	0		/* Unspecified depth value */
+#define	NO_FBBPP	0		/* Unspecified fbbpp value */
+		if ((display_subsectn_ptr->disp_depth != NO_DEPTH) &&
+		    (display_subsectn_ptr->disp_depth
+				!= screen_sectn_ptr->scrn_defaultdepth)) {
+			continue;	/* Not a match */
+		}
+		if ((display_subsectn_ptr->disp_bpp != NO_FBBPP) &&
+		    (display_subsectn_ptr->disp_bpp
+				!= screen_sectn_ptr->scrn_defaultfbbpp)) {
+			continue;	/* Not a match */
+		}
+
+		/*
+		 * Return the first matching Display subsection found
+		 */
+		return (display_subsectn_ptr);
+	}
+
+	/*
+	 * Return unsuccessfully
+	 */
+	return (NULL);
+
+}	/* fbc_find_active_Display_subsection() */
+
+
+/*
+ * fbc_find_active_Screen_section()
+ *
+ *    Find the Screen section that refers to the specified device name.
+ *
+ *    Note that we can't tell whether a given Screen section will be
+ *    considered active at execution time.  This is because even if we
+ *    could guess which ServerLayout section is likely to be active, the
+ *    -screen command line option could still be used to override our
+ *    best guess.
+ */
+
+XF86ConfScreenPtr
+fbc_find_active_Screen_section(
+	XF86ConfScreenPtr conf_screen_lst, /* Head of Screen section list */
+	const char	* const	device_identifier) /* Device name */
+{
+	XF86ConfScreenPtr scrn_sectn_ptr; /* Ptr to Screen section */
+
+	/*
+	 * Search each Screen section for the specified device identifier
+	 */
+	for (scrn_sectn_ptr = conf_screen_lst;
+	    scrn_sectn_ptr != NULL;
+	    scrn_sectn_ptr = scrn_sectn_ptr->list.next) {
+		if (xf86nameCompare(scrn_sectn_ptr->scrn_device_str,
+					device_identifier) == 0) {
+			/*
+			 * Return this as the active Screen section
+			 */
+			return (scrn_sectn_ptr);
+		}
+	}
+
+	/*
+	 * Return unsuccessfully
+	 */
+	return (NULL);
+
+}	/* fbc_find_active_Screen_section() */
+
+
+/*
+ * fbc_edit_Display_subsection()
+ *
+ *    Modify or insert Display subsection values to the Internal and
+ *    External Representations of the configuration file:
+ *        Modes       "<mode_name>" ...
+ */
+
+int
+fbc_edit_Display_subsection(
+	XF86ConfDisplayPtr display_subsectn_ptr, /* Ptr to Display subsectn */
+	xf86_ent_mod_t	*xf86_entry_mods) /* Config entry modifications */
+{
+	XF86ModePtr	*disp_mode_pptr; /* Ptr to ptr to Modes element */
+	XF86ModePtr	disp_mode_ptr;	/* Ptr to Modes list element */
+	int		no_modes_line;	/* TRUE => No Modes line */
+
+	/*
+	 * See whether a Mode name has been specified (-res option)
+	 */
+	if (xf86_entry_mods->video_mode.name == NULL) {
+		return (FBC_SUCCESS);	/* No "-res <video_mode>" option */
+	}
+
+	/*
+	 *  Before disturbing it, remember whether we found the list empty
+	 */
+	no_modes_line = (display_subsectn_ptr->disp_mode_lst == NULL);
+
+	/*
+	 * Look for a matching Modes name element or create one if not found
+	 */
+	for (disp_mode_pptr = &display_subsectn_ptr->disp_mode_lst;
+	    ;
+	    disp_mode_pptr = (XF86ModePtr *)&disp_mode_ptr->list.next) {
+		disp_mode_ptr = *disp_mode_pptr;
+
+		/*
+		 * See whether we've reached the end of the Modes list
+		 */
+		if (disp_mode_ptr == NULL) {
+			/*
+			 * Create a new Modes list element for this Mode name
+			 */
+			disp_mode_ptr =
+				xf86confcalloc(1, sizeof (XF86ModeRec));
+			if (disp_mode_ptr == NULL) {
+				fbc_errormsg(
+				"Insufficient memory, \"%s\" list element\n",
+					xf86_entry_mods->video_mode.name);
+				return (FBC_ERR_NOMEM);
+			}
+			disp_mode_ptr->mode_name =
+			    xf86configStrdup(xf86_entry_mods->video_mode.name);
+			if (disp_mode_ptr->mode_name == NULL) {
+				xf86conffree(disp_mode_ptr);
+				fbc_errormsg(
+				"Insufficient memory, \"%s\" name string\n",
+					    xf86_entry_mods->video_mode.name);
+				return (FBC_ERR_NOMEM);
+			}
+			break;
+		}
+
+		/*
+		 * See whether this existing Mode name is a match
+		 */
+		if (xf86nameCompare(xf86_entry_mods->video_mode.name,
+				    disp_mode_ptr->mode_name) == 0) {
+			/*
+			 * Unlink the matching Mode name element from the list
+			 */
+			*disp_mode_pptr =
+				(XF86ModePtr)disp_mode_ptr->list.next;
+			break;
+		}
+	}
+
+	/*
+	 * Replace the Mode
+	 */
+	if (display_subsectn_ptr->disp_mode_lst)
+		xf86conffree(display_subsectn_ptr->disp_mode_lst);
+	display_subsectn_ptr->disp_mode_lst = disp_mode_ptr;
+
+	/*
+	 * Insert a new Mode line ER or modify an existing one
+	 */
+	if (no_modes_line) {
+		/*
+		 * Insert the External Representation of the new Modes line
+		 */
+		(void) fbc_insert_line_ER(
+				display_subsectn_ptr->disp_end_line_er,
+				display_subsectn_ptr,
+				(xf86_print_fn_t *)
+					&xf86printDisplaySubsectionModes,
+				FBC_INDENT_1);
+	} else {
+		/*
+		 * Modify the External Representation of the Modes line
+		 */
+		fbc_modify_line_ER(display_subsectn_ptr->disp_modes_line_er);
+	}
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_edit_Display_subsection() */
+
+
+/*
+ * fbc_insert_Display_subsection()
+ *
+ *    Insert a new, semi-empty Display subsection in the configuration
+ *    at the specified location.
+ *
+ *        Subsection "Display"
+ *     [          Monitor <monitor_num>    ]
+ *    #[          Depth   <depth>          ]
+ *    #[          FbBpp   <bpp>            ]
+ *        EndSubsection
+ */
+
+int
+fbc_insert_Display_subsection(
+	XF86ConfScreenPtr screen_ptr,	/* Ptr to new Screen section IR */
+	fbc_line_elem_t *next_line_er,	/* Line ER following insertion point */
+	XF86ConfScrnMonitorEntryPtr mon_ptr, /* Ptr to Monitor entry */
+	XF86ConfDisplayPtr *display_ptr) /* Ptr to new Display subsection IR */
+{
+
+	/*
+	 * Allocate and initialize the Internal Rep for new Display subsection
+	 */
+	*display_ptr = xf86confcalloc(1, sizeof (XF86ConfDisplayRec));
+	if (*display_ptr == NULL) {
+		return (FBC_ERR_NOMEM);
+	}
+
+	(*display_ptr)->disp_monitor_seen = FALSE;
+
+	(*display_ptr)->disp_black.red    = -1;
+	(*display_ptr)->disp_black.green  = -1;
+	(*display_ptr)->disp_black.blue   = -1;
+
+	(*display_ptr)->disp_white.red    = -1;
+	(*display_ptr)->disp_white.green  = -1;
+	(*display_ptr)->disp_white.blue   = -1;
+
+	(*display_ptr)->disp_frameX0      = -1;
+	(*display_ptr)->disp_frameY0      = -1;
+
+	/*
+	 * Insert the External Representation data for the Display subsection
+	 */
+	/*  Subsection "Display"  */
+	(void) fbc_insert_line_ER(
+			next_line_er,
+			*display_ptr,
+			(xf86_print_fn_t *)
+				&xf86printDisplaySubsectionSubsection,
+			FBC_INDENT_1);
+
+	/*  Monitor <monitor_num>  */
+	if ((mon_ptr != NULL) && (mon_ptr->scrn_monitor_num_seen)) {
+		(*display_ptr)->disp_monitor_seen = TRUE;
+		(*display_ptr)->disp_monitor_num  = mon_ptr->scrn_monitor_num;
+		(void) fbc_insert_line_ER(
+			next_line_er,
+			*display_ptr,
+			(xf86_print_fn_t *)&xf86printDisplaySubsectionMonitor,
+			FBC_INDENT_2);
+	}
+
+	/*  Depth <depth>  */
+
+	/*  FbBpp <bpp>  */
+
+	/*  EndSubsection  */
+	(*display_ptr)->disp_end_line_er =
+		fbc_insert_line_ER(
+			next_line_er,
+			*display_ptr,
+			(xf86_print_fn_t *)
+				&xf86printDisplaySubsectionEndSubsection,
+			FBC_INDENT_1);
+
+	/*
+	 * Add the new Display subsection to the in-memory configuration
+	 */
+	screen_ptr->scrn_display_lst =
+			(XF86ConfDisplayPtr)xf86addListItem(
+					(glp)screen_ptr->scrn_display_lst,
+					(glp)*display_ptr);
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_insert_Display_subsection() */
+
+
+/*
+ * fbc_edit_Screen_section()
+ *
+ *    Modify or insert Screen section values to the Internal
+ *    Representation of the configuration file.
+ *        DefaultDepth "8"|"24"                       # -defdepth "8"|"24"
+ */
+
+int
+fbc_edit_Screen_section(
+	XF86ConfScreenPtr screen_sectn_ptr, /* Ptr to current Screen section */
+	xf86_ent_mod_t	*xf86_entry_mods) /* Config entry modifications */
+{
+
+	/*
+	 * Make any DefaultDepth modification to the Screen section
+	 */
+	if (xf86_entry_mods->scrn_defaultdepth != FBC_NO_DefaultDepth) {
+		/*
+		 * Update the line's Internal Representation
+		 */
+		screen_sectn_ptr->scrn_defaultdepth =
+					xf86_entry_mods->scrn_defaultdepth;
+
+		/*
+		 * Insert or modify the line's External Representation
+		 */
+		fbc_edit_line_ER(&screen_sectn_ptr->scrn_defaultdepth_line_er,
+				screen_sectn_ptr->scrn_end_line_er,
+				screen_sectn_ptr,
+				(xf86_print_fn_t *)
+					&xf86printScreenSectionDefaultDepth,
+				FBC_INDENT_1);
+	}
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_edit_Screen_section() */
+
+
+/*
+ * fbc_insert_new_Screen_section()
+ *
+ *    Insert a new, mostly empty Screen section in the configuration at
+ *    the specified location.
+ *
+ *        Section "Screen"
+ *            Identifier  "<screen_identifier>"
+ *            Device      "<device_identifier>"
+ *        EndSection
+ *        <blank line>
+ *
+ *    The Monitor entry will be inserted later, iff there are command
+ *    line options that modify a Monitor section.
+ *
+ *    Note that the Screen section identifier string, scrn_identifier,
+ *    has been dynamically allocated by our caller.  The Device section
+ *    identifier, scrn_device_str, is assumed not to have been.
+ */
+
+static
+int
+fbc_insert_new_Screen_section(
+	XF86ConfigPtr	configIR,	/* Config Internal Representation */
+	fbc_line_elem_t *next_line_er,	/* Line ER following insertion point */
+	char		*scrn_identifier, /* Screen section identifier */
+	const char	*scrn_device_str, /* Device section identifier */
+	XF86ConfScreenPtr *screen_ptr)	/* Ptr to new Screen section IR */
+{
+
+	/*
+	 * Allocate and initialize the Internal Rep for a new Screen section
+	 */
+	*screen_ptr = xf86confcalloc(1, sizeof (XF86ConfScreenRec));
+	if (*screen_ptr == NULL) {
+		return (FBC_ERR_NOMEM);
+	}
+
+	(*screen_ptr)->scrn_identifier = scrn_identifier;
+	(*screen_ptr)->scrn_device_str = xf86configStrdup(scrn_device_str);
+
+	/*
+	 * Insert the External Representation data for the Screen section
+	 */
+	/*  Section "Screen"  */
+	(void) fbc_insert_line_ER(
+			next_line_er,
+			*screen_ptr,
+			(xf86_print_fn_t *)&xf86printScreenSectionSection,
+			FBC_INDENT_0);
+
+	/*  Identifier "<screen_identifier>"  */
+	(void) fbc_insert_line_ER(
+			next_line_er,
+			*screen_ptr,
+			(xf86_print_fn_t *)&xf86printScreenSectionIdentifier,
+			FBC_INDENT_1);
+
+	/*  Device "<device_identifier>"  */
+	(void) fbc_insert_line_ER(
+			next_line_er,
+			*screen_ptr,
+			(xf86_print_fn_t *)&xf86printScreenSectionDevice,
+			FBC_INDENT_1);
+
+	/*  EndSection  */
+	(*screen_ptr)->scrn_end_line_er =
+		fbc_insert_line_ER(
+			next_line_er,
+			*screen_ptr,
+			(xf86_print_fn_t *)&xf86printScreenSectionEndSection,
+			FBC_INDENT_0);
+
+	/*  <blank line>  */
+	(void) fbc_insert_line_ER(
+			next_line_er,
+			"\n",
+			(xf86_print_fn_t *)&fbc_print_config_text,
+			FBC_INDENT_0);
+
+	/*
+	 * Add the new Screen section to the in-memory configuration
+	 *
+	 *    The External and Internal Representations of this Screen
+	 *    section must agree that it is either first (FBC_FIRST_ER)
+	 *    or last (FBC_LAST_ER aka NULL) in the configuration.
+	 */
+	if (next_line_er == FBC_LAST_ER) {
+		/*
+		 * Last Screen section in the configuration
+		 */
+		configIR->conf_screen_lst =
+			(XF86ConfScreenPtr)xf86addListItem(
+					(glp)configIR->conf_screen_lst,
+					(glp)*screen_ptr);
+	} else {
+		/*
+		 * First Screen section in the configuration
+		 */
+		(*screen_ptr)->list.next  = configIR->conf_screen_lst;
+		configIR->conf_screen_lst = *screen_ptr;
+	}
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_insert_new_Screen_section() */
+
+
+/*
+ * fbc_insert_Screen_section()
+ *
+ *    Insert a new, empty Screen section in the configuration at the
+ *    specified location.
+ */
+
+int
+fbc_insert_Screen_section(
+	XF86ConfigPtr	configIR,	/* Config Internal Representation */
+	fbc_line_elem_t *next_line_er,	/* Line ER following insertion point */
+	const char	*scrn_ident_tmpl, /* Screen section ident template */
+	const char	*scrn_device_str, /* Device section identifier */
+	XF86ConfScreenPtr *screen_ptr)	/* Ptr to new Screen section IR */
+{
+	int		error_code;	/* Error code */
+	unsigned int	i;		/* Loop counter / uniqueness factor */
+	const char	*ident_format;	/* Format for unique identifier */
+	char		*scrn_identifier; /* Screen section identifier */
+
+	/*
+	 * Allocate memory for the new Screen identifier string
+	 *
+	 *    Allocate space for the intended name and any extra
+	 *    underscore and decimal digits needed to make it unique.
+	 *    The number of digits will never be greater than the byte
+	 *    size of the loop counter, i, multiplied by three decimal
+	 *    digits per byte.
+	 */
+	scrn_identifier = xf86confmalloc(strlen(scrn_ident_tmpl)
+					+ 1			/* "_" */
+					+ 3 * sizeof (i)	/* Digits */
+					+ 1);			/* Nul */
+	if (scrn_identifier == NULL) {
+		return (FBC_ERR_NOMEM);
+	}
+
+	/*
+	 * Insure that the new Screen section identifier will be unique
+	 */
+	ident_format = "%s";
+	for (i = 0; ; ) {
+		XF86ConfScreenPtr scrn_ptr; /* Ptr to existing Screen sectn */
+
+		/*
+		 * Try the name alone and then the name with a numeric suffix
+		 */
+		sprintf(scrn_identifier, ident_format, scrn_ident_tmpl, i);
+		ident_format = "%s_%u";
+
+		/*
+		 * Search for this name among the existing Screen sections
+		 */
+		for (scrn_ptr = configIR->conf_screen_lst;
+		     scrn_ptr != NULL;
+		     scrn_ptr = scrn_ptr->list.next) {
+			if (xf86nameCompare(scrn_identifier,
+					    scrn_ptr->scrn_identifier) == 0) {
+				break;	/* Not unique */
+			}
+		}
+
+		/*
+		 * Stop when the name is unique (or if the loop counter wraps)
+		 */
+		i += 1;
+		if ((scrn_ptr == NULL) || (i == 0)) {
+			break;		/* The name is unique enough */
+		}
+	}
+
+	/*
+	 * Insert a new Screen section into the in-memory configuration
+	 */
+	error_code = fbc_insert_new_Screen_section(configIR,
+						    next_line_er,
+						    scrn_identifier,
+						    scrn_device_str,
+						    screen_ptr);
+	if (error_code != FBC_SUCCESS) {
+		xf86conffree(scrn_identifier);
+		return (error_code);
+	}
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_insert_Screen_section() */
+
+
+/* End of fbc_Screen.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_Screen.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_Screen - Edit Screen sections
+ */
+
+
+
+#ifndef	_FBC_SCREEN_C
+#define	_FBC_SCREEN_C
+
+
+#include "xf86Parser.h"		/* Public function, etc. declarations */
+#include "Configint.h"
+
+#include "fbc_edit_config.h"	/* Write an updated config file */
+#include "fbc_Option.h"		/* Edit Option lists */
+
+
+XF86ConfScrnMonitorEntryPtr fbc_find_active_Monitor_entry(
+	XF86ConfScrnMonitorEntryPtr scrn_monitor_lst); /* Monitor entry list */
+
+int fbc_insert_Monitor_entry(
+	XF86ConfScreenPtr screen_sectn_ptr, /* Ptr to current Screen section */
+	XF86ConfMonitorPtr monitor_sectn_ptr, /* Ptr to cur Monitor section */
+	XF86ConfScrnMonitorEntryPtr *mon_ptr); /* Ptr to Monitor entry */
+
+const char *fbc_find_active_Mode_name(
+	XF86ConfDisplayPtr display_subsectn_ptr); /* Ptr to Display subsectn */
+
+XF86ConfDisplayPtr fbc_find_active_Display_subsection(
+	XF86ConfScreenPtr screen_sectn_ptr, /* Ptr to active Screen section */
+	XF86ConfScrnMonitorEntryPtr mon_ptr, /* Ptr to active Monitor entry */
+	XF86ConfDisplayPtr scrn_display_lst); /* Display subsection list */
+
+XF86ConfScreenPtr fbc_find_active_Screen_section(
+	XF86ConfScreenPtr conf_screen_lst, /* Head of Screen section list */
+	const char	* const	device_identifier); /* Device name */
+
+int fbc_edit_Display_subsection(
+	XF86ConfDisplayPtr display_subsectn_ptr, /* Ptr to Display subsectn */
+	xf86_ent_mod_t	*xf86_entry_mods); /* Config entry modifications */
+
+int fbc_insert_Display_subsection(
+	XF86ConfScreenPtr screen_ptr,	/* Ptr to new Screen section IR */
+	fbc_line_elem_t *next_line_er,	/* Line ER following insertion point */
+	XF86ConfScrnMonitorEntryPtr mon_ptr, /* Ptr to Monitor entry */
+	XF86ConfDisplayPtr *display_ptr); /* Ptr to new Display subsectn IR */
+
+int fbc_edit_Screen_section(
+	XF86ConfScreenPtr screen_sectn_ptr, /* Ptr to Screen section IR */
+	xf86_ent_mod_t	*xf86_entry_mods); /* Config entry modifications */
+
+int fbc_insert_Screen_section(
+	XF86ConfigPtr	configIR,	/* Config Internal Representation */
+	fbc_line_elem_t *next_line_er,	/* Line ER following insertion point */
+	const char	*scrn_ident_tmpl, /* Screen section ident template */
+	const char	*scrn_device_str, /* Device section identifier */
+	XF86ConfScreenPtr *screen_ptr); /* Ptr to new Screen section IR */
+
+
+#endif	/* _FBC_SCREEN_C */
+
+
+/* End of fbc_Screen.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_append_config.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_append_config - Append configuration file supplement
+ */
+
+
+#include <stdio.h>		/* NULL */
+#include <stdlib.h>		/* exit() */
+
+#include "xf86Parser.h"		/* Public function, etc. declarations */
+#include "Configint.h"		/* Private definitions, etc. */
+#include "configProcs.h"	/* Private function, etc. declarations */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_append_config.h"	/* Append configuration file supplement */
+#include "fbc_error.h"		/* Error reporting */
+
+
+/*
+ * fbc_append_config()
+ *
+ *    Open a configuration supplement file and append it to the Internal
+ *    and External representation of the current configuration.
+ *
+ *    A supplement name and corresponding supplement pathname might be:
+ *        "SunModes"    /usr/lib/fbconfig/SunModes_xorg.conf
+ */
+
+int
+fbc_append_config(
+	XF86ConfigPtr	configIR,	/* Config Internal Representation */
+	const char	*supplement_name) /* Config supplement name prefix */
+{
+	const char	*supplement_path; /* Config supplement pathname */
+
+	/*
+	 * Open the config supplement file, /usr/lib/fbconfig/<name>_xorg.conf
+	 */
+	supplement_path = xf86openConfigFileIn("%P/%R_xorg.conf",
+						supplement_name,
+						FBC_LIB_DIR);
+	if (supplement_path == NULL) {
+		return (FBC_ERR_OPEN);
+	}
+	xf86conffree((char *)supplement_path);	/* Don't need this path */
+
+#if (0)	/* This may or may not be necessary */
+	/*
+	 * Set effective UID to real UID while reading config file
+	 */
+	if (euid != uid) {
+		if (seteuid(uid) != 0) {
+			fbc_errormsg(
+				"Unable to set effective user ID\n");
+			exit(FBC_EXIT_FAILURE);
+		}
+	}
+
+#endif	/* This may or may not be necessary */
+	/*
+	 * Read the configuration supplement file
+	 */
+	if (xf86readNextConfigFile(configIR) == NULL) {
+		fbc_errormsg("Error in configuration file, %s\n",
+				supplement_path);
+		exit(FBC_EXIT_FAILURE);	/* Just lost all config IR data */
+	}
+#if (0)	/* This may or may not be necessary */
+	if (euid != uid) {
+		(void) seteuid(euid);
+	}
+#endif	/* This may or may not be necessary */
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_append_config() */
+
+
+/* End of fbc_append_config.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_append_config.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_append_config - Append configuration file supplement
+ */
+
+
+
+#ifndef	_FBC_APPEND_CONFIG_H
+#define	_FBC_APPEND_CONFIG_H
+
+
+#include "xf86Parser.h"		/* Public function, etc. declarations */
+
+
+int fbc_append_config(
+	XF86ConfigPtr	configIR,	/* Config Internal Representation */
+	const char	*supplement_name); /* Config supplement name prefix */
+
+
+#endif	/* _FBC_APPEND_CONFIG_H */
+
+
+/* End of fbc_append_config.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_ask.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_ask - User interaction
+ */
+
+
+#include <ctype.h>		/* iscntrl(), toupper() */
+#include <stdarg.h>		/* va_end(), va_start(), vfprintf() */
+#include <stdio.h>		/* fflush(), fgets(), fprintf() */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_ask.h"		/* User interaction */
+#include "fbc_error.h"		/* Error reporting */
+
+
+/*
+ * fbc_ask_yes_no()
+ *
+ *    Ask a variable format yes/no question of the user, read the reply,
+ *    and return TRUE iff the reply seems to be in the affirmative.
+ */
+
+int
+fbc_ask_yes_no(
+	const char	*format,	/* Prompt format string */
+	...)				/* Variable argument list for prompt */
+{
+	va_list		ap;		/* Variable argument pointer */
+	char		input_buf[128];	/* Yes/no input buffer */
+	int		reply;		/* TRUE => Affirmative response */
+
+	/*
+	 * Flush any fbc_errormsg() messages that might explain why we're here
+	 */
+	fflush(stderr);
+
+	/*
+	 * Ask the question until an answer makes sense
+	 */
+	va_start(ap, format);
+
+	reply = FALSE;
+	for (;;) {
+		/*
+		 * Display the variable format yes/no prompt
+		 */
+		(void) fprintf(stdout, "%s: ", fbc_prog_name);
+		(void) vfprintf(stdout, format, ap);
+
+		/*
+		 * Read the reply, and return the sense of the answer
+		 *
+		 *    Ignore any but the first input character.
+		 *    Treat 'Y' or 'y' as affirmative.
+		 *    Treat 'N' or 'n' as negative.
+		 *    Treat Newline, Nul, or any other control character
+		 *    as negative.
+		 *    Treat EOF or any input error as negative.
+		 *    Loop again if the cat stepped on some other key.
+		 */
+		if ((fgets(input_buf, sizeof (input_buf), stdin) == NULL) ||
+		    iscntrl(input_buf[0]) ||
+		    (toupper(input_buf[0]) == 'N')) {
+			break;
+		}
+		if (toupper(input_buf[0]) == 'Y') {
+			reply = TRUE;
+			break;
+		}
+	}
+
+	va_end(ap);
+
+	return (reply);
+
+}	/* fbc_ask_yes_no() */
+
+
+/* End of fbc_ask.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_ask.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_ask - User interaction
+ */
+
+
+
+#ifndef _FBC_ASK_H
+#define	_FBC_ASK_H
+
+
+int fbc_ask_yes_no(
+	const char	*format,	/* Prompt format string */
+	...);				/* Variable argument list for prompt */
+
+
+#endif	/* _FBC_ASK_H */
+
+
+/* End of fbc_ask.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_dev.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,515 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_dev - Identify the graphics device (-dev opt)
+ */
+
+
+#include <sys/param.h>		/* MAXPATHLEN */
+#include <ctype.h>		/* isdigit() */
+#include <errno.h>		/* errno */
+#include <stdlib.h>		/* strchr(), strtol() */
+#include <string.h>		/* memset(), strcasecmp(), strerror(), ... */
+#include <unistd.h>		/* readlink() */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_open_device.h"	/* Open the frame buffer device */
+
+
+/*
+ * fbc_get_device_arg()
+ *
+ *    Scan the fbconf_xorg(1M) program command line options in order to
+ *    find the (first) frame buffer device name (-dev) argument, if any.
+ *    Return a pointer to the -dev argument string, else a NULL pointer.
+ *
+ *    Considerations:
+ *        * The -dev option must be fully spelled out, not abbreviated.
+ *          Until the device type is known, we don't know what other
+ *          command line options might be supported.  At least one of
+ *          -defaults, -defdepth, -deflinear, -defoverlay, or
+ *          -deftransparent is likely to be supported, in which case
+ *          the full spelling of -dev would be needed anyway.
+ *        * No command line option is likely to be given a "-dev"
+ *          argument.
+ */
+
+int
+fbc_get_device_arg(
+	const int	argc,		/* Program argument count */
+	char	* const	argv[],		/* Program argument vector */
+	const char	**device_arg)	/* Returned effective arg to -dev */
+
+{
+	int		arg;		/* Program cmd line arg index */
+
+	/*
+	 * Find the (first, if any) -dev option and return its argument
+	 *
+	 *    The last argv[] string is ignored.  The -dev option
+	 *    requires an argument, so "-dev" can't legitimately be the
+	 *    last argv[] string.  The fbc_getargs() function should
+	 *    handle the "Option requires a value" error.
+	 */
+	*device_arg = NULL;
+	for (arg = 1; arg < (argc - 1); arg += 1) {
+		if (strcasecmp(argv[arg], "-dev") == 0) {
+			*device_arg = argv[arg+1];
+			break;
+		}
+	}
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_get_device_arg() */
+
+
+/*
+ * fbc_resolve_device_links()
+ *
+ *
+ *    The device_path_buf buffer is assumed to be unused.
+ */
+
+static
+int
+fbc_resolve_device_links(
+	const char	*default_path,	/* Default device symlink path */
+	char		*device_path_buf, /* Ptr to device path buffer */
+	size_t		device_path_buflen, /* Device path buffer length */
+	fbc_dev_t	*device)	/* Returned device names, etc. */
+{
+	int		i;		/* Symlink loop counter */
+	ssize_t		len;		/* Pathname length (signed) */
+	char		*ptr;		/* Ptr to pathname component */
+	char		respath_buf[MAXPATHLEN]; /* Symlink path buffer */
+	char		symlink_buf[MAXPATHLEN]; /* Resolution path buffer */
+
+	/*
+	 * Resolve the symlink to a "/devices/...:<devname>" pathname
+	 *
+	 *    A resolved symlink string could resemble one of these (or
+	 *    some else unhelpful):
+	 *        fbs/kfb0
+	 *        /dev/fbs/kfb0
+	 *        /devices/pci@1f,700000/SUNW,XVR-2500@0:kfb0
+	 *    Examples like the first one are only acceptable as
+	 *    intermediate resolutions.  Examples like the second are
+	 *    what we want ultimately, but might not encounter.
+	 *    Examples like the third should be the resolution of the
+	 *    final symlink (e.g. second exmple).
+	 */
+	len = strlen(default_path);
+	if (len >= sizeof (symlink_buf)) {
+		return (FBC_ERR_READLINK);
+	}
+	memcpy(symlink_buf, default_path, len+1);
+
+	for (i = 16; ; i -= 1) {
+		if (i <= 0) {
+			return (FBC_ERR_READLINK);	/* ELOOP */
+		}
+
+		/*
+		 * Resolve this symbolic link (if that's what it is)
+		 */
+		memset(respath_buf, '\0', sizeof (respath_buf));
+		len = readlink(symlink_buf,
+				respath_buf, sizeof (respath_buf) - 1);
+		if (len < 0) {
+			if (errno == EINVAL) {
+				break;	/* Not a symbolic link */
+			}
+			fbc_errormsg("%s, %s\n",
+					strerror(errno), symlink_buf);
+			return (FBC_ERR_READLINK);
+		}
+
+		/*
+		 * Make sure the end result is a full pathname
+		 */
+		ptr = &symlink_buf[0];	/* To overwrite the entire link path */
+		if (respath_buf[0] != '/') {
+			ptr = strrchr(symlink_buf, '/');
+			if (ptr == NULL) {
+				ptr = &symlink_buf[0];
+			} else {
+				ptr += 1;
+			}
+		}
+		if ((ptr - &symlink_buf[0] + len) >= sizeof (respath_buf)) {
+			return (FBC_ERR_READLINK);
+		}
+		memcpy(ptr, respath_buf, len+1);
+	}
+
+	/*
+	 * Convert "/devices/...:<devname>" to <devname>
+	 *
+	 *    Merely assume that the final resolution pathname specifies
+	 *    the correct "/devices/..." directory, realizing that it
+	 *    actually might look something like this:
+	 *        /dev/fb/../../devices/pci@1f,700000/SUNW,XVR-2500@0:kfb0
+	 *
+	 *    The simple filename component must match "*:<devname>".
+	 */
+	ptr = strrchr(symlink_buf, ':');
+	if (ptr == NULL) {
+		return (FBC_ERR_READLINK);
+	}
+	ptr += 1;
+
+	/*
+	 * Construct the device pathname and point to the simple filename
+	 */
+	len = strlen(FBC_DEVICE_DIR "/");
+	if ((len + strlen(ptr)) >= device_path_buflen) {
+		return (FBC_ERR_READLINK);
+	}
+	memcpy(device_path_buf, FBC_DEVICE_DIR "/", len);
+	device->path = device_path_buf;
+	strcpy(device_path_buf + len, ptr);
+	device->name = device_path_buf + len;
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_resolve_device_links() */
+
+
+/*
+ * fbc_parse_device_filename()
+ *
+ *    Decompose the device simple filename into:
+ *      * Device type/driver name
+ *      * Device "unit" number, if specified, else -1 (arbitrary)
+ *      * Device stream/screen character: '\0', 'a', 'b', ...
+ *    Return a non-zero error code, FBC_ERR_NAME_LEN, if the
+ *    caller's buffer isn't long enough.
+ */
+
+static
+int
+fbc_parse_device_filename(
+	char		*device_type_buf, /* Ptr to device type buffer */
+	size_t		device_type_buflen, /* Device type buffer length */
+	fbc_dev_t	*device)	/* Returned device names, etc. */
+{
+	const char *const stream_suffix_chars = FBC_STREAM_SUFFIX_CHARS;
+	const char	*cp;		/* Ptr into device name string */
+	int		len;		/* Length of device type substring */
+	const char	*suffix_cp;	/* Ptr to suffix char, else NULL */
+
+	/*
+	 * Parse the video stream suffix, if any
+	 *
+	 *    If present, the video stream suffix is generally a lower
+	 *    case letter, 'a' or 'b', following the unit number, as the
+	 *    last character of the simple device name (e.g. 'a' in
+	 *    "efb0a").  No video stream suffix will be found if the
+	 *    unit number is not present.  If no video stream suffix is
+	 *    found then store a Nul.
+	 *
+	 *    The set of valid video stream suffix characters is
+	 *    contained in the FBC_STREAM_SUFFIX_CHARS string.  If the
+	 *    device name has a video stream suffix that isn't
+	 *    appropriate for the device (e.g. 'b' in "kfb0b"), the
+	 *    subsequent fbc_open_device() call can be expected to fail.
+	 *
+	 *    The actual device->max_streams value should be provided
+	 *    later via fbc_get_properties().  We'll use a "safe" value
+	 *    until fbc_get_properties() and fbc_revise_device_info()
+	 *    can be called.
+	 */
+	device->stream_char = '\0';	/* Represents all video streams */
+	device->stream_lo   = 0;	/* First video stream */
+	device->stream_hi   = 0;	/* Bounded by device->max_streams */
+	device->max_streams = 1;	/* Provided via fbc_get_properties() */
+
+	len = strlen(device->name);
+	if ((len >= 2) && (isdigit(*(device->name + len - 2)))) {
+		cp = device->name + len - 1;
+		suffix_cp =  strchr(stream_suffix_chars, *cp);
+		if (suffix_cp != NULL) {
+			device->stream_char = *cp;
+			device->stream_lo   = suffix_cp - stream_suffix_chars;
+			device->stream_hi   = device->stream_lo;
+			len -= 1;
+		}
+	}
+
+	/*
+	 * Parse the frame buffer "unit" number, if any
+	 */
+	for (cp = device->name + len; cp > device->name; cp -= 1) {
+		if (!isdigit(*(cp-1))) {
+			break;
+		}
+	}
+	device->number = -1;
+	if (*cp != '\0') {
+		device->number = (int)strtol(cp, NULL, 10);
+	}
+
+	/*
+	 * Copy the device type/driver substring into the caller's buffer
+	 */
+	device->type = device_type_buf;
+	len = cp - device->name;
+	if (len >= device_type_buflen) {
+		*device_type_buf = '\0'; /* Empty string */
+		return (FBC_ERR_NAME_LEN); /* Device type name is too long */
+	}
+	memcpy(device_type_buf, device->name, len);
+	*(device_type_buf + len) = '\0';
+
+	/*
+	 * Return a pointer to the device type/driver string
+	 */
+	return (FBC_SUCCESS);
+
+}	/* fbc_parse_device_filename() */
+
+
+typedef struct {
+	char		*pathname;	/* Full pathname    (e.g. "/dev/fb") */
+	char		*filename;	/* Simple filename  (e.g. "fb")      */
+} fbc_path_file_t;
+
+static const fbc_path_file_t fbc_default_device[] = {
+	{ FBC_DEVICE_SYMLINK_PATH,	FBC_DEVICE_SYMLINK_NAME  	},
+	{ FBC_DEVICE_SYMLINK_PATH_0,	FBC_DEVICE_SYMLINK_NAME_0	},
+	{ NULL,				NULL				}
+};
+
+
+/*
+ * fbc_get_default_device()
+ *
+ *    Determine the most likely default frame buffer device (e.g.
+ *    "/dev/fb" or "/dev/fb0") and return pointers to:
+ *      * Full pathname of the device   (e.g. "/dev/fbs/efb0a")
+ *      * Simple device filename        (e.g. "efb0a")
+ *      * Device type/driver name       (e.g. "efb")
+ *      * Device "unit" number, if specified, else -1 (arbitrary)
+ *      * Device stream/screen character: '\0', 'a', 'b', ...
+ */
+
+int
+fbc_get_default_device(
+	char		*device_path_buf, /* Ptr to device path buffer */
+	size_t		device_path_buflen, /* Device path buffer length */
+	char		*device_type_buf, /* Ptr to device type buffer */
+	size_t		device_type_buflen, /* Device type buffer length */
+	fbc_dev_t	*device)	/* Returned device name components */
+{
+	const fbc_path_file_t *default_dev; /* Ptr into fbc_default_device[] */
+	int		error_code;	/* Error code (see errno.h) */
+
+	/*
+	 * See whether any default device will open and identify itself
+	 */
+	for (default_dev = &fbc_default_device[0]; ; default_dev += 1) {
+		if (default_dev->pathname == NULL) {
+			return (FBC_ERR_OPEN); /* No default device found */
+		}
+		device->path = default_dev->pathname;
+		if (fbc_open_device(device) == FBC_SUCCESS) {
+			break;
+		}
+	}
+
+	/*
+	 * Resolve symbolic links and construct the device file pathname
+	 */
+	error_code = fbc_resolve_device_links(default_dev->pathname,
+						device_path_buf,
+						device_path_buflen,
+						device);
+	if (error_code != FBC_SUCCESS) {
+		return (error_code);
+	}
+
+	/*
+	 * Decompose the simple filename of the frame buffer device
+	 */
+	return (fbc_parse_device_filename(
+			device_type_buf, device_type_buflen, device));
+
+}	/* fbc_get_default_device() */
+
+
+/*
+ * fbc_get_device_name()
+ *
+ *    Given a -dev argument string, a device pathname buffer, and a
+ *    device type/driver name buffer, return pointers to:
+ *      * Full pathname of the device   (e.g. "/dev/fbs/efb0a")
+ *      * Simple device filename        (e.g. "efb0a")
+ *      * Device type/driver name       (e.g. "efb")
+ *      * Device "unit" number, if specified, else -1 (arbitrary)
+ *      * Device stream/screen character: '\0', 'a', 'b', ...
+ *
+ *    A caller-supplied buffer might be needed in order to construct the
+ *    full pathname string.  Return NULL if the caller's buffer is
+ *    needed but isn't long enough.
+ *
+ *    The device name string will be extracted into a second, caller-
+ *    supplied buffer.  Return an error code if the caller's buffer
+ *    isn't long enough.
+ */
+
+int
+fbc_get_device_name(
+	const char	*device_arg,	/* Device argument (-dev opt) */
+	char		*device_path_buf, /* Ptr to device path buffer */
+	size_t		device_path_buflen, /* Device path buffer length */
+	char		*device_type_buf, /* Ptr to device type buffer */
+	size_t		device_type_buflen, /* Device type buffer length */
+	fbc_dev_t	*device)	/* Returned device name components */
+{
+	const fbc_path_file_t *default_dev; /* Ptr into fbc_default_device[] */
+	const char	*device_dir;	/* Ptr to "/dev/fbs/" or "/dev/" */
+	size_t		device_dir_len;	/* Length of "/dev/fbs/", etc. */
+	int		error_code;	/* Error code (zero => success) */
+	const char	*sep_ptr;	/* Ptr to pathname seperator char */
+
+	/*
+	 * Assume it's the fully qualified path of a real device
+	 */
+	device->path = device_arg;
+
+	/*
+	 * Resolve any default device name
+	 */
+	for (default_dev = &fbc_default_device[0];
+	    default_dev->pathname != NULL;
+	    default_dev += 1) {
+		if ((strcmp(device_arg, default_dev->pathname) == 0) ||
+		    (strcmp(device_arg, default_dev->filename) == 0)) {
+			error_code = fbc_resolve_device_links(
+						default_dev->pathname,
+						device_path_buf,
+						device_path_buflen,
+						device);
+			if (error_code != FBC_SUCCESS) {
+				return (error_code);
+			}
+			device_arg = device->path;
+			break;
+		}
+	}
+
+	/*
+	 * Determine the device pathname, simple name, type/driver, etc.
+	 */
+	sep_ptr = strrchr(device_arg, '/');
+	if (sep_ptr == NULL) {
+		/*
+		 * Decompose the simple device name, yeilding its type, etc.
+		 */
+		device->name = device_arg;
+		error_code   = fbc_parse_device_filename(device_type_buf,
+						 	device_type_buflen,
+							device);
+
+		/*
+		 * Determine the device directory path for this device type
+		 *
+		 *    We'll handle the "fb" => "/dev/fb" case, but this
+		 *    should have been done in fbc_get_device_arg().
+		 */
+		device_dir = FBC_DEVICE_DIR "/";
+		if (strcmp(device->name, FBC_DEVICE_SYMLINK_NAME) == 0) {
+			device_dir = FBC_DEVICE_SYMLINK_DIR "/";
+		}
+
+		/*
+		 * Construct a full pathname (iff it fits in the buffer)
+		 */
+		device_dir_len = strlen(device_dir);
+		if ((device_dir_len + strlen(device_arg))
+						>= device_path_buflen) {
+			return (FBC_ERR_PATH_LEN); /* Path is too long */
+		}
+		memcpy(device_path_buf, device_dir, device_dir_len);
+		device->path = device_path_buf;
+		device->name = device_path_buf + device_dir_len;
+		strcpy(device_path_buf + device_dir_len, device_arg);
+	} else {
+		/*
+		 * Point to the simple device name within the device pathname
+		 */
+		device->name = sep_ptr + 1;
+
+		/*
+		 * Decompose the frame buffer's simple device name
+		 */
+		error_code = fbc_parse_device_filename(device_type_buf,
+							device_type_buflen,
+							device);
+	}
+
+	/*
+	 * Return successfully or with a buffer overflow error
+	 */
+	return (error_code);
+
+}	/* fbc_get_device_name() */
+
+
+/*
+ * fbc_revise_device_info()
+ *
+ *    Finish the video streams initialization that
+ *    fbc_parse_device_filename() didn't have enough information to do.
+ *
+ *    Before this function can be called, the fbc_get_properties() must
+ *    be called in order to fill in the device->max_streams value.
+ */
+
+void
+fbc_revise_device_info(
+	fbc_dev_t	*device)	/* Revised frame buffer device info */
+{
+
+	/*
+	 * An absent video stream suffix character signifies all streams
+	 *
+	 *    A video stream suffix character that is out of range (e.g.
+	 *    'b' in "kfb0b") can be logically ignored here, since the
+	 *    subsequent fbc_open_device() call ought to fail.
+	 */
+	if ((device->stream_char == '\0') ||
+	    (device->stream_hi >= device->max_streams)) {
+		device->stream_char   = '\0';
+		device->stream_lo = 0;
+		device->stream_hi = device->max_streams - 1;
+	}
+
+}	/* fbc_revise_device_info() */
+
+
+/* End of fbc_dev.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_dev.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_dev - Identify the graphics device (-dev opt)
+ */
+
+
+
+#ifndef	_FBC_DEV_H
+#define	_FBC_DEV_H
+
+
+#include <string.h>		/* size_t */
+#include <sys/visual_io.h>	/* VISUAL environment device identifier */
+
+
+/*
+ * Frame buffer device information (derived from the effective -dev argument)
+ */
+typedef struct {
+	const char	*path;		/* Full path (e.g. "/dev/fbs/efb0a") */
+	const char	*name;		/* Simple filename (e.g. "efb0a") */
+	const char	*type;		/* Device type name (e.g. "efb") */
+	int		number;		/* Unit number, else -1 */
+	char		stream_char;	/* Stream suffix { '\0', 'a', 'b' } */
+	char		stream_lo;	/* Stream index lower bound { 0..1 } */
+	char		stream_hi;	/* Stream index upper bound { 0..1 } */
+	int		max_streams;	/* Number of video streams { 1..2 } */
+	int		fd;		/* File descriptor number, else -1 */
+	int		is_default;	/* TRUE => Is default frame buffer */
+	struct vis_identifier vis_ident; /* VISUAL environment identifier */
+} fbc_dev_t;
+
+
+int fbc_get_device_arg(
+	const int	argc,		/* Program argument count */
+	char	* const	argv[],		/* Program argument vector */
+	const char	**device_arg);	/* Returned effective arg to -dev */
+
+int fbc_get_default_device(
+	char		*device_path_buf, /* Ptr to device path buffer */
+	size_t		device_path_buflen, /* Device path buffer length */
+	char		*device_type_buf, /* Ptr to device type buffer */
+	size_t		device_type_buflen, /* Device type buffer length */
+	fbc_dev_t	*device);	/* Returned device name components */
+
+int fbc_get_device_name(
+	const char	*device_arg,	/* Device argument (-dev opt) */
+	char		*device_path_buf, /* Ptr to device path buffer */
+	size_t		device_path_buflen, /* Device path buffer length */
+	char		*device_type_buf, /* Ptr to device type buffer */
+	size_t		device_type_buflen, /* Device type buffer length */
+	fbc_dev_t	*device);	/* Returned device name components */
+
+void fbc_revise_device_info(
+	fbc_dev_t	*device);	/* Revised frame buffer device info */
+
+
+#endif	/* _FBC_DEV_H */
+
+
+/* End of fbc_dev.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_edid_test_data.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,691 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_edid_data - EDID test data
+ */
+
+
+
+/*
+ * This module can be employed by inserting lines such as the following
+ * into the code to be tested (e.g. fbc_prconf.c, fbc_predid.c).  It is
+ * assumed that edid_data and edid_length are the appropriate variable
+ * names.
+ *
+ *    #define FBC_EDID_TEST_DATA <n>
+ *
+ *    #if defined(FBC_EDID_TEST_DATA)
+ *    #include "fbc_edid_test_data.h"
+ *    #endif
+ *
+ *    $ make -f Makefile.fbc clobber all DEFINE=-DFBC_EDID_TEST_DATA=<n>
+ */
+
+
+{
+
+/*
+ * EXAMPLE 1: Sample BASE EDID (Block 0) for an LCD Desktop IT Display
+ *
+ *    "VESA Enhanced Extended Display Identification Data Standard,"
+ *    Release A, Revision 2, September 25, 2006.  (EDID 1.4)
+ */
+const uint8_t fbc_edid_test_data_ex1[1 * 0x80] = {
+
+	/* EDID Base Block (Block 0) */
+
+	    /* Header */
+		0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
+	    /* Vendor & Product Identification */
+		0x04, 0x43, 0x06, 0xF2, 0x01, 0x00, 0x00, 0x00,
+		0x01, 0x11,
+	    /* EDID Structure Version & Revision */
+		0x01, 0x04,
+	    /* Basic Display Parameters & Features */
+		0x0F, 0x2B, 0x20, 0x78, 0x2B,
+	    /* Color Characteristics */
+		0x9C, 0x68, 0xA0, 0x57, 0x4A, 0x9B, 0x26, 0x12,
+		0x48, 0x4C,
+	    /* Established Timings */
+		0xFF, 0xFF, 0x80,
+	    /* Standard Timings */
+		0xA9, 0x59, 0xA9, 0x4F, 0xA9, 0x4A, 0xA9, 0x45,
+		0x81, 0x99, 0x81, 0x80, 0x61, 0x59, 0x45, 0x59,
+	    /* 18-Byte Data Block #1 */
+		/* Preferred Timing Mode */
+		0x48, 0x3F, 0x40, 0x30, 0x62, 0xB0, 0x32, 0x40,
+		0x40, 0xC0, 0x13, 0x00, 0xAB, 0x40, 0x11, 0x00,
+		0x00, 0x1E,
+	    /* 18-Byte Data Block #2 */
+		/* Display Range Limits Descriptor With CVT Support Info */
+		0x00, 0x00, 0x00, 0xFD, 0x00, 0x32, 0x5A, 0x1E,
+		0x6E, 0x17, 0x04, 0x11, 0x00, 0xC8, 0x90, 0x00,
+		0x50, 0x3C,
+	    /* 18-Byte Data Block #3 */
+		/* Established Timings III Display Descriptor */
+		0x00, 0x00, 0x00, 0xF7, 0x00, 0x0A, 0xF7, 0x0F,
+		0x03, 0x87, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00,
+	    /* 18-Byte Data Block #4 */
+		/* Display Product Name (ASCII) String */
+		0x00, 0x00, 0x00, 0xFC, 0x00, 0x41, 0x42, 0x43,
+		0x20, 0x4C, 0x43, 0x44, 0x32, 0x31, 0x0A, 0x20,
+		0x20, 0x20,
+	    /* Extension Block Count N */
+		0x00,
+	    /* Checksum C */
+		0x0B
+
+};
+
+
+/*
+ * EXAMPLE 2: Sample BASE EDID & CEA861 Extension for a DTV Display
+ *
+ *    "VESA Enhanced Extended Display Identification Data Standard,"
+ *    Release A, Revision 2, September 25, 2006.  (EDID 1.4)
+ */
+const uint8_t fbc_edid_test_data_ex2[2 * 0x80] = {
+
+	/* EDID Base Block (Block 0) */
+
+	    /* Header */
+		0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
+	    /* Vendor & Product Identification */
+		0x04, 0x43, 0x07, 0xF2, 0x01, 0x00, 0x00, 0x00,
+		0xFF, 0x11,
+	    /* EDID Structure Version & Revision */
+		0x01, 0x04,
+	    /* Basic Display Parameters & Features */
+		0xA2, 0x4F, 0x00, 0x78, 0x1E,
+	    /* Color Characteristics */
+		0xEE, 0x91, 0xA3, 0x54, 0x4C, 0x99, 0x26, 0x0F,
+		0x50, 0x54,
+	    /* Established Timings */
+		0x20, 0x00, 0x00,
+	    /* Standard Timings */
+		0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+		0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+	    /* 18-Byte Data Block #1 */
+		/* Preferred Timing Mode */
+		0x02, 0x3A, 0x80, 0x18, 0x71, 0x38, 0x2D, 0x40,
+		0x58, 0x2C, 0x04, 0x05, 0x0F, 0x48, 0x42, 0x00,
+		0x00, 0x1E,
+	    /* 18-Byte Data Block #2 */
+		/* Detailed Timing Descriptor */
+		0x01, 0x1D, 0x80, 0x18, 0x71, 0x1C, 0x16, 0x20,
+		0x58, 0x2C, 0x25, 0x00, 0x0F, 0x48, 0x42, 0x00,
+		0x00, 0x9E,
+	    /* 18-Byte Data Block #3 */
+		/* Detailed Timing Descriptor */
+		0x01, 0x1D, 0x00, 0x72, 0x51, 0xD0, 0x1E, 0x20,
+		0x6E, 0x28, 0x55, 0x00, 0x0F, 0x48, 0x42, 0x00,
+		0x00, 0x1E,
+	    /* 18-Byte Data Block #4 */
+		/* Monitor Name ASCII Descriptor */
+		0x00, 0x00, 0x00, 0xFC, 0x00, 0x41, 0x42, 0x43,
+		0x20, 0x4C, 0x43, 0x44, 0x34, 0x37, 0x77, 0x0A,
+		0x20, 0x20,
+	    /* Extension Block Count N */
+		0x01,
+	    /* Checksum C */
+		0xCB,
+
+	/* CEA 861 EXTENSION Block Version 3 (Block 1) */
+
+	    /* Extension Block Tag Number */
+		0x02,
+	    /* Extension Block Revision Number */
+		0x03,
+	    /*  */
+		0x18, 0x72, 0x47, 0x90, 0x85, 0x04, 0x03, 0x02,
+		0x07, 0x06, 0x23, 0x09, 0x07, 0x07, 0x83, 0x01,
+		0x00, 0x00, 0x65, 0x03, 0x0C, 0x00, 0x10, 0x00,
+	    /* 18-Byte Data Block #5 */
+		/* Detailed Timing */
+		0x8E, 0x0A, 0xD0, 0x8A, 0x20, 0xE0, 0x2D, 0x10,
+		0x10, 0x3E, 0x96, 0x00, 0x1F, 0x09, 0x00, 0x00,
+		0x00, 0x18,
+	    /* 18-Byte Data Block #6 */
+		/* Detailed Timing */
+		0x8E, 0x0A, 0xD0, 0x8A, 0x20, 0xE0, 0x2D, 0x10,
+		0x10, 0x3E, 0x96, 0x00, 0x04, 0x03, 0x00, 0x00,
+		0x00, 0x18,
+	    /* 18-Byte Data Block #7 */
+		/* Detailed Timing */
+		0x8E, 0x0A, 0xA0, 0x14, 0x51, 0xF0, 0x16, 0x00,
+		0x26, 0x7C, 0x43, 0x00, 0x1F, 0x09, 0x00, 0x00,
+		0x00, 0x98,
+	    /* 18-Byte Data Block #8 */
+		/* Detailed Timing */
+		0x8E, 0x0A, 0xA0, 0x14, 0x51, 0xF0, 0x16, 0x00,
+		0x26, 0x7C, 0x43, 0x00, 0x04, 0x03, 0x00, 0x00,
+		0x00, 0x98,
+	    /* Unused Addresses */
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00,
+	    /* Checksum */
+		0xC9
+
+};
+
+
+/*
+ * EXAMPLE 3: Sample BASE EDID & CEA861 Extension for a IT/DTV Display
+ *
+ *    "VESA Enhanced Extended Display Identification Data Standard,"
+ *    Release A, Revision 2, September 25, 2006.  (EDID 1.4)
+ */
+const uint8_t fbc_edid_test_data_ex3[2 * 0x80] = {
+
+	/* EDID Base Block (Block 0) */
+
+	    /* Header */
+		0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
+	    /* Vendor & Product Identification */
+		0x04, 0x43, 0x08, 0xF2, 0x01, 0x00, 0x00, 0x00,
+		0x10, 0x11,
+	    /* EDID Structure Version & Revision */
+		0x01, 0x04,
+	    /* Basic Display Parameters & Features */
+		0xA2, 0x79, 0x44, 0x78, 0x1E,
+	    /* Color Characteristics */
+		0xEE, 0x91, 0xA3, 0x54, 0x4C, 0x99, 0x26, 0x0F,
+		0x50, 0x54,
+	    /* Established Timings */
+		0xFF, 0xEF, 0x80,
+	    /* Standard Timings */
+		0x81, 0x99, 0x81, 0x80, 0x81, 0x59, 0x81, 0x40,
+		0x61, 0x59, 0x4B, 0xC0, 0x45, 0x59, 0x31, 0x59,
+	    /* 18-Byte Data Block #1 */
+		/* Preferred Timing Mode */
+		0x66, 0x21, 0x50, 0xB0, 0x51, 0x00, 0x1B, 0x30,
+		0x40, 0x70, 0x36, 0x00, 0xBE, 0xAB, 0x42, 0x00,
+		0x00, 0x1E,
+	    /* 18-Byte Data Block #2 */
+		0x01, 0x1D, 0x00, 0x72, 0x51, 0xD0, 0x1E, 0x20,
+		0x6E, 0x28, 0x55, 0x00, 0xBE, 0xAB, 0x42, 0x00,
+		0x00, 0x1E,
+	    /* 18-Byte Data Block #3 */
+		0x00, 0x00, 0x00, 0xF7, 0x00, 0x0A, 0xF7, 0x0F,
+		0x03, 0x87, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00,
+	    /* 18-Byte Data Block #4 */
+		0x00, 0x00, 0x00, 0xFC, 0x00, 0x41, 0x42, 0x43,
+		0x20, 0x50, 0x4C, 0x41, 0x35, 0x35, 0x0A, 0x20,
+		0x20, 0x20,
+	    /* Extension Block Count N */
+		0x01,
+	    /* Checksum C */
+		0x0A,
+
+	/* CEA 861 EXTENSION Block Version 3 (Block 1) */
+
+	    /* Extension Block Tag Number */
+		0x02,
+	    /* Extension Block Revision Number */
+		0x03,
+	    /*  */
+		0x17, 0xF0, 0x46, 0x05, 0x04, 0x03, 0x02, 0x07,
+		0x06, 0x23, 0x09, 0x07, 0x07, 0x83, 0x01, 0x00,
+		0x00, 0x65, 0x03, 0x0C, 0x00, 0x10, 0x00,
+	    /* 18-Byte Data Block #5 */
+		/* Detailed Timing */
+		0x01, 0x1D, 0x80, 0x18, 0x71, 0x1C, 0x16, 0x20,
+		0x58, 0x2C, 0x25, 0x00, 0x0F, 0x48, 0x42, 0x00,
+		0x00, 0x9E,
+	    /* 18-Byte Data Block #6 */
+		/* Detailed Timing */
+		0x01, 0x1D, 0x00, 0x72, 0x51, 0xD0, 0x1E, 0x20,
+		0x6E, 0x28, 0x55, 0x00, 0x0F, 0x48, 0x42, 0x00,
+		0x00, 0x1E,
+	    /* 18-Byte Data Block #7 */
+		/* Detailed Timing */
+		0x8C, 0x0A, 0xD0, 0x8A, 0x20, 0xE0, 0x2D, 0x10,
+		0x10, 0x3E, 0x96, 0x00, 0xB9, 0x88, 0x21, 0x00,
+		0x00, 0x18,
+	    /* 18-Byte Data Block #8 */
+		/* Detailed Timing */
+		0x8E, 0x0A, 0xA0, 0x14, 0x51, 0xF0, 0x16, 0x00,
+		0x26, 0x7C, 0x43, 0x00, 0xB9, 0x88, 0x21, 0x00,
+		0x00, 0x98,
+	    /* Unused Addresses */
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	    /* Checksum */
+		0x5A
+
+};
+
+
+/*
+ * EDID Base Block  (Based on an actual monitor)
+ *
+ *    Monitor manufacturer: SUN
+ *    Product Code:         4
+ *    Serial Number:        12212555
+ *    Manufacture date:     2000, week 9
+ *    EDID Version:         1.1
+ *
+ * Extension Map Block  (Hand-crafted according to standard)
+ *
+ *    "VESA Enhanced Extended Display Identification Data Standard,"
+ *    Release A, Revision 2, September 25, 2006.  (EDID 1.4)
+ *
+ * DI-EXT Blocks  (Examples 1-4 from standard)
+ *
+ *    "VESA Display Information Extension Block Standard,"
+ *    Release A, August 21, 2001.
+ *
+ * VTB-EXT Block  (Sample from standard)
+ *
+ *    "VESA Video Timing Block Extension Data Standard,"
+ *    Release A, November 24, 2003.
+ */
+const uint8_t fbc_edid_test_data_misc[] = {
+
+	/* EDID Base Block (Block 0) */
+
+	    /* Header */
+		0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
+	    /* Vendor & Product Identification */
+		0x4E, 0xAE, 0x04, 0x00, 0x4B, 0x59, 0xBA, 0x00,
+		0x09, 0x0A,
+	    /* EDID Structure Version & Revision */
+		/* 0x01, 0x01, */
+		0x01, 0x04,
+	    /* Basic Display Parameters & Features */
+		0x0E, 0x24, 0x1D, 0xA2, 0xE8,
+	    /* Color Characteristics */
+		0x8F, 0x17, 0x9B, 0x58, 0x4D, 0x90, 0x25,
+		0x1E, 0x4F, 0x55,
+	    /* Established Timings */
+		0xBF, 0xEF, 0x00,
+	    /* Standard Timings */
+		0x81, 0x80, 0x81, 0x90, 0x71, 0x86, 0x81, 0x8F,
+		0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+	    /* 18-Byte Data Block #1 */
+		/* Preferred Timing Mode */
+		0x30, 0x2A, 0x00, 0x98, 0x51, 0x00, 0x2A, 0x40,
+		0x30, 0x70, 0x13, 0x00, 0x67, 0x1F, 0x11, 0x00,
+		0x00, 0x14,
+	    /* 18-Byte Data Block #2 */
+		/* Detailed Timing */
+		0xBC, 0x34, 0x00, 0x80, 0x51, 0x00, 0x2A, 0x40,
+		0x20, 0x40, 0x28, 0x00, 0x67, 0x1F, 0x11, 0x00,
+		0x00, 0x14,
+	    /* 18-Byte Data Block #3 */
+		/* Detailed Timing */
+		0xEA, 0x24, 0x80, 0x78, 0x41, 0x84, 0x25, 0x30,
+		0x20, 0x80, 0x24, 0x00, 0x43, 0xFC, 0x10, 0x00,
+		0x00, 0x14,
+	    /* 18-Byte Data Block #4 */
+		/* Detailed Timing */
+		0xBC, 0x34, 0x00, 0x98, 0x51, 0x00, 0x2A, 0x40,
+		0x10, 0x90, 0x13, 0x00, 0x67, 0x1F, 0x11, 0x00,
+		0x00, 0x1E,
+	    /* Extension Block Count N */
+		/* 0x00 */
+		0x06,
+	    /* Checksum C */
+		/* 0x33 */
+		0x2A,
+
+	/* Extension Block Map #1 (Block 1) */
+
+	    /* Extension Block Tag Number */
+		0xF0,
+	    /* Extension Block Tag Numbers for subsequent blocks */
+		      0x40, 0x40, 0x40, 0x40, 0x10,
+	    /* Unused Bytes */
+		                                    0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	    /* Checksum */
+		0x00,
+
+	/* EXAMPLE 1: DI-EXT Extension Block */
+
+	    /* General Information section */
+		/* Block Header */
+		0x40,
+		/* DI-EXT Version Number */
+		0x01,
+	    /* Digital Interface section */
+		/* Standard/Specification Supported */
+		0x03,
+		/* Version/Revision Number */
+		0x41, 0x00, 0x00, 0x00,
+		/* Data Format Description */
+		0xD8, 0x48,
+		/* Min, Max & Cross-Over Pixel Clock Frequency */
+		0x19, 0xA5, 0x00, 0xA5, 0x00,
+	    /* Display Device section */
+		/* Sub-Pixel Layout & Shape */
+		0x00, 0x02, 0x00,
+		/* Dot/Pixel Pitch */
+		0x1A, 0x00,
+		/* Major Display Characteristics */
+		0x28,
+	    /* Display Capabilities & Feature Support Set */
+		/* Miscellaneous Display Capabilities */
+		0x80,
+		/* Frame Rate Conversion */
+		0x00, 0x00, 0x00, 0x00, 0x00,
+		/* Display/Scan Orientation */
+		0x42,
+		/* Color/Luminance Coding Description */
+		0x01, 0x00, 0x80, 0x00,
+		/* Monitor Color Depth */
+		0x00, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00,
+		/* Aspect Ratio Conversion Modes */
+		0x00,
+		/* Packetized Digital Video Support Information */
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	    /* Unused Bytes (Reserved) section */
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00,
+	    /* Audio Support (Reserved) section */
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00,
+	    /* Display Transfer Characteristic - Gamma */
+		0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00,
+	    /* Miscellaneous Items */
+		/* Checksum */
+		0x59,
+
+	/* EXAMPLE 2 (modified): DI-EXT Extension Block */
+
+	    /* General Information section */
+		/* Block Header */
+		0x40,
+		/* DI-EXT Version Number */
+		0x01,
+	    /* Digital Interface section */
+		/* Standard/Specification Supported */
+		0x02,
+		/* Version/Revision Number */
+		/* 0x41, 0x00, 0x00, 0x00, */
+		0xC0, 0x0B, 0x08, 0x15,
+		/* Data Format Description */
+		0xD0, 0x24,
+		/* Min, Max & Cross-Over Pixel Clock Frequency */
+		0x19, 0x70, 0x00, 0x00, 0x00,
+	    /* Display Device section */
+		/* Sub-Pixel Layout & Shape */
+		0x00, 0x00, 0x00,
+		/* Dot/Pixel Pitch */
+		0x00, 0x00,
+		/* Major Display Characteristics */
+		0xE4,
+	    /* Display Capabilities & Feature Support Set */
+		/* Miscellaneous Display Capabilities */
+		0x09,
+		/* Frame Rate Conversion */
+		0x60, 0x70, 0x17, 0x00, 0x19,
+		/* Display/Scan Orientation */
+		0x43,
+		/* Color/Luminance Coding Description */
+		0x01, 0x00, 0x80, 0x00,
+		/* Monitor Color Depth */
+		0x00, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00,
+		/* Aspect Ratio Conversion Modes */
+		0xE0,
+		/* Packetized Digital Video Support Information */
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	    /* Unused Bytes (Reserved) section */
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00,
+	    /* Audio Support (Reserved) section */
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00,
+	    /* Display Transfer Characteristic - Gamma */
+		0x6D,
+		0x00, 0x01, 0x01, 0x02, 0x04, 0x05, 0x07, 0x08,
+		0x09, 0x0B, 0x0E, 0x11, 0x16, 0x19, 0x1E, 0x23,
+		0x29, 0x30, 0x38, 0x42, 0x4F, 0x5B, 0x7F, 0xA3,
+		0xAF, 0xBC, 0xC5, 0xCE, 0xD4, 0xD8, 0xE0, 0xE5,
+		0xE9, 0xED, 0xEF, 0xF3, 0xF5, 0xF6, 0xF8, 0xF9,
+		0xFA, 0xFB, 0xFC, 0xFD, 0xFE,
+	    /* Miscellaneous Items */
+		/* Checksum */
+		0xF5,
+
+	/* EXAMPLE 3: DI-EXT Extension Block */
+
+	    /* General Information section */
+		/* Block Header */
+		0x40,
+		/* DI-EXT Version Number */
+		0x01,
+	    /* Digital Interface section */
+		/* Standard/Specification Supported */
+		0x00,
+		/* Version/Revision Number */
+		0x00, 0x00, 0x00, 0x00,
+		/* Data Format Description */
+		0x00, 0x00,
+		/* Min, Max & Cross-Over Pixel Clock Frequency */
+		0x00, 0x00, 0x00, 0x00, 0x00,
+	    /* Display Device section */
+		/* Sub-Pixel Layout & Shape */
+		0x01, 0x00, 0x03,
+		/* Dot/Pixel Pitch */
+		0x1E, 0x1E,
+		/* Major Display Characteristics */
+		0xA8,
+	    /* Display Capabilities & Feature Support Set */
+		/* Miscellaneous Display Capabilities */
+		0x0C,
+		/* Frame Rate Conversion */
+		0x60, 0x70, 0x17, 0xE8, 0x12,
+		/* Display/Scan Orientation */
+		0x82,
+		/* Color/Luminance Coding Description */
+		0x01, 0x00, 0x80, 0x00,
+		/* Monitor Color Depth */
+		0x00, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00,
+		/* Aspect Ratio Conversion Modes */
+		0xE0,
+		/* Packetized Digital Video Support Information */
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	    /* Unused Bytes (Reserved) section */
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00,
+	    /* Audio Support (Reserved) section */
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00,
+	    /* Display Transfer Characteristic - Gamma */
+		0x8A,
+		0x00, 0x05, 0x0E, 0x23, 0x4F, 0xBC, 0xE0, 0xF3,
+		0xFA, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x01, 0x06, 0x0F, 0x24, 0x50, 0xBB, 0xDF, 0xF2,
+		0xF9, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x04, 0x0D, 0x22, 0x4E, 0xBD, 0xE1, 0xF4,
+		0xFB, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00,
+	    /* Miscellaneous Items */
+		/* Checksum */
+		0x40,
+
+	/* EXAMPLE 4: DI-EXT Extension Block */
+
+	    /* General Information section */
+		/* Block Header */
+		0x40,
+		/* DI-EXT Version Number */
+		0x01,
+	    /* Digital Interface section */
+		/* Standard/Specification Supported */
+		0x05,
+		/* Version/Revision Number */
+		0x80, 0x41, 0x00, 0x00,
+		/* Data Format Description */
+		0xDC, 0x24,
+		/* Min, Max & Cross-Over Pixel Clock Frequency */
+		0x19, 0x70, 0x00, 0x00, 0x00,
+	    /* Display Device section */
+		/* Sub-Pixel Layout & Shape */
+		0x00, 0x02, 0x00,
+		/* Dot/Pixel Pitch */
+		0x1F, 0x00,
+		/* Major Display Characteristics */
+		0x26,
+	    /* Display Capabilities & Feature Support Set */
+		/* Miscellaneous Display Capabilities */
+		0x01,
+		/* Frame Rate Conversion */
+		0x00, 0x00, 0x00, 0x00, 0x00,
+		/* Display/Scan Orientation */
+		0x42,
+		/* Color/Luminance Coding Description */
+		0x01, 0x03, 0x8F, 0xE0,
+		/* Monitor Color Depth */
+		0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
+		/* Aspect Ratio Conversion Modes */
+		0xF0,
+		/* Packetized Digital Video Support Information */
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	    /* Unused Bytes (Reserved) section */
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00,
+	    /* Audio Support (Reserved) section */
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00,
+	    /* Display Transfer Characteristic - Gamma */
+		0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00,
+	    /* Miscellaneous Items */
+		/* Checksum */
+		0x53,
+
+	/* Sample VTB-EXT Block */
+
+	    /* Tag Label & Version Number */
+		/* Block Header */
+		0x10,
+		/* Version Number */
+		0x01,
+	    /* Data Structure Layout */
+		0x03, 0x06, 0x03,
+	    /* Detailed Timing Blocks (DTB) */
+		/* Detailed Timing Block #1 */
+		0x64, 0x32, 0x00, 0x00, 0xF1, 0x60, 0x16, 0x90,
+		0x20, 0x80, 0x4A, 0x00, 0xDD, 0x29, 0x11, 0x00,
+		0x00, 0x1C,
+		/* Detailed Timing Block #2 */
+		0x54, 0x3D, 0x00, 0x78, 0xC0, 0x80, 0x28, 0x70,
+		0x10, 0x40, 0xAC, 0x00, 0xDD, 0x29, 0x11, 0x00,
+		0x00, 0x1C,
+		/* Detailed Timing Block #3 */
+		0xB8, 0x3D, 0x98, 0x78, 0x90, 0x00, 0x24, 0x60,
+		0x10, 0x40, 0xA8, 0x00, 0xDD, 0x29, 0x11, 0x00,
+		0x00, 0x1C,
+	    /* Coordinated Video Timing (CVT) Descriptors */
+		0xCF, 0x28, 0x21, 0x57, 0x28, 0x21, 0x1B, 0x28,
+		0x21, 0x67, 0x18, 0x2C, 0x2B, 0x18, 0x2C, 0xEF,
+		0x08, 0x2C,
+	    /* Standard Timing (ST) Descriptors */
+		0xB3, 0x3C, 0xA1, 0x3C, 0x7A, 0x3C,
+	    /* Unused Bytes (Reserved) */
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00,
+	    /* Checksum */
+		0x0A
+
+};
+
+
+/*
+ * Select an EDID test case
+ */
+#if (FBC_EDID_TEST_DATA == 0)
+	/*
+	 * Examples: EDID Base block, Map Block, DI-EXT Blocks, VTB-EXT Block
+	 */
+	edid_data   = &fbc_edid_test_data_misc[0];
+	edid_length = sizeof (fbc_edid_test_data_misc);
+#elif (FBC_EDID_TEST_DATA == 1)
+	/*
+	 * EXAMPLE 1: Sample BASE EDID (Block 0) for an LCD Desktop IT Display
+	 */
+	edid_data   = &fbc_edid_test_data_ex1[0];
+	edid_length = sizeof (fbc_edid_test_data_ex1);
+#elif (FBC_EDID_TEST_DATA == 2)
+	/*
+	 * EXAMPLE 2: Sample BASE EDID & CEA861 Extension for a DTV Display
+	 */
+	edid_data   = &fbc_edid_test_data_ex2[0];
+	edid_length = sizeof (fbc_edid_test_data_ex2);
+#elif (FBC_EDID_TEST_DATA == 3)
+	/*
+	 * EXAMPLE 3: Sample BASE EDID & CEA861 Extension for an IT/DTV Display
+	 */
+	edid_data   = &fbc_edid_test_data_ex3[0];
+	edid_length = sizeof (fbc_edid_test_data_ex3);
+#endif
+
+}
+
+
+/* End of fbc_edid_data.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_edit_config.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,333 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_edit_config - Write an updated configuration file
+ */
+
+
+#include <sys/types.h>		/* off_t */
+#include <sys/param.h>		/* MAXPATHLEN */
+#include <errno.h>		/* errno */
+#include <stdio.h>		/* fprintf() */
+#include <stdlib.h>		/* mkstemp() */
+#include <string.h>		/* strcat(), strcpy(), strlen(), strerror() */
+#include <unistd.h>
+#include <sys/stat.h>		/* stat() */
+
+#include "xf86Parser.h"		/* Public function, etc. declatations */
+#include "Configint.h"		/* Private definitions, etc. */
+#include "configProcs.h"	/* Private function, etc. declarations */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+#include "fbc_Device.h"		/* Edit Device sections */
+#include "fbc_Monitor.h"	/* Edit Monitor sections */
+#include "fbc_Screen.h"		/* Edit Screen sections */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_edit_config.h"	/* Write an updated configuration file */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_fields.h"		/* Measure aligned whitespace fields */
+#include "fbc_line_er.h"	/* External Representation of config lines */
+
+
+/*
+ * fbc_find_active_sections()
+ *
+ *    Find the active/target sections in the configuration that are
+ *    associated with the specified frame buffer device:
+ *        Device  section  (required)
+ *        Screen  section  (required)
+ *        Monitor section  (optional unless the user wants to reference it)
+ *        Display subsection of Screen section  (optional unless referenced)
+ *
+ *    The device handle is used to find (or construct) the target Device
+ *    section.  The Device section identifier is used to find (or
+ *    construct) the referencing Screen section.  The target Screen
+ *    section identifies the target Monitor section (or one may have to
+ *    be constructed).  The target Screen section also contains the
+ *    target Display subsection (or one may have to be constructed),
+ *    which the Monitor section helps to identify.
+ */
+
+int
+fbc_find_active_sections(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar,		/* fbconf_xorg(1M) varient data */
+	XF86ConfigPtr	configIR,	/* Config Internal Representation */
+	sectn_mask_t	ref_config)	/* Referenced config sections, etc. */
+{
+	int		error_code;	/* Error code (FBC_ERR_XXXXX) */
+	XF86ConfScrnMonitorEntryPtr mon_ptr; /* Ptr to active Monitor entry */
+	fbc_line_elem_t *next_line_er;	/* Line ER following insertion point */
+	int		stream_num;	/* Device stream/screen number */
+
+	fbvar->active.screen_sectn     = NULL;
+	fbvar->active.display_subsectn = NULL;
+	fbvar->active.monitor_sectn    = NULL;
+
+	/*
+	 * Find the Device section that refers to this device
+	 *
+	 *    The Device section must exist for the configuration to be
+	 *    correct.  If it doesn't exist then it must be created.  If
+	 *    there is more than one, all but the first will be ignored.
+	 */
+/*???*/	stream_num = 0;
+	fbvar->active.device_sectn =
+		fbc_find_active_Device_section(
+				device, configIR->conf_device_lst, stream_num);
+	if (fbvar->active.device_sectn == NULL) {
+		/*
+		 * Insert a Device section for this device
+		 */
+		error_code = fbc_insert_Device_section(
+					device,
+					fbvar,
+					configIR,
+					FBC_LAST_ER,
+					&fbvar->active.device_sectn);
+		if (error_code != FBC_SUCCESS) {
+			fbc_errormsg("Can't create Device section, %s\n",
+					device->path);
+			return (error_code);
+		}
+	}
+
+	/*
+	 * Find the first Screen section referring to this Device section name
+	 *
+	 *    The Screen section must exist for the configuration to be
+	 *    correct.  If it doesn't exist then it must be created.
+	 */
+	fbvar->active.screen_sectn =
+		fbc_find_active_Screen_section(
+				configIR->conf_screen_lst,
+				fbvar->active.device_sectn->dev_identifier);
+	if (fbvar->active.screen_sectn == NULL) {
+		/*
+		 * Insert a Screen section that refers to the Device section
+		 *
+		 *    If this is the default device (/dev/fb), make this
+		 *    the first Screen section in the configuration.
+		 *    Otherwise, just append it.
+		 */
+		next_line_er = FBC_LAST_ER;	/* Append to config */
+		if (device->is_default) {
+			next_line_er = FBC_FIRST_ER; /* Prepend to config */
+		}
+		error_code = fbc_insert_Screen_section(
+				configIR,
+				next_line_er,
+				device->name,
+				fbvar->active.device_sectn->dev_identifier,
+				&fbvar->active.screen_sectn);
+		if (error_code != FBC_SUCCESS) {
+			fbc_errormsg(
+		"Can't create Screen section for Device section, \"%s\"\n",
+				fbvar->active.device_sectn->dev_identifier);
+			return (error_code);
+		}
+	}
+
+	/*
+	 * Find any active Monitor entry, and therefore the Monitor section
+	 *
+	 *    Monitor entries within a Screen section are optional.  If
+	 *    the user wants to modify the Monitor section, the Display
+	 *    subsection, or get to Modes sections (-res ?), then the
+	 *    Monitor entry and section must exist or be created.
+	 */
+	mon_ptr = fbc_find_active_Monitor_entry(
+				fbvar->active.screen_sectn->scrn_monitor_lst);
+	if ((mon_ptr == NULL) &&
+	    (ref_config & (FBC_SECTION_Monitor | FBC_SUBSCTN_Display))) {
+		/*
+		 * Insert a Monitor section and its Monitor entry
+		 *
+		 *    Memory allocation errors are unlikely and
+		 *    won't corrupt program state.
+		 */
+		if (fbc_insert_Monitor_section(
+					configIR,
+					FBC_LAST_ER,
+					device->name,
+					&fbvar->active.monitor_sectn)
+						!= FBC_SUCCESS) {
+			fbc_errormsg(
+		"Can't create Monitor section for Screen section, \"%s\"\n",
+				fbvar->active.screen_sectn->scrn_identifier);
+		} else
+		if (fbc_insert_Monitor_entry(
+					fbvar->active.screen_sectn,
+					fbvar->active.monitor_sectn,
+					&mon_ptr)
+						!= FBC_SUCCESS) {
+			fbc_errormsg(
+		"Can't create Monitor entry in Screen section, \"%s\"\n",
+				fbvar->active.screen_sectn->scrn_identifier);
+		}
+	}
+	if (mon_ptr != NULL) {
+		/*
+		 * Note the active/target Monitor section
+		 */
+		fbvar->active.monitor_sectn = mon_ptr->scrn_monitor;
+
+		/*
+		 * Find any active/target Display subsection
+		 *
+		 *    Display subsections within a Screen section are
+		 *    optional.  If the user wants to modify the Display
+		 *    subsection then it must exist or be created.
+		 */
+		fbvar->active.display_subsectn =
+			fbc_find_active_Display_subsection(
+				fbvar->active.screen_sectn,
+				mon_ptr,
+				fbvar->active.screen_sectn->scrn_display_lst);
+		if ((fbvar->active.display_subsectn == NULL) &&
+		    (ref_config & FBC_SUBSCTN_Display)) {
+			/*
+			 * Insert a Display subsection
+			 */
+			if (fbc_insert_Display_subsection(
+				fbvar->active.screen_sectn,
+				fbvar->active.screen_sectn->scrn_end_line_er,
+				mon_ptr,
+				&fbvar->active.display_subsectn)
+						!= FBC_SUCCESS) {
+				fbc_errormsg(
+		"Can't create Display subsection in Screen section, \"%s\"\n",
+				fbvar->active.screen_sectn->scrn_identifier);
+			}
+		}
+	}
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_find_active_sections() */
+
+
+/*
+ * fbc_find_active_mode()
+ *
+ *    This function tries to find the name of the active video mode in
+ *    the Modes entry of the active Display Subsection of the active
+ *    Screen Section.  For completeness, it also looks for the
+ *    corresponding ModeLine / Mode-EndMode entry.
+ */
+
+int
+fbc_find_active_mode(
+	sectn_mask_t	modify_config,	/* Config sections, etc. to modify */
+	xf86_active_t	*active)	/* Active config sections for device */
+{
+
+	/*
+	 * No Mode name or ModeLine / Mode-EndMode entry has been found yet
+	 */
+	active->mode_name  = NULL;
+	active->mode_entry = NULL;
+
+	/*
+	 * If Display & Monitor sections are known, find Mode name & Mode entry
+	 */
+	if (active->display_subsectn != NULL) {
+		active->mode_name =
+			fbc_find_active_Mode_name(active->display_subsectn);
+		if (active->mode_name != NULL) {
+			/*
+			 * Look for the ModeLine / Mode-EndMode entry
+			 */
+			active->mode_entry = fbc_find_Monitor_Mode(
+							active->monitor_sectn,
+							active->mode_name);
+		}
+	}
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_find_active_mode() */
+
+
+/*
+ * fbc_edit_active_sections()
+ *
+ *    Edit the active sections in the configuration that are associated
+ *    with the frame buffer device.
+ */
+
+int
+fbc_edit_active_sections(
+	XF86ConfigPtr	configIR,	/* Config Internal Representation */
+	xf86_active_t	*active,	/* Active config sections for device */
+	xf86_ent_mod_t	*xf86_entry_mods) /* Config entry modifications */
+{
+	int		error_code;	/* Error code */
+
+	/*
+	 * Make any modifications to the existing active Screen section
+	 */
+	error_code = fbc_edit_Screen_section(
+				active->screen_sectn, xf86_entry_mods);
+	if (error_code != FBC_SUCCESS) {
+		return (error_code);
+	}
+
+	/*
+	 * Make any modifications to the active Display subsection, if any
+	 */
+	if (active->display_subsectn != NULL) {
+		error_code = fbc_edit_Display_subsection(
+				active->display_subsectn, xf86_entry_mods);
+		if (error_code != FBC_SUCCESS) {
+			return (error_code);
+		}
+	}
+
+	/*
+	 * Make any modifications to the active Monitor section
+	 */
+	if (active->monitor_sectn != NULL) {
+		/*
+		 * Make any changes to the active Monitor section
+		 */
+		error_code = fbc_edit_Monitor_section(
+				active->monitor_sectn, xf86_entry_mods);
+		if (error_code != FBC_SUCCESS) {
+			return (error_code);
+		}
+	}
+
+	/*
+	 * Make any modifications to the Option lists of active sections
+	 */
+	fbc_edit_Options(active, xf86_entry_mods->Option_mods);
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_edit_active_sections() */
+
+
+/* End of fbc_edit_config.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_edit_config.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_edit_config - Write an updated configuration file
+ */
+
+
+
+#ifndef	_FBC_EDIT_CONFIG_H
+#define	_FBC_EDIT_CONFIG_H
+
+
+//#include <stdio.h>		/* FILE */
+
+#include "xf86Parser.h"		/* XF86ConfigPtr */
+
+#include "fbc_xorg.h"		/* Edit config file data representations */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+
+
+int fbc_find_active_sections(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar,		/* fbconf_xorg(1M) varient data */
+	XF86ConfigPtr	configIR,	/* Config Internal Representation */
+	sectn_mask_t	ref_config);	/* Referenced config sections, etc. */
+
+int fbc_find_active_mode(
+	sectn_mask_t	modify_config,	/* Config sections, etc. to modify */
+	xf86_active_t	*active);	/* Active config sections for device */
+
+int fbc_edit_active_sections(
+	XF86ConfigPtr	configIR,	/* Config Internal Representation */
+	xf86_active_t	*active,	/* Active config sections for device */
+	xf86_ent_mod_t	*xf86_entry_mods); /* Config entry modifications */
+
+
+#endif	/* _FBC_EDIT_CONFIG_H */
+
+
+/* End of fbc_edit_config.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_error.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_error - Error reporting
+ */
+
+
+
+#include <stdarg.h>		/* va_end(), va_start(), vfprintf() */
+#include <stdio.h>		/* fprintf() */
+
+#include "configProcs.h"	/* Private function, etc. declarations */
+
+#include "fbc_error.h"		/* Error reporting */
+
+
+#if !defined(FBC_PROG_NAME)		/* Permit the Makefile to have a say */
+#define	FBC_PROG_NAME	"fbconf_xorg"
+#endif
+
+const char	*fbc_prog_name = FBC_PROG_NAME;	/* Program name */
+
+
+/*
+ * fbc_errormsg()
+ *
+ *    Write a variable format error message to stderr, prefixed by the
+ *    program name.
+ */
+
+void
+fbc_errormsg(const char *format, ...)
+{
+	va_list		ap;		/* Variable argument pointer */
+
+	fprintf(stderr, "%s: ", fbc_prog_name);
+	va_start(ap, format);
+	vfprintf(stderr, format, ap);
+	va_end(ap);
+
+}	/* fbc_errormsg() */
+
+
+/*
+ *
+ * Copyright (c) 1997  Metro Link Incorporated
+ *
+ * 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
+ * THE X CONSORTIUM 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.
+ *
+ * Except as contained in this notice, the name of the Metro Link shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Metro Link.
+ *
+ */
+
+/*
+ * Error reporting functions (declared in configProcs.h) required by the
+ * XFree86 configuration file parser:
+ */
+
+/*
+ * ErrorF()
+ *
+ *    Write a variable format diagnostic message string, not prefixed by
+ *    the program name, to stderr.
+ */
+
+void
+ErrorF(const char *format, ...)
+{
+	va_list		ap;		/* Variable argument pointer */
+
+	va_start(ap, format);
+	vfprintf(stderr, format, ap);
+	va_end(ap);
+}
+
+
+/*
+ * VErrorF()
+ *
+ *    Write a variable format diagnostic message string, not prefixed by
+ *    the program name, to stderr.  The variable argument list is
+ *    provided by the caller's caller.
+ *    (See scan.c of the XFree86 parser.)
+ */
+
+void
+VErrorF(const char *format, va_list ap)
+{
+	vfprintf(stderr, format, ap);
+}
+
+
+/* End of fbc_error.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_error.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_error - Error reporting
+ */
+
+
+
+#ifndef	_FBC_ERROR_H
+#define	_FBC_ERROR_H
+
+
+/*
+ * Program exit codes
+ */
+enum {
+	FBC_EXIT_SUCCESS	= 0,	/* No errors */
+	FBC_EXIT_USAGE		= 1,	/* Usage error */
+	FBC_EXIT_FAILURE	= 2	/* Program execution error */
+};
+
+
+/*
+ * Error codes
+ *
+ *    These values often do not have special significance, aside from
+ *    being zero vs. non-zero return codes and as potential debugging
+ *    aids.
+ */
+enum {
+	FBC_SUCCESS = 0,		/* No errors */
+	FBC_ERR_NOMEM,			/* Insufficient memory */
+	FBC_ERR_PATH_LEN,		/* Pathname is too long */
+	FBC_ERR_NAME_LEN,		/* Name (e.g., device) is too long */
+	FBC_ERR_READLINK,		/* Symbolic link resolution error */
+	FBC_ERR_STAT,			/* File status query error */
+	FBC_ERR_OPEN,			/* File open error */
+	FBC_ERR_IOCTL,			/* File I/O control error */
+	FBC_ERR_SEEK,			/* File positioning error */
+	FBC_ERR_READ,			/* File input error */
+	FBC_ERR_ACCESS,			/* File access permissions error */
+	FBC_ERR_RENAME,			/* File renaming error */
+	FBC_ERR_KWD_INVALID,		/* Invalid keyword */
+	FBC_ERR_KWD_AMBIGUOUS,		/* Ambiguous keyword */
+	FBC_ERR_OPT_CONFLICT,		/* Conflicting command line option */
+	FBC_ERR_GAMMA_VALUE,		/* Invalid gamma correction value */
+	FBC_ERR_GAMMA_COUNT,		/* Wrong number of gamma values */
+	FBC_ERR_GAMMA_PACK,		/* Gamma value packing error */
+	FBC_ERR_GENERAL			/* (*TBD*) All-purpose non-zero code */
+};
+
+
+extern const char	*fbc_prog_name;	/* Program name */
+
+
+void fbc_errormsg(const char *format, ...);
+
+
+#endif	/* _FBC_ERROR_H */
+
+
+/* End of fbc_error.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_fields.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,179 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_fields - Measure aligned whitespace fields
+ */
+
+
+#include <string.h>		/* memcpy(), memset() */
+
+#include "fields.h"		/* Write aligned whitespace and text fields */
+
+#include "fbc_fields.h"		/* Measure aligned whitespace fields */
+
+
+/*
+ * fbc_measure_whitespace()
+ *
+ *    Scan the first couple of whitespace fields in a non-comment
+ *    configuration line.  Save versions of of these fields that have
+ *    the text strings (non-whitespace) removed.  The xf86printFields()
+ *    function can fill in other text strings, which may have different
+ *    lengths.
+ */
+
+void
+fbc_measure_whitespace(
+	const char * const configBuf,	/* Configuration file line buffer */
+	fbc_wspace_t	*wspace_chars)	/* Line's whitespace characteristics */
+{
+	int		column;		/* Zero-relative text column number */
+	const char	*cptr;		/* Ptr into config file line buffer */
+	const char	*cptr0;		/* Ptr into config file line buffer */
+	int		field;		/* Whitespace field counter */
+	char		wspace_char;	/* Whitespace char: Space or Tab */
+	int		wspace_count;	/* Text string len in Spaces or Tabs */
+	char		*wspace_ptr;	/* Ptr into whitespace buffer */
+
+	/*
+	 * Initialize to start scanning the configuration line
+	 */
+	cptr         = configBuf;
+	column       = 0;
+	wspace_char  = ' ';
+	wspace_count = 0;
+	wspace_ptr   = wspace_chars->whitespace_buf;
+
+	/*
+	 * Examine the first couple of whitespace fields of this line
+	 */
+	for (field = 0; field < FBC_WSPACE_FIELDS; field += 1) {
+		/*
+		 * Count the chars in the (possibly empty) whitespace string
+		 */
+		cptr0 = cptr;
+		for ( ; ; cptr += 1) {
+			if (*cptr == '\t') {
+				column = (column / XF86_TAB_WIDTH + 1)
+							* XF86_TAB_WIDTH;
+				continue;
+			}
+			if (*cptr == ' ') {
+				column += 1;
+				continue;
+			}
+			break;		/* Nul or other non-whitespace */
+		}
+
+		/*
+		 * Ignore comment lines (since those don't get modified)
+		 */
+		if ((*cptr == '#') && (field == 0)) {
+			return;
+		}
+
+		/*
+		 * Don't overrun the whitespace string buffer
+		 */
+		if ((wspace_count + (cptr - cptr0) + 1)
+				> sizeof (wspace_chars->whitespace_buf)) {
+			wspace_chars->whitespace[field] =
+						xf86whitespace_1[field];
+			continue;	/* Maybe the next string will fit */
+		}
+
+		/*
+		 * Save this whitespace string pointer for possible future use
+		 */
+		wspace_chars->whitespace[field] = wspace_ptr;
+
+		/*
+		 * Make a string of Spaces or Tabs long as the prev text string
+		 *
+		 *    Note that there will be no previous text string on the
+		 *    first iteration.
+		 */
+		memset(wspace_ptr, wspace_char, wspace_count);
+		wspace_ptr += wspace_count;
+
+		/*
+		 * Append a copy of the just scanned whitespace string
+		 */
+		wspace_count = cptr - cptr0;
+		memcpy(wspace_ptr, cptr0, wspace_count);
+		wspace_ptr += wspace_count;
+		*wspace_ptr = '\0';
+		wspace_ptr += 1;
+
+		/*
+		 * Scan the text string that occupies this field
+		 *
+		 *    We want to get the equivalent length of the text
+		 *    string, measured as a number (wspace_count) of
+		 *    Spaces or Tabs (wspace_char), whichever character
+		 *    follows the text string.
+		 *      * Getting the length as an equivalent number of
+		 *        Spaces is straightforward.
+		 *      * Getting the length in Tabs actually means
+		 *        counting the Tab Stops that are crossed by the
+		 *        text string.
+		 *
+		 *    We also want to scan past the text string.
+		 *
+		 *    We're expecting to see the Space or Tab, but a
+		 *    line terminator musn't be allowed to cause havoc.
+		 *    (Inserting an Option line after an EndSubsection
+		 *    line works, but it isn't formatted well.)
+		 *
+		 *    We're assuming that the text string doesn't
+		 *    include whitespace (e.g. "Screen 0").  If it does,
+		 *    the worst that can happen is a strangely formatted
+		 *    output file.
+		 */
+		wspace_char  = ' ';
+		wspace_count = 0;
+		for ( ;
+		    (*cptr != '\0') && (*cptr != ' ') && (*cptr != '\n');
+		    cptr += 1) {
+			if (*cptr == '\t') {
+				wspace_char  = '\t';
+				wspace_count = (column / XF86_TAB_WIDTH)
+						- ((column - wspace_count)
+							/ XF86_TAB_WIDTH);
+				break;
+			}
+			column       += 1;
+			wspace_count += 1;
+		}
+	}
+
+	/*
+	 * Mark the end of the whitespace array
+	 */
+	wspace_chars->whitespace[field] = NULL;
+
+}	/* fbc_measure_whitespace() */
+
+
+/* End of fbc_fields.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_fields.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_fields - Measure aligned whitespace fields
+ */
+
+
+
+#ifndef	_FBC_FIELDS_H
+#define	_FBC_FIELDS_H
+
+
+/*
+ * Whitespace used to format a configuration line
+ *
+ *    Once populated, the NULL-terminated fbc_wspace_t.whitespace[]
+ *    array can be passed to the xf86printFields() function, as the
+ *    whitespace[] parameter.
+ */
+#define	FBC_WSPACE_FIELDS 2		/* Look at just the first two fields */
+
+typedef struct {
+	const char	*whitespace[FBC_WSPACE_FIELDS+1]; /* Wspace ptrs */
+	char		whitespace_buf[1024]; /* Whitespace strings buffer */
+} fbc_wspace_t;
+
+
+void fbc_measure_whitespace(
+	const char * const configBuf,	/* Configuration file line buffer */
+	fbc_wspace_t	*wspace_chars);	/* Line's whitespace characteristics */
+
+
+#endif	/* _FBC_FIELDS_H */
+
+
+/* End of fbc_fields.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_gamma_table.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,494 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_gamma_table - Read, pack, and write a gamma table
+ */
+
+
+#include <sys/types.h>
+#include <ctype.h>		/* isspace() */
+#include <fcntl.h>
+#include <stdio.h>		/* fclose(), feof(), fgets(), fopen(), ... */
+#include <stdlib.h>		/* free(), malloc(), strchr(), strtoul() */
+#include <string.h>		/* strcat(), strcpy(), strlen(), strrchr() */
+#include <sys/stat.h>		/* stat() */
+
+#include "gfx_gamma_pack.h"	/* gfx_pack_gamma_string_16() */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_gamma_table.h"	/* Read, pack, and write a gamma table table */
+
+
+#define	MAX_LINE_LEN	1024		/* Max length of gamma file line */
+
+#define	NUM_COLORS	3		/* # of colors in RGB triplet */
+
+#define	MAX_GAMMA_VALUE	0x0FFF		/* Maximum gamma value */
+
+
+/*
+ * fbc_read_users_gamma_table()
+ *
+ *    Read a text file containing the user's Red-Green-Blue gamma
+ *    correction value triplets.  Return arrays of Red, Green, and Blue
+ *    gamma binary values.
+ *
+ *    Gamma file syntax:
+ *        <file>    =:: <line>...
+ *        <line>    =:: [<sp>][<number>[<sp><number>]...]<eol>
+ *        <sp>      =:: ' '|'\t'...
+ *                   # Whitespace character recognized by isspace()
+ *        <number>  =:: <octal_int> | <decimal_int> | <hexadecimal_int>
+ *                   # Numeric string recognized by strtoul(,,0)
+ *        <eol>     =:: [<comment>]'\n'
+ *        <comment> =:: '#'[<text>]
+ *
+ *    Gamma file example:
+ *        #
+ *        # Gamma correction table for fictitious FB device
+ *        #
+ *
+ *        0x000   0x000   0x000   #    0
+ *        0x001   0x001   0x001   #    1
+ *        0x002   0x002   0x002   #    2
+ *         ...     ...     ...    . ...
+ *        0x3FF   0x3FF   0x3FF   # 1023
+ *
+ *        # End of gamma_file.txt
+ */
+
+static
+int
+fbc_read_users_gamma_table(
+	const char	*gfile_in_path,	/* Pathname of input gamma file */
+	int		lut_size,	/* Gamma look-up table size */
+	unsigned short	gamma_red[],	/* Returned Red   gamma values */
+	unsigned short	gamma_green[],	/* Returned Green gamma values */
+	unsigned short	gamma_blue[])	/* Returned Blue  gamma values */
+{
+	char		*end_ptr;	/* Ptr to terminator char */
+	int		error_code;	/* Returned error code */
+	int		gamma_count;	/* # of gamma values encountered */
+	FILE		*gamma_in_stream; /* Gamma file stream descriptor */
+	unsigned long	gamma_value;	/* Current gamma value */
+	int		i;		/* RGB array indices */
+	char		line_buf[MAX_LINE_LEN + 1]; /* Gamma line buffer */
+	int		line_num;	/* Gamma file line number */
+	char		*line_ptr;	/* Ptr into gamma file line buffer */
+
+	/*
+	 * Assume no errors
+	 */
+	error_code = FBC_SUCCESS;
+
+	/*
+	 * Open the user's text file containing a gamma correction table
+	 */
+	gamma_in_stream = fopen(gfile_in_path, "r");
+	if (gamma_in_stream == NULL) {
+		fbc_errormsg("Can't open input gamma file, %s\n",
+				gfile_in_path);
+		return (FBC_ERR_OPEN);
+	}
+
+	/*
+	 * Read the gamma table, parsing a lut_size number of RGB triplets
+	 */
+	line_num  = 0;
+	line_ptr  = &line_buf[0];
+	*line_ptr = '\0';		/* Empty line buffer */
+	for (gamma_count = 0; ; ) {
+		/*
+		 * Get the next non-whitespace, non-comment character
+		 */
+		if ((*line_ptr == '\0') || (*line_ptr == '#')) {
+			/*
+			 * Read a text line from the gamma file
+			 */
+			line_num += 1;
+			if (fgets(line_buf, MAX_LINE_LEN, gamma_in_stream)
+						== NULL) {
+				if (feof(gamma_in_stream) == 0) {
+					error_code = FBC_ERR_READ;
+					fbc_errormsg(
+				"Error reading gamma file, %s, line %d\n",
+						gfile_in_path, line_num);
+					break;	/* Gamma file input error */
+				}
+
+				/*
+				 * Check for correct # of RGB triplets
+				 */
+				if (gamma_count !=
+					(NUM_COLORS * lut_size)) {
+					/* Wrong # of gamma values */
+					error_code = FBC_ERR_GAMMA_COUNT;
+					fbc_errormsg(
+				"Too few gamma values in file, %s, line %d\n",
+						gfile_in_path, line_num);
+				}
+				break;	/* End of gamma file */
+			}
+			line_ptr = &line_buf[0];
+			continue;
+		}
+		if (isspace(*line_ptr)) {
+			line_ptr += 1;
+			continue;
+		}
+
+		/*
+		 * Parse the hexadecimal, decimal, or octal value
+		 */
+		gamma_value = strtoul(line_ptr, &end_ptr, 0);
+		if ((end_ptr <= line_ptr) || (gamma_value > MAX_GAMMA_VALUE)) {
+			error_code = FBC_ERR_GAMMA_VALUE;
+			fbc_errormsg("Invalid gamma value, %s, line %d\n",
+					gfile_in_path, line_num);
+			break;
+		}
+		line_ptr = end_ptr;
+
+		/*
+		 * Make sure gamma file doesn't contain too many gamma values
+		 */
+		i = gamma_count / NUM_COLORS;
+		if (i >= lut_size) {
+			error_code = FBC_ERR_GAMMA_COUNT;
+			fbc_errormsg(
+				"Too many gamma values in file, %s, line %d\n",
+					gfile_in_path, line_num);
+			break;
+		}
+
+		/*
+		 * Save the Red, Green, or Blue gamma correction value
+		 */
+		switch (gamma_count % NUM_COLORS) {
+		case 0:
+			gamma_red[i]   = (unsigned short)gamma_value;
+			break;
+		case 1:
+			gamma_green[i] = (unsigned short)gamma_value;
+			break;
+		case 2:
+			gamma_blue[i]  = (unsigned short)gamma_value;
+			break;
+		}
+		gamma_count += 1;
+	}
+
+	/*
+	 * Close the input gamma file
+	 */
+	fclose(gamma_in_stream);
+
+	return (error_code);
+
+}	/* fbc_read_users_gamma_table() */
+
+
+/*
+ * fbc_read_gamma_table()
+ *
+ *    Read a text file containing the user's gamma correction table,
+ *    consisting of a lut_size number of Red-Green-Blue triplet values.
+ *    Return pointers to dynamically allocated packed strings of Red,
+ *    Green, and Blue gamma correction values.
+ */
+
+int
+fbc_read_gamma_table(
+	const char	*gfile_in_path,	/* Pathname of input gamma file */
+	int		lut_size,	/* # of RGB triplets in gamma file */
+	char		**gamma_string_red, /* Returned packed Red values */
+	char		**gamma_string_green, /* Returned packed Green vals */
+	char		**gamma_string_blue) /* Returned packed Blue values */
+{
+	int		error_code;	/* Returned error code */
+	uint16_t	*gt_data_red;	/* Red   gamma input values array */
+	uint16_t	*gt_data_green;	/* Green gamma input values array */
+	uint16_t	*gt_data_blue;	/* Blue  gamma input values array */
+
+	/*
+	 * Show that the strings for packed gamma values aren't allocated yet
+	 *
+	 *    Our caller may have done this already, since the caller is
+	 *    responsible for releasing the memory.
+	 */
+	*gamma_string_red   = NULL;
+	*gamma_string_green = NULL;
+	*gamma_string_blue  = NULL;
+
+	/*
+	 * Allocate arrays for the input gamma table data
+	 */
+	gt_data_red = (uint16_t *)malloc(
+				lut_size * NUM_COLORS * sizeof (uint16_t));
+	if (gt_data_red == NULL) {
+		fbc_errormsg("Insufficient memory, %s\n", gfile_in_path);
+		return (FBC_ERR_NOMEM);
+	}
+	gt_data_green = gt_data_red   + lut_size;
+	gt_data_blue  = gt_data_green + lut_size;
+
+	/*
+	 * Read the gamma correction table data from the user's gamma file
+	 */
+	error_code = fbc_read_users_gamma_table(
+				gfile_in_path, lut_size,
+				gt_data_red, gt_data_green, gt_data_blue);
+	if (error_code == FBC_SUCCESS) {
+		/*
+		 * Pack the gamma correction values into dynamic strings
+		 */
+		if ((gfx_pack_gamma_string_16(
+			gamma_string_red, lut_size, gt_data_red) <= 0) ||
+		    (gfx_pack_gamma_string_16(
+			gamma_string_green, lut_size, gt_data_green) <= 0) ||
+		    (gfx_pack_gamma_string_16(
+			gamma_string_blue, lut_size, gt_data_blue) <= 0)) {
+		  	/*
+			 * Handle a gamma data packing error
+			 */
+			fbc_free_gamma_strings(*gamma_string_red,
+						*gamma_string_green,
+						*gamma_string_blue);
+			*gamma_string_red   = NULL;
+			*gamma_string_green = NULL;
+			*gamma_string_blue  = NULL;
+			fbc_errormsg("Error packing gamma table data, %s\n",
+					gfile_in_path);
+			error_code = FBC_ERR_GAMMA_PACK;
+		}
+	}
+
+	/*
+	 * Release the input gamma table data arrays
+	 */
+	free(gt_data_red);
+
+	return (error_code);
+
+}	/* fbc_read_gamma_table() */
+
+
+/*
+ * fbc_build_gamma_table_path()
+ *
+ *    Construct the output gamma correction table pathname.  The
+ *    directory component will be the same as for the configuration
+ *    file.  The file name will be unique for the frame buffer device,
+ *    consisting of the device name with a ".gamma" extension.
+ */
+
+int
+fbc_build_gamma_table_path(
+	const char	*config_file_path, /* Configuration file pathname */
+	const char	*device_name,	/* Frame buffer device name */
+	char		*gfile_path_buf, /* Gamma table output pathname buf */
+	int		gfile_path_buf_len) /* Gamma table path buf len */
+{
+	size_t		dir_len;	/* Length of directory path */
+	char		*dir_ptr;	/* Ptr to last "/" in directory path */
+
+	dir_ptr = strrchr(config_file_path, '/');
+	dir_len = 0;			/* Case of no directory component */
+	if (dir_ptr != NULL) {
+		dir_len = dir_ptr - config_file_path + 1;
+	}
+	if ((dir_len + strlen(device_name) + strlen(GAMMA_TABLE_EXT))
+				>= gfile_path_buf_len) {
+		fbc_errormsg("Gamma table pathname is too long\n");
+		return (FBC_ERR_PATH_LEN);
+	}
+	memcpy(gfile_path_buf, config_file_path, dir_len);
+	strcpy(gfile_path_buf + dir_len, device_name);
+	strcat(gfile_path_buf, GAMMA_TABLE_EXT);
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_build_gamma_table_path() */
+
+
+/*
+ * fbc_write_packed_gamma_table()
+ *
+ *    Write a packed gamma correction table to a newly created file.
+ *    The file will contain three lines of characters, each ending with
+ *    a Newline character.
+ */
+
+int
+fbc_write_packed_gamma_table(
+	const char	*gfile_out_path, /* Pathname of output gamma file */
+	char		*gamma_string_red, /* Packed Red values string */
+	char		*gamma_string_green, /* Packed Green values string */
+	char		*gamma_string_blue) /* Packed Blue values string */
+{
+	FILE		*gamma_out_stream; /* Gamma file stream descriptor */
+
+	/*
+	 * Delete, create, and open the output packed gamma table file
+	 */
+	gamma_out_stream = fopen(gfile_out_path, "w");
+	if (gamma_out_stream == NULL) {
+		fbc_errormsg("Can't create and open output gamma file, %s\n",
+				gfile_out_path);
+		return (FBC_ERR_OPEN);
+	}
+
+	/*
+	 * Write the packed gamma correction table to the file
+	 */
+	fprintf(gamma_out_stream, "%s\n", gamma_string_red);
+	fprintf(gamma_out_stream, "%s\n", gamma_string_green);
+	fprintf(gamma_out_stream, "%s\n", gamma_string_blue);
+
+	/*
+	 * Close the new gamma table file
+	 */
+	fclose(gamma_out_stream);
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_write_packed_gamma_table() */
+
+
+/*
+ * fbc_read_packed_gamma_table()
+ *
+ *    Read the contents of a packed gamma table file into a single
+ *    dynamically allocated buffer.  The file should contain three lines
+ *    of characters, each ending with a Newline character.  Other than
+ *    the presence of Newlines, no assumptions are made concerning the
+ *    lengths of the lines.  Each Newline character is replaced by a
+ *    Nul.  Pointers to the three RGB Nul-terminated strings are
+ *    returned.
+ */
+
+int
+fbc_read_packed_gamma_table(
+	const char	*gfile_in_path,	/* Pathname of input gamma file */
+	char		**gamma_string_red, /* Returned packed Red values */
+	char		**gamma_string_green, /* Returned packed Green vals */
+	char		**gamma_string_blue) /* Returned packed Blue values */
+{
+	size_t		bytes_read;	/* # of bytes read from gamma file */
+	int		error_code;	/* Returned error code */
+	FILE		*gamma_in_stream; /* Gamma file stream descriptor */
+	struct stat	stat_buf;	/* Gamma file status */
+
+	/*
+	 * Measure the gamma file for a new buffer
+	 */
+	if ((stat(gfile_in_path, &stat_buf) < 0) ||
+				(stat_buf.st_size == NUM_COLORS)) {
+		fbc_errormsg("Bad gamma file status, %s\n", gfile_in_path);
+		return (FBC_ERR_STAT);
+	}
+	*gamma_string_red = malloc(stat_buf.st_size);
+	if (*gamma_string_red == NULL) {
+		fbc_errormsg("Insufficient memory, %s\n", gfile_in_path);
+		return (FBC_ERR_NOMEM);
+	}
+
+	/*
+	 * Open the file containing the packed gamma correction table
+	 */
+	gamma_in_stream = fopen(gfile_in_path, "r");
+	if (gamma_in_stream == NULL) {
+		fbc_errormsg("Can't open input gamma file, %s\n",
+				gfile_in_path);
+		error_code = FBC_ERR_OPEN;
+		goto read_packed_gamma_error;
+	}
+
+	/*
+	 * Read the packed gamma table strings
+	 */
+	bytes_read = fread(*gamma_string_red,
+				sizeof (char),
+				stat_buf.st_size,
+				gamma_in_stream);
+	fclose(gamma_in_stream);
+	if (bytes_read != stat_buf.st_size) {
+		fbc_errormsg("Error reading gamma file, %s\n", gfile_in_path);
+		error_code = FBC_ERR_READ;
+		goto read_packed_gamma_error;
+	}
+
+	/*
+	 * Separate the gamma buffer into its component colors and return
+	 */
+	if (*(*gamma_string_red + stat_buf.st_size - 1) == '\n') {
+		*(*gamma_string_red + stat_buf.st_size - 1) = '\0';
+		*gamma_string_green = strchr(*gamma_string_red, '\n');
+		if (*gamma_string_green != NULL) {
+			**gamma_string_green = '\0';
+			*gamma_string_green += 1;
+			*gamma_string_blue = strchr(*gamma_string_green, '\n');
+			if (*gamma_string_blue != NULL) {
+				**gamma_string_blue = '\0';
+				*gamma_string_blue += 1;
+				return (FBC_SUCCESS);
+			}
+		}
+	}
+	fbc_errormsg("Gamma file is corrupt, %s\n", gfile_in_path);
+	error_code = FBC_ERR_READ;
+
+	/*
+	 * Release the buffer and return unsuccessfully
+	 */
+read_packed_gamma_error:
+	free(*gamma_string_red);
+	return (error_code);
+
+}	/* fbc_read_packed_gamma_table() */
+
+
+/*
+ * fbc_free_gamma_strings()
+ *
+ *    Free any packed gamma string memory that was allocated by
+ *    gfx_pack_gamma_string_16().
+ */
+
+void
+fbc_free_gamma_strings(
+	char		*gamma_string_red, /* Packed Red values string */
+	char		*gamma_string_green, /* Packed Green values string */
+	char		*gamma_string_blue) /* Packed Blue values string */
+{
+
+	free(gamma_string_red);
+	free(gamma_string_green);
+	free(gamma_string_blue);
+
+}	/* fbc_free_gamma_strings() */
+
+
+/* End of fbc_gamma_table.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_gamma_table.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_gamma_table - Read, pack, and write a gamma table
+ */
+
+
+
+#ifndef _FBC_GAMMA_TABLE_H
+#define	_FBC_GAMMA_TABLE_H
+
+
+int fbc_read_gamma_table(
+	const char	*gfile_in_path,	/* Pathname of input gamma file */
+	int		lut_size,	/* Gamma look-up table size */
+	char		**gamma_string_red, /* Returned packed Red values */
+	char		**gamma_string_green, /* Returned packed Green vals */
+	char		**gamma_string_blue); /* Returned packed Blue values */
+
+int fbc_build_gamma_table_path(
+	const char	*config_file_path, /* Configuration file pathname */
+	const char	*device_name,	/* Frame buffer device name */
+	char		*gfile_path_buf, /* Gamma table output pathname buf */
+	int		gfile_path_buf_len); /* Gamma table path buf len */
+
+int fbc_write_packed_gamma_table(
+	const char	*gfile_out_path, /* Pathname of output gamma file */
+	char		*gamma_string_red, /* Packed Red values string */
+	char		*gamma_string_green, /* Packed Green values string */
+	char		*gamma_string_blue); /* Packed Blue values string */
+
+int fbc_read_packed_gamma_table(
+	const char	*gfile_in_path,	/* Pathname of input gamma file */
+	char		**gamma_string_red, /* Returned packed Red values */
+	char		**gamma_string_green, /* Returned packed Green vals */
+	char		**gamma_string_blue); /* Returned packed Blue values */
+
+void fbc_free_gamma_strings(
+	char		*gamma_string_red, /* Packed Red values string */
+	char		*gamma_string_green, /* Packed Green values string */
+	char		*gamma_string_blue); /* Packed Blue values string */
+
+
+#endif	/* _FBC_GAMMA_TABLE_H */
+
+
+/* fbc_gamma_table.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_get_properties.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_get_properties - Get fbconf_xorg(1M) program properties
+ */
+
+
+#include <sys/param.h>		/* MAXPATHLEN */
+#include <dlfcn.h>		/* Dynamic linking: dlopen(), etc. */
+#include <errno.h>		/* errno */
+#include <link.h>
+#include <stdio.h>		/* snprintf() */
+#include <stdlib.h>		/* exit() */
+#include <string.h>		/* strerror() */
+#include <sys/stat.h>		/* stat() */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_get_properties.h"	/* Get fbconf_xorg(1M) program properties */
+
+
+#define	FBC_FUNC_NAME_FMT "%s_get_properties"
+
+
+/*
+ * fbc_get_properties()
+ *
+ *    Return the fbconf_xorg(1M) properties for the specified frame
+ *    buffer device type.
+ */
+
+int
+fbc_get_properties(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar)		/* Returned fbconf_xorg properties */
+{
+	char		*error_msg;	/* Error message */
+	fbc_api_ver_t	*fb_api_version; /* API version of shared library */
+	int		(*fb_get_properties)(
+				fbc_dev_t	*device,
+				fbc_varient_t	*fbvar);
+					/* Device-specific properties functn */
+	void		*lib_handle;	/* Handle for shared library */
+	int		len;		/* Value returned by snprintf() */
+	char		name_buf[MAXPATHLEN]; /* Pathname & symbol name buf */
+	struct stat	stat_buf;	/* stat() buffer for device */
+
+	/*
+	 * Construct the pathname of the device-specific shared library
+	 */
+	len = snprintf(name_buf, sizeof (name_buf),
+				FBC_LIB_PATH_FMT, device->vis_ident.name);
+	if ((len < 0) || (len >= sizeof (name_buf))) {
+		fbc_errormsg("Unable to construct device library pathname, "
+					FBC_LIB_NAME_FMT "\n",
+				device->vis_ident.name);
+		exit(FBC_EXIT_FAILURE);
+	}
+
+	/*
+	 * Open the shared library for this frame buffer device type
+	 */
+	lib_handle = dlopen(name_buf, RTLD_LAZY);
+	if (lib_handle == NULL) {
+		/*
+		 * Decide whether to inflict a great ugly informative message
+		 */
+		if (stat(name_buf, &stat_buf) == 0) {
+			fbc_errormsg("%s\n", dlerror());  /* Ugly message */
+		} else {
+			fbc_errormsg("%s, %s\n", strerror(errno), name_buf);
+		}
+		exit(FBC_EXIT_FAILURE);
+	}
+
+	/*
+	 * Make sure fbconf_xorg(1M) and this libSUNW*_conf.so use the same API
+	 */
+	len = snprintf(name_buf, sizeof (name_buf),
+				FBC_API_VERSION_FMT, device->vis_ident.name);
+	if ((len < 0) || (len >= sizeof (name_buf))) {
+		fbc_errormsg("Unable to construct API version symbol name, "
+				     FBC_API_VERSION_FMT "\n",
+				device->vis_ident.name);
+		exit(FBC_EXIT_FAILURE);
+	}
+
+	fb_api_version = (fbc_api_ver_t *)dlsym(lib_handle, name_buf);
+	error_msg = dlerror();
+	if (error_msg != NULL) {
+		fbc_errormsg("%s\n", error_msg);
+		exit(FBC_EXIT_FAILURE);
+	}
+	if (*fb_api_version != FBC_API_VERSION) {
+		fbc_errormsg("API version mismatch (expected %d, found %d), "
+					FBC_LIB_NAME_FMT " \n",
+				FBC_API_VERSION,    /* fbconf_xorg(1M) */
+				*fb_api_version,    /* libSUNW*_conf.so */
+				device->vis_ident.name);
+		exit(FBC_EXIT_FAILURE);
+	}
+
+	/*
+	 * Construct the name of the device-specific properties function
+	 */
+	len = snprintf(name_buf, sizeof (name_buf),
+				FBC_FUNC_NAME_FMT, device->vis_ident.name);
+	if ((len < 0) || (len >= sizeof (name_buf))) {
+		fbc_errormsg("Unable to construct function name, "
+				     FBC_FUNC_NAME_FMT "\n",
+				device->vis_ident.name);
+		exit(FBC_EXIT_FAILURE);
+	}
+
+	/*
+	 * Get the address of the device-specific properties function
+	 */
+	fb_get_properties = (int (*)(fbc_dev_t *, fbc_varient_t *))
+					dlsym(lib_handle, name_buf);
+	error_msg = dlerror();
+	if (error_msg != NULL) {
+		fbc_errormsg("%s\n", error_msg);
+		exit(FBC_EXIT_FAILURE);
+	}
+
+	/*
+	 * Gather up and return with the device-specific properties
+	 */
+	return ((*fb_get_properties)(device, fbvar));
+
+}	/* fbc_get_properties() */
+
+
+/* End of fbc_properties.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_get_properties.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_get_properties - Get fbconf_xorg(1M) program properties
+ */
+
+
+
+#ifndef _FBC_GET_PROPERTIES_H
+#define	_FBC_GET_PROPERTIES_H
+
+
+#include <stdio.h>		/* FILE */
+
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_properties.h"	/* Establish fbconf_xorg(1M) properties */
+
+
+int fbc_get_properties(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar);	/* Returned fbconf_xorg properties */
+
+
+#endif	/* _FBC_GET_PROPERTIES_H */
+
+
+/* End of fbc_get_properties.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_getargs.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,1456 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_getargs - Program command line processing
+ */
+
+
+#include <stdio.h>		/* fprintf(), fputs() */
+#include <stdlib.h>		/* exit(), malloc(), strtof(), strtol() */
+#include <string.h>		/* strchr(), strcmp(), strlen() */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_getargs.h"	/* Program command line processing */
+#include "fbc_keywds.h"		/* Command line keyword look-up */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+#include "fbc_res.h"		/* Video modes/resolutions (-res option) */
+#include "fbc_xorg.h"		/* Edit config file data representations */
+
+
+/*
+ * fbc_search_optvals()
+ *
+ *    Look up the keyword that has been provided as the value for a
+ *    command line option.
+ */
+
+void
+fbc_search_optvals(
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const char	* const	option_name, /* Command line option name */
+	const keywd_int_t *keywd_table,	/* Table of recognized keywords */
+	const char	* const	option_value, /* Keyword string to look up */
+	const keywd_int_t **match_ent_ptr) /* Returned ptr to matching ent */
+{
+	int		error_code;	/* Error code */
+	int		i;		/* Loop counter / array index */
+
+	/*
+	 * Look up the option value keyword
+	 */
+	error_code = fbc_search_keywds((void *)keywd_table,
+					sizeof (keywd_int_t),
+					option_value,
+					(const void **)match_ent_ptr);
+	if (error_code != FBC_SUCCESS) {
+		if (error_code == FBC_ERR_KWD_INVALID) {
+			/*
+			 * Handle an unknown/invalid option value keyword
+			 */
+			fbc_errormsg("Invalid value for -%s option: %s\n",
+					option_name, option_value);
+			fprintf(stderr, "Valid values for -%s option are:\n",
+					option_name);
+			for (i = 0; keywd_table[i].argv_name != NULL; i += 1) {
+				fprintf(stderr, "\t%s\n",
+					keywd_table[i].argv_name);
+			}
+		} else {
+			/*
+			 * Handle an ambiguous abbreviation of a value keyword
+			 */
+			fbc_errormsg("Ambiguous value for -%s option.\n",
+					option_name);
+			fprintf(stderr, "Possible values are:\n");
+			fbc_print_matching_keywds((void *)keywd_table,
+						sizeof (keywd_int_t),
+						option_value);
+		}
+		fbvar->usage(stderr, fbvar);
+		exit(FBC_EXIT_USAGE);
+	}
+
+}	/* fbc_search_optvals() */
+
+
+/*
+ * fbc_add_Option_mod()
+ *
+ *    Add a config Option entry description to the .Option_mods[] array.
+ *
+ *    Reject conflicting Option values and consolidate duplicate
+ *    descriptions.  (Among other things, duplicates raise the
+ *    possibility overfilling the .Option_mods[] array).
+ *
+ *    Currently supported are Option entries having no value or a single
+ *    value.
+ *
+ *    Use fbvar->modify_config to show that the specified section of
+ *    the configuration file is to be modified.
+ */
+
+int
+fbc_add_Option_mod(
+	sectn_mask_t	option_section,	/* Option entry (sub)section */
+	const char	*option_name,	/* Option entry name  string */
+	const char	*option_value,	/* Option entry value string */
+	int (* strcmp_fn)(const char *s1, const char *s2),
+					/* strcmp(), strcasecmp(), etc. */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	xf86_opt_mod_t	**option_mod_p)	/* Option descr ptr ptr, else NULL */
+{
+	int		i;		/* Loop counter / array subscript */
+	xf86_opt_mod_t	*option_mod;	/* Ptr to Option modification descr */
+
+	/*
+	 * A NULL Option description pointer can be returned in case of error
+	 */
+	if (option_mod_p == NULL) {
+		/*
+		 * If the caller doesn't want this result, discard it someplace
+		 */
+		option_mod_p = &option_mod;
+	}
+	*option_mod_p = NULL;
+
+	/*
+	 * Taking this code path shows intent to modify a config file section
+	 */
+	fbvar->modify_config |= option_section;
+
+	/*
+	 * See if this Option was specified already and if the values conflict
+	 */
+	for (i = 0; i < fbvar->xf86_entry_mods.Option_mods_num; i += 1) {
+		/*
+		 * Compare the config sections and Option names
+		 *
+		 *    Differences in alphabetic case aren't expected,
+		 *    but are possible if our tables are constructed
+		 *    carelessly.  XFree86-style insensitivity to
+		 *    whitespace and underscores could be supported,
+		 *    should that become an issue.
+		 */
+		option_mod = &fbvar->xf86_entry_mods.Option_mods[i];
+		if ((option_section == option_mod->section) &&
+		    (strcasecmp(option_name, option_mod->name) == 0)) {
+			/*
+			 * Compare the Option values or absence thereof
+			 *
+			 *    Our caller has provided strcmp_fn that
+			 *    does case-insensitive comparisons for
+			 *    keywords, or that does case sensitive
+			 *    comparisons for other values such as
+			 *    pathnames.  Whitespace- and underscore-
+			 *    sensitivity could also be controlled in
+			 *    this way.
+			 */
+			if ((option_value      != NULL) ||
+			    (option_mod->value != NULL)) {
+				if ((option_value      == NULL) ||
+				    (option_mod->value == NULL)) {
+					/* NULL and non-NULL conflict */
+					return (FBC_ERR_OPT_CONFLICT);
+				}
+				if (strcmp_fn(option_value, option_mod->value)
+						!= 0) {
+					/* Value strings don't match */
+					return (FBC_ERR_OPT_CONFLICT);
+				}
+			}
+
+			/*
+			 * Option name and value have been specified already
+			 */
+			*option_mod_p = option_mod;
+			return (FBC_SUCCESS);
+		}
+	}
+
+	/*
+	 * Point to the next available Option entry description slot
+	 *
+	 *    Leave space for the array terminator element.
+	 */
+	option_mod = &fbvar->xf86_entry_mods.Option_mods[
+				fbvar->xf86_entry_mods.Option_mods_num];
+	fbvar->xf86_entry_mods.Option_mods_num += 1;
+	if (fbvar->xf86_entry_mods.Option_mods_num >=
+				fbvar->xf86_entry_mods.Option_mods_size) {
+		fbc_errormsg("Internal error; array bound exceeded\n");
+		exit(FBC_EXIT_FAILURE);
+	}
+
+	/*
+	 * Fill in the Option entry description
+	 */
+	option_mod->name    = option_name;
+	option_mod->value   = option_value;
+	option_mod->section = option_section;
+
+	*option_mod_p = option_mod;
+	return (FBC_SUCCESS);
+
+}	/* fbc_add_Option_mod() */
+
+
+/*
+ * fbc_add_radio_Option_mod()
+ *
+ *    Add a config Option entry description to the .Option_mods[] array.
+ *    If this and other Options are ganged together in radio button
+ *    fashion (e.g., if one's value is set to True then all others' must
+ *    be False) then reset the values of the other Options when
+ *    necesary.  Note that these Options are all assumed to belong to
+ *    the same, single section of the configuration file.
+ *
+ *    If the Option value is a keyword, look up the command line
+ *    argument and convert it to its config file form.
+ *
+ *    For all Option descriptions that are to be added, reject
+ *    conflicting Option values and consolidate duplicate descriptions.
+ */
+
+void
+fbc_add_radio_Option_mod(
+	const keywd_int_t *keywd_table,	/* Table of recognized keywords */
+	const char	*option_reset_value, /* Opt reset keyword, else NULL */
+	char	* const	argv[],		/* Program argument vector */
+	int		arg,		/* Program argument subscript */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const void	*fbopt_descr,	/* Ptr to cmd line option descr */
+	xf86_opt_mod_t	**option_mod_p)	/* Option descr ptr ptr, else NULL */
+{
+	const keywd_int_t *match_ent_ptr; /* Ptr to matching keyword entry */
+	const char	*option_name;	/* Option name  string */
+	const char	*option_value;	/* Option value string */
+	int (* strcmp_fn)(const char *s1, const char *s2);
+					/* strcmp(), strcasecmp(), etc. */
+
+	/*
+	 * See whether the config Option value involves a keyword look-up
+	 */
+	option_value = argv[arg+1];
+	strcmp_fn = &strcmp;		/* Assume case-sensitive value */
+	if (keywd_table != NULL) {
+		/*
+		 * Validate the config Option's keyword value
+		 */
+		fbc_search_optvals(fbvar,
+				((fbopt_descr_t *)fbopt_descr)->argv_name,
+				keywd_table,
+				option_value,
+				&match_ent_ptr);
+
+		/*
+		 * Get the Option value as it will appear in the config file
+		 *
+		 *    If the .conf_name hasn't been provided (e.g.,
+		 *    fbc_keywds_Samples[]), use the .argv_name.
+		 */
+		option_value = match_ent_ptr->conf_name;
+		if (option_value == NULL) {
+			option_value = match_ent_ptr->argv_name;
+		}
+		strcmp_fn = &strcasecmp; /* Keywords are case insensitive */
+	}
+
+	/*
+	 * Set up the Option description for the config file
+	 */
+	option_name = ((const fbopt_descr_t *)fbopt_descr)->conf_name;
+	if (fbc_add_Option_mod(
+			((const fbopt_descr_t *)fbopt_descr)->section,
+			option_name,
+			option_value,
+			strcmp_fn,
+			fbvar,
+			option_mod_p) != FBC_SUCCESS) {
+		fbc_errormsg("Conflicting option, %s %s\n",
+				argv[arg], argv[arg+1]);
+		exit(FBC_EXIT_USAGE);
+	}
+
+	/*
+	 * See whether setting this value should reset related Option values
+	 *
+	 *    The values of related Options should be reset (in radio
+	 *    button fashion) if:
+	 *      * A reset value (option_reset_value) has been provided
+	 *      * The value of this Option isn't the reset value
+	 *      * Related Options exist
+	 */
+	if ((option_reset_value != NULL) &&
+	    (strcasecmp(option_value, option_reset_value) != 0)) {
+		/*
+		 * Reset each related Option value
+		 */
+		for (;;) {
+			option_name += strlen(option_name) + 1;
+			if (*option_name == '\0') {
+				break;
+			}
+
+			/*
+			 * Set up the Option description for the config file
+			 */
+			if (fbc_add_Option_mod(
+					((const fbopt_descr_t *)fbopt_descr)->
+								section,
+					option_name,
+					option_reset_value,
+					strcmp_fn,
+					fbvar,
+					NULL) != FBC_SUCCESS) {
+				fbc_errormsg(
+				"Conflicting associated option, %s %s\n",
+						argv[arg], argv[arg+1]);
+				exit(FBC_EXIT_USAGE);
+			}
+		}
+	}
+
+}	/* fbc_add_radio_Option_mod() */
+
+#ifdef FBC_FUTURE
+
+/*
+ * fbc_Option_none()
+ *
+ *    Handle a configuration Option entry having no Option value.
+ *
+ *    Note: This is a fbc_getopt_fn_t typed function.
+ */
+
+void
+fbc_Option_none(
+	char	* const	argv[],		/* Program argument vector */
+	int		*arg,		/* Program argument subscript */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const void	*fbopt_descr)	/* Ptr to cmd line option descr */
+{
+
+	if (fbc_add_Option_mod(((const fbopt_descr_t *)fbopt_descr)->section,
+			((const fbopt_descr_t *)fbopt_descr)->conf_name,
+			NULL,		/* Option entry has no value */
+			&strcmp,	/* Not used; there's no value */
+			fbvar,
+			NULL) != FBC_SUCCESS) {
+		fbc_errormsg("Conflicting option, %s\n", argv[*arg]);
+		exit(FBC_EXIT_USAGE);
+	}
+
+}	/* fbc_Option_none() */
+
+#endif	/* FBC_FUTURE */
+
+/*
+ * Keyword tables for command line options having keyword arguments
+ *
+ *    The zeroth keywd_int_t array element contains the "radio button"
+ *    reset value in its .conf_name member.  The zeroth element is not
+ *    part of the keyword look-up table.  The keyword look-up table
+ *    begins at array element [1].
+ */
+
+	/* True | False */
+const keywd_int_t fbc_keywds_boolean[] = {
+	{ NULL,      "False", FBC_Bool_False },	/* Reset value (Boolean) */
+	{ "true",    "True",  FBC_Bool_True  },	/* Start of keyword table */
+	{ "false",   "False", FBC_Bool_False },
+	{ "enable",  "True",  FBC_Bool_True  },
+	{ "disable", "False", FBC_Bool_False },
+	{ "yes",     "Yes",   FBC_Bool_True  },
+	{ "no",      "No",    FBC_Bool_False },
+	{ "on",      "On",    FBC_Bool_True  },
+	{ "off",     "Off",   FBC_Bool_False },
+	{ "0",       "0",     FBC_Bool_False },
+	{ "1",       "1",     FBC_Bool_True  },
+	{ NULL,      NULL,    FBC_Bool_False }	/* End of keyword table */
+};
+
+	/* Enable | Disable */
+const keywd_int_t fbc_keywds_xable[] = {
+	{ NULL,      "Disable", FBC_Bool_False }, /* Reset value (Boolean) */
+	{ "enable",  "Enable",  FBC_Bool_True  }, /* Start of keyword table */
+	{ "disable", "Disable", FBC_Bool_False },
+	{ "true",    "Enable",  FBC_Bool_True  },
+	{ "false",   "Disable", FBC_Bool_False },
+	{ "on",      "Enable",  FBC_Bool_True  },
+	{ "off",     "Disable", FBC_Bool_False },
+	{ "yes",     "Enable",  FBC_Bool_True  },
+	{ "no",      "Disable", FBC_Bool_False },
+	{ NULL,      NULL,      FBC_Bool_False }  /* End of keyword table */
+};
+
+	/* -outputs Swapped | Direct */
+const keywd_int_t fbc_keywds_swappedirect[] = {
+	{ NULL,      "Direct",  FBC_Bool_False }, /* Reset value (Boolean) */
+	{ "swapped", "Swapped", FBC_Bool_True  }, /* Start of keyword table */
+	{ "direct",  "Direct",  FBC_Bool_False },
+	{ "true",    "Swapped", FBC_Bool_True  },
+	{ "false",   "Direct",  FBC_Bool_False },
+	{ "yes",     "Swapped", FBC_Bool_True  },
+	{ "no",      "Direct",  FBC_Bool_False },
+	{ NULL,      NULL,      FBC_Bool_False }  /* End of keyword table */
+};
+
+	/* -slave Disable | Multiview | ... */
+const keywd_int_t fbc_keywds_MultiviewMode[] = {
+	{ NULL,        NULL,        0                       }, /* No reset */
+	{ "disable",   "Disable",   FBC_Multiview_Disable   }, /* Start */
+	{ "multiview", "Multiview", FBC_Multiview_Multiview },
+#ifdef U22only
+	{ "bnc",       "BNC",       FBC_Multiview_BNC       },
+#endif
+	{ NULL,        NULL,        0                       }  /* End */
+};
+
+	/* -multisample Disable | Available | ForceOn */
+const keywd_int_t fbc_keywds_Multisample[] = {
+	{ NULL,        NULL,        0                   }, /* No reset value */
+	{ "disable",   "Disable",   FBC_SampleMode_Off  }, /* Start of table */
+	{ "available", "Available", FBC_SampleMode_On   },
+	{ "forceon",   "ForceOn",   FBC_SampleMode_Auto },
+	{ "off",       "Disable",   FBC_SampleMode_Off  },
+	{ "on",        "Available", FBC_SampleMode_On   },
+	{ "enable",    "Available", FBC_SampleMode_On   },
+	{ "auto",      "ForceOn",   FBC_SampleMode_Auto },
+	{ "true",      "Available", FBC_SampleMode_On   },
+	{ "false",     "Disable",   FBC_SampleMode_Off  },
+	{ NULL,        NULL,        0                   }  /* End of table */
+};
+
+	/* -samples */
+const keywd_int_t fbc_keywds_Samples[] = {
+	{ NULL,  NULL,  0 },		/* No reset value defined */
+	{ "1",   NULL,  1 },		/* Start of keyword table */
+	{ "4",   NULL,  4 },
+	{ "8",   NULL,  8 },
+	{ "16",  NULL, 16 },
+	{ NULL,  NULL,  0 }		/* End of keyword table */
+};
+
+
+/*
+ * fbc_Option_keyword()
+ *
+ *    Handle an configuration Option entry having a keyword value (that
+ *    is independent of other Option entries),
+ *
+ *        Option  "Clone"         "Enable"|"Disable"      # -clone
+ *
+ *        Option  "MultiviewMode" "Disable"|"Multiview"   # -slave
+ *
+ *        Option  "Multisample"   "Disable"|"Available"|"ForceOn"
+ *
+ *        Option  "Samples"       "1"|"4"|"8"|"16"        # -samples
+ *
+ *        Option  "StereoEnable"  "Enable"|"Disable"      # -stereo
+ *
+ *    or multiple such configuration Option entries that are ganged
+ *    together in radio-button fashion.
+ *
+ *        Option  "DefLinear"      "True"|"False"         # -deflinear
+ *        Option  "DefOverlay"     "True"|"False"         # -defoverlay
+ *        Option  "DefTransparent" "True"|"False"         # -deftransparent
+ *
+ *        Option  "DoubleWide"    "Enable"|"Disable"      # -doublewide
+ *        Option  "DoubleHigh"    "Enable"|"Disable"      # -doublehigh
+ *
+ *    If this and other Options are ganged together in radio button
+ *    fashion (e.g., if one's value is set to True then all others' must
+ *    be False) then reset the values of the other Options when
+ *    necessary.
+ *
+ *    Note: This is a fbc_getopt_fn_t typed function.
+ */
+
+void
+fbc_Option_keyword(
+	char	* const	argv[],		/* Program argument vector */
+	int		*arg,		/* Program argument subscript */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const void	*fbopt_descr)	/* Ptr to cmd line option descr */
+{
+	const keywd_int_t *keywd_table;	/* Table of recognized keywords */
+
+	/*
+	 * Prepare an Option entry having a Boolean-style keyword value
+	 */
+	keywd_table = ((fbopt_descr_t *)fbopt_descr)->keywd_table;
+	fbc_add_radio_Option_mod(&keywd_table[1],
+				keywd_table[0].conf_name,
+				argv,
+				*arg,
+				fbvar,
+				fbopt_descr,
+				NULL);
+
+}	/* fbc_Option_keyword() */
+
+#ifndef FBC_FUTURE
+
+/*
+ * fbc_Option_int()
+ *
+ *    Handle a configuration Option entry having an integer value.
+ *
+ *    Note: This is a fbc_getopt_fn_t typed function.
+ */
+
+void
+fbc_Option_int(
+	char	* const	argv[],		/* Program argument vector */
+	int		*arg,		/* Program argument subscript */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const void	*fbopt_descr)	/* Ptr to cmd line option descr */
+{
+	char		*end_ptr;	/* Ptr to terminator char */
+
+	/*
+	 * Validate the integer value string
+	 */
+	(void) strtol(argv[*arg+1], &end_ptr, 0);
+	if ((end_ptr == argv[*arg+1]) || (*end_ptr != 0)) {
+		fbc_errormsg("Invalid integer value, %s %s\n",
+				argv[*arg], argv[*arg+1]);
+		fbvar->usage(stderr, fbvar);
+		exit(FBC_EXIT_USAGE);
+	}
+
+	/*
+	 * Initialize the config Option descriptor
+	 */
+	if (fbc_add_Option_mod(((const fbopt_descr_t *)fbopt_descr)->section,
+			((const fbopt_descr_t *)fbopt_descr)->conf_name,
+			argv[*arg+1],
+			&strcasecmp,	/* Hexadecimal is case insensitive */
+			fbvar,
+			NULL) != FBC_SUCCESS) {
+		fbc_errormsg("Conflicting option, %s %s\n",
+				argv[*arg], argv[*arg+1]);
+		exit(FBC_EXIT_USAGE);
+	}
+
+}	/* fbc_Option_int() */
+
+#endif	/* FBC_FUTURE */
+
+/*
+ * fbc_Option_Stream_Offset()
+ *
+ *    Handle the configuration Option entries:
+ *         Option "StreamXOffset" <int>
+ *         Option "StreamYOffset" <int>
+ *
+ *    This function handles a single command line option, -offset, that
+ *    takes two integer arguments.  Retrieving two config Option names
+ *    from one fbopt_descr_t table entry is atypical, and involves an
+ *    embedded Nul character in the Option name(s) string.  Config
+ *    Option entry descriptors are produced for StreamXOffset &
+ *    StreamYOffset.
+ *
+ *    Note: This is a fbc_getopt_fn_t typed function.
+ */
+
+void
+fbc_Option_Stream_Offset(
+	char	* const	argv[],		/* Program argument vector */
+	int		*arg,		/* Program argument subscript */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const void	*fbopt_descr)	/* Ptr to cmd line option descriptor */
+{
+	char		*end_ptr;	/* Ptr to terminator char */
+	int		i;		/* Loop counter / argv[] index */
+	const char	*option_name;	/* Option name string */
+
+	/*
+	 * Validate the signed integer offset value strings
+	 */
+	for (i = 1; i <= 2; i += 1) {
+		(void) strtol(argv[*arg+i], &end_ptr, 0);
+		if ((end_ptr == argv[*arg+i]) || (*end_ptr != 0)) {
+			fbc_errormsg("Invalid offset value #%d, %s %s %s\n",
+				    i, argv[*arg], argv[*arg+1], argv[*arg+2]);
+			fbvar->usage(stderr, fbvar);
+			exit(FBC_EXIT_USAGE);
+		}
+	}
+
+	/*
+	 * Initialize StreamXOffset & StreamYOffset config Option descriptors
+	 */
+	option_name = ((const fbopt_descr_t *)fbopt_descr)->conf_name;
+	for (i = 1; i <= 2; i += 1) {
+		if (fbc_add_Option_mod(
+				((const fbopt_descr_t *)fbopt_descr)->section,
+				option_name,
+				argv[*arg+i],
+				&strcasecmp,	/* Hex is case insensitive */
+				fbvar,
+				NULL) != FBC_SUCCESS) {
+			fbc_errormsg("Conflicting option, %s %s %s\n",
+				argv[*arg], argv[*arg+1], argv[*arg+2]);
+			exit(FBC_EXIT_USAGE);
+		}
+		option_name += strlen(option_name) + 1;
+	}
+
+}	/* fbc_Option_Stream_Offset() */
+
+#ifdef FBC_FUTURE
+
+/*
+ * fbc_Option_real()
+ *
+ *    Handle a configuration Option entry having a floating point value.
+ *
+ *    Note: This is a fbc_getopt_fn_t typed function.
+ */
+
+void
+fbc_Option_real(
+	char	* const	argv[],		/* Program argument vector */
+	int		*arg,		/* Program argument subscript */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const void	*fbopt_descr)	/* Ptr to cmd line option descriptor */
+{
+	char		*end_ptr;	/* Ptr to terminator char */
+
+	/*
+	 * Validate the floating point value string
+	 */
+	(void) strtod(argv[*arg+1], &end_ptr);
+	if ((end_ptr == argv[*arg+1]) || (*end_ptr != 0)) {
+		fbc_errormsg("Invalid floating point value, %s %s\n",
+				argv[*arg], argv[*arg+1]);
+		fbvar->usage(stderr, fbvar);
+		exit(FBC_EXIT_USAGE);
+	}
+
+	/*
+	 * Initialize the config Option entry descriptor
+	 */
+	if (fbc_add_Option_mod(((const fbopt_descr_t *)fbopt_descr)->section,
+			((const fbopt_descr_t *)fbopt_descr)->conf_name,
+			argv[*arg+1],
+			strcasecmp,	/* Floating point is insensitive */
+			fbvar,
+			NULL) != FBC_SUCCESS) {
+		fbc_errormsg("Conflicting option, %s %s\n",
+				argv[*arg], argv[*arg+1]);
+		exit(FBC_EXIT_USAGE);
+	}
+
+}	/* fbc_Option_real() */
+
+#endif	/* FBC_FUTURE */
+#ifdef FBC_FUTURE
+
+/*
+ * fbc_Option_string()
+ *
+ *    Handle a configuration Option entry having a string value.
+ *
+ *    Note: This is a fbc_getopt_fn_t typed function.
+ */
+
+void
+fbc_Option_string(
+	char	* const	argv[],		/* Program argument vector */
+	int		*arg,		/* Program argument subscript */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const void	*fbopt_descr)	/* Ptr to cmd line option descriptor */
+{
+
+	if (fbc_add_Option_mod(((const fbopt_descr_t *)fbopt_descr)->section,
+			((const fbopt_descr_t *)fbopt_descr)->conf_name,
+			argv[*arg+1],
+			&strcasecmp,	/* Ummm ... */
+			fbvar,
+			NULL) != FBC_SUCCESS) {
+		fbc_errormsg("Conflicting option, %s %s\n",
+				argv[*arg], argv[*arg+1]);
+		exit(FBC_EXIT_USAGE);
+	}
+
+}	/* fbc_Option_string() */
+
+#endif	/* FBC_FUTURE */
+#ifdef FBC_FUTURE	/* or past */
+
+/*
+ * fbc_opt_DefaultDepth()
+ *
+ *    Set the DefaultDepth entry of a Screen section (-defdepth):
+ *
+ *        DefaultDepth 8|24
+ *
+ *    (Had been implemented for kfbconfig OS release 5.9.)
+ *
+ *    Note: This is a fbc_getopt_fn_t typed function.
+ */
+
+const keywd_int_t fbc_keywds_DefaultDepth[] = {
+	{ "8",  NULL,  8 },
+	{ "24", NULL, 24 },
+	{ NULL, NULL,  0 }		/* End of table */
+};
+
+void
+fbc_opt_DefaultDepth(
+	char	* const	argv[],		/* Program argument vector */
+	int		*arg,		/* Program argument subscript */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const void	*fbopt_descr)	/* Ptr to cmd line option descriptor */
+{
+	const keywd_int_t *match_ent_ptr; /* Ptr to matching keyword entry */
+
+	/*
+	 * Get the option's keyword value
+	 */
+	fbc_search_optvals(fbvar,
+			((fbopt_descr_t *)fbopt_descr)->argv_name,
+			((fbopt_descr_t *)fbopt_descr)->keywd_table,
+			argv[*arg+1],
+			&match_ent_ptr);
+
+	/*
+	 * Convert the keyword value to the corresponding depth value
+	 */
+	fbvar->xf86_entry_mods.scrn_defaultdepth = match_ent_ptr->value;
+
+	/*
+	 * The -defdepth option shows intent to modify the Screen section
+	 */
+	fbvar->modify_config |= FBC_SECTN_DefaultDepth;
+
+}	/* fbc_opt_DefaultDepth() */
+
+#endif
+
+/*
+ * fbc_opt_defaults()
+ *
+ *    Establish the default configuration for the specified device
+ *    (-defaults).
+ *
+ *    Note: This is a fbc_getopt_fn_t typed function.
+ */
+
+void
+fbc_opt_defaults(
+	char	* const	argv[],		/* Program argument vector */
+	int		*arg,		/* Program argument subscript */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const void	*fbopt_descr)	/* Ptr to cmd line option descr */
+{
+	int		defaults_arg;	/* Implied command line arg index */
+	const fbopt_descr_t *fbopt_dsc;	/* Ptr to cmd line option descr */
+
+	/*
+	 * For each command line option descriptor, set any -defaults values
+	 */
+	for (fbopt_dsc = fbvar->fbc_option;
+	    fbopt_dsc->argv_name != NULL;
+	    fbopt_dsc += 1) {
+		/*
+		 * See if this command line option has any -defaults values
+		 */
+		if (fbopt_dsc->defaults_argv == NULL) {
+			continue;	/* Nope */
+		}
+
+		/*
+		 * Avoid infinite recursion; disallow defaults for -defaults
+		 */
+		if ((fbopt_dsc == (fbopt_descr_t *)fbopt_descr) ||
+		    (strcasecmp(fbopt_dsc->argv_name, "defaults") == 0)) {
+			fbc_errormsg(
+	"Internal error; recursive -defaults encountered and ignored\n");
+			continue;	/* Let's not find out what that does */
+		}
+
+		/*
+		 * Set the default(s) for this implied command line option
+		 */
+		defaults_arg = 0;
+		(*fbopt_dsc->fbc_getopt_fn)(fbopt_dsc->defaults_argv,
+					    &defaults_arg,
+					    fbvar,
+					    fbopt_dsc);
+	}
+
+}	/* fbc_opt_defaults() */
+
+
+/*
+ * fbc_opt_dev()
+ *
+ *    Needn't get the frame buffer device name (-dev).
+ *
+ *    The frame buffer device name should have been determined already
+ *    (by fbc_get_device_arg() and fbc_get_device_name()), so it could
+ *    be established what command line options to support.
+ *
+ *    Note: This is a fbc_getopt_fn_t typed function.
+ */
+
+void
+fbc_opt_dev(
+	char	* const	argv[],		/* Program argument vector */
+	int		*arg,		/* Program argument subscript */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const void	*fbopt_descr)	/* Ptr to cmd line option descr */
+{
+
+	/* void */
+
+}	/* fbc_opt_dev() */
+
+
+/*
+ * fbc_opt_file()
+ *
+ *    Specify the configuration file (-file)
+ *
+ *    Note: This is a fbc_getopt_fn_t typed function.
+ */
+
+/*
+ * Note:  Initialization code in main() assumes that the
+ *        fbc_keywds_file[0] entry contains the default values.
+ */
+const keywd_int_t	fbc_keywds_file[] = {
+	{ FBC_FILE_KEYWD_MACHINE, FBC_FILE_PATH_MACHINE, FBC_File_Machine },
+	{ FBC_FILE_KEYWD_SYSTEM,  FBC_FILE_PATH_SYSTEM,  FBC_File_System  },
+	{ NULL,                   NULL,                  0                }
+};
+
+const char * const fbc_config_search_path  = "%A";	/* Absolute path: %A */
+
+void
+fbc_opt_file(
+	char	* const	argv[],		/* Program argument vector */
+	int		*arg,		/* Program argument subscript */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const void	*fbopt_descr)	/* Ptr to cmd line option descr */
+{
+	const keywd_int_t *match_ent_ptr; /* Ptr to matching keyword entry */
+
+	/*
+	 * Distinguish between keywords and pathnames
+	 *
+	 *    Pathnames ought to be absolute ("%A"), which means the
+	 *    first character must be a slash.  Otherwise, it's assumed
+	 *    that the argument is a keyword.
+	 */
+	if (*argv[*arg+1] == '/') {
+		/*
+??? Allow this?	 * Save the fully qualified configuration file pathname
+		 */
+		fbvar->config_file_loc  = NULL;
+		fbvar->config_file_path = argv[*arg+1];
+	} else {
+		/*
+		 * Look up the configuration file location keyword
+		 */
+		fbc_search_optvals(fbvar,
+				((fbopt_descr_t *)fbopt_descr)->argv_name,
+				((fbopt_descr_t *)fbopt_descr)->keywd_table,
+				argv[*arg+1],
+				&match_ent_ptr);
+
+		/*
+		 * Normalize the location keyword, to be used in -propt output
+		 */
+		fbvar->config_file_loc  = match_ent_ptr->argv_name;
+
+		/*
+		 * Establish the configuration file pathname
+		 */
+		fbvar->config_file_path = match_ent_ptr->conf_name;
+	}
+
+	/*
+	 * Establish the configuration file search path
+	 */
+	fbvar->config_search_path = fbc_config_search_path;
+
+}	/* fbc_opt_file() */
+
+
+/*
+ * fbc_opt_Gamma()
+ *
+ *    Set the Gamma entry of a Monitor section (-g <gamma_value>):
+ *
+ *        Gamma <gamma_value>
+ *
+ *    Note: This is a fbc_getopt_fn_t typed function.
+ */
+
+void
+fbc_opt_Gamma(
+	char	* const	argv[],		/* Program argument vector */
+	int		*arg,		/* Program argument subscript */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const void	*fbopt_descr)	/* Ptr to cmd line option descr */
+{
+	char		*end_ptr;	/* Ptr to terminator char */
+
+	/*
+	 * Process the gamma correction value argument
+	 */
+	fbvar->xf86_entry_mods.mon_gamma_red = strtof(argv[*arg+1], &end_ptr);
+	if ((end_ptr == argv[*arg+1]) ||
+	    (*end_ptr != '\0') ||
+	    !FBC_VALID_Gamma(fbvar->xf86_entry_mods.mon_gamma_red)) {
+		fbc_errormsg("Invalid gamma value, %s %s\n",
+				argv[*arg], argv[*arg+1]);
+		fbvar->usage(stderr, fbvar);
+		exit(FBC_EXIT_USAGE);
+	}
+	fbvar->xf86_entry_mods.mon_gamma_green =
+				fbvar->xf86_entry_mods.mon_gamma_red;
+	fbvar->xf86_entry_mods.mon_gamma_blue  =
+				fbvar->xf86_entry_mods.mon_gamma_red;
+
+	/*
+	 * Add the "#Gamma" pseudo-Option and reset any "GFile" Option
+	 *
+	 *    If no config entries are ganged with -g ("#Gamma"), we
+	 *    don't need to do anything.  This is indicated by having no
+	 *    config Option entry names (.conf_name is NULL).
+	 *
+	 *    If this device has any config entries that are ganged with
+	 *    "#Gamma" then they should also be pseudo-Options, or real
+	 *    Options for which the empty pathname value, "", is the
+	 *    correct reset value.  Pseudo-options are flagged with a
+	 *    "#" name prefix.  These fake Options will be eliminated
+	 *    from the .Option_mods[] array before the array is used to
+	 *    update the config file, so the choice of a reset value is
+	 *    unimportant in such cases.
+	 *
+	 *    The point of all this is to permit these two (more in the
+	 *    future?) config entries to be manipulated in radio-button
+	 *    fashion, when one is an Option entry and the other is not.
+	 */
+	if (((const fbopt_descr_t *)fbopt_descr)->conf_name != NULL) {
+		fbc_add_radio_Option_mod(NULL,
+					"",	/* No gamma table pathname */
+					argv,
+					*arg,
+					fbvar,
+					fbopt_descr,
+					NULL);
+	}
+
+}	/* fbc_opt_Gamma() */
+
+
+/*
+ * fbc_Option_GFile()
+ *
+ *    Handle a gamma table file pathname configuration Option entry
+ *    (-gfile):
+ *        Option "GFile" "[<gfile_path>]"
+ *
+ *    Note: This is a fbc_getopt_fn_t typed function.
+ */
+
+void
+fbc_Option_GFile(
+	char	* const	argv[],		/* Program argument vector */
+	int		*arg,		/* Program argument subscript */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const void	*fbopt_descr)	/* Ptr to cmd line option descriptor */
+{
+	xf86_opt_mod_t	*option_mod;	/* Option entry description */
+
+	/*
+	 * Save the gamma table input file pathname (or empty string)
+	 */
+	fbvar->gfile_in_path = argv[*arg+1];
+
+	/*
+	 * Add the "GFile" Option and reset the "#Gamma" pseudo-Option, if any
+	 *
+	 *    If this device has any config entries that are ganged with
+	 *    "GFile" then they should be pseudo-Options, such as
+	 *    "#Gamma", or be real Options for which the arbitrarily
+	 *    chosen FBC_GAMMA_DEFAULT_STR is the correct reset value.
+	 *    Pseudo-options are flagged with a "#" name prefix.  These
+	 *    fake Options will be eliminated from the .Option_mods[]
+	 *    array before the array is used to update the config file,
+	 *    so the choice of a reset value is unimportant.
+	 *
+	 *    The point of all this is to permit these two (more in the
+	 *    future?) config entries to be manipulated in radio-button
+	 *    fashion, when one is an Option entry and the other is not.
+	 */
+	fbc_add_radio_Option_mod(NULL,		/* "GFile" takes no keywords */
+				FBC_GAMMA_DEFAULT_STR, /* A "don't care" arg */
+				argv,
+				*arg,
+				fbvar,
+				fbopt_descr,
+				&option_mod);
+
+	/*
+	 * Arrange to delete any Gamma entry
+	 */
+	fbvar->xf86_entry_mods.mon_gamma_red   = 0.;
+	fbvar->xf86_entry_mods.mon_gamma_green = 0.;
+	fbvar->xf86_entry_mods.mon_gamma_blue  = 0.;
+
+	/*
+	 * Note where the pointer for the gamma table pathname has been stored
+	 *
+	 *    The description for the "GFile" Option entry has just been
+	 *    initialized using a pointer to the input gamma table
+	 *    pathname.  Before the actual Option entry is created, this
+	 *    must be replaced by a pointer to the output pathname (e.g.
+	 *    "/etc/X11/kfb0.gamma"), which is based on the config file
+	 *    directory and the device name.  We don't necessarily know
+	 *    the config file directory yet.
+	 *
+	 *    A further wrinkle is that the Option description needs the
+	 *    input pathname during command line processing so that
+	 *    conflicting -gfile argument strings can be detected.
+	 *
+	 *    If this -gfile option has a non-empty pathname argument
+	 *    and no other -gfile option has been seen, remember the
+	 *    address of the pathname pointer so it can be changed
+	 *    later, after the command line processing has been
+	 *    completed, and once the output pathname components are
+	 *    known.
+	 */
+	if ((*(argv[*arg+1]) != '\0') && (fbvar->gfile_out_path == NULL)) {
+		fbvar->gfile_out_path = &option_mod->value;
+	}
+
+}	/* fbc_Option_GFile() */
+
+
+/*
+ * fbc_opt_help()
+ *
+ *    Handle a request for help with the current varient of
+ *    fbconf_xorg(1M) (-help).
+ *
+ *    Note: This is a fbc_getopt_fn_t typed function.
+ */
+
+void
+fbc_opt_help(
+	char	* const	argv[],		/* Program argument vector */
+	int		*arg,		/* Program argument subscript */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const void	*fbopt_descr)	/* Ptr to cmd line option descr */
+{
+
+	/*
+	 * Remember to be helpful later on
+	 */
+	fbvar->option_set.help = TRUE;
+
+}	/* fbc_opt_help() */
+
+
+/*
+ * fbc_opt_prconf()
+ *
+ *    Print hardware configuration (-prconf).
+ *
+ *    Note: This is a fbc_getopt_fn_t typed function.
+ */
+
+void
+fbc_opt_prconf(
+	char	* const	argv[],		/* Program argument vector */
+	int		*arg,		/* Program argument subscript */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const void	*fbopt_descr)	/* Ptr to cmd line option descr */
+{
+
+	fbvar->option_set.prconf = TRUE;
+
+}	/* fbc_opt_prconf() */
+
+
+/*
+ * fbc_opt_predid()
+ *
+ *    Print EDID data (-predid [raw] [parsed]).
+ *
+ *    Note: This is a fbc_getopt_fn_t typed function.
+ */
+
+enum {
+	FBC_PrEDID_Raw,
+	FBC_PrEDID_Parsed
+};
+const keywd_int_t	fbc_keywds_predid[] = {
+	{ "raw",    NULL, FBC_PrEDID_Raw	},
+	{ "parsed", NULL, FBC_PrEDID_Parsed	},
+	{ NULL,     NULL, 0			}	/* End of table */
+};
+
+void
+fbc_opt_predid(
+	char	* const	argv[],		/* Program argument vector */
+	int		*arg,		/* Program argument subscript */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const void	*fbopt_descr)	/* Ptr to cmd line option descr */
+{
+	const keywd_int_t *match_ent_ptr; /* Ptr to matching keyword entry */
+
+	/*
+	 * Redundant but safe
+	 */
+	fbvar->option_set.predid_raw    = FALSE;
+	fbvar->option_set.predid_parsed = FALSE;
+
+	/*
+	 * Repeat for each argv[] string that looks like an argument
+	 */
+	while ((argv[*arg+1] != NULL) && (*argv[*arg+1] != '-')) {
+		/*
+		 * Look up the keyword (and exit if it isn't found)
+		 */
+		fbc_search_optvals(fbvar,
+				((fbopt_descr_t *)fbopt_descr)->argv_name,
+				&fbc_keywds_predid[0],
+				argv[*arg+1],
+				&match_ent_ptr);
+
+		switch (match_ent_ptr->value) {
+		case FBC_PrEDID_Raw:	/* 10-sec video mode trial */
+			fbvar->option_set.predid_raw = TRUE;
+			break;
+		case FBC_PrEDID_Parsed:	/* Apply new video mode now */
+			fbvar->option_set.predid_parsed = TRUE;
+			break;
+		default:
+			fbc_errormsg(
+			"Internal error; unimplemented keyword, %s\n",
+					argv[*arg+2]);
+			break;
+		}
+
+		/*
+		 * Include this keyword argument in the count
+		 */
+		*arg += 1;
+	}
+
+	/*
+	 * The default is "-predid parsed"
+	 */
+	if (!(fbvar->option_set.predid_raw ||
+		fbvar->option_set.predid_parsed)) {
+	    fbvar->option_set.predid_parsed = TRUE;
+	}
+
+}	/* fbc_opt_predid() */
+
+
+/*
+ * fbc_opt_propt()
+ *
+ *    Print configuration options (-propt).
+ *
+ *    Note: This is a fbc_getopt_fn_t typed function.
+ */
+
+void
+fbc_opt_propt(
+	char	* const	argv[],		/* Program argument vector */
+	int		*arg,		/* Program argument subscript */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const void	*fbopt_descr)	/* Ptr to cmd line option descr */
+{
+
+	fbvar->option_set.propt = TRUE;
+
+}	/* fbc_opt_propt() */
+
+
+/*
+ * fbc_opt_res()
+ *
+ *    Video mode/resolution:
+ *        -res ?
+ *        -res <video_mode> [noconfirm|nocheck]
+ *        -res <video_mode> [noconfirm|nocheck] [try|now]
+ *
+ *    Note: This is a fbc_getopt_fn_t typed function.
+ */
+
+enum {
+	FBC_ResMode_NOTSET = 0,	/* No update, let window system do it later */
+	FBC_ResMode_NoCheck,	/* Don't check video mode for monitor support */
+	FBC_ResMode_NoConfirm,	/* Check video mode, but don't ask user */
+	FBC_ResMode_Try,	/* Update for 10 seconds, then restore */
+	FBC_ResMode_Now		/* Update video mode now */
+};
+const keywd_int_t fbc_keywds_res_nn[] = {
+	{ "nocheck",   NULL, FBC_ResMode_NoCheck   },
+	{ "noconfirm", NULL, FBC_ResMode_NoConfirm },
+	{ NULL,        NULL, 0                }	/* End of table */
+};
+const keywd_int_t fbc_keywds_res_nntn[] = {
+	{ "nocheck",   NULL, FBC_ResMode_NoCheck    },
+	{ "noconfirm", NULL, FBC_ResMode_NoConfirm  },
+	{ "try",       NULL, FBC_ResMode_Try	    },
+	{ "now",       NULL, FBC_ResMode_Now	    },
+	{ NULL,        NULL, 0			    }	/* End of table */
+};
+
+void
+fbc_opt_res(
+	char	* const	argv[],		/* Program argument vector */
+	int		*arg,		/* Program argument subscript */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const void	*fbopt_descr)	/* Ptr to cmd line option descr */
+{
+	const keywd_int_t *match_ent_ptr; /* Ptr to matching keyword entry */
+
+	/*
+	 * Redundant but safe
+	 */
+	fbvar->option_set.res_list           = FALSE;
+	fbvar->option_set.res_mode_nocheck   = FALSE;
+	fbvar->option_set.res_mode_noconfirm = FALSE;
+	fbvar->option_set.res_mode_try       = FALSE;
+	fbvar->option_set.res_mode_now       = FALSE;
+
+	/*
+	 * Handle -res ? as the special directive for listing video modes
+	 */
+	if (strcmp(argv[*arg+1], "?") == 0) {
+		fbvar->option_set.res_list = TRUE;
+		return;
+	}
+
+	/*
+	 * Save the video mode / resolution name
+	 */
+	fbvar->xf86_entry_mods.video_mode.name = argv[*arg+1];
+
+	/*
+	 * Handle any keyword arguments
+	 */
+	if (((fbopt_descr_t *)fbopt_descr)->keywd_table != NULL) {
+		/*
+		 * Repeat for each argv[] string that looks like an argument
+		 */
+		while ((argv[*arg+2] != NULL) && (*argv[*arg+2] != '-')) {
+			/*
+			 * Look up the keyword (and exit if it isn't found)
+			 */
+			fbc_search_optvals(
+				fbvar,
+				((fbopt_descr_t *)fbopt_descr)->argv_name,
+				((fbopt_descr_t *)fbopt_descr)->keywd_table,
+				argv[*arg+2],
+				&match_ent_ptr);
+
+			switch (match_ent_ptr->value) {
+			case FBC_ResMode_NoCheck:
+				/* Don't check the video mode argument */
+				fbvar->option_set.res_mode_nocheck = TRUE;
+				/* "nocheck" implies "noconfirm" */
+				/*FALLTHROUGH*/
+			case FBC_ResMode_NoConfirm:
+				/* Check without confirmation */
+				fbvar->option_set.res_mode_noconfirm = TRUE;
+				break;
+			case FBC_ResMode_Try:
+				/* 10-second video mode trial */
+				fbvar->option_set.res_mode_try = TRUE;
+				break;
+			case FBC_ResMode_Now:
+				/* Apply the new video mode now */
+				fbvar->option_set.res_mode_now = TRUE;
+				break;
+			default:
+				fbc_errormsg(
+				"Internal error; unimplemented keyword, %s\n",
+						argv[*arg+2]);
+				break;
+			}
+
+			/*
+			 * Include this keyword argument in the count
+			 */
+			*arg += 1;
+		}
+	}
+
+	/*
+	 * Taking this code path shows intent to modify a config file section
+	 */
+	fbvar->modify_config |= FBC_SECTN_Res;
+
+}	/* fbc_opt_res() */
+
+
+/*
+ * fbc_getargs()
+ *
+ *    Process the fbconf_xorg(1M) program command line options.  There
+ *    are no legal program command line arguments.
+ *
+ *    In the event of an error this function or one of its subordinate
+ *    functions is expected to report the error and exit the program.
+ */
+
+int
+fbc_getargs(
+	const int	argc,		/* Program argument count */
+	char	 *const	argv[],		/* Program argument vector */
+	fbc_varient_t	*fbvar)		/* Program varient data */
+{
+	int		arg;		/* Program cmd line arg index */
+	int		error_code;	/* Error code */
+	fbopt_descr_t	*fbopt_descr;	/* Program option descriptors */
+	xf86_opt_mod_t	*option_mod;	/* Ptr to Option mod descr */
+
+	/*
+	 * Fill in "not set" values for the explicitly named xorg.conf entries
+	 */
+	fbvar->xf86_entry_mods.scrn_defaultdepth = FBC_NO_DefaultDepth;
+
+	fbvar->xf86_entry_mods.mon_gamma_red     = FBC_NO_Gamma;
+	fbvar->xf86_entry_mods.mon_gamma_green   = FBC_NO_Gamma;
+	fbvar->xf86_entry_mods.mon_gamma_blue    = FBC_NO_Gamma;
+
+	fbvar->xf86_entry_mods.video_mode.name   = FBC_NO_MODE_NAME;
+
+	/*
+	 * Allocate a descriptor array of config Option entries to be modified
+	 *
+	 *    This includes space for the descriptor array's terminator
+	 *    element.
+	 */
+	fbvar->xf86_entry_mods.Option_mods =
+			malloc(fbvar->xf86_entry_mods.Option_mods_size
+						* sizeof (xf86_opt_mod_t));
+	if (fbvar->xf86_entry_mods.Option_mods == NULL) {
+		fbc_errormsg("Insufficient memory, Option_mods\n");
+		exit(FBC_EXIT_FAILURE);
+	}
+	fbvar->xf86_entry_mods.Option_mods_num = 0; /* No entries yet */
+
+	fbvar->modify_config = FBC_SECTION_NONE; /* No modifications yet */
+
+	/*
+	 * Process the program command line options
+	 */
+	for (arg = 1; arg < argc; arg += 1) {
+		/*
+		 * Look up the command line option by name
+		 */
+		if (*argv[arg] != '-') {
+			break;		/* This looks more like an argument */
+		}
+		error_code = fbc_search_keywds(fbvar->fbc_option,
+						sizeof (fbopt_descr_t),
+						argv[arg]+1,
+						(void *)&fbopt_descr);
+		if (error_code != FBC_SUCCESS) {
+			if (error_code == FBC_ERR_KWD_INVALID) {
+				fbc_errormsg("Unknown option, %s\n",
+						argv[arg]);
+			} else {
+				fbc_errormsg("Option %s is ambiguous.\n",
+						argv[arg]);
+				fprintf(stderr, "Possible values are:\n");
+				fbc_print_matching_keywds(fbvar->fbc_option,
+							sizeof (fbopt_descr_t),
+							argv[arg]+1);
+			}
+			fbvar->usage(stderr, fbvar);
+			exit(FBC_EXIT_USAGE);
+		}
+
+		/*
+		 * Make sure the final cmd line option isn't missing an arg
+		 */
+		if ((arg + fbopt_descr->option_args) >= argc) {
+			fbc_errormsg("Option requires an argument, %s\n",
+					argv[arg]);
+			fbvar->usage(stderr, fbvar);
+			exit(FBC_EXIT_USAGE);
+		}
+
+		/*
+		 * Process the command line option and any argument(s)
+		 */
+		(*fbopt_descr->fbc_getopt_fn)(argv, &arg, fbvar, fbopt_descr);
+
+		/*
+		 * Advance to the next option, if any
+		 *
+		 *    If the current option accepted a variable number
+		 *    of arguments, the "fbc_getopt_fn" function should
+		 *    have incremented the "arg" index by the number of
+		 *    optional arguments that were encountered.  Here
+		 *    the "arg" index is incremented by the number of
+		 *    required arguments.
+		 */
+		arg += fbopt_descr->option_args;
+	}
+
+	/*
+	 * Disallow program command line arguments
+	 */
+	if (arg < argc) {
+		fbc_errormsg("Unknown option, %s\n", argv[arg]);
+		fbvar->usage(stderr, fbvar);
+		exit(FBC_EXIT_USAGE);
+	}
+
+	/*
+	 * Mark the end of the array of config Option entries to be modified
+	 */
+	option_mod = &fbvar->xf86_entry_mods.Option_mods[
+			fbvar->xf86_entry_mods.Option_mods_num];
+	option_mod->section = 0;
+	option_mod->name    = NULL;
+	option_mod->value   = NULL;
+
+	/*
+	 * Return without incident
+	 */
+	return (FBC_EXIT_SUCCESS);
+
+}	/* fbc_getargs() */
+
+
+/* End of fbc_getargs.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_getargs.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,216 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_getargs - Program command line processing
+ */
+
+
+
+#ifndef	_FBC_GETARGS_H
+#define	_FBC_GETARGS_H
+
+
+#include <stdio.h>		/* FILE */
+
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+#include "fbc_xorg.h"		/* Edit config file data representations */
+
+
+/*
+ * Configuration file pathnames & search path (passed to xf86openConfigFile())
+ */
+extern const char *const fbc_config_search_path; /* Absolute pathname: "%A" */
+
+
+/*
+ * Ordinal-valued keyword table entry definition and table declarations
+ */
+
+typedef struct {
+	const char *const argv_name;	/* Program command line keyword */
+	const char *const conf_name;	/* Config file keyword, else NULL */
+	int		value;		/* Keyword's ordinal value */
+} keywd_int_t;
+
+enum {
+	FBC_File_Machine,		/* /etc/X11/xorg.conf */
+	FBC_File_System			/* /usr/X11/xorg.conf */
+};
+extern const keywd_int_t fbc_keywds_file[];	/* Machine, System */
+
+#ifdef FBC_FUTURE
+extern const keywd_int_t fbc_keywds_DefaultDepth[]; /* 8, 24 */
+
+#endif	/* FBC_FUTURE */
+
+enum {
+	FBC_Bool_False,			/* False */
+	FBC_Bool_True			/* True */
+};
+extern const keywd_int_t fbc_keywds_boolean[];
+extern const keywd_int_t fbc_keywds_xable[];
+extern const keywd_int_t fbc_keywds_swappedirect[];
+
+	/* -slave / MultiviewMode */
+enum {
+	FBC_Multiview_NOTSET = 0,
+	FBC_Multiview_Disable,
+	FBC_Multiview_Multiview,
+	FBC_Multiview_Stereo,
+	FBC_Multiview_BNC
+};
+extern const keywd_int_t fbc_keywds_MultiviewMode[];
+
+	/* -multisample / Multisample */
+enum {
+	FBC_SampleMode_NOTSET = 0,
+	FBC_SampleMode_Off,		/* Disable */
+	FBC_SampleMode_On,		/* Available / Enable(old) */
+	FBC_SampleMode_Auto		/* ForceOn / Auto(old) */
+};
+extern const keywd_int_t fbc_keywds_Multisample[];
+
+extern const keywd_int_t fbc_keywds_res_nn[];	/* noconfirm, nocheck */
+extern const keywd_int_t fbc_keywds_res_nntn[];	/* nocon., nocheck, try, now */
+
+extern const keywd_int_t fbc_keywds_Samples[]; /* 1, 4, 8, 16 */
+
+
+void fbc_search_optvals(
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const char	*const	option_name, /* Command line option name */
+	const keywd_int_t *keywd_table,	/* Table of recognized keywords */
+	const char	*const	option_value, /* Keyword string to look up */
+	const keywd_int_t **match_ent_ptr); /* Returned ptr to matching ent */
+
+int fbc_add_Option_mod(
+	sectn_mask_t	option_section,	/* Option entry (sub)section */
+	const char	*option_name,	/* Option entry name  string */
+	const char	*option_value,	/* Option entry value string */
+	int (* strcmp_fn)(const char *s1, const char *s2),
+					/* strcmp(), strcasecmp(), etc. */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	xf86_opt_mod_t	**option_mod_p); /* Option descr ptr ptr, else NULL */
+
+void fbc_add_radio_Option_mod(
+	const keywd_int_t *keywd_table,	/* Table of recognized keywords */
+	const char	*option_reset_value, /* Opt reset keyword, else NULL */
+	char	*const	argv[],		/* Program argument vector */
+	int		arg,		/* Program argument number */
+	fbc_varient_t	*fbvar,		/* Program varient data */
+	const void	*fbopt_descr,	/* Ptr to cmd line option descr */
+	xf86_opt_mod_t	**option_mod_p); /* Option descr ptr ptr, else NULL */
+
+/*
+ * Program command line option evaluation functions
+ */
+
+typedef void fbc_getopt_fn_t(		/* Program cmd line option evaluator */
+		char	*const argv[],	/*   Program argument vector */
+		int	*arg,		/*   Program argument subscript */
+		fbc_varient_t *fbvar,	/*   Program varient data */
+		const void *fbopt_descr); /*   Ptr to cmd line option descr */
+
+#ifdef FBC_FUTURE
+fbc_getopt_fn_t		fb_Option_none;
+#endif
+fbc_getopt_fn_t		fbc_Option_keyword;
+#ifdef FBC_FUTURE
+fbc_getopt_fn_t		fbc_Option_int;
+#endif
+fbc_getopt_fn_t		fbc_Option_Stream_Offset;
+#ifdef FBC_FUTURE
+fbc_getopt_fn_t		fbc_Option_real;
+fbc_getopt_fn_t		fbc_Option_frequency;
+fbc_getopt_fn_t		fbc_Option_string;
+fbc_getopt_fn_t		fbc_opt_DefaultDepth;
+#endif
+fbc_getopt_fn_t		fbc_opt_defaults;
+fbc_getopt_fn_t		fbc_opt_dev;
+fbc_getopt_fn_t		fbc_opt_file;
+fbc_getopt_fn_t		fbc_opt_Gamma;
+fbc_getopt_fn_t		fbc_Option_GFile;
+fbc_getopt_fn_t		fbc_opt_help;
+fbc_getopt_fn_t		fbc_opt_prconf;
+fbc_getopt_fn_t		fbc_opt_predid;
+fbc_getopt_fn_t		fbc_opt_propt;
+fbc_getopt_fn_t		fbc_opt_res;
+
+
+/*
+ * fbconf_xorg(1M) program command line option descriptor
+ *
+ *    The array of fbopt_descr_t elements is used to describe program
+ *    command line options that are recognized and how they should be
+ *    handled.
+ *
+ *    When not NULL, the .conf_name pointer provides a string of one or
+ *    more names.  Each name is Nul-terminated.  An additional Nul
+ *    terminates the entire string when a variable number of names is
+ *    expected (which precludes zero-length names other than the first
+ *    one).  These are config Option entry names and/or pseudo-Option
+ *    names.  Pseudo-Option names have a "#" prefix (e.g., "#Gamma") to
+ *    identify and set them apart.  The names in a string are often of
+ *    Options that are ganged in radio-button fashion; setting one
+ *    resets the others (e.g., "DefLinear", "DefOverlay", and
+ *    "DefTransparent").  Attempting to set more than one is an error.
+ *    Pseudo-Options are an evil necessitated by "GFile", which is an
+ *    Option, and "Gamma", which is not, however, they must work in
+ *    radio-button fashion.  The corresponding fbc_getopt_fn function
+ *    uses the string of names according to its needs.  The case of
+ *    "StreamXOffset" and "StreamYOffset" is an exception where one
+ *    command line option generates two Option entries.
+ *
+ *    The .defaults_argv pointer is NULL except for command line options
+ *    that have default values that can be set by the -defaults option.
+ *    In that case, the .defaults_argv member points to an argv-style
+ *    array of option strings that provide the default value(s).
+ *
+ *    For command line option processing, a NULL .argv_name pointer
+ *    marks the end of the array.  For help text display, a NULL
+ *    .help_text pointer marks the end of the array.  Both pointers
+ *    should therefore be NULL in the array terminator element.
+ */
+typedef struct {
+	const char *const argv_name;	/* Command line option name */
+	const char *const help_text;	/* Command line option help text */
+	int		option_args;	/* Minimum # of option arguments */
+	fbc_getopt_fn_t	*fbc_getopt_fn;	/* Cmd line option eval function */
+	const keywd_int_t *keywd_table;	/* Cmd line option argument keywords */
+	sectn_mask_t	section;	/* Config entry [sub]section code */
+	const char *const conf_name;	/* Config Option entry name(s) */
+	char	*const	*defaults_argv;	/* argv[] for -defaults, else NULL */
+} fbopt_descr_t;
+
+
+int fbc_getargs(
+	const int	argc,		/* Program argument count */
+	char	*const	argv[],		/* Program argument vector */
+	fbc_varient_t	*fbvar);	/* Program varient data */
+
+
+#endif	/* _FBC_GETARGS_H */
+
+
+/* End of fbc_getargs.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_help.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,241 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_help - Program usage and help messages
+ */
+
+
+#include <stdio.h>		/* fprintf(), fputs() */
+#include <string.h>		/* strchr(), strcmp(), strlen() */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_getargs.h"	/* Program command line processing */
+#include "fbc_help.h"		/* Program usage and help messages */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+
+
+/*
+ * Usage message header for all frame buffer devices
+ */
+const char	fbc_usage_text_header[] =
+	"Usage:\n\t";
+
+/*
+ * Usage message body for an unknown frame buffer device type
+ */
+const char	fbc_usage_text_body[] =
+	" [-dev devname] [-file machine | system | config-path]\n"
+	"\t\t  [device-specific-options]\n"
+	"\t\t  [-defaults]\n"
+	"\t\t  [-help]\n"
+	"\t\t  [-res \\?]\n"
+	"\t\t  [-prconf] [-predid [raw] [parsed]] [-propt]\n"
+	"\n";
+
+
+/*
+ * Help (-help) message text
+ */
+const char	fbc_help_clone[] =
+"	-clone		If enabled, the two display devices will display\n"
+"			identically.  Default: disable.\n";
+const char	fbc_help_defaults[] =
+"	-defaults	Set configuration options for the specified device\n"
+"			to default values.  (This does not reset -res video\n"
+"			modes.)\n";
+#ifdef	FBC_FUTURE	/* ... or past */
+const char	fbc_help_defdepth[] =
+"	-defdepth	Default depth to start the window system in.\n"
+"			Default: 24\n";
+#endif
+const char	fbc_help_deflinear[] =
+"	-deflinear	If True, default visual will be linear visual.\n"
+"			Default: false\n";
+const char	fbc_help_defoverlay[] =
+"	-defoverlay	If True, default visual will be an overlay visual.\n"
+"			Default: false\n";
+const char	fbc_help_deftransparent[] =
+"	-deftransparent	If True, default visual will be a transparent overlay\n"
+"			visual.  Default: false\n";
+#if (0)	/* From Xsun's nfbconfig.c & pfbbconfig.c for Solaris 8 & 9 */
+const char	fbc_help_depth[] =
+"	-depth		Set the depth (bits per pixel) for the window system.\n"
+"			Default: 24.\n";
+#endif	/* From Xsun's nfbbconfig.c & pfbbconfig.c for Solaris 8 & 9 */
+const char	fbc_help_dev[] =
+"	-dev		Specify the frame buffer device file name.\n"
+"			Default: "
+FBC_DEVICE_SYMLINK_PATH " else " FBC_DEVICE_SYMLINK_PATH_0 ".\n";
+const char	fbc_help_doublewide[] =
+"	-doublewide	Combine both displays into one horizontal virtual\n"
+"			display.  Default: disable\n";
+const char	fbc_help_doublehigh[] =
+"	-doublehigh	Combine both displays into one vertical virtual\n"
+"			display.  Default: disable\n";
+const char	fbc_help_fake8[] =
+"	-fake8		If enabled, 8-bit windows will be rendered without\n"
+"			a hardware colormap to reduce colormap flashing.\n"
+"			Performance degradation might be observed.\n"
+"			Default: disable\n";
+const char	fbc_help_file[] =
+"	-file		Which xorg.conf configuration file to update.\n"
+"			Default: "
+FBC_DEFAULT_CONFIG_LOC
+"\n";
+const char	fbc_help_g[] =
+"	-g		Gamma Correction Value.\n"
+"			Default: "
+FBC_GAMMA_DEFAULT_STR
+"\n";
+const char	fbc_help_gfile[] =
+"	-gfile		Filename of the file containing Gamma Correction Table.\n";
+const char	fbc_help_help[] =
+"	-help		Display this help text.\n";
+const char	fbc_help_multisample[] =
+"	-multisample	If disable, no multisampling is possible. If available,\n"
+"			multisampling is possible but selected on a per window\n"
+"			basis.  If forceon, all OpenGL windows are rendered\n"
+"			using multisampling.\n"
+"			Default: disable\n";
+const char	fbc_help_offset[] =
+"	-offset		Adjust the position of the specified stream.\n"
+"			Currently only implemented in -doublewide and\n"
+"			-doublehigh modes.\n"
+"			For -doublewide the X offset is used to position the\n"
+"			rightmost stream. Negative is left (overlaps with\n"
+"			left stream).\n"
+"			For -doublehigh the Y offset is used to position the\n"
+"			bottommost stream.  Negative is up (overlaps with\n"
+"			upper stream).\n";
+const char	fbc_help_outputs[] =
+"	-outputs	With the swapped setting, the displays are swapped\n"
+"			horizontally or vertically, depending on whether\n"
+"			-doublewide or -doublehigh is set.  With the direct\n"
+"			setting, or if neither -doublewide nor -doublehigh is\n"
+"			set, no swapping is done.\n"
+"			Default: direct\n";
+const char	fbc_help_prconf[] =
+"	-prconf		Print the device hardware configuration.\n";
+const char	fbc_help_predid[] =
+"	-predid		Print the EDID (Enhanced Extended Display\n"
+"			Identification Data) information obtained from the\n"
+"			display device(s), which must be online.\n"
+"			Optional arguments are:\n"
+"			    raw    - Display the data as hexadecimal bytes\n"
+"			    parsed - Display the data as human-readable text\n"
+"			Default: parsed\n";
+const char	fbc_help_propt[] =
+"	-propt		Print the current configuration option settings.\n";
+const char	fbc_help_res_nn[] =
+"	-res		To list the video modes configured for the device,\n"
+"			use the -res \\? option.  To change the current video\n"
+"			mode use -res <video-mode>.  Modifiers are:\n"
+"			    nocheck   - Bypass all video mode validation\n"
+"			    noconfirm - No confirmation of unrecognized mode\n"
+"			There is no default video mode.\n";
+const char	fbc_help_res_nntn[] =
+"	-res		To list the video modes configured for the device,\n"
+"			use the -res \\? option.  To change the current video\n"
+"			mode use -res <video-mode>.  Modifiers are:\n"
+"			    nocheck   - Bypass all video mode validation\n"
+"			    noconfirm - No confirmation if mode is not known\n"
+"			    try       - Try the video mode for 10 seconds\n"
+"			    now       - Apply the new video mode now\n"
+"			There is no default video mode.\n";
+const char	fbc_help_rscreen[] =
+"	-rscreen	Enable or disable remote graphics console access.\n"
+"			Default: disable.\n";
+const char	fbc_help_samples[] =
+"	-samples	Request the number of samples to compute per display\n"
+"			pixel.\n"
+"			Default: 4\n";
+const char	fbc_help_slave[] =
+"	-slave		If multiview this device synchronizes video with a\n"
+"			master through the multiview ribbon cable.  Both\n"
+"			devices should be running the same resolution and\n"
+"			this option should be issued when the window system\n"
+"			is running.  Default: disable\n";
+const char	fbc_help_stereo[] =
+"	-stereo		Enable or disable stereo video mode.  Default: false\n";
+
+
+/*
+ * fbc_usage()
+ *
+ *    Display the appropriate program command line usage.
+ */
+
+void
+fbc_usage(
+	FILE		*output_stream,	/* stdout or stderr */
+	fbc_varient_t	*fbvar)		/* Program varient data */
+{
+
+	fputs(fbvar->usage_text_header, output_stream);
+	fputs(fbvar->prog_name, output_stream);
+	fputs(fbvar->usage_text_body, output_stream);
+
+}	/* fbc_usage() */
+
+
+/*
+ * fbc_help()
+ *
+ *    Display the appropriate program help text (-help).
+ */
+
+void
+fbc_help(
+	fbc_varient_t	*fbvar)		/* Program varient data */
+{
+	const fbopt_descr_t *option;	/* Current cmd option descriptor */
+
+	/*
+	 * Display the usage text
+	 */
+	fbvar->usage(stdout, fbvar);
+
+	/*
+	 * Display the help text for each command line option
+	 */
+	for (option = fbvar->fbc_option;
+	    option->help_text != NULL;
+	    option += 1) {
+		if (option->help_text != NULL) {
+			fputs(option->help_text, stdout);
+#ifdef DEBUG
+		} else {
+			/* Undocumented(?) option */
+			fbc_error("No help text for option, -%s\n",
+					option->argv_name);
+#endif
+		}
+	}
+	fputs("\n", stdout);
+
+}	/* fbc_help() */
+
+
+/* End of fbc_help.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_help.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_help - Program usage and help messages
+ */
+
+
+
+#ifndef	_FBC_HELP_H
+#define	_FBC_HELP_H
+
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+
+
+/*
+ * Usage message text
+ */
+extern const char fbc_usage_text_header[];
+extern const char fbc_usage_text_body[];
+
+/*
+ * Help (-help) message text
+ */
+extern const char fbc_help_clone[];
+extern const char fbc_help_defaults[];
+#ifdef	FBC_FUTURE	/* ... or past */
+extern const char fbc_help_defdepth[];
+#endif
+extern const char fbc_help_deflinear[];
+extern const char fbc_help_defoverlay[];
+extern const char fbc_help_deftransparent[];
+extern const char fbc_help_dev[];
+extern const char fbc_help_doublewide[];
+extern const char fbc_help_doublehigh[];
+extern const char fbc_help_fake8[];
+extern const char fbc_help_file[];
+extern const char fbc_help_g[];
+extern const char fbc_help_gfile[];
+extern const char fbc_help_help[];
+extern const char fbc_help_multisample[];
+extern const char fbc_help_offset[];
+extern const char fbc_help_outputs[];
+extern const char fbc_help_prconf[];
+extern const char fbc_help_predid[];
+extern const char fbc_help_propt[];
+extern const char fbc_help_res_nn[];
+extern const char fbc_help_res_nntn[];
+extern const char fbc_help_rscreen[];
+extern const char fbc_help_samples[];
+extern const char fbc_help_slave[];
+extern const char fbc_help_stereo[];
+
+
+void fbc_usage(
+	FILE		*output_stream,	/* stdout or stderr */
+	fbc_varient_t	*fbvar);	/* Program varient data */
+
+void fbc_help(
+	fbc_varient_t	*fbvar);	/* Program varient data */
+
+
+#endif	/* _FBC_HELP_H */
+
+
+/* End of fbc_help.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_keywds.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_keywds - Command line keyword look-up
+ */
+
+
+#include <stdio.h>		/* fprintf(), fputs() */
+#include <string.h>		/* strlen(), strncasecmp() */
+
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_keywds.h"		/* Command line keyword look-up */
+
+
+/*
+ * fbc_search_keywds()
+ *
+ *    Given a table of recognized keywords and a user-submitted keyword
+ *    string, search the table for a matching keyword.  The search is
+ *    case insensitive and unique abbreviations are accepted.  Keyword
+ *    table entries must be of uniform length and begin with a (char *)
+ *    pointer to the keyword string.
+ */
+
+int
+fbc_search_keywds(
+	void		*keywd_table,	/* Table of recognized keywords */
+	int		table_ent_len,	/* Keyword table entry length */
+	const char * const keywd,	/* Keyword string to look up */
+	const void	**match_ent_ptr) /* Returned ptr to matching entry */
+{
+	int		error_code;	/* Error code */
+	size_t		keywd_len;	/* Len of user-submitted keywd */
+	const void	*table_ent_ptr;	/* Ptr to keyword entry in table */
+	size_t		table_keywd_len; /* Length of keyword from table */
+
+	/*
+	 * No matching keyword found yet
+	 */
+	*match_ent_ptr = NULL;
+	error_code     = FBC_ERR_KWD_INVALID;
+
+	/*
+	 * Examine each entry in the keyword table for a match
+	 */
+	keywd_len = strlen(keywd);
+	for (table_ent_ptr = keywd_table;
+		*(char **)table_ent_ptr != NULL;
+		table_ent_ptr =
+			(void *)((char *)table_ent_ptr + table_ent_len)) {
+
+		table_keywd_len = strlen(*(char **)table_ent_ptr);
+		if ((keywd_len <= table_keywd_len) &&
+			(strncasecmp(keywd, *(char **)table_ent_ptr, keywd_len)
+					== 0)) {
+			error_code = FBC_SUCCESS;  /* Tentative match */
+			if (*match_ent_ptr != NULL) {
+				error_code = FBC_ERR_KWD_AMBIGUOUS;
+			}
+			*match_ent_ptr = table_ent_ptr;
+			if (keywd_len == table_keywd_len) {
+				return (FBC_SUCCESS);  /* Exact match */
+			}
+		}
+
+	}
+
+	/*
+	 * Return with a table entry for a unique abbreviation or with an error
+	 */
+	return (error_code);
+
+}	/* fbc_search_keywds() */
+
+
+/*
+ * fbc_print_matching_keywds()
+ *
+ *    Given a table of recognized keywords and an ambiguous keyword
+ *    abbreviation (as flagged by fbc_search_keywds()), display on
+ *    stderr all of the keywords in the table that match the
+ *    abbreviation.  Keyword table entries must be of uniform length and
+ *    begin with a (char *) pointer to the keyword string.
+ */
+
+void
+fbc_print_matching_keywds(
+	void		*keywd_table,	/* Table of recognized keywords */
+	int		table_ent_len,	/* Keyword table entry length */
+	const char	* const	keywd)	/* Ambiguous keyword abbreviation */
+{
+	size_t		keywd_len;	/* Len of user-submitted keywd */
+	const void	*table_ent_ptr;	/* Ptr to keyword entry in table */
+	size_t		table_keywd_len; /* Length of keyword from table */
+
+	/*
+	 * Examine each entry in the keyword table for a match
+	 */
+	keywd_len = strlen(keywd);
+	for (table_ent_ptr = keywd_table;
+		*(char **)table_ent_ptr != NULL;
+		table_ent_ptr =
+			(void *)((char *)table_ent_ptr + table_ent_len)) {
+
+		table_keywd_len = strlen(*(char **)table_ent_ptr);
+		if ((keywd_len <= table_keywd_len) &&
+			(strncasecmp(keywd, *(char **)table_ent_ptr, keywd_len)
+					== 0)) {
+			fprintf(stderr, "\t%s\n", *(char **)table_ent_ptr);
+		}
+
+	}
+
+}	/* fbc_print_matching_keywds() */
+
+
+/* End of fbc_keywds.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_keywds.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_keywds - Command line keyword look-up
+ */
+
+
+
+#ifndef	_FBC_KEYWDS_H
+#define	_FBC_KEYWDS_H
+
+
+int fbc_search_keywds(
+	void		*keywd_table,	/* Table of recognized keywords */
+	int		table_ent_len,	/* Keyword table entry length */
+	const char * const keywd,	/* Keyword string to look up */
+	const void	**match_ent_ptr); /* Returned ptr to matching entry */
+
+void fbc_print_matching_keywds(
+	void		*keywd_table,	/* Table of recognized keywords */
+	int		table_ent_len,	/* Keyword table entry length */
+	const char * const keywd);	/* Ambiguous keyword abbreviation */
+
+
+#endif	/* _FBC_KEYWDS_H */
+
+
+/* End of fbc_keywds.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_line_er.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,418 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_line_er - External Representation of config lines
+ */
+
+
+#include <sys/types.h>		/* off_t */
+#include <stdio.h>		/* NULL */
+#include <stdlib.h>		/* exit(), free(), malloc() */
+
+#include "xf86Parser.h"		/* Public function, etc. declatations */
+#include "Configint.h"		/* Private definitions, etc. */
+#include "configProcs.h"	/* Private function, etc. declarations */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_line_er.h"	/* External Representation of config lines */
+
+
+/*
+ * The External Representation of the configuration file is used to
+ * maintain the order and formatting of the lines from the input file.
+ * The XFree86 parser code has not been designed to preserve
+ * configuration file text that has not been modified.  Consequently,
+ * the high-level xf86printXxxxx() functions are not used to write the
+ * output file.
+ */
+
+
+/*
+ * Doubly-linked list of config line External Representations
+ */
+fbc_line_list_t	fbc_line_ER_list = {
+	NULL,		/* Ptr to first config line ER */
+	NULL,		/* Ptr to last  config line ER */
+};
+
+
+/*
+ * fbc_ER_list_first()
+ *
+ *    Return a pointer to the first config line External Representation
+ *    in the list, else NULL.
+ */
+
+fbc_line_elem_t *
+fbc_ER_list_first(void)
+{
+
+	return (fbc_line_ER_list.head_ptr);
+
+}	/* fbc_ER_list_first() */
+
+
+/*
+ * fbc_list_append()
+ *
+ *    Append a new config line External Representation to the doubly-
+ *    linked list.
+ */
+
+static
+void
+fbc_list_append(
+	fbc_line_list_t *line_ER_list,	/* List of configuration data lines */
+	fbc_line_elem_t *element)	/* Ptr to new element */
+{
+
+	element->next_ptr = NULL;
+	element->prev_ptr = line_ER_list->tail_ptr;
+	if (line_ER_list->tail_ptr == NULL) {
+		line_ER_list->head_ptr = element;
+	} else {
+		line_ER_list->tail_ptr->next_ptr = element;
+	}
+	line_ER_list->tail_ptr = element;
+
+}	/* fbc_list_append() */
+
+
+/*
+ * fbc_list_insert_prev()
+ *
+ *    Insert a new element into the doubly-linked list, making it the
+ *    previous element of the specified element.
+ */
+
+static
+void
+fbc_list_insert_prev(
+	fbc_line_list_t *line_ER_list,	/* List of configuration data lines */
+	fbc_line_elem_t *next_line_er,	/* Line ER following insertion point */
+	fbc_line_elem_t *new_line_er)	/* Ptr to ER for new config line */
+{
+
+	new_line_er->next_ptr  = next_line_er;
+	new_line_er->prev_ptr  = next_line_er->prev_ptr;
+	next_line_er->prev_ptr = new_line_er;
+	if (line_ER_list->head_ptr == next_line_er) {
+		line_ER_list->head_ptr = new_line_er;
+	} else {
+		new_line_er->prev_ptr->next_ptr = new_line_er;
+	}
+
+}	/* fbc_list_insert_prev() */
+
+
+/*
+ * fbc_list_free()
+ *
+ *    Free the elements of the doubly-linked list of configuration
+ *    lines.
+ */
+
+void
+fbc_list_free(
+	fbc_line_list_t *line_ER_list)	/* List of configuration data lines */
+{
+	fbc_line_elem_t *cur_line_er;	/* Ptr to current list element */
+	fbc_line_elem_t *next_ptr;	/* Ptr to  next   list element */
+
+	for (cur_line_er = line_ER_list->head_ptr;
+	    cur_line_er != NULL;
+	    cur_line_er = next_ptr) {
+		next_ptr = cur_line_er->next_ptr;
+		free(cur_line_er);
+	}
+
+	line_ER_list->head_ptr = NULL;
+	line_ER_list->tail_ptr = NULL;
+
+}	/* fbc_list_free() */
+
+
+/*
+ * fbc_save_line_location()
+ *
+ *    Create, initialize, and append a new config line element to the
+ *    doubly-linked list.
+ */
+
+void
+fbc_save_line_location(
+	FILE		*config_stream_in, /* Config file input stream */
+	off_t		line_pos)	/* Position of line in config file */
+{
+	fbc_line_elem_t *line_er;	/* Ptr to ER data for a config line */
+
+	/*
+	 * Check for ftell() error encountered by xf86getToken() in scan.c
+	 */
+	if (line_pos < 0) {
+		fbc_errormsg("Invalid file offset for configuration line\n");
+		exit(FBC_EXIT_FAILURE);
+	}
+
+	/*
+	 * Save the External Representation of the configuration line
+	 */
+	line_er = malloc(sizeof (fbc_line_elem_t));
+	if (line_er == NULL) {
+		fbc_errormsg(
+		"Insufficient memory while saving config line at offset %d\n",
+		       line_pos);
+		exit(FBC_EXIT_FAILURE);
+	}
+	line_er->config_stream_in = config_stream_in;
+	line_er->line_pos         = line_pos;
+	line_er->ir_ptr           = NULL;	/* No Internal Rep data yet */
+	line_er->print_fn         = NULL;	/* No Internal Rep data yet */
+	line_er->status           = FBC_LINE_ORIGINAL;
+
+	fbc_list_append(&fbc_line_ER_list, line_er);
+
+}	/* fbc_save_line_location() */
+
+
+/*
+ * fbc_get_current_line_ER()
+ *
+ *    Return the pointer to the External Representation of the current
+ *    line.  This facilitates the linking of the External and Internal
+ *    Representations of this line of the configuration file.
+ */
+
+fbc_line_elem_t *
+fbc_get_current_line_ER(void)
+{
+
+	return (fbc_line_ER_list.tail_ptr);
+
+}	/* fbc_get_current_line_ER() */
+
+
+/*
+ * fbc_link_line_ER()
+ *
+ *    Store the opaque pointer to the config line's Internal
+ *    Representation with the line's External Representation.
+ */
+
+void
+fbc_link_line_ER(
+	fbc_line_elem_t *er_ptr,	/* Ptr to ER data for a config line */
+	void		*ir_ptr,	/* Ptr to IR data for a config line */
+	xf86_print_fn_t	*print_fn,	/* Configuration line print function */
+	unsigned char	indent_level)	/* Indentation level: FBC_INDENT_n */
+{
+
+	er_ptr->ir_ptr       = ir_ptr;
+	er_ptr->print_fn     = print_fn;
+	er_ptr->indent_level = indent_level;
+
+}	/* fbc_link_line_ER() */
+
+
+/*
+ * fbc_insert_line_ER()
+ *
+ *    Insert the specfied External Representation of a config line and
+ *    mark it as inserted.  Return a pointer to the new line's ER.
+ */
+
+fbc_line_elem_t *
+fbc_insert_line_ER(
+	fbc_line_elem_t *next_line_er,	/* Line ER following insertion point */
+	void		*ir_ptr,	/* Ptr to IR data for a config line */
+	xf86_print_fn_t	*print_fn,	/* Configuration line print function */
+	unsigned char	indent_level)	/* Indentation level: FBC_INDENT_n */
+{
+	fbc_line_elem_t *new_line_er;	/* Ptr to ER data for a config line */
+
+	new_line_er = malloc(sizeof (fbc_line_elem_t));
+	if (new_line_er == NULL) {
+		fbc_errormsg(
+			"Insufficient memory, inserting line IR\n");
+	} else {
+		new_line_er->config_stream_in = NULL;
+		new_line_er->line_pos         = -1;
+		new_line_er->ir_ptr           = ir_ptr;
+		new_line_er->print_fn         = print_fn;
+		new_line_er->status           = FBC_LINE_INSERTED;
+		new_line_er->indent_level     = indent_level;
+
+		if (next_line_er == NULL) {
+			fbc_list_append(&fbc_line_ER_list, new_line_er);
+		} else {
+			if (indent_level == FBC_INDENT_ENTRY) {
+				/*
+				 * Determine the real indentation of this line
+				 *
+				 *    Entries are indented by one level
+				 *    (FBC_INDENT_1) within sections, by
+				 *    two levels (FBC_INDENT_2) in
+				 *    subsections, etc.  We happen to
+				 *    know that new entry lines are
+				 *    always inserted just before the
+				 *    existing EndSection or
+				 *    EndSubsection line, the
+				 *    indentation of which is known.
+				 */
+				new_line_er->indent_level =
+					next_line_er->indent_level + 1;
+			}
+			fbc_list_insert_prev(
+				&fbc_line_ER_list, next_line_er, new_line_er);
+		}
+	}
+
+	return (new_line_er);
+
+}	/* fbc_insert_line_ER() */
+
+
+/*
+ * fbc_modify_line_ER()
+ *
+ *    In the External Representation, mark the specified line as
+ *    modified.
+ */
+
+void
+fbc_modify_line_ER(
+	fbc_line_elem_t *line_er)	/* Ptr to ER data for a config line */
+{
+
+	line_er->status = FBC_LINE_MODIFIED;
+
+}	/* fbc_modify_line_ER() */
+
+
+/*
+ * fbc_edit_line_ER()
+ *
+ *    Arrange to insert or to modify the External Representation of the
+ *    specified config line.
+ */
+
+void
+fbc_edit_line_ER(
+	fbc_line_elem_t **line_er,	/* Ptr to ER data for a config line */
+	fbc_line_elem_t *next_line_er,	/* Ptr to ER for a config line */
+	void		*ir_ptr,	/* Ptr to IR context for a line */
+	xf86_print_fn_t	*print_fn,	/* Configuration line print function */
+	unsigned char	indent_level)	/* Indentation level: FBC_INDENT_n */
+{
+
+	/*
+	 * Distinguish between inserting and modifying a config line
+	 */
+	if (*line_er == NULL) {
+		/*
+		 * Insert a new config line
+		 */
+		*line_er = fbc_insert_line_ER(
+				next_line_er, ir_ptr, print_fn, indent_level);
+	} else {
+		/*
+		 * Modify the existing config line
+		 */
+		fbc_modify_line_ER(*line_er);
+	}
+
+}	/* fbc_edit_line_ER() */
+
+
+/*
+ * fbc_delete_line_ER()
+ *
+ *    Mark the  External Representation of the specified config line as
+ *    deleted (unless it already doesn't exist).
+ */
+
+void
+fbc_delete_line_ER(
+	fbc_line_elem_t *line_er)	/* Ptr to ER data for a config line */
+{
+
+	if (line_er != NULL) {
+		line_er->ir_ptr = NULL;	/* Assignment should be redundant */
+		line_er->status = FBC_LINE_DELETED;
+	}
+
+}	/* fbc_delete_line_ER() */
+
+
+/*
+ * fbc_close_down_config()
+ *
+ *    Close the input configuration file(s) and release memory for the
+ *    list of config line External Representations.
+ *
+ *    This function mimics the relevant features of and is used in place
+ *    of the xf86closeConfigFile() function in scan.c, and must be
+ *    maintained accordingly.  (Note that the "builtinConfig" stuff is
+ *    not relevant.)
+ */
+
+void
+fbc_close_down_config(void)
+{
+	FILE		*config_stream_in; /* Config file input stream */
+	fbc_line_elem_t *line_er;	/* Ptr to current list element */
+
+	/*
+	 * Close each input configuration file stream recorded in the list
+	 *
+	 *    Note that xf86closeConfigFile() in scan.c closes only one
+	 *    config file stream, while the line ER list may know of two
+	 *    or more.
+	 */
+	config_stream_in = NULL;
+	for (line_er = fbc_line_ER_list.head_ptr;
+	    line_er != NULL;
+	    line_er = line_er->next_ptr) {
+		if ((line_er->status != FBC_LINE_INSERTED) &&
+		    (config_stream_in != line_er->config_stream_in)) {
+			config_stream_in = line_er->config_stream_in;
+			fclose(config_stream_in);
+		}
+	}
+
+	/*
+	 * Free the configuration line External Representation list
+	 */
+	fbc_list_free(&fbc_line_ER_list);
+
+	/*
+	 * Free the memory used in scanning the configuration file(s)
+	 */
+	xf86confScanFree();
+
+}	/* fbc_close_down_config() */
+
+
+/* End of fbc_line_er.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_line_er.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_line_er - External Representation of config lines
+ */
+
+
+
+#ifndef	_FBC_LINE_ER_H
+#define	_FBC_LINE_ER_H
+
+
+#include <sys/types.h>		/* off_t */
+#include <stdio.h>		/* FILE */
+
+
+/*
+ * Configuration line editing status (External Representation)
+ */
+typedef enum {
+	FBC_LINE_ORIGINAL = 0,		/* Line is unchanged */
+	FBC_LINE_INSERTED,		/* Line is new */
+	FBC_LINE_MODIFIED,		/* Line is modified */
+	FBC_LINE_DELETED		/* Line is deleted */
+} line_stat_t;
+
+/*
+ * Configuration line indentation levels (incrementable) for inserted lines
+ */
+enum {
+	FBC_INDENT_0	= 0,		/* Indentation level 0 */
+	FBC_INDENT_1,			/* Indentation level 1 */
+	FBC_INDENT_2,			/* Indentation level 2 */
+	FBC_INDENT_ENTRY		/* Option in a section or subsection */
+};
+
+/*
+ * Configuration line's xf86printXxxxx() function
+ */
+typedef	void xf86_print_fn_t(
+		FILE	*config_stream_out, /* Config file output stream */
+		void	*ir_ptr,	/* Ptr to Internal Rep data */
+		const	char *const whitespace[]); /* Line indentation */
+
+/*
+ * Configuration line's original or modified External Representation
+ */
+typedef struct fbc_line_elem_st {
+	struct fbc_line_elem_st *next_ptr; /* Ptr to next line element */
+	struct fbc_line_elem_st *prev_ptr; /* Ptr to previous line element */
+	FILE		*config_stream_in; /* Config file input stream */
+	off_t		line_pos;	/* Position of line in config file */
+	void		*ir_ptr;	/* Ptr to IR data, else NULL */
+	xf86_print_fn_t	*print_fn;	/* Configuration line print function */
+	unsigned char	status;		/* Line status: FBC_LINE_XXXXX */
+	unsigned char	indent_level;	/* Indentation level: FBC_INDENT_n */
+} fbc_line_elem_t;
+
+typedef struct {
+	fbc_line_elem_t *head_ptr;	/* Ptr to first line list element */
+	fbc_line_elem_t *tail_ptr;	/* Ptr to last  line list element */
+} fbc_line_list_t;
+
+extern fbc_line_list_t	fbc_line_ER_list; /* Config line External Reps */
+
+
+#define	FBC_FIRST_ER	fbc_ER_list_first() /* Start of the ER list */
+#define	FBC_LAST_ER	NULL		/* End of the ER list */
+
+
+fbc_line_elem_t *fbc_ER_list_first(void);
+
+void fbc_list_free(
+	fbc_line_list_t *linePosList);	/* List of configuration data lines */
+
+void fbc_save_line_location(
+	FILE		*config_stream_in, /* Config file input stream */
+	off_t		line_pos);	/* Position of line in config file */
+
+fbc_line_elem_t *fbc_get_current_line_ER(void);
+
+void fbc_link_line_ER(
+	fbc_line_elem_t *er_ptr,	/* Ptr to ER data for a config line */
+	void		*ir_ptr,	/* Ptr to IR data for a config line */
+	xf86_print_fn_t	*print_fn,	/* Configuration line print function */
+	unsigned char	indent_level);	/* Indentation level: FBC_INDENT_n */
+
+fbc_line_elem_t *fbc_insert_line_ER(
+	fbc_line_elem_t *next_line_er,	/* Line ER following insertion point */
+	void		*ir_ptr,	/* Ptr to IR data for a config line */
+	xf86_print_fn_t	*print_fn,	/* Configuration line print function */
+	unsigned char	indent_level);	/* Indentation level: FBC_INDENT_n */
+
+void fbc_modify_line_ER(
+	fbc_line_elem_t *line_er);	/* Ptr to ER data for a config line */
+
+void fbc_edit_line_ER(
+	fbc_line_elem_t **line_er,	/* Ptr to ER data for a config line */
+	fbc_line_elem_t *next_line_er,	/* Ptr to ER for a config line */
+	void		*ir_ptr,	/* Ptr to IR context for a line */
+	xf86_print_fn_t	*print_fn,	/* Configuration line print function */
+	unsigned char	indent_level);	/* Indentation level: FBC_INDENT_n */
+
+void fbc_delete_line_ER(
+	fbc_line_elem_t *line_er);	/* Ptr to ER data for a config line */
+
+void fbc_close_down_config(void);
+
+
+#endif	/* _FBC_LINE_ER_H */
+
+
+/* End of fbc_line_er.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_mode_list.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,343 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_mode_list - List of Modes from the config file
+ */
+
+
+#include <stdio.h>		/* NULL */
+#include <stdlib.h>		/* free(), malloc() */
+
+#include "xf86Parser.h"		/* Public function, etc. declarations */
+
+#include "fbc_Modes.h"		/* Edit Modes sections */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_mode_list.h"	/* List of Modes from the config file */
+
+
+/*
+ * fbc_insert_mode_in_list()
+ *
+ *    Insert a ModeLine / Mode-EndMode element into an unintrusive
+ *    singly-linked list of sorted Mode elements.  The list is sorted in
+ *    "-res ?" display order.  Duplicate Modes are discarded.
+ */
+
+static
+fbc_mode_elem_t *
+fbc_insert_mode_in_list(
+	fbc_mode_elem_t	*mode_list,	/* Modes from Monitor section of cfg */
+	XF86ConfModeLinePtr new_mode_ptr) /* ModeLine / Mode-EndMode entry */
+{
+	int		frequency;	/* Vert frequency of Mode in list */
+	fbc_mode_elem_t	*mode_elem;	/* Mode list element (unintrusive) */
+	fbc_mode_elem_t	**mode_elem_p;	/* Ptr to ptr to Mode list element */
+	XF86ConfModeLinePtr mode_ptr;	/* ModeLine / Mode-EndMode entry */
+	int		name_comp;	/* Result of Mode name comparison */
+	int		new_frequency;	/* Vertical frequency of new Mode */
+	long		total;		/* Total pixels */
+
+	/*
+	 * Find the insertion point in the sorted list for the new Mode element
+	 *
+	 *    The insertion point will be left in the *mode_elem_p
+	 *    location.  The list is sorted according to these keys:
+	 *        Primary:    Horizontal addressable pixels  (Descending)
+	 *        Secondary:  Vertical addressable lines     (Descending)
+	 *        Tertiary:   Vertical frequency             (Descending)
+	 *        Quaternary: Mode name string               (Ascending)
+	 *
+	 *    Quinary, etc. keys aren't needed for -res ? display
+	 *    purposes.  They are used so that exact duplicate Modes can
+	 *    be detected easily and discarded.  Their sort order is
+	 *    arbitrary.
+	 *
+	 *    Raw DotClock values shouldn't be used in place of vertical
+	 *    frequency values, since they don't reflect the blanking
+	 *    times or borders (if any).
+	 */
+	total = (long)new_mode_ptr->ml_htotal * new_mode_ptr->ml_vtotal;
+	if (total <= 0) {
+		return (mode_list);	/* Needs to be more pixilated */
+	}
+	new_frequency = (long)new_mode_ptr->ml_clock * 1000 / total;
+
+	for (mode_elem_p = &mode_list;
+	    *mode_elem_p != NULL;
+	     mode_elem_p = (fbc_mode_elem_t **)&mode_elem->list.next) {
+		mode_elem = *mode_elem_p;
+		mode_ptr  = mode_elem->mode_ptr;
+
+		/*
+		 * See if an insertion point has been found for -res ? purposes
+		 */
+		if (new_mode_ptr->ml_hdisplay > mode_ptr->ml_hdisplay) {
+			break;
+		}
+		if (new_mode_ptr->ml_hdisplay < mode_ptr->ml_hdisplay) {
+			continue;
+		}
+
+		if (new_mode_ptr->ml_vdisplay > mode_ptr->ml_vdisplay) {
+			break;
+		}
+		if (new_mode_ptr->ml_vdisplay < mode_ptr->ml_vdisplay) {
+			continue;
+		}
+
+		total     = (long)mode_ptr->ml_htotal * mode_ptr->ml_vtotal;
+		frequency = (long)mode_ptr->ml_clock * 1000 / total;
+		if (new_frequency > frequency) {
+			break;
+		}
+		if (new_frequency < frequency) {
+			continue;
+		}
+
+		name_comp = xf86nameCompare(new_mode_ptr->ml_identifier,
+					    mode_ptr->ml_identifier);
+		if (name_comp < 0) {
+			break;
+		}
+		if (name_comp > 0) {
+			continue;
+		}
+
+		/*
+		 * Discard this seemingly duplicate Mode if it's an exact dup
+		 */
+		if (new_mode_ptr->ml_htotal     > mode_ptr->ml_htotal) {
+			break;
+		}
+		if (new_mode_ptr->ml_htotal     < mode_ptr->ml_htotal) {
+			continue;
+		}
+
+		if (new_mode_ptr->ml_vtotal     > mode_ptr->ml_vtotal) {
+			break;
+		}
+		if (new_mode_ptr->ml_vtotal     < mode_ptr->ml_vtotal) {
+			continue;
+		}
+
+		if (new_mode_ptr->ml_clock      > mode_ptr->ml_clock) {
+			break;
+		}
+		if (new_mode_ptr->ml_clock      < mode_ptr->ml_clock) {
+			continue;
+		}
+
+		if (new_mode_ptr->ml_hsyncstart > mode_ptr->ml_hsyncstart) {
+			break;
+		}
+		if (new_mode_ptr->ml_hsyncstart < mode_ptr->ml_hsyncstart) {
+			continue;
+		}
+
+		if (new_mode_ptr->ml_hsyncend   > mode_ptr->ml_hsyncend) {
+			break;
+		}
+		if (new_mode_ptr->ml_hsyncend   < mode_ptr->ml_hsyncend) {
+			continue;
+		}
+
+		if (new_mode_ptr->ml_vsyncstart > mode_ptr->ml_vsyncstart) {
+			break;
+		}
+		if (new_mode_ptr->ml_vsyncstart < mode_ptr->ml_vsyncstart) {
+			continue;
+		}
+
+		if (new_mode_ptr->ml_vsyncend   > mode_ptr->ml_vsyncend) {
+			break;
+		}
+		if (new_mode_ptr->ml_vsyncend   < mode_ptr->ml_vsyncend) {
+			continue;
+		}
+
+		if (new_mode_ptr->ml_vscan      > mode_ptr->ml_vscan) {
+			break;
+		}
+		if (new_mode_ptr->ml_vscan      < mode_ptr->ml_vscan) {
+			continue;
+		}
+
+		if (new_mode_ptr->ml_hskew      > mode_ptr->ml_hskew) {
+			break;
+		}
+		if (new_mode_ptr->ml_hskew      < mode_ptr->ml_hskew) {
+			continue;
+		}
+
+		if (new_mode_ptr->ml_flags      > mode_ptr->ml_flags) {
+			break;
+		}
+		if (new_mode_ptr->ml_flags      < mode_ptr->ml_flags) {
+			continue;
+		}
+
+		return (mode_list);	/* Duplicate Mode, list is unchanged */
+	}
+
+	/*
+	 * Allocate, initialize, and insert the new Mode list element
+	 */
+	mode_elem = malloc(sizeof (fbc_mode_elem_t));
+	if (mode_elem == NULL) {
+		fbc_errormsg("Insufficient memory, mode_list\n");
+		exit(FBC_EXIT_FAILURE);	/* Avoid repeating error messages */
+	}
+
+	mode_elem->list.next = *mode_elem_p;
+	mode_elem->mode_ptr  = new_mode_ptr;
+	*mode_elem_p         = mode_elem;
+
+	/*
+	 * Return the (potentially new) list head
+	 */
+	return (mode_list);
+
+}	/*  fbc_insert_mode_in_list() */
+
+
+/*
+ * fbc_append_mode_list_to_list()
+ *
+ *    Insert the ModeLine / Mode-EndMode entries from a config list into
+ *    an unintrusive singly-linked list of sorted Mode elements.
+ */
+
+static
+fbc_mode_elem_t *
+fbc_append_mode_list_to_list(
+	fbc_mode_elem_t	*mode_list,	/* Modes from Monitor section of cfg */
+	XF86ConfModeLinePtr mode_ptr)	/* ModeLine / Mode-EndMode entry */
+{
+
+	/*
+	 * Insert each ModeLine / Mode-EndMode entry into the unintrusive list
+	 */
+	for ( ; mode_ptr != NULL; mode_ptr = mode_ptr->list.next) {
+		mode_list = fbc_insert_mode_in_list(mode_list, mode_ptr);
+	}
+	return (mode_list);
+
+}	/* fbc_append_mode_list_to_list() */
+
+
+/*
+ * fbc_get_mode_list()
+ *
+ *    Create the Monitor section if it does not exist, along with any
+ *    Modes sections that might be appropriate.
+ *
+ *    Return a dynamically allocated list of ModeLine / Mode-EndMode
+ *    entries that are accessable from the specified Monitor section of
+ *    the configuration file.
+ */
+
+fbc_mode_elem_t *
+fbc_get_mode_list(
+	XF86ConfigPtr	configIR,	/* Ptr to configuration Internal Rep */
+	XF86ConfMonitorPtr monitor_sectn_ptr, /* Ptr to Monitor section IR */
+	const char	*device_type)	/* Device type name (e.g. "nfb") */
+{
+	fbc_mode_elem_t	*mode_list;	/* Modes from Monitor section of cfg */
+	XF86ConfModesLinkPtr modeslink;	/* Ptr to UseModes list entry */
+
+	/*
+	 * Make sure there's a Monitor section that declares some video modes
+	 *
+	 *    This function is called as part of processing some form of
+	 *    the -res option.  By now the active/target sections should
+	 *    have been identified, being created if necessary.  If the
+	 *    Monitor section isn't present then a mischief has
+	 *    occurred.  If the active Monitor section contains no video
+	 *    mode declaration entries (ModeLine, Mode-EndMode, or
+	 *    UseModes) then it may be that the section was newly
+	 *    created and not yet accoutred.
+	 */
+	if (monitor_sectn_ptr == NULL) {
+		return (NULL);		/* Unwelcome but not fatal (to us) */
+	}
+
+	/*
+	 * Always get the predefined SunModes sections
+	 */
+	(void) fbc_append_Modes_sections(
+				configIR, monitor_sectn_ptr, device_type);
+
+	/*
+	 * Start with any ModeLine / Mode-EndMode entries the Monitor section
+	 */
+	mode_list = fbc_append_mode_list_to_list(
+				NULL, monitor_sectn_ptr->mon_modeline_lst);
+
+	/*
+	 * Traverse the list of Modes sectns specified by any UseModes entries
+	 */
+	for (modeslink = monitor_sectn_ptr->mon_modes_sect_lst;
+	    modeslink != NULL;
+	    modeslink = modeslink->list.next) {
+		/*
+		 * Add any ModeLine / Mode-EndMode entries in this Modes sectn
+		 */
+		mode_list = fbc_append_mode_list_to_list(
+				mode_list,
+				modeslink->ml_modes->mon_modeline_lst);
+	}
+
+	/*
+	 * Return a pointer to the unintrusive Modes list
+	 */
+	return (mode_list);
+
+}	/* fbc_get_mode_list() */
+
+
+/*
+ * fbc_free_mode_list()
+ *
+ *    Free a dynamically allocated list of unintrusive singly-linked
+ *    Mode elements.
+ */
+
+void
+fbc_free_mode_list(
+	fbc_mode_elem_t	*mode_list)	/* Modes from Monitor section of cfg */
+{
+	fbc_mode_elem_t	*mode_elem;	/* Mode list element (unintrusive) */
+	fbc_mode_elem_t	*next_mode_elem; /* Next Mode list element */
+
+	for (mode_elem = mode_list;
+	    mode_elem != NULL;
+	    mode_elem = next_mode_elem) {
+		next_mode_elem = mode_elem->list.next;
+		free(mode_elem);
+	}
+
+}	/* fbc_free_mode_list() */
+
+
+/* End of fbc_mode_list.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_mode_list.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_mode_list - List of Modes from the config file
+ */
+
+
+
+#ifndef	_FBC_MODE_LIST_H
+#define	_FBC_MODE_LIST_H
+
+
+#include "xf86Parser.h"
+#include "configProcs.h"
+
+
+/*
+ * Unintrusive singly-linked ModeLine / Mode-EndMode list element
+ */
+typedef struct fbc_mode_elem_st {
+	GenericListRec list;		/* Ptr to next Mode list element */
+	XF86ConfModeLinePtr mode_ptr;	/* ModeLine / Mode-EndMode entry */
+} fbc_mode_elem_t;
+
+
+fbc_mode_elem_t *fbc_get_mode_list(
+	XF86ConfigPtr	configIR,	/* Ptr to configuration Internal Rep */
+	XF86ConfMonitorPtr monitor_sectn_ptr, /* Ptr to Monitor section IR */
+	const char	*device_type);	/* Device type name (e.g. "nfb") */
+
+void fbc_free_mode_list(
+	fbc_mode_elem_t	*mode_list);	/* List of Monitor Mode names */
+
+
+#endif	/* _FBC_MODE_LIST_H */
+
+
+/* End of fbc_mode_list.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_open_device.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_open_device - Open the frame buffer device
+ */
+
+
+#include <sys/types.h>
+#include <errno.h>		/* errno */
+#include <fcntl.h>
+#include <string.h>		/* strerror() */
+#include <unistd.h>		/* ioctl() */
+#include <sys/stat.h>		/* stat() */
+#include <sys/visual_io.h>	/* VISUAL environment device identifier */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_open_device.h"	/* Open the frame buffer device */
+
+
+/*
+ * fbc_open_device()
+ *
+ *    Verify that the frame buffer device pathname specifies an
+ *    existing, character special device.  Open the existing graphics
+ *    device and get the VISUAL environment identifier name (e.g.
+ *    "SUNWkfb").  Return the identifier name and the file descriptor
+ *    number upon success.  Return an FBC_ERR_XXXXX code otherwise.
+ */
+
+int
+fbc_open_device(
+	fbc_dev_t	*device)	/* Frame buffer device info (-dev) */
+{
+	dev_t		device_rdev_id;	/* Device type and number */
+	int		fd;		/* Graphics device file descriptor # */
+	struct stat	stat_buf;	/* stat() buffer for device */
+
+	device->fd = -1;
+	memset(device->vis_ident.name, 0, sizeof (device->vis_ident.name));
+	device->is_default = FALSE;
+
+	/*
+	 * Make sure this is a character special file
+	 */
+	if (stat(device->path, &stat_buf) != 0) {
+	        fbc_errormsg("Unable to get status, %s, %s\n",
+				strerror(errno), device->path);
+		return (FBC_ERR_STAT);
+	}
+	if ((stat_buf.st_mode & S_IFCHR) == 0) {
+		fbc_errormsg("Not a character special file, %s\n",
+				device->path);
+		return (FBC_ERR_STAT);
+	}
+
+	/*
+	 * Open the existing device file
+	 */
+	fd = open(device->path, O_RDWR);
+	if (fd == -1) {
+		fbc_errormsg("Unable to open device, %s, %s\n",
+				strerror(errno), device->path);
+		return (FBC_ERR_OPEN);
+	}
+
+	/*
+	 * Get the VISUAL environment device identifier name
+	 */
+	if (ioctl(fd, VIS_GETIDENTIFIER, &device->vis_ident.name[0]) < 0) {
+		fbc_errormsg("Unable to get device identifier, %s, %s\n",
+					strerror(errno), device->path);
+		close(fd);
+		return (FBC_ERR_IOCTL);
+	}
+
+	device->fd = fd;
+
+	/*
+???"the" * Find out whether this is the default device
+	 *
+	 *    This would determine whether or not the Screen section for
+	 *    this device is potentially the active Screen section, and,
+	 *    if the section is missing, where in the configuration it
+	 *    should be inserted.
+	 */
+	device_rdev_id     = stat_buf.st_rdev & ~FBC_CLONE_MASK;
+	device->is_default =
+		((stat(FBC_DEVICE_SYMLINK_PATH, &stat_buf) == 0) &&
+		((stat_buf.st_mode & S_IFCHR) != 0) &&
+		((stat_buf.st_rdev & ~FBC_CLONE_MASK) == device_rdev_id));
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_open_device() */
+
+
+/* End of fbc_open_device.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_open_device.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_open_device - Open the frame buffer device
+ */
+
+
+
+#ifndef	_FBC_OPEN_DEVICE_H
+#define	_FBC_OPEN_DEVICE_H
+
+
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+
+
+int fbc_open_device(
+	fbc_dev_t	*device);	/* Frame buffer device info (-dev) */
+
+
+#endif	/* _FBC_OPEN_DEVICE_H */
+
+
+/* End of fbc_open_device.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_open_master.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,179 @@
+/*
+ * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_open_master - Find and open the matching device
+ */
+
+
+#include <sys/types.h>
+#include <dirent.h>		/* closedir(), opendir(), readdir() */
+#include <errno.h>		/* errno */
+#include <fcntl.h>
+#include <stdio.h>		/* NULL */
+#include <string.h>		/* strcmp(), strcpy() */
+#include <unistd.h>		/* close(), ioctl() */
+#include <sys/stat.h>		/* fstat(), stat() */
+#include <sys/visual_io.h>	/* VISUAL environment device identifier */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_open_master.h"	/* Find and open the matching device */
+
+
+/*
+ * fbc_open_master()
+ *
+ *    Given a VISUAL environment identifier (e.g. "SUNWkfb") and the
+ *    file number of an open FB device, search the /dev/fbs directory
+ *    for a second, matching FB device and open it.  Return the file
+ *    number of this second device, else -1.
+ *
+ *    Note that the caller knows the slave device and wants to find the
+ *    master, but this function doesn't care which device will be which.
+ */
+
+int
+fbc_open_master(
+	const char *const ident_name,	/* VISUAL identifier name */
+	int		slave_fd)	/* Slave device fd */
+{
+	DIR		*dir;		/* Directory stream */
+	struct dirent	*entry;		/* Directory entry */
+	char		*filename;	/* Ptr to filename within pathname[] */
+	char		pathname[FBC_MAX_DEV_PATH_LEN]; /* Master dev path */
+	int		master_fd;	/* File number of master device */
+	dev_t		slave_rdev_id;	/* Slave device type and number */
+	dev_t		slave_rdev_type; /* Slave device type */
+	struct stat	stat_buf;	/* File status information */
+	int		temp_fd;	/* File number of potential master */
+	struct vis_identifier vis_ident; /* VISUAL env device identifier */
+
+	/*
+	 * Get the st_rdev device info
+	 */
+	if (fstat(slave_fd, &stat_buf) < 0) {
+		return (-1);
+	}
+	slave_rdev_id   = stat_buf.st_rdev & ~FBC_CLONE_MASK;
+	slave_rdev_type = slave_rdev_id    & ~FBC_MINOR_MASK;
+
+	/*
+	 * Initialize to build fully qualified /dev/fbc/... pathnames
+	 */
+	strcpy(pathname, FBC_DEVICE_DIR "/");
+	filename = pathname + strlen(pathname);
+
+	/*
+	 * Open the /dev/fbs frame buffer device directory
+	 */
+	dir = opendir(FBC_DEVICE_DIR);
+	if (dir == NULL) {
+		return (-1);
+	}
+
+	/*
+	 * Examine each /dev/fbs entry to see if it's the same type of device
+	 */
+	master_fd = -1;
+	while ((entry = readdir(dir))) {
+		/*
+		 * Ignore dot files
+		 */
+		if (entry->d_name[0] == '.') {
+			continue;
+		}
+
+		/*
+		 * Build the pathname unless it would overflow the buffer
+		 */
+		if (strlen(entry->d_name) >=
+				&pathname[FBC_MAX_DEV_PATH_LEN] - filename) {
+			continue;
+		}
+		strcpy(filename, entry->d_name);
+
+		/*
+		 * Get the device file status, ignoring it if there's an error
+		 */
+		if (stat(pathname, &stat_buf) < 0) {
+			continue;
+		}
+
+		/*
+		 * Ignore this device file if:
+		 *    * it's not a character special file
+		 *    * it's not the same type of FB as the slave device
+		 *    * it's the self-same slave device
+		 */
+		if (((stat_buf.st_mode & S_IFCHR) == 0) ||
+		    ((stat_buf.st_rdev & ~FBC_MINOR_MASK) != slave_rdev_type) ||
+		    ((stat_buf.st_rdev & ~FBC_CLONE_MASK) == slave_rdev_id)) {
+			continue;
+		}
+
+		/*
+		 * Open the device file, ignoring it if it won't open
+		 */
+		temp_fd = open(pathname, O_RDWR);
+		if (temp_fd < 0) {
+			continue;
+		}
+
+		/*
+		 * Ignore this device if:
+		 *    * the device identifier name can't be obtained
+		 *    * the identifier name doesn't match the slave's ID name
+		 */
+		if ((ioctl(temp_fd, VIS_GETIDENTIFIER, &vis_ident) < 0) ||
+		    (strcmp(vis_ident.name, ident_name) != 0)) {
+			close(temp_fd);
+			continue;
+		}
+
+		/*
+		 * Give up if more than one potential master is found
+		 */
+		if (master_fd >= 0) {
+			close(temp_fd);
+			close(master_fd);
+			master_fd = -1;
+			break;
+		}
+
+		/*
+		 * Assume this will be the master device, but look for others
+		 */
+		master_fd = temp_fd;
+	}
+	closedir(dir);
+
+	/*
+	 * Return the open file descriptor number, else -1
+	 */
+	return (master_fd);
+
+}	/* fbc_open_master() */
+
+
+/* End of fbc_open_master.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_open_master.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_open_master - Find and open the matching device
+ */
+
+
+
+#ifndef _FBC_OPEN_MASTER_H
+#define	_FBC_OPEN_MASTER_H
+
+
+int fbc_open_master(
+	const char *const ident_name,	/* VISUAL identifier name */
+	int		slave_fd);	/* Slave device fd */
+
+
+#endif	/* _FBC_OPEN_MASTER_H */
+
+
+/* End of fbc_open_master.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_prconf.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,425 @@
+/*
+ * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_prconf - Display current hardware configuration
+ */
+
+
+#include <ctype.h>		/* isprint() */
+#include <stdio.h>		/* printf(), putchar() */
+#include <string.h>		/* strlen(), strstr() */
+#include <unistd.h>		/* ioctl() */
+
+#include "gfx_common.h"		/* Model name, part number, cur video mode */
+
+#include "sun_edid.h"		/* EDID data parsing */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_prconf.h"		/* Display current hardware configuration */
+
+
+static const char *const FBC_Unavailable = "Unavailable";
+
+
+/*
+ * fbc_prconf_model()
+ *
+ *    Display the frame buffer model name and part number.
+ */
+
+void
+fbc_prconf_model(
+	int		device_fd)	/* Device file descriptor number */
+{
+	const char *const SUNW_ = "SUNW,"; /* Prefix on model & part strings */
+	struct gfx_identifier gfx_ident; /* Graphics identifier */
+	const char	*model_name;	/* Frame buffer model name */
+	const char	*part_number;	/* Frame buffer part number */
+
+	/*
+	 * Display the model name and part number
+	 */
+	model_name  = FBC_Unavailable;
+	part_number = FBC_Unavailable;
+	if (ioctl(device_fd, GFX_IOCTL_GET_IDENTIFIER, &gfx_ident) >= 0) {
+		if (gfx_ident.flags & GFX_IDENT_MODELNAME) {
+			model_name = &gfx_ident.model_name[0];
+			if (strstr(model_name, SUNW_) != NULL) {
+				model_name += strlen(SUNW_);
+			}
+		}
+		if (gfx_ident.flags & GFX_IDENT_PARTNUM) {
+			part_number = &gfx_ident.part_number[0];
+			if (strstr(part_number, SUNW_) != NULL) {
+				part_number += strlen(SUNW_);
+			}
+		}
+	}
+	printf("Model name:  %s\n", model_name);
+	printf("Part number: %s\n", part_number);
+
+}	/* fbc_prconf_model() */
+
+
+/*
+ * fbc_prconf_edid_product_id()
+ *
+ *    Display the Vendor & Product Identification, etc. found in the
+ *    EDID Base block.
+ */
+
+static
+void
+fbc_prconf_edid_product_id(
+	uint8_t		edid_data[])	/* EDID Base block */
+{
+	uint16_t	product_code;	/* ID Product Code */
+	uint32_t	serial_num;	/* ID Serial Number, else zero */
+	char		string_buf[14];	/* ID Manufacturer, Serial #, etc. */
+	int		week;		/* Week of Manufacture (or flag) */
+	int		year;		/* Year of Manufacture or Model Year */
+
+	sun_edid_vendor(edid_data, string_buf, &product_code, &serial_num);
+	printf(FBC_PR_INDENT "Monitor manufacturer: %s\n", string_buf);
+
+	printf(FBC_PR_INDENT "Product Code:  %u\n", product_code);
+	if (sun_edid_product_name(edid_data, string_buf) == 0) {
+		printf(FBC_PR_INDENT "Product Name:  %s\n", string_buf);
+	}
+
+	if ((sun_edid_serial_number(edid_data, string_buf) == 0) ||
+	    (serial_num != 0)) {
+		printf(FBC_PR_INDENT "Serial Number:");
+		if (serial_num != 0) {
+			printf(" %u", serial_num);
+		}
+		if (string_buf[0] != '\0') {
+			printf(" %s", string_buf);
+		}
+		putchar('\n');
+	}
+
+	sun_edid_mdate(edid_data, &week, &year);
+	if (week == 0xFF) {
+		printf(FBC_PR_INDENT "Model year:    %d\n", year);
+	} else {
+		printf(FBC_PR_INDENT "Manufacture date: %d", year);
+		if (week != 0) {
+			printf(", week %d", week);
+		}
+		putchar('\n');
+	}
+
+}	/* fbc_prconf_edid_product_id() */
+
+
+/*
+ * fbc_prconf_edid_version()
+ *
+ *    Display the EDID Structure Version & Revision, obtained from EDID
+ *    Base block bytes 0x12 and 0x13, respectively.
+ */
+
+static
+void
+fbc_prconf_edid_version(
+	uint8_t		edid_data[])	/* EDID Base block */
+{
+
+	printf(FBC_PR_INDENT "EDID Version:  %u.%u\n",
+		edid_data[0x12],	/* EDID version byte */
+		edid_data[0x13]);	/* EDID revision byte */
+
+}	/* fbc_prconf_edid_version() */
+
+
+/*
+ * fbc_prconf_edid_basic_display()
+ *
+ *    Display the Basic Display Parameters & Features of the display
+ *    device.  This is obtained from the EDID Base block.
+ */
+
+static
+void
+fbc_prconf_edid_basic_display(
+	uint8_t		edid_data[])	/* EDID Base block */
+{
+	float		aspect;		/* Aspect ratio, else zero */
+	float		gamma;		/* Gamma value, else zero */
+	int		horizontal;	/* Horizontal screen size (cm), etc. */
+	int		vertical;	/* Vertical screen size (cm), etc. */
+	sun_edid_viddef_t video_def;	/* Video Input Definition */
+
+#if (0)	/* Made redundant by -predid */
+	/*
+	 * Video Input Definition (sync support info)
+	 *
+	 *    Check for Analog Video Signal Interface
+	 */
+	sun_edid_video_input(edid_data, &video_def);
+	if (!video_def.digital) {
+		const char *const Supported      = "Supported";
+		const char *const Not_supported  = "Not supported";
+
+		/*
+		 * Display Synchronization Types for this analog display device
+		 */
+		printf(FBC_PR_INDENT
+			"Separate sync H & V signals:  %s\n",
+			(video_def.alg.sync_separate) ?
+				Supported : Not_supported);
+		printf(FBC_PR_INDENT
+			"Composite sync on Horizontal: %s\n",
+			(video_def.alg.sync_composite) ?
+				Supported : Not_supported);
+		printf(FBC_PR_INDENT
+			"Composite sync on Green:      %s\n",
+			(video_def.alg.sync_green) ?
+				Supported : Not_supported);
+	}
+
+#endif	/* Made redundant by -predid */
+	/*
+	 * Horizontal & Vertical Screen Size or Aspect Ratio
+	 *
+	 *    The returned aspect ratio value (introduced in EDID 1.4)
+	 *    is only valid iff positive.  Aspect ratios are rounded to
+	 *    the hundredth decimal place.
+	 */
+	sun_edid_screen_size(edid_data, &horizontal, &vertical, &aspect);
+	if ((horizontal != 0) && (vertical != 0)) {
+		printf(FBC_PR_INDENT "Monitor dimensions: %dx%d cm\n",
+			horizontal, vertical);
+	} else
+	if (aspect > 0.0) {
+		if (horizontal != 0) {
+			printf(FBC_PR_INDENT
+				"Monitor aspect ratio (Landscape): %4.2f:1\n",
+				aspect);
+		} else {
+			printf(FBC_PR_INDENT
+				"Monitor aspect ratio (Portrait): %4.2f:1\n",
+				aspect);
+		}
+	}
+
+	/*
+	 * Display Transfer Characteristic (Gamma)
+	 */
+	sun_edid_gamma(edid_data, &gamma);
+	if (gamma > 0.0) {
+		printf(FBC_PR_INDENT "Default Gamma: %4.2f\n", gamma);
+	}
+
+}	/* fbc_prconf_edid_basic_display() */
+
+
+/*
+ * fbc_prconf_edid_display_descriptor()
+ *
+ *    Display any EDID Display Descriptor information that isn't handled
+ *    elsewhere.
+ */
+
+static
+void
+fbc_prconf_edid_display_descriptor(
+	uint8_t		edid_data[])	/* EDID Base block */
+{
+	char		string_buf[14];	/* Display Descriptor strings buffer */
+
+	if (sun_edid_alphanum_data(edid_data, string_buf) == 0) {
+		printf(FBC_PR_INDENT "Alphanumeric Data String: %s\n",
+			string_buf);
+	}
+
+}	/* fbc_prconf_edid_display_descriptor() */
+
+
+/*
+ * fbc_prconf_edid_modes()
+ *
+ *    Display the list of display-supported resolution names obtained
+ *    from EDID timings data.  The caller must have made sure that the
+ *    list exists.  Mode names can be filtered (excluded or substituted)
+ *    based on the edid_mode_mods[] array.
+ */
+
+static
+void
+fbc_prconf_edid_modes(
+	sun_edid_mode_t	*edid_mode)	/* Display-supported video modes */
+{
+	const char	*comma_str;	/* Label string or "," */
+	size_t		len;		/* Length of Space & mode name */
+	size_t		line_len;	/* Line length in text columns */
+	const char	*mode_name;	/* EDID video mode name */
+
+	/*
+	 * Display the preferred video mode of the display device
+	 *
+	 *    The display's Preferred Timing Mode should be encoded in
+	 *    the first Detailed Timing Descriptor in the EDID Base
+	 *    block.  This yeilds the preferred video mode, which should
+	 *    be stored in the first element of the edid_mode[] array.
+	 *    An empty mode name string ("") means that no Preferred
+	 *    Timing was specified (e.g. pre EDID 1.1).
+	 */
+	mode_name = edid_mode->name;
+	if (*mode_name != '\0') {
+		printf(FBC_PR_INDENT "Monitor preferred resolution: %s\n",
+			mode_name);
+	}
+
+	/*
+	 * Display the video modes supported by the display device
+	 *
+	 *    Which mode names will get past the filter isn't yet known.
+	 *    Hypothetically, no names might be displayed.  A suitable
+	 *    generalization is wanted.
+	 *
+	 *    A comma preceeds each video mode name except for the
+	 *    first.  The first video mode name is preceded by the
+	 *    "supported resolutions" label.  The label will be treated
+	 *    as an honorary comma so that the loop will be able to
+	 *    handle each mode name in the same way.
+	 */
+	comma_str = FBC_PR_INDENT "Monitor supported resolutions from EDID:";
+	line_len  = 0;
+	for (; edid_mode->name != NULL; edid_mode += 1) {
+		mode_name = edid_mode->name;
+		if (*mode_name == '\0') {
+			continue;	/* Video mode has been filtered out */
+		}
+		printf("%s", comma_str); /* Resolutions label string or "," */
+		line_len += strlen(comma_str);
+		comma_str = ",";
+		len = 1 + strlen(mode_name); /* " " & mode_name */
+		if (line_len + len + 1 >= FBC_MAX_LINE_LEN) {  /* 1 for "," */
+			printf("\n" FBC_PR_INDENT "   ");  /* NL & 7 Spaces */
+			line_len =  FBC_PR_INDENT_LEN + 3; /* 7 now, 1 later */
+		}
+		printf(" %s", mode_name);	/* One Space & mode name */
+		line_len += len;
+	}
+	if (line_len > 0) {
+		putchar('\n');
+	}
+
+}	/* fbc_prconf_edid_modes() */
+
+
+/*
+ * fbc_prconf_edid()
+ *
+ *    Display the EDID information for this video stream's display device.
+ */
+
+void
+fbc_prconf_edid(
+	uint8_t		*edid_data,	/* EDID Base & Extension blocks */
+	size_t		edid_length,	/* EDID data block(s) length */
+	fbc_mode_elem_t	*mode_list)	/* Modes from configuration file */
+{
+	int		block_num;	/* Zero, else bad Extension block # */
+	sun_edid_mode_t	*edid_modes;	/* Display-supported video modes */
+
+#if defined(FBC_EDID_TEST_DATA)
+#include "fbc_edid_test_data.h"	/* EDID test data */
+#endif
+
+	/*
+	 * Validate the EDID Base block and any Extension blocks
+	 *
+	 *    The Base block is needed in order for this function to do
+	 *    anything.  Extension blocks aren't used in the current
+	 *    implementation.
+	 */
+	if (sun_edid_check_base(edid_data, edid_length) != 0) {
+		printf(FBC_PR_INDENT
+			"EDID Data: EDID Base block is not available\n");
+		return;
+	}
+	block_num = sun_edid_check_extensions(edid_data, edid_length);
+	if (block_num != 0) {
+		printf(FBC_PR_INDENT
+			"EDID Data: Error near EDID Extension block #%d\n",
+			block_num);
+	}
+
+	/*
+	 * Display Vendor & Product ID, Version, Basic Display Params, etc.
+	 */
+	fbc_prconf_edid_product_id(edid_data);
+	fbc_prconf_edid_version(edid_data);
+	fbc_prconf_edid_display_descriptor(edid_data);
+	fbc_prconf_edid_basic_display(edid_data);
+
+	/*
+	 * Get the EDID video mode names for this stream's display device
+	 */
+	edid_modes = sun_edid_video_modes(edid_data, edid_length, mode_list);
+
+	/*
+	 * Display the display-supported video modes (possibly filtered)
+	 */
+	if ((edid_modes != NULL) && (edid_modes->name != NULL)) {
+		fbc_prconf_edid_modes(edid_modes);
+	}
+
+	sun_edid_video_modes_free(edid_modes);
+
+}	/* fbc_prconf_edid() */
+
+
+/*
+ * fbc_prconf_cur_mode()
+ *
+ *    Display the current video mode setting.
+ */
+
+void
+fbc_prconf_cur_mode(
+	int		device_fd)	/* Device file descriptor number */
+{
+	struct gfx_video_mode gfx_vid_mode; /* Current video mode info */
+	const char	*mode_name;	/* Current video mode name */
+
+	/*
+	 * Display the current video mode setting
+	 */
+	mode_name = FBC_Unavailable;
+	if (ioctl(device_fd,
+		    GFX_IOCTL_GET_CURRENT_VIDEO_MODE,
+		    &gfx_vid_mode) >= 0) {
+		mode_name = &gfx_vid_mode.mode_name[0];
+	}
+	printf(FBC_PR_INDENT "Current resolution setting: %s\n", mode_name);
+
+}	/* fbc_prconf_cur_mode() */
+
+
+/* End of fbc_prconf.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_prconf.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_prconf - Display current hardware configuration
+ */
+
+
+
+#ifndef _FBC_PRCONF_H
+#define	_FBC_PRCONF_H
+
+
+#include <sys/int_types.h>	/* uint8_t */
+
+#define	FBC_MAX_LINE_LEN 75	/* Max -prconf output line length in columns */
+
+
+void fbc_prconf_model(
+	int		device_fd);	/* Device file descriptor number */
+
+void fbc_prconf_edid(
+	uint8_t		*edid_data,	/* EDID Base & Extension blocks */
+	size_t		edid_length,	/* EDID data block(s) length */
+	fbc_mode_elem_t	*mode_list);	/* Video modes from config file */
+
+void fbc_prconf_cur_mode(
+	int		device_fd);	/* Device file descriptor number */
+
+
+#endif	/* _FBC_PRCONF_H */
+
+
+/* End of fbc_prconf.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_predid.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,1336 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_predid - Display EDID data
+ */
+
+
+#include <ctype.h>		/* isprint() */
+#include <stdio.h>		/* printf(), putchar(), sprintf() */
+#include <string.h>		/* strlen() */
+
+#include "sun_edid.h"		/* EDID data parsing */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_predid.h"		/* Display EDID data */
+#include "fbc_predid_ceaext.h"	/* Display EDID CEA-EXT data */
+#include "fbc_predid_diext.h"	/* Display EDID DI-EXT data */
+#include "fbc_predid_vtbext.h"	/* Display EDID VTB-EXT data */
+
+
+/*
+ * Conversions from EDID flag bit value to output text string
+ */
+static const char	*const fbc_No  = "No";
+static const char	*const fbc_Yes = "Yes";
+
+#define	FBC_YES_NO(_byte, _mask) \
+		((_byte) & (_mask)) ? fbc_Yes : fbc_No
+
+static const char	*const fbc_Supported     = "Supported";
+static const char	*const fbc_Not_supported = "Not supported";
+
+
+/*
+ * fbc_predid_dump_bytes()
+ *
+ *    Dump the specified bytes of the EDID data block in hexadecimal.
+ *
+ *    Byte addresses as well as data bytes are displayed using two hex
+ *    digits.  Each line can contain 16 bytes.  The data is such that an
+ *    ASCII display wouldn't be useful.
+ */
+
+void
+fbc_predid_dump_bytes(
+	const uint8_t	edid_data[],	/* EDID Base & Extension blocks */
+	size_t		start_addr,	/* Starting byte address */
+	size_t		end_addr)	/* Ending   byte address */
+{
+	const size_t	bytes_per_line = 16; /* Bytes per line (power of 2) */
+	const int	hex_cols = 3;	/* Columns per hex value (" %02X") */
+	size_t		byte_addr;	/* Current byte address */
+	char		hex_buf[hex_cols*bytes_per_line+1]; /* Hex byte buf */
+	size_t		i;		/* Loop counter / array index */
+	size_t		line_addr;	/* Address for start of current line */
+
+	/*
+	 * Provide Spaces for undisplayed bytes that precede the start address
+	 */
+	hex_buf[0] = '\0';
+	line_addr = start_addr & ~(bytes_per_line - 1); /* Round down */
+	for (byte_addr = line_addr; byte_addr < start_addr; byte_addr += 1) {
+		strcat(hex_buf, "   ");
+	}
+
+	/*
+	 * Display each 16-byte wide line of the dump
+	 */
+	for (; line_addr <= end_addr; line_addr += bytes_per_line) {
+		for (;
+		    (((byte_addr - line_addr) < bytes_per_line) &&
+			      (byte_addr <= end_addr));
+		    byte_addr += 1) {
+			i = byte_addr - line_addr;
+			sprintf(&hex_buf[hex_cols*i], " %02X",
+				edid_data[byte_addr]);
+		}
+		printf("\t0x%02X: %s\n", line_addr, hex_buf);
+		hex_buf[0] = '\0';
+	}
+
+}	/* fbc_predid_dump_bytes() */
+
+
+/*
+ * fbc_predid_tagged_string()
+ *
+ *    Given a string tag number, a table of tagged strings with a
+ *    final NULL entry, and a default string, return the text string
+ *    with the matching tag, else return the default text string.
+ */
+
+const char *
+fbc_predid_tagged_string(
+	unsigned int	tag,		/* String tag number */
+	const fbc_tag_str_t string[],	/* Array of tagged strings */
+	const char *const default_text)	/* Default string text */
+{
+	int		i;		/* Loop counter / arrax index */
+
+	for (i = 0; string[i].text != NULL; i += 1) {
+		if (string[i].tag == tag) {
+			return (string[i].text);
+		}
+	}
+
+	return (default_text);
+
+}	/* fbc_predid_tagged_string() */
+
+
+/*
+ * Parsed EDID data display function type
+ */
+typedef void (parsed_fn_t)(
+	const uint8_t	edid_block[],	/* EDID data block */
+	unsigned int	start_addr,	/* Starting byte address */
+	unsigned int	end_addr);	/* Ending   byte address */
+
+/*
+ * EDID data block format descriptor
+ */
+typedef struct {
+	unsigned int	start_addr;	/* Starting byte address */
+	unsigned int	end_addr;	/* Ending   byte address */
+	const char	*heading;	/* Description */
+	parsed_fn_t	*parsed_fn;	/* Parsed EDID data display function */
+} fbc_edid_fmt_t;
+
+enum {
+	NO_DATA		= 0x0100,	/* Don't display hex data bytes */
+	END_MARKER	= 0xFFFF	/* End of format descriptor table */
+};
+
+
+/*
+ * fbc_predid_vendor()
+ *
+ *    Decode and display Vendor & Product Identification from an EDID
+ *    Base block:
+ *	* ID Manufacturer
+ *	* ID Product Code
+ *	* ID Serial Number (Zero = Not used)
+ *      * Week of Manufacture
+ *        (0x00 = Not used, 1..54 = Week, 0xFF = Model year flag (EDID 1.4))
+ *      * Year of Manufacture or Model Year
+ */
+
+static
+void
+fbc_predid_vendor(
+	const uint8_t	edid_base[],	/* EDID Base block */
+	unsigned int	start_addr,	/* Starting byte address (0x08) */
+	unsigned int	end_addr)	/* Ending   byte address (0x11) */
+{
+	uint16_t	product_code;	/* ID Product Code */
+	uint32_t	serial_num;	/* ID Serial Number, else zero */
+	char		string_buf[4];	/* ID Manufacturer (3 chars & Nul) */
+	int		week;		/* Week of Manufacture (or flag) */
+	int		year;		/* Year of Manufacture or Model Year */
+
+	sun_edid_vendor(edid_base, string_buf, &product_code, &serial_num);
+	printf("\t  ID Manufacturer Name: %s\n", string_buf);
+	printf("\t  ID Product Code:      %u\n", product_code);
+	printf("\t  ID Serial Number:     %u\n", serial_num);
+
+	sun_edid_mdate(edid_base, &week, &year);
+	if ((week >= 1) && (week <= 54)) {
+		printf("\t  Week of Manufacture:  %d\n", week);
+	} else {
+		printf("\t  Week Flag:            0x%02X\n", week);
+	}
+	if (week == 0xFF) {
+		printf("\t  Model Year:           %d\n", year);
+	} else {
+		printf("\t  Year of Manufacture:  %d\n", year);
+	}
+
+}	/* fbc_predid_vendor() */
+
+
+/*
+ * fbc_predid_version()
+ *
+ *    Decode and display the EDID Structure and Revision from an EDID
+ *    Base block:
+ *	* ID Manufacturer
+ *	* ID Product Code
+ *	* ID Serial Number (Zero = Not used)
+ *      * Week of Manufacture (0x00 = Not used, 1..54 = Week,
+ *                             0xFF = Model year flag (EDID 1.4))
+ *      * Year of Manufacture or Model Year
+ */
+
+static
+void
+fbc_predid_version(
+	const uint8_t	edid_base[],	/* EDID Base block */
+	unsigned int	start_addr,	/* Starting byte address (0x12) */
+	unsigned int	end_addr)	/* Ending   byte address (0x13) */
+{
+
+	printf("\t  EDID Version:         %u.%u\n",
+		edid_base[0x12],	/* EDID version byte */
+		edid_base[0x13]);	/* EDID revision byte */
+
+}	/* fbc_predid_version() */
+
+
+/*
+ * fbc_predid_disp_params()
+ *
+ *    Decode and display the Basic Display Parameters & Features section
+ *    of an EDID Base block:
+ *	* Video Input Definition
+ *	* Horizontal & Vertical Screen Size or Aspect Ratio
+ *	* Vertical Screen Size or Aspect Ratio
+ *      * Display Transfer Characteristic (Gamma)
+ *      * Feature Support
+ */
+
+static
+void
+fbc_predid_disp_params(
+	const uint8_t	edid_base[],	/* EDID Base block */
+	unsigned int	start_addr,	/* Starting byte address (0x14) */
+	unsigned int	end_addr)	/* Ending   byte address (0x18) */
+{
+	float		aspect;		/* Aspect ratio, else zero */
+	sun_edid_feature_t feature;	/* Feature Support info */
+	float		gamma;		/* Gamma value, else zero */
+	int		horizontal;	/* Horizontal screen size (cm), etc. */
+	int		vertical;	/* Vertical screen size (cm), etc. */
+	sun_edid_viddef_t video_def;	/* Video Input Definition */
+
+	/*
+	 * Video Input Definition
+	 */
+	sun_edid_video_input(edid_base, &video_def);
+
+	if (!video_def.digital) {
+		/*
+		 * Input is an Analog Video Signal Interface
+		 */
+		printf("\t  Signal Level Std (Video+Sync=Total): "
+			" %5.3f + %5.3f = %5.3f\n",
+			video_def.alg.video,
+			video_def.alg.sync,
+			video_def.alg.video + video_def.alg.sync);
+		printf("\t  Video Setup: %s\n",
+			(video_def.alg.black2black) ?
+				"Blank-to-Black setup or pedestal" :
+				"Blank Level = Black Level");
+		printf("\t  Separate Sync H & V Signals:          %s\n",
+			(video_def.alg.sync_separate) ?
+				fbc_Supported : fbc_Not_supported);
+		printf("\t  Composite Sync Signal on Horizontal:  %s\n",
+			(video_def.alg.sync_composite) ?
+				fbc_Supported : fbc_Not_supported);
+		printf("\t  Composite Sync Signal on Green Video: %s\n",
+			(video_def.alg.sync_green) ?
+				fbc_Supported : fbc_Not_supported);
+		printf("\t  Serration on the Vertical Sync:       %s\n",
+			(video_def.alg.serration) ?
+				fbc_Supported : fbc_Not_supported);
+	} else {
+		const char *dvi_std[] = {
+			"Not defined",
+			"DVI",
+			"HDMI-a",
+			"HDMI-b",
+			"MDDI",
+			"DisplayPort"
+		};
+
+		/*
+		 * Input is a Digital Video Signal Interface
+		 */
+		printf("\t  Color Bit Depth:  ");
+		if (video_def.dig.color_depth == 0) {
+			printf("Undefined\n");
+		} else
+		if (video_def.dig.color_depth >= 0) {
+			printf("%u\n", video_def.dig.color_depth);
+		} else {
+			printf("Reserved\n");
+		}
+
+		printf("\t  Digital Video Interface Standard: %s\n",
+			(video_def.dig.vid_standard <= 5) ?
+				dvi_std[video_def.dig.vid_standard] :
+				"Reserved");
+	}
+
+	/*
+	 * Horizontal & Vertical Screen Size or Aspect Ratio
+	 *
+	 *    The returned aspect ratio value (introduced in EDID 1.4)
+	 *    is only valid iff positive.  Aspect ratios are rounded to
+	 *    the hundredth decimal place.
+	 */
+	sun_edid_screen_size(edid_base, &horizontal, &vertical, &aspect);
+	if ((horizontal != 0) && (vertical != 0)) {
+		printf("\t  Screen Size (HxV):    %dx%d cm\n",
+			horizontal, vertical);
+	} else
+	if (aspect > 0.0) {
+		if (horizontal != 0) {
+			printf(FBC_PR_INDENT
+				"\t  Aspect ratio (Landscape): %4.2f:1\n",
+				aspect);
+		} else {
+			printf("\t  Aspect ratio (Portrait): %4.2f:1\n",
+				aspect);
+		}
+	}
+
+	/*
+	 * Display Transfer Characteristic (Gamma)
+	 */
+	sun_edid_gamma(edid_base, &gamma);
+	printf("\t  Gamma:                ");
+	if (gamma > 0.0) {
+		printf("%4.2f\n", gamma);
+	} else {
+		printf("Undefined\n");
+	}
+
+	/*
+	 * Feature Support
+	 */
+	sun_edid_feature_support(edid_base, &feature);
+
+	printf("\t  Standby Mode:         %s\n",
+		feature.standby ? fbc_Supported : fbc_Not_supported);
+	printf("\t  Suspend Mode:         %s\n",
+		feature.suspend ? fbc_Supported : fbc_Not_supported);
+	printf("\t  Active Off:           %s\n",
+		feature.active_off ? fbc_Supported : fbc_Not_supported);
+
+	if (!feature.digital) {
+		const char *color_type[4] = {
+			"Monochrome or Grayscale",
+			"RGB color",
+			"Non-RGB color",
+			"Undefined"
+		};
+
+		printf("\t  Display Color Type:   %s\n",
+			color_type[feature.color_info]);
+	} else {
+		const char *color_fmts[4] = {
+			"RGB 4:4:4",
+			"RGB 4:4:4 & YCrCb 4:4:4",
+			"RGB 4:4:4 & YCrCb 4:2:2",
+			"RGB 4:4:4 & YCrCb 4:4:4 & YCrCb 4:2:2"
+		};
+
+		printf("\t  Color Encoding Format(s): %s\n",
+			color_fmts[feature.color_info]);
+	}
+
+	printf("\t  sRGB Standard is default color space: %s\n",
+		feature.srgb_std ? fbc_Yes : fbc_No);
+	printf("\t  Preferred Timing Mode inclusions:     %s\n",
+		feature.ptm_incl ? fbc_Yes : fbc_No);
+	printf("\t  Display is continuous frequency:      %s\n",
+		feature.cont_freq ? fbc_Yes : fbc_No);
+
+}	/* fbc_predid_disp_params() */
+
+
+/*
+ * fbc_predid_color_chars()
+ *
+ *    Decode and display the Color Characteristics section of an EDID
+ *    Base block.
+ */
+
+static
+void
+fbc_predid_color_chars(
+	const uint8_t	edid_base[],	/* EDID Base block */
+	unsigned int	start_addr,	/* Starting byte address (0x19) */
+	unsigned int	end_addr)	/* Ending   byte address (0x22) */
+{
+	sun_edid_colorchrs_t color_chars; /* Color Characteristics */
+
+	sun_edid_color_chars(edid_base, &color_chars);
+	printf("\t  Red   x,y:  %9.7f  %9.7f\n",
+		color_chars.red_x, color_chars.red_y);
+	printf("\t  Green x,y:  %9.7f  %9.7f\n",
+		color_chars.green_x, color_chars.green_y);
+	printf("\t  Blue  x,y:  %9.7f  %9.7f\n",
+		color_chars.blue_x, color_chars.blue_y);
+	printf("\t  White x,y:  %9.7f  %9.7f\n",
+		color_chars.blue_x, color_chars.blue_y);
+
+}	/* fbc_predid_color_chars() */
+
+
+/*
+ * fbc_predid_est_timings()
+ *
+ *    Decode and display the sense of an Established Timings bit array.
+ */
+
+static
+void
+fbc_predid_est_timings(
+	const uint8_t	edid_base[],	/* EDID Base block */
+	unsigned int	start_addr,	/* Starting byte address */
+	unsigned int	end_addr)	/* Ending   byte address */
+{
+	int		bit_off;	/* Established Timings bit offset */
+	int		frequency;	/* Vertical frequency */
+	int		height;		/* Vertical addressable lines */
+	int		width;		/* Horizontal addressable pixels */
+
+	for (bit_off = 0;
+	    bit_off < (end_addr - start_addr + 1) * 8;
+	    bit_off += 1) {
+		if (sun_edid_etiming(edid_base, start_addr, bit_off,
+					&width, &height, &frequency) == 1) {
+			printf("\t  %2d:  %4d x %4d @ %3d\n",
+			       bit_off, width, height, frequency);
+		}
+	}
+
+}	/* fbc_predid_est_timings() */
+
+
+/*
+ * fbc_predid_std_timing()
+ *
+ *    Decode and display a Standard Timing Descriptor.
+ */
+
+void
+fbc_predid_std_timings(
+	const uint8_t	edid_block[],	/* EDID data block */
+	unsigned int	start_addr,	/* Starting byte address */
+	unsigned int	end_addr)	/* Ending   byte address */
+{
+	int		addr;		/* Byte address within EDID block */
+	int		frequency;	/* Vertical frequency */
+	int		height;		/* Vertical addressable lines */
+	int		index;		/* Index into Std Timing byte pairs */
+	int		width;		/* Horizontal addressable pixels */
+
+	index = 0;
+	for (addr = start_addr; addr <= end_addr; addr += 2) {
+		if (sun_edid_stiming(edid_block, addr,
+					&width, &height, &frequency) == 0) {
+			printf("\t  %2d:  %4d x %4d @ %3d\n",
+			       index, width, height, frequency);
+		}
+		index += 1;
+	}
+
+}	/* fbc_predid_std_timings() */
+
+
+/*
+ * fbc_predid_det_timing()
+ *
+ *    Decode and display a Detailed Timing Descriptor.
+ */
+
+void
+fbc_predid_det_timing(
+	const uint8_t	edid_block[],	/* EDID data block */
+	unsigned int	start_addr,	/* Starting byte address */
+	unsigned int	end_addr)	/* Ending   byte address */
+{
+	sun_edid_dtiming_t dt;		/* Detailed Timing info */
+
+	if (sun_edid_dtiming(edid_block, start_addr, &dt) == 0) {
+		/*
+		 * Detailed Timing Definition -- Part 1
+		 */
+		printf("\t  Pixel Clock:              %ld kHz\n", dt.pixclock);
+		printf("\t  H Addressable Video:      %d\n", dt.hactive);
+		printf("\t  Horizontal Blanking:      %d\n", dt.hblanking);
+		printf("\t  V Addressable Video:      %d\n", dt.vactive);
+		printf("\t  Vertical Blanking:        %d\n", dt.vblanking);
+		printf("\t  Horiz Front Porch:        %d\n", dt.hsyncOffset);
+		printf("\t  H Sync Pulse Width:       %d\n", dt.hsyncWidth);
+		printf("\t  Vertical Front Porch:     %d\n", dt.vsyncOffset);
+		printf("\t  V Sync Pulse Width:       %d\n", dt.vsyncWidth);
+/*???*/		if (((dt.hsize == 16) && (dt.vsize == 9)) ||
+/*???*/		    ((dt.hsize ==  4) && (dt.vsize == 3))) {
+			/* Note 18 for Table 3.21 */
+			printf("\t  Image Aspect Ratio:       %d:%d\n",
+				dt.hsize, dt.vsize);
+		} else {
+			printf("\t  H Addr Video Image:       %d mm\n",
+				dt.hsize);
+			printf("\t  V Addr Video Image:       %d mm\n",
+				dt.vsize);
+		}
+		printf("\t  Left/Rt Horiz Border:     %d\n", dt.hborder);
+		printf("\t  Top/Bot Vert Border:      %d\n", dt.vborder);
+
+		/*
+		 * Detailed Timing Definition -- Part 2 (Flags)
+		 */
+		printf("\t  Signal Interface Type:    %s\n",
+			(dt.flags & 0x80) ? "Interlaced" : "Non-Interlaced");
+		{
+			const char *stereo_support[8] = {
+			    "Normal Display - No Stereo",
+			    "Normal Display - No Stereo",
+			    "Field sequential, right when sync = 1",
+			    "2-way interleaved, right on even lines",
+			    "Field sequential, left when sync = 1",
+			    "2-way interleaved, left on even lines",
+			    "4-way interleaved stereo",
+			    "Side-by-Side interleaved stereo"
+			};
+			printf("\t  Stereo Viewing Support:   %s\n",
+				stereo_support[((dt.flags & 0x60) >> 4)
+						| (dt.flags & 0x01)]);
+		}
+		if (!(dt.flags & 0x10)) {
+			printf("\t  Analog Sync Signal Definitions:\n");
+			printf("\t\tBipolar Analog Composite Sync:   %s\n",
+				FBC_YES_NO(dt.flags, 0x08));
+			printf("\t\tSerrations:                      %s\n",
+				FBC_YES_NO(dt.flags, 0x04));
+			printf("\t\tSync On:                         %s\n",
+				(dt.flags & 0x02) ? "RGB" : "Green");
+		} else {
+			printf("\t  Digital Sync Signal Definitions:\n");
+			if (!(dt.flags & 0x08)) {
+				printf("\t      Digital Composite Sync:\n");
+				printf("\t\t  Serrations:       %s\n",
+					FBC_YES_NO(dt.flags, 0x080));
+			} else {
+				printf("\t      Digital Separate Sync:\n");
+				printf("\t\t  Vertical Sync:    %s\n",
+					(dt.flags & 0x080)
+						? "Positive" : "Negative");
+			}
+			printf("\t      Horizontal Sync:      %s\n",
+				(dt.flags & 0x080) ? "Positive" : "Negative");
+		}
+	}
+
+}	/* fbc_predid_det_timing() */
+
+
+static
+void
+fbc_predid_range_limits(
+	const uint8_t	*edid_data,	/* Display Descriptor bytes */
+	sun_edid_range_lim_t *range_limits) /* Display Range Limits */
+{
+
+	printf("\t  Display Range Limits\n");
+	printf("\t    Vertical Rate:       %u - %u Hz\n",
+		range_limits->vert_min,
+		range_limits->vert_max);
+	printf("\t    Horizontal Rate:     %u - %u kHz\n",
+		range_limits->horiz_min,
+		range_limits->horiz_max);
+	printf("\t    Maximum Pixel Clock: %u MHz\n",
+		range_limits->pixclock_max);
+
+	switch (edid_data[10]) {
+	case 0x00:
+		/* Note that this bit must be set: (edid_data[0x18] & 0x01) */
+		printf("\t    Default GTF supported\n");
+		break;
+	case 0x01:
+		printf("\t    Range Limits only\n");
+		break;
+	case 0x02:	/* Generalized Timing Formula (deprecated) */
+		/* Note that this bit must be set: (edid_data[0x18] & 0x01) */
+		printf("\t    GTF Secondary Curve\n");
+		printf(
+		"\t\tStart break frequency for secondary curve:  %u kHz\n",
+			range_limits->gtf_start_break);
+		printf("\t\tC:  %u\n", range_limits->gtf_C);
+		printf("\t\tM:  %u\n", range_limits->gtf_M);
+		printf("\t\tK:  %u\n", range_limits->gtf_K);
+		printf("\t\tJ:  %u\n", range_limits->gtf_J);
+		break;
+	case 0x04:
+		/* Note that this bit must be set: (edid_data[0x18] & 0x01) */
+		printf("\t    CVT Support Information\n");
+		printf("\t\tCVT Standard Version:  %u.%u\n",
+			range_limits->cvt_version >> 4,
+			range_limits->cvt_version & 0x0F);
+		printf("\t\tMaximum Pixel Clock:   %u.%02u MHz\n",
+			range_limits->cvt_pixclock_max >> 2,
+			(range_limits->cvt_pixclock_max & 0x03) * 25);
+		printf("\t\tMaximum Active Pixels per Line: ");
+		if (range_limits->cvt_hactive_max == 0) {
+			printf("No limit\n");
+		} else {
+			printf("%u\n", range_limits->cvt_hactive_max);
+		}
+		{
+			const char *aspect_ratio[] = {
+			    "4:3",
+			    "16:9",
+			    "16:10",
+			    "5:4",
+			    "15:9",
+			    "Reserved",
+			    "Reserved",
+			    "Reserved",
+			    NULL
+			};
+			int bit_off;
+			char *comma;
+
+			printf("\t\tSupported Aspect Ratios: ");
+			comma = "";
+			for (bit_off = 0;
+			    aspect_ratio[bit_off] != NULL;
+			    bit_off += 1) {
+				if (sun_edid_bit_set(
+						&edid_data[14], bit_off)) {
+					printf("%s%s",
+						comma,
+						aspect_ratio[bit_off]);
+						comma = ", ";
+				}
+			}
+			printf("\n");
+			printf("\t\tPreferred Aspect Ratio:  %s\n",
+				aspect_ratio[edid_data[15] >> 5]);
+		}
+		printf("\t\tStandard CVT Blanking:   %s\n",
+		       FBC_YES_NO(edid_data[15], 0x08));
+		printf("\t\tReduced CVT Blanking:    %s\n",
+		       FBC_YES_NO(edid_data[15], 0x10));
+		{
+			const char *display_scaling[] = {
+			    "Horizontal Shrink",
+			    "Horizontal Stretch",
+			    "Vertical Shrink",
+			    "Vertical Stretch",
+			    NULL
+			};
+			int bit_off;
+
+			printf("\t\tSupported Display Scaling:\n");
+			for (bit_off = 0;
+			    display_scaling[bit_off] != NULL;
+			    bit_off += 1) {
+				if (sun_edid_bit_set(
+						&edid_data[16], bit_off)) {
+					printf("\t\t    %s\n",
+						display_scaling[bit_off]);
+				}
+			}
+		}
+		printf("\t\tPreferred Refresh Rate: %u Hz\n", edid_data[17]);
+		break;
+	}
+
+}	/* fbc_predid_range_limits() */
+
+
+/*
+ * fbc_predid_18_byte_data()
+ *
+ *    Decode and display an 18-Byte Data Block.
+ */
+
+static
+void
+fbc_predid_18_byte_data(
+	const uint8_t	edid_base[],	/* EDID Base block */
+	unsigned int	start_addr,	/* Starting byte address */
+	unsigned int	end_addr)	/* Ending   byte address */
+{
+
+	/*
+	 * Determine what kind of 18-Byte Data Block this is
+	 */
+	if ((edid_base[start_addr+0] != 0) || (edid_base[start_addr+1] != 0)) {
+		/*
+		 * Display the Detailed Timing Descriptor
+		 */
+		fbc_predid_det_timing(edid_base, start_addr, end_addr);
+	} else
+	/* if (edid_base[start_addr+2] == 0) */ {	/* Reserved */
+		char	string_buf[14];	/* String from Display Descriptor */
+		uint8_t	tag;		/* Display Descriptor tag number */
+
+		/*
+		 * Display the Display Descriptor
+		 *
+		 *    Display Descriptor tag numbers are (as of EDID 1.4):
+		 *      0xFF  Display Product Serial Number
+		 *      0xFE  Alphanumeric Data String (ASCII)
+		 *      0xFD  Display Range Limits
+		 *      0xFC  Display Product Name
+		 *      0xFB  Color Point Data
+		 *      0xFA  Standard Timing Identifications
+		 *      0xF9  Display Color Management (DCM) Data
+		 *      0xF8  CVT 3 Byte Timing Codes
+		 *      0xF7  Established Timings III
+		 *      0x11..0xF6  Reserved
+		 *      0x10  Dummy Descriptor
+		 *      0x00..0x0F  Manufacturer Specified Display Descriptors
+		 */
+		tag = edid_base[start_addr+3];
+		switch (tag) {
+		case 0xFF:
+			sun_edid_descriptor_string(&edid_base[start_addr],
+						    string_buf);
+			printf("\t  Display Product Serial Number: %s\n",
+				string_buf);
+			break;
+		case 0xFE:
+			sun_edid_descriptor_string(&edid_base[start_addr],
+						    string_buf);
+			printf("\t  Alphanumeric Data String: %s\n",
+				string_buf);
+			break;
+		case 0xFD:
+			{
+				sun_edid_range_lim_t range_limits;
+
+				/* Display Range Limits */
+				sun_edid_range_limits(&edid_base[start_addr],
+							&range_limits);
+				fbc_predid_range_limits(&edid_base[start_addr],
+							&range_limits);
+			}
+			break;
+		case 0xFC:
+			sun_edid_descriptor_string(&edid_base[start_addr],
+						    string_buf);
+			printf("\t  Display Product Name: %s\n",
+				string_buf);
+			break;
+		case 0xFB:
+			printf("\t  Color Point Data\n");
+			break;
+		case 0xFA:
+			printf("\t  Standard Timing Identifications\n");
+			fbc_predid_std_timings(edid_base,
+						start_addr+5, start_addr+16);
+			break;
+		case 0xF9:
+			printf("\t  Display Color Management (DCM) Data\n");
+			break;
+		case 0xF8:
+			printf("\t  CVT 3 Byte Timing Codes\n");
+			break;
+		case 0xF7:
+			printf("\t  Established Timings III\n");
+			fbc_predid_est_timings(edid_base,
+						start_addr+6, start_addr+11);
+			break;
+		case 0x10:
+			printf("\t  Dummy Descriptor\n");
+			break;
+		default:
+			if ((tag >= 0x11) && (tag <= 0xF6)) {
+				printf(
+		       "\t  Reserved Display Descriptor (tag = 0x%02X)\n",
+					tag);
+				break;
+			}
+			if (tag <= 0x0F) {
+				printf(
+	"\t  Manufacturer Specified Display Descriptor (tag = 0x%02X)\n",
+					tag);
+				break;
+			}
+			break;
+		}
+	}
+
+}	/* fbc_predid_18_byte_data() */
+
+
+/*
+ * fbc_predid_ext_blk_cnt()
+ *
+ *    Display the Extension Block Count N of an EDID Base block.
+ */
+
+static
+void
+fbc_predid_ext_blk_cnt(
+	const uint8_t	edid_block[],	/* EDID data block */
+	unsigned int	start_addr,	/* Starting byte address */
+	unsigned int	end_addr)	/* Ending   byte address */
+{
+
+	printf("\t  Extension blocks: %u\n", edid_block[0x7E]);
+
+}	/* fbc_predid_ext_blk_cnt() */
+
+
+/*
+ * fbc_predid_checksum()
+ *
+ *    Display the checksum byte of an EDID data block and complain when
+ *    it's not correct.
+ */
+
+static
+void
+fbc_predid_checksum(
+	const uint8_t	edid_block[],	/* EDID data block */
+	unsigned int	start_addr,	/* Starting byte address */
+	unsigned int	end_addr)	/* Ending   byte address */
+{
+	uint8_t		sum;		/* 1-byte sum of all 128 bytes */
+
+	printf("\t  Checksum: 0x%02X\n", edid_block[0x7F]);
+	sum = sun_edid_checksum(edid_block);
+	if (sum != 0) {
+		printf(
+		    "\t    Sum of bytes (0x%02X) in EDID block is non-zero\n",
+		    sum);
+	}
+
+}	/* fbc_predid_checksum() */
+
+
+/*
+ * fbc_predid_ext_revision()
+ *
+ *    EDID Extension Block revision number.
+ */
+
+static
+void
+fbc_predid_ext_revision(
+	const uint8_t	edid_block[],	/* EDID Extension Block */
+	unsigned int	start_addr,	/* Starting byte address (0x01) */
+	unsigned int	end_addr)	/* Ending   byte address (0x01) */
+{
+
+	printf("\t  Revision: %u\n", edid_block[0x01]);
+
+}	/* fbc_predid_ext_revision() */
+
+
+/* Base Block common strings (referenced at least twice) */
+static const char bb_base_block[]	= "EDID Base Block";
+static const char bb_header[]		= "Header";
+static const char bb_vendor_prod_id[]	= "Vendor & Product Identification";
+static const char bb_version_revision[]	= "EDID Structure Version & Revision";
+static const char bb_disp_params[]     = "Basic Display Parameters & Features";
+static const char bb_color_chars[]	= "Color Characteristics";
+static const char bb_est_timings[]	= "Established Timings";
+static const char bb_std_timings[]	= "Standard Timings";
+static const char bb_det_timings[]	= "Detailed Timing Blocks";
+static const char bb_18_byte_data_blks[] = "18-Byte Data Blocks";
+static const char bb_block_1[]		= "  Block #1";
+static const char bb_block_2[]		= "  Block #2";
+static const char bb_block_3[]		= "  Block #3";
+static const char bb_block_4[]		= "  Block #4";
+static const char bb_det_timing_2_etc[]	=
+			"  Detailed Timing #2 or Display Descriptor";
+static const char bb_det_timing_3_etc[]	=
+			"  Detailed Timing #3 or Display Descriptor";
+static const char bb_det_timing_4_etc[]	=
+			"  Detailed Timing #4 or Display Descriptor";
+static const char bb_ext_blk_cnt[]	= "Extension Block Count N";
+static const char bb_checksum[]		= "Checksum C";
+
+
+/* Base Block format, EDID 1.0 */
+static const fbc_edid_fmt_t edid_1_0_base_fmt[] = {
+	{ NO_DATA, NO_DATA, "EDID 1.0 Base Block", NULL			},
+	{ 0x00, 0x07, bb_header,		NULL			},
+	{ 0x08, 0x11, bb_vendor_prod_id,	&fbc_predid_vendor	},
+	{ 0x12, 0x13, bb_version_revision,	&fbc_predid_version	},
+	{ 0x14, 0x18, bb_disp_params,		&fbc_predid_disp_params	},
+	{ 0x19, 0x22, bb_color_chars,		&fbc_predid_color_chars	},
+	{ 0x23, 0x25, bb_est_timings,		&fbc_predid_est_timings	},
+	{ 0x26, 0x35, bb_std_timings,		&fbc_predid_std_timings	},
+	{ NO_DATA, NO_DATA, bb_det_timings,	NULL			},
+	{ 0x36, 0x47, "    Block 1",		&fbc_predid_det_timing	},
+	{ 0x48, 0x59, "    Block 2",		&fbc_predid_det_timing	},
+	{ 0x5A, 0x6B, "    Block 3",		&fbc_predid_det_timing	},
+	{ 0x6C, 0x7D, "    Block 4",		&fbc_predid_det_timing	},
+	{ 0x7E, 0x7E, bb_ext_blk_cnt,		&fbc_predid_ext_blk_cnt	},
+	{ 0x7F, 0x7F, bb_checksum,		&fbc_predid_checksum	},
+	{ END_MARKER, END_MARKER, NULL,		NULL			}
+};
+
+/* Base Block format, EDID 1.1 & 1.2 */
+static const fbc_edid_fmt_t edid_1_1_base_fmt[] = {
+	{ NO_DATA, NO_DATA, bb_base_block,	NULL			},
+	{ 0x00, 0x07, bb_header,		NULL			},
+	{ 0x08, 0x11, bb_vendor_prod_id,	&fbc_predid_vendor	},
+	{ 0x12, 0x13, bb_version_revision,	&fbc_predid_version	},
+	{ 0x14, 0x18, bb_disp_params,		&fbc_predid_disp_params	},
+	{ 0x19, 0x22, bb_color_chars,		&fbc_predid_color_chars	},
+	{ 0x23, 0x25, bb_est_timings,		&fbc_predid_est_timings	},
+	{ 0x26, 0x35, bb_std_timings,		&fbc_predid_std_timings	},
+	{ NO_DATA, NO_DATA, bb_18_byte_data_blks, NULL			},
+	{ 0x36, 0x47, "  Detailed Timing #1 or Display Descriptor",
+						&fbc_predid_18_byte_data },
+	{ 0x48, 0x59,    bb_det_timing_2_etc,	&fbc_predid_18_byte_data },
+	{ 0x5A, 0x6B,    bb_det_timing_3_etc,	&fbc_predid_18_byte_data },
+	{ 0x6C, 0x7D,    bb_det_timing_4_etc,	&fbc_predid_18_byte_data },
+	{ 0x7E, 0x7E, bb_ext_blk_cnt,		&fbc_predid_ext_blk_cnt	},
+	{ 0x7F, 0x7F, bb_checksum,		&fbc_predid_checksum	},
+	{ END_MARKER, END_MARKER, NULL,		NULL			}
+};
+
+/* Base Block format, EDID 1.3 & 1.4 */
+static const fbc_edid_fmt_t edid_1_3_base_fmt[] = {
+	{ NO_DATA, NO_DATA, bb_base_block,	NULL			},
+	{ 0x00, 0x07, bb_header,		NULL			},
+	{ 0x08, 0x11, bb_vendor_prod_id,	&fbc_predid_vendor	},
+	{ 0x12, 0x13, bb_version_revision,	&fbc_predid_version	},
+	{ 0x14, 0x18, bb_disp_params,		&fbc_predid_disp_params	},
+	{ 0x19, 0x22, bb_color_chars,		&fbc_predid_color_chars	},
+	{ 0x23, 0x25, bb_est_timings,		&fbc_predid_est_timings	},
+	{ 0x26, 0x35, bb_std_timings,		&fbc_predid_std_timings	},
+	{ NO_DATA, NO_DATA, bb_18_byte_data_blks, NULL			},
+	{ 0x36, 0x47, "  Preferred Timing Mode", &fbc_predid_18_byte_data },
+	{ 0x48, 0x59,    bb_det_timing_2_etc,	&fbc_predid_18_byte_data },
+	{ 0x5A, 0x6B,    bb_det_timing_3_etc,	&fbc_predid_18_byte_data },
+	{ 0x6C, 0x7D,    bb_det_timing_4_etc,	&fbc_predid_18_byte_data },
+	{ 0x7E, 0x7E, bb_ext_blk_cnt,		&fbc_predid_ext_blk_cnt	},
+	{ 0x7F, 0x7F, bb_checksum,		&fbc_predid_checksum	},
+	{ END_MARKER, END_MARKER, NULL,		NULL			}
+};
+
+
+/* Extension Block common strings (referenced at least twice) */
+static const char ext_block_tag[]	= "Extension Block Tag Number";
+static const char ext_revision[]	= "Revision number";
+static const char ext_data[]		= "Extension Block Data";
+static const char ext_checksum[]	= "Extension Block Checksum";
+static const char ext_map_checksum[]	= "Extension Block Map Checksum";
+
+
+/* CEA-EXT (Tag 0x02): CEA 861 Series Extension Block */
+static const fbc_edid_fmt_t edid_cea_ext_fmt[] = {
+	{ NO_DATA, NO_DATA,
+	  "CEA 861 Series Extension (CEA-EXT) Block", NULL		},
+	{ 0x00, 0x00, ext_block_tag,		NULL			},
+	{ 0x01, 0x01, ext_revision,		&fbc_predid_ext_revision },
+	{ 0x02, 0x02, "Detailed Timing Descriptor Start Address",
+						&fbc_predid_ceaext_layout },
+	{ NO_DATA, NO_DATA, NULL,		&fbc_predid_ceaext_xxx	},
+	{ NO_DATA, NO_DATA, NULL,		&fbc_predid_ceaext_data	},
+	{ 0x7F, 0x7F, ext_checksum,		&fbc_predid_checksum	},
+	{ END_MARKER, END_MARKER, NULL,		NULL			}
+};
+
+
+/* VTB-EXT (Tag 0x10): Video Timing Block Extension Block */
+static const fbc_edid_fmt_t edid_vtb_ext_fmt[] = {
+	{ NO_DATA, NO_DATA,
+	  "Video Timing Block Extension (VTB-EXT) Block", NULL		},
+	{ 0x00, 0x00, ext_block_tag,		NULL			},
+	{ 0x01, 0x01, ext_revision,		&fbc_predid_ext_revision },
+	{ 0x02, 0x04, "VTB Data Structure Layout", &fbc_predid_vtbext_layout },
+	{ NO_DATA, NO_DATA, NULL,		&fbc_predid_vtbext_data },
+	{ 0x7F, 0x7F, ext_checksum,		&fbc_predid_checksum	},
+	{ END_MARKER, END_MARKER, NULL,		NULL			}
+};
+
+
+/* DI-EXT (Tag 0x40): Display Information Extension Block */
+static const fbc_edid_fmt_t edid_di_ext_fmt[] = {
+	{ NO_DATA, NO_DATA,
+		      "Display Information Extension (DI-EXT) Block", NULL },
+	{ 0x00, 0x00, "Block Header; Tag Number", NULL			},
+	{ 0x01, 0x01, ext_revision,		&fbc_predid_ext_revision },
+	{ 0x02, 0x0D, "Digital Interface section",
+					&fbc_predid_diext_display_interface },
+	{ 0x0E, 0x13, "Display Device section",
+					&fbc_predid_diext_display_device },
+	{ 0x14, 0x36, "Display Capabilities & Feature Support Set",
+					&fbc_predid_diext_capabilities	},
+	{ 0x37, 0x47, "Unused Bytes (Reserved)", NULL			},
+	{ 0x48, 0x50, "Audio Support (Reserved)", NULL			},
+	{ 0x51, 0x7E, "Display Transfer Characteristic - Gamma",
+						&fbc_predid_diext_gamma	},
+	{ 0x7F, 0x7F, "Miscellaneous Items; Checksum", &fbc_predid_checksum },
+	{ END_MARKER, END_MARKER, NULL,		NULL			}
+};
+
+
+/* LS-EXT (Tag 0x50): Localized String Extension Block */
+static const fbc_edid_fmt_t edid_ls_ext_fmt[] = {
+	{ NO_DATA, NO_DATA,
+	  "Localized String Extension (LS-EXT) Block", NULL		},
+	{ 0x00, 0x00, ext_block_tag,		NULL			},
+	{ 0x01, 0x01, ext_revision,		&fbc_predid_ext_revision },
+	{ 0x02, 0x7E, ext_data,			NULL			},
+	{ 0x7F, 0x7F, ext_checksum,		&fbc_predid_checksum	},
+	{ END_MARKER, END_MARKER, NULL,		NULL			}
+};
+
+
+/* DPVL-EXT (Tag 0x60): Digital Packet Video Link (DPVL-EXT) Extension */
+static const fbc_edid_fmt_t edid_dpvl_ext_fmt[] = {
+	{ NO_DATA, NO_DATA,
+	  "Digital Packet Video Link Extension (DPVL-EXT) Block", NULL	},
+	{ 0x00, 0x00, ext_block_tag,		NULL			},
+	{ 0x01, 0x01, ext_revision,		&fbc_predid_ext_revision },
+	{ 0x02, 0x7E, ext_data,			NULL			},
+	{ 0x7F, 0x7F, ext_checksum,		&fbc_predid_checksum	},
+	{ END_MARKER, END_MARKER, NULL,		NULL			}
+};
+
+
+/* Extension Block Map 1 format (Tag 0xF0 at Block 1) */
+static const fbc_edid_fmt_t edid_map1_ext_fmt[] = {
+	{ NO_DATA, NO_DATA, "Extension Block Map 1", NULL		},
+	{ 0x00, 0x00, ext_block_tag,		NULL			},
+	{ 0x01, 0x7E,
+	  "Extension Block Tags for Extension Blocks 2 to 127", NULL	},
+	{ 0x7F, 0x7F, ext_map_checksum,		&fbc_predid_checksum	},
+	{ END_MARKER, END_MARKER, NULL,		NULL			}
+};
+
+/* Extension Block Map 2 format (Tag 0xF0 at Block 128) */
+static const fbc_edid_fmt_t edid_map2_ext_fmt[] = {
+	{ NO_DATA, NO_DATA, "Extension Block Map 2", NULL		},
+	{ 0x00, 0x00, ext_block_tag,		NULL			},
+	{ 0x01, 0x7E,
+	  "Extension Block Tags for Extension Blocks 129 to 254", NULL	},
+	{ 0x7F, 0x7F, ext_map_checksum,		&fbc_predid_checksum	},
+	{ END_MARKER, END_MARKER, NULL,		NULL			}
+};
+
+
+/* Extensions defined by the display manufacturer (Tag 0xFF) */
+static const fbc_edid_fmt_t edid_mfg_ext_fmt[] = {
+	{ NO_DATA, NO_DATA,
+	  "Extensions defined by the display manufacturer", NULL	},
+	{ 0x00, 0x00, ext_block_tag,		NULL			},
+	{ 0x01, 0x01, ext_revision,		&fbc_predid_ext_revision },
+	{ 0x02, 0x7E, ext_data,			NULL			},
+	{ 0x7F, 0x7F, ext_checksum,		&fbc_predid_checksum	},
+	{ END_MARKER, END_MARKER, NULL,		NULL			}
+};
+
+
+/* Unknown Extension block (This might be passed to fbc_predid_dump_block()) */
+static const fbc_edid_fmt_t edid_unknown_ext_fmt[] = {
+	{ NO_DATA, NO_DATA, "Extension Block",	NULL			},
+	{ 0x00, 0x00, ext_block_tag,		NULL			},
+	{ 0x01, 0x01, ext_revision,		&fbc_predid_ext_revision },
+	{ 0x02, 0x7E, ext_data,			NULL			},
+	{ 0x7F, 0x7F, ext_checksum,		&fbc_predid_checksum	},
+	{ END_MARKER, END_MARKER, NULL,		NULL			}
+};
+
+
+/* Unknown EDID block  (This won't be passed to fbc_predid_dump_block()) */
+static const fbc_edid_fmt_t edid_unknown_fmt[] = {
+	{ NO_DATA, NO_DATA, "Unknown EDID block", NULL			},
+	{ END_MARKER, END_MARKER, NULL,		NULL			}
+};
+
+
+/*
+ * fbc_predid_dump_block()
+ *
+ *    Display this EDID data block according to the provided format
+ *    descriptors (as from edid_1_3_base_fmt[], etc.).
+ */
+
+static
+void
+fbc_predid_dump_block(
+	const uint8_t	edid_block[],	/* EDID data block */
+	const fbc_edid_fmt_t block_fmt[], /* EDID data block format */
+	int		predid_raw)	/* TRUE => Display raw EDID data */
+{
+	const fbc_edid_fmt_t *blk_fmt;	/* EDID structure format descriptor */
+	int		parsed;		/* TRUE => Parsed data displayed */
+
+	/*
+	 * Repeat for each EDID structure format descriptor
+	 *
+	 *    The EDID data block heading (block_fmt[0].heading) has
+	 *    been displayed already.
+	 */
+	for (blk_fmt = &block_fmt[1];
+	    blk_fmt->start_addr != END_MARKER;
+	    blk_fmt += 1) {
+		/*
+		 * Display a line describing the data that follows
+		 */
+		if (blk_fmt->heading != NULL) {
+			printf("    %s\n", blk_fmt->heading);
+		}
+
+		/*
+		 * If the function exisis, display the EDID data in parsed form
+		 *
+		 *    There typically wouldn't be a parser function for:
+		 *      * Heading text lines
+		 *      * EDID Base block header bytes
+		 *      * Raw, opaque, or enigmatic data bytes
+		 *      * Reserved bytes (zeroes)
+		 *      * etc.
+		 */
+		parsed = (blk_fmt->parsed_fn != NULL);
+		if (parsed) {
+			blk_fmt->parsed_fn(edid_block,
+					    blk_fmt->start_addr,
+					    blk_fmt->end_addr);
+		}
+
+		/*
+		 * Display the EDID data as raw hexadecimal bytes
+		 *
+		 *    Skip this if this fbc_edid_fmt_t descriptor is for
+		 *    a header line, and not for data bytes (NO_DATA).
+		 *
+		 *    Otherwise, display the raw data if either is true:
+		 *      * There is no parsed EDID data display function
+		 *      * The "-predid ... raw ..." option is specified
+		 */
+		if ((blk_fmt->start_addr != NO_DATA) &&
+		    (predid_raw || !parsed)) {
+			fbc_predid_dump_bytes(edid_block,
+						blk_fmt->start_addr,
+						blk_fmt->end_addr);
+		}
+	}
+
+}	/* fbc_predid_dump_block() */
+
+
+/*
+ * fbc_predid()
+ *
+ *    Dump the E-EDID (Enhanced Extended Display Identification Data)
+ *    data blocks.  The contiguous EDID data bytes are pointed to by
+ *    edid_data.  The byte length is specified by edid_length.
+ *
+ *    The output format will be raw hexadecimal (predid_raw) and/or
+ *    human-readable text (predid_parsed).  If only raw data is wanted,
+ *    the hex values will appear in a 16x8 grid.  Parsed output will
+ *    include subheadings, text labels, numeric or textual values, etc.
+ *    If both raw and parsed form are wanted, raw hex for each
+ *    subheading will appear after the parsed output, as an aligned
+ *    fragment of a 16x8 grid.
+ */
+
+void
+fbc_predid(
+	const uint8_t	*edid_data,	/* EDID Base & Extension blocks */
+	size_t		edid_length,	/* EDID data block(s) length */
+	int		predid_raw,	/* TRUE => Display raw EDID data */
+	int		predid_parsed)	/* TRUE => Display parsed EDID data */
+{
+	size_t		block_addr;	/* Byte addr of current data block */
+	const fbc_edid_fmt_t *block_fmt; /* EDID structure format descriptor */
+	const uint8_t	*block_map;	/* Ptr to current Block Map block */
+	int		block_num;	/* EDID data block number */
+	size_t		block_len;	/* EDID data block length */
+	int		edid_version;	/* EDID_v_r */
+	unsigned int	ext_block_tag;	/* Extension Block Tag Number (temp) */
+	uint8_t		tag;		/* Extension Block Tag Number (temp) */
+
+#if defined(FBC_EDID_TEST_DATA)
+#include "fbc_edid_test_data.h"	/* EDID test data */
+#endif
+
+	/*
+	 * Make sure there's at least some EDID data to display
+	 */
+	if ((edid_data == NULL) || (edid_length < 0x80)) {
+		printf(FBC_PR_INDENT
+			"EDID Data: EDID Base block is not available\n");
+		return;
+	}
+
+	/*
+	 * EDID version and revision
+	 */
+	edid_version = EDID_VER_REV(edid_data);
+
+	/*
+	 * Display each EDID data block
+	 */
+	block_num = 0;
+	block_map = NULL;		/* Assume Block Maps aren't used */
+	for (block_addr = 0x00;
+	    block_addr < edid_length;
+	    block_addr += 0x80) {
+		/*
+		 * Figure out what kind of EDID block this might be
+		 */
+		block_fmt = &edid_unknown_fmt[0];
+		block_len = 0x80;
+		if (block_len > edid_length - block_addr) {
+			/*
+			 * Incomplete EDID data block
+			 */
+			block_len = edid_length - block_addr;
+		} else
+		if (block_num == 0) {
+			/*
+			 * EDID Base Block
+			 */
+			block_fmt = &edid_1_0_base_fmt[0];
+			if (edid_version >= EDID_1_1) {
+				block_fmt = &edid_1_1_base_fmt[0];
+			}
+			if (edid_version >= EDID_1_3) {
+				block_fmt = &edid_1_3_base_fmt[0];
+			}
+		} else
+		if (block_num <= 255) {
+			/*
+			 * EDID Extension Block
+			 *
+			 *    There's not much solid documentation on
+			 *    Extension Blocks until the EDID 1.4 spec.
+			 *    The EDID 1.3 spec is kind of runny.
+			 *
+			 *    If block #255 is found to be out of range,
+			 *    retain &edid_unknown_fmt[0] as the value
+			 *    of block_fmt.
+			 */
+			ext_block_tag = 0xFFFF;	/* Unrecognized tag */
+			tag           = edid_data[block_addr + 0x00];
+
+			if (edid_version < EDID_1_3) {
+				block_fmt = &edid_unknown_ext_fmt[0];
+			} else
+			if (edid_version == EDID_1_3) {
+				if (block_num < 255) {
+					block_fmt = &edid_unknown_ext_fmt[0];
+					if ((tag == 0xF0) || (tag == 0xFF)) {
+						ext_block_tag = tag;
+					}
+				}
+			} else
+			if (edid_version >= EDID_1_4) {
+				if ((block_num < 255) || (block_map == NULL)) {
+					ext_block_tag = tag;
+				}
+			}
+
+			switch (ext_block_tag) {
+			default:    /* Bad blk #, bad tag, no documentation */
+				break;
+			case 0x02:  /* CEA-EXT: CEA 861 Series Extension */
+				block_fmt = &edid_cea_ext_fmt[0];
+				break;
+			case 0x10:  /* VTB-EXT: Video Timing Block Ext */
+				block_fmt = &edid_vtb_ext_fmt[0];
+				break;
+			case 0x40:  /* DI-EXT: Display Info Extension */
+				block_fmt = &edid_di_ext_fmt[0];
+				break;
+			case 0x50:  /* LS-EXT: Localized String Extension */
+				block_fmt = &edid_ls_ext_fmt[0];
+				break;
+			case 0x60:  /* DPVL-EXT: Digital Packet Video Link */
+				block_fmt = &edid_dpvl_ext_fmt[0];
+				break;
+			case 0xF0:  /* EXTENSION Block Map 1 or 2 */
+				if (block_num == 1) {
+					block_fmt = &edid_map1_ext_fmt[0];
+					block_map = &edid_data[block_addr];
+				} else
+				if (block_num == 128) {
+					block_fmt = &edid_map2_ext_fmt[0];
+					block_map = &edid_data[block_addr];
+				}
+				/* Reject Block Maps at other locations */
+				break;
+			case 0xFF:  /* EXTENSIONS by display manufacturer */
+				block_fmt = &edid_mfg_ext_fmt[0];
+				break;
+			}
+		}
+
+		/*
+		 * Display the EDID data block
+		 */
+		if (block_num > 0) {
+			putchar('\n');	/* Blank line between EDID blocks */
+		}
+		printf("Block %d: %s\n", block_num, block_fmt->heading);
+		if (!predid_parsed || (block_fmt == edid_unknown_fmt)) {
+			/*
+			 * Display a raw valid or unknown/invalid EDID block
+			 */
+			fbc_predid_dump_bytes(
+				&edid_data[block_addr], 0, block_len-1);
+		} else {
+			/*
+			 * Display a valid EDID block parsed or parsed & raw
+			 */
+			fbc_predid_dump_block(
+				&edid_data[block_addr], block_fmt, predid_raw);
+		}
+
+		block_num += 1;
+	}
+
+}	/* fbc_predid() */
+
+
+/* End of fbc_predid.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_predid.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_predid - Display EDID data
+ */
+
+
+
+#ifndef _FBC_PREDID_H
+#define	_FBC_PREDID_H
+
+
+#include <sys/int_types.h>	/* uint8_t */
+
+
+void fbc_predid_dump_bytes(
+	const uint8_t	edid_data[],	/* EDID Base & Extension blocks */
+	size_t		start_offset,	/* Starting byte offset */
+	size_t		end_offset);	/* Ending   byte offset */
+
+typedef struct {
+	unsigned int	tag;		/* String tag number */
+	const char	*text;		/* String text */
+} fbc_tag_str_t;
+
+const char *
+fbc_predid_tagged_string(
+	unsigned int	tag,		/* String tag number */
+	const fbc_tag_str_t string[],	/* Array of tagged strings */
+	const char *const default_text); /* Default string text */
+
+void fbc_predid_std_timings(
+	const uint8_t	edid_block[],	/* EDID data block */
+	unsigned int	start_addr,	/* Starting byte address */
+	unsigned int	end_addr);	/* Ending   byte address */
+
+void fbc_predid_det_timing(
+	const uint8_t	edid_block[],	/* EDID data block */
+	unsigned int	start_addr,	/* Starting byte address */
+	unsigned int	end_addr);	/* Ending   byte address */
+
+void fbc_predid(
+	const uint8_t	*edid_data,	/* EDID Base & Extension blocks */
+	size_t		edid_length,	/* EDID data block(s) length */
+	int		predid_raw,	/* TRUE => Display raw EDID data */
+	int		predid_parsed);	/* TRUE => Display parsed EDID data */
+
+
+#endif	/* _FBC_PREDID_H */
+
+
+/* End of fbc_predid.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_predid_ceaext.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_predid_ceaext - Display EDID CEA-EXT data
+ */
+
+
+#include <sys/types.h>		/* uint8_t */
+#include <stdio.h>		/* printf() */
+
+#include "fbc_predid.h"		/* Display EDID data */
+#include "fbc_predid_ceaext.h"	/* Display EDID CEA-EXT data */
+
+
+/*
+ * fbc_predid_ceaext_layout()
+ *
+ *    CEA-EXT Data Structure Layout
+ */
+
+void
+fbc_predid_ceaext_layout(
+	const uint8_t	edid_block[],	/* EDID CEA-EXT Extension block */
+	unsigned int	start_addr,	/* Starting byte address (0x02) */
+	unsigned int	end_addr)	/* Ending   byte address (0x04) */
+{
+
+	/*
+	 * CEA 861 Series Extension (CEA-EXT) layout
+	 */
+	printf("\t  Detailed Timing Descriptor offset:  0x%02X\n",
+		edid_block[0x02]);
+
+}	/* fbc_predid_ceaext_layout() */
+
+
+/*
+ * fbc_predid_ceaext_xxx(
+ *
+ *    ??? Need the CEA 861 Series Extension (CEA-EXT) spec in order to
+ *    ??? interpret these bytes.
+ */
+
+void
+fbc_predid_ceaext_xxx(
+	const uint8_t	edid_block[],	/* EDID CEA-EXT Extension block */
+	unsigned int	start_addr,	/* Starting byte address */
+	unsigned int	end_addr)	/* Ending   byte address */
+{
+	unsigned int	e_addr;		/* Ending byte address */
+
+	printf("    CEA 861 Series data\n");
+	e_addr = 0x02 + edid_block[0x02];
+	if (e_addr > 0x7F) {
+		e_addr = 0x7F;
+	}
+	fbc_predid_dump_bytes(edid_block, 0x03, e_addr - 1);
+
+}	/* fbc_predid_ceaext_xxx() */
+
+
+/*
+ * fbc_predid_ceaext_data()
+ *
+ *    CEA 861 Series Extension (CEA-EXT) free format data bytes.
+ */
+
+void
+fbc_predid_ceaext_data(
+	const uint8_t	edid_block[],	/* EDID CEA-EXT Extension block */
+	unsigned int	start_addr,	/* Starting byte address */
+	unsigned int	end_addr)	/* Ending   byte address */
+{
+	unsigned int	e_addr;		/* Ending byte address */
+	unsigned int	i;		/* Detailed Timing Block # */
+	unsigned int	s_addr;		/* Starting byte address */
+
+	/*
+	 * Detailed Timing Descriptors (??? or 18-Byte Data Blocks ???)
+	 *
+	 *    ??? Need the CEA 861 Series Extension (CEA-EXT) spec in
+	 *    ??? order to understand how the Video Image Size bytes can
+	 *    ??? be interpreted as Displayed Image Aspect Ratio bytes.
+	 */
+	printf("    Detailed Timing Descriptors\n");
+	i = 0;
+	for (s_addr = 0x02 + edid_block[0x02]; ; s_addr += 18) {
+		e_addr = s_addr + 18 - 1;
+		if ((e_addr >= 0x7F) ||
+		    ((edid_block[s_addr+0] | edid_block[s_addr+1]) == 0)) {
+			break;
+		}
+		i += 1;
+		printf("      Detailed Timing Block #%u\n", i);
+		fbc_predid_det_timing(edid_block, s_addr, e_addr);
+		fbc_predid_dump_bytes(edid_block, s_addr, e_addr);
+	}
+
+	/*
+	 * Unused Bytes
+	 */
+	printf("    Unused Bytes (Reserved)\n");
+	fbc_predid_dump_bytes(edid_block, s_addr, 0x7F - 1);
+
+}	/* fbc_predid_ceaext_data() */
+
+
+/* End of fbc_predid_ceaext.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_predid_ceaext.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_predid_ceaext - Display EDID CEA-EXT data
+ */
+
+
+#ifndef	FBC_PREDID_CEAEXT_H
+#define	FBC_PREDID_CEAEXT_H
+
+
+#include <sys/types.h>		/* uint8_t */ 
+
+
+void fbc_predid_ceaext_layout(
+	const uint8_t	edid_block[],	/* EDID CEA-EXT Extension block */
+	unsigned int	start_addr,	/* Starting byte address (0x02) */
+	unsigned int	end_addr);	/* Ending   byte address (0x04) */
+
+void fbc_predid_ceaext_xxx(
+	const uint8_t	edid_block[],	/* EDID CEA-EXT Extension block */
+	unsigned int	start_addr,	/* Starting byte address */
+	unsigned int	end_addr);	/* Ending   byte address */
+
+void fbc_predid_ceaext_data(
+	const uint8_t	edid_block[],	/* EDID CEA-EXT Extension block */
+	unsigned int	start_addr,	/* Starting byte address */
+	unsigned int	end_addr);	/* Ending   byte address */
+
+
+#endif	/* FBC_PREDID_CEAEXT_H */
+
+
+/* End of fbc_predid_ceaext.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_predid_diext.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,625 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_predid_diext - Display EDID data DI-EXT data
+ */
+
+
+#include <stdio.h>		/* printf(), putchar() */
+
+#include "sun_edid.h"		/* EDID data parsing */
+
+#include "fbc_predid.h"		/* Display EDID data */
+#include "fbc_predid_diext.h"	/* Display EDID DI-EXT data */
+
+
+/*
+ * Conversions from EDID flag bit value to output text string
+ */
+static const char	*const fbc_No  = "No";
+static const char	*const fbc_Yes = "Yes";
+
+#define	FBC_YES_NO(_byte, _mask) \
+		((_byte) & (_mask)) ? fbc_Yes : fbc_No
+
+static const char	*const fbc_Supported     = "Supported";
+static const char	*const fbc_Not_supported = "Not supported";
+
+#define	FBC_SUPPORTED_NOT(_byte, _mask) \
+		((_byte) & (_mask)) ? fbc_Supported : fbc_Not_supported
+
+
+/*
+ * fbc_predid_diext_display_interface()
+ *
+ *    Display Interface (Monitors with a digital video interface)
+ */
+
+void
+fbc_predid_diext_display_interface(
+	const uint8_t	edid_block[],	/* EDID DI-EXT Extension block */
+	unsigned int	start_addr,	/* Starting byte address (0x02) */
+	unsigned int	end_addr)	/* Ending   byte address (0x0D) */
+{
+
+	/*
+	 * Standard/Specification Supported
+	 */
+	{
+		const fbc_tag_str_t di_std_spec[] = {
+		    { 0x00, "Display has an Analog Video Input"		},
+		    { 0x01, "Display has a Digital Video Input"		},
+		    { 0x02, "Digital Visual Interface (DVI) - Single link" },
+		    { 0x03,
+	"Digital Visual Interface (DVI) - Dual link, High resolution"	},
+		    { 0x04,
+	"Digital Visual Interface (DVI) - Dual link, High color"	},
+		    { 0x05,
+	"Digital Visual Interface (DVI) - For consumer electronics"	},
+		    { 0x06, "Plug & Display (P&D)"			},
+		    { 0x07, "Digital Flat Panel (DFP)"			},
+		    { 0x08, "Open LDI - Single Link"			},
+		    { 0x09, "Open LDI - Dual Link"			},
+		    { 0x0A, "Open LDI - For consumer electronics"	},
+		};
+		printf("\t  Standard/Specification:\n");
+		printf("\t\t%s\n",
+			fbc_predid_tagged_string(
+				edid_block[0x02], di_std_spec, "Reserved"));
+	}
+
+	/*
+	 * Version/Revision Number
+	 */
+	printf("\t  Version/Revision:              ");
+	switch (edid_block[0x03] >> 6) {
+	case 0:
+		printf("Not specified\n");
+		break;
+	case 1:	/* Version/Revision */
+		printf("%d.%d / %d.%d\n",
+			edid_block[0x03] & 0x3F,
+			edid_block[0x04],
+			edid_block[0x05],
+			edid_block[0x06]);
+		break;
+	case 2:	/* ASCII character */
+		printf("%c\n", edid_block[4]);
+		break;
+	case 3:	/* Year, Month, Day */
+		printf("%d/%02d/%02d\n",
+			1990 + edid_block[0x04],
+			edid_block[0x05],
+			edid_block[0x06]);
+		break;
+	}
+
+	/*
+	 * Data Format Description
+	 */
+	printf("\t  Data Enable Signal:            ");
+	if (edid_block[0x07] & 0x80) {
+		printf("Available\n");
+		printf("\t  Data enabled upon:             %s signal\n",
+		       (edid_block[0x07] & 0x40) ? "High" : "Low");
+	} else {
+		printf("Unavailable\n");
+	}
+
+	{
+		const char *const shift_clock[4] = {
+		    "Not specified",
+		    "Rising edge",
+		    "Falling edge",
+		    "Both rising and falling edges"
+		};
+		printf("\t  Shift Clock usage:             %s\n",
+			shift_clock[(edid_block[0x07] >> 4) & 0x03]);
+	}
+
+	printf("\t  HDCP Support:                  %s\n",
+				FBC_YES_NO(edid_block[0x07], 0x08));
+	printf("\t  Double Clocking of Input Data: %s\n",
+				FBC_SUPPORTED_NOT(edid_block[0x07], 0x04));
+	printf("\t  Packetized Digital Video:      %s\n",
+				FBC_SUPPORTED_NOT(edid_block[0x07], 0x02));
+
+	/*
+	 * Data Format Description
+	 */
+	{
+		const fbc_tag_str_t data_format[] = {
+		    { 0x00, "Display has an Analog Video Input"		},
+		    { 0x15, "8-bit Over 8-bit RGB"			},
+		    { 0x19, "12-bit Over 12-bit RGB"			},
+		    { 0x24, "24-Bit MSB-Aligned RGB (Single Link)"	},
+		    { 0x48, "48-Bit MSB-Aligned RGB (Dual Link Hi-Res)"	},
+		    { 0x49, "48-Bit MSB-Aligned RGB (Dual Link Hi-Color)" },
+		    {    0, NULL					}
+		};
+		printf("\t  Digital Interface:  %s\n",
+			fbc_predid_tagged_string(
+				edid_block[0x08], data_format, "Undefined"));
+	}
+
+	/*
+	 * Min & Max Pixel Clock Frequency (PCF) Per Link and Crossover PCF
+	 */
+	{
+		unsigned int frequency;	/* Pixel Clock Frequency */
+
+		printf("\t  Min Pixel Clock Frequency:     ");
+		frequency = edid_block[0x09];
+		if (frequency == 0x00) {
+			printf("Display has an Analog Video Input\n");
+		} else
+		if (frequency == 0xFF) {
+			printf("Reserved\n");
+		} else {
+			printf("%3u MHz\n", frequency);
+		}
+
+		printf("\t  Max Pixel Clock Frequency:     ");
+		frequency = sun_edid_get_le_short(&edid_block[0x0A]);
+		if (frequency == 0x0000) {
+			printf("Display has an Analog Video Input\n");
+		} else
+		if (frequency == 0xFFFF) {
+			printf("Reserved\n");
+		} else {
+			printf("%3u MHz\n", frequency);
+		}
+
+		printf("\t  Crossover Pixel Clock Freq:    ");
+		frequency = sun_edid_get_le_short(&edid_block[0x0C]);
+		if (frequency == 0x0000) {
+			printf("Display has an Analog Video Input\n");
+		} else
+		if (frequency == 0xFFFF) {
+			printf("Single Link (no frequency)\n");
+		} else {
+			printf("%3u MHz\n", frequency);
+		}
+	}
+
+}	/* fbc_predid_diext_display_interface() */
+
+
+/*
+ * fbc_predid_diext_display_device()
+ *
+ *    Display Device (Monitors w/ analog and/or digital interface(s))
+ */
+
+void
+fbc_predid_diext_display_device(
+	const uint8_t	edid_block[],	/* EDID DI-EXT Extension block */
+	unsigned int	start_addr,	/* Starting byte address (0x0E) */
+	unsigned int	end_addr)	/* Ending   byte address (0x13) */
+{
+
+	/*
+	 * Sub-Pixel Layout, Configuration, and Shape
+	 */
+	{
+		const fbc_tag_str_t subpix_layout[] = {
+		    { 0x00, "Not defined"		},
+		    { 0x01, "RGB"			},
+		    { 0x02, "BGR"			},
+		    { 0x03, "Quad pixel (RG/GB)"	},
+		    { 0x04, "Quad pixel (GR/BG)"	},
+		    {    0, NULL			}
+		};
+		printf("\t  Sub-Pixel Layout:           %s\n",
+			fbc_predid_tagged_string(
+				edid_block[0x0E], subpix_layout, "Reserved"));
+	}
+	{
+		const fbc_tag_str_t subpix_config[] = {
+		    { 0x00, "Not defined"			},
+		    { 0x01, "Delta (Tri-ad)"			},
+		    { 0x02, "Stripe"				},
+		    { 0x03, "Stripe Offset"			},
+		    { 0x04, "Quad pixel (4 sub-pixels / pixel)"	},
+		    {    0, NULL				}
+		};
+		printf("\t  Sub-Pixel Configuration:    %s\n",
+			fbc_predid_tagged_string(
+				edid_block[0x0F], subpix_config, "Reserved"));
+	}
+	{
+		const fbc_tag_str_t subpix_shape[] = {
+		    { 0x00, "Not defined"	},
+		    { 0x01, "Round"		},
+		    { 0x02, "Square"		},
+		    { 0x03, "Rectangular"	},
+		    { 0x04, "Oval"		},
+		    { 0x05, "Elliptical"	},
+		    {    0, NULL		}
+		};
+		printf("\t  Sub-Pixel Shape:            %s\n",
+			fbc_predid_tagged_string(
+				edid_block[0x10], subpix_shape, "Reserved"));
+	};
+
+	/*
+	 * Dot/Pixel Pitch
+	 */
+	printf("\t  Horizontal Dot/Pixel Pitch: %u.%02u mm\n",
+		edid_block[0x11] / 100,
+		edid_block[0x11] % 100);
+	printf("\t  Vertical Dot/Pixel Pitch:   %u.%02u mm\n",
+		edid_block[0x12] / 100,
+		edid_block[0x12] % 100);
+
+	/*
+	 * Major Display Device Characteristics
+	 */
+	{
+		const char *const view_direction[4] = {
+		    "Not specified",
+		    "Direct View",
+		    "Reflected View",
+		    "Directed & Reflected View"
+		};
+		const char *const phys_implementation[4] = {
+		    "Not specified",
+		    "Large image device (group viewing)",
+		    "Desktop or personal display",
+		    "Eyepiece type personal display"
+		};
+		printf("\t  Fixed Pixel Format:         %s\n",
+			FBC_YES_NO(edid_block[0x13], 0x80));
+		printf("\t  View Direction:             %s\n",
+		       view_direction[(edid_block[0x13] >> 5) & 0x03]);
+		printf("\t  Transparent Background:     %s\n",
+			FBC_YES_NO(edid_block[0x13], 0x10));
+		printf("\t  Physical Implementation:    %s\n",
+			phys_implementation[(edid_block[0x13] >> 2) & 0x03]);
+		printf("\t  DDC/CI support:             %s\n",
+			FBC_YES_NO(edid_block[0x13], 0x02));
+	};
+
+}	/* fbc_predid_diext_display_device() */
+
+
+/*
+ * fbc_predid_diext_capabilities()
+ *
+ *    Display Capabilities & Feature Support Set (analog and/or digital)
+ */
+
+void
+fbc_predid_diext_capabilities(
+	const uint8_t	edid_block[],	/* EDID DI-EXT Extension block */
+	unsigned int	start_addr,	/* Starting byte address (0x14) */
+	unsigned int	end_addr)	/* Ending   byte address (0x36) */
+{
+	unsigned int	frequency;	/* Frame Rate Conversion frequency */
+
+	/*
+	 * Miscellaneous Display Capabilities
+	 */
+	printf("\t  Legacy Timing Mode support: %s\n",
+				FBC_YES_NO(edid_block[0x14], 0x80));
+	{
+		const fbc_tag_str_t stereo_video[] = {
+		    { 0, "No direct stereo"				},
+		    { 1, "Field seq. stereo via stero sync signal"	},
+		    { 2, "Auto-stereoscopic, column interleave"		},
+		    { 3, "Auto-stereoscopic, line interleave"		},
+		    { 0, NULL						}
+		};
+		printf("\t  Stereo Video:               %s\n",
+			fbc_predid_tagged_string(
+					(edid_block[0x14] >> 4) & 0x07,
+					stereo_video,
+					"Reserved"));
+	}
+	printf("\t  Scaler On Board:            %s\n",
+				FBC_YES_NO(edid_block[0x14], 0x08));
+	printf("\t  Image Centering:            %s\n",
+				FBC_YES_NO(edid_block[0x14], 0x04));
+	printf("\t  Conditional Update:         %s\n",
+				FBC_YES_NO(edid_block[0x14], 0x02));
+	printf("\t  Interlaced Video:           %s\n",
+				FBC_YES_NO(edid_block[0x14], 0x01));
+
+	/*
+	 * Frame Lock and Frame Rate Conversion
+	 */
+	printf("\t  Frame Lock Support:         %s\n",
+				FBC_YES_NO(edid_block[0x15], 0x80));
+	{
+		const char *const frame_rate_cnv[4] = {
+		    "Not supported",
+		    "Vertical converted to single frequency",
+		    "Horizontal converted to single frequency",
+		    "Vert & Horiz converted to single freqs"
+		};
+		printf("\t  Frame Rate Conversion:      %s\n",
+			frame_rate_cnv[(edid_block[0x15] >> 5) & 0x03]);
+	}
+
+	frequency = sun_edid_get_le_short(&edid_block[0x16]);
+	printf("\t  Vertical Frequency:         %u.%02u Hz%s\n",
+		frequency / 100,
+		frequency % 100,
+		(frequency == 0xFFFF) ? " (Reserved)" : "");
+	frequency = sun_edid_get_le_short(&edid_block[0x18]);
+	printf("\t  Horizontal Frequency:       %u.%02u Hz%s\n",
+		frequency / 100,
+		frequency % 100,
+		(frequency == 0xFFFF) ? " (Reserved)" : "");
+
+	/*
+	 * Display/Scan Orientation
+	 */
+	{
+		const char *const display_orientation[4] = {
+		    "Not defined",
+		    "Fixed orientation (doesn't rotate)",
+		    "Rotates (single EDID extension table)",
+		    "Rotates (multiple EDID extension tables)"
+		};
+		printf("\t  Display/Scan Orientation:   %s\n",
+			display_orientation[(edid_block[0x1A] >> 6) & 0x03]);
+	}
+	{
+		const char *const screen_orientation[2] = {
+		    "Landscape",
+		    "Portrait"
+		};
+		printf("\t  Screen Orientation:         %s\n",
+			screen_orientation[(edid_block[0x1A] >> 5) & 0x01]);
+	}
+	{
+		const char *const zero_pixel_loc[4] = {
+		    "Upper left",
+		    "Upper right",
+		    "Lower left",
+		    "Lower right"
+		};
+		printf("\t  Zero Pixel Location:        %s\n",
+			zero_pixel_loc[(edid_block[0x1A] >> 3) & 0x03]);
+	}
+	{
+		const char *const scan_direction[4] = {
+		    "Not defined",
+		    "Fast on Major, Slow on Minor",
+		    "Fast on Minor, Slow on Major",
+		    "Undefined"
+		};
+		printf("\t  Scan Direction:             %s\n",
+			scan_direction[(edid_block[0x1A] >> 1) & 0x03]);
+	}
+	printf("\t  Standalone Projector:       %s\n",
+				FBC_YES_NO(edid_block[0x1A], 0x01));
+
+	/*
+	 * Default Color/Luminescence Coding Description
+	 */
+	{
+		const fbc_tag_str_t def_color_lum[] = {
+		    { 0x00, "Not defined"			},
+		    { 0x01, "BGR (additive color)"		},
+		    { 0x02, "Y/C (S-Video) NTSC"		},
+		    { 0x03, "Y/C (S-Video) PAL"			},
+		    { 0x04, "Y/C (S-Video) SECAM"		},
+		    { 0x05, "YCrCb (4:4:4)"			},
+		    { 0x06, "YCrCb (4:2:2)"			},
+		    { 0x07, "YCrCb (4:2:0)"			},
+		    { 0x08, "YCrCb (Legacy HDTV)"		},
+		    { 0x09, "YPbPr (Legacy HDTV)"		},
+		    { 0x0A, "YCrCb (Modern HDTV)"		},
+		    { 0x0B, "YPbPr (Modern HDTV)"		},
+		    { 0x0C, "Y B-Y R-Y BetaCam (Sony)"		},
+		    { 0x0D, "Y B-Y R-Y M-2 (Matsushita)"	},
+		    { 0x0E, "Monochrome"			},
+		    {    0, NULL				}
+		};
+		printf("\t  Default Color/Luminescence:   %s\n",
+			fbc_predid_tagged_string(
+				edid_block[0x1B], def_color_lum, "Reserved"));
+	}
+
+	/*
+	 * Preferred Color/Luminescence Coding Description
+	 */
+	{
+		const fbc_tag_str_t pref_color_lum[] = {
+		    { 0x00, "Default Color/Lum only"		},
+		    { 0x01, "BGR (additive color)"		},
+		    { 0x02, "Y/C (S-Video) xxxx color"		},
+		    { 0x03, "Yxx (SMPTE 2xxM) Color Diff)"	},
+		    { 0x04, "Monochrome"			},
+		    {    0, NULL				}
+		};
+		printf("\t  Preferred Color/Luminescence: %s\n",
+			fbc_predid_tagged_string(
+				edid_block[0x1C], pref_color_lum, "Reserved"));
+	}
+
+	/*
+	 * Color/Luminescence Decoding Capabilities Description
+	 */
+	{
+		const char *const capabilities[16] = {
+		    "BGR (additive color)",
+		    "Y/C (S-Video) NTSC color",
+		    "Y/C (S-Video) PAL color",
+		    "Y/C (S-Video) SECAM color",
+		    "YCrCb (4:4:4)",
+		    "YCrCb (4:2:2)",
+		    "YCrCb (4:2:0)",
+		    "YCrCb (Legacy HDTV)",
+		    "YpbPr (Legacy HDTV)",
+		    "YCrCb (Modern HDTV)",
+		    "YpbPr (Modern HDTV)",
+		    "Y B-Y R-Y BetaCam (Sony)",
+		    "Y B-Y R-Y M-2 (Matsushita)",
+		    "Monochrome",
+		    "Undefined (Bit 1)",
+		    "Undefined (Bit 0)"
+		};
+		printf("\t  Color/Luminescence Decoding Capabilities:\n");
+		if ((edid_block[0x1D] | edid_block[0x1E]) == 0x00) {
+			printf("\t\tNot defined\n");
+		} else {
+			int bit_off;	/* Bit offset */
+			for (bit_off = 0; bit_off < 16; bit_off += 1) {
+				if (sun_edid_bit_set(
+						&edid_block[0x1D], bit_off)) {
+					printf("\t\t%s\n",
+						capabilities[bit_off]);
+				}
+			}
+		}
+	}
+
+	/*
+	 * Monitor Color Depth
+	 */
+	printf("\t  Dithering:                  %s\n",
+				FBC_YES_NO(edid_block[0x1F], 0x80));
+	{
+		const char *const color[6] = {
+		    "Blue:",
+		    "Green:",
+		    "Red:",
+		    "Cb/Pb:",
+		    "Y:",
+		    "Cr/Pr:"
+		};
+		int	i;
+		printf("\t  Monitor Color Depth:\n");
+		for (i = 0; i < 6; i += 1) {
+			printf("\t\t%-6s %2u %s\n",
+				color[i],
+				edid_block[0x20 + i],
+				(edid_block[0x20 + i] == 0x00)
+					? "- No Color Depth information"
+					: "bits per color");
+		}
+	}
+
+	/*
+	 * Aspect Ratio Conversion Modes
+	 */
+	{
+		const char *const aspect_modes[8] = {
+		    "Full mode",
+		    "Zoom mode",
+		    "Squeeze mode",
+		    "Variable (Expand/Shrink) mode",
+		    "Reserved (Bit 3)",
+		    "Reserved (Bit 2)",
+		    "Reserved (Bit 1)",
+		    "Reserved (Bit 0)"
+		};
+		printf("\t  Aspect Ratio Conversion Modes:\n");
+		if (edid_block[0x26] == 0x00) {
+			printf("\t\tNot supported\n");
+		} else {
+			int bit_off;	/* Bit offset */
+			for (bit_off = 0; bit_off < 8; bit_off += 1) {
+				if (sun_edid_bit_set(
+						&edid_block[0x26], bit_off)) {
+					printf("\t\t%s\n",
+						aspect_modes[bit_off]);
+				}
+			}
+		}
+	}
+
+	/*
+	 * Packetized Digital Video Support Information (reserved)
+	 */
+
+}	/* fbc_predid_diext_capabilities() */
+
+
+/*
+ * fbc_predid_diext_gamma()
+ *
+ *    Display Transfer Characteristic - Gamma (analog and/or digital)
+ */
+
+void
+fbc_predid_diext_gamma(
+	const uint8_t	edid_block[],	/* EDID DI-EXT Extension block */
+	unsigned int	start_addr,	/* Starting byte address (0x51) */
+	unsigned int	end_addr)	/* Ending   byte address (0x7E) */
+{
+	const char *const curve_white[] =
+			{ "White", NULL };
+	const char *const curve_color[] =
+			{ "Color 0", "Color 1", "Color 2", NULL };
+	unsigned int	addr;		/* Curve byte address */
+	const char *const *curve_name;	/* White or color curve name */
+	unsigned int	entries;	/* Number of Luminance Entries */
+	int		i;		/* Loop counter / entry number */
+	unsigned int	max_entries;	/* Max number of Luminance Entries */
+
+	printf("\t  Combined or Separate:  ");
+	curve_name  = &curve_white[0];
+	max_entries = 45;
+	switch (edid_block[0x51] >> 6) {
+	case 0:
+		printf("Not defined\n");
+		return;
+	case 1:
+		printf("Single White Curve\n");
+		break;
+	case 2:
+		printf("Three Color Curves\n");
+		curve_name  = &curve_color[0];
+		max_entries = 15;
+		break;
+	case 3:
+		printf("Reserved\n");
+		return;
+	}
+
+	entries = edid_block[0x51] & 0x3F;
+	printf("\t  Luminance Entries:     %u\n", entries);
+	if (entries > max_entries) {
+		entries = max_entries;	/* Avoid using invalid EDID data */
+	}
+
+	addr = 0x52;
+	for (; *curve_name != NULL; curve_name += 1) {
+		printf("\t  %s Curve:", *curve_name);
+		for (i = 0; i < entries; i += 1) {
+			printf(((i % 16) == 0) ? "\n\t\t" : " ");
+			printf("%02X", edid_block[addr + i]);
+		}
+		putchar('\n');
+		addr += 15;		/* For next color curve */
+	}
+
+}	/* fbc_predid_diext_gamma() */
+
+
+/* End of fbc_predid_diext.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_predid_diext.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_predid_diext - Display EDID data DI-EXT data
+ */
+
+
+
+#ifndef FBC_PREDID_DIEXT_H
+#define	FBC_PREDID_DIEXT_H
+
+
+#include <sys/types.h>		/* uint8_t, uint16_t, uint32_t */ 
+
+
+void fbc_predid_diext_display_interface(
+	const uint8_t	edid_block[],	/* EDID DI-EXT Extension block */
+	unsigned int	start_addr,	/* Starting byte address (0x02) */
+	unsigned int	end_addr);	/* Ending   byte address (0x0D) */
+
+void fbc_predid_diext_display_device(
+	const uint8_t	edid_block[],	/* EDID DI-EXT Extension block */
+	unsigned int	start_addr,	/* Starting byte address (0x0E) */
+	unsigned int	end_addr);	/* Ending   byte address (0x13) */
+
+void fbc_predid_diext_capabilities(
+	const uint8_t	edid_block[],	/* EDID DI-EXT Extension block */
+	unsigned int	start_addr,	/* Starting byte address (0x14) */
+	unsigned int	end_addr);	/* Ending   byte address (0x36) */
+
+void fbc_predid_diext_gamma(
+	const uint8_t	edid_block[],	/* EDID DI-EXT Extension block */
+	unsigned int	start_addr,	/* Starting byte address (0x51) */
+	unsigned int	end_addr);	/* Ending   byte address (0x7E) */
+
+
+#endif	/* FBC_PREDID_DIEXT_H */
+
+
+/* End of fbc_predid_diext.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_predid_vtbext.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,196 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_predid_vtbext - Display EDID VTB-EXT data
+ */
+
+
+#include <sys/types.h>		/* uint8_t */
+#include <stdio.h>		/* printf() */
+
+#include "fbc_predid.h"		/* Display EDID data */
+#include "fbc_predid_vtbext.h"	/* Display EDID VTB-EXT data */
+
+
+/*
+ * Conversions from EDID flag bit value to output text string
+ */
+static const char	*const fbc_No  = "No";
+static const char	*const fbc_Yes = "Yes";
+
+#define	FBC_YES_NO(_byte, _mask) \
+		((_byte) & (_mask)) ? fbc_Yes : fbc_No
+
+
+/*
+ * fbc_predid_vtbext_layout()
+ *
+ *    VTB Data Structure Layout
+ */
+
+void
+fbc_predid_vtbext_layout(
+	const uint8_t	edid_block[],	/* EDID VTB-EXT Extension block */
+	unsigned int	start_addr,	/* Starting byte address (0x02) */
+	unsigned int	end_addr)	/* Ending   byte address (0x04) */
+{
+
+	/*
+	 * VTB Data Structure Layout
+	 */
+	printf("\t  Detailed Timing Blocks:                %u\n",
+		edid_block[0x02]);
+	printf("\t  Coordinated Video Timing Descriptions: %u\n",
+		edid_block[0x03]);
+	printf("\t  Standard Timings Descriptions:         %u\n",
+		edid_block[0x04]);
+
+}	/* fbc_predid_vtbext_layout() */
+
+
+/*
+ * fbc_predid_coord_video_timing()
+ *
+ *    Coordinated Video Timing (CVT) Descriptions.
+ */
+
+static
+void
+fbc_predid_coord_video_timing(
+	const uint8_t	edid_block[],	/* EDID VTB-EXT Extension block */
+	unsigned int	start_addr,	/* Starting byte address (0x0E) */
+	unsigned int	end_addr)	/* Ending   byte address (0x13) */
+{
+
+	printf("\t  Active vertical lines (VSize): %u\n",
+	       (((unsigned int)edid_block[start_addr + 1] & 0xF0) << 4)
+					| edid_block[start_addr + 0]);
+	{
+		const char *const aspect_ratio[4] = {
+		    "4:3",
+		    "16:9",
+		    "16:10",
+		    "Undefined (reserved)"
+		};
+		printf("\t  Aspect ratio:                  %s\n",
+		       aspect_ratio[(edid_block[start_addr + 1] >> 2) & 0x03]);
+	}
+	{
+		const char *const preferred_rate[4] = {
+		    "50",
+		    "60",
+		    "75",
+		    "85"
+		};
+		printf("\t  Preferred refresh rate:        %s Hz\n",
+			preferred_rate[(edid_block[start_addr + 2] >> 5)
+							& 0x03]);
+	}
+	printf("\t  Supported refresh rates:\n");
+	printf("\t\t50 Hz:                   %s\n",
+		FBC_YES_NO(edid_block[start_addr + 2], 0x10));
+	printf("\t\t60 Hz:                   %s\n",
+		FBC_YES_NO(edid_block[start_addr + 2], 0x08));
+	printf("\t\t75 Hz:                   %s\n",
+		FBC_YES_NO(edid_block[start_addr + 2], 0x04));
+	printf("\t\t85 Hz:                   %s\n",
+		FBC_YES_NO(edid_block[start_addr + 2], 0x02));
+	printf("\t\t60 Hz Reduced Blanking:  %s\n",
+		FBC_YES_NO(edid_block[start_addr + 2], 0x01));
+
+}	/* fbc_predid_coord_video_timing() */
+
+
+/*
+ * fbc_predid_vtbext_data()
+ *
+ *    Video Timing Block (VTB) free format data bytes.
+ */
+
+void
+fbc_predid_vtbext_data(
+	const uint8_t	edid_block[],	/* EDID VTB-EXT Extension block */
+	unsigned int	start_addr,	/* Starting byte address */
+	unsigned int	end_addr)	/* Ending   byte address */
+{
+	unsigned int	e_addr;		/* Ending   byte addr of description */
+	unsigned int	i;		/* DTB/CVT/ST loop counter */
+	unsigned int	s_addr;		/* Starting byte addr of description */
+
+	/*
+	 * Start of VTB data area
+	 */
+	s_addr = 0x05;
+
+	/*
+	 * Detailed Timing Blocks (DTB)
+	 */
+	printf("    Detailed Timing Blocks (DTB)\n");
+	for (i = 1; i <= edid_block[0x02]; i += 1) {
+		e_addr = s_addr + 18 - 1;
+		if (e_addr >= 0x7F) {
+			break;
+		}
+		printf("      Detailed Timing Block #%u\n", i);
+		fbc_predid_det_timing(edid_block, s_addr, e_addr);
+		fbc_predid_dump_bytes(edid_block, s_addr, e_addr);
+		s_addr += 18;		/* 0x12=18 bytes per DTB */
+	}
+
+	/*
+	 * Coordinated Video Timing (CVT) Descriptions
+	 */
+	printf("    Coordinated Video Timing (CVT) Descriptions\n");
+	for (i = 1; i <= edid_block[0x03]; i += 1) {
+		e_addr = s_addr + 3 - 1;
+		if (e_addr >= 0x7F) {
+			break;
+		}
+		printf("      CVT Descriptor #%u\n", i);
+		fbc_predid_coord_video_timing(edid_block, s_addr, e_addr);
+		fbc_predid_dump_bytes(edid_block, s_addr, e_addr);
+		s_addr += 3;		/* 3 bytes per CVT */
+	}
+
+	/*
+	 * Standard Timings (ST) Descriptions
+	 */
+	printf("    Standard Timings (ST) Descriptions\n");
+	e_addr = s_addr + edid_block[0x04] * 2 - 1; /* 2 bytes per ST */
+	if (e_addr >= 0x7F) {
+		e_addr = 0x7F;		/* Avoid overruns */
+	}
+	fbc_predid_std_timings(edid_block, s_addr, e_addr);
+	fbc_predid_dump_bytes(edid_block, s_addr, e_addr);
+
+	/*
+	 * Unused Bytes
+	 */
+	printf("    Unused Bytes (Reserved)\n");
+	fbc_predid_dump_bytes(edid_block, e_addr + 1, 0x7F - 1);
+
+}	/* fbc_predid_vtbext_data() */
+
+
+/* End of fbc_predid_vtbext.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_predid_vtbext.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_predid_vtbext - Display EDID VTB-EXT data
+ */
+
+
+
+#ifndef	FBC_PREDID_VTBEXT_H
+#define	FBC_PREDID_VTBEXT_H
+
+
+#include <sys/types.h>		/* uint8_t */ 
+
+
+void fbc_predid_vtbext_layout(
+	const uint8_t	edid_block[],	/* EDID VTB-EXT Extension block */
+	unsigned int	start_addr,	/* Starting byte address (0x02) */
+	unsigned int	end_addr);	/* Ending   byte address (0x04) */
+
+
+void fbc_predid_vtbext_data(
+	const uint8_t	edid_block[],	/* EDID VTB-EXT Extension block */
+	unsigned int	start_addr,	/* Starting byte address */
+	unsigned int	end_addr);	/* Ending   byte address */
+
+
+#endif	/* FBC_PREDID_VTBEXT_H */
+
+
+/* End of fbc_predid_vtbext.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_properties.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_properties - Establish fbconf_xorg(1M) program properties
+ */
+
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_getargs.h"	/* Program command line processing */
+#include "fbc_help.h"		/* Program usage and help messages */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+#include "fbc_propt.h"		/* Display the current option settings */
+
+
+/*
+ * Command line options that commonly might be implied by "-defaults"
+ *
+ *    The form of every <x> option name string should be something like:
+ *        "-defaults; -<x>"
+ *    instead of simply:
+ *        "-<x>"
+ *    Read ";" as "implies" (which could be spelled out if need be).
+ *    This is for reporting errors, such as conflicting option values.
+ *    It allows us to tell the user that the error is asociated with the
+ *    actual -defaults option and the -<x> option that is implied.
+ *    Whatever form is chosen, this option name string must look right
+ *    when displayed by the fbc_errormsg() error reporting code.
+ */
+
+char *const fbc_defargv_clone[] =
+	{ "-defaults; -clone", "disable", NULL };
+
+char *const fbc_defargv_deflinear[] =
+	{ "-defaults; -deflinear", "false", NULL };
+
+char *const fbc_defargv_defoverlay[] =
+	{ "-defaults; -defoverlay", "false", NULL };
+
+char *const fbc_defargv_deftransparent[] =
+	{ "-defaults; -deftransparent", "false", NULL };
+
+char *const fbc_defargv_doublehigh[] =
+	{ "-defaults; -doublehigh", "disable", NULL };
+
+char *const fbc_defargv_doublewide[] =
+	{ "-defaults; -doublewide", "disable", NULL };
+
+char *const fbc_defargv_fake8[] =
+	{ "-defaults; -fake8", "disable", NULL };
+
+char *const fbc_defargv_g[] =
+	{ "-defaults; -g", FBC_GAMMA_DEFAULT_STR, NULL };
+
+char *const fbc_defargv_multisample[] =
+	{ "-defaults; -multisample", "disable", NULL };
+
+char *const fbc_defargv_offset[] =
+	{ "-defaults; -offset", "0", "0", NULL };
+
+char *const fbc_defargv_outputs[] =
+	{ "-defaults; -outputs", "direct", NULL };
+
+char *const fbc_defargv_rscreen[] =
+	{ "-defaults; -rscreen", "disable", NULL };
+
+char *const fbc_defargv_samples[] =
+	{ "-defaults; -samples", "4", NULL };
+
+char *const fbc_defargv_slave[] =
+	{ "-defaults; -slave", "disable", NULL };
+
+char *const fbc_defargv_stereo[] =
+	{ "-defaults; -stereo", "false", NULL };
+
+
+/*
+ * Command line option descriptors for fbconf_xorg with an unknown device type
+ *
+ *    This descriptor array won't be used except in the case of an
+ *    unproven [a-z]fb_properties.c module.
+ */
+static fbopt_descr_t	fbc_option[] = {
+	{
+	/* End-of-table marker */
+		NULL,
+		NULL,
+		NULL,
+		0,
+		NULL,
+		0,
+		NULL
+	}
+};
+
+
+/*
+ * List of functions to display the current option settings (-propt)
+ *
+ *    This function array won't be used except in the case of an
+ *    unproven [a-z]fb_properties.c module.
+ */
+static fbc_propt_fn_t	*fbc_propt_fn[] = {
+	fbc_propt_file,			/* Configuration file */
+	NULL				/* End of table */
+};
+
+
+/*
+ * fbc_get_base_properties()
+ *
+ *    Establish some minimal and/or generic fbconf_xorg(1M) properties.
+ *
+ *    Some of these are applicable when the device type is not known.
+ *    Some might be overwritten when the device type becomes known.
+ *    Some of these are "universally" applicable and need not be
+ *    overwritten except in fairly unforseen circumstances.
+ */
+
+void
+fbc_get_base_properties(
+	fbc_varient_t	*fbvar)		/* Returned fbconf_xorg properties */
+{
+
+	/*
+	 * Establish the minimal fbconf_xorg(1M) behavior
+	 */
+	fbvar->getargs           = &fbc_getargs;
+	fbvar->usage             = &fbc_usage;
+	fbvar->usage_text_header = fbc_usage_text_header;
+	fbvar->usage_text_body   = fbc_usage_text_body;
+	fbvar->help              = &fbc_help;
+
+	fbvar->fbc_option        = &fbc_option[0];
+
+	fbvar->xf86_entry_mods.Option_mods_size =
+				sizeof (fbc_option) / sizeof (fbopt_descr_t);
+
+	fbvar->revise_settings   = NULL;
+	fbvar->init_device       = NULL;
+	fbvar->propt_fn          = &fbc_propt_fn[0];
+	fbvar->res_mode_try      = NULL;	/* "-res <video_mode> try" */
+	fbvar->res_mode_now      = NULL;	/* "-res <video_mode> now" */
+
+}	/* fbc_get_base_properties() */
+
+
+/* End of fbc_properties.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_properties.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_properties - Establish fbconf_xorg(1M) program properties
+ */
+
+
+
+#ifndef _FBC_PROPERTIES_H
+#define	_FBC_PROPERTIES_H
+
+
+#include <stdio.h>		/* FILE */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_xorg.h"		/* Edit config file data representations */
+#include "fbc_mode_list.h"	/* List of Modes from Monitor section of cfg */
+#include "fbc_query_device.h"	/* Query a frame buffer device */
+
+
+/*
+ * Set of common fbconf_xorg(1M) command line option flags
+ */
+typedef struct {
+	unsigned int	help		: 1;	/* -help		*/
+	unsigned int	prconf		: 1;	/* -prconf		*/
+	unsigned int	predid_raw	: 1;	/* -predid raw		*/
+	unsigned int	predid_parsed	: 1;	/* -predid parsed	*/
+	unsigned int	propt		: 1;	/* -propt		*/
+	unsigned int	res_list	: 1;	/* -res ?		*/
+	unsigned int	res_mode_nocheck : 1;	/* -res <mode> nocheck	*/
+	unsigned int	res_mode_noconfirm : 1;	/* -res <mode> noconfirm */
+	unsigned int	res_mode_now	: 1;	/* -res <mode> now	*/
+	unsigned int	res_mode_try	: 1;	/* -res <mode> try	*/
+	/* Flags available for future use */
+	unsigned int	spare_10	: 1;
+	unsigned int	spare_11	: 1;
+	unsigned int	spare_12	: 1;
+	unsigned int	spare_13	: 1;
+	unsigned int	spare_14	: 1;
+	unsigned int	spare_15	: 1;
+} opt_set_t;
+
+
+/*
+ * fbconf_xorg(1M) program properties, typically frame buffer device specific
+ */
+typedef struct fbc_varient_st {
+	const char	*prog_name;	/* Program name used for messages */
+	const char	*config_file_loc; /* Config file location (-file) */
+	const char	*config_search_path; /* Config file search path */
+	const char	*config_file_path; /* Config input file pathname */
+	int (*getargs)(			/* Process the command line */
+		const int argc,		/*   Program argument count */
+		char	* const	argv[],	/*   Program argument vector */
+		struct fbc_varient_st *fbvar); /*   Program varient data */
+	void (*usage)(FILE *, struct fbc_varient_st *fbvar);
+					/* Program usage() function */
+	const char	*usage_text_header; /* Program usage text header */
+	const char	*usage_text_body; /* Program usage text body */
+	void (*help)(struct fbc_varient_st *fbvar);
+					/* Program help() function */
+	float		gamma_default;	/* Default gamma correction value */
+	char		*gfile_in_path;	/* Gamma table input path, else NULL */
+	const char	**gfile_out_path; /* Gamma table output pathname */
+	int		lut_size;	/* Gamma look-up table size */
+	char		*gamma_string_red; /* Red gamma packed data string */
+	char		*gamma_string_green; /* Green gamma packed string */
+	char		*gamma_string_blue; /* Blue gamma packed data string */
+//???	fbopt_descr_t	*fbc_option;	/* Recognized command line options */
+	void		*fbc_option;	/* Recognized command line options */
+	xf86_ent_mod_t	xf86_entry_mods; /* xorg.conf entry values */
+	opt_set_t	option_set;	/* Common command line option flags */
+	sectn_mask_t	modify_config;	/* Config sections, etc. to modify */
+	xf86_active_t	active;		/* Active config sections for device */
+	void (*get_edid_res_info)
+			(const fbc_dev_t *,
+			fbc_mode_elem_t *,
+			fbc_edid_res_t []); /* Get display device information */
+	int (*revise_settings)(struct fbc_varient_st *fbvar);
+					/* Config revision functn, else NULL */
+	int (*init_device)
+			(fbc_dev_t *device, struct fbc_varient_st *fbvar);
+					/* Device init function, else NULL */
+	void (*prconf)(const fbc_dev_t *device,
+			struct fbc_varient_st *fbvar,
+			XF86ConfigPtr	configIR);
+					/* Display hardware config (-prconf) */
+	void (*predid)(const fbc_dev_t *device,
+			struct fbc_varient_st *fbvar);
+					/* Display EDID data (-predid) */
+//???	fbc_propt_fn_t	**propt_fn;	/* List of -propt display functions */
+	void		*propt_fn;	/* List of -propt display functions */
+	int (*res_mode_try)(fbc_dev_t *device, fbc_video_mode_t *video_mode);
+					/* Video mode trial fn, else NULL */
+	int (*res_mode_now)(fbc_dev_t *device, fbc_video_mode_t *video_mode);
+					/* Video mode setting fn, else NULL */
+} fbc_varient_t;
+
+
+/*
+ * Command line options that might commonly be invoked by "-defaults"
+ */
+extern char *const fbc_defargv_clone[];
+extern char *const fbc_defargv_deflinear[];
+extern char *const fbc_defargv_defoverlay[];
+extern char *const fbc_defargv_deftransparent[];
+extern char *const fbc_defargv_doublehigh[];
+extern char *const fbc_defargv_doublewide[];
+extern char *const fbc_defargv_fake8[];
+extern char *const fbc_defargv_g[];
+extern char *const fbc_defargv_multisample[];
+extern char *const fbc_defargv_offset[];
+extern char *const fbc_defargv_outputs[];
+extern char *const fbc_defargv_rscreen[];
+extern char *const fbc_defargv_samples[];
+extern char *const fbc_defargv_slave[];
+extern char *const fbc_defargv_stereo[];
+
+
+void fbc_get_base_properties(
+	fbc_varient_t	*fbvar);	/* Returned fbconf_xorg properties */
+
+
+#endif	/* _FBC_PROPERTIES_H */
+
+
+/* End of fbc_properties.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_propt.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,523 @@
+/* Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_propt - Display current software configuration
+ */
+
+
+#include <stdio.h>		/* printf() */
+#include <string.h>		/* strcasecmp(), strcmp() */
+
+#include "configProcs.h"	/* xf86findOption(), xf86nameCompare() */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_Option.h"		/* Edit Option lists */
+#include "fbc_propt.h"		/* Display current software configuration */
+
+
+static const char *const fbc_msg_Not_set = "Not set";
+
+
+/*
+ * fbc_propt_name()
+ *
+ *    Display a label string, a quoted name string or the alternative
+ *    string for a missing name, and a line terminator.
+ *
+ *    The name string is quoted, as it is in the config file, since it
+ *    may include leading, trailing, and/or embedded whitespace.
+ */
+
+void
+fbc_propt_name(
+	const char * const label,	/* Label string */
+	const char * const name,	/* Name string, else NULL */
+	const char * const no_name)	/* Alternate string for missing name */
+{
+
+	if (name != NULL) {
+		printf("%s\"%s\"\n", label, name);
+	} else {
+		printf("%s%s\n", label, no_name);
+	}
+
+}	/* fbc_propt_name() */
+
+
+/*
+ * fbc_propt_file()
+ *
+ *    Display identifying information for the current config file and
+ *    for the active configuration sections.
+ */
+
+void
+fbc_propt_file(
+	fbc_varient_t	*fbvar)		/* Program varient data */
+{
+	const char	*name;		/* Active section, etc. name */
+	const char	*no_name;	/* Alternate string for missing name */
+
+	/*
+	 * Configuration file location and pathname
+	 */
+	printf("\nxorg.conf: ");
+	if (fbvar->config_file_loc != NULL) {
+		printf("%s -- ", fbvar->config_file_loc);
+	}
+	printf("%s\n", fbvar->config_file_path);
+
+	/*
+	 * Active Screen section  (section and name string must exist)
+	 */
+	name    = NULL;
+	no_name = "*** none ***";	/* Asterisks to emphasize a problem */
+	if (fbvar->active.screen_sectn != NULL) {
+		name    = fbvar->active.screen_sectn->scrn_identifier;
+		no_name = "*** no name ***";
+	}
+	fbc_propt_name(FBC_PR_INDENT "Screen section:  ", name, no_name);
+
+	/*
+	 * Active Device section  (section and name string must exist)
+	 */
+	name    = NULL;
+	no_name = "*** none ***";
+	if (fbvar->active.device_sectn != NULL) {
+		no_name = "*** no name ***";
+		name    = fbvar->active.device_sectn->dev_identifier;
+	}
+	fbc_propt_name(FBC_PR_INDENT "Device section:  ", name, no_name);
+
+	/*
+	 * Active Monitor section, if any  (section must have a name string)
+	 */
+	name    = NULL;
+	no_name = "none";
+	if (fbvar->active.monitor_sectn != NULL) {
+		name    = fbvar->active.monitor_sectn->mon_identifier;
+		no_name = "*** no name ***";
+	}
+	fbc_propt_name(FBC_PR_INDENT "Monitor section: ", name, no_name);
+
+	printf("\n");
+
+}	/* fbc_propt_file() */
+
+
+/*
+ * fbc_propt_video_mode()
+ *
+ *    Display the current video mode name.
+ */
+
+void
+fbc_propt_video_mode(
+	fbc_varient_t	*fbvar)		/* Program varient data */
+{
+
+	fbc_propt_name("Video Mode: ",
+			fbvar->active.mode_name,
+			fbc_msg_Not_set);
+
+}	/* fbc_propt_video_mode() */
+
+
+/*
+ * fbc_propt_stereo()
+ *
+ *    Display the current stereo video mode name (-res).
+ */
+
+void
+fbc_propt_stereo(
+	fbc_varient_t	*fbvar)		/* Program varient data */
+{
+
+	printf(FBC_PR_INDENT FBC_KEYWD_StereoEnable ": %s\n",
+		fbc_get_Option_string_value(&fbvar->active,
+					    FBC_SECTN_StereoEnable,
+					    FBC_KEYWD_StereoEnable,
+					    fbc_msg_Not_set,
+					    fbc_msg_Not_set));
+
+}	/* fbc_propt_stereo() */
+
+
+/*
+ * fbc_propt_multisample()
+ *
+ *    Display the current Multisample mode settings.
+ */
+
+void
+fbc_propt_multisample(
+	fbc_varient_t	*fbvar)		/* Program varient data */
+{
+	const char	*description;	/* Ptr to description of setting */
+	const char	*setting;	/* Ptr to setting text string */
+
+	printf("\nMultisample Information:\n");
+
+	/*
+	 * Multisample
+	 */
+	setting = fbc_get_Option_string_value(&fbvar->active,
+					      FBC_SECTN_Multisample,
+					      FBC_KEYWD_Multisample,
+					      fbc_msg_Not_set,
+			"*** Missing \"" FBC_KEYWD_Multisample "\" value ***");
+	description = "";
+	if (strcasecmp(setting, "Disabled") == 0) {
+		description = " (multisample visuals will not be available)";
+	} else
+	if (strcasecmp(setting, "Available") == 0) {
+		description = " (multisample visuals will be available)";
+	} else
+	if (strcasecmp(setting, "ForceOn") == 0) {
+		description =
+			" (All Sun OpenGL programs will be multisampled)";
+	}
+	printf(FBC_PR_INDENT
+		"Multisample Mode:  %s%s\n", setting, description);
+
+	/*
+	 * Samples  (This was "MultisampleDepth" in OWconfig)
+	 */
+	printf(FBC_PR_INDENT
+		"Samples Per Pixel: %s\n",
+		fbc_get_Option_string_value(&fbvar->active,
+					    FBC_SECTN_Samples,
+					    FBC_KEYWD_Samples,
+					    fbc_msg_Not_set,
+			"*** Missing \"" FBC_KEYWD_Samples "\" value ***"));
+
+}	/* fbc_propt_multisample() */
+
+
+/*
+ * fbc_propt_screen_title()
+ *
+ *    Display the screen settings title line.
+ */
+
+void
+fbc_propt_screen_title(
+	fbc_varient_t	*fbvar)		/* Program varient data */
+{
+
+	/*
+	 * Screen information
+	 */
+	printf("\nScreen Information:\n");
+
+}	/* fbc_propt_screen_title() */
+
+
+/*
+ * fbc_propt_dual_screen()
+ *
+ *    Display the current dual-screen (-doublewide, -doublehigh)
+ *    settings.
+ */
+
+void
+fbc_propt_dual_screen(
+	fbc_varient_t	*fbvar)		/* Program varient data */
+{
+
+	printf(FBC_PR_INDENT FBC_KEYWD_DoubleWide ": %s\n",
+		fbc_get_Option_string_value(&fbvar->active,
+					    FBC_SECTN_DoubleWide,
+					    FBC_KEYWD_DoubleWide,
+					    fbc_msg_Not_set,
+					    fbc_msg_Not_set));
+	printf(FBC_PR_INDENT FBC_KEYWD_DoubleHigh ": %s\n",
+		fbc_get_Option_string_value(&fbvar->active,
+					    FBC_SECTN_DoubleHigh,
+					    FBC_KEYWD_DoubleHigh,
+					    fbc_msg_Not_set,
+					    fbc_msg_Not_set));
+
+}	/* fbc_propt_dual_screen() */
+
+
+/*
+ * fbc_propt_clone()
+ *
+ *    Display the current clone setting (-clone).
+ */
+
+void
+fbc_propt_clone(
+	fbc_varient_t	*fbvar)		/* Program varient data */
+{
+
+	printf(FBC_PR_INDENT FBC_KEYWD_Clone ": %s\n",
+		fbc_get_Option_string_value(&fbvar->active,
+					    FBC_SECTN_Clone,
+					    FBC_KEYWD_Clone,
+					    fbc_msg_Not_set,
+					    fbc_msg_Not_set));
+
+}	/* fbc_propt_clone() */
+
+
+/*
+ * fbc_propt_offset()
+ *
+ *    Display the current screen offset settings (-offset).
+ */
+
+void
+fbc_propt_offset(
+	fbc_varient_t	*fbvar)		/* Program varient data */
+{
+
+	printf(FBC_PR_INDENT "Offset/Overlap: [%s, %s]\n",
+		fbc_get_Option_string_value(&fbvar->active,
+					    FBC_SECTN_StreamXOffset,
+					    FBC_KEYWD_StreamXOffset,
+					    "0",
+		    "*** Missing \"" FBC_KEYWD_StreamXOffset "\" value ***"),
+		fbc_get_Option_string_value(&fbvar->active,
+					    FBC_SECTN_StreamXOffset,
+					    FBC_KEYWD_StreamYOffset,
+					    "0",
+		    "*** Missing \"" FBC_KEYWD_StreamYOffset "\" value ***"));
+
+}	/* fbc_propt_offset() */
+
+
+/*
+ * fbc_propt_outputs()
+ *
+ *    Display the current Outputs setting (-outputs).
+ */
+
+void
+fbc_propt_outputs(
+	fbc_varient_t	*fbvar)		/* Program varient data */
+{
+
+	printf(FBC_PR_INDENT FBC_KEYWD_Outputs ":        %s\n",
+		fbc_get_Option_string_value(&fbvar->active,
+					    FBC_SECTN_Outputs,
+					    FBC_KEYWD_Outputs,
+					    fbc_msg_Not_set,
+					    fbc_msg_Not_set));
+
+}	/* fbc_propt_outputs() */
+
+
+/*
+ * fbc_propt_fake8()
+ *
+ *    Display the current Fake8 Rendering setting (-fake8).
+ */
+
+void
+fbc_propt_fake8(
+	fbc_varient_t	*fbvar)		/* Program varient data */
+{
+
+	printf(FBC_PR_INDENT "Fake8 Rendering: %s\n",
+		fbc_get_Option_string_value(&fbvar->active,
+					    FBC_SECTN_Fake8,
+					    FBC_KEYWD_Fake8,
+					    fbc_msg_Not_set,
+					    fbc_msg_Not_set));
+
+}	/* fbc_propt_fake8() */
+
+
+/*
+ * fbc_propt_rscreen()
+ *
+ *    Display the current Remote Console setting (-rscreen).
+ */
+
+void
+fbc_propt_rscreen(
+	fbc_varient_t	*fbvar)		/* Program varient data */
+{
+
+	printf(FBC_PR_INDENT "Remote Screen: %s\n",
+		fbc_get_Option_string_value(&fbvar->active,
+					    FBC_SECTN_RScreen,
+					    FBC_KEYWD_RScreen,
+					    fbc_msg_Not_set,
+					    fbc_msg_Not_set));
+
+}	/* fbc_propt_rscreen() */
+
+
+/*
+ * fbc_propt_visual_title()
+ *
+ *    Display the default visual title line.
+ */
+
+void
+fbc_propt_visual_title(
+	fbc_varient_t	*fbvar)		/* Program varient data */
+{
+
+	printf("\nVisual Information:\n");
+
+}	/* fbc_propt_visual_title() */
+
+
+/*
+ * fbc_propt_default_visual()
+ *
+ *    Display the current default visual setting for -deflinear,
+ *    -defoverlay, and -deftransparent.
+ */
+
+void
+fbc_propt_default_visual(
+	fbc_varient_t	*fbvar)		/* Program varient data */
+{
+
+	/*
+	 * Default visual
+	 *
+	 *    DefLinear, DefOverlay, and DefTransparent are supposed to
+	 *    be mutually exclusive, however, there is no assurance that
+	 *    manual editing of the configuration file left it in a
+	 *    consistent state.
+	 */
+	if (fbc_get_Option_bool_value(&fbvar->active,
+					FBC_SECTN_DefOverlay,
+					FBC_KEYWD_DefOverlay)) {
+		printf(FBC_PR_INDENT
+			"Default Visual: Nonlinear Overlay Visual\n");
+	} else
+	if (fbc_get_Option_bool_value(&fbvar->active,
+					FBC_SECTN_DefTransparent,
+					FBC_KEYWD_DefTransparent)) {
+		printf(FBC_PR_INDENT
+			"Default Visual: Transparent Overlay Visual\n");
+	} else
+	if (fbc_get_Option_bool_value(&fbvar->active,
+					FBC_SECTN_DefLinear,
+					FBC_KEYWD_DefLinear)) {
+		printf(FBC_PR_INDENT "Default Visual: Linear Normal Visual\n");
+	} else {
+		printf(FBC_PR_INDENT
+			"Default Visual: Nonlinear Normal Visual\n");
+	}
+
+}	/* fbc_propt_default_visual() */
+
+
+#define	GAMMA_CORRECTION_LABEL	"Gamma Correction: "
+
+/*
+ * fbc_propt_g()
+ *
+ *    Display the current gamma correction setting for -g only.
+ */
+
+void
+fbc_propt_g(
+	fbc_varient_t	*fbvar)		/* Program varient data */
+{
+
+	/*
+	 * Gamma correction
+	 */
+	if ((fbvar->active.monitor_sectn != NULL) &&
+			(fbvar->active.monitor_sectn->mon_gamma_red > 0.0)) {
+		printf(FBC_PR_INDENT GAMMA_CORRECTION_LABEL
+					"Using gamma value %.2f\n",
+			fbvar->active.monitor_sectn->mon_gamma_red);
+	} else {
+		printf(FBC_PR_INDENT GAMMA_CORRECTION_LABEL
+					"Using default gamma value %2.2f\n",
+			fbvar->gamma_default);
+	}
+
+}	/* fbc_propt_g() */
+
+
+/*
+ * fbc_propt_gamma()
+ *
+ *    Display the current gamma correction settings for -g and -gfile.
+ */
+
+void
+fbc_propt_gamma(
+	fbc_varient_t	*fbvar)		/* Program varient data */
+{
+	const char	*setting;	/* Ptr to setting text string */
+
+	/*
+	 * Gamma correction
+	 *
+	 *    Gamma and GFile should be mutually exclusive entries.
+	 *    There's no assurance, however, that manual editing of the
+	 *    configuration file will leave it in a consistent state.
+	 */
+	setting = fbc_get_Option_string_value(&fbvar->active,
+						FBC_SECTN_GFile,
+						FBC_KEYWD_GFile,
+						"", "");
+	if (*setting != '\0') {
+		printf(FBC_PR_INDENT GAMMA_CORRECTION_LABEL
+					"Using gamma file\n");
+	} else {
+		fbc_propt_g(fbvar);
+	}
+
+}	/* fbc_propt_gamma() */
+
+
+/*
+ * fbc_propt()
+ *
+ *    Display the current software configuration (option settings) for a
+ *    frame buffer device (-propt).
+ */
+
+void
+fbc_propt(
+	fbc_varient_t	*fbvar)		/* Program varient data */
+{
+	fbc_propt_fn_t	**propt_fn;	/* Ptr to addr of a display function */
+
+	/*
+	 * Repeat for each -propt display function in the array
+	 */
+	for (propt_fn = (fbc_propt_fn_t **)fbvar->propt_fn;
+	    *propt_fn != NULL;
+	    propt_fn += 1) {
+		(**propt_fn)(fbvar);
+	}
+
+}	/* fbc_propt() */
+
+
+/* End of fbc_propt.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_propt.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_propt - Display the current option settings
+ */
+
+
+
+#ifndef	_FBC_PROPT_H
+#define	_FBC_PROPT_H
+
+
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+#include "fbc_xorg.h"		/* Edit config file data representations */
+
+
+typedef void fbc_propt_fn_t(fbc_varient_t *fbvar);
+
+void fbc_propt_name(
+	const char * const label,	/* Label string */
+	const char * const name,	/* Name string, else NULL */
+	const char * const no_name);	/* Alternate string for missing name */
+
+fbc_propt_fn_t	fbc_propt_file;		/* Configuration file */
+fbc_propt_fn_t	fbc_propt_video_mode;	/* Current video mode name: -res */
+fbc_propt_fn_t	fbc_propt_stereo;	/* Current stereo video mode */
+fbc_propt_fn_t	fbc_propt_multisample;	/* Multisample mode settings */
+fbc_propt_fn_t	fbc_propt_screen_title;	/* Screen settings title */
+fbc_propt_fn_t	fbc_propt_dual_screen;	/* Dual-screen: -doublexxxxx */
+fbc_propt_fn_t	fbc_propt_clone;	/* Clone setting */
+fbc_propt_fn_t	fbc_propt_offset;	/* Screen offset settings */
+fbc_propt_fn_t	fbc_propt_outputs;	/* Outputs setting */
+fbc_propt_fn_t	fbc_propt_fake8;	/* Fake8 rendering: -fake8 */
+fbc_propt_fn_t	fbc_propt_rscreen;	/* Remote console setting: -rscreen */
+fbc_propt_fn_t	fbc_propt_visual_title;	/* Visual Information title */
+fbc_propt_fn_t	fbc_propt_default_visual; /* Default visual: -defxxxxx" */
+fbc_propt_fn_t	fbc_propt_g;		/* Gamma setting: -g only */
+fbc_propt_fn_t	fbc_propt_gamma;	/* Gamma setting: -g and -gfile */
+
+void fbc_propt(
+	fbc_varient_t	*fbvar);	/* Program varient data */
+
+
+#endif	/* _FBC_PROPT_H */
+
+
+/* End of fbc_propt.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_query_device.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,264 @@
+/* Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_query_device - Query a frame buffer device
+ */
+
+
+#include <errno.h>		/* errno */
+#include <stdlib.h>		/* free(), malloc() */
+#include <string.h>		/* memset(), strerror(), strlen(), strstr() */
+#include <unistd.h>		/* ioctl() */
+
+#include <sys/fbio.h>		/* fbgattr */
+
+#include "gfx_common.h"		/* Model name, part #, cur video mode, EDID */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_query_device.h"	/* Query a frame buffer device */
+
+
+/*
+ * fbc_get_attributes()
+ *
+ *    Query the frame buffer device for attribute information.  Return
+ *    zero upon success, along with the attribute information.  In the
+ *    event of an error, display an error message, clear the fbgattr
+ *    structure, and return the errno code.
+ */
+
+int
+fbc_get_attributes(
+	int		device_fd,	/* Device file descriptor number */
+	struct fbgattr	*gattr)		/* Returned "Get attributes" struct */
+{
+	int		error_code;	/* Error code (from errno.h) */
+
+	error_code = 0;
+	if (ioctl(device_fd, FBIOGATTR, gattr) < 0) {
+		error_code = errno;
+		fbc_errormsg("%s, ioctl(FBIOGATTR)\n", strerror(error_code));
+		memset(gattr, 0, sizeof (struct fbgattr));
+	}
+	return (error_code);
+
+}	/* fbc_get_attributes() */
+
+
+/*
+ * fbc_get_fb_model_name()
+ *
+ *    Return a pointer to a dynamically allocated string containing the
+ *    complete frame buffer model name string (with any "SUNW," prefix)
+ *    as well as a pointer to the simple model name substring (without
+ *    any "SUNW," prefix), else NULLs in the event of an error.
+ *
+ *    It is the caller's responsibility to free the dynamically
+ *    allocated model name string.
+ */
+
+char *
+fbc_get_fb_model_name(
+	int		device_fd,	/* Device file descriptor number */
+	char		**simple_model_name) /* Returned name w/o "SUNW," */
+{
+	const char *const SUNW_ = "SUNW,"; /* Prefix on model & part strings */
+	struct gfx_identifier gfx_ident; /* Graphics identifier */
+	char		*full_model_name; /* Model name w/ "SUNW," prefix */
+
+	full_model_name    = NULL;	/* Unavailable */
+	*simple_model_name = NULL;
+
+	if (ioctl(device_fd, GFX_IOCTL_GET_IDENTIFIER, &gfx_ident) >= 0) {
+		if (gfx_ident.flags & GFX_IDENT_MODELNAME) {
+			full_model_name = strdup(&gfx_ident.model_name[0]);
+			if (full_model_name != NULL) {
+				*simple_model_name = full_model_name;
+				if (strncmp(full_model_name,
+						SUNW_,
+						strlen(SUNW_)) == 0) {
+					*simple_model_name += strlen(SUNW_);
+				}
+			}
+		}
+	}
+
+	return (full_model_name);
+
+}	/* fbc_get_fb_model_name() */
+
+
+/*
+ * fbc_get_edid_data()
+ *
+ *    Query the frame buffer device for EDID data.  Return zero upon
+ *    success, along with the EDID data, etc.  In the event of an error,
+ *    display an error message and return the errno code and a NULL
+ *    data pointer.
+ */
+
+#include "fbc_predid.h"
+
+int
+fbc_get_edid_data(
+	int		device_fd,	/* Device file descriptor number */
+	int		stream_index,	/* Video stream index (zero-based) */
+	uint8_t		**edid_data,	/* Returned EDID Base block, etc. */
+	size_t		*edid_length)	/* Returned EDID data length */
+{
+#define	GFX_EDID_HEAD_A	0x01		/* ??? */
+#define	GFX_EDID_HEAD_B	0x02		/* ??? */
+	const uint32_t	edid_head[2] = {
+		GFX_EDID_HEAD_A,	/* Video stream A */
+		GFX_EDID_HEAD_B		/* Video stream B */
+	};
+	gfx_edid_t	edid;		/* EDID data retrieval structure */
+	int		error_code;	/* Error code (see errno.h) */
+
+	/*
+	 * In case of error
+	 */
+	*edid_data   = NULL;
+	*edid_length = 0;
+
+	/*
+	 * Get the byte length of the available EDID data (else try to fake it)
+	 *
+	 *    If there's an error, assume the display device isn't
+	 *    present.  Don't report the error here.  Just try to keep
+	 *    going.
+	 */
+	memset(&edid, 0, sizeof(gfx_edid_t));
+	edid.version = GFX_EDID_VERSION;
+	edid.head    = edid_head[stream_index];
+	error_code   = 0;
+	if (ioctl(device_fd, GFX_IOCTL_GET_EDID_LENGTH, &edid) < 0) {
+		error_code = errno;
+		return error_code;
+	}
+
+	if (edid.length <= 0) {
+		return -1;
+	}
+
+	/*
+	 * Allocate the EDID data buffer
+	 */
+	edid.data = malloc(edid.length);
+	if (edid.data == NULL) {
+		error_code = errno;
+		fbc_errormsg("%s, malloc(%u)\n",
+			    strerror(error_code),
+			    edid_length);
+		return (error_code);
+	}
+
+	/*
+	 * Get the EDID data
+	 *
+	 *    If there's an error, assume the display device isn't
+	 *    present.  Don't report the error here.  Just return the
+	 *    first error code encountered.
+	 */
+	if (ioctl(device_fd, GFX_IOCTL_GET_EDID, &edid) < 0) {
+		if (error_code == 0) {
+			error_code = errno;
+		}
+		free(edid.data);
+		return (error_code);
+	}
+
+	/*
+	 * Return successfully with the EDID data
+	 */
+	*edid_data   = (uint8_t *)edid.data;
+	*edid_length = edid.length;
+	return (0);
+
+}	/* fbc_get_edid_data() */
+
+
+/*
+ * fbc_get_edid_res_info()
+ *
+ *    For each stream indicated by the effective -dev option, retrieve
+ *    the EDID data from the display device and return the following
+ *    information:
+ *      * Manufacturer ID
+ *      * Product Code
+ *      * Pointer to a dynamically allocated array of supported video
+ *        mode name strings w/ preferred video mode in first element
+ *    The display device information is returned in the
+ *    edid_res_info[FBC_MAX_STREAMS] array.
+ */
+
+void
+fbc_get_edid_res_info(
+	const fbc_dev_t *device,	/* Frame buffer device info (-dev) */
+	fbc_mode_elem_t	*mode_list,	/* Modes from Monitor section of cfg */
+	fbc_edid_res_t	edid_res_info[]) /* Returned display device info */
+{
+	uint8_t		*edid_data;	/* EDID Base block, etc. */
+	size_t		edid_length;	/* EDID data length */
+	uint32_t	serial_num;	/* ID Serial Number (ignored) */
+	int		stream_index;	/* Video stream index (zero-based) */
+
+	memset(edid_res_info, 0, sizeof (fbc_edid_res_t) * FBC_MAX_STREAMS);
+
+	/*
+	 * Repeat for each video stream
+	 */
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+		/*
+		 * Get the EDID data for the display device
+		 */
+		if (fbc_get_edid_data(device->fd,
+					stream_index,
+					&edid_data,
+					&edid_length) != 0) {
+			continue;
+		}
+		if (sun_edid_check_base(edid_data, edid_length) == 0) {
+			/*
+			 * Get the -res related data for this display device
+			 */
+			sun_edid_vendor(edid_data,
+					edid_res_info[0].manufacturer_id,
+					&edid_res_info[0].product_code,
+					&serial_num);
+			edid_res_info[0].video_mode =
+				sun_edid_video_modes(edid_data,
+							edid_length,
+							mode_list);
+			free(edid_data);
+		}
+	}
+
+}	/* fbc_get_edid_res_info() */
+
+
+/* End of fbc_query_device.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_query_device.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_query_device - Query a frame buffer device
+ */
+
+
+
+#ifndef _FBC_QUERY_DEVICE_H
+#define	_FBC_QUERY_DEVICE_H
+
+
+#include <sys/int_types.h>	/* uint16_t */
+#include <sys/fbio.h>		/* fbgattr */
+
+#include "sun_edid.h"		/* EDID data parsing */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+
+
+/*
+ * Display device information returned by xxx_get_edid_res_info() functions
+ *
+ *    Note that the length, 4, for manufacturer_id[] is hard-wired by
+ *    EDID and includes a Nul terminator.
+ */
+typedef struct {
+	char		manufacturer_id[4]; /* ID Manufacturer */
+	uint16_t	product_code;	/* ID Product Code */
+	sun_edid_mode_t	*video_mode;	/* Supported video modes array */
+} fbc_edid_res_t;
+
+
+int fbc_get_attributes(
+	int		device_fd,	/* Device file descriptor number */
+	struct fbgattr	*gattr);	/* Returned "Get attributes" struct */
+
+char *fbc_get_fb_model_name(
+	int		device_fd,	/* Device file descriptor number */
+	char		**simple_model_name); /* Returned name w/o "SUNW," */
+
+int fbc_get_edid_data(
+	int		device_fd,	/* Device file descriptor number */
+	int		stream_index,	/* Video stream index (zero-based) */
+	uint8_t		**edid_data,	/* Returned EDID Base block, etc. */
+	size_t		*edid_length);	/* Returned EDID data length */
+
+void fbc_get_edid_res_info(
+	const fbc_dev_t *device,	/* Frame buffer device info (-dev) */
+	fbc_mode_elem_t	*mode_list,	/* Modes from Monitor section of cfg */
+	fbc_edid_res_t	edid_res_info[]); /* Returned display device info */
+
+
+#endif	/* _FBC_QUERY_DEVICE_H */
+
+
+/* End of fbc_query_device.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_res.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,986 @@
+/*
+ * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_res - Video modes/resolutions (-res option)
+ */
+
+
+#include <ctype.h>		/* isdigit(), ispunct(), toupper() */
+#include <stdio.h>		/* fputc(), printf(), sprintf() */
+#include <string.h>		/* str[case]cmp(), strrchr(), strstr(), ... */
+
+#include "xf86Parser.h"		/* Public function, etc. declarations */
+
+#include "resolutions.h"	/* Video mode summary table: SunVideoTable[] */
+#include "sun_edid.h"		/* EDID data parsing */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_xorg.h"		/* Edit config file data representations */
+#include "fbc_ask.h"		/* User interaction */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_mode_list.h"	/* List of Modes from the config file */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+#include "fbc_res.h"		/* Video modes/resolutions (-res option) */
+#include "fbc_res_compatible.h"	/* Video mode compatibity check (-res) */
+
+
+/*
+ * fbc_resname_attr_str()
+ *
+ *    Return TRUE iff the video mode/resolution name contains a case
+ *    insensitive version of the specified attribute substring (e.g.,
+ *    "STEREO"), set off by punctuation characters (typically '_' or
+ *    '-'), and/or, hypothetically, the string ends.
+ *
+ *    This code doesn't observe XFree86 name comparison rules with
+ *    respect to whitespace and underscores.
+ */
+
+static
+int
+fbc_resname_attr_str(
+	const char	*resname,	/* Video mode/resolution name */
+	const char	*attribute)	/* Attribute substring */
+{
+	char		prev_char;	/* Previous mode/res name char */
+	size_t		attr_len;	/* Length of attribute substring */
+	size_t		resname_len;	/* Length of mode/resolution name */
+	const char	*resname_ptr;	/* Ptr into mode/resolution name */
+	char		term_char;	/* Potential '_' or '\0' in resname */
+
+	resname_len = strlen(resname);
+	attr_len    = strlen(attribute);
+	prev_char   = '_';		/* Behave as if this were true */
+	for (resname_ptr = resname;
+	    resname_ptr <= resname + resname_len - attr_len;
+	    resname_ptr += 1) {
+		if (ispunct(prev_char)) {
+			term_char = *(resname_ptr + attr_len);
+			if ((ispunct(term_char) || (term_char == '\0')) &&
+			    (strncasecmp(resname_ptr, attribute, attr_len)
+						== 0)) {
+				return (TRUE);
+			}
+		}
+		prev_char = *resname_ptr;
+	}
+	return (FALSE);
+
+}	/* fbc_resname_attr_str() */
+
+
+/*
+ * fbc_resname_attr_chr()
+ *
+ *    Return TRUE iff the mode/resolution name has a case-insensitive
+ *    version of the specified suffix character.  The suffix character
+ *    must be passed to this function in upper case.
+ *
+ *    This code doesn't observe XFree86 comparison rules w/r/t
+ *    whitespace and underscores.
+ */
+
+static
+int
+fbc_resname_attr_chr(
+	const char	*resname,	/* Video mode name */
+	char		attribute)	/* Attribute suffix char, upper case */
+{
+	size_t		len;		/* Length of mode/resolution name */
+
+	len = strlen(resname);
+	return ((len > 0) && (toupper(resname[len-1]) == attribute));
+
+}	/* fbc_resname_attr_chr() */
+
+
+/*
+ * fbc_resname_stereo()
+ *
+ *    Return TRUE iff the mode/resolution name indicates stereo video
+ *    mode.  Such names contain a "STEREO" substring or have an 'S' or
+ *    's' suffix character.
+ */
+
+int
+fbc_resname_stereo(
+	const char	*resname)	/* Video mode name */
+{
+
+	return (fbc_resname_attr_str(resname, "STEREO") ||
+		fbc_resname_attr_chr(resname, 'S'));
+
+}	/* fbc_resname_stereo() */
+
+
+/*
+ * fbc_resname_digital()
+ *
+ *    Return TRUE iff the mode/resolution name indicates digital video
+ *    mode.  Such names contain a "DIG" substring.
+ */
+
+int
+fbc_resname_digital(
+	const char	*resname)	/* Video mode/resolution name */
+{
+
+	return (fbc_resname_attr_str(resname, "DIG"));
+
+}	/* fbc_resname_digital() */
+
+
+/*
+ * fbc_resname_cmp()
+ *
+ *    Compare two video mode/resolution name strings for equivalence.
+ *    The first name, full_resname, is the full name of a valid
+ *    mode/resolution.  The name to be validated, resname, matches
+ *    the first name if it is identical or if it is a substring
+ *    consisting of the numeric dimensions and anything that follows in
+ *    the full name.
+ *
+ *    Assumptions made by this algorithm:
+ *      * Abbreviations begin with the first digit of the dimensions.
+ *      * A full name can not be abbreviated unless it contains an
+ *        underscore (_).
+ *      * Its abbreviation would be the entire substring following the
+ *        last underscore.
+ *      * XFree86 comparison rules concerning whitespace and
+ *        underscores are not applied.  The alternative would
+ *        involve calling xf86nameCompare() instead of strcasecmp().
+ *
+ *    Return zero iff the video mode/resolution names match.
+ */
+
+static
+int
+fbc_resname_cmp(
+	const char	*full_resname,	/* Full name of a video mode/res */
+	const char	*resname)	/* Mode/res name or abbreviation */
+{
+	const char	*full_ptr;	/* Ptr into full_resname string */
+
+	if (strcasecmp(full_resname, resname) == 0) {
+		return (0);		/* Exact match of full names */
+	}
+
+	full_ptr = full_resname;
+	if (isdigit(*resname)) {
+		full_ptr = strrchr(full_resname, '_');
+		if (full_ptr != NULL) {
+			return (strcasecmp(full_ptr+1, resname));
+		}
+	}
+
+	return (1);			/* No match */
+
+}	/* fbc_resname_cmp() */
+
+
+/*
+ * fbc_get_monitor_id()
+ *
+ *    If there is more than one video stream, return a string containing
+ *    the stream number (" %d").  Otherwise return an empty string ("").
+ *    The string is returned in a monitor_id_buf[FBC_MAX_MONITOR_ID_LEN]
+ *    buffer, and will be used to identify the monitor for display
+ *    purposes (i.e., "... monitor <id> ..." or just "... monitor ...").
+ */
+
+void
+fbc_get_monitor_id(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	int		stream_index,	/* Video stream index (zero-based) */
+	char		*monitor_id_buf) /* Returned monitor ID, else "" */
+{
+
+	*monitor_id_buf = '\0';
+	if (device->max_streams > 1) {
+		sprintf(monitor_id_buf, " %d", stream_index + 1);
+	}
+
+}	/* fbc_get_monitor_id() */
+
+
+/*
+ * fbc_in_edid_modes()
+ *
+ *    Given a video mode name from the config file, find out whether:
+ *      * the video mode name is present in the list of modes (from
+ *        EDID) that are supported by the display device
+ *      * the video mode name is first in the list (e.g. represents the
+ *        preferred mode/resolution for the display)
+ *
+ *    Return the zero-relative subscript of the video mode name within
+ *    the list/array of mode/resolution names.  Return
+ *    FBC_NOT_IN_EDID_MODES if the name is not present in the list.
+ */
+
+#define	FBC_CHECK_EDID_MODES  (-2)	/* Check EDID video modes */
+#define	FBC_NOT_IN_EDID_MODES (-1)	/* Video mode name not in EDID list */
+#define	FBC_FIRST_EDID_MODE   (0)	/* First video mode in EDID list */
+
+static
+int
+fbc_in_edid_modes(
+	sun_edid_mode_t	*edid_mode,	/* Supported video modes array */
+	const char	*mode_name)	/* Video mode name */
+{
+	int		i;		/* Index of matching EDID mode name */
+
+	if (edid_mode != NULL) {
+		for (i = 0; edid_mode[i].name != NULL; i += 1) {
+// ??? Accept abbreviations, etc. ...
+			if (fbc_resname_cmp(edid_mode[i].name, mode_name)
+					== 0) {
+// ??? ... or not
+// ???			if (strcasecmp(edid_mode[i].name, mode_name) == 0) {
+				return (i);
+			}
+		}
+	}
+	return (FBC_NOT_IN_EDID_MODES);	/* No list or name isn't in list */
+
+}	/* fbc_in_edid_modes() */
+
+
+/*
+ * fbc_list_video_mode()
+ *
+ *    Display the specified video mode name from the config file unless
+ *    it's disqualified by some special case.  This typically is a video
+ *    mode name that has been referenced by the active Monitor section
+ *    of the config file.
+ *
+ *    Set footnote[0] to TRUE iff a video mode is displayed that is not
+ *    supported by all display devices.
+ *
+ *    Display any applicable footnote references (e.g. [1], [2], ...).
+ *    Footnotes are applicable iff the video mode name appears in the
+ *    list of EDID timings supported by the display device.  Return the
+ *    corresponding note text, to be displayed later by the caller.
+ */
+
+static
+void
+fbc_list_video_mode(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	const char	*mode_name,	/* Video mode name to display */
+	int		support_level,	/* FBC_xxxxx_EDID_MODEx */
+	fbc_edid_res_t	edid_res_info[], /* EDID/-res information */
+	int		footnote[])	/* Returned flags, else unchanged */
+{
+	int		i;		/* Index of matching video mode name */
+	int		stream_index;	/* Video stream index (zero-based) */
+
+	/*
+	 * Suppress certain video mode names
+	 *
+??? Is this code suitable for kfb?  For any other frame buffers?
+	 *    'I' - Interlaced video timing
+	 *    'S' - Stereo video mode
+	 */
+	if (fbc_resname_attr_str(mode_name, "NTSC") ||
+	    fbc_resname_attr_str(mode_name, "PAL") ||
+	    fbc_resname_attr_str(mode_name, "INT") ||
+	    fbc_resname_attr_str(mode_name, "FSC") ||
+	    fbc_resname_attr_chr(mode_name, 'S') ||
+	    fbc_resname_attr_chr(mode_name, 'I')) {
+		return;
+	}
+
+	/*
+	 * Display this video mode name
+	 */
+	printf("\t%-26s", mode_name);
+
+	/*
+	 * For the indicated video streams (-dev), display any footnote numbers
+	 */
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+		/*
+		 * See whether video mode is supported by this display device
+		 *
+		 *    Most video modes should be looked up in the
+		 *    list(s) of EDID video modes/timings.  Getting
+		 *    support level footnotes for "AUTO" or "NONE" is
+		 *    the exception.
+		 */
+		i = support_level;
+		if (support_level == FBC_CHECK_EDID_MODES) {
+			i = fbc_in_edid_modes(
+				edid_res_info[stream_index].video_mode,
+				mode_name);
+		}
+		if (i == FBC_NOT_IN_EDID_MODES) {
+			footnote[0] = TRUE;	/* Mode not fully supported */
+		} else {
+			int note_num;	/* Note number */
+
+			/*
+			 * Show the whether the video mode is supported
+			 */
+			note_num = stream_index * 2 + 1;
+			printf("[%d]", note_num);
+			footnote[note_num] = TRUE;
+			if (i == FBC_FIRST_EDID_MODE) {
+				/* First mode in list is preferred one */
+				printf("[%d]", note_num + 1);
+				footnote[note_num + 1] = TRUE;
+			}
+		}
+	}
+
+	/*
+	 * Terminate the line containing the video mode and any note numbers
+	 */
+	putchar('\n');
+
+}	/* fbc_list_video_mode() */
+
+
+/*
+ * Keywords representing the display device's preferred video mode
+ */
+static const char *mode_pref_keywd[] = {
+	FBC_RESNAME_PREFERRED,		/* AUTO */
+	FBC_RESNAME_NONE,		/* NONE */
+	NULL				/* End marker */
+};
+
+
+/*
+ * fbc_res_list_modes()
+ *
+ *    Display the video mode names from the active Monitor section
+ *    (-res ?).  For each video mode and for each video stream, footnote
+ *    whether the mode is supported by the stream's display device and
+ *    whether it is the preferred mode for the display device.
+ *
+ *    Note that a mode name should not be displayed unless the config
+ *    file contains the a ModeLine or Mode-EndMode entry to define that
+ *    mode.  Only the "mode_list" modes are defined in the config file.
+ *    Additional modes in the edid_res_info[].mode_names arrays and in
+ *    the SunVideoTable[] array are not defined in the config file.
+ */
+
+#define	FBC_MAX_NOTES	(FBC_MAX_STREAMS * 2)	/* Two footnotes per stream */
+
+void
+fbc_res_list_modes(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar,		/* fbconf_xorg(1M) varient data */
+	XF86ConfigPtr	configIR)	/* Ptr to configuration Internal Rep */
+{
+	fbc_edid_res_t	edid_res_info[FBC_MAX_STREAMS]; /* EDID/-res info */
+	int		i;		/* Loop counter / array index */
+	int		footnote[FBC_MAX_NOTES+1]; /* TRUE => Display note */
+	int		footnoted;	/* TRUE => Footnotes displayed */
+	fbc_mode_elem_t *mode_elem;	/* Mode list element (unintrusive) */
+	fbc_mode_elem_t	*mode_list;	/* Modes from Monitor section of cfg */
+	int		stream_index;	/* Video stream index (zero-based) */
+
+	/*
+	 * No footnotes to display yet
+	 */
+	for (i = 0; i <= FBC_MAX_NOTES; i += 1) {
+		footnote[i] = FALSE;
+	}
+
+	printf("Video modes accepted by the -res option:\n");
+
+	/*
+	 * Display keywords representing the monitor's preferred video mode
+	 *
+	 *    The FBC_FIRST_EDID_MODE argument is used here in order to
+	 *    force the generation of the desired "supports" and
+	 *    "preferred" footnotes.
+	 */
+	for (i = 0; mode_pref_keywd[i] != NULL; i += 1) {
+		fbc_list_video_mode(device,
+				    mode_pref_keywd[i],	/* "AUTO", "NONE" */
+				    FBC_FIRST_EDID_MODE, /* Preferred */
+				    edid_res_info,	/* Not used */
+				    footnote);
+	}
+
+	/*
+	 * Get from the config file the video modes to be displayed
+	 */
+	mode_list = fbc_get_mode_list(
+			configIR, fbvar->active.monitor_sectn, device->type);
+
+	/*
+	 * Get the supported video modes from the EDID data
+	 */
+	fbvar->get_edid_res_info(device, mode_list, edid_res_info);
+
+	/*
+	 * Exclude any mode that's incompatible w/ this frame buffer & monitor
+	 */
+	(void) fbc_res_compatible(device, edid_res_info, NULL, mode_list);
+
+	/*
+	 * Display the video modes that are configured for this frame buffer
+	 */
+	for (mode_elem = mode_list;
+	    mode_elem != NULL;
+	    mode_elem = mode_elem->list.next) {
+		if (mode_elem->mode_ptr == NULL) {
+			continue;	/* This video mode has been excluded */
+		}
+		fbc_list_video_mode(device,
+				    mode_elem->mode_ptr->ml_identifier,
+				    FBC_CHECK_EDID_MODES,
+				    edid_res_info,
+				    footnote);
+	}
+
+	fbc_free_mode_list(mode_list);
+
+	fputc('\n', stdout);		/* Blank line */
+
+	/*
+	 * Display all footnotes that apply
+	 */
+	footnoted = FALSE;
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+		char monitor_id[FBC_MAX_MONITOR_ID_LEN];
+		int note_num;
+
+		fbc_get_monitor_id(device, stream_index, &monitor_id[0]);
+
+		note_num = stream_index * 2 + 1;
+		if (footnote[note_num]) {
+			printf("[%d] Resolution is supported by monitor%s\n",
+			       note_num, monitor_id);
+			footnoted = TRUE;
+		}
+		note_num += 1;
+		if (footnote[note_num]) {
+			printf("[%d] Preferred resolution for monitor%s\n",
+			       note_num, monitor_id);
+			footnoted = TRUE;
+		}
+
+		if (edid_res_info[stream_index].video_mode == NULL) {
+			printf(
+"No EDID data for monitor%s.  Can not determine supported resolutions.\n",
+				monitor_id);
+			footnoted = TRUE;
+			footnote[0] = TRUE;
+		}
+	}
+	if (footnoted) {
+		fputc('\n', stdout);		/* Blank line */
+	}
+
+	if (footnote[0]) {
+		printf(
+"Use of an unsupported resolution can render the video display unusable.\n\n");
+	}
+
+	printf("Abbreviations such as \"1280x1024x75\" may also be used.\n");
+
+	/*
+	 * Release dynamically allocated memory
+	 */
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+		sun_edid_video_modes_free(
+				edid_res_info[stream_index].video_mode);
+	}
+
+}	/* fbc_res_list_modes() */
+
+
+/*
+ * fbc_is_known_mode()
+ *
+ *    Given a "-res <video_mode> ..." command line option:
+ *      * If present in the video mode name, replace '@' with 'x'
+ *      * Look up the video mode name in these places:
+ *          * The EDID video mode names supported by the monitor
+ *          * The active Monitor section of the configuration file
+ *          * The built-in SunVideoTable[] array
+ *      * If the video mode name is found, substitute and return its
+ *        canonical form (full spelling, in the proper case, with no '@'
+ *        character)
+ *      * Return video mode display dimensions or something like them
+ *    Return TRUE iff the video mode name is found.
+ */
+
+static
+int
+fbc_is_known_mode(
+	XF86ConfigPtr	configIR,	/* Ptr to configuration Internal Rep */
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_edid_res_t	edid_res_info[], /* Display device information */
+	XF86ConfMonitorPtr monitor_sectn_ptr, /* Ptr to Monitor section IR */
+	char		*mode_name_buf,	/* Video mode name scratch buffer */
+	size_t		mode_name_buf_len, /* Scratch buffer length */
+	fbc_video_mode_t *video_mode)	/* Video mode (-res <video_mode>) */
+{
+	sun_edid_mode_t	*edid_mode;	/* EDID/supported video mode */
+	const char	*full_resname;	/* Current video mode/res name */
+	fbc_mode_elem_t *mode_elem;	/* Mode list element (unintrusive) */
+	fbc_mode_elem_t	*mode_list;	/* Modes from Monitor section of cfg */
+	const char	*ptr;		/* Ptr into mode name, else NULL */
+	int		stream_index;	/* Video stream index (zero-based) */
+	const SunVideoSummary *vs;	/* Video summary array element ptr */
+
+	/*
+	 * Try to determine the display parameters for this video mode
+	 *
+	 *    For example, "VESA_STD_1280x1024x60" or "1280x1024x60"
+	 *    would yeild 1280 for width and 1024 for height.
+	 *
+	 *    This is being done to cover the case in which the video
+	 *    mode name isn't recognized.  The values may be needed for
+	 *    "-res <video_mode> try" support.
+	 *
+	 *    This approach wouldn't work well with "AUTO" or "NONE."
+	 *    It also is questionable to assume that a video mode name
+	 *    reflects precise values.  Note the height values for these
+	 *    EDID Standard Timings and the corresponding video mode
+	 *    names:
+	 *        1152x921x76 => "SUNW_STD_1152x900x76"
+	 *        1152x921x66 => "SUNW_STD_1152x900x66"
+	 */
+	ptr = strrchr(video_mode->name, '_');
+	if (ptr != NULL) {
+		ptr += 1;
+	} else {
+		ptr = video_mode->name;
+	}
+	if (sscanf(ptr, "%dx%d", &video_mode->width, &video_mode->height)
+					< 2) {
+		video_mode->width  = 0;
+		video_mode->height = 0;
+	}
+	video_mode->frequency = 0;	/* Not needed by any code so far */
+
+	/*
+	 * If found, replace '@' with 'x' (e.g. "640x480@60" => "640x480x60")
+	 */
+	ptr = strrchr(video_mode->name, '@');
+	if (ptr != NULL) {
+		if (strlcpy(mode_name_buf, video_mode->name, mode_name_buf_len)
+					>= mode_name_buf_len) {
+			return (FALSE);	/* Mode name is too problematic */
+		}
+		mode_name_buf[ptr - video_mode->name] = 'x';
+		video_mode->name = mode_name_buf;
+	}
+
+	/*
+	 * See whether the video mode name is found among the EDID modes
+	 *
+	 *    Ideally, the video mode name can be found with each of the
+	 *    specified video streams, since we'll have to reject it
+	 *    later otherwise.  For now, however, we just want to know
+	 *    whether the name is valid.
+	 */
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+		if (edid_res_info[stream_index].video_mode == NULL) {
+			continue;	/* No EDID data, etc. */
+		}
+		for (edid_mode = edid_res_info[stream_index].video_mode;
+		     edid_mode->name != NULL;
+		     edid_mode += 1) {
+			if (fbc_resname_cmp(edid_mode->name, video_mode->name)
+					== 0) {
+				/* Return w/ canonicalized name, etc. */
+				video_mode->name      = mode_name_buf;
+				video_mode->width     = edid_mode->width;
+				video_mode->height    = edid_mode->height;
+				video_mode->frequency = edid_mode->frequency;
+				return (strlcpy(mode_name_buf,
+						edid_mode->name,
+						mode_name_buf_len)
+							< mode_name_buf_len);
+			}
+		}
+	}
+
+	/*
+	 * See whether the video mode name is found in the config file
+	 */
+	mode_list =
+		fbc_get_mode_list(configIR, monitor_sectn_ptr, device->type);
+	for (mode_elem = mode_list;
+	    mode_elem != NULL;
+	    mode_elem = mode_elem->list.next) {
+		full_resname = mode_elem->mode_ptr->ml_identifier;
+		if (fbc_resname_cmp(full_resname, video_mode->name) == 0) {
+			/* Return succesfully w/ canonicalized name, etc. */
+			video_mode->name   = full_resname;
+			video_mode->width  = mode_elem->mode_ptr->ml_hdisplay;
+			video_mode->height = mode_elem->mode_ptr->ml_vdisplay;
+			video_mode->frequency = 0; /* Unnecessary to compute */
+			fbc_free_mode_list(mode_list);
+			return (TRUE);
+		}
+	}
+	fbc_free_mode_list(mode_list);
+
+	/*
+	 * See whether the video mode name is found in the built-in table
+	 */
+	for (vs = &SunVideoTable[0]; vs->id_string != NULL; vs += 1) {
+		if (fbc_resname_cmp(vs->id_string, video_mode->name) == 0) {
+			/* Return succesfully w/ canonicalized name, etc. */
+			video_mode->name      = vs->id_string;
+			video_mode->width     = vs->width;
+			video_mode->height    = vs->height;
+			video_mode->frequency = vs->vfreq;
+			return (TRUE);
+		}
+	}
+
+	/*
+	 * Unrecognized video mode name
+	 */
+	return (FALSE);
+
+}	/* fbc_is_known_mode() */
+
+
+/*
+ * fbc_is_supported_mode()
+ *
+ *    Given the canonicalized video mode name derived from a
+ *    "-res <video_mode> ..." command line option:
+ *      * Make sure the video mode is supported by all of the display
+ *        devices associated with the frame buffer device.  The EDID
+ *        data from each display device says which video timings and
+ *        therefore which names are supported.
+ *      * Make sure the hardware combination of frame buffer and each
+ *        display device works with this video mode.
+ *    Return TRUE iff the video mode appears valid.
+ */
+
+static
+int
+fbc_is_supported_mode(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	const char	*mode_name,	/* Video mode name (-res) */
+	fbc_edid_res_t	edid_res_info[]) /* Display device information */
+{
+	sun_edid_mode_t	*edid_mode;	/* EDID/supported video mode(s) */
+	int		stream_index;	/* Video stream index (zero-based) */
+	int		supported_mode;	/* TRUE => Video mode is supported */
+
+#if (1)	/* Unexplained vestige from Xsun's kfbconfig.c and nfbconfig.c */
+	/*
+	 * Compensate for some omission in sun_edid.c or resolutions.c?
+	 */
+	if (strcasecmp(mode_name, "VESA_STD_1600x1200x60") == 0) {
+        	mode_name = "1600x1200x60";
+	}
+
+#endif
+#if (0)	/* Is this a worthwhile check? */
+	/*
+	 * Make sure the mode is defined by a ModeLine / Mode-EndMode entry
+	 */
+	if (active->mode_entry == NULL) {
+		fbc_errormsg(
+			"Mode \"%s\" not found using Monitor section \"%s\"\n",
+			active->mode_name,
+			active->monitor_sectn->mon_identifier);
+		return (FBC_ERR_GENERAL);
+	}
+
+#endif
+	/*
+	 * Validate the video mode for the indicated video streams (-dev)
+	 */
+	supported_mode = TRUE;
+
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+
+		edid_mode = edid_res_info[stream_index].video_mode;
+
+		/*
+		 * Make sure this monitor provided EDID data
+		 */
+		if (edid_mode == NULL) {
+			char monitor_id[FBC_MAX_MONITOR_ID_LEN];
+
+			fbc_get_monitor_id(
+					device, stream_index, &monitor_id[0]);
+			fbc_errormsg(
+			"Warning: EDID data is not available for monitor%s\n",
+				monitor_id);
+			supported_mode = FALSE;
+			continue;	/* Check any other monitors too */
+		}
+
+		/*
+		 * See if this monitor supports the mode, according to EDID
+		 */
+		for ( ; ; edid_mode += 1) {
+			if (edid_mode->name == NULL) {
+				supported_mode = FALSE;
+				break;	/* Not supported by this monitor */
+			}
+			if (fbc_resname_cmp(edid_mode->name, mode_name) == 0) {
+				break;	/* Supported by this monitor */
+			}
+		}
+	}
+
+	return (supported_mode);
+
+}	/* fbc_is_supported_mode() */
+
+
+/*
+ * fbc_res_validate_mode()
+ *
+ *    Given a "-res <video_mode> [nocheck|noconfirm] ..." command line
+ *    option:
+ *      * Look up the video mode name argument in these places:
+ *          * The predefined keywords, "AUTO" and "NONE"
+ *          * The EDID video mode names supported by the monitor
+ *          * The active Monitor section of the configuration file
+ *          * The built-in SunVideoTable[] array
+ *      * If the video mode name is found, and if necessary, substitute
+ *        and return its canonical form.
+ *      * If the user didn't specify "nocheck" or "noconfirm",
+ *          * make sure the video mode name was found, and
+ *              * make sure the video mode is supported by each of the
+ *                applicable display devices, including in combination
+ *                with the frame buffer, or else
+ *              * ask if the user knows what he's doing.
+ *    Return TRUE iff the video mode appears valid or if the user
+ *    insists.
+ */
+
+int
+fbc_res_validate_mode(
+	XF86ConfigPtr	configIR,	/* Ptr to configuration Internal Rep */
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar,		/* fbconf_xorg(1M) varient data */
+	char		mode_name_buf[], /* Returned canonicalized mode name */
+	size_t		mode_name_buf_len, /* Scratch buffer length */
+	fbc_video_mode_t *video_mode)	/* Video mode (-res <video_mode>) */
+{
+	fbc_edid_res_t	edid_res_info[FBC_MAX_STREAMS];
+	int		i;		/* Loop counter / array index */
+	int		known_mode;	/* TRUE => Video mode name is known */
+	fbc_mode_elem_t	*mode_list;	/* Modes from active Monitor section */
+	int		stream_index;	/* Video stream index (zero-based) */
+	int		valid_mode;	/* TRUE => Accept this video mode */
+	int		sun_mode;	/* TRUE if mode is defined in SunModes section */
+
+
+	/*
+	 * Get the video modes from the active Monitor sectn of the config file
+	 */
+	mode_list = fbc_get_mode_list(
+			configIR, fbvar->active.monitor_sectn, device->type);
+
+	/*
+	 * Get the video modes from the EDID data for each display device
+	 */
+	fbvar->get_edid_res_info(device, mode_list, edid_res_info);
+
+	/*
+	 * Free the list of video modes from the config file
+	 *
+	 *    Note that this is an unintrusive list.  Freeing it does
+	 *    not affect the xf86 config data structures.
+	 */
+	fbc_free_mode_list(mode_list);
+
+	/*
+	 * Accept a keyword representing the monitors' preferred video mode
+	 *
+???	 *    TODO: Make sure all display devices have the same preferred mode
+	 */
+	for (i = 0; mode_pref_keywd[i] != NULL; i += 1) {
+		if (strcasecmp(video_mode->name, mode_pref_keywd[i]) == 0) {
+			sun_edid_mode_t	*edid_mode; /* Preferred mode */
+
+			/*
+			 * Return succesfully w/ preferred video mode, "AUTO"
+			 */
+			video_mode->name      = FBC_RESNAME_PREFERRED;
+			video_mode->width     = 0;	/* If no EDID data */
+			video_mode->height    = 0;	/* If no EDID data */
+			video_mode->frequency = 0;	/* If no EDID data */
+
+			stream_index = device->stream_lo;
+			edid_mode = edid_res_info[stream_index].video_mode;
+			if (edid_mode != NULL) {
+				video_mode->width     = edid_mode->width;
+				video_mode->height    = edid_mode->height;
+				video_mode->frequency = edid_mode->frequency;
+			}
+
+			for ( ;
+			    stream_index <= device->stream_hi;
+			    stream_index += 1) {
+				sun_edid_video_modes_free(
+				    edid_res_info[stream_index].video_mode);
+			}
+
+
+			/* 
+			 * If "AUTO" or "NONE" is specified, there is no need
+			 * to include a SunModes section. So remove it,
+			 * both internal & external representation
+			 */
+			fbc_trim_Modes_sections(configIR, video_mode->name);
+			fbc_remove_monitor_sunmodes_section_ER(configIR,
+						fbvar->active.monitor_sectn);
+
+			/*
+			 * Also remove the device specific use SunModes entry as well
+			 */
+			fbc_remove_monitor_usemodes_entry_ER(configIR,
+						fbvar->active.monitor_sectn);
+	
+			return (TRUE);
+		}
+	}
+
+	/*
+	 * Look up and canonicalize the -res <video_mode> name argument
+	 */
+	known_mode = fbc_is_known_mode(configIR,
+					device,
+					edid_res_info,
+					fbvar->active.monitor_sectn,
+					mode_name_buf,
+					mode_name_buf_len,
+					video_mode);
+
+	/*
+	 * Check the video mode unless the user said "nocheck"
+	 */
+	valid_mode = TRUE;
+	if (!fbvar->option_set.res_mode_nocheck) {
+		const char *msg_format;	/* Error message format */
+
+		/*
+		 * Accept this video mode if either main bullet point is true:
+		 *
+		 *    * The video mode satisfies all of:
+		 *        * is known from EDID, the config file, etc.
+		 *        * is supported by the display device(s)
+		 *        * is compatible with the frame buffer/monitor
+		 *          combination
+		 *    * The user said "noconfirm" or gives confirmation
+		 */
+		valid_mode = FALSE;
+		msg_format = "Unrecognized video mode, \"%s\"\n";
+		if (known_mode) {
+			msg_format =
+		    "Cannot verify that \"%s\" is a supported video mode\n";
+			if (fbc_is_supported_mode(
+				    device, video_mode->name, edid_res_info)) {
+				/*
+				 * See if frame buf & monitor(s) like this mode
+				 */
+				msg_format =
+			    "Hardware does not support video mode, \"%s\"\n";
+				if (fbc_res_compatible(device,
+							edid_res_info,
+							video_mode->name,
+							NULL)) {
+					valid_mode = TRUE;
+				}
+			}
+		}
+		if (!valid_mode) {
+			fbc_errormsg(msg_format, video_mode->name);
+			valid_mode =
+				fbvar->option_set.res_mode_noconfirm ||
+				fbc_ask_yes_no("Use \"%s\" anyway (yes/no) ? ",
+						video_mode->name);
+		}
+		if (!valid_mode) {
+			fbc_errormsg("No configuration changes made!\n");
+			fbc_errormsg(
+			"Note: Use \"-res ?\" to show valid video modes\n");
+		}
+	}
+
+	/*
+	 * Discard the mode name lists derived from EDID data
+	 */
+	for (stream_index = device->stream_lo;
+	    stream_index <= device->stream_hi;
+	    stream_index += 1) {
+		sun_edid_video_modes_free(
+				edid_res_info[stream_index].video_mode);
+	}
+
+	/*
+	 * after the validation, only keep the specified sun mode in the
+	 * SunModes section
+ 	 */
+	sun_mode = fbc_trim_Modes_sections(configIR, video_mode->name);
+
+	/*
+	 * remove the SunModes external representation that was added when
+	 * the config file was read.
+	 * A device specific SunModes section will be added to the file
+	 * later which only includes the mode specified in the -res option.
+	 * The reason is if all the SunModes are included in the mode section,
+	 * xf86ValidateModes code will set the virtual dimension to the largest
+	 * possible. This is not what is expected from fbconfig.
+ 	 */
+	fbc_remove_monitor_sunmodes_section_ER(configIR,
+						fbvar->active.monitor_sectn);
+
+	if (!sun_mode) {
+		/*
+		 * if the specified mode is not a SunMode, remove the
+		 * use SunMode entry
+		 */
+		fbc_remove_monitor_usemodes_entry_ER(configIR,
+						fbvar->active.monitor_sectn);
+	}
+
+	return (valid_mode);
+
+}	/* fbc_res_validate_mode() */
+
+
+/* End of fbc_res.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_res.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_res - Video mode/resolutions (-res option)
+ */
+
+
+
+#ifndef	_FBC_RES_H
+#define	_FBC_RES_H
+
+
+#include <string.h>		/* size_t */
+
+#include "xf86Parser.h"		/* Public function, etc. declarations */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+#include "fbc_query_device.h"	/* Query a frame buffer device */
+
+
+int fbc_resname_stereo(
+	const char	*resname);	/* Video mode name */
+
+int fbc_resname_digital(
+	const char	*resname);	/* Video mode name */
+
+#define	FBC_MAX_MONITOR_ID_LEN	16	/* Room for " %d" or "" string */
+
+void fbc_get_monitor_id(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	int		stream_index,	/* Video stream index (zero-based) */
+	char		*monitor_id_buf); /* Returned monitor ID, else "" */
+
+void fbc_res_list_modes(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar,		/* fbconf_xorg(1M) varient data */
+	XF86ConfigPtr	configIR);	/* Ptr to configuration Internal Rep */
+
+int fbc_res_validate_mode(
+	XF86ConfigPtr	configIR,	/* Ptr to configuration Internal Rep */
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_varient_t	*fbvar,		/* fbconf_xorg(1M) varient data */
+	char		*mode_name_buf,	/* Returned normalized video mode */
+	size_t		mode_name_buf_len, /* Scratch buffer length */
+	fbc_video_mode_t *video_mode);	/* Video mode (-res <video_mode>) */
+
+
+#endif	/* _FBC_RES_H */
+
+
+/* End of fbc_res.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_res_compatible.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,443 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_res_compatible - Video mode compatibity check (-res)
+ */
+
+
+//#include <sys/types.h>
+#include <ctype.h>		/* isspace() */
+#include <errno.h>		/* errno, ENOENT */
+#include <stdio.h>		/* fclose(), feof(), fgets(), fopen(), ... */
+#include <stdlib.h>		/* strtoul() */
+#include <string.h>		/* strcasecmp(), strchr(), str[c]spn() */
+#include <unistd.h>		/* ioctl() */
+
+#include "gfx_common.h"		/* Model name, part number, cur video mode */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_mode_list.h"	/* List of Modes from the config file */
+#include "fbc_query_device.h"	/* Query a frame buffer device */
+#include "fbc_res_compatible.h"	/* Video mode compatibity check (-res) */
+
+
+#define	MAX_LINE_LEN	1024		/* Max length of input line */
+
+
+/*
+ * fbc_res_comp_parse()
+ *
+ *    Parse an incompatibility file line and return the field values, if
+ *    any.  The line buffer most likely will be altered in the process.
+ */
+
+static
+int
+fbc_res_comp_parse(
+	char		*line_buf,	/* Line of video mode exception file */
+	char		**fb_model_name, /* Returned frame buffer model name */
+	char		**manufacturer_id, /* Returned display manufacturer */
+	char		**product_field, /* Returned display product code */
+	uint16_t	*product_code,	/* Returned display product code */
+	char		**video_mode,	/* Returned video mode name */
+	char		**error_text)	/* Returned error message text */
+{
+#define	FBC_WHITESPACE	"\t\n "		/* Characters treated as whitespace */
+	char		*end_ptr;	/* Ptr to product code terminator */
+	char		*line_ptr;	/* Ptr into line buffer */
+
+	/*
+	 * No fields to return yet
+	 */
+	*fb_model_name   = NULL;	/* Assume the line is empty */
+	*manufacturer_id = NULL;
+	*product_field   = NULL;
+	*product_code    = 0;
+	*video_mode      = NULL;
+	*error_text      = NULL;	/* Assume no error to report */
+
+	/*
+	 * Discard any comment string
+	 */
+	line_ptr = strchr(line_buf, '#');
+	if (line_ptr != NULL) {
+		*line_ptr = '\0';
+	}
+
+	/*
+	 * Skip any leading whitespace and ignore logically empty lines
+	 */
+	line_ptr = line_buf;
+	line_ptr += strspn(line_ptr, FBC_WHITESPACE);
+	if (*line_ptr == '\0') {
+		return (FBC_SUCCESS);	/* Logically empty line */
+	}
+
+	/*
+	 * Scan the frame buffer model name field (e.g., "SUNW,XVR-2500")
+	 */
+	*fb_model_name = line_ptr;
+	line_ptr += strcspn(line_ptr, FBC_WHITESPACE);
+	if (*line_ptr == '\0') {
+		*error_text = "Error near frame buffer model name";
+	}
+	*line_ptr = '\0';		/* Nul overwrites whitespace char */
+	line_ptr += 1;
+
+	/*
+	 * Skip any remaining whitespace that separates fields
+	 */
+	line_ptr += strspn(line_ptr, FBC_WHITESPACE);
+
+	/*
+	 * Scan the display device manufacturer ID field (e.g., "SUN" or "*")
+	 */
+	*manufacturer_id = line_ptr;
+	line_ptr += strcspn(line_ptr, ",");
+	if (*line_ptr == '\0') {
+		*error_text = "Error near display device manufacturer ID";
+		return (FBC_ERR_GENERAL);
+	}
+	*line_ptr = '\0';		/* Nul overwrites ',' char */
+	line_ptr += 1;
+
+	/*
+	 * Parse the display device product code field (number or "*")
+	 */
+	*product_field = line_ptr;
+	line_ptr += strcspn(line_ptr, FBC_WHITESPACE);
+	if ((line_ptr == *product_field) || (*line_ptr == '\0')) {
+		*error_text = "Error near display device product code";
+	}
+	*line_ptr = '\0';		/* Nul overwrites whitespace char */
+	line_ptr += 1;
+	if (strcmp(*product_field, "*") != 0) {
+		*product_code = strtoul(*product_field, &end_ptr, 0);
+		if (*end_ptr != '\0') {
+			*error_text = "Invalid display device product code";
+			return (FBC_ERR_GENERAL);
+		}
+	}
+
+	/*
+	 * Skip any whitespace separating fields
+	 */
+	line_ptr += strspn(line_ptr, FBC_WHITESPACE);
+
+	/*
+	 * Scan the video mode name field
+	 */
+	*video_mode = line_ptr;
+	line_ptr += strcspn(line_ptr, FBC_WHITESPACE);
+	if (*line_ptr == '\0') {
+		return (FBC_SUCCESS);	/* No trailing whitespace */
+	}
+	*line_ptr = '\0';
+	line_ptr += 1;			/* Nul overwrites whitespace or NL */
+
+	/*
+	 * Skip any additional trailing whitespace
+	 */
+	line_ptr += strspn(line_ptr, FBC_WHITESPACE);
+	if (*line_ptr != '\0') {
+		*error_text = "Garbage following video mode name";
+		return (FBC_ERR_GENERAL);
+	}
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_res_comp_parse() */
+
+
+/*
+ * fbc_res_comp_lookup()
+ *
+ *    Read a text file containing entries:
+ *        Frame buffer model name,
+ *        Display device Manufacturer ID and Product Code
+ *        Video mode name
+ *    one entry per line.  Return TRUE iff the arguments to this
+ *    function do not match any incompatibility entry.
+ *
+ *    File syntax:
+ *        <file>    =:: <line>...
+ *        <line>    =:: [<sp>][<entry>][<sp>]<eol>
+ *        <entry>   =:: <fb_model_name><sp><display><sp><video_mode_name>
+ *        <display> =:: <edid_manufacturer_id>,<edid_product_code>
+ *        <sp>      =:: ' '|'\t'
+ *        <eol>     =:: [<comment>]'\n'
+ *        <comment> =:: '#'[<text>]
+ *
+ *        The "*" wildcard string will match any <edid_manufacturer_id>
+ *        or any <edid_product_code>.  It follows that "*,*" will match
+ *        any <display>.
+ *
+ *    File example:
+ *
+ *        # Hardware configurations and incompatible video modes
+ *        #
+ *        # Frame Buffer    Display Device         Video Mode Name
+ *        # Model Name      Mfg ID, Product Code
+ *        # ------------    --------------------   ---------------
+ *        SUNW,XVR-50       *,*                    SUNW_STD_1280x1024x76
+ *        SUNW,XVR-50       *,*                    SUNW_STD_1920x1200x75
+ *        SUNW,XVR-100      SUN,0x586              SUNW_STD_1280x1024x76
+ *        SUNW,XVR-300      SUN,0x586              SUNW_STD_1280x1024x76
+ *
+ *        # End of fbconf_res.rc
+ */
+
+static
+int
+fbc_res_comp_lookup(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	char		*gfx_model_name, /* Our frame buffer model name */
+	fbc_edid_res_t	edid_res_info[], /* Display device information */
+	const char	*res_mode_name,	/* "-res <video_mode>", else NULL */
+	fbc_mode_elem_t	*res_mode_list,	/* "-res ?" mode list, else NULL */
+	const char *const mode_comp_path, /* Video mode compatibility path */
+	FILE		*mode_comp_stream) /* Vid mode compatibility stream */
+{
+	char		*manufacturer_id; /* Display Mfg ID in line_buf[] */
+	uint16_t	product_code;	/* Display device product code */
+	char		*product_field;	/* Disp dev prod code in line_buf[] */
+	char		*end_ptr;	/* Ptr to terminator char */
+	char		*error_text;	/* Error message text */
+	char		*fb_model_name;	/* Frame buffer model in line_buf[] */
+	char		line_buf[MAX_LINE_LEN];	/* Line of video mode file */
+	int		line_num;	/* Exceptions file line number */
+	char		*line_ptr;	/* Ptr into line_buf[] buffer */
+	char		*mode_name;	/* Video mode name in line_buf[] */
+	int		stream_index;	/* Video stream index (zero-based) */
+
+	/*
+	 * Examine each line of the video mode incompatibility file
+	 */
+	line_num  = 0;
+	line_ptr  = &line_buf[0];
+	*line_ptr = '\0';		/* Empty line buffer */
+	for (;;) {
+		/*
+		 * Read a line from the file
+		 */
+		line_num += 1;
+		if (fgets(line_buf, MAX_LINE_LEN, mode_comp_stream) == NULL) {
+			if (feof(mode_comp_stream) == 0) {
+				fbc_errormsg(
+		"Error reading video mode exceptions file, %s, line %d\n",
+						mode_comp_path, line_num);
+				break;	/* Mode exceptions file input error */
+			}
+			break;		/* End of mode exceptions file */
+		}
+
+		/*
+		 * Parse the line
+		 */
+		if (fbc_res_comp_parse(line_buf,
+					&fb_model_name,
+					&manufacturer_id,
+					&product_field,
+					&product_code,
+					&mode_name,
+					&error_text) != FBC_SUCCESS) {
+			fbc_errormsg("%s, %s, line %d\n",
+					error_text, mode_comp_path, line_num);
+			continue;
+		}
+
+		/*
+		 * See if this line specifies our frame buffer model
+		 */
+		if (fb_model_name == NULL) {
+			continue;	/* Logically empty line */
+		}
+		if (strcasecmp(fb_model_name, gfx_model_name) != 0) {
+			continue;	/* Not our frame buffer model */
+		}
+
+		/*
+		 * See if this line matches any of our display devices
+		 */
+		for (stream_index = device->stream_lo; ; stream_index += 1) {
+			if (stream_index > device->stream_hi) {
+				/* None of our display devices found */
+				goto continue_outer_loop;
+			}
+
+			if (((strcmp(manufacturer_id, "*") == 0) ||
+			    (strcasecmp(manufacturer_id,
+					edid_res_info[stream_index]
+							.manufacturer_id)
+					== 0)) &&
+			    ((strcmp(product_field, "*") == 0) ||
+			    (product_code ==
+				edid_res_info[stream_index].product_code))) {
+				/* At least one of our display devices found */
+				break;
+			}
+		}
+
+		/*
+		 * See if this line specifies a video mode of interest
+		 */
+		if ((res_mode_name != NULL) &&
+		    (strcasecmp(mode_name, res_mode_name) == 0)) {
+			/*
+			 * Incompatible "-res <video_mode>" mode
+			 */
+			return (FALSE);
+		}
+
+		if (res_mode_list != NULL) {
+			fbc_mode_elem_t *mode_elem; /* Mode list element */
+
+			for (mode_elem = res_mode_list;
+			    mode_elem != NULL;
+			    mode_elem = mode_elem->list.next) {
+
+				if ((mode_elem->mode_ptr->ml_identifier
+						!= NULL) &&
+				    (strcasecmp(mode_name,
+						mode_elem->mode_ptr->
+							ml_identifier) == 0)) {
+					/*
+					 * Incompatible "-res ?" video mode
+					 */
+					mode_elem->mode_ptr = NULL;
+				}
+			}
+		}
+
+		/*
+		 * No match with this line of the file
+		 */
+continue_outer_loop:
+		;
+	}
+
+	/*
+	 * Show that we didn't find an incompatible "-res <video_mode>" mode
+	 *
+	 *    The return value is defined only for the
+	 *    "-res <video_mode>" case.  In the "-res ?" case, this is
+	 *    the sole return path, and any incompatible video modes
+	 *    have been unlinked from the res_mode_list list.
+	 */
+	return (TRUE);
+
+}	/* fbc_res_comp_lookup() */
+
+
+/*
+ * fbc_res_compatible()
+ *
+ *    Given the caller's frame buffer, its attached display devices, and
+ *    a video mode or list of video modes, indicate which of the
+ *    caller's video modes are on file as being incompatible with the
+ *    hardware.  Known incompatibilities are contained in a text file
+ *    consisting of entries of the form:
+ *        Frame buffer model name
+ *        Display device Manufacturer ID and Product Code
+ *        Video mode name
+ *    Each one-line entry represents hardware and a video mode that
+ *    behave badly when used together.
+ *
+ *    To check a "-res <video_mode>" command line option value for
+ *    compatibility, the caller should pass the video mode name via the
+ *    res_mode_name parameter and a NULL via the res_mode_list
+ *    parameter.  This function will return TRUE iff the parameters do
+ *    not match any entry in the file, or if the file doesn't exist.
+ *
+ *    To filter the "-res ?" video modes that will be displayed, the
+ *    caller should pass a NULL via the res_mode_name parameter and an
+ *    unintrusive linked list of config file Mode entries via the
+ *    res_mode_list parameter.  This function will unlink any Mode
+ *    entries that are known to be incompatible with the hardware.
+ *    (The caller is responsible for insuring that this does not cause
+ *    memory leaks.)  The function return value is undefined.
+ *
+ *    The results are undefined if the res_mode_name and res_mode_list
+ *    parameters are both NULL or are both non-NULL.
+ */
+
+int
+fbc_res_compatible(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_edid_res_t	edid_res_info[], /* Display device information */
+	const char	*res_mode_name,	/* "-res <video_mode>", else NULL */
+	fbc_mode_elem_t	*res_mode_list)	/* "-res ?" mode list, else NULL */
+{
+	const char *const mode_comp_path = FBC_LIB_DIR "/fbconf_res.rc";
+	int		error_code;	/* Returned error code */
+	struct gfx_identifier gfx_ident; /* Graphics identifier */
+	int		is_compatible;	/* TRUE => Video mode should be OK */
+	FILE		*mode_comp_stream; /* Mode compatibility stream */
+
+	/*
+	 * Get the complete frame buffer model name (e.g., "SUNW,XVR-2500")
+	 */
+	if ((ioctl(device->fd, GFX_IOCTL_GET_IDENTIFIER, &gfx_ident) < 0) ||
+	    ((gfx_ident.flags & GFX_IDENT_MODELNAME) == 0)) {
+		return (TRUE);	/* Assume compatibility */
+	}
+
+	/*
+	 * Open the video mode incompatibility file, if any
+	 */
+	errno = 0; /* fopen() can fail and not set errno if no free streams */
+	mode_comp_stream = fopen(mode_comp_path, "r");
+	if (mode_comp_stream == NULL) {
+		if (errno != ENOENT) {
+			fbc_errormsg(
+			    "Can't open video mode compatibility file, %s\n",
+				    mode_comp_path);
+		}
+		return (TRUE);		/* Assume no incompatibilities */
+	}
+
+	/*
+	 * Read incompatibility entries, checking each for a match
+	 */
+	is_compatible = fbc_res_comp_lookup(device,
+					    &gfx_ident.model_name[0],
+					    edid_res_info,
+					    res_mode_name,
+					    res_mode_list,
+					    mode_comp_path,
+					    mode_comp_stream);
+
+	/*
+	 * Close the video mode incompatibilities file
+	 */
+	fclose(mode_comp_stream);
+
+	return (is_compatible);
+
+}	/* fbc_res_compatible() */
+
+
+/* End of fbc_res_compatible.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_res_compatible.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_res_compatible - Video mode compatibity check (-res)
+ */
+
+
+
+#ifndef	_FBC_RES_COMPATIBLE_H
+#define	_FBC_RES_COMPATIBLE_H
+
+
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_query_device.h"	/* Query a frame buffer device */
+
+
+int fbc_res_compatible(
+	fbc_dev_t	*device,	/* Frame buffer device info (-dev) */
+	fbc_edid_res_t	edid_res_info[], /* Display device information */
+	const char	*res_mode_name,	/* "-res <video_mode>", else NULL */
+	fbc_mode_elem_t	*res_mode_list); /* "-res ?" mode list, else NULL */
+
+
+#endif	/* _FBC_RES_COMPATIBLE_H */
+
+
+/* End of fbc_res_compatible.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_write_config.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,452 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_write_config - Write an updated configuration file
+ */
+
+
+#include <sys/types.h>		/* off_t */
+#include <sys/param.h>		/* MAXPATHLEN */
+#include <errno.h>		/* errno */
+#include <stdio.h>		/* fdopen(), fprintf(), fseeko(), ... */
+#include <stdlib.h>		/* mkstemp() */
+#include <string.h>		/* strcat(), strcpy(), strlen(), strerror() */
+#include <unistd.h>
+#include <sys/stat.h>		/* stat() */
+
+#include "xf86Parser.h"		/* Public function, etc. declatations */
+#include "Configint.h"		/* Private definitions, etc. */
+#include "configProcs.h"	/* Private function, etc. declarations */
+#include "fields.h"		/* Write aligned whitespace and text fields */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_fields.h"		/* Measure aligned whitespace fields */
+#include "fbc_line_er.h"	/* External Representation of config lines */
+#include "fbc_write_config.h"	/* Write an updated configuration file */
+
+
+/*
+ * fbc_reread_config_line()
+ *
+ *    Reread a line from an xorg.conf input file.  Measure the
+ *    indentation whitespace (to be used when modifying this current
+ *    line or when inserting subsequent lines).
+ */
+
+static
+int
+fbc_reread_config_line(
+	FILE		*config_stream_in, /* Config file input stream */
+	off_t		line_pos,	/* Configuration line file position */
+	char 		**configBuf,	/* Config file line buffer */
+	int		*configBufLen,	/* Line buffer length */
+	fbc_wspace_t	*wspace_chars)	/* Line's whitespace characteristics */
+{
+
+	/*
+	 * Position the input configuration file to the line in question
+	 */
+	if (fseeko(config_stream_in, line_pos, SEEK_SET) != 0) {
+		return (FBC_ERR_SEEK);
+	}
+
+	/*
+	 * Reread the line from the input configuration file
+	 */
+	if (xf86getNextLine(configBuf, configBufLen, config_stream_in)
+					== NULL) {
+		return (FBC_ERR_READ);
+	}
+
+	/*
+	 * Measure the first whitespace fields if this is a non-comment line
+	 */
+	fbc_measure_whitespace(*configBuf, wspace_chars);
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_reread_config_line() */
+
+
+/*
+ * fbc_print_config_text()
+ *
+ *    Write a text string, typically a single line, to the output
+ *    configuration file.
+ *
+ *    This is considered to be an xf86_print_fn_t typed function.
+ */
+
+void
+fbc_print_config_text(
+	FILE		*config_stream_out, /* Config file output stream */
+	const char	*text,		/* Text string */
+	const char *const whitespace[]) /* Line indentation, ignored */
+{
+
+	fputs(text, config_stream_out);
+
+}	/* fbc_print_config_text() */
+
+
+static void
+fbc_write_config_modes(
+	FILE			*config_stream_out, /* Config file output stream */
+	XF86ConfigPtr		configIR,	    /* Ptr to config file Internal Rep */
+	XF86ConfMonitorPtr 	monitor_sectn_ptr)
+{
+        XF86ConfModesPtr modes_sectn_ptr; /* Ptr to Modes section IR */
+        XF86ConfModeLinePtr modes, mode;
+	char text[100];
+
+        modes_sectn_ptr = xf86findModes("SunModes", configIR->conf_modes_lst);
+        if (modes_sectn_ptr == NULL)
+                return;
+
+        modes = modes_sectn_ptr->mon_modeline_lst;
+
+	if (modes != NULL) {
+		fprintf(config_stream_out, "Section \"Modes\"\n");
+		fprintf(config_stream_out, "\tIdentifier \"SunModes_%s\"\n", 
+				monitor_sectn_ptr->mon_identifier);
+	}
+
+	mode = modes;
+	while (mode != NULL) {
+
+		xf86printMxxxSectionMode(config_stream_out, mode, xf86whitespace_1, xf86whitespace_2);
+	
+		mode = mode->list.next;
+	}
+
+	if (modes != NULL) {
+		fprintf(config_stream_out, "\nEndSection\n");
+	}
+}
+
+
+/*
+ * fbc_write_config_file()
+ *
+ *    Write the updated configuration data to a file.
+ */
+
+static
+int
+fbc_write_config_file(
+	FILE		*config_stream_out, /* Config file output stream */
+	fbc_line_list_t	*line_list,	    /* List of configuration data lines */
+	XF86ConfigPtr	configIR,	    /* Ptr to config file Internal Rep */
+	fbc_varient_t	*fbvar)		    /* fbconf_xorg(1M) varient data */
+{
+	int		error_code;	/* Error code */
+	fbc_line_elem_t	*line_ptr;	/* Ptr to ER data for a config line */
+	const char *const *whitespace;	/* Whitespace strings */
+	fbc_wspace_t	wspace_chars;	/* Line's whitespace characteristics */
+	int		wspace_measured; /* TRUE => Input whitespace seen */
+
+	/*
+	 * Initial line indentation
+	 */
+	wspace_measured = FALSE;
+
+	wspace_chars.whitespace[0] = xf86whitespace_0[0];
+	wspace_chars.whitespace[1] = xf86whitespace_0[1];
+	wspace_chars.whitespace[2] = xf86whitespace_0[2];
+
+	/*
+	 * Repeat for each configuration line in the External Representation
+	 */
+	for (line_ptr = line_list->head_ptr;
+	    line_ptr != NULL;
+	    line_ptr = line_ptr->next_ptr) {
+		/*
+		 * Copy, modify, or delete the current config line
+		 */
+		switch (line_ptr->status) {
+		default:
+			/*
+			 * Unlikely internal error
+			 */
+			fbc_errormsg(
+		    "Internal error; unknown config line status code, %d\n",
+				line_ptr->status);
+			fprintf(config_stream_out,
+				"### The following line was copied verbatim"
+				" due to an unknown status code, %d\n",
+				line_ptr->status);
+			/*FALLTHROUGH*/
+		case FBC_LINE_ORIGINAL:
+			/*
+			 * Go copy the original configuration line
+			 */
+			break;
+
+		case FBC_LINE_INSERTED:
+			/*
+			 * See whether we know what we're doing
+			 */
+			if (line_ptr->print_fn == NULL) {
+				fbc_errormsg(
+		    "Internal error; no print function for inserted line\n");
+				fprintf(config_stream_out,
+				"### A line to be inserted here was discarded"
+				" for lack of a print function\n");
+				continue; /* Discard the unknown line */
+			}
+
+			/*
+			 * Attempt to match the original indentation style
+			 *
+			 *    The original heuristic assumed that a line
+			 *    to be inserted should be indented to match
+			 *    the line that precedes it.  This works for
+			 *    a line to be inserted at the end of an
+			 *    existing and well-formed section.  Now
+			 *    we support insertion of omitted sections
+			 *    and subsections in empty and in existing
+			 *    config files.  Tricksy it is, yessss.
+			 */
+			whitespace = wspace_chars.whitespace;
+			if (!wspace_measured ||
+			    (line_ptr->indent_level == FBC_INDENT_0)) {
+				/*
+				 * Nothing to match, so use the default style
+				 */
+				switch (line_ptr->indent_level) {
+				case FBC_INDENT_0:
+					wspace_measured = FALSE;
+					whitespace = xf86whitespace_0;
+					break;
+				case FBC_INDENT_1:
+				case FBC_INDENT_ENTRY:
+					whitespace = xf86whitespace_1;
+					break;
+				case FBC_INDENT_2:
+				default:
+					whitespace = xf86whitespace_2;
+					break;
+				}
+			}
+
+			/*
+			 * Insert a new configuration line
+			 */
+			(line_ptr->print_fn)(config_stream_out,
+					    line_ptr->ir_ptr,
+					    whitespace);
+			continue;
+
+		case FBC_LINE_MODIFIED:
+			/*
+			 * Measure the whitespace (then discard the input line)
+			 */
+			(void) fbc_reread_config_line(
+						line_ptr->config_stream_in,
+						line_ptr->line_pos,
+						&xf86configBuf,
+						&xf86configBufLen,
+						&wspace_chars);
+			wspace_measured = TRUE;
+
+			/*
+			 * Insert a replacement configuration line
+			 */
+			if (line_ptr->print_fn == NULL) {
+				fbc_errormsg(
+		    "Internal error; no print function for modified line\n");
+				fprintf(config_stream_out,
+				    "### The following line was not modified"
+				    " for lack of a print function\n");
+				break;	/* Copy the unknown line */
+			}
+			(line_ptr->print_fn)(config_stream_out,
+					    line_ptr->ir_ptr,
+					    wspace_chars.whitespace);
+			continue;
+
+		case FBC_LINE_DELETED:
+			/*
+			 * Discard the configuration line
+			 */
+			continue;
+		}
+
+		/*
+		 * Copy the original configuration line
+		 */
+		error_code = fbc_reread_config_line(line_ptr->config_stream_in,
+						    line_ptr->line_pos,
+						    &xf86configBuf,
+						    &xf86configBufLen,
+						    &wspace_chars);
+		if (error_code != FBC_SUCCESS) {
+			fbc_errormsg("Configuration file input error\n");
+			return (error_code);
+		}
+		wspace_measured = TRUE;
+		fputs(xf86configBuf, config_stream_out);
+	}
+
+	/*
+	 * Lastly output the device specific SunModes section
+	 */
+        if (fbvar->xf86_entry_mods.video_mode.name != FBC_NO_MODE_NAME) {
+		fbc_write_config_modes(config_stream_out, configIR, fbvar->active.monitor_sectn);
+	}
+
+
+	return (FBC_SUCCESS);
+
+}	/* fbc_write_config_file() */
+
+
+/*
+ * fbc_write_config()
+ *
+ *    Write the updated configuration data to a new output file having a
+ *    temporary name.  Close the input configuration file, if any.
+ *    Replace any input configuration file with the output configuration
+ *    file, preserving the original file name, modes, and ownership.
+ */
+
+int
+fbc_write_config(
+	fbc_varient_t	*fbvar,		/* fbconf_xorg(1M) varient data */
+	XF86ConfigPtr	configIR)	/* Ptr to config file Internal Rep */
+{
+	int		config_fd_out;	/* Config file output fd */
+	char		config_path_out[MAXPATHLEN]; /* Output file pathname */
+	FILE		*config_stream_out; /* Config file output stream */
+	int		error_code;	/* Error code */
+	mode_t		orig_umask;	/* Original file creation mask */
+
+	/*
+	 * Generate the template for the temporary name of the output file
+	 *
+	 *    The temporary pathname is the concatenation of the input
+	 *    config file pathname, "XXXXXX", and a Nul terminator.
+	 */
+	if ((strlen(fbvar->config_file_path) + 6 + 1)
+					> sizeof (config_path_out)) {
+		fbc_errormsg("Configuration file pathname is too long, %s\n",
+				fbvar->config_file_path);
+		fbc_close_down_config();
+		return (FBC_ERR_PATH_LEN); /* Output name would be too long */
+	}
+	strcpy(config_path_out, fbvar->config_file_path);
+	strcat(config_path_out, "XXXXXX");
+
+	/*
+	 * Create and open the output config file using the temporary name
+	 */
+	orig_umask = umask(0177);
+	config_fd_out = mkstemp(config_path_out);
+	umask(orig_umask);
+	if (config_fd_out == -1) {
+	        fbc_errormsg("%s, %s\n", strerror(errno), config_path_out);
+		fbc_close_down_config();
+		return (FBC_ERR_OPEN);
+	}
+	config_stream_out = fdopen(config_fd_out, "w");
+	if (config_stream_out == NULL) {
+	        fbc_errormsg("%s, %s\n", strerror(errno), config_path_out);
+		close(config_fd_out);
+		fbc_close_down_config();
+		return (FBC_ERR_OPEN);
+	}
+
+	/*
+	 * Write the configuration data to the output file
+	 */
+	error_code =
+		fbc_write_config_file(config_stream_out, &fbc_line_ER_list, configIR, fbvar);
+
+	/*
+	 * Close the input config file(s), release resources, etc.
+	 */
+	fbc_close_down_config();
+
+	if (error_code == FBC_SUCCESS) {
+		struct stat stat_buf;	/* Input config file status */
+
+		/*
+		 * Get any input cfg file mode and ownership, else use defaults
+		 */
+		if (stat(fbvar->config_file_path, &stat_buf) == -1) {
+			stat_buf.st_mode = FBC_CONFIG_FILE_MODE;
+			stat_buf.st_uid  = FBC_CONFIG_FILE_UID;
+			stat_buf.st_gid  = FBC_CONFIG_FILE_GID;
+		}
+
+		/*
+		 * Set the mode and ownership of the output config file
+		 */
+		if (fchmod(config_fd_out, stat_buf.st_mode) == -1) {
+		        fbc_errormsg("%s, %s\n",
+					strerror(errno), config_path_out);
+			error_code = FBC_ERR_ACCESS;
+		}
+		if (fchown(config_fd_out, stat_buf.st_uid, stat_buf.st_gid)
+					== -1)
+		{
+		        fbc_errormsg("%s, %s\n",
+					strerror(errno), config_path_out);
+			error_code = FBC_ERR_ACCESS;
+		}
+	}
+
+	/*
+	 * Close the output config file (whether or not all went well)
+	 */
+	fclose(config_stream_out);
+
+	/*
+	 * Delete the input file, if any, replacing it with the output file
+	 */
+	if (error_code == FBC_SUCCESS) {
+		if (rename(config_path_out, fbvar->config_file_path) != 0) {
+			fbc_errormsg("%s, %s\n", strerror(errno),
+					fbvar->config_file_path);
+			error_code = FBC_ERR_RENAME;
+		}
+	}
+	if (error_code != FBC_SUCCESS) {
+		/*
+		 * Just delete the temporary output file
+		 */
+		(void) unlink(config_path_out);
+	}
+
+	/*
+	 * Return, indicating whether or not all went well
+	 */
+	return (error_code);
+
+}	/* fbc_write_config() */
+
+
+/* End of fbc_write_config.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_write_config.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_write_config - Write an updated configuration file
+ */
+
+
+
+#ifndef	_FBC_WRITE_CONFIG_H
+#define	_FBC_WRITE_CONFIG_H
+
+
+#include <stdio.h>		/* FILE */
+
+#include "xf86Parser.h"		/* XF86ConfigPtr */
+
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+
+
+void fbc_print_config_text(
+	FILE		*config_stream_out, /* Config file output stream */
+	const char	*text,		/* Text string */
+	const char *const whitespace[]); /* Line indentation, ignored */
+
+int fbc_write_config(
+	fbc_varient_t	*fbvar,		/* fbconf_xorg(1M) varient data */
+	XF86ConfigPtr	configIR);	/* Ptr to config file Internal Rep */
+
+
+#endif	/* _FBC_WRITE_CONFIG_H */
+
+
+/* End of fbc_write_config.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbc_xorg.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,253 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbc_xorg - Edit config file data representations
+ */
+
+
+
+#ifndef	_FBC_XORG_H
+#define	_FBC_XORG_H
+
+
+#include <stdio.h>		/* NULL */
+
+#include "xf86Parser.h"		/* Configuration (sub)section definitions */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+
+
+/*
+ * Active (sub)sections associated with the specified frame buffer device
+ */
+typedef struct {
+	XF86ConfScreenPtr screen_sectn;	/* Ptr to Screen  section */
+	XF86ConfDisplayPtr display_subsectn; /* Ptr to Display subsection */
+	XF86ConfMonitorPtr monitor_sectn; /* Ptr to Monitor section */
+	const char	*mode_name;	/* Video mode name (for -propt) */
+	XF86ConfModeLinePtr mode_entry;	/* ModeLine / Mode-EndMode entry */
+	XF86ConfDevicePtr device_sectn;	/* Ptr to Device section */
+} xf86_active_t;
+
+/*
+ * Codes representing active configuration (sub)sections or entries
+ *
+ *    These codes are used to show what type of (sub)section, etc. would
+ *    contain a particular Option entry within the configuration.  In
+ *    this context, the codes are selector indices (e.g. switch statement
+ *    values) and are not intended to be ORed together as a bit mask.
+ *
+ *    These codes can also be used to show which active configuration
+ *    (sub)sections, etc. are to be modified.  In this context, the
+ *    codes are flag bits that can be ORed together.
+ *
+ *    Beyond that, these values are arbitrary.
+ */
+typedef enum {
+	FBC_SECTION_NONE    = 0x0000,	/* Nothing (initial/zero state)	*/
+	FBC_SECTION_Screen  = 0x0001,	/* Screen  section		*/
+	FBC_SUBSCTN_Display = 0x0002,	/* Display subsection		*/
+	FBC_SECTION_Monitor = 0x0004,	/* Monitor section		*/
+	FBC_SECTION_Device  = 0x0008,	/* Device  section		*/
+/*	FBC_ENTRY_Mode	    = 0x0010	** ModeLine / Mode-EndMode entry */
+} sectn_mask_t;
+
+/*
+ * Array element describing a config Option entry to be inserted or updated
+ */
+typedef struct {
+	sectn_mask_t	section;	/* Option entry [sub]section code */
+	const char	*name;		/* Option entry name string */
+	const char	*value;		/* Option entry value string */
+} xf86_opt_mod_t;
+
+/*
+ * Definitions for command line processing and configuration entries
+ */
+	/*
+	 * Prefix character used to mark pseudo-Option entries
+	 *
+	 *    Pseudo-Option entry names (e.g., "#Gamma") are placed in
+	 *    the .Option_mods[] array to help detect conflicting
+	 *    command line option values and to implement a radio-button
+	 *    behavior among related options.
+	 */
+#define	FBC_PSEUDO_PREFIX	"#"	/* Not a legal Option name character */
+
+	/* -clone */
+#define	FBC_SECTN_Clone		FBC_SECTION_Screen
+#define	FBC_KEYWD_Clone		"Clone"
+
+	/* -defaults */
+#define	FBC_SECTN_Defaults	FBC_SECTION_NONE
+#define	FBC_KEYWD_Defaults	NULL
+
+	/* -defaultdepth 8|24 */
+#define	FBC_NO_DefaultDepth	(0)	/* No DefaultDepth value */
+
+	/* -deflinear true|false */
+#define	FBC_SECTN_DefLinear	FBC_SUBSCTN_Display
+#define	FBC_KEYWD_DefLinear	"DefLinear"
+
+	/* -defoverlay true|false */
+#define	FBC_SECTN_DefOverlay	FBC_SUBSCTN_Display
+#define	FBC_KEYWD_DefOverlay	"DefOverlay"
+
+	/* -deftransparent true|false */
+#define	FBC_SECTN_DefTransparent FBC_SUBSCTN_Display
+#define	FBC_KEYWD_DefTransparent "DefTransparent"
+
+	/* -dev <device> */
+#define	FBC_SECTN_Device	FBC_SECTION_Device
+#define	FBC_KEYWD_Device	"Device"
+
+	/* -doublehigh enable|disable */
+#define	FBC_SECTN_DoubleHigh	FBC_SECTION_Screen
+#define	FBC_KEYWD_DoubleHigh	"DoubleHigh"
+
+	/* -doublewide enable|disable */
+#define	FBC_SECTN_DoubleWide	FBC_SECTION_Screen
+#define	FBC_KEYWD_DoubleWide	"DoubleWide"
+
+	/* -fake8 enable|disable */
+#define	FBC_SECTN_Fake8		FBC_SECTION_Screen
+#define	FBC_KEYWD_Fake8		"Fake8"
+
+	/* -file machine|system|<config-path> */
+#define	FBC_SECTN_File		FBC_SECTION_NONE
+#define	FBC_KEYWD_File		NULL
+
+	/* -g <gamma-value> */
+#define	FBC_SECTN_Gamma		FBC_SECTION_Monitor
+#define	FBC_KEYWD_Gamma		"Gamma"
+#define	FBC_NO_Gamma		(-1.0)	/* No Gamma correction value */
+#define	FBC_VALID_Gamma(_gamma)	(((_gamma) >= 1.0) && ((_gamma) <= 10.0))
+
+	/* -gfile <gamma-file> */
+#define	FBC_SECTN_GFile		FBC_SECTION_Monitor
+#define	FBC_KEYWD_GFile		"GFile"
+
+	/* -help */
+#define	FBC_SECTN_Help		FBC_SECTION_NONE
+#define	FBC_KEYWD_Help		NULL
+
+	/* -multisample disable|available|forceon */
+#define	FBC_SECTN_Multisample	FBC_SECTION_Screen
+#define	FBC_KEYWD_Multisample	"Multisample"
+
+	/* -offset <xoff> <yoff> */
+#define	FBC_SECTN_StreamXOffset	FBC_SECTION_Screen
+#define	FBC_KEYWD_StreamXOffset	"StreamXOffset"
+
+#define	FBC_SECTN_StreamYOffset	FBC_SECTION_Screen
+#define	FBC_KEYWD_StreamYOffset	"StreamYOffset"
+
+	/* -outputs swapped|direct */
+#define	FBC_SECTN_Outputs	FBC_SECTION_Screen
+#define	FBC_KEYWD_Outputs	"Outputs"
+
+	/* -prconf */
+#define	FBC_SECTN_PrConf	FBC_SECTION_NONE
+#define	FBC_KEYWD_PrConf	NULL
+
+	/* -predid */
+#define	FBC_SECTN_PrEDID	FBC_SECTION_NONE
+#define	FBC_KEYWD_PrEDID	NULL
+
+	/* -propt */
+#define	FBC_SECTN_PrOpt		FBC_SECTION_NONE
+#define	FBC_KEYWD_PrOpt		NULL
+
+	/* -res ? */
+	/* -res <video-mode> [nocheck] [noconfirm] [try] [now] */
+#define	FBC_SECTN_Res		FBC_SUBSCTN_Display
+#define	FBC_KEYWD_Res		NULL
+#define	FBC_NO_MODE_NAME	NULL	/* No video mode name string */
+
+#define	FBC_SECTN_StereoEnable	FBC_SUBSCTN_Display
+#define	FBC_KEYWD_StereoEnable	"StereoEnable"
+
+	/* -rscreen enable|disable */
+#define	FBC_SECTN_RScreen	FBC_SECTION_Screen
+#define	FBC_KEYWD_RScreen	"RemoteScreen"
+
+	/* -samples 1|4|8|16 */
+#define	FBC_SECTN_Samples	FBC_SECTION_Screen
+#define	FBC_KEYWD_Samples	"Samples"
+
+	/* -slave disable|multiview */
+#define	FBC_SECTN_MultiviewMode	FBC_SECTION_Screen
+#define	FBC_KEYWD_MultiviewMode	"MultiviewMode"
+
+
+/*
+ * Configuration entries to be modified or inserted
+ */
+typedef struct {
+	/*
+	 * Screen section explicit entries  (see XF86ConfScreenRec)
+	 */
+	int	scrn_defaultdepth;	/* Default depth (8|24), else zero */
+	/*
+	 * Monitor section explicit entries  (see XF86ConfMonitorRec)
+	 */
+	float	mon_gamma_red;		/* Red   gamma, else FBC_NO_Gamma */
+	float	mon_gamma_green;	/* Green gamma value, else undefined */
+	float	mon_gamma_blue;		/* Blue  gamma value, else undefined */
+	/*
+	 * "-res <video_mode>" command line option
+	 */
+	fbc_video_mode_t video_mode;	/* Video mode (e.g. ModeLine) name */
+
+	/*
+	 * Option entry modification descriptors
+	 *
+	 *    This can include descriptors for pseudo-Options.  Pseudo
+	 *    Options are explicitly named entries, such as "Gamma,"
+	 *    that are placed in this array as part of the mechanism to
+	 *    detect conflicting entries, such as "Gamma" (-g) and the
+	 *    "GFile" Option (-gfile).
+	 */
+	int		Option_mods_size; /* Option_mods[] array size */
+	int		Option_mods_num; /* # of Option_mods[] entries */
+	xf86_opt_mod_t *Option_mods;	/* Option entries to be modified */
+
+} xf86_ent_mod_t;
+
+
+/*
+ * Preferred video mode/resolution for monitor
+ *
+ *    Case-insensitive "NONE" is accepted as an argument to the -res
+ *    command line option.  Later it is translated to uppercase "AUTO"
+ *    and isn't recognized thereafter.
+ */
+#define	FBC_RESNAME_PREFERRED	"AUTO"	/* Preferred resolution for monitor */
+#define	FBC_RESNAME_NONE	"NONE"	/* Accepted only as a -res argument */
+
+
+#endif	/* _FBC_XORG_H */
+
+
+/* End of fbc_xorg.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/fbconf_xorg.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,698 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * fbconf_xorg - Frame buffer configuration program for Xorg
+ */
+
+
+#include <sys/param.h>		/* MAXPATHLEN */
+#include <sys/types.h>
+#include <sys/stat.h>		/* stat(), umask() */
+#include <libgen.h>		/* basename() */
+#include <stdio.h>		/* fprintf(), printf(), putc() */
+#include <stdlib.h>		/* exit() */
+#include <string.h>		/* memcpy(), strcat(), strcpy() */
+#include <unistd.h>		/* geteuid(), getuid(), seteuid(), unlink() */
+
+#include "xf86Parser.h"		/* Public function, etc. declarations */
+#include "Configint.h"		/* Private definitions, xf86confcalloc() ... */
+#include "configProcs.h"	/* Private function, etc. declarations */
+
+#include "sun_edid.h"		/* EDID data parsing */
+
+#include "fbc.h"		/* Common fbconf_xorg(1M) definitions */
+#include "fbc_xorg.h"		/* Edit config file data representations */
+
+#include "fbc_Device.h"		/* Edit Device sections */
+#include "fbc_Option.h"		/* Edit Option lists */
+#include "fbc_ask.h"		/* User interaction */
+#include "fbc_dev.h"		/* Identify the graphics device (-dev opt) */
+#include "fbc_edit_config.h"	/* Write an updated config file */
+#include "fbc_error.h"		/* Error reporting */
+#include "fbc_gamma_table.h"	/* Read, pack, and write a gamma table */
+#include "fbc_getargs.h"	/* Program command line processing */
+#include "fbc_get_properties.h"	/* Get fbconf_xorg(1M) program properties */
+#include "fbc_mode_list.h"	/* List of Modes from the config file */
+#include "fbc_open_device.h"	/* Open the frame buffer device */
+#include "fbc_propt.h"		/* Display the current option settings */
+#include "fbc_properties.h"	/* fbconf_xorg(1M) program properties */
+#include "fbc_res.h"		/* Video modes/resolutions (-res option) */
+#include "fbc_write_config.h"	/* Write an updated config file */
+
+
+/*
+ * fbc_check_args()
+ *
+ *    Make sure all program command line argument strings are properly
+ *    terminated within a reasonable number of characters.  See Bug
+ *    4031253, reported for ffbconfig circa 10 Feb 1997.
+ *
+ *    Command line option strings generally don't exceed 16 characters
+ *    (e.g., "-deftransparent").  The longest argument strings would be
+ *    pathnames (e.g. for -gfile).  A string longer than MAXPATHLEN
+ *    (typically 1024) characters would be expected to fail anyway for
+ *    one reason or another.
+ *
+ *    If this function segfaults despite all precautions, the caller has
+ *    insured that it'll happen while the user is executing as himself.
+ *
+ *    Note that the fbc_prog_name string used by fbc_errormsg() has been
+ *    set at build time to something useable.  The argv[0] string isn't
+ *    trusted until everything checks out.
+ */
+
+#define	MAX_ARG_LEN	(MAXPATHLEN + 32) /* Reasonable length plus slack */
+
+static
+void
+fbc_check_args(
+	const int	argc,		/* Program argument count */
+	char	*const	argv[])		/* Program argument vector */
+{
+	int		arg;		/* Program command line arg index */
+	size_t		len;		/* Length of argument string */
+	const char	*ptr;		/* Pointer into argument string */
+
+	/*
+	 * Make sure something exists resembling an argument vector
+	 */
+	if ((argc <= 0) || (argv == NULL)) {
+		fbc_errormsg("Program argument vector is missing\n");
+		exit(FBC_EXIT_USAGE);
+	}
+
+	/*
+	 * Make sure all argument strings are properly Nul-terminated, etc.
+	 */
+	for (arg = 0; arg < argc; arg += 1) {
+		if (argv[arg] == NULL) {
+			fbc_errormsg("Program argument %d is missing\n", arg);
+			exit(FBC_EXIT_USAGE);
+		}
+		len = 0;
+		for (ptr = argv[arg]; *ptr != '\0'; ptr += 1) {
+			if (len >= MAX_ARG_LEN) {
+				fbc_errormsg(
+				"Program argument %d is unacceptably long\n",
+						arg);
+				exit(FBC_EXIT_USAGE);
+			}
+			len += 1;
+		}
+	}
+
+	/*
+	 * Make sure the argument vector is NULL-terminated
+	 */
+	if (argv[argc] != NULL) {
+		fbc_errormsg("Program argument vector is not terminated\n");
+		exit(FBC_EXIT_USAGE);
+	}
+
+}	/* fbc_check_args() */
+
+
+/*
+ * main()
+ *
+ *    Main function for the fbconf_xorg(1M) frame buffer configuration
+ *    program for Xorg.
+ */
+
+int
+main(
+	const int	argc,		/* Program argument count */
+	char	*const	argv[])		/* Program argument vector */
+{
+	const char	*config_file_path; /* Name from xf86openConfigFile() */
+	XF86ConfigPtr	configIR;	/* Config file Internal Rep */
+	fbc_dev_t	device;		/* Frame buffer device info (-dev) */
+	const char	*device_arg;	/* Effective argument to -dev option */
+	char		device_path_buf[FBC_MAX_DEV_PATH_LEN];
+	char		device_type_buf[FBC_MAX_DEV_PATH_LEN];
+	uid_t		euid;		/* Effective user ID */
+	int		exit_code;	/* Program exit code */
+	fbc_varient_t	fbvar;		/* fbconf_xorg(1M) varient data */
+	char		gfile_out_path[MAXPATHLEN]; /* Gamma table path */
+	char		mode_name_buf[FBC_MAX_MODE_NAME_LEN]; /* Video mode */
+	sectn_mask_t	ref_config;	/* Referenced config sections, etc. */
+	uid_t		uid;		/* Real user ID */
+
+	/*
+	 * For security, neutralize the EUID except when accessing system files
+	 */
+	euid = geteuid();
+	uid  = getuid();
+	if (euid != uid) {
+		if (seteuid(uid) != 0) {
+			fbc_errormsg("Unable to change effective user ID\n");
+			return (FBC_EXIT_FAILURE);
+		}
+	}
+
+	/*
+	 * Safely validate all command line argument strings
+	 *
+	 *    This is an suid program.  Bug 4031253 involves a buffer
+	 *    overflow attack that uses an exec(2) call to pass a
+	 *    non-string argument to ffbconfig, which is invoked with
+	 *    superpowers.
+	 */
+	fbc_check_args(argc, argv);
+
+	/*
+	 * Zero all of the fbconf_xorg(1M) parameters
+	 */
+	memset(&fbvar, 0, sizeof (fbvar));
+
+	/*
+	 * Get the program name for diagnostic messages
+	 */
+	fbvar.prog_name = basename(argv[0]);	/* For usage display */
+	fbc_prog_name   = fbvar.prog_name;	/* For error messages */
+
+	/*
+	 * Use generic fbconf_xorg properties until the actual device is known
+	 *
+	 *    This enables minimal usage text display, sets basic
+	 *    defaults, etc.
+	 */
+	fbc_get_base_properties(&fbvar);
+
+	/*
+	 * Determine the device pathname (-dev argument) and open it
+	 *
+	 *    The device pathname (explicitly named or resolved from the
+	 *    "/dev/fb" or "/dev/fb0" symbolic link) does the following:
+	 *      * Specifies which device file to open, which in turn
+	 *        yeilds the VISUAL identifier string (e.g. "SUNWkfb"):
+	 *          * Helps to confirm the device's validity
+	 *          * Determines which device-specific library to
+	 *            dynamically open and use (e.g. libSUNWkfb_conf.so)
+	 *          * Helps to match master and slave devices
+	 *      * Specifies which Device section to find (or create) in
+	 *        the configuration file
+	 *      * Gives the name for the Device section's Driver entry
+	 *        (e.g. "kfb")
+	 *      * Contains a unit number (which may have a future use)
+	 *      * May may include a stream letter (e.g. "a" or "b")
+	 */
+	(void) fbc_get_device_arg(argc, argv, &device_arg);
+	if (device_arg == NULL) {
+		/*
+		 * Determine the default device, which includes opening it
+		 */
+		if (fbc_get_default_device(device_path_buf,
+					sizeof (device_path_buf),
+					device_type_buf,
+					sizeof (device_type_buf),
+					&device) != FBC_SUCCESS) {
+			fbc_errormsg("Unable to open default device\n");
+			return (FBC_EXIT_FAILURE);
+		}
+	} else {
+		/*
+		 * Parse the -dev device name argument
+		 */
+		if (fbc_get_device_name(device_arg,
+				device_path_buf, sizeof (device_path_buf),
+				device_type_buf, sizeof (device_type_buf),
+				&device) != FBC_SUCCESS) {
+			fbvar.usage(stderr, &fbvar);
+			return (FBC_EXIT_USAGE);
+		}
+
+		/*
+		 * Open the -dev device and get the VISUAL env identifier name
+		 *
+		 *    The VISUAL environment identifier, rather than the
+		 *    device name, determines which libSUNWxxx_conf.so
+		 *    library is needed with this frame buffer device.
+		 *    The device name still should agree with the
+		 *    identifier name (e.g."kfb0" w/ "SUNWkfb").
+		 */
+		if (fbc_open_device(&device) != FBC_SUCCESS) {
+			/* Error message has been displayed, so just exit */
+			return (FBC_EXIT_FAILURE);
+		}
+	}
+
+	/*
+	 * Initialize the default state for the -file command line option
+	 *
+	 *    The configuration file location is not likely to be device
+	 *    dependent, but it could be changed via the call to
+	 *    fbc_get_properties() below.
+	 */
+	fbvar.config_file_loc    = fbc_keywds_file[0].argv_name;
+	fbvar.config_file_path   = fbc_keywds_file[0].conf_name;
+	fbvar.config_search_path = fbc_config_search_path;
+
+	/*
+	 * Establish device-specific properties and fbconf_xorg(1M) behavior
+	 */
+	if (fbc_get_properties(&device, &fbvar) != FBC_SUCCESS) {
+		return (FBC_EXIT_FAILURE);	/* Unknown device type, etc. */
+	}
+	fbc_revise_device_info(&device);	/* Revise the streams info */
+
+	/*
+	 * Communicate gamma table pathname info with the -gfile option handler
+	 */
+	fbvar.gfile_in_path  = NULL;		/* No input gamma file path */
+	fbvar.gfile_out_path = NULL;		/* No output gamma file path */
+
+	/*
+	 * No dynamically allocated gamma table packed data strings yet
+	 */
+	fbvar.gamma_string_red   = NULL;
+	fbvar.gamma_string_green = NULL;
+	fbvar.gamma_string_blue  = NULL;
+
+	/*
+	 * Evaluate the program command line
+	 *
+	 *    The fbc_get_properties() code path above is able to
+	 *    provide a wrapper for fbc_getargs() or to replace it
+	 *    altogether, should that be necessary.
+	 */
+	fbvar.getargs(argc, argv, &fbvar);
+
+	/*
+	 * If the program command line is a no-op, display usage and terminate
+	 *
+	 *    The command line is a no-op if none of these operations
+	 *    has been requested:
+	 *      * Display help text (-help)
+	 *      * Display the frame buffer device configuration (-prconf)
+	 *      * Display EDID data from the display device (-predid)
+	 *      * Display the software configuration (-propt)
+	 *      * Display a video modes/resolutions list (-res ?)
+	 *      * Modify one or more entries in the configuration file
+	 *
+	 *    It would be a no-op, for instance, if only -dev and/or
+	 *    -file is specified.
+	 */
+	if (!fbvar.option_set.help &&
+	    !fbvar.option_set.prconf &&
+	    !(fbvar.option_set.predid_raw || fbvar.option_set.predid_parsed) &&
+	    !fbvar.option_set.propt &&
+	    !fbvar.option_set.res_list &&
+	    (fbvar.modify_config == FBC_SECTION_NONE)) {
+		fbvar.usage(stderr, &fbvar);
+		return (FBC_EXIT_SUCCESS);
+	}
+
+	/*
+	 * If -help was specified, display device-specific program help text
+	 *
+	 *    If -help and/or -res ? was specified, the program will
+	 *    terminate immediately upon satisfying those request(s).
+	 */
+	if (fbvar.option_set.help) {
+		fbvar.help(&fbvar);
+		if (!fbvar.option_set.res_list) {
+			return (FBC_EXIT_SUCCESS);
+		}
+	}
+
+	/*
+	 * Restore the effective UID while reading the config file
+	 */
+	if (euid != uid) {
+		(void) seteuid(euid);
+	}
+
+	/*
+	 * Search for and open the input configuration file
+	 */
+	config_file_path = xf86openConfigFile(fbvar.config_search_path,
+						fbvar.config_file_path,
+						NULL);
+	if (config_file_path != NULL) {
+		/*
+		 * Save the pathname of the opened input config file
+		 */
+		fbvar.config_file_path = config_file_path;
+
+		/*
+		 * Read the input configuration file
+		 */
+		configIR = xf86readConfigFile();
+		if (configIR == NULL) {
+			fbc_errormsg("Error in configuration file\n");
+			fbc_close_down_config();
+			return (FBC_EXIT_FAILURE);
+		}
+	}
+
+	/*
+	 * Neutralize the EUID again
+	 */
+	if (euid != uid) {
+		if (seteuid(uid) != 0) {
+			fbc_errormsg("Unable to change effective user ID\n");
+			return (FBC_EXIT_FAILURE);
+		}
+	}
+
+	/*
+	 * If no config file, allocate and zero the config IR structure
+	 */
+	if (config_file_path == NULL) {
+		configIR = xf86confcalloc(1, sizeof (XF86ConfigRec));
+		if (configIR == NULL)
+		{
+			fbc_errormsg("Insufficient memory\n");
+			return (FBC_EXIT_FAILURE);
+		}
+	}
+
+	/*
+	 * Find the active/target config sections for this device
+	 *
+	 *    Sections that are required by Xorg or that are referenced
+	 *    based on the command line will be created if they are not
+	 *    found.  The -res option is an implied reference to the
+	 *    Monitor section or the Modes sections it may reference.
+	 */
+	ref_config = fbvar.modify_config;
+	if (fbvar.option_set.res_list ||
+	    (fbvar.xf86_entry_mods.video_mode.name != NULL)) {
+		ref_config |= FBC_SECTION_Monitor;
+	}
+	if (fbc_find_active_sections(&device, &fbvar, configIR, ref_config)
+					!= 0) {
+		fbc_close_down_config();
+		return (FBC_EXIT_FAILURE);
+	}
+
+	/*
+	 * If -res ? was specified, display the video mode names and terminate
+	 */
+	if (fbvar.option_set.res_list) {
+		fbc_res_list_modes(&device, &fbvar, configIR);
+		fbc_close_down_config();
+		return (FBC_EXIT_SUCCESS);
+	}
+
+	/*
+	 * If -res <video_mode> was specified, validate & canonicalize the mode
+	 *
+	 *    The video mode name is passed to and from the function via
+	 *    the fbvar.xf86_entry_mods.video_mode structure.  The
+	 *    mode_name_buf buffer may be needed for canonicalization.
+	 */
+	if (fbvar.xf86_entry_mods.video_mode.name != FBC_NO_MODE_NAME) {
+		if (!fbc_res_validate_mode(configIR,
+					&device,
+					&fbvar,
+					mode_name_buf,
+					sizeof (mode_name_buf),
+					&fbvar.xf86_entry_mods.video_mode)) {
+			fbc_close_down_config();
+			return (FBC_EXIT_USAGE);  /* Invalid video mode name */
+		}
+	}
+
+	/*
+	 * See if there's any work to do involving a gamma file (-gfile)
+	 */
+	if (fbvar.gfile_in_path != NULL) {
+		/*
+		 * Construct the output gamma table pathname for this device
+		 *
+		 *    This must be done after xf86openConfigFile() is
+		 *    called, so the config file pathname will be known,
+		 *    and before the call to fbc_edit_active_sections(),
+		 *    which might use this gamma table pathname as the
+		 *    "GFile" Option entry value.
+		 */
+		if (fbc_build_gamma_table_path(fbvar.config_file_path,
+						device.name,
+						gfile_out_path,
+						sizeof (gfile_out_path))
+					!= FBC_SUCCESS) {
+			fbc_close_down_config();
+			return (FBC_EXIT_FAILURE);
+		}
+
+		/*
+		 * See if we'll be removing an old file or creating a new one
+		 */
+		if (*fbvar.gfile_in_path != '\0') {
+			/*
+			 * Read and pack the gamma correction table
+			 */
+			if (fbc_read_gamma_table(fbvar.gfile_in_path,
+						fbvar.lut_size,
+						&fbvar.gamma_string_red,
+						&fbvar.gamma_string_green,
+						&fbvar.gamma_string_blue)
+					!= 0) {
+				fbc_close_down_config();
+				return (FBC_EXIT_FAILURE);
+			}
+
+			/*
+			 * Fix the modification descriptor for the "GFile" Opt
+			 *
+			 *    See commentary in fbc_Option_GFile().
+			 */
+			if (fbvar.gfile_out_path != NULL) {
+				*fbvar.gfile_out_path = gfile_out_path;
+			}
+		}
+	}
+
+	/*
+	 * See whether we're modifying the configuration
+	 */
+	if (fbvar.modify_config != FBC_SECTION_NONE) {
+		/*
+		 * Edit the in-memory copy of the config sections
+		 */
+		(void) fbc_edit_active_sections(
+			configIR, &fbvar.active, &fbvar.xf86_entry_mods);
+
+		/*
+		 * Apply any constraints on the results (e.g., memory limits)
+		 */
+		if (fbvar.revise_settings != NULL) {
+			if (fbvar.revise_settings(&fbvar) != FBC_SUCCESS) {
+				fbc_close_down_config();
+				return (FBC_EXIT_FAILURE);
+			}
+		}
+
+		/*
+		 * Do any device initialization
+		 */
+		if (fbvar.init_device != NULL) {
+			if (fbvar.init_device(&device, &fbvar)
+					!= FBC_SUCCESS) {
+				fbc_close_down_config();
+				return (FBC_EXIT_FAILURE);
+			}
+		}
+
+		/*
+		 * If "-res try", give the new video mode a 10-second trial
+		 *
+		 *    The "try" keyword should not have been recognized
+		 *    if there is no res_mode_try() function.  Treat
+		 *    such an anomoly as an unsuccessful trial (drawing
+		 *    attention to the need to fix the code in
+		 *    SUNWxxx_get_properties(), etc.).
+		 */
+		if (fbvar.option_set.res_mode_try) {
+			if ((fbvar.res_mode_try == NULL) ||
+			    !fbvar.res_mode_try(
+				&device, &fbvar.xf86_entry_mods.video_mode)) {
+				fbc_errormsg(
+			"Unsuccessful video mode trial.  No changes made!\n");
+				fbc_close_down_config();
+				return (FBC_EXIT_FAILURE);
+			}
+			printf("Video resolution will be set to \"%s\"\n",
+				fbvar.xf86_entry_mods.video_mode.name);
+		}
+	}
+
+	/*
+	 * Identify the active video Mode, if any
+	 *
+	 *    This is done for the benefit of the -propt display code.
+	 *    It must be done after the -res <video-mode> has been
+	 *    executed.
+	 */
+	(void) fbc_find_active_mode(fbvar.modify_config, &fbvar.active);
+
+	/*
+	 * If -prconf was specified, display current hardware configuration
+	 */
+	if (fbvar.option_set.prconf) {
+		printf("\n--- Hardware Configuration for %s ---\n\n",
+			device.path);
+		fbvar.prconf(&device, &fbvar, configIR);
+		putc('\n', stdout);
+	}
+
+	/*
+	 * If -predid was specified, display the EDID data
+	 */
+	if (fbvar.option_set.predid_raw || fbvar.option_set.predid_parsed) {
+		printf("\n--- EDID Data for %s ---\n\n", device.path);
+		fbvar.predid(&device, &fbvar);
+		putc('\n', stdout);
+	}
+
+	/*
+	 * If -propt was specified, display the current config option settings
+	 *
+	 *    This should be executed after any modifications to the in-
+	 *    memory configuration are made.
+	 */
+	if (fbvar.option_set.propt) {
+		printf("\n--- Graphics Configuration for %s ---\n",
+			device.path);
+		fbc_propt(&fbvar);
+		putc('\n', stdout);
+	}
+
+	/*
+	 * Write the updated config and any gamma file, and close everything
+	 */
+	exit_code = FBC_EXIT_SUCCESS;
+
+	if (fbvar.modify_config != FBC_SECTION_NONE) {
+		/*
+		 * Announce config file creation if no input file was found
+		 */
+		if (config_file_path == NULL) {
+			printf("New configuration file, %s\n",
+				fbvar.config_file_path);
+		}
+
+		/*
+		 * Set the file mode creation mask to limit modes to 644
+		 */
+		(void) umask(022);
+
+		/*
+		 * Restore the effective UID while writing config & gamma files
+		 */
+		if (euid != uid) {
+			(void) seteuid(euid);
+		}
+
+		/*
+		 * Write the updated config file and close down config stuff
+		 */
+		if (fbc_write_config(&fbvar, configIR) != FBC_SUCCESS) {
+			fbc_errormsg("Unable to update config file, %s\n",
+					fbvar.config_file_path);
+			exit_code = FBC_EXIT_FAILURE;
+		}
+
+		/*
+		 * If -gfile was specified, update the gamma correction table
+		 */
+		if ((exit_code == FBC_EXIT_SUCCESS) &&
+					(fbvar.gfile_in_path != NULL)) {
+			if (*fbvar.gfile_in_path == '\0') {
+				/*
+				 * Delete any now obsolete gamma table file
+				 */
+				unlink(gfile_out_path);
+			} else {
+				/*
+				 * Create the new packed gamma table file
+				 */
+				if (fbc_write_packed_gamma_table(
+						gfile_out_path,
+						fbvar.gamma_string_red,
+						fbvar.gamma_string_green,
+						fbvar.gamma_string_blue)
+							!= FBC_SUCCESS) {
+					exit_code = FBC_EXIT_FAILURE;
+				}
+			}
+		}
+
+		/*
+		 * Neutralize the effective UID again
+		 */
+		if (euid != uid) {
+			if (seteuid(uid) != 0) {
+				fbc_errormsg(
+				    "Unable to change effective user ID\n");
+				fbc_close_down_config();
+				return (FBC_EXIT_FAILURE);
+			}
+		}
+	} else {
+		/*
+		 * Close down the unmodified config file(s) and IR & ER memory
+		 */
+		fbc_close_down_config();
+	}
+
+	/*
+	 * If "-res now" was specified, set the new video mode now
+	 */
+	if (fbvar.option_set.res_mode_now) {
+		if ((fbvar.res_mode_now == NULL) ||
+		    (fbvar.res_mode_now(&device,
+					&fbvar.xf86_entry_mods.video_mode)
+						!= FBC_SUCCESS)) {
+			fbc_errormsg("Unable to set new video mode now\n");
+			exit_code = FBC_EXIT_FAILURE;
+		} else {
+			printf("Video mode has been set to \"%s\"\n",
+				fbvar.xf86_entry_mods.video_mode.name);
+		}
+	}
+
+	/*
+	 * Release the config file pathname
+	 */
+	xf86conffree((char *)config_file_path);
+
+	/*
+	 * Release any packed gamma correction value strings
+	 */
+	fbc_free_gamma_strings(fbvar.gamma_string_red,
+				fbvar.gamma_string_green,
+				fbvar.gamma_string_blue);
+
+	/*
+	 * Terminate ourselves, indicating the state of things
+	 */
+	return (exit_code);
+
+}	/* main() */
+
+
+/* End of fbconf_xorg.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/resolutions.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,214 @@
+
+/*
+ * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 <stdio.h>		/* NULL */
+
+#include "resolutions.h"	/* Video mode summary table: SunVideoTable[] */
+
+
+const SunVideoSummary SunVideoTable[] = {
+
+/* 720x400x85 from VESA standard 1.0r7, 12/18/96 */
+  {"VESA_STD_720x400x85", 720,400,85, 36,72,108, 1,3,42, 35500, 0,0, 1, 0,1},
+
+/* r640x480x60 from VESA Monitor Timing Standards Version 1.0, Industry
+ * Practice */
+  {"VESA_STD_640x480x60", 640,480,60, 16,96,48, 10,2,33, 25175, 0,0, 1, 0,0},
+
+
+/* r640x480x72 from VESA Monitor Timing Standard VS901101 12/2/92 */
+  {"VESA_STD_640x480x72", 640,480,72, 24,40,128, 9,3,28, 31500, 0,0, 1, 0,0},
+
+/* r640x480x75 from VESA Monitor Timing Standard VDMT75HZ 10/4/93 */
+  {"VESA_STD_640x480x75", 640,480,75, 16,64,120, 1,3,16, 31500, 0,0, 1, 0,0},
+
+/* r640x480x180fsc from Clayton Castle 10/2/01 */
+  {"SUNW_STD_640x480x180", 640,480,180, 40,80,120, 1,3,36, 82350, 0,0, 0, 0,0},
+
+/* 800x600x56 from VESA standard 1.0r7, 12/18/96 */
+  {"VESA_STD_800x600x56", 800,600,56, 24,72,128, 1,2,22, 36000, 0,0, 1, 1,1},
+
+/* 800x600x60 from VESA standard 1.0r7, 12/18/96 */
+  {"VESA_STD_800x600x60", 800,600,60, 40,128,88, 1,4,23, 40000, 0,0, 1, 1,1},
+
+/* 800x600x72 from VESA standard 1.0r7, 12/18/96 */
+  {"VESA_STD_800x600x72", 800,600,72, 56,120,64, 37,6,23, 50000, 0,0, 1, 1,1},
+
+/* r800x600x75 from VESA Standard VDMT75HZ */
+  {"VESA_STD_800x600x75", 800,600,75, 16,80,160, 1,3,21, 49500, 0,0, 1, 1,1},
+
+/* 800x600x85 from VESA standard 1.0r7, 12/18/96 */
+  {"VESA_STD_800x600x85", 800,600,85, 32,64,152, 1,3,27, 56250, 0,0, 1, 1,1},
+
+
+/* r960x680x108 stereo from ZX 10/21/94 */
+  {"SUNW_STEREO_960x680x108", 960,680,108, 64,64,192, 3,4,34, 99900, 0,0, 0, 0,0},
+
+/* r960x680x112s stereo from ZX 10/21/94 */
+  {"SUNW_STEREO_960x680x112", 960,680,112, 24,48,216, 2,8,32, 101250, 0,0, 0, 0,0},
+
+/* r1024x768x60 from VESA Monitor Timing Standards Version 1.0 */
+  {"VESA_STD_1024x768x60", 1024,768,60, 24,136,160, 3,6,29, 65000, 0,0, 1, 0,0},
+
+/* r1024x768x70 from VESA Monitor Timing Standards VS910801-2 8/9/91 */
+  {"VESA_STD_1024x768x70", 1024,768,70, 24,136,144, 3,6,29, 75214, 0,0, 1, 0,0},
+
+/* r1024x768x75 from VESA Monitor Timing Standards Version 1.0 */
+  {"VESA_STD_1024x768x75", 1024,768,75, 16,96,176, 1,3,28, 78750, 0,0, 1, 1,1},
+
+/* r1024x768x77 from 15" monitor spec 950-1915-01 rev 51 10/21/94 */
+  {"SUNW_STD_1024x768x77", 1024,768,77, 32,64,240, 2,4,31, 84375, 0,0, 0, 0,0},
+
+/* 1024x768x85 from VESA standard 1.0r7, 12/18/96 */
+  {"VESA_STD_1024x768x85", 1024,768,85, 48,96,208, 1,3,36, 94500, 0,0, 1, 1,1},
+
+/* r1024x800x84 from tgxplus bootprom 1/6/95 */
+  {"SUNW_STD_1024x800x84", 1024,800,86, 16,128,152, 2,4,31, 94500, 0,0, 0, 0,0},
+
+/* 1152x864x75 from VESA standard 1.0r7, 12/18/96 */
+  {"VESA_STD_1152x864x75", 1152,864,75, 64,128,256, 1,3,32, 108000, 0,0, 1, 1,1},
+
+/* r1152x900x66 from 20" monitor spec 950-1695-01 Rev11 1/6/95  */
+  {"SUNW_STD_1152x900x66", 1152,900,66, 40,128,208, 2,4,31, 94500, 0,0, 0, 0,0},
+
+/* r1152x900x76 from 20" monitor spec 950-1695-01 Rev11 1/6/95 */
+  {"SUNW_STD_1152x900x76", 1152,900,76, 32,128,192, 2,8,33, 108000, 0,0, 0, 0,0},
+
+/* r1152x900x120s from John Martin 9/13/2000 */
+  {"SUNW_STEREO_1152x900x120", 1152,900,120, 64,136,216, 2,10,44, 180000, 0,1, 1, 1,1},
+ 
+/* r1280x768x56 Pioneer 50" Plasma */
+  {"SUNW_STD_1280x768x56", 1280,768,56, 48,112,248, 1,3,30, 76179, 0,0, 1, 0,0},
+
+/* r1280x800x76 from Michele Law 6/26/96 */
+  {"SUNW_STD_1280x800x76", 1280,800,76, 20,114,156, 3,7,36, 101250, 0,0, 0, 0,0},
+
+/* r1280x800x112s stereo from John Martin 2/15/2000 */
+  {"SUNW_STEREO_1280x800x112", 1280,800,112, 16,176,264, 2,8,36, 164700, 0,1, 1, 1,1},
+
+/* r1280x1024x60 from Michele Law from VESA 4/3/96 */
+  {"VESA_STD_1280x1024x60", 1280,1024,60, 48,112,248, 1,3,38, 108000, 0,0, 1, 1,1},
+
+/* The GH18PS flat panel asks for this (same as above, but Composite */
+  {"SUNW_STD_1280x1024x60", 1280,1024,60, 48,112,248, 1,3,38, 108000, 0,0, 0, 0,0},
+
+/* r1280x1024x67 from gx (lsc.ref) 10/21/94 */
+  {"SUNW_STD_1280x1024x67", 1280,1024,67, 16,112,224, 2,8,33, 117000, 0,0, 0, 0,0},
+
+/* r1280x1024x75 from VESA Standard VDMT75HZ 10/4/93 */
+  {"VESA_STD_1280x1024x75", 1280,1024,75, 16,144,248, 1,3,38, 135000, 0,0, 1, 1,1},
+
+/* r1280x1024x76 from gx (lsc.ref) 10/21/94 */
+  {"SUNW_STD_1280x1024x76", 1280,1024,76, 32,64,288, 2,8,32, 135000, 0,0, 0, 0,0},
+
+/* r1280x1024x85 from VESA Standard VDMTREV 12/18/96 */
+  {"VESA_STD_1280x1024x85", 1280,1024,85, 64,160,224, 1,3,44, 157500, 0,0, 1, 1,1},
+
+/* r1280x1024x96s alternate stereo for Barco 808 3/28/01 John Martin */
+  {"SUNW_STEREO_1280x1024x96", 1280,1024,96, 20,160,140, 3,6,30, 163280, 0,1, 1, 0,0},
+
+/* r1280x1024x108s stereo for Christie Digital Mirage 5/25/01 John Martin */
+  {"SUNW_STEREO_1280x1024x108", 1280,1024,108, 8,80,56, 2,4,6, 159300, 0,1, 1, 0,0},
+
+/* r1280x1024x112s from Tom Fussy 5/25/99 */
+  {"SUNW_STEREO_1280x1024x112", 1280,1024,112, 26,160,320, 1,8,47, 216000, 0,1, 1, 0,0},
+ 
+/* r1440x900x76.res from Michele Law 4/11/96 */
+  {"SUNW_STD_1440x900x76", 1440,900,76, 40,160,240, 2,3,39, 135000, 0,0, 0, 0,0},
+
+/* r1600x1000x66.res from Michele Law 6/24/96 */
+  {"SUNW_STD_1600x1000x66", 1600,1000,66, 40,136,192, 2,5,32, 135000, 0,0, 0, 0,0},
+
+/* r1600x1000x76.res from Michele Law 4/11/96 */
+  {"SUNW_STD_1600x1000x76", 1600,1000,76, 32,216,280, 2,3,46, 170100, 0,0, 0, 0,0},
+
+/* r1600x1024x60 SGI 1600SW FP analog  John Martin 7/25/2001 */
+  {"SGI_STD_1600x1024x60", 1600,1024,60, 16,56,36, 2,1,26, 107000, 0,0, 1, 0,0},
+
+/* r1600x1200x60 from VESA Standard VDMTREV 12/18/96 */
+  {"VESA_STD_1600x1200x60", 1600,1200,60, 64,192,304, 1,3,46, 162000, 0,0, 1, 1,1},
+
+/* r1600x1200x60d from Joe Miseli, Clayton Castle 4/11/2001 */
+  {"SUNW_DIG_1600x1200x60", 1600,1200,60, 4,64,106, 5,10,24, 132300, 0,0, 1, 1,1},
+
+/* 1600x1200x65 from VESA standard 1.0r7, 12/18/96 */
+  {"VESA_STD_1600x1200x65", 1600,1200,65, 64,192,304, 1,3,46, 175500, 0,0, 1, 1,1},
+
+/* 1600x1200x70 from VESA standard 1.0r7, 12/18/96 */
+  {"VESA_STD_1600x1200x70", 1600,1200,70, 64,192,304, 1,3,46, 189000, 0,0, 1, 1,1},
+
+/* r1600x1200x73 for Siemens SMM 21105 LS 10/25/01 */
+  {"SIEMENS_STD_1600x1200x73", 1600,1200,73, 88,216,296, 0,5,43, 200460, 0,0, 1, 1,1},
+
+/* r1600x1200x75 from VESA (1/9/97) */
+  {"VESA_STD_1600x1200x75", 1600,1200,75, 64,192,304, 1,3,46, 202500, 0,0, 1, 1,1},
+
+/* 1600x1200x85 from VESA standard 1.0r7, 12/18/96 */
+  {"VESA_STD_1600x1200x85", 1600,1200,85, 64,192,304, 1,3,46, 229500, 0,0, 1, 1,1},
+
+/* r1600x1280x76 from gx (lsc.ref) 10/24/94 */
+  {"SUNW_STD_1600x1280x76", 1600,1280,76, 24,216,280, 2,8,50, 216000, 0,0, 0, 0,0},
+
+/* r1792x1344x60 from VESA Standard 1.0 Rev 0.8 9/98 */
+  {"VESA_STD_1792x1344x60", 1792,1344,60, 128,200,328, 1,3,46, 204750, 0,0, 1, 0,1},
+ 
+/* r1792x1344x75 from VESA Standard 1.0 Rev 0.8 9/98 */
+  {"VESA_STD_1792x1344x75", 1792,1344,75, 96,216,352, 1,3,69, 261000, 0,0, 1, 0,1},
+ 
+/* r1856x1392x60 from VESA Standard 1.0 Rev 0.8 9/98 */
+  {"VESA_STD_1856x1392x60", 1856,1392,60, 96,224,352, 1,3,43, 219375, 0,0, 1, 0,1},
+ 
+/* r1856x1392x75 from VESA Standard 1.0 Rev 0.8 9/98 */
+  {"VESA_STD_1856x1392x75", 1856,1392,75, 128,224,352, 1,3,104, 288000, 0,0, 1, 0,1},
+
+/* r1920x1080x60d from Joe Miseli 4/11/01 */
+  {"SUNW_DIG_1920x1080x60", 1920,1080,60, 4,64,68, 2,4,26, 137700, 0,0, 1, 1,1},
+ 
+/* r1920x1080x72 from Marc Klingelhofer's HRV Workstation doc 10/21/94 */
+  {"SUNW_STD_1920x1080x72", 1920,1080,72, 48,216,376, 3,3,86, 216000, 0,0, 0, 0,0},
+
+/* r1920x1200x60d from Joe Miseli 4/11/01 */
+  {"SUNW_DIG_1920x1200x60", 1920,1200,60, 4,64,68, 2,4,28, 151200, 0,0, 1, 1,1},
+
+/* r1920x1200x70 from Michele Law 6/24/96 */
+  {"SUNW_STD_1920x1200x70", 1920,1200,70, 24,228,344, 1,3,36, 219375, 0,0, 0, 0,0},
+
+/* r1920x1200x75 from Michele Law */
+  {"SUNW_STD_1920x1200x75", 1920,1200,75, 64,224,352, 3,3,44, 239625, 0,0, 0, 0,0},
+
+/* r640x480x60i ntsc from calculation, monitor group and ZX 10/21/94  */
+  {"SUNW_INT_640x240x60", 640,240,60, 20,58,62, 3,3,16, 12273, 1,0, 0, 0,0},
+
+/* r768x575x50i pal from calculation, monitor group and ZX 10/21/94  */
+  {"SUNW_INT_768x287x50", 768,287,50, 14,70,84, 3,2,19, 14625, 0,0, 0, 0,0},
+
+/* 1400x1050 @60 for Sparc laptop with NatureTech lcd */
+  {"SUNW_DIG_1400x1050x60", 1400,1050,60, 6,112,170, 0,3,13, 108000, 0,0, 0, 0,0},
+
+  {NULL, 0,0,0, 0,0,0, 0,0,0, 0, 0,0, 1, 0,0}
+};
+
+
+/* End of resolutions.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/resolutions.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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	_RESOLUTIONS_H
+#define	_RESOLUTIONS_H
+
+
+/*
+ * Video mode summary table
+ */
+
+typedef	struct {
+	const char	*id_string;	/* e.g. "SUNW_STD_1280x1024x60" */
+	unsigned int	width;
+	unsigned int	height;
+	unsigned int	vfreq;		/* Rounded to nearest Hz */
+	unsigned int	Hfp;		/* Front porch */
+	unsigned int	Hsw;		/* Horizontal sync width */
+	unsigned int	Hbp;		/* Back porch */
+	unsigned int	Vfp;		/* Front porch */
+	unsigned int	Vsw;		/* Vertical sync width */
+	unsigned int	Vbp;		/* Back porch */
+	unsigned int	Pclk;		/* Pixel clock, kHz */
+	unsigned int	Fint  : 1;	/* Interlaced */
+	unsigned int	Fst   : 1;	/* Stereo */
+	unsigned int	Stype : 1;	/* Sync type (seperate, combined) */
+	unsigned int	SHpol : 1;	/* Horizontal polarity */
+	unsigned int	SVpol : 1;	/* Vertical polarity */
+} SunVideoSummary;
+
+extern const SunVideoSummary SunVideoTable[]; /* NULL-terminated */
+
+
+#endif	/* _RESOLUTIONS_H */
+
+
+/* End of resolutions.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/sun_edid.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,1976 @@
+/*
+ * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/* sun_edid - EDID data parsing */
+
+
+
+/*
+  ___________________________________________________________________________
+ /\									     \
+ \_|									     |
+   |  This module contains basic functions for parsing EDID data.	     |
+   |  The evolution of this code has been based on documents such as:	     |
+   |									     |
+   |	    "Extended Display Identification Data Standard Document,"	     |
+   |        Version 2, Revision 1, July 24th 1996.  (EDID 1.1)		     |
+   |									     |
+   |	    "VESA Enhanced Extended Display Identification Data Standard,"   |
+   |        Release A, Revision 1, February 9, 2000.  (EDID 1.3)	     |
+   |									     |
+   |	    "VESA Enhanced Extended Display Identification Data Standard,"   |
+   |        Release A, Revision 2, September 25, 2006.  (EDID 1.4)	     |
+   |									     |
+   |  For clarity, this module endeavors to use the same terminology and     |
+   |  hexadecimal and decimal constants (addresses, byte numbers, data	     |
+   |  values, etc.) that best reflect the (latest) EDID spec.		     |
+   |									     |
+   |  This module also contains functions to create and destroy arrays of    |
+   |  EDID video mode names that are supported by the display device.	     |
+   |									     |
+   |   ______________________________________________________________________|_
+    \_/_______________________________________________________________________/
+
+*/
+
+
+#include <sys/types.h>
+#include <stdio.h>		/* snprintf() */
+#include <stdlib.h>		/* free(), malloc(), memset(), strdup() */
+#include <string.h>		/* strcmp() */
+
+#include "gfx_res_util.h"	/* SunVideoTiming */
+
+#include "resolutions.h"	/* Video mode summary table: SunVideoTable[] */
+#include "sun_edid.h"		/* EDID data parsing */
+
+#include "fbc_mode_list.h"	/* List of Modes from the config file */
+
+
+#define	NAME_BUF_LEN	(64)	/* Buffer length for WxHxF mode name strings */
+
+
+/*
+ * sun_edid_get_be_short()
+ *
+ *    Return the unsigned 16-bit bigendian value decoded from the
+ *    indicated EDID bytes.
+ */
+
+uint16_t
+sun_edid_get_be_short(
+	const uint8_t	*edid_bytes)	/* EDID data bytes */
+{
+
+	return ((((uint16_t)edid_bytes[0]) << 8) | edid_bytes[1]);
+
+}	/* sun_edid_get_be_short() */
+
+
+/*
+ * sun_edid_get_le_short()
+ *
+ *    Return the unsigned 16-bit littleendian value decoded from the
+ *    indicated EDID bytes.
+ */
+
+uint16_t
+sun_edid_get_le_short(
+	const uint8_t	*edid_bytes)	/* EDID data bytes */
+{
+
+	return ((((uint16_t)edid_bytes[1]) << 8) | edid_bytes[0]);
+
+}	/* sun_edid_get_le_short() */
+
+
+/*
+ * sun_edid_get_le_long()
+ *
+ *    Return the unsigned 32-bit littleendian value decoded from the
+ *    indicated EDID bytes.
+ */
+
+uint32_t
+sun_edid_get_le_long(
+	const uint8_t	*edid_bytes)	/* EDID data bytes */
+{
+
+	return ((((((((uint32_t)edid_bytes[3]) << 8) | edid_bytes[2]) << 8)
+				| edid_bytes[1]) << 8) | edid_bytes[0]);
+
+}	/* sun_edid_get_le_long() */
+
+
+/*
+ * sun_edid_checksum()
+ *
+ *    Return the 1-byte sum of all 128 bytes in the EDID data block.
+ *    For the block to be valid, the sum of its bytes must be zero.
+ */
+
+uint8_t
+sun_edid_checksum(
+	const uint8_t	*edid_data)	/* EDID data block */
+{
+	int		addr;		/* Byte address within EDID block */
+	uint8_t		sum;		/* 1-byte sum of all 128 bytes */
+
+	sum = 0;
+	for (addr = 0x00; addr < 0x80; addr += 1) {
+	    sum += edid_data[addr];
+	}
+	return (sum);
+
+}	/* sun_edid_checksum() */
+
+
+/*
+ * sun_edid_check_base()
+ *
+ *    Return zero if the EDID Base block passes all tests:
+ *      * Non-NULL pointer to EDID data
+ *      * Length permits at least a complete 128-byte Base block
+ *      * 8-byte Header contains the pattern,
+ *        [0x00 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0x00]
+ *      * 1-byte sum of all 128 bytes is zero
+ *
+ *    Return -1 otherwise.
+ */
+
+int
+sun_edid_check_base(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	size_t		edid_length)	/* EDID data length */
+{
+
+	if ((edid_data != NULL) && (edid_length >= 0x80) &&
+	    (edid_data[0x00] == 0x00) &&
+	    (edid_data[0x01] == 0xFF) &&
+	    (edid_data[0x02] == 0xFF) &&
+	    (edid_data[0x03] == 0xFF) &&
+	    (edid_data[0x04] == 0xFF) &&
+	    (edid_data[0x05] == 0xFF) &&
+	    (edid_data[0x06] == 0xFF) &&
+	    (edid_data[0x07] == 0x00) &&
+	    (sun_edid_checksum(edid_data) == 0)) {
+	    return (0);
+	}
+	return (-1);
+
+}	/* sun_edid_check_base() */
+
+
+/*
+ * sun_edid_check_extensions()
+ *
+ *    The sun_edid_check_base() function must have been called
+ *    successfully.
+ *
+ *    Return zero if the EDID Extension blocks pass all tests:
+ *      * EDID data length is not less than the combined lengths of the
+ *        128-byte EDID blocks expected to be present
+ *      * 1-byte sum of each 128-byte Extension block is zero
+ *      * EDID data length is equal to the combined lengths of the
+ *        128-byte EDID blocks expected to be present
+ *
+ *    Return the non-zero block number of the offending EDID Extension
+ *    block otherwise.
+ */
+
+int
+sun_edid_check_extensions(
+	const uint8_t	*edid_data,	/* EDID Base & Extension blocks */
+	size_t		edid_length)	/* EDID data length */
+{
+	int		block_num;	/* EDID block number */
+	size_t		block_off;	/* Byte offset of EDID block */
+
+	block_num = 0;			/* EDID Base block number */
+	block_off = 0;			/* EDID Base block offset */
+	while (block_num < edid_data[0x7E]) {
+	    block_num += 1;
+	    block_off += 0x80;
+	    if ((edid_length < block_off + 0x80) ||
+		(sun_edid_checksum(&edid_data[block_off]) != 0)) {
+		return (block_num);	/* Insufficient data or bad checksum */
+	    }
+	}
+	if (edid_length != block_off + 0x80) {
+	    return (block_num + 1);	/* Data length exceeds blocks found */
+	}
+	return (0);			/* Success */
+
+}	/* sun_edid_check_extensions() */
+
+
+/*
+ * sun_edid_vendor()
+ *
+ *    Decode and return the following information from the Vendor &
+ *    Product Identification from an EDID Base block:
+ *	* Manufacturer ID	(three ASCII chars w/ Nul terminator)
+ *	* Product Code		(16 bits)
+ *	* Serial Number		(32 bits, Zero = Not used)
+ */
+
+void
+sun_edid_vendor(
+	const uint8_t	*buf,		/* EDID Base block, etc. */
+	char		*name,		/* Manufacturer ID  (3 chars & Nul) */
+	uint16_t	*product_code,	/* Product code */
+	uint32_t	*serial_num)	/* Serial number, else zero */
+{
+
+	name[0] = 'A' - 1 +  ((buf[0x08] >> 2)			   & 0x1F);
+	name[1] = 'A' - 1 + (((buf[0x08] << 3) | (buf[0x09] >> 5)) & 0x1F);
+	name[2] = 'A' - 1 +   (buf[0x09]			   & 0x1F);
+	name[3] = '\0';
+
+	*product_code = sun_edid_get_le_short(&buf[0x0A]);
+	*serial_num   = sun_edid_get_le_long(&buf[0x0C]);
+
+}	/* sun_edid_vendor() */
+
+
+/*
+ * sun_edid_mdate()
+ *
+ *    Decode and return the manufacture date information from the Vendor
+ *    & Product Identification section of an EDID Base block:
+ *	* Week of manufacture
+ *	  (0x00 = Not used, 1..54 = Week, 0xFF = Model year flag (EDID 1.4))
+ *	* Year of manufacture or model year (EDID 1.4)
+ */
+
+void
+sun_edid_mdate(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	int		*week,		/* Week of manufacture, else flags */
+	int		*year)		/* Year of manufacture or model year */
+{
+
+	*week = edid_data[0x10];
+	*year = edid_data[0x11] + 1990;
+
+}	/* sun_edid_mdate() */
+
+
+/*
+ * sun_edid_video_input()
+ *
+ *    Decode and return these Basic Display Paramaters & Features from
+ *    an EDID Base block:
+ *      * Video Input Definition
+ */
+
+void
+sun_edid_video_input(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	sun_edid_viddef_t *video_def)	/* Returned Video Input Definition */
+{
+	uint8_t		byte;		/* Video Input Definition byte value */
+
+	byte = edid_data[0x14];
+
+	video_def->digital = ((byte & 0x80) != 0);
+	if (video_def->digital) {
+	    const short	color_bit_depth[8] =
+			{ 0, 6, 8, 10, 12, 14, 16, -1 };
+
+	    /*
+	     * Input is a Digital Video Signal Interface
+	     */
+	    video_def->dig.color_depth  = color_bit_depth[(byte >> 4) & 0x07];
+	    video_def->dig.vid_standard = byte & 0x0F;
+	} else {
+	    const struct {
+		float	video;
+		float	sync;
+	    } sig_level_std[4] = {	/* Signal Level Standard */
+	    	{ 0.700, 0.300 },
+	    	{ 0.714, 0.286 },
+	    	{ 1.000, 0.400 },
+	    	{ 0.700, 0.000 }
+	    };
+
+	    /*
+	     * Input is an Analog Video Signal Interface
+	     */
+	    video_def->alg.video = sig_level_std[byte >> 5 & 0x03].video;
+	    video_def->alg.sync  = sig_level_std[byte >> 5 & 0x03].sync;
+
+	    video_def->alg.black2black    = ((byte & 0x10) != 0);
+
+	    video_def->alg.sync_separate  = ((byte & 0x08) != 0);
+	    video_def->alg.sync_composite = ((byte & 0x04) != 0);
+	    video_def->alg.sync_green     = ((byte & 0x02) != 0);
+
+	    video_def->alg.serration      = ((byte & 0x01) != 0);
+	}
+
+}	/* sun_edid_video_input() */
+
+
+/*
+ * sun_edid_screen_size()
+ *
+ *    Decode and return these Basic Display Paramaters & Features from
+ *    an EDID Base block:
+ *      * Horizontal screen size in centimeters, or aspect ratio
+ *        (Landscape), or zero
+ *      * Vertical screen size in cm., or aspect ratio (Portrait), or
+ *        zero
+ *      * Aspect ratio (Landscape or Portrait), else zero  (EDID 1.4)
+ */
+
+void
+sun_edid_screen_size(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	int		*horizontal,	/* Horizontal Screen Size (cm), etc. */
+	int		*vertical,	/* Vertical Screen Size (cm), etc. */
+	float		*aspect)	/* Aspect ratio, else zero */
+{
+
+	/*
+	 * Max Horizontal & Vertical Screen Sizes
+	 */
+	*horizontal = edid_data[0x15];
+	*vertical   = edid_data[0x16];
+
+	/*
+	 * Decode the aspect ratio, if any (introduced in EDID 1.4)
+	 */
+	*aspect = 0.0;
+	if (EDID_VER_REV(edid_data) >= EDID_1_4) {
+	    if ((*horizontal != 0) && (*vertical == 0)) {
+		*aspect = (*horizontal + 99) * 0.01;
+	    } else
+	    if ((*horizontal == 0) && (*vertical != 0)) {
+		*aspect = (100.0 / *vertical) - 99.0;
+	    }
+	}
+
+}	/* sun_edid_screen_size() */
+
+
+/*
+ * sun_edid_gamma()
+ *
+ *    Decode and return these Basic Display Paramaters & Features from
+ *    an EDID Base block:
+ *      * Display Transfer Characteristic (Gamma)
+ */
+
+void
+sun_edid_gamma(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	float		*gamma)		/* Returned gamma value, else zero */
+{
+
+	/*
+	 * Decode the Display Transfer Characteristic (Gamma)
+	 *
+	 *    If it is defined (not 0xFF), the actual gamma value is
+	 *    computed by adding 100 to the byte and dividing the result
+	 *    by 100.  The range is from 1.00 to 3.54.
+	 */
+	*gamma = 0.0;
+	if (edid_data[0x17] != 0xFF) {
+	    *gamma = (100 + edid_data[0x17]) * 0.01;
+	}
+
+}	/* sun_edid_gamma() */
+
+
+/*
+ * sun_edid_feature_support()
+ *
+ *    Decode and return these Basic Display Paramaters & Features from
+ *    an EDID Base block:
+ *      * Feature Support
+ */
+
+void
+sun_edid_feature_support(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	sun_edid_feature_t *feature)	/* Returned Feature Support info */
+{
+
+	feature->standby    = ((edid_data[0x18] & 0x80) != 0);
+	feature->suspend    = ((edid_data[0x18] & 0x40) != 0);
+	feature->active_off = ((edid_data[0x18] & 0x20) != 0);
+
+	feature->digital    = ((edid_data[0x14] & 0x80) != 0);
+	feature->color_info = edid_data[0x18] >> 3 & 0x03;
+
+	feature->srgb_std   = ((edid_data[0x18] & 0x04) != 0);
+	feature->ptm_incl   = ((edid_data[0x18] & 0x02) != 0);
+	feature->cont_freq  = ((edid_data[0x18] & 0x01) != 0);
+
+}	/* sun_edid_feature_support() */
+
+
+/*
+ * sun_edid_color_chars()
+ *
+ *    Decode and return Color Characteristics from an EDID Base block:
+ *      * Red-x
+ *      * Red-y
+ *      * Green-x
+ *      * Green-y
+ *      * Blue-x
+ *      * Blue-y
+ *      * White-x
+ *      * White-y
+ */
+
+void
+sun_edid_color_chars(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	sun_edid_colorchrs_t *color_chars) /* Returned Color Characteristics */
+{
+
+	color_chars->red_x   =
+	    ((edid_data[0x1B] << 2) | (edid_data[0x19] >> 6 & 0x03)) / 1024.;
+	color_chars->red_y   =
+	    ((edid_data[0x1C] << 2) | (edid_data[0x19] >> 4 & 0x03)) / 1024.;
+	color_chars->green_x =
+	    ((edid_data[0x1D] << 2) | (edid_data[0x19] >> 2 & 0x03)) / 1024.;
+	color_chars->green_y =
+	    ((edid_data[0x1E] << 2) | (edid_data[0x19]      & 0x03)) / 1024.;
+	color_chars->blue_x  =
+	    ((edid_data[0x1F] << 2) | (edid_data[0x1A] >> 6 & 0x03)) / 1024.;
+	color_chars->blue_y  =
+	    ((edid_data[0x20] << 2) | (edid_data[0x1A] >> 4 & 0x03)) / 1024.;
+	color_chars->white_x =
+	    ((edid_data[0x21] << 2) | (edid_data[0x1A] >> 2 & 0x03)) / 1024.;
+	color_chars->white_y =
+	    ((edid_data[0x22] << 2) | (edid_data[0x1A]      & 0x03)) / 1024.;
+
+}	/* sun_edid_color_chars() */
+
+
+/*
+ * Established Timings represented by flag bits in Bytes 0x23..0x25
+ *
+ *    These timing numbers and "Source" column comments can be found in
+ *    Table 3.18 of the VESA Enhanced Extended Display Identification
+ *    Data Standard, Release A, Revision 2, September 25, 2006.
+ */
+
+typedef struct {
+	const char *const name;		/* Video mode name */
+	int		width;		/* Horizontal addressable pixels */
+	int		height;		/* Vertical addressable lines */
+	int		frequency;	/* Vertical frequency */
+} sun_timing_t;
+
+#define	ETIMING_BITS	((0x25-0x23+1)*8) /* Three bytes worth of flag bits */
+
+static	const sun_timing_t est_timings[ETIMING_BITS] = {
+	/*
+	 * Established Timings I  (Byte address 0x23)
+	 */
+	{ "720x400x70",     	     720,  400, 70 },	/* IBM, VGA */
+	{ "720x400x88",     	     720,  400, 88 },	/* IBM, XGA2 */
+	{ "VESA_STD_640x480x60",     640,  480, 60 },	/* IBM, VGA */
+	{ "640x480x67",     	     640,  480, 67 },	/* Apple, Mac II */
+	{ "VESA_STD_640x480x72",     640,  480, 72 },	/* VESA */
+	{ "VESA_STD_640x480x75",     640,  480, 75 },	/* VESA */
+	{ "800x600x56",     	     800,  600, 56 },	/* VESA */
+	{ "800x600x60",     	     800,  600, 60 },	/* VESA */
+	/*
+	 * Established Timings II  (Byte address 0x24)
+	 *
+	 *    ??? Need proper names for est_timings[11] and [14] ???
+	 */
+	{ "800x600x72",     	     800,  600, 72 },	/* VESA */
+	{ "VESA_STD_800x600x75",     800,  600, 75 },	/* VESA */
+	{ "832x624x75",    	     832,  624, 75 },	/* Apple, Mac II */
+	{ "1024x768x87",      	    1024,  768, 87 },	/* IBM - Interlaced */
+	{ "VESA_STD_1024x768x60",   1024,  768, 60 },	/* VESA */
+	{ "VESA_STD_1024x768x70",   1024,  768, 70 },	/* VESA */
+	{ "VESA_STD_1024x768x75",   1024,  768, 75 },	/* VESA */
+	{ "VESA_STD_1280x1024x75",  1280, 1024, 75 },	/* VESA */
+	/*
+	 * Manufacturer's Timings  (Byte address 0x25)
+	 */
+	{ "1152x870x75",	    1152,  870, 75 },	/* Apple, Mac II */
+	{ NULL,			       0,    0,  0 },	/* Reserved */
+	{ NULL,			       0,    0,  0 },	/* Reserved */
+	{ NULL,			       0,    0,  0 },	/* Reserved */
+	{ NULL,			       0,    0,  0 },	/* Reserved */
+	{ NULL,			       0,    0,  0 },	/* Reserved */
+	{ NULL,			       0,    0,  0 },	/* Reserved */
+	{ NULL,			       0,    0,  0 }	/* Reserved */
+};
+
+
+/*
+ * Established Timings III represented by a Display Descriptor w/ Tag 0xF7
+ */
+
+#define	ETIMING_III_BITS ((11-6+1)*8)	/* Bytes #6..11 have defined flags */
+
+static	const sun_timing_t est_timings_iii[ETIMING_III_BITS] = {
+	{	"640x350x85",        640,  350, 85 },
+	{	"640x400x85",        640,  400, 85 },
+	{	"720x400x85",        720,  400, 85 },
+	{	"640x480x85",        640,  480, 85 },
+	{	"848x480x60",        848,  480, 60 },
+	{	"800x600x85",        800,  600, 85 },
+	{	"1024x768x85",      1024,  768, 85 },
+	{	"1152x864x75",      1152,  864, 75 },
+
+	{	"1280x768x60",      1280,  768, 60 },	/* Reduced Blanking */
+	{	"1280x768x60",      1280,  768, 60 },
+	{	"1280x768x75",      1280,  768, 75 },
+	{	"1280x768x85",      1280,  768, 85 },
+	{	"1280x960x60",      1280,  960, 60 },
+	{	"1280x960x85",      1280,  960, 85 },
+	{	"1280x1024x60",     1280, 1024, 60 },
+	{	"1280x1024x85",     1280, 1024, 85 },
+
+	{	"1360x768x60",      1360,  768, 60 },
+	{	"1440x900x60",      1440,  900, 60 },	/* Reduced Blanking */
+	{ "VESA_STD_1440x900x60",   1440,  900, 60 },
+	{	"1440x900x75",      1440,  900, 75 },
+	{	"1440x900x85",      1440,  900, 85 },
+	{	"1400x1050x60",     1400, 1050, 60 },	/* Reduced Blanking */
+	{	"1400x1050x60",     1400, 1050, 60 },
+	{	"1400x1050x75",     1400, 1050, 75 },
+
+	{	"1400x1050x85",     1400, 1050, 85 },
+	{ "VESA_RB_1680x1050x60",   1680, 1050, 60 },	/* Reduced Blanking */
+	{ "VESA_STD_1680x1050x60",  1680, 1050, 60 },
+	{	"1680x1050x75",     1680, 1050, 75 },
+	{	"1680x1050x85",     1680, 1050, 85 },
+	{	"1600x1200x60",     1600, 1200, 60 },
+	{	"1600x1200x65",     1600, 1200, 65 },
+	{	"1600x1200x70",     1600, 1200, 70 },
+
+	{	"1600x1200x75",     1600, 1200, 75 },
+	{	"1600x1200x85",     1600, 1200, 85 },
+	{	"1792x1344x60",     1792, 1344, 60 },
+	{	"1792x1344x75",     1792, 1344, 75 },
+	{	"1856x1392x60",     1856, 1392, 60 },
+	{	"1856x1392x75",     1856, 1392, 75 },
+	{	"1920x1200x60",     1920, 1200, 60 },	/* Reduced Blanking */
+	{	"1920x1200x60",     1920, 1200, 60 },
+
+	{	"1920x1200x75",     1920, 1200, 75 },
+	{	"1920x1200x85",     1920, 1200, 85 },
+	{	"1920x1440x60",     1920, 1440, 60 },
+	{	"1920x1440x75",     1920, 1440, 75 },
+	{ NULL,			       0,    0,  0 },	/* Reserved */
+	{ NULL,			       0,    0,  0 },	/* Reserved */
+	{ NULL,			       0,    0,  0 },	/* Reserved */
+	{ NULL,			       0,    0,  0 }	/* Reserved */
+};
+
+
+/*
+ * sun_edid_bit_set()
+ *
+ *    Return non-zero (TRUE) iff the bit is set at the specified offset
+ *    within the bit field (e.g. Established Timings).
+ */
+
+int
+sun_edid_bit_set(
+	const uint8_t	*edid_bytes,	/* First byte of the bit field */
+	int		bit_off)	/* Bit offset into the bit field */
+{
+
+	/*
+	 * Test the indicated bit within the bit field
+	 */
+	return (edid_bytes[bit_off / 8] & (0x80 >> bit_off % 8));
+
+}	/* sun_edid_bit_set() */
+
+
+/*
+ * sun_edid_etiming()
+ *
+ *    Given an EDID Base block and a bit offset (0..23) into the
+ *    Established Timings flag bits, validate the offset and return the
+ *    corresponding width, height, and vertical frequency.  Return -1 if
+ *    the bit offset is out of range.  Return zero if the timing isn't
+ *    supported.  Return 1 if the timing is supported.
+ */
+
+int
+sun_edid_etiming(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	int		addr,		/* Byte address within EDID block */
+	int		bit_off,	/* Established Timings bit offset */
+	int		*width,		/* Returned width */
+	int		*height,	/* Returned height */
+	int		*frequency)	/* Returned vertical frequency */
+{
+
+	/*
+	 * Validate the bit offset
+	 */
+	if ((bit_off < 0) || (bit_off >= 3*8)) {
+	    return (-1);
+	}
+
+	/*
+	 * Return the Established Timing information (supported or not)
+	 */
+	*width     = est_timings[bit_off].width;
+	*height    = est_timings[bit_off].height;
+	*frequency = est_timings[bit_off].frequency;
+
+	/*
+	 * See whether the bit offset corresponds to a supported timing
+	 */
+	if (!sun_edid_bit_set(&edid_data[addr], bit_off) ||
+	    (est_timings[bit_off].width == 0)) {
+	    return (0);			/* Timing is not supported */
+	}
+	return (1);			/* Timing is supported */
+
+}	/* sun_edid_etiming() */
+
+
+/*
+ * decode_stiming()
+ *
+ *    Decode a Standard Timings byte pair and return the width, height,
+ *    and vertical frequency.  Return 0 upon success and -1 on failure.
+ */
+
+static
+int
+decode_stiming(
+	int		edid_ver_rev,	/* EDID version and revision */
+	const uint8_t	*edid_bytes,	/* Standard Timings byte pair */
+	int		*x,		/* Returned horiz addressable pixels */
+	int		*y,		/* Returned vert addressable lines */
+	int		*f)		/* Returned vertical frequency */
+{
+
+	/*
+	 * Check for reserved encodings and unused slots
+	 */
+	if (edid_bytes[0] == 0x00) {
+	    return (-1);		/* Zero in the 1st byte is reserved */
+	}
+	if ((edid_bytes[0] == 0x01) && (edid_bytes[1] == 0x01)) {
+	    return (-1);		/* Unused */
+	}
+
+	/*
+	 * Horizontal addressable pixels  (1st byte)
+	 */
+	*x = (edid_bytes[0] + 31) * 8;
+
+	/*
+	 * Image Aspect Ratio  (bits 7..6 of 2nd byte)
+	 */
+	switch (edid_bytes[1] >> 6) {
+	case 0:	if (edid_ver_rev <= EDID_1_2) {
+		    *y = *x;		/* 1:1 AR */
+		} else {
+		    *y = *x * 10 / 16;	/* 16:10 AR */
+		}
+		break;
+	case 1:	*y = *x * 3 / 4;	/* 4:3 AR */
+		break;
+	case 2:	*y = *x * 4 / 5;	/* 5:4 AR */
+		break;
+	case 3:	*y = *x * 9 / 16;	/* 16:9 AR */
+		break;
+	}
+
+	/*
+	 * Field Refresh Rate  (bits 5..0 of 2nd byte)
+	 */
+	*f = (edid_bytes[1] & 0x3F) + 60;
+
+	/*
+	 * Return zero upon success
+	 */
+	return (0);
+
+}	/* decode_stiming() */
+
+
+/*
+ * sun_edid_stiming()
+ *
+ *    Decode the Standard Timings byte pair at the byte specified byte
+ *    address.  Return the width, height, and vertical frequency.
+ *    Return zero upon success and -1 upon failure (invalid Standard
+ *    Timings data).
+ */
+
+int
+sun_edid_stiming(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	int		addr,		/* Byte address within EDID block */
+	int		*width,		/* Returned horiz addressable pixels */
+	int		*height,	/* Returned vert addressable lines */
+	int		*frequency)	/* Returned vertical frequency */
+{
+
+	/*
+	 * Decode the Standard Timings byte pair and return the results
+	 */
+	return (decode_stiming(EDID_VER_REV(edid_data),
+				&edid_data[addr], width, height, frequency));
+
+}	/* sun_edid_stiming() */
+
+
+/*
+ * decode_dtiming()
+ *
+ *    Decode the Detailed Timing Descriptor and return the results in
+ *    the Detailed Timing information structure.  Return zero upon
+ *    success and -1 upon failure.
+ */
+
+static
+int
+decode_dtiming(
+	const uint8_t	*data_block,	/* EDID 18-Byte Data Block */
+	sun_edid_dtiming_t *dt)		/* Returned Detailed Timing info */
+{
+
+	/*
+	 * See whether this 18-Byte Data Block is a Detailed Timing Descriptor
+	 */
+	if ((data_block[0] == 0) && (data_block[1] == 0)) {
+	    return (-1);		/* This is a Display Descriptor */
+	}
+
+	/*
+	 * Decode this Detailed Timing Descriptor
+	 */
+	dt->pixclock	= sun_edid_get_le_short(&data_block[0])*10000;
+	dt->hactive	= data_block[ 2] | (data_block[ 4] << 4 & 0xF00);
+	dt->hblanking	= data_block[ 3] | (data_block[ 4] << 8 & 0xF00);
+	dt->vactive	= data_block[ 5] | (data_block[ 7] << 4 & 0xF00);
+	dt->vblanking	= data_block[ 6] | (data_block[ 7] << 8 & 0xF00);
+	dt->hsyncOffset	= data_block[ 8] | (data_block[11] << 2 & 0x300);
+	dt->hsyncWidth	= data_block[ 9] | (data_block[11] << 4 & 0x300);
+	dt->vsyncOffset	=
+			(data_block[10] >> 4)   | (data_block[11] << 2 & 0x30);
+	dt->vsyncWidth	=
+			(data_block[10] & 0x0F) | (data_block[11] << 4 & 0x30);
+	dt->hsize	= data_block[12] | (data_block[14] << 4 & 0xF00);
+	dt->vsize	= data_block[13] | (data_block[14] << 8 & 0xF00);
+	dt->hborder	= data_block[15];
+	dt->vborder	= data_block[16];
+	dt->flags	= data_block[17];
+
+	return (0);
+
+}	/* decode_dtiming() */
+
+
+/*
+ * get_dtiming_frequency()
+ *
+ *    Calculate and return the vertical frequency for this Detailed
+ *    Timing.
+ */
+
+static
+int
+get_dtiming_frequency(
+	const sun_edid_dtiming_t *dt)	/* Detailed Timing info */
+{
+	long		htotal;		/* Total horizontal pixels */
+	long		vtotal;		/* Total vertical lines */
+//???	long		total;		/* Total pixels */
+
+	htotal = dt->hborder + dt->hactive + dt->hborder + dt->hblanking;
+	vtotal = dt->vborder + dt->vactive + dt->vborder + dt->vblanking;
+	if ((htotal <= 0) || (vtotal <= 0)) {
+	    return (0);		/* Don't divide by zero or use negatives */
+	}
+//??? Round upwards?
+//???	total = htotal * vtotal;
+//???	return ((int)((dt->pixclock + total/2) / total));
+//??? Or truncate?
+	return ((int)(dt->pixclock / (htotal * vtotal)));
+
+}	/* get_dtiming_frequency() */
+
+
+/*
+ * dtiming_to_vtiming()
+ *
+ *    Convert Detailed Timing information to SunVideoTiming information.
+ */
+
+static
+void
+dtiming_to_vtiming(
+	const sun_edid_dtiming_t *dt,	/* Detailed Timing information */
+	SunVideoTiming	*block)		/* Returned SunVideoTiming info */
+{
+
+	/*
+	 * Fill in some of the video timing info block
+	 */
+	block->Hact = dt->hactive;
+	block->Hfp  = dt->hsyncOffset;
+	block->Hsw  = dt->hsyncWidth;
+	block->Hbp  = dt->hblanking - dt->hsyncOffset - dt->hsyncWidth;
+	block->Hsrp = 0;			/* TODO: serration */
+	block->Vact = dt->vactive;
+	block->Vfp  = dt->vsyncOffset;
+	block->Vsw  = dt->vsyncWidth;
+	block->Vbp  = dt->vblanking - dt->vsyncOffset - dt->vsyncWidth;
+	block->Pclk = dt->pixclock / 1000;
+	block->Fint = (dt->flags & 0x80) != 0; /* Interlaced flag */
+	block->Fseq = 0;			/* TODO: field sequential */
+
+	/* Stereo flags.  TODO: SunVideoTiming block needs more flags */
+	switch (dt->flags & 0x61) {
+	case 0x00:
+	case 0x01:	block->Fst = 0;	/* Normal Display, No Stereo */
+			break;
+	case 0x20:
+	case 0x21:
+	case 0x40:
+	case 0x41:
+	case 0x60:
+	case 0x61:	block->Fst = 1;	/* Stereo */
+			break;
+	}
+
+	/* Sync type flags.  TODO: a flag for sync on RGB */
+	/* TODO: do serration right */
+	switch (dt->flags & 0x18) {
+	case 0x00:	/* Analog Composite Sync */
+	case 0x08:	/* Bipolar Analog Composite Sync */
+			block->Hsrp  = (dt->flags & 0x04) != 0;
+			block->Stype = 0;		/* combined sync */
+			block->SHpol = 0;		/* TODO */
+			block->SVpol = 0;		/* TODO */
+			break;
+	case 0x10:	/* Digital Composite Sync */
+			block->Hsrp  = (dt->flags & 0x04) != 0;
+			block->Stype = 0;		/* combined sync */
+			block->SHpol = (dt->flags & 0x02) ? 1 : 0;
+			block->SVpol = 0;		/* always negative? */
+			break;
+	case 0x18:	/* Digital Separate Sync */
+			block->Stype = 1;		/* Separate */
+			block->SHpol = (dt->flags & 0x02) ? 1 : 0;
+			block->SVpol = (dt->flags & 0x04) ? 1 : 0;
+			break;
+	}
+
+	block->Encod = SunVideoEncodingNone;		/* TODO */
+	block->Hund  = 0.;				/* TODO */
+	block->Vund  = 0.;				/* TODO */
+
+}	/* dtiming_to_vtiming() */
+
+
+/*
+ * sun_edid_dtiming()
+ *
+ *    Decode the Detailed Timing Descriptor that is assumed to be in the
+ *    18-Byte Data Block that corresponds to the specified index (0..3).
+ *    Return the width, height, and vertical frequency.  If a timing
+ *    info block has been provided by the caller, fill it in also.  This
+ *    includes a dynamically allocated name string (id_string).  Return
+ *    zero upon success and -1 upon failure.
+ */
+
+int
+sun_edid_dtiming(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	int		addr,		/* Byte address within EDID block */
+	sun_edid_dtiming_t *dt)		/* Returned Detailed Timing info */
+{
+
+	/*
+	 * Decode the Detailed Timing Descriptor (if that's what it is)
+	 *
+	 *    An 18-Byte Data Block is encoded in 18 (decimal) bytes.
+	 *    The 1st descriptor starts at EDID block address 0x36.
+	 *    The 4th descriptor ends at EDID block address 0x7E.
+	 */
+	return (decode_dtiming(&edid_data[addr], dt));
+
+}	/* sun_edid_dtiming() */
+
+
+/*
+ * find_display_descriptor()
+ *
+ *    Return the address of the first Display Descriptor that contains
+ *    the specified tag, or -1 if the descriptor isn't found.
+ *
+ *    Subsequent descriptors having the same tag won't be found.
+ *
+ *    Display Descriptor tag numbers are (as of EDID 1.4):
+ *      0xFF  Display Product Serial Number
+ *      0xFE  Alphanumeric Data String (ASCII)
+ *      0xFD  Display Range Limits
+ *      0xFC  Display Product Name
+ *      0xFB  Color Point Data
+ *      0xFA  Standard Timing Identifications
+ *      0xF9  Display Color Management (DCM) Data
+ *      0xF8  CVT 3 Byte Timing Codes
+ *      0xF7  Established Timings III
+ *      0x11..0xF6  Reserved
+ *      0x10  Dummy Descriptor
+ *      0x00..0x0F  Manufacturer Specified Display Descriptors
+ */
+
+int
+find_display_descriptor(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	uint8_t		tag)		/* Display Descriptor tag number */
+{
+	int		addr;		/* Address of Display Descriptor */
+
+	/*
+	 * Prior to EDID 1.1, Display Descriptors were not applicable
+	 */
+	if (EDID_VER_REV(edid_data) < EDID_1_1) {
+	    return (-1);
+	}
+
+	/*
+	 * Examine each of the 18-Byte Data Blocks for the Display Descriptor
+	 *
+	 *    An 18-Byte Data Block is encoded in 18 (decimal) bytes.
+	 *    The 1st descriptor starts at EDID block address 0x36.
+	 *    The 4th descriptor ends at EDID block address 0x7E.
+	 *
+	 *    The Byte #2 of a Display Descriptor is always reserved.
+	 *    Byte #4 is reserved except for Display Range Limits
+	 *    descriptors.
+	 */
+	for (addr = 0x36; addr < 0x7E; addr += 18) {
+	    if ((edid_data[addr+0] == 0) &&	/* Display Descriptor */
+		(edid_data[addr+1] == 0) &&	/* Display Descriptor */
+		(edid_data[addr+2] == 0) &&	/* Reserved */
+		(edid_data[addr+3] == tag)) {	/* Display Descriptor tag */
+		return (addr);
+	    }
+	}
+
+	return (-1);
+
+}	/* find_display_descriptor() */
+
+
+/*
+ * sun_edid_descriptor_string()
+ *
+ *    Return a string that has been encoded in a Display Descriptor of
+ *    an EDID data block.
+ *
+ *    The name string can be up to 13 (18-5) ASCII characters long and
+ *    will be terminated by a Nul character, requiring the caller to
+ *    provide a 14-character buffer.
+ */
+
+void
+sun_edid_descriptor_string(
+	const uint8_t	*edid_data,	/* Display Descriptor bytes */
+	char		*string_buf)	/* Returned Display Descriptor str */
+{
+	int		i;		/* Offset into Display Descriptor */
+
+	/*
+	 * Extract the string from the Display Descriptor
+	 *
+	 *    The string can be up to 13 (18-5) ASCII characters long.
+	 *    A name that is shorter will have been terminated by a Line
+	 *    Feed (0x0A) followed by zero or more Spaces (0x20).
+	 */
+	for (i = 5; (i < 18) && (edid_data[i] != 0x0A); i += 1) {
+	    *string_buf = edid_data[i];
+	    string_buf += 1;
+	}
+	*string_buf = '\0';
+
+}	/* sun_edid_descriptor_string() */
+
+
+/*
+ * display_descriptor_string()
+ *
+ *    Search the EDID Base block for the first Display Descriptor
+ *    having the specified tag.  If found, return the Nul-terminated
+ *    string that has been encoded in the Display Descriptor along with
+ *    a zero return code.  Otherwise return an empty string and a return
+ *    code of -1.
+ *
+ *    The name string can be up to 13 (18-5) ASCII characters long and
+ *    will be terminated by a Nul character, requiring the caller to
+ *    provide a 14-character buffer.
+ */
+
+static
+int
+display_descriptor_string(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	uint8_t		tag,		/* Display Descriptor tag number */
+	char		*string_buf)	/* Returned Display Descriptor str */
+{
+	int		addr;		/* Address of Display Descriptor */
+
+	*string_buf = '\0';		/* In case nothing is found */
+
+	/*
+	 * Examine each of the 18-Byte Data Blocks for a matching tag
+	 */
+	addr = find_display_descriptor(edid_data, tag);
+	if (addr <= 0) {
+	    return (-1);
+	}
+
+	/*
+	 * Extract the string from the Display Descriptor
+	 */
+	sun_edid_descriptor_string(&edid_data[addr], string_buf);
+	return (0);
+
+}	/* display_descriptor_string() */
+
+
+/*
+ * sun_edid_serial_number()
+ *
+ *    Return a Nul-terminated Display Product Serial Number string in a
+ *    caller-supplied 14-character buffer and a zero iff successful.
+ *    Return an empty string and -1 otherwise.
+ */
+
+int
+sun_edid_serial_number(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	char		*string_buf)	/* Returned Display Product Serial # */
+{
+
+	return (display_descriptor_string(edid_data, 0xFF, string_buf));
+
+}	/* sun_edid_serial_number() */
+
+
+/*
+ * sun_edid_alphanum_data()
+ *
+ *    Return a Nul-terminated Alphanumeric Data String in a caller-
+ *    supplied 14-character buffer and a zero iff successful.  Return an
+ *    empty string and -1 otherwise.
+ */
+
+int
+sun_edid_alphanum_data(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	char		*string_buf)	/* Returned Alphanumeric Data String */
+{
+
+	return (display_descriptor_string(edid_data, 0xFE, string_buf));
+
+}	/* sun_edid_alphanum_data() */
+
+
+/*
+ * sun_edid_range_limits()
+ *
+ *    Return Display Range Limits (frequency) from a Display Descriptor
+ *    in an EDID Base block, including:
+ *      * Vertical frequencies in Hz
+ *      * Horizontal frequencies in kHz
+ *      * Pixel Clock frequency in MHz.
+ *
+ *    Only valid in EDID 1.1 or higher.
+ */
+
+void
+sun_edid_range_limits(
+	const uint8_t	*edid_data,	/* Display Descriptor bytes */
+	sun_edid_range_lim_t *range_limits) /* Display Range Limits */ 
+{
+
+	memset(range_limits, 0, sizeof (sun_edid_range_lim_t));
+
+	range_limits->vert_min  =
+		edid_data[5] + (((edid_data[4] & 0x03) == 0x03) ? 255 : 0);
+	range_limits->vert_max  =
+		edid_data[6] + ( (edid_data[4] & 0x02)          ? 255 : 0);
+
+	range_limits->horiz_min =
+		edid_data[7] + (((edid_data[4] & 0x0C) == 0x0C) ? 255 : 0);
+	range_limits->horiz_max =
+		edid_data[8] + ( (edid_data[4] & 0x08)          ? 255 : 0);
+
+	range_limits->pixclock_max     = edid_data[9] * 10;
+	range_limits->cvt_pixclock_max = range_limits->pixclock_max << 2;
+
+	switch (edid_data[10]) {
+
+	case 0x02: /* General Timing Formula (GTF) Secondary Curve supported */
+		range_limits->gtf_start_break = edid_data[12];
+		range_limits->gtf_C = edid_data[13] >> 1;
+		range_limits->gtf_M = sun_edid_get_le_short(&edid_data[14]);
+		range_limits->gtf_K = edid_data[16];
+		range_limits->gtf_J = edid_data[17] >> 1;
+		break;
+
+	case 0x04: /* CVT supported */
+		range_limits->cvt_version = edid_data[11];
+		range_limits->cvt_pixclock_max -= edid_data[12] >> 2;
+		if (edid_data[13] != 0) {
+			range_limits->cvt_hactive_max =
+				(((edid_data[12] & 0x03) << 8) | edid_data[13])
+					* 8;
+		}
+		/* ??? TODO ??? */
+		break;
+
+	}
+
+}	/* sun_edid_range_limits() */
+
+
+/*
+ * sun_edid_product_name()
+ *
+ *    Return a Nul-terminated Display Product Name in a caller-supplied
+ *    14-character buffer and a zero iff successful.  Return an empty
+ *    string and -1 otherwise.
+ */
+
+int
+sun_edid_product_name(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	char		*string_buf)	/* Returned Display Product Name */
+{
+
+	return (display_descriptor_string(edid_data, 0xFC, string_buf));
+
+}	/* sun_edid_product_name() */
+
+
+/*
+ * End of EDID structure parsing functions
+ * ---------------------------------------------------------------------
+ * Start of EDID video mode name list construction functions
+ */
+
+
+#include "fbc_res.h"		/* Video modes/resolutions (-res option) */
+
+
+/*
+ * add_video_mode()
+ *
+ *    Insert a new video mode name at the end of a mode names array,
+ *    assuming the name pointer isn't NULL and the name isn't already in
+ *    the list.
+ *
+ *    A NULL name pointer can result when a reserved Established or
+ *    Standard Timing is encountered.
+ */
+
+static
+void
+add_video_mode(
+	sun_edid_mode_t	*edid_modes,	/* Growing list of modes */
+	sun_edid_mode_t	**edid_modes_end, /* Ptr to end of modes list */
+	const char	*mode_name,	/* Potential new mode name, or NULL */
+	short		width,		/* Horizontal addressable pixels */
+	short		height,		/* Vertical addressable lines */
+	short		frequency)	/* Vertical frequency */
+{
+	sun_edid_mode_t	*mode_ptr;	/* Ptr to video mode within list */
+
+	/*
+	 * Ignore this video mode if the caller didn't provide the name
+	 */
+	if (mode_name == NULL) {
+	    return;
+	}
+
+	/*
+	 * Ignore the video mode if it's already in the list
+	 */
+	for (mode_ptr = edid_modes; mode_ptr->name != NULL; mode_ptr += 1) {
+	    if ((strcmp(mode_name, mode_ptr->name) == 0) &&
+		(width     == mode_ptr->width) &&
+		(height    == mode_ptr->height) &&
+		(frequency == mode_ptr->frequency)) {
+		return;
+	    }
+	}
+
+	/*
+	 * Append the new video mode to the list
+	 *
+	 *    Note that a distant caller function has allocated the
+	 *    edid_modes array of sufficient size to eliminate the
+	 *    possibility of overrunning it.
+	 */
+	(*edid_modes_end)->name = strdup(mode_name);
+	if ((*edid_modes_end)->name == NULL) {
+	    return;			/* Never mind */
+	}
+	(*edid_modes_end)->width     = width;
+	(*edid_modes_end)->height    = height;
+	(*edid_modes_end)->frequency = frequency;
+	*edid_modes_end += 1;
+
+	/*
+	 * Mark the new end of the list
+	 */
+	(*edid_modes_end)->name = NULL;
+
+}	/* add_video_mode() */
+
+
+/*
+ * add_etiming_modes()
+ *
+ *    Test each of the Established Timings flag bits in the EDID data
+ *    bytes 0x23..0x25.  Do the same with the Established Timings III
+ *    flag bits, if present in a Display Descriptor.  If a bit is set
+ *    and the name pointer isn't NULL (indicating a reserved bit) then
+ *    the timing is supported by the display device.  If the timing is
+ *    supported then add the mode name to the array of names.  Return
+ *    the updated list.
+ */
+
+static
+void
+add_etiming_modes(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	sun_edid_mode_t	*edid_modes,	/* Growing list of modes */
+	sun_edid_mode_t	**edid_modes_end) /* Ptr to end of modes list */
+{
+	int		addr;		/* Address of Display Descriptor */
+	int		bit_off;	/* Established Timings bit offset */
+
+	/*
+	 * Test each bit of the three Established Timings bytes
+	 */
+	for (bit_off = 0; bit_off < ETIMING_BITS; bit_off += 1) {
+	    if (sun_edid_bit_set(&edid_data[0x23], bit_off)) {
+		/*
+		 * Add this timing mode to the list
+		 *
+		 *    If the Established Timings bit is reserved, the
+		 *    mode name pointer is NULL, preventing the mode
+		 *    from being added to the list.
+		 */
+		add_video_mode(edid_modes, edid_modes_end,
+				est_timings[bit_off].name,
+				est_timings[bit_off].width,
+				est_timings[bit_off].height,
+				est_timings[bit_off].frequency);
+	    }
+	}
+
+	/*
+	 * Ditto for Established Timings III bytes, if present
+	 */
+	addr = find_display_descriptor(edid_data, 0xF7);
+	if (addr > 0) {
+	    for (bit_off = 0; bit_off < ETIMING_III_BITS; bit_off += 1) {
+		if (sun_edid_bit_set(&edid_data[addr+6], bit_off)) {
+		    add_video_mode(edid_modes, edid_modes_end,
+				    est_timings_iii[bit_off].name,
+				    est_timings_iii[bit_off].width,
+				    est_timings_iii[bit_off].height,
+				    est_timings_iii[bit_off].frequency);
+		}
+	    }
+	}
+
+}	/* add_etiming_modes() */
+
+#if defined(ACTIVATE_DEAD_CODE)	/* Not used by fbconfig */
+
+/*
+ * sun_edid_etiming_modes()
+ *
+ *    Return a NULL-terminated array of Established Timing / video
+ *    resolution name strings that the display device supports,
+ *    according to the timing data found in this EDID data block.
+ *
+ *    The dynamically allocated memory for the array and name strings
+ *    can be freed by calling the sun_edid_mode_names_free() function.
+ */
+
+char **
+sun_edid_etiming_modes(uint8_t *edid_data, int len)
+{
+	sun_edid_mode_t	*edid_modes;	/* Returned list of mode names */
+	sun_edid_mode_t	**edid_modes_end; /* Ptr to end of mode names list */
+
+	/*
+	 * Allocate and populate an array of ptrs to Established Timing names
+	 *
+	 *    There may be:
+	 *     24  Established Timings mode names      (ETIMING_BITS     = 24)
+	 *     48  Established Timings III mode names  (ETIMING_III_BITS = 48)
+	 *      1  NULL terminator for the array
+	 *
+	 */
+	edid_modes = malloc((ETIMING_BITS + ETIMING_III_BITS + 1)
+					* sizeof (*edid_modes));
+	if (edid_modes != NULL) {
+	    edid_modes_end       = edid_modes;
+	    edid_modes_end->name = NULL;
+
+	    add_etiming_modes(edid_data, edid_modes, &edid_modes_end);
+
+	    if (edid_modes_end <= edid_modes) {
+		free(edid_modes);
+		edid_modes = NULL;	/* The list is empty */
+	    }
+	}
+
+	return (edid_modes);
+
+}	/* sun_edid_etiming_modes() */
+
+#endif	/* Not used by fbconfig */
+
+/*
+ *    A few "standard" timings actually come from us.  If we
+ *    recognize one of them, we return a different name.
+ *    This list may grow over time.
+ *
+ *    Note that with EDID 1.2 and before, the Standard Timings byte
+ *    pair, 0xD1,0x00, will decode differently than shown here.
+ */
+static	const sun_timing_t std_timings[] = {
+	{ "SUNW_STD_1280x1024x76",	1280, 1024,  76 },	/* 0x81 0x90 */
+	{ "SUNW_STD_1152x900x76",	1152,  921,  76 },	/* 0x71 0x90 */
+		      /* ^^^ */		    /* ^^^ */
+	{ "VESA_STD_1280x1024x75",	1280, 1024,  75 },	/* 0x81 0x8F */
+	{ "SUNW_STD_1280x1024x67",	1280, 1024,  67 },	/* 0x81 0x87 */
+	{ "SUNW_STD_1152x900x66",	1152,  921,  66 },	/* 0x71 0x86 */
+		      /* ^^^ */		    /* ^^^ */
+	{ "VESA_STD_1024x768x75",	1024,  768,  75 },	/* 0x61 0x4F */
+	{ "SUNW_STD_1600x1200x75",	1600, 1200,  75 },	/* 0xA9 0x4F */
+	{ "SUNW_STEREO_1280x1024x112",	1280, 1024, 112 },	/* 0x81 0xB4 */
+	{ "VESA_STD_1280x1024x60",	1280, 1024,  60 },	/* 0x81 0x80 */
+	{ "SUNW_DIG_1920x1200x60",	1920, 1200,  60 },	/* 0xD1 0x00 */
+	{ "SUNW_DIG_1920x1080x60",	1920, 1080,  60 },	/* 0xD1 0xC0 */
+	{ "SUNW_DIG_1600x1200x60",	1600, 1200,  60 },	/* 0xA9 0x40 */
+	{ NULL,				   0,    0,   0 }
+};
+
+
+/*
+ * get_stiming_name()
+ *
+ *    Given a Standard Timing width, height, and frequency, return the
+ *    corresponding video mode / resolution name.  The name might be
+ *    found in a built-in table or in configuration file video modes
+ *    data structures, or it might be constructed on the fly.
+ *
+ *    If a name must be constructed, the caller-supplied name_buf buffer
+ *    will be used.  The buffer must be at least NAME_BUF_LEN bytes
+ *    long.
+ */
+
+static
+const char *
+get_stiming_name(
+	int		width,		/* Horizontal addressable pixels */
+	int		height,		/* Vertical addressable lines */
+	int		frequency,	/* Vertical frequency */
+	fbc_mode_elem_t	*mode_list,	/* Modes from config file */
+	char		*name_buf)	/* Buffer for returned WxHxF name */
+{
+	int		i;		/* Loop ctr / std_timings[] index */
+	fbc_mode_elem_t	*mode_elem;	/* Modes list element (unintrusive) */
+	const SunVideoSummary *ptr;	/* Ptr into SunVideoTable[] table */
+
+	/*
+	 * Look for the video mode name in the built-in std_timings[] table
+	 */
+	for (i = 0; std_timings[i].width != 0; i += 1) {
+	    if ((width     == std_timings[i].width) &&
+		(height    == std_timings[i].height) &&
+		(frequency == std_timings[i].frequency)) {
+		return (std_timings[i].name);
+	    }
+	}
+
+	/*
+	 * Look for the video mode name in the built-in SunVideoTable[] table
+	 */
+	for (ptr = &SunVideoTable[0]; ptr->id_string != NULL; ptr += 1) {
+	    if ((width     == ptr->width) &&
+		(height    == ptr->height) &&
+		(frequency == ptr->vfreq)) {
+		return (ptr->id_string);
+	    }
+	}
+
+	/*
+	 * Look for the mode name in the active Mode entries of the config file
+	 */
+	for (mode_elem = mode_list;
+	    mode_elem != NULL;
+	    mode_elem = mode_elem->list.next) {
+	    XF86ConfModeLinePtr mode_ptr; /* ModeLine / Mode-EndMode entry */
+	    int		ml_vfreq;	/* Computed vertical frequency */
+
+	    /*
+	     * Get the config file ModeLine / Mode-EndMode entry
+	     */
+	    mode_ptr = mode_elem->mode_ptr;
+
+	    /*
+	     * Compute the vertical frequency for the ModeLine entry
+	     */
+	    ml_vfreq = mode_ptr->ml_htotal * mode_ptr->ml_vtotal;
+	    if (ml_vfreq <= 0) {
+		continue;	/* Don't divide by zero or use negatives */
+	    }
+	    ml_vfreq = mode_ptr->ml_clock * 1000 / ml_vfreq;
+
+	    /*
+	     * If the parameters match, return the video mode name
+	     */
+	    if ((width     == mode_ptr->ml_hdisplay) &&
+		(height    == mode_ptr->ml_vdisplay) &&
+		(frequency ==           ml_vfreq)) {
+		return (mode_ptr->ml_identifier);
+	    }
+	}
+
+	/*
+	 * Construct and return a WxHxF mode name in the caller-supplied buffer
+	 */
+	snprintf(name_buf, NAME_BUF_LEN, "%dx%dx%d", width, height, frequency);
+	return (name_buf);
+
+}	/* get_stiming_name() */
+
+
+/*
+ * add_stiming_modes()
+ *
+ *    Given an EDID data block, decode each of the Standard Timings and
+ *    determine a name for it, and populate a dynamically allocated
+ *    array of pointers to these Standard Timings names.
+ */
+
+static
+void
+add_stiming_modes(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	fbc_mode_elem_t	*mode_list,	/* Modes from config file */
+	sun_edid_mode_t	*edid_modes,	/* Growing list of modes */
+	sun_edid_mode_t	**edid_modes_end) /* Ptr to end of modes list */
+{
+	int		addr;		/* Byte address within EDID block */
+	int		edid_ver_rev;	/* EDID version and revision */
+	int		frequency;	/* Vertical frequency */
+	int		height;		/* Vertical addressable lines */
+	char		mode_name_buf[NAME_BUF_LEN];
+	int		width;		/* Horizontal addressable pixels */
+
+	edid_ver_rev = EDID_VER_REV(edid_data);
+
+	/*
+	 * Decode each of the eight Std Timings and add the names to the list
+	 */
+	for (addr = 0x26; addr < 0x36; addr += 2) {
+	    if (decode_stiming(edid_ver_rev, &edid_data[addr],
+				&width, &height, &frequency) == 0) {
+		add_video_mode(edid_modes, edid_modes_end,
+				get_stiming_name(width,
+						height,
+						frequency,
+						mode_list,
+						mode_name_buf),
+				width, height, frequency);
+	    }
+	}
+
+	/*
+	 * Decode any Standard Timings contained in 18-Byte Data Blocks
+	 *
+	 *    The display device may have additional Standard Timings
+	 *    in the 18-Byte Data Blocks (formerly known as Detailed
+	 *    Timing blocks).
+	 *
+	 *    The VESA EDID 1.4 spec requires the first 18-Byte Data
+	 *    Block to contain the Preferred Timing Mode.  EDID 1.1 and
+	 *    1.2 allowed this block to be used for a Display (Monitor)
+	 *    Descriptor, however, so it's best to simply scan all of
+	 *    the blocks.
+	 *
+	 *    Not applicable prior to EDID 1.1
+	 */
+	if (edid_ver_rev >= EDID_1_1) {
+	    /*
+	     * Examine each of the four 18-Byte Data Blocks
+	     *
+	     *    An 18-Byte Data Block is encoded in 18 (decimal) bytes.
+	     *    The 1st descriptor starts at EDID block address 0x36.
+	     *    The 4th descriptor ends at EDID block address 0x7E.
+	     */
+	    for (addr = 0x36; addr < 0x7E; addr += 18) {
+		/*
+		 * See if this 18-Byte Data Block contains Standard Timings
+		 */
+		if ((edid_data[addr+0] == 0) &&	/* Display Descriptor */
+		    (edid_data[addr+1] == 0) &&	/* Display Descriptor */
+		    (edid_data[addr+2] == 0) &&	/* Reserved */
+		    (edid_data[addr+3] == 0xFA) && /* Std Timing Ident tag */
+		    (edid_data[addr+4] == 0)) {	/* Reserved */
+		    int i;
+
+		    /*
+		     * Decode the six Std Timings and add the names to the list
+		     *
+		     *    Standard Timings are encoded in 2 bytes.
+		     *    The 1st pair of bytes starts at offset 5.
+		     *    The 6th pair of bytes ends at offset 17 (decimal).
+		     */
+		    for (i = 5; i < 17; i += 2) {
+			if (decode_stiming(edid_ver_rev, &edid_data[addr + 1],
+					&width, &height, &frequency) == 0) {
+			    add_video_mode(edid_modes, edid_modes_end,
+					get_stiming_name(width,
+							height,
+							frequency,
+							mode_list,
+							mode_name_buf),
+					width, height, frequency);
+			}
+		    }
+		}
+	    }
+	}
+
+}	/* add_stiming_modes() */
+
+#if defined(ACTIVATE_DEAD_CODE)	/* Not used by fbconfig */
+
+/*
+ * sun_edid_stiming_modes()
+ *
+ *    Return a NULL-terminated array of Standard Timing mode name
+ *    strings that the display device supports, according to the timing
+ *    data found in this EDID data block.
+ *
+ *    The dynamically allocated memory for the array and name strings
+ *    can be freed by calling the sun_edid_mode_names_free() function.
+ */
+
+char **
+sun_edid_stiming_modes(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	size_t		len,		/* EDID data length */
+	fbc_mode_elem_t	*mode_list)	/* Modes from config file */
+{
+	sun_edid_mode_t	*edid_modes;	/* Returned list of mode names */
+	sun_edid_mode_t	*edid_modes_end; /* Ptr to end of mode names list */
+
+	/*
+	 * Allocate and populate an array of pointers to Standard Timing names
+	 *
+	 *    There may be:
+	 *      8  Standard Timings mode names
+	 *    4*6  Additional Standard Timings names  (6 per descriptor)
+	 *      1  NULL terminator for the array
+	 */
+	edid_modes = malloc((8 + 4*6 + 1) * sizeof (*edid_modes));
+	if (edid_modes != NULL) {
+	    edid_modes_end       = edid_modes;
+	    edid_modes_end->name = NULL;
+
+	    add_stiming_modes(
+			edid_data, mode_list, edid_modes, &edid_modes_end);
+
+	    if (edid_modes_end <= edid_modes) {
+		free(edid_modes);
+		edid_modes = NULL;	/* The list is empty */
+	    }
+	}
+
+	return (edid_modes);
+
+}	/* sun_edid_stiming_modes() */
+
+#endif	/* Not used by fbconfig */
+
+/*
+ * get_dtiming_name()
+ *
+ *    Given decoded Detailed Timing info, produce a corresponding video
+ *    mode / resolution name.  The name might be found in a built-in
+ *    table or in configuration file video modes data structures, or it
+ *    might be constructed on the fly.
+ *
+ *    If a name must be constructed, the caller-supplied name_buf buffer
+ *    will be used.  The buffer must be at least NAME_BUF_LEN bytes
+ *    long.
+ */
+
+static
+const char *
+get_dtiming_name(
+	const sun_edid_dtiming_t *dt,	/* Detailed Timing info */
+	int		frequency,	/* Vertical frequency */
+	fbc_mode_elem_t	*mode_list,	/* Modes from config file */
+	char		*name_buf)	/* Buffer for returned WxHxF name */
+{
+	/*
+	 * Detailed Timing data repackaged as xorg.conf ModeLine data
+	 */
+	int		dt__hdisplay;	/* Horizontal addressable pixels */
+	int		dt__hsyncstart;
+	int		dt__hsyncend;
+	int		dt__htotal;	/* Total horizontal pixels */
+	int		dt__vdisplay;	/* Vertical addressable lines */
+	int		dt__vsyncstart;
+	int		dt__vsyncend;
+	int		dt__vtotal;	/* Total vertical lines */
+	int		dt__interlace;	/* TRUE => Interlaced */
+	int		dt__stereo;	/* TRUE => Stereo viewing support */
+	int		dt__digital;	/* TRUE => Digital sync */
+/*???*/	int		dt__composite;	/* TRUE => Composite sync */
+
+	SunVideoTiming	info;		/* Video timing info block */
+	fbc_mode_elem_t	*mode_elem;	/* Modes list element (unintrusive) */
+	XF86ConfModeLinePtr mode_ptr;	/* ModeLine / Mode-EndMode entry */
+	const SunVideoSummary *ptr;	/* Ptr into SunVideoTable[] table */
+
+	/*
+	 * Look for the video mode name in the built-in SunVideoTable[] table
+	 */
+	dtiming_to_vtiming(dt, &info);
+
+	for (ptr = &SunVideoTable[0]; ptr->id_string != NULL; ptr += 1) {
+	    if ((info.Hact  == ptr->width) &&
+		(info.Vact  == ptr->height) &&
+		(info.Pclk  == ptr->Pclk) &&
+		(info.Hfp   == ptr->Hfp) &&
+		(info.Hsw   == ptr->Hsw) &&
+		(info.Hbp   == ptr->Hbp) &&
+		(info.Vfp   == ptr->Vfp) &&
+		(info.Vsw   == ptr->Vsw) &&
+		(info.Vbp   == ptr->Vbp) &&
+		(info.Fint  == ptr->Fint) &&
+		(info.Fst   == ptr->Fst) &&
+		(info.Stype == ptr->Stype) &&
+		(info.SHpol == ptr->SHpol) &&
+		(info.SVpol == ptr->SVpol)) {
+		return (ptr->id_string);
+	    }
+	}
+
+	/*
+	 * Look for the mode name in the active Mode entries of the config file
+	 *
+	 *    Not used in establishing a match:
+	 *      dt->hsize   - Addressable Video Image, millimeters
+	 *      dt->vsize   - Addressable Video Image, millimeters
+???	 *      dt->hborder - Not in common use (typically zero)
+???	 *      dt->vborder - Not in common use (typically zero)
+	 *      mode_ptr->ml_vscan - Times each scan line is painted
+	 *      mode_ptr->ml_hskew - Pixels that Display Enable is skewed
+	 */
+//???	dt__hdisplay   = dt->hborder + dt->hactive + dt->hborder;
+	dt__hdisplay   = dt->hactive;
+	dt__hsyncstart = dt__hdisplay   + dt->hsyncOffset;
+	dt__hsyncend   = dt__hsyncstart + dt->hsyncWidth;
+	dt__htotal     = dt__hdisplay   + dt->hblanking;
+
+//???	dt__vdisplay   = dt->vborder + dt->vactive + dt->vborder;
+	dt__vdisplay   = dt->vactive;
+	dt__vsyncstart = dt__vdisplay   + dt->vsyncOffset;
+	dt__vsyncend   = dt__vsyncstart + dt->vsyncWidth;
+	dt__vtotal     = dt__vdisplay   + dt->vblanking;
+
+	dt__interlace  = ((dt->flags & 0x80) != 0);
+	dt__stereo     = ((dt->flags & 0x60) != 0);
+	dt__digital    = ((dt->flags & 0x10) != 0);
+/*???*/	dt__composite  = ((dt->flags & 0x08) == 0);
+
+	for (mode_elem = mode_list;
+	    mode_elem != NULL;
+	    mode_elem = mode_elem->list.next) {
+	    /*
+	     * See whether the ModeLine / Mode-EndMode config entry matches
+	     *
+	     *    The Stereo and Digital attributes of a mode from the
+	     *    config file can't be determined except by parsing the
+	     *    mode name.  That can tell us whether the attribute is
+	     *    TRUE, but not for sure whether it is FALSE.  The only
+	     *    certainty is that there's no match when the Detailed
+	     *    Timing attribute (dt__xxxxx) is FALSE and the config
+	     *    file mode attribute (fbc_resname_xxxxx()) is TRUE.
+	     */
+	    mode_ptr = mode_elem->mode_ptr;
+	    if ((dt->pixclock   == mode_ptr->ml_clock * 1000) &&
+		(dt__hdisplay   == mode_ptr->ml_hdisplay) &&
+		(dt__hsyncstart == mode_ptr->ml_hsyncstart) &&
+		(dt__hsyncend   == mode_ptr->ml_hsyncend) &&
+		(dt__htotal     == mode_ptr->ml_htotal) &&
+		(dt__vdisplay   == mode_ptr->ml_vdisplay) &&
+		(dt__vsyncstart == mode_ptr->ml_vsyncstart) &&
+		(dt__vsyncend   == mode_ptr->ml_vsyncend) &&
+		(dt__vtotal     == mode_ptr->ml_vtotal) &&
+		(dt__interlace  ==
+			((mode_ptr->ml_flags & XF86CONF_INTERLACE) != 0)) &&
+//???		(dt__composite  ==
+//???			((mode_ptr->ml_flags & XF86CONF_CSYNC) != 0)) &&
+		(dt__stereo || !fbc_resname_stereo(mode_ptr->ml_identifier)) &&
+		(dt__digital ||
+			!fbc_resname_digital(mode_ptr->ml_identifier))) {
+		return (mode_ptr->ml_identifier);
+	    }
+	}
+
+	/*
+	 * Construct and return a WxHxF mode name in the caller-supplied buffer
+	 */
+	snprintf(name_buf, NAME_BUF_LEN, "%dx%dx%d",
+		dt->hactive, dt->vactive, frequency);
+	return (name_buf);
+
+}	/* get_dtiming_name() */
+
+
+/*
+ * add_dtiming_modes()
+ *
+ *    Add Detailed Timing mode names to the list of mode names.
+ */
+
+static
+void
+add_dtiming_modes(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	size_t		edid_length,	/* EDID data length */
+	fbc_mode_elem_t	*mode_list,	/* Modes from config file */
+	sun_edid_mode_t	*edid_modes,	/* Growing list of modes */
+	sun_edid_mode_t	**edid_modes_end) /* Ptr to end of modes list */
+{
+	int		addr;		/* Address of 18-Byte Data Block */
+	sun_edid_dtiming_t dt;		/* Detailed Timing info */
+	char		mode_name_buf[NAME_BUF_LEN];
+
+	/*
+	 * Examine each of the four 18-Byte Data Blocks for Detailed Timings
+	 *
+	 *    An 18-Byte Data Block is encoded in 18 (decimal) bytes.
+	 *    The 1st descriptor starts at EDID block address 0x36.
+	 *    The 4th descriptor ends at EDID block address 0x7E.
+	 */
+	for (addr = 0x36; addr < 0x7E; addr += 18) {
+	    /*
+	     * Decode this 18-Byte Data Block if it's a Detailed Timing Block
+	     */
+	    if (decode_dtiming(&edid_data[addr], &dt) == 0) {
+		int	frequency;	/* Vertical frequency */
+
+		frequency = get_dtiming_frequency(&dt);
+		add_video_mode(edid_modes,
+				edid_modes_end,
+				get_dtiming_name(&dt,
+						frequency,
+						mode_list,
+						mode_name_buf),
+				dt.hactive,
+				dt.vactive,
+				frequency);
+
+		/*
+???		 * "Only valid in Edid 1.1 or higher"
+		 *
+		 *    In EDID 1.0, the Preferred Timing Descriptor
+		 *    Block is optional.  Other Detailed Timing
+		 *    Blocks appear to be not applicable.
+		 */
+		if (EDID_VER_REV(edid_data) < EDID_1_1) {
+		    break;
+		}
+	    }
+	}
+
+	/* Someday we should look at what's in any EDID Extension Blocks */
+
+}	/* add_dtiming_modes() */
+
+#if defined(ACTIVATE_DEAD_CODE)	/* Not used by fbconfig */
+
+/*
+ * sun_edid_dtiming_modes()
+ *
+ *    Return a NULL-terminated array of Detailed Timing mode name
+ *    strings that the display device supports, according to the timing
+ *    data found in this EDID data block.  The first element will
+ *    contain the name of the display device's preferred mode.
+ *
+ *    Knowing the length of the EDID data, the EDID parser can examine
+ *    extension blocks for more information.
+ *
+ *    The dynamically allocated memory for the array and name strings
+ *    can be freed by calling the sun_edid_mode_names_free() function.
+ */
+
+char **
+sun_edid_dtiming_modes(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	size_t		edid_length,	/* EDID data length */
+	fbc_mode_elem_t	*mode_list)	/* Modes from config file */
+{
+	sun_edid_mode_t	*edid_modes;	/* Returned list of mode names */
+	sun_edid_mode_t	*edid_modes_end; /* Ptr to end of list */
+
+	/*
+	 * Allocate and populate an array of pointers to Detailed Timing names
+	 *
+	 *    There may be:
+	 *      4  Detailed Timings mode names  (1 per descriptor)
+	 *      1  NULL terminator for the array
+	 */
+	edid_modes = malloc((4 + 1) * sizeof (*edid_modes));
+	if (edid_modes != NULL) {
+	    edid_modes_end       = edid_modes;
+	    edid_modes_end->name = NULL;
+
+	    add_dtiming_modes(edid_data, edid_length, mode_list,
+				edid_modes, &edid_modes_end);
+
+	    if (edid_modes_end <= edid_modes) {
+		free(edid_modes);
+		edid_modes = NULL;	/* The list is empty */
+	    }
+	}
+
+	return (edid_modes);
+
+}	/* sun_edid_dtiming_modes() */
+
+#endif	/* Not used by fbconfig */
+
+/*
+ * sun_edid_video_modes()
+ *
+ *    Return a NULL-terminated array of video mode name strings that the
+ *    display device supports, according to the timing data found in
+ *    this EDID data block.  The first array element will contain the
+ *    name of the display device's preferred mode, else the mode name
+ *    string will be empty.
+ *
+ *    Knowing the length of the EDID data, the EDID parser can examine
+ *    extension blocks for more information.  Hypothetically, for now.
+ *
+ *    The dynamically allocated memory for the array and name strings
+ *    can be freed by calling the sun_edid_mode_names_free() function.
+ */
+
+sun_edid_mode_t *
+sun_edid_video_modes(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	size_t		edid_length,	/* EDID data length */
+	fbc_mode_elem_t	*mode_list)	/* Modes from config file */
+{
+	sun_edid_mode_t	*edid_modes;	/* Returned list of video modes */
+	sun_edid_mode_t	*edid_modes_end; /* Ptr to end of list */
+
+	/*
+	 * Allocate and populate an array of EDID video mode names
+	 *
+	 *    There may be:
+	 *      4  Detailed Timings modes  (1 per descriptor)
+	 *      8  Standard Timings modes
+	 *    4*6  Additional Standard Timing modes  (6 per descriptor)
+	 *     24  Established Timings modes         (ETIMING_BITS     = 24)
+	 *     48  Established Timings III modes     (ETIMING_III_BITS = 48)
+	 *      1  Array terminator (NULL name ptr)
+	 *
+	 *    Note that an 18-Byte Data Block can contain one Detailed
+	 *    Timing or six additional Standard Timings or 48
+	 *    Established Timing IIIs, so this array will always be
+	 *    longer than necessary.
+	 */
+	edid_modes = malloc((4 + 8 + 4*6 + ETIMING_BITS + ETIMING_III_BITS + 1)
+					* sizeof (sun_edid_mode_t));
+	if (edid_modes != NULL) {
+	    edid_modes_end       = edid_modes;
+	    edid_modes_end->name = NULL;
+
+	    add_dtiming_modes(edid_data, edid_length, mode_list,
+				edid_modes, &edid_modes_end);
+	    if (edid_modes_end == edid_modes) {
+		/* Show that no Preferred Timing Mode was found */
+		add_video_mode(edid_modes, &edid_modes_end, "", 0, 0, 0);
+	    }
+	    add_stiming_modes(edid_data, mode_list,
+				edid_modes, &edid_modes_end);
+	    add_etiming_modes(edid_data, edid_modes, &edid_modes_end);
+	}
+
+	return (edid_modes);
+
+}	/* sun_edid_video_modes() */
+
+
+/*
+ * sun_edid_video_modes_free()
+ *
+ *    Free a NULL-terminated array of EDID video modes that was returned
+ *    by one of the add_[esd]mode_names() functions above.
+ */
+
+void
+sun_edid_video_modes_free(
+	sun_edid_mode_t	*edid_modes)	/* EDID video mode list */
+{
+	sun_edid_mode_t	*video_mode;	/* Ptr to video mode within list */
+
+	if (edid_modes != NULL) {
+	    for (video_mode = edid_modes;
+		video_mode->name != NULL;
+		video_mode += 1) {
+		free(video_mode->name);
+	    }
+	    free(edid_modes);
+	}
+
+}	/* sun_edid_video_modes_free() */
+
+
+/* End of sun_edid.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/fbc/sun_edid.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,256 @@
+/*
+ * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+
+/* sun_edid - EDID data parsing */
+
+
+#ifndef	_SUN_EDID_H
+#define	_SUN_EDID_H
+
+
+#include <sys/types.h>		/* uint8_t, uint16_t, uint32_t */ 
+
+//#include "gfx_res_util.h"	/* SunVideoTiming */
+
+#include "resolutions.h"	/* Video mode summary table: SunVideoTable[] */
+
+#include "fbc_mode_list.h"	/* List of Modes from Monitor section of cfg */
+
+
+/*
+ * EDID Version & Revision comparison primitives
+ */
+#define	EDID_VER_REV(_BUF)	sun_edid_get_be_short(&_BUF[0x12])
+#define	EDID_1_0		0x0100		/* EDID 1.0 */
+#define	EDID_1_1		0x0101		/* EDID 1.1 */
+#define	EDID_1_2		0x0102		/* EDID 1.2 */
+#define	EDID_1_3		0x0103		/* EDID 1.3 */
+#define	EDID_1_4		0x0104		/* EDID 1.4 */
+
+
+uint16_t sun_edid_get_be_short(
+	const uint8_t	*edid_data);	/* EDID data bytes */
+
+uint16_t sun_edid_get_le_short(
+	const uint8_t	*edid_data);	/* EDID data bytes */
+
+uint32_t sun_edid_get_le_long(
+	const uint8_t	*edid_bytes);	/* EDID data bytes */
+
+uint8_t sun_edid_checksum(
+	const uint8_t	*edid_data);	/* EDID data block */
+
+int sun_edid_check_base(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	size_t		edid_length);	/* EDID data length */
+
+int sun_edid_check_extensions(
+	const uint8_t	*edid_data,	/* Base & Extension EDID blocks */
+	size_t		edid_length);	/* EDID data length */
+
+void sun_edid_vendor(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	char		*name,		/* Manufacturer ID  (3 chars & Nul) */
+	uint16_t	*product_code,	/* Product code */
+	uint32_t	*serial_num);	/* Serial number, else zero */
+
+void sun_edid_mdate(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	int		*week,		/* Week of manufacture (or flags) */
+	int		*year);		/* Year of manufacture or model year */
+
+/* Video Input Definition */
+typedef struct {
+	short		digital;	/* TRUE => Digital Video Interface */
+	/* Analog Video Signal Interface */
+	struct {
+		float	video;		/* Signal Level Standard, Video */
+		float	sync;		/* Signal Level Standard, Sync */
+		short	black2black    : 1; /* Blank-to-Black or pedestal */
+		short	sync_separate  : 1; /* Separate Sync H & V Signals */
+		short	sync_composite : 1; /* Composite Sync on Horizontal */
+		short	sync_green     : 1; /* Composite Sync on Green Video */
+		short	serration      : 1; /* Serration on Vertical Sync */
+	} alg;
+	/* Digital Video Signal Interface */
+	struct {
+		short	color_depth;	/* Color Bit Depth */
+		short	vid_standard;	/* Digital Video Interface Standard */
+	} dig;
+} sun_edid_viddef_t;
+
+void sun_edid_video_input(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	sun_edid_viddef_t *video_def);	/* Returned Video Input Definition */
+
+void sun_edid_screen_size(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	int		*horizontal,	/* Horizontal Screen Size (cm), etc. */
+	int		*vertical,	/* Vertical Screen Size (cm), etc. */
+	float		*aspect);	/* Aspect ratio, else zero */
+
+void sun_edid_gamma(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	float		*gamma);	/* Returned gamma value, else zero */
+
+/* EDID Feature Support info */
+typedef struct {
+	short		color_info;	/* Color Type / Color Encoding Fmt */
+	short		standby    : 1;	/* TRUE => Standby Mode supported */
+	short		suspend    : 1;	/* TRUE => Suspend Mode supported */
+	short		active_off : 1;	/* TRUE => Active Off supported */
+	short		digital    : 1;	/* TRUE => Input is Digital Video */
+	short		srgb_std   : 1;	/* TRUE => sRGB Std is default */
+	short		ptm_incl   : 1;	/* TRUE => PTM does include ... */
+	short		cont_freq  : 1;	/* TRUE => Continuous frequency */
+} sun_edid_feature_t;
+
+void sun_edid_feature_support(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	sun_edid_feature_t *feature);	/* Returned Feature Support info */
+
+/* EDID Color Characteristics */
+typedef struct {
+	float		red_x;		/* Red-x   */
+	float		red_y;		/* Red-y   */
+	float		green_x;	/* Green-x */
+	float		green_y;	/* Green-y */
+	float		blue_x;		/* Blue-x  */
+	float		blue_y;		/* Blue-y  */
+	float		white_x;	/* White-x */
+	float		white_y;	/* White-y */
+} sun_edid_colorchrs_t;
+
+void sun_edid_color_chars(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	sun_edid_colorchrs_t *color_char); /* Returned Color Characteristics */
+
+int sun_edid_bit_set(
+	const uint8_t	*edid_bytes,	/* First byte of the bit field */
+	int		bit_off);	/* Bit offset into the bit field */
+
+int sun_edid_etiming(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	int		addr,		/* Byte address within EDID block */
+	int		bit_off,	/* Established Timings bit offset */
+	int		*width,		/* Returned horiz addressable pixels */
+	int		*height,	/* Returned vert addressable lines */
+	int		*frequency);	/* Returned vertical frequency */
+
+int sun_edid_stiming(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	int		addr,		/* Byte address within EDID block */
+	int		*width,		/* Returned horiz addressable pixels */
+	int		*height,	/* Returned vert addressable lines */
+	int		*frequency);	/* Returned vertical frequency */
+
+/* Detailed Timing information */
+typedef struct {
+	long		pixclock;	/* Pixel Clock, kHz   (Bytes #0,1) */
+	int		hactive;	/* H Addr'able Video  (Bytes #2,4) */
+	int		hblanking;	/* Horiz Blanking     (Bytes #3,4) */
+	int		vactive;	/* V Addr'able Video  (Bytes #5,7) */
+	int		vblanking;	/* Vert Blanking      (Bytes #6,7) */
+	int		hsyncOffset;	/* Horiz Front Porch  (Bytes #8,11) */
+	int		hsyncWidth;	/* H Sync Pulse Width (Bytes #9,11) */
+	int		vsyncOffset;	/* Vert Front Porch   (Bytes #10,11) */
+	int		vsyncWidth;	/* V Sync Pulse Width (Bytes #10,11) */
+	int		hsize;		/* H Addr Vid Img, mm (Bytes #12,14) */
+	int		vsize;		/* V Addr Vid Img, mm (Bytes #13,14) */
+	int		hborder;	/* L/R Horiz Border   (Byte  #15) */
+	int		vborder;	/* Top/Bot V Border   (Byte  #16) */
+	int		flags;		/* Flag bits & fields (Byte  #17) */
+} sun_edid_dtiming_t;
+
+int sun_edid_dtiming(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	int		addr,		/* Byte address within EDID block */
+	sun_edid_dtiming_t *dt);	/* Returned Detailed Timing info */
+
+void sun_edid_descriptor_string(
+	const uint8_t	*edid_data,	/* Display Descriptor bytes */
+	char		*string_buf);	/* Returned Display Descriptor str */
+
+int sun_edid_serial_number(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	char		*string_buf);	/* Returned Display Product Serial # */
+
+int sun_edid_alphanum_data(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	char		*string_buf);	/* Returned Alphanumeric Data String */
+
+
+/* Display Range Limits */
+typedef struct {
+	uint16_t	vert_min;	/* Minimum Vertical Rate */
+	uint16_t	vert_max;	/* Maximum Vertical Rate */
+	uint16_t	horiz_min;	/* Minimum Horizontal Rate */
+	uint16_t	horiz_max;	/* Maximum Horizontal Rate */
+	uint16_t	pixclock_max;	/* Maximum Pixel Clock */
+	/* Generalized Timing Formula (GTF) Secondary Curve (deprecated) */
+	uint16_t	gtf_start_break; /* Start break frequency */
+	uint16_t	gtf_C;
+	uint16_t	gtf_M;
+	uint16_t	gtf_K;
+	uint16_t	gtf_J;
+	/* CVT Support */
+	uint8_t		cvt_version;	/* CVT Standard Version Number */
+	uint16_t	cvt_pixclock_max; /* Maximum Pixel Clock */
+	uint16_t	cvt_hactive_max; /* Maximum Active Pixels per line */
+} sun_edid_range_lim_t;
+
+void sun_edid_range_limits(
+	const uint8_t	*edid_data,	/* Display Descriptor bytes */
+	sun_edid_range_lim_t *range_limits); /* Display Range Limits */ 
+
+int sun_edid_product_name(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	char		*string_buf);	/* Returned Display Product Name */
+
+/*
+ * End of EDID structure parsing functions
+ * ---------------------------------------------------------------------
+ * Start of EDID video mode name list construction functions
+ */
+
+typedef struct {
+	char		*name;		/* Video mode name */
+	short		width;		/* Horizontal addressable pixels */
+	short		height;		/* Vertical addressable lines */
+	short		frequency;	/* Vertical frequency */
+} sun_edid_mode_t;
+
+sun_edid_mode_t *sun_edid_video_modes(
+	const uint8_t	*edid_data,	/* EDID Base block, etc. */
+	size_t		edid_length,	/* EDID data length */
+	fbc_mode_elem_t	*mode_list);	/* Modes from config file */
+
+void sun_edid_video_modes_free(
+	sun_edid_mode_t	*edid_modes);	/* EDID video mode list */
+
+
+#endif	/* _SUN_EDID_H */
+
+
+/* End of sun_edid.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Configint.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,239 @@
+/*
+ * 
+ * Copyright (c) 1997  Metro Link Incorporated
+ * 
+ * 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
+ * THE X CONSORTIUM 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.
+ * 
+ * Except as contained in this notice, the name of the Metro Link shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Metro Link.
+ * 
+ */
+/*
+ * Copyright (c) 1997-2002 by The XFree86 Project, 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
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+
+/* 
+ * These definitions are used through out the configuration file parser, but
+ * they should not be visible outside of the parser.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifndef _Configint_h_
+#define _Configint_h_
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include "xf86Parser.h"
+
+typedef struct
+{
+	int num;		/* returned number */
+	char *str;		/* private copy of the return-string */
+	double realnum;		/* returned number as a real */
+}
+LexRec, *LexPtr;
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#include "configProcs.h"
+#include <stdlib.h>
+#define xf86confmalloc malloc
+#define xf86confrealloc realloc
+#define xf86confcalloc calloc
+#define xf86conffree free
+
+#define TestFree(a) if (a) { xf86conffree (a); a = NULL; }
+
+#define parsePrologue(typeptr,typerec) typeptr ptr; \
+if( (ptr=(typeptr)xf86confcalloc(1,sizeof(typerec))) == NULL ) { return NULL; } \
+memset(ptr,0,sizeof(typerec));
+
+#define parsePrologueVoid(typeptr,typerec) int token; typeptr ptr; \
+if( (ptr=(typeptr)xf86confcalloc(1,sizeof(typerec))) == NULL ) { return; } \
+memset(ptr,0,sizeof(typerec));
+
+#define HANDLE_RETURN(f,func)\
+if ((ptr->f=func) == NULL)\
+{\
+	CLEANUP (ptr);\
+	return (NULL);\
+}
+
+#define HANDLE_LIST(field,func,type)\
+{\
+type p = func ();\
+if (p == NULL)\
+{\
+	CLEANUP (ptr);\
+	return (NULL);\
+}\
+else\
+{\
+	ptr->field = (type) xf86addListItem ((glp) ptr->field, (glp) p);\
+}\
+}
+
+#define Error(a,b) do { \
+			xf86parseError (a, b); CLEANUP (ptr); return NULL; \
+		   } while (0)
+
+/* 
+ * These are defines for error messages to promote consistency.
+ * error messages are preceded by the line number, section and file name,
+ * so these messages should be about the specific keyword and syntax in error.
+ * To help limit namespace polution, end each with _MSG.
+ * limit messages to 70 characters if possible.
+ */
+
+#define BAD_OPTION_MSG \
+"The Option keyword requires 1 or 2 quoted strings to follow it."
+#define INVALID_KEYWORD_MSG \
+"\"%s\" is not a valid keyword in this section."
+#define INVALID_SECTION_MSG \
+"\"%s\" is not a valid section name."
+#define UNEXPECTED_EOF_MSG \
+"Unexpected EOF. Missing EndSection keyword?"
+#define QUOTE_MSG \
+"The %s keyword requires a quoted string to follow it."
+#define NUMBER_MSG \
+"The %s keyword requires a number to follow it."
+#define POSITIVE_INT_MSG \
+"The %s keyword requires a positive integer to follow it."
+#define ZAXISMAPPING_MSG \
+"The ZAxisMapping keyword requires 2 positive numbers or X or Y to follow it."
+#define AUTOREPEAT_MSG \
+"The AutoRepeat keyword requires 2 numbers (delay and rate) to follow it."
+#define XLEDS_MSG \
+"The XLeds keyword requries one or more numbers to follow it."
+#define DACSPEED_MSG \
+"The DacSpeed keyword must be followed by a list of up to %d numbers."
+#define DISPLAYSIZE_MSG \
+"The DisplaySize keyword must be followed by the width and height in mm."
+#define HORIZSYNC_MSG \
+"The HorizSync keyword must be followed by a list of numbers or ranges."
+#define VERTREFRESH_MSG \
+"The VertRefresh keyword must be followed by a list of numbers or ranges."
+#define VIEWPORT_MSG \
+"The Viewport keyword must be followed by an X and Y value."
+#define VIRTUAL_MSG \
+"The Virtual keyword must be followed by a width and height value."
+#define WEIGHT_MSG \
+"The Weight keyword must be followed by red, green and blue values."
+#define BLACK_MSG \
+"The Black keyword must be followed by red, green and blue values."
+#define WHITE_MSG \
+"The White keyword must be followed by red, green and blue values."
+#define SCREEN_MSG \
+"The Screen keyword must be followed by an optional number, a screen name\n" \
+"\tin quotes, and optional position/layout information."
+#define INVALID_SCR_MSG \
+"Invalid Screen line."
+#define INPUTDEV_MSG \
+"The InputDevice keyword must be followed by an input device name in quotes."
+#define INACTIVE_MSG \
+"The Inactive keyword must be followed by a Device name in quotes."
+#define UNDEFINED_SCREEN_MSG \
+"Undefined Screen \"%s\" referenced by ServerLayout \"%s\"."
+#define UNDEFINED_MONITOR_MSG \
+"Undefined Monitor \"%s\" referenced by Screen \"%s\"."
+#define UNDEFINED_MODES_MSG \
+"Undefined Modes Section \"%s\" referenced by Monitor \"%s\"."
+#define UNDEFINED_DEVICE_MSG \
+"Undefined Device \"%s\" referenced by Screen \"%s\"."
+#define UNDEFINED_ADAPTOR_MSG \
+"Undefined VideoAdaptor \"%s\" referenced by Screen \"%s\"."
+#define ADAPTOR_REF_TWICE_MSG \
+"VideoAdaptor \"%s\" already referenced by Screen \"%s\"."
+#define UNDEFINED_DEVICE_LAY_MSG \
+"Undefined Device \"%s\" referenced by ServerLayout \"%s\"."
+#define UNDEFINED_INPUT_MSG \
+"Undefined InputDevice \"%s\" referenced by ServerLayout \"%s\"."
+#define NO_IDENT_MSG \
+"This section must have an Identifier line."
+#define ONLY_ONE_MSG \
+"This section must have only one of either %s line."
+#define UNDEFINED_DRIVER_MSG \
+"Device section \"%s\" must have a Driver line."
+#define UNDEFINED_INPUTDRIVER_MSG \
+"InputDevice section \"%s\" must have a Driver line."
+#define INVALID_GAMMA_MSG \
+"gamma correction value(s) expected\n either one value or three r/g/b values."
+#define GROUP_MSG \
+"The Group keyword must be followed by either a group name in quotes or\n" \
+"\ta numerical group id."
+#define MULTIPLE_MSG \
+"Multiple \"%s\" lines."
+#define	MONITOR_SYNTAX_MSG \
+"The Monitor keyword must be followed by an optional monitor number and\n" \
+"\ta monitor name in quotes."
+#define	MONITOR_NUM_REQUIRED_MSG \
+"The Monitor keyword must be followed by a monitor number when there\n" \
+"\tare multiple monitor entries."
+#define	MONITOR_DUP_NUM_MSG \
+"Duplicate monitor number."
+#define	MONITOR_DUP_NAME_MSG \
+"Duplicate monitor name."
+
+#define	NO_MEMORY_MSG \
+"Insufficient memory."
+
+/* Warning messages */
+#define OBSOLETE_MSG \
+"Ignoring obsolete keyword \"%s\"."
+#define MOVED_TO_FLAGS_MSG \
+"Keyword \"%s\" is now an Option flag in the ServerFlags section."
+
+#endif /* _Configint_h_ */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/DRI.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,186 @@
+/* DRI.c -- DRI Section in XF86Config file
+ * Created: Fri Mar 19 08:40:22 1999 by [email protected]
+ * Revised: Thu Jun 17 16:08:05 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.
+ * 
+ * 
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "Configint.h"
+
+extern LexRec val;
+
+static xf86ConfigSymTabRec DRITab[] =
+{
+    {ENDSECTION, "endsection"},
+    {GROUP,      "group"},
+    {BUFFERS,    "buffers"},
+    {MODE,       "mode"},
+    {-1,         ""},
+};
+
+#define CLEANUP xf86freeBuffersList
+
+XF86ConfBuffersPtr
+xf86parseBuffers (void)
+{
+    int token;
+    parsePrologue (XF86ConfBuffersPtr, XF86ConfBuffersRec)
+
+    if (xf86getSubToken (&(ptr->buf_comment)) != NUMBER)
+	Error ("Buffers count expected", NULL);
+    ptr->buf_count = val.num;
+
+    if (xf86getSubToken (&(ptr->buf_comment)) != NUMBER)
+	Error ("Buffers size expected", NULL);
+    ptr->buf_size = val.num;
+
+    if ((token = xf86getSubToken (&(ptr->buf_comment))) == STRING) {
+	ptr->buf_flags = val.str;
+	if ((token = xf86getToken (NULL)) == COMMENT)
+	    ptr->buf_comment = xf86addComment(ptr->buf_comment, val.str);
+	else
+	    xf86unGetToken(token);
+    }
+
+#ifdef DEBUG
+    printf ("Buffers parsed\n");
+#endif
+
+    return ptr;
+}
+
+#undef CLEANUP
+	
+#define CLEANUP xf86freeDRI
+
+XF86ConfDRIPtr
+xf86parseDRISection (void)
+{
+    int token;
+    parsePrologue (XF86ConfDRIPtr, XF86ConfDRIRec);
+
+    /* Zero is a valid value for this. */
+    ptr->dri_group = -1;
+    while ((token = xf86getToken (DRITab)) != ENDSECTION) {
+	switch (token)
+	    {
+	    case GROUP:
+		if ((token = xf86getSubToken (&(ptr->dri_comment))) == STRING)
+		    ptr->dri_group_name = val.str;
+		else if (token == NUMBER)
+		    ptr->dri_group = val.num;
+		else
+		    Error (GROUP_MSG, NULL);
+		break;
+	    case MODE:
+		if (xf86getSubToken (&(ptr->dri_comment)) != NUMBER)
+		    Error (NUMBER_MSG, "Mode");
+		ptr->dri_mode = val.num;
+		break;
+	    case BUFFERS:
+		HANDLE_LIST (dri_buffers_lst, xf86parseBuffers,
+			     XF86ConfBuffersPtr);
+		break;
+	    case EOF_TOKEN:
+		Error (UNEXPECTED_EOF_MSG, NULL);
+		break;
+	    case COMMENT:
+		ptr->dri_comment = xf86addComment(ptr->dri_comment, val.str);
+		break;
+	    default:
+		Error (INVALID_KEYWORD_MSG, xf86tokenString ());
+		break;
+	    }
+    }
+    
+#ifdef DEBUG
+    ErrorF("DRI section parsed\n");
+#endif
+    
+    return ptr;
+}
+
+#undef CLEANUP
+
+void
+xf86printDRISection (FILE * cf, XF86ConfDRIPtr ptr)
+{
+    XF86ConfBuffersPtr bufs;
+    
+    if (ptr == NULL)
+	return;
+    
+    fprintf (cf, "Section \"DRI\"\n");
+    if (ptr->dri_comment)
+	fprintf (cf, "%s", ptr->dri_comment);
+    if (ptr->dri_group_name)
+	fprintf (cf, "\tGroup        \"%s\"\n", ptr->dri_group_name);
+    else if (ptr->dri_group >= 0)
+	fprintf (cf, "\tGroup        %d\n", ptr->dri_group);
+    if (ptr->dri_mode)
+	fprintf (cf, "\tMode         0%o\n", ptr->dri_mode);
+    for (bufs = ptr->dri_buffers_lst; bufs; bufs = bufs->list.next) {
+	fprintf (cf, "\tBuffers      %d %d",
+		 bufs->buf_count, bufs->buf_size);
+	if (bufs->buf_flags) fprintf (cf, " \"%s\"", bufs->buf_flags);
+	if (bufs->buf_comment)
+	    fprintf(cf, "%s", bufs->buf_comment);
+	else
+	    fprintf (cf, "\n");
+    }
+    fprintf (cf, "EndSection\n\n");
+}
+
+void
+xf86freeDRI (XF86ConfDRIPtr ptr)
+{
+    if (ptr == NULL)
+	return;
+    
+    xf86freeBuffersList (ptr->dri_buffers_lst);
+    TestFree (ptr->dri_comment);
+    xf86conffree (ptr);
+}
+
+void
+xf86freeBuffersList (XF86ConfBuffersPtr ptr)
+{
+    XF86ConfBuffersPtr prev;
+
+    while (ptr) {
+	TestFree (ptr->buf_flags);
+	TestFree (ptr->buf_comment);
+	prev = ptr;
+	ptr  = ptr->list.next;
+	xf86conffree (prev);
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Device.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,532 @@
+/* 
+ * 
+ * Copyright (c) 1997  Metro Link Incorporated
+ * 
+ * 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
+ * THE X CONSORTIUM 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.
+ * 
+ * Except as contained in this notice, the name of the Metro Link shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Metro Link.
+ * 
+ */
+/*
+ * Copyright (c) 1997-2003 by The XFree86 Project, 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
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+
+/* View/edit this file with tab stops set to 4 */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "Configint.h"
+#include "fields.h"		/* Config file output line fields */
+#if defined(SMI_FBCONFIG)
+#include "fbc_line_er.h"	/* External Representation of config lines */
+#endif
+
+extern LexRec val;
+
+static
+xf86ConfigSymTabRec DeviceTab[] =
+{
+	{ENDSECTION, "endsection"},
+	{IDENTIFIER, "identifier"},
+	{VENDOR, "vendorname"},
+	{BOARD, "boardname"},
+	{CHIPSET, "chipset"},
+	{RAMDAC, "ramdac"},
+	{DACSPEED, "dacspeed"},
+	{CLOCKS, "clocks"},
+	{OPTION, "option"},
+	{VIDEORAM, "videoram"},
+	{BIOSBASE, "biosbase"},
+	{MEMBASE, "membase"},
+	{IOBASE, "iobase"},
+	{CLOCKCHIP, "clockchip"},
+	{CHIPID, "chipid"},
+	{CHIPREV, "chiprev"},
+	{CARD, "card"},
+	{DRIVER, "driver"},
+	{BUSID, "busid"},
+	{TEXTCLOCKFRQ, "textclockfreq"},
+	{IRQ, "irq"},
+	{SCREEN, "screen"},
+	{-1, ""},
+};
+
+#define CLEANUP xf86freeDeviceList
+
+XF86ConfDevicePtr
+xf86parseDeviceSection (void)
+{
+	int i;
+	int has_ident = FALSE;
+	int token;
+#if defined(SMI_FBCONFIG)
+	void *line_er;		/* Ptr to Extnl Rep of config file line */
+#endif
+	parsePrologue (XF86ConfDevicePtr, XF86ConfDeviceRec)
+
+	/* Zero is a valid value for these */
+	ptr->dev_chipid = -1;
+	ptr->dev_chiprev = -1;
+	ptr->dev_irq = -1;
+	for (;;)
+	{
+		token = xf86getToken(DeviceTab);
+#if defined(SMI_FBCONFIG)
+		/*
+		 * Get a ptr to the External Representation of this config line
+		 */
+		line_er = fbc_get_current_line_ER();
+
+#endif
+		if (token == ENDSECTION)
+		{
+			break;
+		}
+		switch (token)
+		{
+		case COMMENT:
+			ptr->dev_comment = xf86addComment(ptr->dev_comment, val.str);
+			break;
+		case IDENTIFIER:
+			if (xf86getSubToken (&(ptr->dev_comment)) != STRING)
+				Error (QUOTE_MSG, "Identifier");
+			if (has_ident == TRUE)
+				Error (MULTIPLE_MSG, "Identifier");
+			ptr->dev_identifier = val.str;
+			has_ident = TRUE;
+			break;
+		case VENDOR:
+			if (xf86getSubToken (&(ptr->dev_comment)) != STRING)
+				Error (QUOTE_MSG, "Vendor");
+			ptr->dev_vendor = val.str;
+			break;
+		case BOARD:
+			if (xf86getSubToken (&(ptr->dev_comment)) != STRING)
+				Error (QUOTE_MSG, "Board");
+			ptr->dev_board = val.str;
+			break;
+		case CHIPSET:
+			if (xf86getSubToken (&(ptr->dev_comment)) != STRING)
+				Error (QUOTE_MSG, "Chipset");
+			ptr->dev_chipset = val.str;
+			break;
+		case CARD:
+			if (xf86getSubToken (&(ptr->dev_comment)) != STRING)
+				Error (QUOTE_MSG, "Card");
+			ptr->dev_card = val.str;
+			break;
+		case DRIVER:
+			if (xf86getSubToken (&(ptr->dev_comment)) != STRING)
+				Error (QUOTE_MSG, "Driver");
+			ptr->dev_driver = val.str;
+			break;
+		case RAMDAC:
+			if (xf86getSubToken (&(ptr->dev_comment)) != STRING)
+				Error (QUOTE_MSG, "Ramdac");
+			ptr->dev_ramdac = val.str;
+			break;
+		case DACSPEED:
+			for (i = 0; i < CONF_MAXDACSPEEDS; i++)
+				ptr->dev_dacSpeeds[i] = 0;
+			if (xf86getSubToken (&(ptr->dev_comment)) != NUMBER)
+			{
+				Error (DACSPEED_MSG, CONF_MAXDACSPEEDS);
+			}
+			else
+			{
+				ptr->dev_dacSpeeds[0] = (int) (val.realnum * 1000.0 + 0.5);
+				for (i = 1; i < CONF_MAXDACSPEEDS; i++)
+				{
+					if (xf86getSubToken (&(ptr->dev_comment)) == NUMBER)
+						ptr->dev_dacSpeeds[i] = (int)
+							(val.realnum * 1000.0 + 0.5);
+					else
+					{
+						xf86unGetToken (token);
+						break;
+					}
+				}
+			}
+			break;
+		case VIDEORAM:
+			if (xf86getSubToken (&(ptr->dev_comment)) != NUMBER)
+				Error (NUMBER_MSG, "VideoRam");
+			ptr->dev_videoram = val.num;
+			break;
+		case BIOSBASE:
+			if (xf86getSubToken (&(ptr->dev_comment)) != NUMBER)
+				Error (NUMBER_MSG, "BIOSBase");
+			ptr->dev_bios_base = val.num;
+			break;
+		case MEMBASE:
+			if (xf86getSubToken (&(ptr->dev_comment)) != NUMBER)
+				Error (NUMBER_MSG, "MemBase");
+			ptr->dev_mem_base = val.num;
+			break;
+		case IOBASE:
+			if (xf86getSubToken (&(ptr->dev_comment)) != NUMBER)
+				Error (NUMBER_MSG, "IOBase");
+			ptr->dev_io_base = val.num;
+			break;
+		case CLOCKCHIP:
+			if (xf86getSubToken (&(ptr->dev_comment)) != STRING)
+				Error (QUOTE_MSG, "ClockChip");
+			ptr->dev_clockchip = val.str;
+			break;
+		case CHIPID:
+			if (xf86getSubToken (&(ptr->dev_comment)) != NUMBER)
+				Error (NUMBER_MSG, "ChipID");
+			ptr->dev_chipid = val.num;
+			break;
+		case CHIPREV:
+			if (xf86getSubToken (&(ptr->dev_comment)) != NUMBER)
+				Error (NUMBER_MSG, "ChipRev");
+			ptr->dev_chiprev = val.num;
+			break;
+
+		case CLOCKS:
+			token = xf86getSubToken(&(ptr->dev_comment));
+			for( i = ptr->dev_clocks;
+				token == NUMBER && i < CONF_MAXCLOCKS; i++ ) {
+				ptr->dev_clock[i] = (int)(val.realnum * 1000.0 + 0.5);
+				token = xf86getSubToken(&(ptr->dev_comment));
+			}
+			ptr->dev_clocks = i;
+			xf86unGetToken (token);
+			break;
+		case TEXTCLOCKFRQ:
+			if ((token = xf86getSubToken(&(ptr->dev_comment))) != NUMBER)
+				Error (NUMBER_MSG, "TextClockFreq");
+			ptr->dev_textclockfreq = (int)(val.realnum * 1000.0 + 0.5);
+			break;
+		case OPTION:
+			ptr->dev_option_lst = xf86parseOption(ptr->dev_option_lst);
+			break;
+		case BUSID:
+			if (xf86getSubToken (&(ptr->dev_comment)) != STRING)
+				Error (QUOTE_MSG, "BusID");
+			ptr->dev_busid = val.str;
+			break;
+		case IRQ:
+			if (xf86getSubToken (&(ptr->dev_comment)) != NUMBER)
+				Error (QUOTE_MSG, "IRQ");
+			ptr->dev_irq = val.num;
+			break;
+		case SCREEN:
+			if (xf86getSubToken (&(ptr->dev_comment)) != NUMBER)
+				Error (NUMBER_MSG, "Screen");
+			ptr->dev_screen = val.num;
+			break;
+		case EOF_TOKEN:
+			Error (UNEXPECTED_EOF_MSG, NULL);
+			break;
+		default:
+			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
+			break;
+		}
+	}
+
+#if defined(SMI_FBCONFIG)
+	/*
+	 * Link Internal & External Representations of the EndSection line
+	 */
+	ptr->dev_end_line_er = line_er;
+	fbc_link_line_ER(line_er,
+			(void *)ptr,
+			(xf86_print_fn_t *)&xf86printDeviceSectionEndSection,
+			FBC_INDENT_0);
+
+#endif
+	if (!has_ident)
+		Error (NO_IDENT_MSG, NULL);
+
+#ifdef DEBUG
+	printf ("Device section parsed\n");
+#endif
+
+	return ptr;
+}
+
+#undef CLEANUP
+
+
+/*
+ * xf86printDeviceSectionSection()
+ *
+ *    Write the Device section Section line to the configuration file.
+ */
+void
+xf86printDeviceSectionSection(
+	FILE *cf, XF86ConfDevicePtr ptr, const char *const whitespace[])
+{
+	fprintf (cf, "Section \"Device\"\n");
+	if (ptr->dev_comment != NULL) {
+		fprintf(cf, "%s", ptr->dev_comment);
+	}
+}
+
+
+/*
+ * xf86printDeviceSectionIdentifier()
+ *
+ *    Write the Device section Identifier line to the configuration
+ *    file.
+ */
+void
+xf86printDeviceSectionIdentifier(
+	FILE *cf, XF86ConfDevicePtr ptr, const char *const whitespace[])
+{
+	xf86printFields(cf, whitespace, "Identifier", NULL);
+	fprintf(cf, "\"%s\"\n", ptr->dev_identifier);
+}
+
+
+/*
+ * xf86printDeviceSectionDriver()
+ *
+ *    Write the Device section Driver line to the configuration file.
+ */
+void
+xf86printDeviceSectionDriver(
+	FILE *cf, XF86ConfDevicePtr ptr, const char *const whitespace[])
+{
+	xf86printFields(cf, whitespace, "Driver", NULL);
+	fprintf (cf, "\"%s\"\n", ptr->dev_driver);
+}
+
+
+/*
+ * xf86printDeviceSectionVendorName()
+ *
+ *    Write the Device section VendorName line to the configuration
+ *    file.
+ */
+void
+xf86printDeviceSectionVendorName(
+	FILE *cf, XF86ConfDevicePtr ptr, const char *const whitespace[])
+{
+	xf86printFields(cf, whitespace, "VendorName", NULL);
+	fprintf (cf, "\"%s\"\n", ptr->dev_vendor);
+}
+
+
+/*
+ * xf86printDeviceSectionBoardName()
+ *
+ *    Write the Device section BoardName line to the configuration file.
+ */
+void
+xf86printDeviceSectionBoardName(
+	FILE *cf, XF86ConfDevicePtr ptr, const char *const whitespace[])
+{
+	xf86printFields(cf, whitespace, "BoardName", NULL);
+	fprintf (cf, "\"%s\"\n", ptr->dev_board);
+}
+
+
+/*
+ * xf86printDeviceSectionEndSection()
+ *
+ *    Write the Device section EndSection line to the configuration
+ *    file.
+ */
+void
+xf86printDeviceSectionEndSection(
+	FILE *cf, XF86ConfDevicePtr ptr, const char *const whitespace[])
+{
+	fprintf (cf, "EndSection\n");
+}
+
+
+/*
+ * xf86printDeviceSection()
+ *
+ *    Write a Device section to the configuration file.
+ */
+void
+xf86printDeviceSection (FILE * cf, XF86ConfDevicePtr ptr)
+{
+	int i;
+
+	while (ptr)
+	{
+		xf86printDeviceSectionSection(cf, ptr, xf86whitespace_0);
+		if (ptr->dev_identifier != NULL) {
+			xf86printDeviceSectionIdentifier(cf, ptr, xf86whitespace_1);
+		}
+		if (ptr->dev_driver != NULL) {
+			xf86printDeviceSectionDriver(cf, ptr, xf86whitespace_1);
+		}
+		if (ptr->dev_vendor != NULL) {
+			xf86printDeviceSectionVendorName(cf, ptr, xf86whitespace_1);
+		}
+		if (ptr->dev_board != NULL) {
+			xf86printDeviceSectionBoardName(cf, ptr, xf86whitespace_1);
+		}
+		if (ptr->dev_chipset)
+			fprintf (cf, "\tChipSet     \"%s\"\n", ptr->dev_chipset);
+		if (ptr->dev_card)
+			fprintf (cf, "\tCard        \"%s\"\n", ptr->dev_card);
+		if (ptr->dev_ramdac)
+			fprintf (cf, "\tRamDac      \"%s\"\n", ptr->dev_ramdac);
+		if (ptr->dev_dacSpeeds[0] > 0 ) {
+			fprintf (cf, "\tDacSpeed    ");
+			for (i = 0; i < CONF_MAXDACSPEEDS
+					&& ptr->dev_dacSpeeds[i] > 0; i++ )
+				fprintf (cf, "%g ", (double) (ptr->dev_dacSpeeds[i])/ 1000.0 );
+			fprintf (cf, "\n");
+		}
+		if (ptr->dev_videoram)
+			fprintf (cf, "\tVideoRam    %d\n", ptr->dev_videoram);
+		if (ptr->dev_bios_base)
+			fprintf (cf, "\tBiosBase    0x%lx\n", ptr->dev_bios_base);
+		if (ptr->dev_mem_base)
+			fprintf (cf, "\tMemBase     0x%lx\n", ptr->dev_mem_base);
+		if (ptr->dev_io_base)
+			fprintf (cf, "\tIOBase      0x%lx\n", ptr->dev_io_base);
+		if (ptr->dev_clockchip)
+			fprintf (cf, "\tClockChip   \"%s\"\n", ptr->dev_clockchip);
+		if (ptr->dev_chipid != -1)
+			fprintf (cf, "\tChipId      0x%x\n", ptr->dev_chipid);
+		if (ptr->dev_chiprev != -1)
+			fprintf (cf, "\tChipRev     0x%x\n", ptr->dev_chiprev);
+
+		xf86printOptionList(cf, ptr->dev_option_lst, xf86whitespace_1);
+		if (ptr->dev_clocks > 0 ) {
+			fprintf (cf, "\tClocks      ");
+			for (i = 0; i < ptr->dev_clocks; i++ )
+				fprintf (cf, "%.1f ", (double)ptr->dev_clock[i] / 1000.0 );
+			fprintf (cf, "\n");
+		}
+		if (ptr->dev_textclockfreq) {
+			fprintf (cf, "\tTextClockFreq %.1f\n",
+					 (double)ptr->dev_textclockfreq / 1000.0);
+		}
+		if (ptr->dev_busid)
+			fprintf (cf, "\tBusID       \"%s\"\n", ptr->dev_busid);
+		if (ptr->dev_screen > 0)
+			fprintf (cf, "\tScreen      %d\n", ptr->dev_screen);
+		if (ptr->dev_irq >= 0)
+			fprintf (cf, "\tIRQ         %d\n", ptr->dev_irq);
+		xf86printDeviceSectionEndSection(cf, ptr, xf86whitespace_0);
+		fprintf (cf, "\n");
+		ptr = ptr->list.next;
+	}
+}
+
+void
+xf86freeDeviceList (XF86ConfDevicePtr ptr)
+{
+	XF86ConfDevicePtr prev;
+
+	while (ptr)
+	{
+		TestFree (ptr->dev_identifier);
+		TestFree (ptr->dev_vendor);
+		TestFree (ptr->dev_board);
+		TestFree (ptr->dev_chipset);
+		TestFree (ptr->dev_card);
+		TestFree (ptr->dev_driver);
+		TestFree (ptr->dev_ramdac);
+		TestFree (ptr->dev_clockchip);
+		TestFree (ptr->dev_comment);
+		xf86optionListFree (ptr->dev_option_lst);
+
+		prev = ptr;
+		ptr = ptr->list.next;
+		xf86conffree (prev);
+	}
+}
+
+int
+xf86validateDevice (XF86ConfigPtr p)
+{
+	XF86ConfDevicePtr device = p->conf_device_lst;
+
+#if !defined(SMI_FBCONFIG)	/* Missing section will be constructed */
+	if (!device) {
+		xf86validationError ("At least one Device section is required.");
+		return (FALSE);
+	}
+
+#endif
+	while (device) {
+		if (!device->dev_driver) {
+			xf86validationError (UNDEFINED_DRIVER_MSG, device->dev_identifier);
+			return (FALSE);
+		}
+		device = device->list.next;
+	}
+	return (TRUE);
+}
+
+XF86ConfDevicePtr
+xf86findDevice (const char *ident, XF86ConfDevicePtr p)
+{
+	while (p)
+	{
+		if (xf86nameCompare (ident, p->dev_identifier) == 0)
+			return (p);
+
+		p = p->list.next;
+	}
+	return (NULL);
+}
+
+char *
+xf86configStrdup (const char *s)
+{
+	char *tmp;
+	if (!s) return NULL;
+	tmp = xf86confmalloc (sizeof (char) * (strlen (s) + 1));
+	if (tmp)
+		strcpy (tmp, s);
+	return (tmp);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Extensions.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2004 Red Hat Inc., Raleigh, North Carolina.
+ *
+ * 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 on 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
+ * NON-INFRINGEMENT.  IN NO EVENT SHALL RED HAT AND/OR THEIR 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:
+ *   Kevin E. Martin <[email protected]>
+ *
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "Configint.h"
+#include "fields.h"		/* Config file output line fields */
+
+extern LexRec val;
+
+static xf86ConfigSymTabRec ExtensionsTab[] =
+{
+    {ENDSECTION, "endsection"},
+    {OPTION,     "option"},
+    {-1,         ""},
+};
+
+#define CLEANUP xf86freeExtensions
+
+XF86ConfExtensionsPtr
+xf86parseExtensionsSection (void)
+{
+    int token;
+    parsePrologue (XF86ConfExtensionsPtr, XF86ConfExtensionsRec);
+
+    while ((token = xf86getToken (ExtensionsTab)) != ENDSECTION) {
+	switch (token) {
+	    case OPTION:
+		ptr->ext_option_lst = xf86parseOption(ptr->ext_option_lst);
+		break;
+	    case EOF_TOKEN:
+		Error (UNEXPECTED_EOF_MSG, NULL);
+		break;
+	    case COMMENT:
+		ptr->extensions_comment =
+		    xf86addComment(ptr->extensions_comment, val.str);
+		break;
+	    default:
+		Error (INVALID_KEYWORD_MSG, xf86tokenString ());
+		break;
+	}
+    }
+
+#ifdef DEBUG
+    ErrorF("Extensions section parsed\n");
+#endif
+
+    return ptr;
+}
+
+#undef CLEANUP
+
+void
+xf86printExtensionsSection (FILE * cf, XF86ConfExtensionsPtr ptr)
+{
+    XF86OptionPtr p;
+
+    if (ptr == NULL || ptr->ext_option_lst == NULL)
+	return;
+
+    p = ptr->ext_option_lst;
+    fprintf (cf, "Section \"Extensions\"\n");
+    if (ptr->extensions_comment)
+	fprintf (cf, "%s", ptr->extensions_comment);
+    xf86printOptionList(cf, p, xf86whitespace_1);
+    fprintf (cf, "EndSection\n\n");
+}
+
+void
+xf86freeExtensions (XF86ConfExtensionsPtr ptr)
+{
+    if (ptr == NULL)
+	return;
+
+    xf86optionListFree (ptr->ext_option_lst);
+    TestFree (ptr->extensions_comment);
+    xf86conffree (ptr);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Files.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,300 @@
+/* 
+ * 
+ * Copyright (c) 1997  Metro Link Incorporated
+ * 
+ * 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
+ * THE X CONSORTIUM 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.
+ * 
+ * Except as contained in this notice, the name of the Metro Link shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Metro Link.
+ * 
+ */
+/*
+ * Copyright (c) 1997-2003 by The XFree86 Project, 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
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+
+/* View/edit this file with tab stops set to 4 */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#if (0)
+#include <X11/Xos.h>
+#endif
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "Configint.h"
+
+extern LexRec val;
+
+static xf86ConfigSymTabRec FilesTab[] =
+{
+	{ENDSECTION, "endsection"},
+	{FONTPATH, "fontpath"},
+	{RGBPATH, "rgbpath"},
+	{MODULEPATH, "modulepath"},
+	{INPUTDEVICES, "inputdevices"},
+	{LOGFILEPATH, "logfile"},
+	{-1, ""},
+};
+
+static char *
+prependRoot (char *pathname)
+{
+#ifndef __EMX__
+	return pathname;
+#else
+	/* XXXX caveat: multiple path components in line */
+	return (char *) __XOS2RedirRoot (pathname);
+#endif
+}
+
+#define CLEANUP xf86freeFiles
+
+XF86ConfFilesPtr
+xf86parseFilesSection (void)
+{
+	int i, j;
+	int k, l;
+	char *str;
+	int token;
+	parsePrologue (XF86ConfFilesPtr, XF86ConfFilesRec)
+
+	while ((token = xf86getToken (FilesTab)) != ENDSECTION)
+	{
+		switch (token)
+		{
+		case COMMENT:
+			ptr->file_comment = xf86addComment(ptr->file_comment, val.str);
+			break;
+		case FONTPATH:
+			if (xf86getSubToken (&(ptr->file_comment)) != STRING)
+				Error (QUOTE_MSG, "FontPath");
+			j = FALSE;
+			str = prependRoot (val.str);
+			if (ptr->file_fontpath == NULL)
+			{
+				ptr->file_fontpath = xf86confmalloc (1);
+				ptr->file_fontpath[0] = '\0';
+				i = strlen (str) + 1;
+			}
+			else
+			{
+				i = strlen (ptr->file_fontpath) + strlen (str) + 1;
+				if (ptr->file_fontpath[strlen (ptr->file_fontpath) - 1] != ',')
+				{
+					i++;
+					j = TRUE;
+				}
+			}
+			ptr->file_fontpath =
+				xf86confrealloc (ptr->file_fontpath, i);
+			if (j)
+				strcat (ptr->file_fontpath, ",");
+
+			strcat (ptr->file_fontpath, str);
+			xf86conffree (val.str);
+			break;
+		case RGBPATH:
+			if (xf86getSubToken (&(ptr->file_comment)) != STRING)
+				Error (QUOTE_MSG, "RGBPath");
+			ptr->file_rgbpath = val.str;
+			break;
+		case MODULEPATH:
+			if (xf86getSubToken (&(ptr->file_comment)) != STRING)
+				Error (QUOTE_MSG, "ModulePath");
+			l = FALSE;
+			str = prependRoot (val.str);
+			if (ptr->file_modulepath == NULL)
+			{
+				ptr->file_modulepath = xf86confmalloc (1);
+				ptr->file_modulepath[0] = '\0';
+				k = strlen (str) + 1;
+			}
+			else
+			{
+				k = strlen (ptr->file_modulepath) + strlen (str) + 1;
+				if (ptr->file_modulepath[strlen (ptr->file_modulepath) - 1] != ',')
+				{
+					k++;
+					l = TRUE;
+				}
+			}
+			ptr->file_modulepath = xf86confrealloc (ptr->file_modulepath, k);
+			if (l)
+				strcat (ptr->file_modulepath, ",");
+
+			strcat (ptr->file_modulepath, str);
+			xf86conffree (val.str);
+			break;
+		case INPUTDEVICES:
+			if (xf86getSubToken (&(ptr->file_comment)) != STRING)
+				Error (QUOTE_MSG, "InputDevices");
+			l = FALSE;
+			str = prependRoot (val.str);
+			if (ptr->file_inputdevs == NULL)
+			{
+				ptr->file_inputdevs = xf86confmalloc (1);
+				ptr->file_inputdevs[0] = '\0';
+				k = strlen (str) + 1;
+			}
+			else
+			{
+				k = strlen (ptr->file_inputdevs) + strlen (str) + 1;
+				if (ptr->file_inputdevs[strlen (ptr->file_inputdevs) - 1] != ',')
+				{
+					k++;
+					l = TRUE;
+				}
+			}
+			ptr->file_inputdevs = xf86confrealloc (ptr->file_inputdevs, k);
+			if (l)
+				strcat (ptr->file_inputdevs, ",");
+
+			strcat (ptr->file_inputdevs, str);
+			xf86conffree (val.str);
+			break;
+		case LOGFILEPATH:
+			if (xf86getSubToken (&(ptr->file_comment)) != STRING)
+				Error (QUOTE_MSG, "LogFile");
+			ptr->file_logfile = val.str;
+			break;
+		case EOF_TOKEN:
+			Error (UNEXPECTED_EOF_MSG, NULL);
+			break;
+		default:
+			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
+			break;
+		}
+	}
+
+#ifdef DEBUG
+	printf ("Files section parsed\n");
+#endif
+
+	return ptr;
+}
+
+#undef CLEANUP
+
+void
+xf86printFileSection (FILE * cf, XF86ConfFilesPtr ptr)
+{
+	char *p, *s;
+
+	if (ptr == NULL)
+		return;
+
+	fprintf (cf, "Section \"Files\"\n");
+
+	if (ptr->file_comment)
+		fprintf (cf, "%s", ptr->file_comment);
+	if (ptr->file_logfile)
+		fprintf (cf, "\tLogFile      \"%s\"\n", ptr->file_logfile);
+	if (ptr->file_rgbpath)
+		fprintf (cf, "\tRgbPath      \"%s\"\n", ptr->file_rgbpath);
+	if (ptr->file_modulepath)
+	{
+		s = ptr->file_modulepath;
+		p = strchr (s, ',');
+		while (p)
+		{
+			*p = '\000';
+			fprintf (cf, "\tModulePath   \"%s\"\n", s);
+			*p = ',';
+			s = p;
+			s++;
+			p = strchr (s, ',');
+		}
+		fprintf (cf, "\tModulePath   \"%s\"\n", s);
+	}
+	if (ptr->file_inputdevs)
+	{
+		s = ptr->file_inputdevs;
+		p = strchr (s, ',');
+		while (p)
+		{
+			*p = '\000';
+			fprintf (cf, "\tInputDevices   \"%s\"\n", s);
+			*p = ',';
+			s = p;
+			s++;
+			p = strchr (s, ',');
+		}
+		fprintf (cf, "\tInputdevs   \"%s\"\n", s);
+	}
+	if (ptr->file_fontpath)
+	{
+		s = ptr->file_fontpath;
+		p = strchr (s, ',');
+		while (p)
+		{
+			*p = '\000';
+			fprintf (cf, "\tFontPath     \"%s\"\n", s);
+			*p = ',';
+			s = p;
+			s++;
+			p = strchr (s, ',');
+		}
+		fprintf (cf, "\tFontPath     \"%s\"\n", s);
+	}
+	fprintf (cf, "EndSection\n\n");
+}
+
+void
+xf86freeFiles (XF86ConfFilesPtr p)
+{
+	if (p == NULL)
+		return;
+
+	TestFree (p->file_logfile);
+	TestFree (p->file_rgbpath);
+	TestFree (p->file_modulepath);
+	TestFree (p->file_inputdevs);
+	TestFree (p->file_fontpath);
+	TestFree (p->file_comment);
+
+	xf86conffree (p);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Flags.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,760 @@
+/* 
+ * 
+ * Copyright (c) 1997  Metro Link Incorporated
+ * 
+ * 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
+ * THE X CONSORTIUM 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.
+ * 
+ * Except as contained in this notice, the name of the Metro Link shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Metro Link.
+ * 
+ */
+/*
+ * Copyright (c) 1997-2003 by The XFree86 Project, 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
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+
+/* View/edit this file with tab stops set to 4 */
+
+#include <math.h>
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "Configint.h"
+
+#include "fields.h"		/* Config file output line fields */
+#if defined(SMI_FBCONFIG)
+#include "fbc_edit_config.h"	/* Write an updated configuration file */
+#include "fbc_line_er.h"	/* External Representation of config lines */
+#endif
+
+
+extern LexRec val;
+
+static xf86ConfigSymTabRec ServerFlagsTab[] =
+{
+	{ENDSECTION, "endsection"},
+	{NOTRAPSIGNALS, "notrapsignals"},
+	{DONTZAP, "dontzap"},
+	{DONTZOOM, "dontzoom"},
+	{DISABLEVIDMODE, "disablevidmodeextension"},
+	{ALLOWNONLOCAL, "allownonlocalxvidtune"},
+	{DISABLEMODINDEV, "disablemodindev"},
+	{MODINDEVALLOWNONLOCAL, "allownonlocalmodindev"},
+	{ALLOWMOUSEOPENFAIL, "allowmouseopenfail"},
+	{OPTION, "option"},
+	{BLANKTIME, "blanktime"},
+	{STANDBYTIME, "standbytime"},
+	{SUSPENDTIME, "suspendtime"},
+	{OFFTIME, "offtime"},
+	{DEFAULTLAYOUT, "defaultserverlayout"},
+	{-1, ""},
+};
+
+#define CLEANUP xf86freeFlags
+
+XF86ConfFlagsPtr
+xf86parseFlagsSection (void)
+{
+	int token;
+	parsePrologue (XF86ConfFlagsPtr, XF86ConfFlagsRec)
+
+	while ((token = xf86getToken (ServerFlagsTab)) != ENDSECTION)
+	{
+		int hasvalue = FALSE;
+		int strvalue = FALSE;
+		int tokentype;
+		switch (token)
+		{
+		case COMMENT:
+			ptr->flg_comment = xf86addComment(ptr->flg_comment, val.str);
+			break;
+			/* 
+			 * these old keywords are turned into standard generic options.
+			 * we fall through here on purpose
+			 */
+		case DEFAULTLAYOUT:
+			strvalue = TRUE;
+		case BLANKTIME:
+		case STANDBYTIME:
+		case SUSPENDTIME:
+		case OFFTIME:
+			hasvalue = TRUE;
+		case NOTRAPSIGNALS:
+		case DONTZAP:
+		case DONTZOOM:
+		case DISABLEVIDMODE:
+		case ALLOWNONLOCAL:
+		case DISABLEMODINDEV:
+		case MODINDEVALLOWNONLOCAL:
+		case ALLOWMOUSEOPENFAIL:
+			{
+				int i = 0;
+				while (ServerFlagsTab[i].token != -1)
+				{
+					char *tmp;
+
+					if (ServerFlagsTab[i].token == token)
+					{
+						char *valstr = NULL;
+						/* can't use strdup because it calls malloc */
+						tmp = xf86configStrdup (ServerFlagsTab[i].name);
+						if (hasvalue)
+						{
+							tokentype = xf86getSubToken(&(ptr->flg_comment));
+							if (strvalue) {
+								if (tokentype != STRING)
+									Error (QUOTE_MSG, tmp);
+								valstr = val.str;
+							} else {
+								if (tokentype != NUMBER)
+									Error (NUMBER_MSG, tmp);
+								valstr = xf86confmalloc(16);
+								if (valstr)
+									sprintf(valstr, "%d", val.num);
+							}
+						}
+						ptr->flg_option_lst = xf86addNewOption
+							(ptr->flg_option_lst, tmp, valstr);
+					}
+					i++;
+				}
+			}
+			break;
+		case OPTION:
+			ptr->flg_option_lst = xf86parseOption(ptr->flg_option_lst);
+			break;
+
+		case EOF_TOKEN:
+			Error (UNEXPECTED_EOF_MSG, NULL);
+			break;
+		default:
+			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
+			break;
+		}
+	}
+
+#ifdef DEBUG
+	printf ("ServerFlags section parsed\n");
+#endif
+
+	return ptr;
+}
+
+#undef CLEANUP
+
+void
+xf86printServerFlagsSection (FILE * f, XF86ConfFlagsPtr flags)
+{
+	XF86OptionPtr p;
+
+	if ((!flags) || (!flags->flg_option_lst))
+		return;
+	p = flags->flg_option_lst;
+	fprintf (f, "Section \"ServerFlags\"\n");
+	if (flags->flg_comment)
+		fprintf (f, "%s", flags->flg_comment);
+	xf86printOptionList(f, p, xf86whitespace_1);
+	fprintf (f, "EndSection\n\n");
+}
+
+
+/*
+ * xf86addNewOptionOrValue()
+ *
+ *    Append a new Option record to the specified Option list if the
+ *    option name is not already present in the list.  If the option
+ *    name is already present, replace the value, etc. of the existing
+ *    option.  Return a pointer to the head of the list.
+ */
+#if !defined(SMI_FBCONFIG)
+static
+#endif
+XF86OptionPtr
+xf86addNewOptionOrValue(
+	XF86OptionPtr	head,		/* Ptr to head of option list */
+	char		*name,		/* Ptr to new option name string */
+	char		*val,		/* Ptr to new option value string */
+#if !defined(SMI_FBCONFIG)
+	int		used)
+#else
+	int		used,		/* Not used w/ SMI_FBCONFIG */
+	void		*end_line_er)	/* Ptr to End[Sub]Section, else NULL */
+#endif
+{
+	XF86OptionPtr	new;		/* Ptr to new or existing option */
+	XF86OptionPtr	old;		/* Ptr to existing option, if any */
+
+	/*
+	 * Disallow duplicate option names, discarding any but the last one
+	 *
+	 *    Note that xf86findOption() accepts NULL as the list head
+	 *    and returns NULL in that case.
+	 */
+	old = xf86findOption(head, name);
+	if (old == NULL) {
+		new = xf86confcalloc (1, sizeof (XF86OptionRec));
+ 		new->list.next = NULL;
+	} else {
+//??? Memory leak in some or all cases (e.g. when old->used==1) ???
+//???		xf86freeconfig(old->opt_name);
+//???		xf86freeconfig(old->opt_val);
+//??? Memory leak in some or all cases (e.g. when old->used==1) ???
+		new = old;
+	}
+
+ 	new->opt_name = name;
+ 	new->opt_val  = val;
+ 	new->opt_used = used;
+	
+  	if (old == NULL) {
+#if defined(SMI_FBCONFIG)
+		/*
+		 * Insert and link the External Representation of this option
+		 *
+		 *    The External Representation of this new Option
+		 *    line will be inserted just before the EndSection
+		 *    or EndSubSection line (assuming our caller has
+		 *    provided a pointer to the ER for the end line).
+		 */
+		if (end_line_er != NULL) {
+			fbc_insert_line_ER(end_line_er, (void *)new,
+					(xf86_print_fn_t *)&xf86printOption,
+					FBC_INDENT_ENTRY);
+		}
+
+#endif
+		/*
+		 * Add the new option and return the (new) list head
+		 */
+		return ((XF86OptionPtr) xf86addListItem((glp)head, (glp)new));
+	}
+
+#if defined(SMI_FBCONFIG)
+	/*
+	 * Mark the External Representation of this option as modified
+	 *
+	 *    If our caller hasn't provided a pointer (end_line_er) to
+	 *    the External Representation of an EndSection or
+	 *    EndSubSection line then it's likely that our caller isn't
+	 *    on an SMI_FBCONFIG code path.  
+	 */
+	if (end_line_er != NULL) {
+		fbc_modify_line_ER(new->opt_line_er);
+	}
+
+#endif
+	/*
+	 * Return the unchanged list head, having modified an existing option
+	 */
+	return (head);
+}
+
+
+/*
+ * xf86addNewOption()
+ *
+ *    Append a new Option record to the specified Option list if the
+ *    option name is not already present in the list.  If the option
+ *    name is already present, replace the value, etc. of the existing
+ *    option.  Return a pointer to the head of the list.
+ */
+XF86OptionPtr
+xf86addNewOption (XF86OptionPtr head, char *name, char *val)
+{
+#if !defined(SMI_FBCONFIG)
+	return (xf86addNewOptionOrValue(head, name, val, 0));
+#else
+	return (xf86addNewOptionOrValue(head, name, val, 0, NULL));
+#endif
+}
+
+
+void
+xf86freeFlags (XF86ConfFlagsPtr flags)
+{
+	if (flags == NULL)
+		return;
+	xf86optionListFree (flags->flg_option_lst);
+	TestFree(flags->flg_comment);
+	xf86conffree (flags);
+}
+
+XF86OptionPtr
+xf86optionListDup (XF86OptionPtr opt)
+{
+	XF86OptionPtr newopt = NULL;
+
+	while (opt)
+	{
+		newopt = xf86addNewOption(newopt, xf86configStrdup(opt->opt_name), 
+					  xf86configStrdup(opt->opt_val));
+		newopt->opt_used = opt->opt_used;
+		if (opt->opt_comment)
+			newopt->opt_comment = xf86configStrdup(opt->opt_comment);
+		opt = opt->list.next;
+	}
+	return newopt;
+}
+
+void
+xf86optionListFree (XF86OptionPtr opt)
+{
+	XF86OptionPtr prev;
+
+	while (opt)
+	{
+		TestFree (opt->opt_name);
+		TestFree (opt->opt_val);
+		TestFree (opt->opt_comment);
+		prev = opt;
+		opt = opt->list.next;
+		xf86conffree (prev);
+	}
+}
+
+char *
+xf86optionName(XF86OptionPtr opt)
+{
+	if (opt)
+		return opt->opt_name;
+	return 0;
+}
+
+char *
+xf86optionValue(XF86OptionPtr opt)
+{
+	if (opt)
+		return opt->opt_val;
+	return 0;
+}
+
+XF86OptionPtr
+xf86newOption(char *name, char *value)
+{
+	XF86OptionPtr opt;
+
+	opt = xf86confcalloc(1, sizeof (XF86OptionRec));
+	if (!opt)
+		return NULL;
+
+	opt->opt_used = 0;
+	opt->list.next = 0;
+	opt->opt_name = name;
+	opt->opt_val = value;
+
+	return opt;
+}
+
+XF86OptionPtr
+xf86nextOption(XF86OptionPtr list)
+{
+	if (!list)
+		return NULL;
+	return list->list.next;
+}
+
+/*
+ * This function searches the given option list for the named option and
+ * returns a pointer to the option rec if found. If not found, it returns
+ * NULL.
+ */
+
+XF86OptionPtr
+xf86findOption (XF86OptionPtr list, const char *name)
+{
+	/*
+	 * Known Boolean option names, which accept a "No" prefix
+	 *
+	 *    This table is arranged in xorg.conf(4) man page order,
+	 *    merely for ease of its creation and potential maintenance.
+	 *
+	 *    What should the opposites of the following Boolean option
+	 *    names be?
+	 *        "NoTrapSignals"  -  "NoNoTrapSignals" or "TrapSignals"
+	 *        "NoPM"           -  "NoNoPM"          or "PM"
+	 *        "NoInt10"        -  "NoNoInt10"       or "Int10"
+	 */
+	static const char * const bool_option_names[] =
+	{
+		/*
+		 * ServerFlags Section
+		 */
+		"NoTrapSignals",	/* ??? Not a negated option name */
+		"DontVTSwitch",
+		"DontZap",
+		"DontZoom",
+		"DisableVidModeExtension",
+		"AllowNonLocalXvidtune",
+		"DisableModInDev",
+		"AllowNonLocalModInDev",
+		"AllowMouseOpenFail",
+		"VTSysReq",
+		"XkbDisable",
+		"PC98",
+		"NoPM",			/* ??? Not a negated option name */
+		"Xinerama",
+		"AllowDeactivateGrabs",
+		"AllowClosedownGrabs",
+		/*
+		 * InputDevice section
+		 */
+		"AIGLX",
+		"IgnoreABI",
+		/*
+		 * Module section
+		 */
+		"AlwaysCore",
+		"SendCoreEvents",
+		"SendDragEvents",
+		/*
+		 * Monitor section
+		 */
+		"DPMS",
+		"SyncOnGreen",
+		"Enable",
+		"Ignore",
+		/*
+		 * Screen section
+		 */
+		"InitPrimary",
+		"NoInt10",		/* ??? Not a negated option name */
+		"SingleCard",
+#if defined(SMI_FBCONFIG)
+		FBC_KEYWD_DefLinear,	/* Display subsection */
+		FBC_KEYWD_DefOverlay,	/* Display subsection */
+		FBC_KEYWD_DefTransparent, /* Display subsection */
+		FBC_KEYWD_DoubleHigh,	/* ??? Is this really a Boolean ??? */
+		FBC_KEYWD_DoubleWide,	/* ??? Is this really a Boolean ??? */
+#endif
+		NULL			/* End-of-table marker */
+	};
+
+	for ( ; list != NULL; list = list->list.next)
+	{
+		if (xf86optionNameCompare (
+				bool_option_names, list->opt_name, name) == 0)
+		{
+			return (list);
+		}
+	}
+	return (NULL);
+}
+
+/*
+ * This function searches the given option list for the named option. If
+ * found and the option has a parameter, a pointer to the parameter is
+ * returned.  If the option does not have a parameter, an empty string
+ * is returned.  If the option is not found, a NULL is returned.
+ */
+
+char *
+xf86findOptionValue (XF86OptionPtr list, const char *name)
+{
+	XF86OptionPtr p = xf86findOption (list, name);
+
+	if (p)
+	{
+		if (p->opt_val)
+			return (p->opt_val);
+		else
+			return "";
+	}
+	return (NULL);
+}
+
+/*
+ * xf86optionListCreate()
+ *
+ *    Create and return a list of options from an array of option &
+ *    value string pairs.  The size of the array is specified by a
+ *    non-negative "count" value or else by a NULL as the last element
+ *    of the array.  The purpose of "used," which appears to be Boolean,
+ *    has been documented only by its name.
+ */
+XF86OptionPtr
+xf86optionListCreate( const char **options, int count, int used )
+{
+	XF86OptionPtr p = NULL;
+	char *t1, *t2;
+	int i;
+
+	if (count == -1)
+	{
+		for (count = 0; options[count]; count++)
+			;
+	}
+	if( (count % 2) != 0 )
+	{
+		fprintf( stderr, "xf86optionListCreate: count must be an even number.\n" );
+		return (NULL);
+	}
+	for (i = 0; i < count; i += 2)
+	{
+		/* can't use strdup because it calls malloc */
+		t1 = xf86confmalloc (sizeof (char) *
+				(strlen (options[i]) + 1));
+		strcpy (t1, options[i]);
+		t2 = xf86confmalloc (sizeof (char) *
+				(strlen (options[i + 1]) + 1));
+		strcpy (t2, options[i + 1]);
+#if !defined(SMI_FBCONFIG)
+		p = xf86addNewOptionOrValue(p, t1, t2, used);
+#else
+		p = xf86addNewOptionOrValue(p, t1, t2, used, NULL);
+#endif
+	}
+
+	return (p);
+}
+
+/* the 2 given lists are merged. If an option with the same name is present in
+ * both, the option from the user list - specified in the second argument -
+ * is used. The end result is a single valid list of options. Duplicates
+ * are freed, and the original lists are no longer guaranteed to be complete.
+ */
+XF86OptionPtr
+xf86optionListMerge (XF86OptionPtr head, XF86OptionPtr tail)
+{
+	XF86OptionPtr a, b, ap = NULL, bp = NULL;
+
+	a = tail;
+	b = head;
+	while (tail && b) {
+		if (xf86nameCompare (a->opt_name, b->opt_name) == 0) {
+			if (b == head)
+				head = a;
+			else
+				bp->list.next = a;
+			if (a == tail)
+				tail = a->list.next;
+			else
+				ap->list.next = a->list.next;
+			a->list.next = b->list.next;
+			b->list.next = NULL;
+			xf86optionListFree (b);
+			b = a->list.next;
+			bp = a;
+			a = tail;
+			ap = NULL;
+		} else {
+			ap = a;
+			if (!(a = a->list.next)) {
+				a = tail;
+				bp = b;
+				b = b->list.next;
+				ap = NULL;
+			}
+		}
+	}
+
+	if (head) {
+		for (a = head; a->list.next; a = a->list.next)
+			;
+		a->list.next = tail;
+	} else 
+		head = tail;
+
+	return (head);
+}
+
+char *
+xf86uLongToString(unsigned long i)
+{
+	char *s;
+	int l;
+
+	l = (int)(ceil(log10((double)i) + 2.5));
+	s = xf86confmalloc(l);
+	if (!s)
+		return NULL;
+	sprintf(s, "%lu", i);
+	return s;
+}
+
+void
+xf86debugListOptions(XF86OptionPtr Options)
+{
+	while (Options) {
+		ErrorF("Option: %s Value: %s\n",Options->opt_name,Options->opt_val);
+		Options = Options->list.next;
+	}
+}
+
+
+/*
+ * xf86parseOption()
+ *
+ *    Parse the current Option line.  Complain about bad Option lines.
+ *    Discard duplicate option names.  Otherwise, append the new option
+ *    to the Option list specified by "head."
+ */
+XF86OptionPtr
+xf86parseOption(XF86OptionPtr head)
+{
+	XF86OptionPtr option, old;
+	char *name, *comment = NULL;
+	int token;
+#if defined(SMI_FBCONFIG)
+	void *line_er;		/* Ptr to External Rep of Option line */
+
+	/*
+	 * Get a pointer to the External Representation of this Option line
+	 */
+	line_er = fbc_get_current_line_ER();
+#endif
+
+	/*
+	 * Get the option name token
+	 */
+	if ((token = xf86getSubToken(&comment)) != STRING) {
+		xf86parseError(BAD_OPTION_MSG, NULL);
+		if (comment)
+			xf86conffree(comment);
+		return (head);
+	}
+	name = val.str;
+
+	/*
+	 * Get the option value token, if any, and comment string, if any
+	 */
+	if ((token = xf86getSubToken(&comment)) == STRING) {
+		option = xf86newOption(name, val.str);
+		option->opt_comment = comment;
+		if ((token = xf86getToken(NULL)) == COMMENT)
+			option->opt_comment = xf86addComment(option->opt_comment, val.str);
+		else
+			xf86unGetToken(token);
+	}
+	else {
+		option = xf86newOption(name, NULL);
+		option->opt_comment = comment;
+		if (token == COMMENT)
+			option->opt_comment = xf86addComment(option->opt_comment, val.str);
+		else
+			xf86unGetToken(token);
+	}
+
+	/*
+	 * Disallow duplicate option names, discarding any but the first one
+	 *
+	 *    Note that xf86findOption() accepts NULL as the list head
+	 *    and returns NULL in that case.
+	 */
+	old = xf86findOption(head, name);
+	if (old != NULL) {
+		xf86conffree(option->opt_name);
+		TestFree(option->opt_val);
+		TestFree(option->opt_comment);
+		xf86conffree(option);
+#if defined(SMI_FBCONFIG)
+		fbc_delete_line_ER(line_er);  /* Delete config line from ER */
+#endif
+		return (head);
+	}
+
+#if defined(SMI_FBCONFIG)
+	/*
+	 * Link the Internal and External Representations of this Option line
+	 */
+	option->opt_line_er = line_er;
+	fbc_link_line_ER(line_er,
+			(void *)option,
+			(xf86_print_fn_t*)&xf86printOption,
+			FBC_INDENT_ENTRY);
+
+#endif
+	return ((XF86OptionPtr)xf86addListItem((glp)head, (glp)option));
+}
+
+
+/*
+ * xf86printOption()
+ *
+ *    Write an Option line to the output configuration file.
+ */
+void
+xf86printOption(
+	FILE *fp, XF86OptionPtr option, const char * const whitespace[])
+{
+	char		*comment;	/* Comment or end-of-line text */
+
+	/*
+	 * Comment or end-of-line text
+	 */
+	comment = "\n";
+	if (option->opt_comment != NULL) {
+		comment = option->opt_comment;
+	}
+
+	/*
+	 * Write the Option line, which may include an Option value
+	 */
+	xf86printFields(fp, whitespace, "Option", NULL);
+	if (option->opt_val != NULL) {
+		fprintf(fp, "\"%s\" \"%s\"%s",
+			option->opt_name, option->opt_val, comment);
+	} else {
+		fprintf(fp, "\"%s\"%s", option->opt_name, comment);
+	}
+}
+
+
+/*
+ * xf86printOptionList()
+ *
+ *    Write all of the Option lines of a (sub)section to the output
+ *    configuration file.
+ */
+void
+xf86printOptionList(
+	FILE *fp, XF86OptionPtr list, const char * const whitespace[])
+{
+
+	for ( ; list != NULL; list = list->list.next) {
+		xf86printOption(fp, list, whitespace);
+	}
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Input.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,215 @@
+/* 
+ * 
+ * Copyright (c) 1997  Metro Link Incorporated
+ * 
+ * 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
+ * THE X CONSORTIUM 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.
+ * 
+ * Except as contained in this notice, the name of the Metro Link shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Metro Link.
+ * 
+ */
+/*
+ * Copyright (c) 1997-2003 by The XFree86 Project, 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
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+
+/* View/edit this file with tab stops set to 4 */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "Configint.h"
+#include "fields.h"		/* Config file output line fields */
+
+extern LexRec val;
+
+static
+xf86ConfigSymTabRec InputTab[] =
+{
+	{ENDSECTION, "endsection"},
+	{IDENTIFIER, "identifier"},
+	{OPTION, "option"},
+	{DRIVER, "driver"},
+	{-1, ""},
+};
+
+#define CLEANUP xf86freeInputList
+
+XF86ConfInputPtr
+xf86parseInputSection (void)
+{
+	int has_ident = FALSE;
+	int token;
+	parsePrologue (XF86ConfInputPtr, XF86ConfInputRec)
+
+	while ((token = xf86getToken (InputTab)) != ENDSECTION)
+	{
+		switch (token)
+		{
+		case COMMENT:
+			ptr->inp_comment = xf86addComment(ptr->inp_comment, val.str);
+			break;
+		case IDENTIFIER:
+			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
+				Error (QUOTE_MSG, "Identifier");
+			if (has_ident == TRUE)
+				Error (MULTIPLE_MSG, "Identifier");
+			ptr->inp_identifier = val.str;
+			has_ident = TRUE;
+			break;
+		case DRIVER:
+			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
+				Error (QUOTE_MSG, "Driver");
+			ptr->inp_driver = val.str;
+			break;
+		case OPTION:
+			ptr->inp_option_lst = xf86parseOption(ptr->inp_option_lst);
+			break;
+		case EOF_TOKEN:
+			Error (UNEXPECTED_EOF_MSG, NULL);
+			break;
+		default:
+			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
+			break;
+		}
+	}
+
+	if (!has_ident)
+		Error (NO_IDENT_MSG, NULL);
+
+#ifdef DEBUG
+	printf ("InputDevice section parsed\n");
+#endif
+
+	return ptr;
+}
+
+#undef CLEANUP
+
+void
+xf86printInputSection (FILE * cf, XF86ConfInputPtr ptr)
+{
+	while (ptr)
+	{
+		fprintf (cf, "Section \"InputDevice\"\n");
+		if (ptr->inp_comment)
+			fprintf (cf, "%s", ptr->inp_comment);
+		if (ptr->inp_identifier)
+			fprintf (cf, "\tIdentifier  \"%s\"\n", ptr->inp_identifier);
+		if (ptr->inp_driver)
+			fprintf (cf, "\tDriver      \"%s\"\n", ptr->inp_driver);
+		xf86printOptionList(cf, ptr->inp_option_lst, xf86whitespace_1);
+		fprintf (cf, "EndSection\n\n");
+		ptr = ptr->list.next;
+	}
+}
+
+void
+xf86freeInputList (XF86ConfInputPtr ptr)
+{
+	XF86ConfInputPtr prev;
+
+	while (ptr)
+	{
+		TestFree (ptr->inp_identifier);
+		TestFree (ptr->inp_driver);
+		TestFree (ptr->inp_comment);
+		xf86optionListFree (ptr->inp_option_lst);
+
+		prev = ptr;
+		ptr = ptr->list.next;
+		xf86conffree (prev);
+	}
+}
+
+int
+xf86validateInput (XF86ConfigPtr p)
+{
+	XF86ConfInputPtr input = p->conf_input_lst;
+
+#if 0 /* Enable this later */
+	if (!input) {
+		xf86validationError ("At least one InputDevice section is required.");
+		return (FALSE);
+	}
+#endif
+
+	while (input) {
+		if (!input->inp_driver) {
+			xf86validationError (UNDEFINED_INPUTDRIVER_MSG, input->inp_identifier);
+			return (FALSE);
+		}
+		input = input->list.next;
+	}
+	return (TRUE);
+}
+
+XF86ConfInputPtr
+xf86findInput (const char *ident, XF86ConfInputPtr p)
+{
+	while (p)
+	{
+		if (xf86nameCompare (ident, p->inp_identifier) == 0)
+			return (p);
+
+		p = p->list.next;
+	}
+	return (NULL);
+}
+
+XF86ConfInputPtr
+xf86findInputByDriver (const char *driver, XF86ConfInputPtr p)
+{
+	while (p)
+	{
+		if (xf86nameCompare (driver, p->inp_driver) == 0)
+			return (p);
+
+		p = p->list.next;
+	}
+	return (NULL);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Keyboard.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,308 @@
+/* 
+ * 
+ * Copyright (c) 1997  Metro Link Incorporated
+ * 
+ * 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
+ * THE X CONSORTIUM 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.
+ * 
+ * Except as contained in this notice, the name of the Metro Link shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Metro Link.
+ * 
+ */
+/*
+ * Copyright (c) 1997-2003 by The XFree86 Project, 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
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+
+/* View/edit this file with tab stops set to 4 */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "Configint.h"
+#include "ctype.h"
+
+extern LexRec val;
+
+static xf86ConfigSymTabRec KeyboardTab[] =
+{
+	{ENDSECTION, "endsection"},
+	{KPROTOCOL, "protocol"},
+	{AUTOREPEAT, "autorepeat"},
+	{XLEDS, "xleds"},
+	{PANIX106, "panix106"},
+	{XKBKEYMAP, "xkbkeymap"},
+	{XKBCOMPAT, "xkbcompat"},
+	{XKBTYPES, "xkbtypes"},
+	{XKBKEYCODES, "xkbkeycodes"},
+	{XKBGEOMETRY, "xkbgeometry"},
+	{XKBSYMBOLS, "xkbsymbols"},
+	{XKBDISABLE, "xkbdisable"},
+	{XKBRULES, "xkbrules"},
+	{XKBMODEL, "xkbmodel"},
+	{XKBLAYOUT, "xkblayout"},
+	{XKBVARIANT, "xkbvariant"},
+	{XKBOPTIONS, "xkboptions"},
+	/* The next two have become ServerFlags options */
+	{VTINIT, "vtinit"},
+	{VTSYSREQ, "vtsysreq"},
+	/* Obsolete keywords */
+	{SERVERNUM, "servernumlock"},
+	{LEFTALT, "leftalt"},
+	{RIGHTALT, "rightalt"},
+	{RIGHTALT, "altgr"},
+	{SCROLLLOCK_TOK, "scrolllock"},
+	{RIGHTCTL, "rightctl"},
+	{-1, ""},
+};
+
+/* Obsolete */
+static xf86ConfigSymTabRec KeyMapTab[] =
+{
+	{CONF_KM_META, "meta"},
+	{CONF_KM_COMPOSE, "compose"},
+	{CONF_KM_MODESHIFT, "modeshift"},
+	{CONF_KM_MODELOCK, "modelock"},
+	{CONF_KM_SCROLLLOCK, "scrolllock"},
+	{CONF_KM_CONTROL, "control"},
+	{-1, ""},
+};
+
+#define CLEANUP xf86freeInputList
+
+XF86ConfInputPtr
+xf86parseKeyboardSection (void)
+{
+	char *s, *s1, *s2;
+	int l;
+	int token, ntoken;
+	parsePrologue (XF86ConfInputPtr, XF86ConfInputRec)
+
+	while ((token = xf86getToken (KeyboardTab)) != ENDSECTION)
+	{
+		switch (token)
+		{
+		case COMMENT:
+			ptr->inp_comment = xf86addComment(ptr->inp_comment, val.str);
+			break;
+		case KPROTOCOL:
+			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
+				Error (QUOTE_MSG, "Protocol");
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+							       xf86configStrdup("Protocol"),
+							       val.str);
+			break;
+		case AUTOREPEAT:
+			if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER)
+				Error (AUTOREPEAT_MSG, NULL);
+			s1 = xf86uLongToString(val.num);
+			if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER) {
+				xf86conffree(s1);
+				Error (AUTOREPEAT_MSG, NULL);
+			}
+			s2 = xf86uLongToString(val.num);
+			l = strlen(s1) + 1 + strlen(s2) + 1;
+			s = xf86confmalloc(l);
+			sprintf(s, "%s %s", s1, s2);
+			xf86conffree(s1);
+			xf86conffree(s2);
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+							       xf86configStrdup("AutoRepeat"), s);
+			break;
+		case XLEDS:
+			if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER)
+				Error (XLEDS_MSG, NULL);
+			s = xf86uLongToString(val.num);
+			l = strlen(s) + 1;
+			while ((token = xf86getSubToken (&(ptr->inp_comment))) == NUMBER)
+			{
+				s1 = xf86uLongToString(val.num);
+				l += (1 + strlen(s1));
+				s = xf86confrealloc(s, l);
+				strcat(s, " ");
+				strcat(s, s1);
+				xf86conffree(s1);
+			}
+			xf86unGetToken (token);
+			xf86conffree(s);
+			break;
+		case SERVERNUM:
+			xf86parseWarning(OBSOLETE_MSG, xf86tokenString());
+			break;
+		case LEFTALT:
+		case RIGHTALT:
+		case SCROLLLOCK_TOK:
+		case RIGHTCTL:
+			xf86parseWarning(OBSOLETE_MSG, xf86tokenString());
+				break;
+			ntoken = xf86getToken (KeyMapTab);
+			switch (ntoken)
+			{
+			case EOF_TOKEN:
+				xf86parseError (UNEXPECTED_EOF_MSG);
+				CLEANUP (ptr);
+				return (NULL);
+				break;
+
+			default:
+				Error (INVALID_KEYWORD_MSG, xf86tokenString ());
+				break;
+			}
+			break;
+		case VTINIT:
+			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
+				Error (QUOTE_MSG, "VTInit");
+			xf86parseWarning(MOVED_TO_FLAGS_MSG, "VTInit");
+			break;
+		case VTSYSREQ:
+			xf86parseWarning(MOVED_TO_FLAGS_MSG, "VTSysReq");
+			break;
+		case XKBDISABLE:
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("XkbDisable"),
+												NULL);
+			break;
+		case XKBKEYMAP:
+			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
+				Error (QUOTE_MSG, "XKBKeymap");
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("XkbKeymap"),
+												val.str);
+			break;
+		case XKBCOMPAT:
+			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
+				Error (QUOTE_MSG, "XKBCompat");
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("XkbCompat"),
+												val.str);
+			break;
+		case XKBTYPES:
+			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
+				Error (QUOTE_MSG, "XKBTypes");
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("XkbTypes"),
+												val.str);
+			break;
+		case XKBKEYCODES:
+			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
+				Error (QUOTE_MSG, "XKBKeycodes");
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("XkbKeycodes"),
+												val.str);
+			break;
+		case XKBGEOMETRY:
+			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
+				Error (QUOTE_MSG, "XKBGeometry");
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("XkbGeometry"),
+												val.str);
+			break;
+		case XKBSYMBOLS:
+			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
+				Error (QUOTE_MSG, "XKBSymbols");
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("XkbSymbols"),
+												val.str);
+			break;
+		case XKBRULES:
+			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
+				Error (QUOTE_MSG, "XKBRules");
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("XkbRules"),
+												val.str);
+			break;
+		case XKBMODEL:
+			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
+				Error (QUOTE_MSG, "XKBModel");
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("XkbModel"),
+												val.str);
+			break;
+		case XKBLAYOUT:
+			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
+				Error (QUOTE_MSG, "XKBLayout");
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("XkbLayout"),
+												val.str);
+			break;
+		case XKBVARIANT:
+			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
+				Error (QUOTE_MSG, "XKBVariant");
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("XkbVariant"),
+												val.str);
+			break;
+		case XKBOPTIONS:
+			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
+				Error (QUOTE_MSG, "XKBOptions");
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("XkbOptions"),
+												val.str);
+			break;
+		case PANIX106:
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("Panix106"), NULL);
+			break;
+		case EOF_TOKEN:
+			Error (UNEXPECTED_EOF_MSG, NULL);
+			break;
+		default:
+			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
+			break;
+		}
+	}
+
+	ptr->inp_identifier = xf86configStrdup(CONF_IMPLICIT_KEYBOARD);
+	ptr->inp_driver = xf86configStrdup("keyboard");
+	ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+										xf86configStrdup("CoreKeyboard"), NULL);
+
+#ifdef DEBUG
+	printf ("Keyboard section parsed\n");
+#endif
+
+	return ptr;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Layout.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,536 @@
+/* 
+ * 
+ * Copyright (c) 1997  Metro Link Incorporated
+ * 
+ * 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
+ * THE X CONSORTIUM 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.
+ * 
+ * Except as contained in this notice, the name of the Metro Link shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Metro Link.
+ * 
+ */
+/*
+ * Copyright (c) 1997-2003 by The XFree86 Project, 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
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+
+/* View/edit this file with tab stops set to 4 */
+
+#include <string.h>
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "Configint.h"
+#include "fields.h"		/* Config file output line fields */
+
+extern LexRec val;
+
+static xf86ConfigSymTabRec LayoutTab[] =
+{
+	{ENDSECTION, "endsection"},
+	{SCREEN, "screen"},
+	{IDENTIFIER, "identifier"},
+	{INACTIVE, "inactive"},
+	{INPUTDEVICE, "inputdevice"},
+	{OPTION, "option"},
+	{-1, ""},
+};
+
+static xf86ConfigSymTabRec AdjTab[] =
+{
+	{RIGHTOF, "rightof"},
+	{LEFTOF, "leftof"},
+	{ABOVE, "above"},
+	{BELOW, "below"},
+	{RELATIVE, "relative"},
+	{ABSOLUTE, "absolute"},
+	{-1, ""},
+};
+
+#define CLEANUP xf86freeLayoutList
+
+XF86ConfLayoutPtr
+xf86parseLayoutSection (void)
+{
+	int has_ident = FALSE;
+	int token;
+	parsePrologue (XF86ConfLayoutPtr, XF86ConfLayoutRec)
+
+	while ((token = xf86getToken (LayoutTab)) != ENDSECTION)
+	{
+		switch (token)
+		{
+		case COMMENT:
+			ptr->lay_comment = xf86addComment(ptr->lay_comment, val.str);
+			break;
+		case IDENTIFIER:
+			if (xf86getSubToken (&(ptr->lay_comment)) != STRING)
+				Error (QUOTE_MSG, "Identifier");
+			if (has_ident == TRUE)
+				Error (MULTIPLE_MSG, "Identifier");
+			ptr->lay_identifier = val.str;
+			has_ident = TRUE;
+			break;
+		case INACTIVE:
+			{
+				XF86ConfInactivePtr iptr;
+
+				iptr = xf86confcalloc (1, sizeof (XF86ConfInactiveRec));
+				iptr->list.next = NULL;
+				if (xf86getSubToken (&(ptr->lay_comment)) != STRING) {
+					xf86conffree (iptr);
+					Error (INACTIVE_MSG, NULL);
+				}
+				iptr->inactive_device_str = val.str;
+				ptr->lay_inactive_lst = (XF86ConfInactivePtr)
+					xf86addListItem ((glp) ptr->lay_inactive_lst, (glp) iptr);
+			}
+			break;
+		case SCREEN:
+			{
+				XF86ConfAdjacencyPtr aptr;
+				int absKeyword = 0;
+
+				aptr = xf86confcalloc (1, sizeof (XF86ConfAdjacencyRec));
+				aptr->list.next = NULL;
+				aptr->adj_scrnum = -1;
+				aptr->adj_where = CONF_ADJ_OBSOLETE;
+				aptr->adj_x = 0;
+				aptr->adj_y = 0;
+				aptr->adj_refscreen = NULL;
+				if ((token = xf86getSubToken (&(ptr->lay_comment))) == NUMBER)
+					aptr->adj_scrnum = val.num;
+				else
+					xf86unGetToken (token);
+				token = xf86getSubToken(&(ptr->lay_comment));
+				if (token != STRING) {
+					xf86conffree(aptr);
+					Error (SCREEN_MSG, NULL);
+				}
+				aptr->adj_screen_str = val.str;
+
+				token = xf86getSubTokenWithTab(&(ptr->lay_comment), AdjTab);
+				switch (token)
+				{
+				case RIGHTOF:
+					aptr->adj_where = CONF_ADJ_RIGHTOF;
+					break;
+				case LEFTOF:
+					aptr->adj_where = CONF_ADJ_LEFTOF;
+					break;
+				case ABOVE:
+					aptr->adj_where = CONF_ADJ_ABOVE;
+					break;
+				case BELOW:
+					aptr->adj_where = CONF_ADJ_BELOW;
+					break;
+				case RELATIVE:
+					aptr->adj_where = CONF_ADJ_RELATIVE;
+					break;
+				case ABSOLUTE:
+					aptr->adj_where = CONF_ADJ_ABSOLUTE;
+					absKeyword = 1;
+					break;
+				case EOF_TOKEN:
+					xf86conffree(aptr);
+					Error (UNEXPECTED_EOF_MSG, NULL);
+					break;
+				default:
+					xf86unGetToken (token);
+					token = xf86getSubToken(&(ptr->lay_comment));
+					if (token == STRING)
+						aptr->adj_where = CONF_ADJ_OBSOLETE;
+					else
+						aptr->adj_where = CONF_ADJ_ABSOLUTE;
+				}
+				switch (aptr->adj_where)
+				{
+				case CONF_ADJ_ABSOLUTE:
+					if (absKeyword) 
+						token = xf86getSubToken(&(ptr->lay_comment));
+					if (token == NUMBER)
+					{
+						aptr->adj_x = val.num;
+						token = xf86getSubToken(&(ptr->lay_comment));
+						if (token != NUMBER) {
+							xf86conffree(aptr);
+							Error(INVALID_SCR_MSG, NULL);
+						}
+						aptr->adj_y = val.num;
+					} else {
+						if (absKeyword) {
+							xf86conffree(aptr);
+							Error(INVALID_SCR_MSG, NULL);
+						} else
+							xf86unGetToken (token);
+					}
+					break;
+				case CONF_ADJ_RIGHTOF:
+				case CONF_ADJ_LEFTOF:
+				case CONF_ADJ_ABOVE:
+				case CONF_ADJ_BELOW:
+				case CONF_ADJ_RELATIVE:
+					token = xf86getSubToken(&(ptr->lay_comment));
+					if (token != STRING) {
+						xf86conffree(aptr);
+						Error(INVALID_SCR_MSG, NULL);
+					}
+					aptr->adj_refscreen = val.str;
+					if (aptr->adj_where == CONF_ADJ_RELATIVE)
+					{
+						token = xf86getSubToken(&(ptr->lay_comment));
+						if (token != NUMBER) {
+							xf86conffree(aptr);
+							Error(INVALID_SCR_MSG, NULL);
+						}
+						aptr->adj_x = val.num;
+						token = xf86getSubToken(&(ptr->lay_comment));
+						if (token != NUMBER) {
+							xf86conffree(aptr);
+							Error(INVALID_SCR_MSG, NULL);
+						}
+						aptr->adj_y = val.num;
+					}
+					break;
+				case CONF_ADJ_OBSOLETE:
+					/* top */
+					aptr->adj_top_str = val.str;
+
+					/* bottom */
+					if (xf86getSubToken (&(ptr->lay_comment)) != STRING) {
+						xf86conffree(aptr);
+						Error (SCREEN_MSG, NULL);
+					}
+					aptr->adj_bottom_str = val.str;
+
+					/* left */
+					if (xf86getSubToken (&(ptr->lay_comment)) != STRING) {
+						xf86conffree(aptr);
+						Error (SCREEN_MSG, NULL);
+					}
+					aptr->adj_left_str = val.str;
+
+					/* right */
+					if (xf86getSubToken (&(ptr->lay_comment)) != STRING) {
+						xf86conffree(aptr);
+						Error (SCREEN_MSG, NULL);
+					}
+					aptr->adj_right_str = val.str;
+
+				}
+				ptr->lay_adjacency_lst = (XF86ConfAdjacencyPtr)
+					xf86addListItem ((glp) ptr->lay_adjacency_lst, (glp) aptr);
+			}
+			break;
+		case INPUTDEVICE:
+			{
+				XF86ConfInputrefPtr iptr;
+
+				iptr = xf86confcalloc (1, sizeof (XF86ConfInputrefRec));
+				iptr->list.next = NULL;
+				iptr->iref_option_lst = NULL;
+				if (xf86getSubToken (&(ptr->lay_comment)) != STRING) {
+					xf86conffree(iptr);
+					Error (INPUTDEV_MSG, NULL);
+				}
+				iptr->iref_inputdev_str = val.str;
+				while ((token = xf86getSubToken (&(ptr->lay_comment))) == STRING)
+				{
+					iptr->iref_option_lst =
+						xf86addNewOption (iptr->iref_option_lst, val.str, NULL);
+				}
+				xf86unGetToken (token);
+				ptr->lay_input_lst = (XF86ConfInputrefPtr)
+					xf86addListItem ((glp) ptr->lay_input_lst, (glp) iptr);
+			}
+			break;
+		case OPTION:
+			ptr->lay_option_lst = xf86parseOption(ptr->lay_option_lst);
+			break;
+		case EOF_TOKEN:
+			Error (UNEXPECTED_EOF_MSG, NULL);
+			break;
+		default:
+			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
+			break;
+		}
+	}
+
+	if (!has_ident)
+		Error (NO_IDENT_MSG, NULL);
+
+#ifdef DEBUG
+	printf ("ServerLayout section parsed\n");
+#endif
+
+	return ptr;
+}
+
+#undef CLEANUP
+
+void
+xf86printLayoutSection (FILE * cf, XF86ConfLayoutPtr ptr)
+{
+	XF86ConfAdjacencyPtr aptr;
+	XF86ConfInactivePtr iptr;
+	XF86ConfInputrefPtr inptr;
+	XF86OptionPtr optr;
+
+	while (ptr)
+	{
+		fprintf (cf, "Section \"ServerLayout\"\n");
+		if (ptr->lay_comment)
+			fprintf (cf, "%s", ptr->lay_comment);
+		if (ptr->lay_identifier)
+			fprintf (cf, "\tIdentifier     \"%s\"\n", ptr->lay_identifier);
+
+		for (aptr = ptr->lay_adjacency_lst; aptr; aptr = aptr->list.next)
+		{
+			fprintf (cf, "\tScreen     ");
+			if (aptr->adj_scrnum >= 0)
+				fprintf (cf, "%2d", aptr->adj_scrnum);
+			else
+				fprintf (cf, "  ");
+			fprintf (cf, "  \"%s\"", aptr->adj_screen_str);
+			switch(aptr->adj_where)
+			{
+			case CONF_ADJ_OBSOLETE:
+				fprintf (cf, " \"%s\"", aptr->adj_top_str);
+				fprintf (cf, " \"%s\"", aptr->adj_bottom_str);
+				fprintf (cf, " \"%s\"", aptr->adj_right_str);
+				fprintf (cf, " \"%s\"\n", aptr->adj_left_str);
+				break;
+			case CONF_ADJ_ABSOLUTE:
+				if (aptr->adj_x != -1)
+					fprintf (cf, " %d %d\n", aptr->adj_x, aptr->adj_y);
+				else
+					fprintf (cf, "\n");
+				break;
+			case CONF_ADJ_RIGHTOF:
+				fprintf (cf, " RightOf \"%s\"\n", aptr->adj_refscreen);
+				break;
+			case CONF_ADJ_LEFTOF:
+				fprintf (cf, " LeftOf \"%s\"\n", aptr->adj_refscreen);
+				break;
+			case CONF_ADJ_ABOVE:
+				fprintf (cf, " Above \"%s\"\n", aptr->adj_refscreen);
+				break;
+			case CONF_ADJ_BELOW:
+				fprintf (cf, " Below \"%s\"\n", aptr->adj_refscreen);
+				break;
+			case CONF_ADJ_RELATIVE:
+				fprintf (cf, " Relative \"%s\" %d %d\n", aptr->adj_refscreen,
+						 aptr->adj_x, aptr->adj_y);
+				break;
+			}
+		}
+		for (iptr = ptr->lay_inactive_lst; iptr; iptr = iptr->list.next)
+			fprintf (cf, "\tInactive       \"%s\"\n", iptr->inactive_device_str);
+		for (inptr = ptr->lay_input_lst; inptr; inptr = inptr->list.next)
+		{
+			fprintf (cf, "\tInputDevice    \"%s\"", inptr->iref_inputdev_str);
+			for (optr = inptr->iref_option_lst; optr; optr = optr->list.next)
+			{
+				fprintf(cf, " \"%s\"", optr->opt_name);
+			}
+			fprintf(cf, "\n");
+		}
+		xf86printOptionList(cf, ptr->lay_option_lst, xf86whitespace_1);
+		fprintf (cf, "EndSection\n\n");
+		ptr = ptr->list.next;
+	}
+}
+
+void
+xf86freeLayoutList (XF86ConfLayoutPtr ptr)
+{
+	XF86ConfLayoutPtr prev;
+
+	while (ptr)
+	{
+		TestFree (ptr->lay_identifier);
+		TestFree (ptr->lay_comment);
+		xf86freeAdjacencyList (ptr->lay_adjacency_lst);
+		xf86freeInputrefList (ptr->lay_input_lst);
+		prev = ptr;
+		ptr = ptr->list.next;
+		xf86conffree (prev);
+	}
+}
+
+void
+xf86freeAdjacencyList (XF86ConfAdjacencyPtr ptr)
+{
+	XF86ConfAdjacencyPtr prev;
+
+	while (ptr)
+	{
+		TestFree (ptr->adj_screen_str);
+		TestFree (ptr->adj_top_str);
+		TestFree (ptr->adj_bottom_str);
+		TestFree (ptr->adj_left_str);
+		TestFree (ptr->adj_right_str);
+
+		prev = ptr;
+		ptr = ptr->list.next;
+		xf86conffree (prev);
+	}
+
+}
+
+void
+xf86freeInputrefList (XF86ConfInputrefPtr ptr)
+{
+	XF86ConfInputrefPtr prev;
+
+	while (ptr)
+	{
+		TestFree (ptr->iref_inputdev_str);
+		xf86optionListFree (ptr->iref_option_lst);
+		prev = ptr;
+		ptr = ptr->list.next;
+		xf86conffree (prev);
+	}
+
+}
+
+#define CheckScreen(str, ptr)\
+if (str[0] != '\0') \
+{ \
+screen = xf86findScreen (str, p->conf_screen_lst); \
+if (!screen) \
+{ \
+	xf86validationError (UNDEFINED_SCREEN_MSG, \
+				   str, layout->lay_identifier); \
+	return (FALSE); \
+} \
+else \
+	ptr = screen; \
+}
+
+int
+xf86validateLayout (XF86ConfigPtr p)
+{
+	XF86ConfLayoutPtr layout = p->conf_layout_lst;
+	XF86ConfAdjacencyPtr adj;
+	XF86ConfInactivePtr iptr;
+	XF86ConfInputrefPtr inptr;
+	XF86ConfScreenPtr screen;
+	XF86ConfDevicePtr device;
+	XF86ConfInputPtr input;
+
+	while (layout)
+	{
+		adj = layout->lay_adjacency_lst;
+		while (adj)
+		{
+			/* the first one can't be "" but all others can */
+			screen = xf86findScreen (adj->adj_screen_str, p->conf_screen_lst);
+			if (!screen)
+			{
+				xf86validationError (UNDEFINED_SCREEN_MSG,
+							   adj->adj_screen_str, layout->lay_identifier);
+				return (FALSE);
+			}
+			else
+				adj->adj_screen = screen;
+
+#if 0
+			CheckScreen (adj->adj_top_str, adj->adj_top);
+			CheckScreen (adj->adj_bottom_str, adj->adj_bottom);
+			CheckScreen (adj->adj_left_str, adj->adj_left);
+			CheckScreen (adj->adj_right_str, adj->adj_right);
+#endif
+
+			adj = adj->list.next;
+		}
+		iptr = layout->lay_inactive_lst;
+		while (iptr)
+		{
+			device = xf86findDevice (iptr->inactive_device_str,
+									p->conf_device_lst);
+			if (!device)
+			{
+				xf86validationError (UNDEFINED_DEVICE_LAY_MSG,
+						iptr->inactive_device_str, layout->lay_identifier);
+				return (FALSE);
+			}
+			else
+				iptr->inactive_device = device;
+			iptr = iptr->list.next;
+		}
+		inptr = layout->lay_input_lst;
+		while (inptr)
+		{
+			input = xf86findInput (inptr->iref_inputdev_str,
+									p->conf_input_lst);
+			if (!input)
+			{
+				xf86validationError (UNDEFINED_INPUT_MSG,
+						inptr->iref_inputdev_str, layout->lay_identifier);
+				return (FALSE);
+			}
+			else
+				inptr->iref_inputdev = input;
+			inptr = inptr->list.next;
+		}
+		layout = layout->list.next;
+	}
+	return (TRUE);
+}
+
+XF86ConfLayoutPtr
+xf86findLayout (const char *name, XF86ConfLayoutPtr list)
+{
+	while (list)
+	{
+		if (xf86nameCompare (list->lay_identifier, name) == 0)
+			return (list);
+		list = list->list.next;
+	}
+	return (NULL);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Module.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,267 @@
+/* 
+ * 
+ * Copyright (c) 1997  Metro Link Incorporated
+ * 
+ * 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
+ * THE X CONSORTIUM 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.
+ * 
+ * Except as contained in this notice, the name of the Metro Link shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Metro Link.
+ * 
+ */
+/*
+ * Copyright (c) 1997-2003 by The XFree86 Project, 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
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+
+/* View/edit this file with tab stops set to 4 */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "Configint.h"
+#include "fields.h"		/* Config file output line fields */
+
+extern LexRec val;
+
+static xf86ConfigSymTabRec SubModuleTab[] =
+{
+	{ENDSUBSECTION, "endsubsection"},
+	{OPTION, "option"},
+	{-1, ""},
+};
+
+static xf86ConfigSymTabRec ModuleTab[] =
+{
+	{ENDSECTION, "endsection"},
+	{LOAD, "load"},
+	{LOAD_DRIVER, "loaddriver"},
+	{SUBSECTION, "subsection"},
+	{-1, ""},
+};
+
+#define CLEANUP xf86freeModules
+
+XF86LoadPtr
+xf86parseModuleSubSection (XF86LoadPtr head, char *name)
+{
+	int token;
+	parsePrologue (XF86LoadPtr, XF86LoadRec)
+
+	ptr->load_name = name;
+	ptr->load_type = XF86_LOAD_MODULE;
+        ptr->ignore    = 0;
+	ptr->load_opt  = NULL;
+	ptr->list.next = NULL;
+
+	while ((token = xf86getToken (SubModuleTab)) != ENDSUBSECTION)
+	{
+		switch (token)
+		{
+		case COMMENT:
+			ptr->load_comment = xf86addComment(ptr->load_comment, val.str);
+			break;
+		case OPTION:
+			ptr->load_opt = xf86parseOption(ptr->load_opt);
+			break;
+		case EOF_TOKEN:
+			xf86parseError (UNEXPECTED_EOF_MSG, NULL);
+			xf86conffree(ptr);
+			return NULL;
+		default:
+			xf86parseError (INVALID_KEYWORD_MSG, xf86tokenString ());
+			xf86conffree(ptr);
+			return NULL;
+			break;
+		}
+
+	}
+
+	return ((XF86LoadPtr) xf86addListItem ((glp) head, (glp) ptr));
+}
+
+XF86ConfModulePtr
+xf86parseModuleSection (void)
+{
+	int token;
+	parsePrologue (XF86ConfModulePtr, XF86ConfModuleRec)
+
+	while ((token = xf86getToken (ModuleTab)) != ENDSECTION)
+	{
+		switch (token)
+		{
+		case COMMENT:
+			ptr->mod_comment = xf86addComment(ptr->mod_comment, val.str);
+			break;
+		case LOAD:
+			if (xf86getSubToken (&(ptr->mod_comment)) != STRING)
+				Error (QUOTE_MSG, "Load");
+			ptr->mod_load_lst =
+				xf86addNewLoadDirective (ptr->mod_load_lst, val.str,
+									 XF86_LOAD_MODULE, NULL);
+			break;
+		case LOAD_DRIVER:
+			if (xf86getSubToken (&(ptr->mod_comment)) != STRING)
+				Error (QUOTE_MSG, "LoadDriver");
+			ptr->mod_load_lst =
+				xf86addNewLoadDirective (ptr->mod_load_lst, val.str,
+									 XF86_LOAD_DRIVER, NULL);
+			break;
+		case SUBSECTION:
+			if (xf86getSubToken (&(ptr->mod_comment)) != STRING)
+						Error (QUOTE_MSG, "SubSection");
+			ptr->mod_load_lst =
+				xf86parseModuleSubSection (ptr->mod_load_lst, val.str);
+			break;
+		case EOF_TOKEN:
+			Error (UNEXPECTED_EOF_MSG, NULL);
+			break;
+		default:
+			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
+			break;
+		}
+	}
+
+#ifdef DEBUG
+	printf ("Module section parsed\n");
+#endif
+
+	return ptr;
+}
+
+#undef CLEANUP
+
+void
+xf86printModuleSection (FILE * cf, XF86ConfModulePtr ptr)
+{
+	XF86LoadPtr lptr;
+
+	if (ptr == NULL)
+		return;
+
+	fprintf (cf, "Section \"Module\"\n");
+
+	if (ptr->mod_comment)
+		fprintf(cf, "%s", ptr->mod_comment);
+	for (lptr = ptr->mod_load_lst; lptr; lptr = lptr->list.next)
+	{
+		switch (lptr->load_type)
+		{
+		case XF86_LOAD_MODULE:
+			if( lptr->load_opt == NULL ) {
+				fprintf (cf, "\tLoad  \"%s\"", lptr->load_name);
+				if (lptr->load_comment)
+					fprintf(cf, "%s", lptr->load_comment);
+				else
+					fputc('\n', cf);
+			}
+			else
+			{
+				fprintf (cf, "\tSubSection \"%s\"\n", lptr->load_name);
+				if (lptr->load_comment)
+					fprintf(cf, "%s", lptr->load_comment);
+				xf86printOptionList(cf, lptr->load_opt, xf86whitespace_2);
+				fprintf (cf, "\tEndSubSection\n");
+			}
+			break;
+		case XF86_LOAD_DRIVER:
+			fprintf (cf, "\tLoadDriver  \"%s\"", lptr->load_name);
+				if (lptr->load_comment)
+					fprintf(cf, "%s", lptr->load_comment);
+				else
+					fputc('\n', cf);
+			break;
+#if 0
+		default:
+			fprintf (cf, "#\tUnknown type  \"%s\"\n", lptr->load_name);
+			break;
+#endif
+		}
+	}
+	fprintf (cf, "EndSection\n\n");
+}
+
+XF86LoadPtr
+xf86addNewLoadDirective (XF86LoadPtr head, char *name, int type, XF86OptionPtr opts)
+{
+	XF86LoadPtr new;
+	int token;
+
+	new = xf86confcalloc (1, sizeof (XF86LoadRec));
+	new->load_name = name;
+	new->load_type = type;
+	new->load_opt  = opts;
+        new->ignore    = 0;
+	new->list.next = NULL;
+
+	if ((token = xf86getToken(NULL)) == COMMENT)
+		new->load_comment = xf86addComment(new->load_comment, val.str);
+	else
+		xf86unGetToken(token);
+
+	return ((XF86LoadPtr) xf86addListItem ((glp) head, (glp) new));
+}
+
+void
+xf86freeModules (XF86ConfModulePtr ptr)
+{
+	XF86LoadPtr lptr;
+	XF86LoadPtr prev;
+
+	if (ptr == NULL)
+		return;
+	lptr = ptr->mod_load_lst;
+	while (lptr)
+	{
+		TestFree (lptr->load_name);
+		TestFree (lptr->load_comment);
+		prev = lptr;
+		lptr = lptr->list.next;
+		xf86conffree (prev);
+	}
+	TestFree (ptr->mod_comment);
+	xf86conffree (ptr);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Monitor.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,1403 @@
+/* 
+ * 
+ * Copyright (c) 1997  Metro Link Incorporated
+ * 
+ * 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
+ * THE X CONSORTIUM 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.
+ * 
+ * Except as contained in this notice, the name of the Metro Link shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Metro Link.
+ * 
+ */
+/*
+ * Copyright (c) 1997-2003 by The XFree86 Project, 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
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+
+/* View/edit this file with tab stops set to 4 */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "Configint.h"
+#include "fields.h"		/* Config file output line fields */
+#if defined(SMI_FBCONFIG)
+#include "fbc_line_er.h"	/* External Representation of config lines */
+#endif
+
+extern LexRec val;
+
+static xf86ConfigSymTabRec MonitorTab[] =
+{
+	{ENDSECTION, "endsection"},
+	{IDENTIFIER, "identifier"},
+	{VENDOR, "vendorname"},
+	{MODEL, "modelname"},
+	{USEMODES, "usemodes"},
+	{MODELINE, "modeline"},
+	{DISPLAYSIZE, "displaysize"},
+	{HORIZSYNC, "horizsync"},
+	{VERTREFRESH, "vertrefresh"},
+	{MODE, "mode"},
+	{GAMMA, "gamma"},
+	{OPTION, "option"},
+	{-1, ""},
+};
+
+static xf86ConfigSymTabRec ModesTab[] =
+{
+	{ENDSECTION, "endsection"},
+	{IDENTIFIER, "identifier"},
+	{MODELINE, "modeline"},
+	{MODE, "mode"},
+	{-1, ""},
+};
+
+static xf86ConfigSymTabRec TimingTab[] =
+{
+	{TT_INTERLACE, "interlace"},
+	{TT_PHSYNC, "+hsync"},
+	{TT_NHSYNC, "-hsync"},
+	{TT_PVSYNC, "+vsync"},
+	{TT_NVSYNC, "-vsync"},
+	{TT_CSYNC, "composite"},
+	{TT_PCSYNC, "+csync"},
+	{TT_NCSYNC, "-csync"},
+	{TT_DBLSCAN, "doublescan"},
+	{TT_HSKEW, "hskew"},
+	{TT_BCAST, "bcast"},
+	{TT_VSCAN, "vscan"},
+	{TT_CUSTOM, "CUSTOM"},
+	{-1, ""},
+};
+
+static xf86ConfigSymTabRec ModeTab[] =
+{
+	{DOTCLOCK, "dotclock"},
+	{HTIMINGS, "htimings"},
+	{VTIMINGS, "vtimings"},
+	{FLAGS, "flags"},
+	{HSKEW, "hskew"},
+	{BCAST, "bcast"},
+	{VSCAN, "vscan"},
+	{ENDMODE, "endmode"},
+	{-1, ""},
+};
+
+#define CLEANUP xf86freeModeLineList
+
+XF86ConfModeLinePtr
+xf86parseModeLine (void)
+{
+	int token;
+#if defined(SMI_FBCONFIG)
+	void *line_er;			/* Ptr to Extnl Rep of config line */
+#endif
+	parsePrologue (XF86ConfModeLinePtr, XF86ConfModeLineRec)
+
+	ptr->ml_verbose = FALSE;
+
+#if defined(SMI_FBCONFIG)
+	/*
+	 * Link Internal & External Representations of the line
+	 */
+	line_er = fbc_get_current_line_ER();
+	ptr->ml_dotclock_line_er = line_er;
+	ptr->ml_htimings_line_er = line_er;
+	ptr->ml_vtimings_line_er = line_er;
+	ptr->ml_flags_line_er    = line_er;
+	ptr->ml_hskew_line_er    = line_er;
+	ptr->ml_vscan_line_er    = line_er;
+	fbc_link_line_ER(line_er, (void *)ptr,
+			(xf86_print_fn_t *)&xf86printMxxxSectionModeLine,
+			FBC_INDENT_1);
+
+#endif
+	/* Identifier */
+	if (xf86getSubToken (&(ptr->ml_comment)) != STRING)
+		Error ("ModeLine identifier expected", NULL);
+	ptr->ml_identifier = val.str;
+
+	/* DotClock */
+	if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
+		Error ("ModeLine dotclock expected", NULL);
+	ptr->ml_clock = (int) (val.realnum * 1000.0 + 0.5);
+
+	/* HDisplay */
+	if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
+		Error ("ModeLine Hdisplay expected", NULL);
+	ptr->ml_hdisplay = val.num;
+
+	/* HSyncStart */
+	if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
+		Error ("ModeLine HSyncStart expected", NULL);
+	ptr->ml_hsyncstart = val.num;
+
+	/* HSyncEnd */
+	if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
+		Error ("ModeLine HSyncEnd expected", NULL);
+	ptr->ml_hsyncend = val.num;
+
+	/* HTotal */
+	if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
+		Error ("ModeLine HTotal expected", NULL);
+	ptr->ml_htotal = val.num;
+
+	/* VDisplay */
+	if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
+		Error ("ModeLine Vdisplay expected", NULL);
+	ptr->ml_vdisplay = val.num;
+
+	/* VSyncStart */
+	if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
+		Error ("ModeLine VSyncStart expected", NULL);
+	ptr->ml_vsyncstart = val.num;
+
+	/* VSyncEnd */
+	if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
+		Error ("ModeLine VSyncEnd expected", NULL);
+	ptr->ml_vsyncend = val.num;
+
+	/* VTotal */
+	if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
+		Error ("ModeLine VTotal expected", NULL);
+	ptr->ml_vtotal = val.num;
+
+	token = xf86getSubTokenWithTab (&(ptr->ml_comment), TimingTab);
+	while ((token == TT_INTERLACE) || (token == TT_PHSYNC) ||
+		   (token == TT_NHSYNC) || (token == TT_PVSYNC) ||
+		   (token == TT_NVSYNC) || (token == TT_CSYNC) ||
+		   (token == TT_PCSYNC) || (token == TT_NCSYNC) ||
+		   (token == TT_DBLSCAN) || (token == TT_HSKEW) ||
+		   (token == TT_VSCAN) || (token == TT_BCAST))
+	{
+		switch (token)
+		{
+
+		case TT_INTERLACE:
+			ptr->ml_flags |= XF86CONF_INTERLACE;
+			break;
+		case TT_PHSYNC:
+			ptr->ml_flags |= XF86CONF_PHSYNC;
+			break;
+		case TT_NHSYNC:
+			ptr->ml_flags |= XF86CONF_NHSYNC;
+			break;
+		case TT_PVSYNC:
+			ptr->ml_flags |= XF86CONF_PVSYNC;
+			break;
+		case TT_NVSYNC:
+			ptr->ml_flags |= XF86CONF_NVSYNC;
+			break;
+		case TT_CSYNC:
+			ptr->ml_flags |= XF86CONF_CSYNC;
+			break;
+		case TT_PCSYNC:
+			ptr->ml_flags |= XF86CONF_PCSYNC;
+			break;
+		case TT_NCSYNC:
+			ptr->ml_flags |= XF86CONF_NCSYNC;
+			break;
+		case TT_DBLSCAN:
+			ptr->ml_flags |= XF86CONF_DBLSCAN;
+			break;
+		case TT_HSKEW:
+			if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
+				Error (NUMBER_MSG, "Hskew");
+			ptr->ml_hskew = val.num;
+			ptr->ml_flags |= XF86CONF_HSKEW;
+			break;
+		case TT_BCAST:
+			ptr->ml_flags |= XF86CONF_BCAST;
+			break;
+		case TT_VSCAN:
+			if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
+				Error (NUMBER_MSG, "Vscan");
+			ptr->ml_vscan = val.num;
+			ptr->ml_flags |= XF86CONF_VSCAN;
+			break;
+		case TT_CUSTOM:
+			ptr->ml_flags |= XF86CONF_CUSTOM;
+			break;
+		case EOF_TOKEN:
+			Error (UNEXPECTED_EOF_MSG, NULL);
+			break;
+		default:
+			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
+			break;
+		}
+		token = xf86getSubTokenWithTab (&(ptr->ml_comment), TimingTab);
+	}
+	xf86unGetToken (token);
+
+#ifdef DEBUG
+	printf ("ModeLine parsed\n");
+#endif
+	return (ptr);
+}
+
+
+/*
+ * xf86parseVerboseMode(void)
+ *
+ *    Parse a "verbose" Mode-EndMode entry of a Monitor or Modes
+ *    section.
+ */
+XF86ConfModeLinePtr
+xf86parseVerboseMode (void)
+{
+	int token, token2;
+	int had_dotclock = 0, had_htimings = 0, had_vtimings = 0;
+#if defined(SMI_FBCONFIG)
+	void *line_er;			/* Ptr to Extnl Rep of config line */
+#endif
+	parsePrologue (XF86ConfModeLinePtr, XF86ConfModeLineRec)
+
+	ptr->ml_verbose = TRUE;
+
+	if (xf86getSubToken (&(ptr->ml_comment)) != STRING)
+		Error ("Mode name expected", NULL);
+	ptr->ml_identifier = val.str;
+	for (;;)
+	{
+		token = xf86getToken(ModeTab);
+#if defined(SMI_FBCONFIG)
+		/*
+		 * Get a ptr to the External Representation of this config line
+		 */
+		line_er = fbc_get_current_line_ER();
+
+#endif
+		if (token == ENDMODE)
+		{
+			break;
+		}
+		switch (token)
+		{
+		case COMMENT:
+			ptr->ml_comment = xf86addComment(ptr->ml_comment, val.str);
+			break;
+		case DOTCLOCK:
+			if ((token = xf86getSubToken (&(ptr->ml_comment))) != NUMBER)
+				Error (NUMBER_MSG, "DotClock");
+			ptr->ml_clock = (int) (val.realnum * 1000.0 + 0.5);
+			had_dotclock = 1;
+#if defined(SMI_FBCONFIG)
+			/*
+			 * Link Internal & External Representations of the line
+			 */
+			ptr->ml_dotclock_line_er = line_er;
+			fbc_link_line_ER(line_er,
+					(void *)ptr,
+					(xf86_print_fn_t *)&xf86printMxxxSectionModeDotClock,
+					FBC_INDENT_2);
+#endif
+			break;
+		case HTIMINGS:
+			if (xf86getSubToken (&(ptr->ml_comment)) == NUMBER)
+				ptr->ml_hdisplay = val.num;
+			else
+				Error ("Horizontal display expected", NULL);
+
+			if (xf86getSubToken (&(ptr->ml_comment)) == NUMBER)
+				ptr->ml_hsyncstart = val.num;
+			else
+				Error ("Horizontal sync start expected", NULL);
+
+			if (xf86getSubToken (&(ptr->ml_comment)) == NUMBER)
+				ptr->ml_hsyncend = val.num;
+			else
+				Error ("Horizontal sync end expected", NULL);
+
+			if (xf86getSubToken (&(ptr->ml_comment)) == NUMBER)
+				ptr->ml_htotal = val.num;
+			else
+				Error ("Horizontal total expected", NULL);
+			had_htimings = 1;
+#if defined(SMI_FBCONFIG)
+			/*
+			 * Link Internal & External Representations of the line
+			 */
+			ptr->ml_htimings_line_er = line_er;
+			fbc_link_line_ER(line_er,
+					(void *)ptr,
+					(xf86_print_fn_t *)&xf86printMxxxSectionModeHTimings,
+					FBC_INDENT_2);
+#endif
+			break;
+		case VTIMINGS:
+			if (xf86getSubToken (&(ptr->ml_comment)) == NUMBER)
+				ptr->ml_vdisplay = val.num;
+			else
+				Error ("Vertical display expected", NULL);
+
+			if (xf86getSubToken (&(ptr->ml_comment)) == NUMBER)
+				ptr->ml_vsyncstart = val.num;
+			else
+				Error ("Vertical sync start expected", NULL);
+
+			if (xf86getSubToken (&(ptr->ml_comment)) == NUMBER)
+				ptr->ml_vsyncend = val.num;
+			else
+				Error ("Vertical sync end expected", NULL);
+
+			if (xf86getSubToken (&(ptr->ml_comment)) == NUMBER)
+				ptr->ml_vtotal = val.num;
+			else
+				Error ("Vertical total expected", NULL);
+			had_vtimings = 1;
+#if defined(SMI_FBCONFIG)
+			/*
+			 * Link Internal & External Representations of the line
+			 */
+			ptr->ml_vtimings_line_er = line_er;
+			fbc_link_line_ER(line_er,
+					(void *)ptr,
+					(xf86_print_fn_t *)&xf86printMxxxSectionModeVTimings,
+					FBC_INDENT_2);
+#endif
+			break;
+		case FLAGS:
+			token = xf86getSubToken (&(ptr->ml_comment));
+			if (token != STRING)
+				Error (QUOTE_MSG, "Flags");
+			while (token == STRING)
+			{
+				token2 = xf86getStringToken (TimingTab);
+				switch (token2)
+				{
+				case TT_INTERLACE:
+					ptr->ml_flags |= XF86CONF_INTERLACE;
+					break;
+				case TT_PHSYNC:
+					ptr->ml_flags |= XF86CONF_PHSYNC;
+					break;
+				case TT_NHSYNC:
+					ptr->ml_flags |= XF86CONF_NHSYNC;
+					break;
+				case TT_PVSYNC:
+					ptr->ml_flags |= XF86CONF_PVSYNC;
+					break;
+				case TT_NVSYNC:
+					ptr->ml_flags |= XF86CONF_NVSYNC;
+					break;
+				case TT_CSYNC:
+					ptr->ml_flags |= XF86CONF_CSYNC;
+					break;
+				case TT_PCSYNC:
+					ptr->ml_flags |= XF86CONF_PCSYNC;
+					break;
+				case TT_NCSYNC:
+					ptr->ml_flags |= XF86CONF_NCSYNC;
+					break;
+				case TT_DBLSCAN:
+					ptr->ml_flags |= XF86CONF_DBLSCAN;
+					break;
+				case TT_CUSTOM:
+					ptr->ml_flags |= XF86CONF_CUSTOM;
+					break;
+				case EOF_TOKEN:
+					Error (UNEXPECTED_EOF_MSG, NULL);
+					break;
+				default:
+					Error ("Unknown flag string, %s",
+							val.str);
+					break;
+				}
+				token = xf86getSubToken (&(ptr->ml_comment));
+			}
+			xf86unGetToken (token);
+#if defined(SMI_FBCONFIG)
+			/*
+			 * Link Internal & External Representations of the line
+			 */
+			ptr->ml_flags_line_er = line_er;
+			fbc_link_line_ER(line_er,
+					(void *)ptr,
+					(xf86_print_fn_t *)&xf86printMxxxSectionModeFlags,
+					FBC_INDENT_2);
+#endif
+			break;
+		case HSKEW:
+			if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
+				Error ("Horizontal skew expected", NULL);
+			ptr->ml_flags |= XF86CONF_HSKEW;
+			ptr->ml_hskew = val.num;
+#if defined(SMI_FBCONFIG)
+			/*
+			 * Link Internal & External Representations of the line
+			 */
+			ptr->ml_hskew_line_er = line_er;
+			fbc_link_line_ER(line_er,
+					(void *)ptr,
+					(xf86_print_fn_t *)&xf86printMxxxSectionModeHSkew,
+					FBC_INDENT_2);
+#endif
+			break;
+		case VSCAN:
+			if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
+				Error ("Vertical scan count expected", NULL);
+			ptr->ml_flags |= XF86CONF_VSCAN;
+			ptr->ml_vscan = val.num;
+#if defined(SMI_FBCONFIG)
+			/*
+			 * Link Internal & External Representations of the line
+			 */
+			ptr->ml_vscan_line_er = line_er;
+			fbc_link_line_ER(line_er,
+					(void *)ptr,
+					(xf86_print_fn_t *)&xf86printMxxxSectionModeVScan,
+					FBC_INDENT_2);
+#endif
+			break;
+		case EOF_TOKEN:
+			Error (UNEXPECTED_EOF_MSG, NULL);
+			break;
+		default:
+			Error ("Unexepcted token in verbose \"Mode\" entry\n", NULL);
+			break;
+		}
+	}
+
+#if defined(SMI_FBCONFIG)
+	/*
+	 * Link Internal & External Representations of the EndMode line
+	 */
+	ptr->ml_end_line_er = line_er;
+	fbc_link_line_ER(line_er,
+			(void *)ptr,
+			NULL /* (xf86_print_fn_t *)&xf86printMxxxSectionEndMode */ ,
+			FBC_INDENT_1);
+
+#endif
+	if (!had_dotclock)
+		Error ("The DotClock is missing", NULL);
+	if (!had_htimings)
+		Error ("The horizontal timings are missing", NULL);
+	if (!had_vtimings)
+		Error ("The vertical timings are missing", NULL);
+
+#ifdef DEBUG
+	printf ("Verbose Mode parsed\n");
+#endif
+	return (ptr);
+}
+
+#undef CLEANUP
+
+#define CLEANUP xf86freeMonitorList
+
+XF86ConfMonitorPtr
+xf86parseMonitorSection (void)
+{
+	int has_ident = FALSE;
+	int token;
+#if defined(SMI_FBCONFIG)
+	void *line_er;			/* Ptr to Extnl Rep of config line */
+#endif
+	parsePrologue (XF86ConfMonitorPtr, XF86ConfMonitorRec)
+
+	for (;;)
+	{
+		token = xf86getToken(MonitorTab);
+#if defined(SMI_FBCONFIG)
+		/*
+		 * Get a ptr to the External Representation of this config line
+		 */
+		line_er = fbc_get_current_line_ER();
+
+#endif
+		if (token == ENDSECTION)
+		{
+			break;
+		}
+		switch (token)
+		{
+		case COMMENT:
+			ptr->mon_comment = xf86addComment(ptr->mon_comment, val.str);
+			break;
+		case IDENTIFIER:
+			if (xf86getSubToken (&(ptr->mon_comment)) != STRING)
+				Error (QUOTE_MSG, "Identifier");
+			if (has_ident == TRUE)
+				Error (MULTIPLE_MSG, "Identifier");
+			ptr->mon_identifier = val.str;
+			has_ident = TRUE;
+			break;
+		case VENDOR:
+			if (xf86getSubToken (&(ptr->mon_comment)) != STRING)
+				Error (QUOTE_MSG, "Vendor");
+			ptr->mon_vendor = val.str;
+			break;
+		case MODEL:
+			if (xf86getSubToken (&(ptr->mon_comment)) != STRING)
+				Error (QUOTE_MSG, "ModelName");
+			ptr->mon_modelname = val.str;
+			break;
+		case MODE:
+			HANDLE_LIST (mon_modeline_lst, xf86parseVerboseMode,
+						 XF86ConfModeLinePtr);
+			break;
+		case MODELINE:
+			HANDLE_LIST (mon_modeline_lst, xf86parseModeLine,
+						 XF86ConfModeLinePtr);
+			break;
+		case DISPLAYSIZE:
+			if (xf86getSubToken (&(ptr->mon_comment)) != NUMBER)
+				Error (DISPLAYSIZE_MSG, NULL);
+			ptr->mon_width = val.realnum;
+			if (xf86getSubToken (&(ptr->mon_comment)) != NUMBER)
+				Error (DISPLAYSIZE_MSG, NULL);
+			ptr->mon_height = val.realnum;
+			break;
+
+		case HORIZSYNC:
+			if (xf86getSubToken (&(ptr->mon_comment)) != NUMBER)
+				Error (HORIZSYNC_MSG, NULL);
+			do {
+				if (ptr->mon_n_hsync >= CONF_MAX_HSYNC)
+					Error ("Sorry. Too many horizontal sync intervals.", NULL);
+				ptr->mon_hsync[ptr->mon_n_hsync].lo = val.realnum;
+				switch (token = xf86getSubToken (&(ptr->mon_comment)))
+				{
+					case COMMA:
+						ptr->mon_hsync[ptr->mon_n_hsync].hi =
+						ptr->mon_hsync[ptr->mon_n_hsync].lo;
+						break;
+					case DASH:
+						if (xf86getSubToken (&(ptr->mon_comment)) != NUMBER ||
+						    (float)val.realnum < ptr->mon_hsync[ptr->mon_n_hsync].lo)
+							Error (HORIZSYNC_MSG, NULL);
+						ptr->mon_hsync[ptr->mon_n_hsync].hi = val.realnum;
+						if ((token = xf86getSubToken (&(ptr->mon_comment))) == COMMA)
+							break;
+						ptr->mon_n_hsync++;
+						goto HorizDone;
+					default:
+						/* We cannot currently know if a '\n' was found,
+						 * or this is a real error
+						 */
+						ptr->mon_hsync[ptr->mon_n_hsync].hi =
+						ptr->mon_hsync[ptr->mon_n_hsync].lo;
+						ptr->mon_n_hsync++;
+						goto HorizDone;
+				}
+				ptr->mon_n_hsync++;
+			} while ((token = xf86getSubToken (&(ptr->mon_comment))) == NUMBER);
+HorizDone:
+			xf86unGetToken (token);
+			break;
+
+		case VERTREFRESH:
+			if (xf86getSubToken (&(ptr->mon_comment)) != NUMBER)
+				Error (VERTREFRESH_MSG, NULL);
+			do {
+				ptr->mon_vrefresh[ptr->mon_n_vrefresh].lo = val.realnum;
+				switch (token = xf86getSubToken (&(ptr->mon_comment)))
+				{
+					case COMMA:
+						ptr->mon_vrefresh[ptr->mon_n_vrefresh].hi =
+						ptr->mon_vrefresh[ptr->mon_n_vrefresh].lo;
+						break;
+					case DASH:
+						if (xf86getSubToken (&(ptr->mon_comment)) != NUMBER ||
+						    (float)val.realnum < ptr->mon_vrefresh[ptr->mon_n_vrefresh].lo)
+							Error (VERTREFRESH_MSG, NULL);
+						ptr->mon_vrefresh[ptr->mon_n_vrefresh].hi = val.realnum;
+						if ((token = xf86getSubToken (&(ptr->mon_comment))) == COMMA)
+							break;
+						ptr->mon_n_vrefresh++;
+						goto VertDone;
+					default:
+						/* We cannot currently know if a '\n' was found,
+						 * or this is a real error
+						 */
+						ptr->mon_vrefresh[ptr->mon_n_vrefresh].hi =
+						ptr->mon_vrefresh[ptr->mon_n_vrefresh].lo;
+						ptr->mon_n_vrefresh++;
+						goto VertDone;
+				}
+				if (ptr->mon_n_vrefresh >= CONF_MAX_VREFRESH)
+					Error ("Sorry. Too many vertical refresh intervals.", NULL);
+				ptr->mon_n_vrefresh++;
+			} while ((token = xf86getSubToken (&(ptr->mon_comment))) == NUMBER);
+VertDone:
+			xf86unGetToken (token);
+			break;
+
+		case GAMMA:
+			if (xf86getSubToken (&(ptr->mon_comment)) != NUMBER)
+			{
+				Error (INVALID_GAMMA_MSG, NULL);
+				break;
+			}
+			ptr->mon_gamma_red = val.realnum;
+			if (xf86getSubToken (&(ptr->mon_comment)) != NUMBER)
+			{
+				ptr->mon_gamma_green = ptr->mon_gamma_red;
+				ptr->mon_gamma_blue  = ptr->mon_gamma_red;
+				xf86unGetToken (token);
+			}
+			else
+			{
+				ptr->mon_gamma_green = val.realnum;
+				if (xf86getSubToken (&(ptr->mon_comment)) != NUMBER)
+				{
+					Error (INVALID_GAMMA_MSG, NULL);
+					break;
+				}
+				ptr->mon_gamma_blue = val.realnum;
+			}
+#if defined(SMI_FBCONFIG)
+			/*
+			 * Link Internal & External Representations of the line
+			 */
+			ptr->mon_gamma_line_er = line_er;
+			fbc_link_line_ER(line_er,
+					(void *)ptr,
+					(xf86_print_fn_t *)&xf86printMonitorSectionGamma,
+					FBC_INDENT_1);
+#endif
+			break;
+		case OPTION:
+			ptr->mon_option_lst = xf86parseOption(ptr->mon_option_lst);
+			break;
+		case USEMODES:
+		        {
+				XF86ConfModesLinkPtr mptr;
+
+				if ((token = xf86getSubToken (&(ptr->mon_comment))) != STRING)
+					Error (QUOTE_MSG, "UseModes");
+
+				/* add to the end of the list of modes sections 
+				   referenced here */
+				mptr = xf86confcalloc (1, sizeof (XF86ConfModesLinkRec));
+				mptr->list.next = NULL;
+				mptr->ml_modes_str = val.str;
+				mptr->ml_modes = NULL;
+				ptr->mon_modes_sect_lst = (XF86ConfModesLinkPtr)
+					xf86addListItem((GenericListPtr)ptr->mon_modes_sect_lst,
+						    (GenericListPtr)mptr);
+#if defined(SMI_FBCONFIG)
+				/*
+			 	 * Link Internal & External Representations of the line
+			 	 */
+				mptr->line_er = line_er;
+				ptr->mon_usemodes_line_er = line_er;
+#endif
+			}
+			break;
+		case EOF_TOKEN:
+			Error (UNEXPECTED_EOF_MSG, NULL);
+			break;
+		default:
+			xf86parseError (INVALID_KEYWORD_MSG, xf86tokenString ());
+			CLEANUP (ptr);
+			return NULL;
+		}
+	}
+
+#if defined(SMI_FBCONFIG)
+	/*
+	 * Link Internal & External Representations of the EndSection line
+	 */
+	ptr->mon_end_line_er = line_er;
+	fbc_link_line_ER(line_er,
+			(void *)ptr,
+			(xf86_print_fn_t *)&xf86printMonitorSectionEndSection,
+			FBC_INDENT_0);
+
+#endif
+	if (!has_ident)
+		Error (NO_IDENT_MSG, NULL);
+
+#ifdef DEBUG
+	printf ("Monitor section parsed\n");
+#endif
+	return ptr;
+}
+
+#undef CLEANUP
+#define CLEANUP xf86freeModesList
+
+XF86ConfModesPtr
+xf86parseModesSection (void)
+{
+	int has_ident = FALSE;
+	int token;
+	parsePrologue (XF86ConfModesPtr, XF86ConfModesRec)
+
+#if defined(SMI_FBCONFIG)
+	fbc_line_elem_t *line_er;			/* Ptr to Extnl Rep of config line */
+	int isSunModesSection = FALSE;
+
+	/*
+	 * Link Internal & External Representations of the line
+	 */
+	line_er = fbc_get_current_line_ER();
+	ptr->begin_line_er = line_er;
+
+#endif /* SMI_FBCONFIG */
+
+
+	while ((token = xf86getToken (ModesTab)) != ENDSECTION)
+	{
+		switch (token)
+		{
+		case COMMENT:
+			ptr->modes_comment = xf86addComment(ptr->modes_comment, val.str);
+			break;
+		case IDENTIFIER:
+			if (xf86getSubToken (&(ptr->modes_comment)) != STRING)
+				Error (QUOTE_MSG, "Identifier");
+			if (has_ident == TRUE)
+				Error (MULTIPLE_MSG, "Identifier");
+			ptr->modes_identifier = val.str;
+			has_ident = TRUE;
+
+#if defined(SMI_FBCONFIG)
+			if (strcmp(val.str, "SunModes") == 0) {
+				isSunModesSection = TRUE;
+			}
+#endif /* SMI_FBCONFIG */
+
+			break;
+		case MODE:
+			HANDLE_LIST (mon_modeline_lst, xf86parseVerboseMode,
+						 XF86ConfModeLinePtr);
+			break;
+		case MODELINE:
+			HANDLE_LIST (mon_modeline_lst, xf86parseModeLine,
+						 XF86ConfModeLinePtr);
+			break;
+		default:
+			xf86parseError (INVALID_KEYWORD_MSG, xf86tokenString ());
+			CLEANUP (ptr);
+			return NULL;
+			break;
+		}
+	}
+
+#if defined(SMI_FBCONFIG)
+	ptr->end_line_er = fbc_get_current_line_ER();
+
+	if (isSunModesSection == TRUE) {
+		while (line_er != NULL) {
+			fbc_delete_line_ER(line_er);
+			line_er = line_er->next_ptr;
+		}
+	}
+#endif /* SMI_FBCONFIG */
+
+	if (!has_ident)
+		Error (NO_IDENT_MSG, NULL);
+
+#ifdef DEBUG
+	printf ("Modes section parsed\n");
+#endif
+	return ptr;
+}
+
+#undef CLEANUP
+
+
+/*
+ * xf86printMonitorSectionSection()
+ *
+ *    Write the Monitor section Section line to the configuration file.
+ */
+void
+xf86printMonitorSectionSection(
+	FILE *cf, XF86ConfMonitorPtr ptr, const char *const whitespace[])
+{
+	fprintf (cf, "Section \"Monitor\"\n");
+	if (ptr->mon_comment != NULL) {
+		fprintf(cf, "%s", ptr->mon_comment);
+	}
+}
+
+
+/*
+ * xf86printMonitorSectionIdentifier()
+ *
+ *    Write the Monitor section Identifier line to the configuration
+ *    file.
+ */
+void
+xf86printMonitorSectionIdentifier(
+	FILE *cf, XF86ConfMonitorPtr ptr, const char *const whitespace[])
+{
+	xf86printFields(cf, whitespace, "Identifier", NULL);
+	fprintf(cf, "\"%s\"\n", ptr->mon_identifier);
+}
+
+
+/*
+ * xf86printMonitorSectionUseModes()
+ *
+ *    Write a Monitor section UseModes entry line to the configuration
+ *    file.
+ */
+void
+xf86printMonitorSectionUseModes(
+	FILE *cf, XF86ConfModesLinkPtr mptr, const char *const whitespace[])
+{
+	xf86printFields(cf, whitespace, "UseModes", NULL);
+	fprintf (cf, "\"%s\"\n", mptr->ml_modes_str);
+}
+
+
+/*
+ * xf86printMonitorSectionGamma()
+ *
+ *    Write the Gamma entry of a Monitor section to the configuration
+ *    file.
+ */
+void
+xf86printMonitorSectionGamma(
+	FILE *cf, XF86ConfMonitorPtr ptr, const char *const whitespace[])
+{
+	xf86printFields(cf, whitespace, "Gamma", NULL);
+	if (ptr->mon_gamma_red == ptr->mon_gamma_green
+			&& ptr->mon_gamma_red == ptr->mon_gamma_blue) {
+		fprintf(cf, "%.4g\n", ptr->mon_gamma_red);
+	} else {
+		fprintf(cf, "%.4g %.4g %.4g\n",
+				ptr->mon_gamma_red,
+				ptr->mon_gamma_green,
+				ptr->mon_gamma_blue);
+	}
+}
+
+
+/*
+ * xf86printMonitorSectionEndSection()
+ *
+ *    Write the Monitor section EndSection line to the configuration
+ *    file.
+ */
+void
+xf86printMonitorSectionEndSection(
+	FILE *cf, XF86ConfMonitorPtr ptr, const char *const whitespace[])
+{
+	fprintf (cf, "EndSection\n");
+}
+
+
+/*
+ * ModeLine/Mode-EndMode entry flags (in man page order)
+ */
+const static struct {
+	int		mask;		/* Mode flag mask bit */
+	char		*name;		/* Mode flag name string */
+} modeFlagTab[] = {
+	{ XF86CONF_INTERLACE, "Interlace"  },
+	{ XF86CONF_DBLSCAN  , "DoubleScan" },
+	{ XF86CONF_PHSYNC   , "+HSync"     },
+	{ XF86CONF_NHSYNC   , "-HSync"     },
+	{ XF86CONF_PVSYNC   , "+VSync"     },
+	{ XF86CONF_NVSYNC   , "-VSync"     },
+	{ XF86CONF_CSYNC    , "Composite"  },
+	{ XF86CONF_PCSYNC   , "+CSync"     },
+	{ XF86CONF_NCSYNC   , "-CSync"     },
+	{ XF86CONF_CUSTOM   , "Custom"     },	/* ??? not in man page ??? */
+	{ XF86CONF_BCAST    , "BCast"      },	/* ??? not in man page ??? */
+	{ 0                 , NULL         }	/* End-of-table marker */
+};
+
+
+/*
+ * xf86printMxxxSectionModeDotClock()
+ *
+ *    Write the DotClock line of a Mode-EndMode entry of a Monitor or
+ *    Modes section to the configuration file.
+ */
+#if !defined(SMI_FBCONFIG)
+static
+#endif
+void
+xf86printMxxxSectionModeDotClock(
+	FILE *cf, XF86ConfModeLinePtr mlptr, const char *const whitespace[])
+{
+	xf86printFields(cf, whitespace, "DotClock", NULL);
+	fprintf(cf, "%2.4f\n", mlptr->ml_clock/1000.0);
+}
+
+
+/*
+ * xf86printMxxxSectionModeHTimings()
+ *
+ *    Write the HTimings line of a Mode-EndMode entry of a Monitor or
+ *    Modes section to the configuration file.
+ */
+#if !defined(SMI_FBCONFIG)
+static
+#endif
+void
+xf86printMxxxSectionModeHTimings(
+	FILE *cf, XF86ConfModeLinePtr mlptr, const char *const whitespace[])
+{
+	xf86printFields(cf, whitespace, "HTimings", NULL);
+	fprintf(cf, "%d %d %d %d\n",
+			mlptr->ml_hdisplay,
+			mlptr->ml_hsyncstart,
+			mlptr->ml_hsyncend,
+			mlptr->ml_htotal);
+}
+
+
+/*
+ * xf86printMxxxSectionModeVTimings()
+ *
+ *    Write the VTimings line of a Mode-EndMode entry of a Monitor or
+ *    Modes section to the configuration file.
+ */
+#if !defined(SMI_FBCONFIG)
+static
+#endif
+void
+xf86printMxxxSectionModeVTimings(
+	FILE *cf, XF86ConfModeLinePtr mlptr, const char *const whitespace[])
+{
+	xf86printFields(cf, whitespace, "VTimings", NULL);
+	fprintf(cf, "%d %d %d %d\n",
+			mlptr->ml_vdisplay,
+			mlptr->ml_vsyncstart,
+			mlptr->ml_vsyncend,
+			mlptr->ml_vtotal);
+}
+
+
+/*
+ * xf86printMxxxSectionModeFlags()
+ *
+ *    Write the Flags line of a Mode-EndMode entry of a Monitor or Modes
+ *    section to the configuration file.
+ */
+#if !defined(SMI_FBCONFIG)
+static
+#endif
+void
+xf86printMxxxSectionModeFlags(
+	FILE *cf, XF86ConfModeLinePtr mlptr, const char *const whitespace[])
+{
+	int		have_flags;	/* TRUE => Flags printed */
+	int		i;		/* Loop counter / array index */
+
+	have_flags = FALSE;
+	for (i = 0; modeFlagTab[i].name != NULL; i += 1) {
+		if (mlptr->ml_flags & modeFlagTab[i].mask) {
+			if (!have_flags) {
+				xf86printFields(cf, whitespace, "Flags", NULL);
+				have_flags = TRUE;
+			} else {
+				fputc(' ', cf);
+			}
+			fprintf(cf, "\"%s\"", modeFlagTab[i].name);
+		}
+	}
+	if (have_flags) {
+		fputc('\n', cf);
+	}
+}
+
+
+/*
+ * xf86printMxxxSectionModeHSkew()
+ *
+ *    Write the HSkew line of a Mode-EndMode entry of a Monitor or Modes
+ *    section to the configuration file.
+ */
+#if !defined(SMI_FBCONFIG)
+static
+#endif
+void
+xf86printMxxxSectionModeHSkew(
+	FILE *cf, XF86ConfModeLinePtr mlptr, const char *const whitespace[])
+{
+	xf86printFields(cf, whitespace, "HSkew", NULL);
+	fprintf(cf, " %d\n", mlptr->ml_hskew);
+}
+
+
+/*
+ * xf86printMxxxSectionModeVScan()
+ *
+ *    Write the VScan line of a Mode-EndMode entry of a Monitor or Modes
+ *    section to the configuration file.
+ */
+#if !defined(SMI_FBCONFIG)
+static
+#endif
+void
+xf86printMxxxSectionModeVScan(
+	FILE *cf, XF86ConfModeLinePtr mlptr, const char *const whitespace[])
+{
+	xf86printFields(cf, whitespace, "VScan", NULL);
+	fprintf(cf, " %d\n", mlptr->ml_vscan);
+}
+
+
+/*
+ * xf86printMxxxSectionMode()
+ *
+ *    Write the Mode-EndMode entry lines of a Monitor or Modes section
+ *    to the configuration file.
+ */
+#if !defined(SMI_FBCONFIG)
+static
+#endif
+void
+xf86printMxxxSectionMode(
+	FILE *cf, XF86ConfModeLinePtr mlptr,
+	const char *const whitespace_a[], const char *const whitespace_b[])
+{
+	xf86printFields(cf, whitespace_a, "Mode", NULL);
+	fprintf(cf, "\"%s\"\n", mlptr->ml_identifier);
+	xf86printMxxxSectionModeDotClock(cf, mlptr, whitespace_b);
+	xf86printMxxxSectionModeHTimings(cf, mlptr, whitespace_b);
+	xf86printMxxxSectionModeVTimings(cf, mlptr, whitespace_b);
+	xf86printMxxxSectionModeFlags(cf, mlptr, whitespace_b);
+	if (mlptr->ml_flags & XF86CONF_HSKEW) {
+		xf86printMxxxSectionModeHSkew(cf, mlptr, whitespace_b);
+	}
+	if (mlptr->ml_flags & XF86CONF_VSCAN) {
+		xf86printMxxxSectionModeVScan(cf, mlptr, whitespace_b);
+	}
+	xf86printFields(cf, whitespace_a, "EndMode\n", NULL);
+}
+
+
+/*
+ * xf86printMxxxSectionModeLine()
+ *
+ *    Write a ModeLine entry of a Monitor or Modes section to the
+ *    configuration file.
+ */
+#if !defined(SMI_FBCONFIG)
+static
+#endif
+void
+xf86printMxxxSectionModeLine(
+	FILE *cf, XF86ConfModeLinePtr mlptr, const char *const whitespace[])
+{
+	int		i;		/* Loop counter / array index */
+
+	/* ModeLine entry name w/ whitespace fields */
+	xf86printFields(cf, whitespace, "ModeLine", NULL);
+
+	/* Identifier, DotClock */
+	fprintf(cf, "\"%s\" %2.1f",
+			mlptr->ml_identifier, mlptr->ml_clock / 1000.0);
+
+	/* HTimings */
+	fprintf(cf, " %d %d %d %d",
+			mlptr->ml_hdisplay, mlptr->ml_hsyncstart,
+			mlptr->ml_hsyncend, mlptr->ml_htotal);
+
+	/* VTimings */
+	fprintf(cf, " %d %d %d %d",
+			mlptr->ml_vdisplay, mlptr->ml_vsyncstart,
+			mlptr->ml_vsyncend, mlptr->ml_vtotal);
+
+	/* Flags */
+	for (i = 0; modeFlagTab[i].name != NULL; i += 1) {
+		if (mlptr->ml_flags & modeFlagTab[i].mask) {
+			fprintf(cf, " %s", modeFlagTab[i].name);
+		}
+	}
+
+	/* HSkew */
+	if (mlptr->ml_hskew != 0) {
+		fprintf(cf, " HSkew %d", mlptr->ml_hskew);
+	}
+
+	/* VScan */
+	if (mlptr->ml_vscan != 0) {
+		fprintf(cf, " VScan %d", mlptr->ml_vscan);
+	}
+
+	/* Comment (if any) and line terminator */
+	if (mlptr->ml_comment) {
+		fprintf(cf, "%s", mlptr->ml_comment);
+	} else {
+		fprintf(cf, "\n");
+	}
+}
+
+
+/*
+ * xf86printMonitorSection()
+ *
+ *    Write a Monitor section to the configuration file.
+ */
+void
+xf86printMonitorSection (FILE * cf, XF86ConfMonitorPtr ptr)
+{
+	int i;
+	XF86ConfModeLinePtr mlptr;	/* Ptr to ModeLine / Mode entry */
+	XF86ConfModesLinkPtr mptr;	/* Ptr to UseModes entry */
+
+	while (ptr)
+	{
+		mptr = ptr->mon_modes_sect_lst;
+
+		xf86printMonitorSectionSection(cf, ptr, xf86whitespace_0);
+		if (ptr->mon_identifier) {
+			xf86printMonitorSectionIdentifier(
+						cf, ptr, xf86whitespace_1);
+		}
+		if (ptr->mon_vendor)
+			fprintf (cf, "\tVendorName   \"%s\"\n", ptr->mon_vendor);
+		if (ptr->mon_modelname)
+			fprintf (cf, "\tModelName    \"%s\"\n", ptr->mon_modelname);
+		while (mptr) {
+			xf86printMonitorSectionUseModes(cf, mptr, xf86whitespace_1);
+			mptr = mptr->list.next;
+		}
+		if (ptr->mon_width)
+			fprintf (cf, "\tDisplaySize  %d\t%d\n",
+					 ptr->mon_width,
+					 ptr->mon_height);
+		if ( ptr->mon_n_hsync || ptr->mon_n_vrefresh )
+		    fprintf(cf," ### Comment all HorizSync and VertRefresh values to use DDC:\n");
+		for (i = 0; i < ptr->mon_n_hsync; i++)
+		{
+			fprintf (cf, "\tHorizSync    %2.1f - %2.1f\n",
+					 ptr->mon_hsync[i].lo,
+					 ptr->mon_hsync[i].hi);
+		}
+		for (i = 0; i < ptr->mon_n_vrefresh; i++)
+		{
+			fprintf (cf, "\tVertRefresh  %2.1f - %2.1f\n",
+					 ptr->mon_vrefresh[i].lo,
+					 ptr->mon_vrefresh[i].hi);
+		}
+		if (ptr->mon_gamma_red) {
+			xf86printMonitorSectionGamma(cf, ptr, xf86whitespace_1);
+		}
+		for (mlptr = ptr->mon_modeline_lst; mlptr; mlptr = mlptr->list.next)
+		{
+			if (mlptr->ml_verbose) {
+				xf86printMxxxSectionMode(
+					cf, mlptr, xf86whitespace_1, xf86whitespace_2);
+			} else {
+				xf86printMxxxSectionModeLine(
+					cf, mlptr, xf86whitespace_1);
+			}
+		}
+		xf86printOptionList(cf, ptr->mon_option_lst, xf86whitespace_1);
+		xf86printMonitorSectionEndSection(cf, ptr, xf86whitespace_0);
+		fprintf (cf, "\n");
+		ptr = ptr->list.next;
+	}
+}
+
+void
+xf86printModesSection (FILE * cf, XF86ConfModesPtr ptr)
+{
+	XF86ConfModeLinePtr mlptr;
+
+	while (ptr)
+	{
+		fprintf (cf, "Section \"Modes\"\n");
+		if (ptr->modes_comment)
+			fprintf (cf, "%s", ptr->modes_comment);
+		if (ptr->modes_identifier)
+			fprintf (cf, "\tIdentifier     \"%s\"\n", ptr->modes_identifier);
+		for (mlptr = ptr->mon_modeline_lst; mlptr; mlptr = mlptr->list.next)
+		{
+			if (mlptr->ml_verbose) {
+				xf86printMxxxSectionMode(
+					cf, mlptr, xf86whitespace_1, xf86whitespace_2);
+			} else {
+				xf86printMxxxSectionModeLine(
+					cf, mlptr, xf86whitespace_1);
+			}
+		}
+		fprintf (cf, "EndSection\n\n");
+		ptr = ptr->list.next;
+	}
+}
+
+void
+xf86freeMonitorList (XF86ConfMonitorPtr ptr)
+{
+	XF86ConfMonitorPtr prev;
+
+	while (ptr)
+	{
+		TestFree (ptr->mon_identifier);
+		TestFree (ptr->mon_vendor);
+		TestFree (ptr->mon_modelname);
+		TestFree (ptr->mon_comment);
+		xf86optionListFree (ptr->mon_option_lst);
+		xf86freeModeLineList (ptr->mon_modeline_lst);
+		prev = ptr;
+		ptr = ptr->list.next;
+		xf86conffree (prev);
+	}
+}
+
+void
+xf86freeModesList (XF86ConfModesPtr ptr)
+{
+	XF86ConfModesPtr prev;
+
+	while (ptr)
+	{
+		TestFree (ptr->modes_identifier);
+		TestFree (ptr->modes_comment);
+		xf86freeModeLineList (ptr->mon_modeline_lst);
+		prev = ptr;
+		ptr = ptr->list.next;
+		xf86conffree (prev);
+	}
+}
+
+void
+xf86freeModeLineList (XF86ConfModeLinePtr ptr)
+{
+	XF86ConfModeLinePtr prev;
+	while (ptr)
+	{
+		TestFree (ptr->ml_identifier);
+		TestFree (ptr->ml_comment);
+		prev = ptr;
+		ptr = ptr->list.next;
+		xf86conffree (prev);
+	}
+}
+
+XF86ConfMonitorPtr
+xf86findMonitor (const char *ident, XF86ConfMonitorPtr p)
+{
+	while (p)
+	{
+		if (xf86nameCompare (ident, p->mon_identifier) == 0)
+			return (p);
+
+		p = p->list.next;
+	}
+	return (NULL);
+}
+
+/*
+ * xf86findModes()
+ *
+ *    Given the name of a Modes section, search the list of Modes
+ *    sections and return a pointer to the matching section.  Return
+ *    NULL if no Modes section has that name.
+ */
+XF86ConfModesPtr
+xf86findModes (const char *ident, XF86ConfModesPtr p)
+{
+	while (p)
+	{
+		if (xf86nameCompare (ident, p->modes_identifier) == 0)
+			return (p);
+
+		p = p->list.next;
+	}
+	return (NULL);
+}
+
+/*
+ * xf86findModeLine()
+ *
+ *    Given the name of a ModeLine / Mode-EndMode entry and a list of
+ *    entries from a Monitor or Modes section, search the list of
+ *    entries and return a pointer to the matching entry.  Return NULL
+ *    if no ModeLine / Mode-EndMode entry in the section has that name.
+ */
+XF86ConfModeLinePtr
+xf86findModeLine (const char *ident, XF86ConfModeLinePtr p)
+{
+	while (p)
+	{
+		if (xf86nameCompare (ident, p->ml_identifier) == 0)
+			return (p);
+
+		p = p->list.next;
+	}
+	return (NULL);
+}
+
+/*
+ * xf86validateMonitor()
+ *
+ *    Validate a Monitor section that is referenced by the specified
+ *    Screen section.  Validation of a Monitor section consists of
+ *    making sure that every UseModes entry in the section specifies the
+ *    name of an existing Modes section.  A link is also created from
+ *    each UseModes entry to the matching Modes section.  Return TRUE
+ *    iff successful.
+ */
+int
+xf86validateMonitor(
+	XF86ConfigPtr	p,		/* Ptr to configuration stuff */
+	const char *const screen_identifier, /* Name of Screen section */
+	XF86ConfMonitorPtr monitor)	/* Monitor section to validate */
+{
+	XF86ConfModesLinkPtr modeslnk;
+	XF86ConfModesPtr modes;
+
+	for (modeslnk = monitor->mon_modes_sect_lst;
+		modeslnk != NULL;
+		modeslnk = modeslnk->list.next) {
+
+		modes = xf86findModes (modeslnk->ml_modes_str, p->conf_modes_lst);
+		if (!modes)
+		{
+			xf86validationError (UNDEFINED_MODES_MSG, 
+						modeslnk->ml_modes_str, 
+						screen_identifier);
+			return (FALSE);
+		}
+		modeslnk->ml_modes = modes;
+	}
+	return (TRUE);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Pointer.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,237 @@
+/* 
+ * 
+ * Copyright (c) 1997  Metro Link Incorporated
+ * 
+ * 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
+ * THE X CONSORTIUM 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.
+ * 
+ * Except as contained in this notice, the name of the Metro Link shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Metro Link.
+ * 
+ */
+/*
+ * Copyright (c) 1997-2003 by The XFree86 Project, 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
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+
+/* View/edit this file with tab stops set to 4 */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "Configint.h"
+
+extern LexRec val;
+
+static xf86ConfigSymTabRec PointerTab[] =
+{
+	{PROTOCOL, "protocol"},
+	{EMULATE3, "emulate3buttons"},
+	{EM3TIMEOUT, "emulate3timeout"},
+	{ENDSUBSECTION, "endsubsection"},
+	{ENDSECTION, "endsection"},
+	{PDEVICE, "device"},
+	{PDEVICE, "port"},
+	{BAUDRATE, "baudrate"},
+	{SAMPLERATE, "samplerate"},
+	{CLEARDTR, "cleardtr"},
+	{CLEARRTS, "clearrts"},
+	{CHORDMIDDLE, "chordmiddle"},
+	{PRESOLUTION, "resolution"},
+	{DEVICE_NAME, "devicename"},
+	{ALWAYSCORE, "alwayscore"},
+	{PBUTTONS, "buttons"},
+	{ZAXISMAPPING, "zaxismapping"},
+	{-1, ""},
+};
+
+static xf86ConfigSymTabRec ZMapTab[] =
+{
+	{XAXIS, "x"},
+	{YAXIS, "y"},
+	{-1, ""},
+};
+
+#define CLEANUP xf86freeInputList
+
+XF86ConfInputPtr
+xf86parsePointerSection (void)
+{
+	char *s, *s1, *s2;
+	int l;
+	int token;
+	parsePrologue (XF86ConfInputPtr, XF86ConfInputRec)
+
+	while ((token = xf86getToken (PointerTab)) != ENDSECTION)
+	{
+		switch (token)
+		{
+		case COMMENT:
+			ptr->inp_comment = xf86addComment(ptr->inp_comment, val.str);
+			break;
+		case PROTOCOL:
+			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
+				Error (QUOTE_MSG, "Protocol");
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("Protocol"),
+												val.str);
+			break;
+		case PDEVICE:
+			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
+				Error (QUOTE_MSG, "Device");
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("Device"),
+												val.str);
+			break;
+		case EMULATE3:
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("Emulate3Buttons"),
+												NULL);
+			break;
+		case EM3TIMEOUT:
+			if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0)
+				Error (POSITIVE_INT_MSG, "Emulate3Timeout");
+			s = xf86uLongToString(val.num);
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("Emulate3Timeout"),
+												s);
+			break;
+		case CHORDMIDDLE:
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("ChordMiddle"),
+												NULL);
+			break;
+		case PBUTTONS:
+			if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0)
+				Error (POSITIVE_INT_MSG, "Buttons");
+			s = xf86uLongToString(val.num);
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("Buttons"), s);
+			break;
+		case BAUDRATE:
+			if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0)
+				Error (POSITIVE_INT_MSG, "BaudRate");
+			s = xf86uLongToString(val.num);
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("BaudRate"), s);
+			break;
+		case SAMPLERATE:
+			if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0)
+				Error (POSITIVE_INT_MSG, "SampleRate");
+			s = xf86uLongToString(val.num);
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("SampleRate"), s);
+			break;
+		case PRESOLUTION:
+			if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0)
+				Error (POSITIVE_INT_MSG, "Resolution");
+			s = xf86uLongToString(val.num);
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("Resolution"), s);
+			break;
+		case CLEARDTR:
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("ClearDTR"), NULL);
+			break;
+		case CLEARRTS:
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("ClearRTS"), NULL);
+			break;
+		case ZAXISMAPPING:
+			switch (xf86getToken(ZMapTab)) {
+			case NUMBER:
+				if (val.num < 0)
+					Error (ZAXISMAPPING_MSG, NULL);
+				s1 = xf86uLongToString(val.num);
+				if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0) {
+					xf86conffree(s1);
+					Error (ZAXISMAPPING_MSG, NULL);
+				}
+				s2 = xf86uLongToString(val.num);
+				l = strlen(s1) + 1 + strlen(s2) + 1;
+				s = xf86confmalloc(l);
+				sprintf(s, "%s %s", s1, s2);
+				xf86conffree(s1);
+				xf86conffree(s2);
+				break;
+			case XAXIS:
+				s = xf86configStrdup("x");
+				break;
+			case YAXIS:
+				s = xf86configStrdup("y");
+				break;
+			default:
+				Error (ZAXISMAPPING_MSG, NULL);
+				break;
+			}
+			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+												xf86configStrdup("ZAxisMapping"),
+												s);
+			break;
+		case ALWAYSCORE:
+			break;
+		case EOF_TOKEN:
+			Error (UNEXPECTED_EOF_MSG, NULL);
+			break;
+		default:
+			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
+			break;
+		}
+	}
+
+	ptr->inp_identifier = xf86configStrdup(CONF_IMPLICIT_POINTER);
+	ptr->inp_driver = xf86configStrdup("mouse");
+	ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
+										xf86configStrdup("CorePointer"), NULL);
+
+#ifdef DEBUG
+	printf ("Pointer section parsed\n");
+#endif
+
+	return ptr;
+}
+
+#undef CLEANUP
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Screen.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,997 @@
+/* 
+ * 
+ * Copyright (c) 1997  Metro Link Incorporated
+ * 
+ * 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
+ * THE X CONSORTIUM 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.
+ * 
+ * Except as contained in this notice, the name of the Metro Link shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Metro Link.
+ * 
+ */
+/*
+ * Copyright (c) 1997-2003 by The XFree86 Project, 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
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+/* View/edit this file with tab stops set to 4 */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "Configint.h"
+#include "fields.h"		/* Config file output line fields */
+
+#if defined(SMI_FBCONFIG)
+#include "fbc_line_er.h"	/* External Representation of config lines */
+#endif
+
+extern LexRec val;
+
+static xf86ConfigSymTabRec DisplayTab[] =
+{
+	{ENDSUBSECTION, "endsubsection"},
+	{MODES, "modes"},
+	{VIEWPORT, "viewport"},
+	{VIRTUAL, "virtual"},
+	{VISUAL, "visual"},
+	{BLACK_TOK, "black"},
+	{WHITE_TOK, "white"},
+	{MONITOR, "monitor"},
+	{DEPTH, "depth"},
+	{BPP, "fbbpp"},
+	{WEIGHT, "weight"},
+	{OPTION, "option"},
+	{-1, ""},
+};
+
+
+/*
+ * xf86parseScrnMonitor()
+ *
+ *    Parse the Monitor entry line of a Screen section.  Return a
+ *    pointer to the diagnostic message text in the event of an error.
+ */
+static
+char *
+xf86parseScrnMonitor(
+	XF86ConfScreenPtr ptr)		/* Ptr to Screen section structure */
+{
+	XF86ConfScrnMonitorEntryRec mon_entry; /* Temp Monitor entry element */
+	XF86ConfScrnMonitorEntryPtr mon_ptr; /* Ptr to Monitor list element */
+	int		token;		/* Monitor entry token ID */
+
+	/*
+	 * Look for the optional monitor number token
+	 */
+	mon_entry.scrn_monitor_num_seen = FALSE;
+	mon_entry.scrn_monitor_num      = 0;
+	token = xf86getSubToken(&(ptr->scrn_comment));
+	if (token == NUMBER) {
+		mon_entry.scrn_monitor_num_seen = TRUE;
+		mon_entry.scrn_monitor_num      = val.num;
+		token = xf86getSubToken(&(ptr->scrn_comment));
+	}
+
+	/*
+	 * Look for the monitor name string token
+	 */
+	if (token != STRING) {
+		/* Monitor entry syntax error */
+		return (MONITOR_SYNTAX_MSG);
+	}
+	mon_entry.scrn_monitor_name = val.str;
+
+	/*
+	 * Don't allow:
+	 *     * Monitor numbers to be omitted when there are muliple
+	 *       Monitor entries
+	 *     * Duplicate Monitor numbers
+	 *     * Duplicate Monitor names
+	 */
+	for (mon_ptr = ptr->scrn_monitor_lst;
+		mon_ptr != NULL;
+		mon_ptr = (XF86ConfScrnMonitorEntryPtr)mon_ptr->list.next) {
+
+		if (!mon_entry.scrn_monitor_num_seen ||
+					!mon_ptr->scrn_monitor_num_seen) {
+			/* Missing monitor number */
+			return (MONITOR_NUM_REQUIRED_MSG);
+		}
+		if (mon_entry.scrn_monitor_num ==
+					mon_ptr->scrn_monitor_num) {
+			/* Duplicate monitor number */
+			return (MONITOR_DUP_NUM_MSG);
+		}
+		if (xf86nameCompare(mon_entry.scrn_monitor_name,
+					mon_ptr->scrn_monitor_name) == 0) {
+			/* Duplicate monitor name */
+			return (MONITOR_DUP_NAME_MSG);
+		}
+	}
+
+	/*
+	 * Append the new Monitor entry element to the list
+	 */
+	mon_ptr = xf86confcalloc(1, sizeof (XF86ConfScrnMonitorEntryRec));
+	if (mon_ptr == NULL) {
+		/* Insufficient memory */
+		return (NO_MEMORY_MSG);
+	}
+	mon_ptr->list.next             = NULL;
+	mon_ptr->scrn_monitor_num_seen = mon_entry.scrn_monitor_num_seen;
+	mon_ptr->scrn_monitor_num      = mon_entry.scrn_monitor_num;
+	mon_ptr->scrn_monitor_name     = mon_entry.scrn_monitor_name;
+	mon_ptr->scrn_monitor          = NULL;
+	ptr->scrn_monitor_lst = (XF86ConfScrnMonitorEntryPtr)xf86addListItem(
+						(glp)ptr->scrn_monitor_lst,
+						(glp)mon_ptr);
+
+	/*
+	 * Return successfully
+	 */
+	return (NULL);
+
+}
+
+
+#define CLEANUP xf86freeDisplayList
+
+XF86ConfDisplayPtr
+xf86parseDisplaySubSection (void)
+{
+	int token;
+#if defined(SMI_FBCONFIG)
+	void *line_er;		/* Ptr to Extnl Rep of config file line */
+#endif
+	parsePrologue (XF86ConfDisplayPtr, XF86ConfDisplayRec)
+
+	ptr->disp_monitor_seen = FALSE;
+
+	ptr->disp_black.red = ptr->disp_black.green = ptr->disp_black.blue = -1;
+	ptr->disp_white.red = ptr->disp_white.green = ptr->disp_white.blue = -1;
+	ptr->disp_frameX0 = ptr->disp_frameY0 = -1;
+	for (;;)
+	{
+		token = xf86getToken(DisplayTab);
+
+#if defined(SMI_FBCONFIG)
+		/*
+		 * Get a ptr to the External Representation of this config line
+		 */
+		line_er = fbc_get_current_line_ER();
+
+#endif
+		if (token == ENDSUBSECTION)
+		{
+			break;
+		}
+		switch (token)
+		{
+		case COMMENT:
+			ptr->disp_comment = xf86addComment(ptr->disp_comment, val.str);
+			break;
+		case VIEWPORT:
+			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
+				Error (VIEWPORT_MSG, NULL);
+			ptr->disp_frameX0 = val.num;
+			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
+				Error (VIEWPORT_MSG, NULL);
+			ptr->disp_frameY0 = val.num;
+			break;
+		case VIRTUAL:
+			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
+				Error (VIRTUAL_MSG, NULL);
+			ptr->disp_virtualX = val.num;
+			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
+				Error (VIRTUAL_MSG, NULL);
+			ptr->disp_virtualY = val.num;
+			break;
+		case MONITOR:
+			if (ptr->disp_monitor_seen ||
+				(xf86getSubToken(&(ptr->disp_comment)) != NUMBER)) {
+					Error (NUMBER_MSG, "Display");
+			}
+			ptr->disp_monitor_seen = TRUE;
+			ptr->disp_monitor_num  = val.num;
+			break;
+		case DEPTH:
+			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
+				Error (NUMBER_MSG, "Display");
+			ptr->disp_depth = val.num;
+			break;
+		case BPP:
+			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
+				Error (NUMBER_MSG, "Display");
+			ptr->disp_bpp = val.num;
+			break;
+		case VISUAL:
+			if (xf86getSubToken (&(ptr->disp_comment)) != STRING)
+				Error (QUOTE_MSG, "Display");
+			ptr->disp_visual = val.str;
+			break;
+		case WEIGHT:
+			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
+				Error (WEIGHT_MSG, NULL);
+			ptr->disp_weight.red = val.num;
+			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
+				Error (WEIGHT_MSG, NULL);
+			ptr->disp_weight.green = val.num;
+			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
+				Error (WEIGHT_MSG, NULL);
+			ptr->disp_weight.blue = val.num;
+			break;
+		case BLACK_TOK:
+			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
+				Error (BLACK_MSG, NULL);
+			ptr->disp_black.red = val.num;
+			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
+				Error (BLACK_MSG, NULL);
+			ptr->disp_black.green = val.num;
+			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
+				Error (BLACK_MSG, NULL);
+			ptr->disp_black.blue = val.num;
+			break;
+		case WHITE_TOK:
+			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
+				Error (WHITE_MSG, NULL);
+			ptr->disp_white.red = val.num;
+			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
+				Error (WHITE_MSG, NULL);
+			ptr->disp_white.green = val.num;
+			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
+				Error (WHITE_MSG, NULL);
+			ptr->disp_white.blue = val.num;
+			break;
+		case MODES:
+			{
+				XF86ModePtr mptr;
+
+				while ((token = xf86getSubTokenWithTab (&(ptr->disp_comment), DisplayTab)) == STRING)
+				{
+					mptr = xf86confcalloc (1, sizeof (XF86ModeRec));
+					mptr->mode_name = val.str;
+					mptr->list.next = NULL;
+					ptr->disp_mode_lst = (XF86ModePtr)
+						xf86addListItem ((glp) ptr->disp_mode_lst, (glp) mptr);
+				}
+				xf86unGetToken (token);
+			}
+#if defined(SMI_FBCONFIG)
+			/*
+			 * Link Internal & External Representations of the line
+			 */
+			ptr->disp_modes_line_er = line_er;
+			fbc_link_line_ER(line_er,
+					(void *)ptr,
+					(xf86_print_fn_t *)&xf86printDisplaySubsectionModes,
+					FBC_INDENT_2);
+#endif
+			break;
+		case OPTION:
+			ptr->disp_option_lst = xf86parseOption(ptr->disp_option_lst);
+			break;
+			
+		case EOF_TOKEN:
+			Error (UNEXPECTED_EOF_MSG, NULL);
+			break;
+		default:
+			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
+			break;
+		}
+	}
+
+#if defined(SMI_FBCONFIG)
+	/*
+	 * Link Internal & External Representations of the EndSubSection line
+	 */
+	ptr->disp_end_line_er = line_er;
+	fbc_link_line_ER(line_er,
+			(void *)ptr,
+			(xf86_print_fn_t *)&xf86printDisplaySubsectionEndSubsection,
+			FBC_INDENT_1);
+
+#endif
+#ifdef DEBUG
+	printf ("Display subsection parsed\n");
+#endif
+
+	return ptr;
+}
+
+#undef CLEANUP
+
+static xf86ConfigSymTabRec ScreenTab[] =
+{
+	{ENDSECTION, "endsection"},
+	{IDENTIFIER, "identifier"},
+	{OBSDRIVER, "driver"},
+	{MDEVICE, "device"},
+	{MONITOR, "monitor"},
+	{VIDEOADAPTOR, "videoadaptor"},
+	{SCREENNO, "screenno"},
+	{SUBSECTION, "subsection"},
+	{DEFAULTDEPTH, "defaultcolordepth"},
+	{DEFAULTDEPTH, "defaultdepth"},
+	{DEFAULTBPP, "defaultbpp"},
+	{DEFAULTFBBPP, "defaultfbbpp"},
+	{OPTION, "option"},
+	{-1, ""},
+};
+
+#define CLEANUP xf86freeScreenList
+XF86ConfScreenPtr
+xf86parseScreenSection (void)
+{
+	int has_ident = FALSE;
+	int has_driver= FALSE;
+	int token;
+#if defined(SMI_FBCONFIG)
+	void *line_er;		/* Ptr to Extnl Rep of config file line */
+#endif
+	parsePrologue (XF86ConfScreenPtr, XF86ConfScreenRec)
+
+	for (;;)
+	{
+		token = xf86getToken(ScreenTab);
+#if defined(SMI_FBCONFIG)
+		/*
+		 * Get a ptr to the External Representation of this config line
+		 */
+		line_er = fbc_get_current_line_ER();
+
+#endif
+		if (token == ENDSECTION)
+		{
+			break;
+		}
+		switch (token)
+		{
+		case COMMENT:
+			ptr->scrn_comment = xf86addComment(ptr->scrn_comment, val.str);
+			break;
+		case IDENTIFIER:
+			if (xf86getSubToken (&(ptr->scrn_comment)) != STRING)
+				Error (QUOTE_MSG, "Identifier");
+			ptr->scrn_identifier = val.str;
+			if (has_ident || has_driver)
+				Error (ONLY_ONE_MSG,"Identifier or Driver");
+			has_ident = TRUE;
+			break;
+		case OBSDRIVER:
+			if (xf86getSubToken (&(ptr->scrn_comment)) != STRING)
+				Error (QUOTE_MSG, "Driver");
+			ptr->scrn_obso_driver = val.str;
+			if (has_ident || has_driver)
+				Error (ONLY_ONE_MSG,"Identifier or Driver");
+			has_driver = TRUE;
+			break;
+		case DEFAULTDEPTH:
+			if (xf86getSubToken (&(ptr->scrn_comment)) != NUMBER)
+				Error (NUMBER_MSG, "DefaultDepth");
+			ptr->scrn_defaultdepth = val.num;
+#if defined(SMI_FBCONFIG)
+			/*
+			 * Link Internal & External Representations of the line
+			 */
+			ptr->scrn_defaultdepth_line_er = line_er;
+			fbc_link_line_ER(line_er,
+					(void *)ptr,
+					(xf86_print_fn_t *)&xf86printScreenSectionDefaultDepth,
+					FBC_INDENT_1);
+#endif
+			break;
+		case DEFAULTBPP:
+			if (xf86getSubToken (&(ptr->scrn_comment)) != NUMBER)
+				Error (NUMBER_MSG, "DefaultBPP");
+			ptr->scrn_defaultbpp = val.num;
+			break;
+		case DEFAULTFBBPP:
+			if (xf86getSubToken (&(ptr->scrn_comment)) != NUMBER)
+				Error (NUMBER_MSG, "DefaultFbBPP");
+			ptr->scrn_defaultfbbpp = val.num;
+			break;
+		case MDEVICE:
+			if (xf86getSubToken (&(ptr->scrn_comment)) != STRING)
+				Error (QUOTE_MSG, "Device");
+			if (ptr->scrn_device_str != NULL) {
+				Error (MULTIPLE_MSG, "Device");
+			}
+			ptr->scrn_device_str = val.str;
+			break;
+		case MONITOR:
+			{
+				char *error_msg;
+				error_msg = xf86parseScrnMonitor(ptr);
+				if (error_msg != NULL) {
+					Error (error_msg, NULL);
+				}
+			}
+			break;
+		case VIDEOADAPTOR:
+			{
+				XF86ConfAdaptorLinkPtr aptr;
+
+				if (xf86getSubToken (&(ptr->scrn_comment)) != STRING)
+					Error (QUOTE_MSG, "VideoAdaptor");
+
+				/* Don't allow duplicates */
+				for (aptr = ptr->scrn_adaptor_lst; aptr; 
+					aptr = (XF86ConfAdaptorLinkPtr) aptr->list.next)
+					if (xf86nameCompare (val.str, aptr->al_adaptor_str) == 0)
+						break;
+
+				if (aptr == NULL)
+				{
+					aptr = xf86confcalloc (1, sizeof (XF86ConfAdaptorLinkRec));
+					aptr->list.next = NULL;
+					aptr->al_adaptor_str = val.str;
+					ptr->scrn_adaptor_lst = (XF86ConfAdaptorLinkPtr)
+						xf86addListItem ((glp) ptr->scrn_adaptor_lst, (glp) aptr);
+				}
+			}
+			break;
+		case OPTION:
+			ptr->scrn_option_lst = xf86parseOption(ptr->scrn_option_lst);
+			break;
+		case SUBSECTION:
+			if (xf86getSubToken (&(ptr->scrn_comment)) != STRING)
+				Error (QUOTE_MSG, "SubSection");
+			{
+				xf86conffree(val.str);
+				HANDLE_LIST (scrn_display_lst, xf86parseDisplaySubSection,
+							 XF86ConfDisplayPtr);
+			}
+			break;
+		case EOF_TOKEN:
+			Error (UNEXPECTED_EOF_MSG, NULL);
+			break;
+		default:
+			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
+			break;
+		}
+	}
+
+#if defined(SMI_FBCONFIG)
+	/*
+	 * Link Internal & External Representations of the EndSection line
+	 */
+	ptr->scrn_end_line_er = line_er;
+	fbc_link_line_ER(line_er,
+			(void *)ptr,
+			(xf86_print_fn_t *)&xf86printScreenSectionEndSection,
+			FBC_INDENT_0);
+
+#endif
+	if (!has_ident && !has_driver)
+		Error (NO_IDENT_MSG, NULL);
+
+#ifdef DEBUG
+	printf ("Screen section parsed\n");
+#endif
+
+	return ptr;
+}
+
+
+/*
+ * xf86printDisplaySubsectionSubsection()
+ *
+ *    Write the Display subsection Subsection line to the configuration
+ *    file.
+ */
+void
+xf86printDisplaySubsectionSubsection(
+	FILE		*cf,		/* Config file output stream */
+	XF86ConfDisplayPtr dptr,	/* Ptr to Display subsection */
+	const char *const whitespace[])
+{
+	fprintf(cf, "\tSubsection \"Display\"\n");
+	if (dptr->disp_comment != NULL) {
+		fprintf(cf, "%s", dptr->disp_comment);
+	}
+}
+
+
+/*
+ * xf86printDisplaySubectionMonitor()
+ *
+ *    Write a Display subsection Monitor entry line to the configuration
+ *    file.
+ */
+void
+xf86printDisplaySubsectionMonitor(
+	FILE		*cf,		/* Config file output stream */
+	XF86ConfDisplayPtr dptr,	/* Ptr to Display subsection */
+	const char *const whitespace[])
+{
+	xf86printFields(cf, whitespace, "Monitor", NULL);
+	fprintf(cf, "%d\n", dptr->disp_monitor_num);
+}
+
+
+/*
+ * xf86printDisplaySubsectionModes()
+ *
+ *    Write the Modes line of a Display subsection of a Screen section
+ *    to the configuration file.
+ */
+void
+xf86printDisplaySubsectionModes(
+	FILE		*cf,		/* Config file output stream */
+	XF86ConfDisplayPtr dptr,	/* Ptr to Display subsection */
+	const char *const whitespace[])
+{
+	XF86ModePtr	mptr;		/* Ptr to Modes name list element */
+	const char	*space;		/* Ptr to "" or " " separator */
+
+	xf86printFields(cf, whitespace, "Modes", NULL);
+	space = "";
+	for (mptr = dptr->disp_mode_lst; mptr != NULL; mptr = mptr->list.next)
+	{
+		fprintf(cf, "%s\"%s\"", space, mptr->mode_name);
+		space = " ";
+	}
+	fprintf(cf, "\n");
+}
+
+
+/*
+ * xf86printDisplaySubsectionEndSubsection()
+ *
+ *    Write the Display subsection EndSubsection line to the
+ *    configuration file.
+ */
+void
+xf86printDisplaySubsectionEndSubsection(
+	FILE		*cf,		/* Config file output stream */
+	XF86ConfDisplayPtr dptr,	/* Ptr to Display subsection */
+	const char *const whitespace[])
+{
+//???	xf86printFields(cf, whitespace, "EndSubsection\n", NULL);
+	fprintf (cf, "\tEndSubsection\n");
+}
+
+
+/*
+ * xf86printScreenSectionSection()
+ *
+ *    Write the Screen section Section line to the configuration file.
+ */
+void
+xf86printScreenSectionSection(
+	FILE * cf, XF86ConfScreenPtr ptr, const char *const whitespace[])
+{
+	fprintf (cf, "Section \"Screen\"\n");
+	if (ptr->scrn_comment != NULL) {
+		fprintf(cf, "%s", ptr->scrn_comment);
+	}
+}
+
+
+/*
+ * xf86printScreenSectionIdentifier()
+ *
+ *    Write the Screen section Identifier line to the configuration
+ *    file.
+ */
+void
+xf86printScreenSectionIdentifier(
+	FILE * cf, XF86ConfScreenPtr ptr, const char *const whitespace[])
+{
+/*???*/	xf86printFields(cf, whitespace, "Identifier", NULL);
+	fprintf(cf, "\"%s\"\n", ptr->scrn_identifier);
+}
+
+
+/*
+ * xf86printScreenSectionDevice()
+ *
+ *    Write the Screen section Device entry line to the configuration
+ *    file.
+ */
+void
+xf86printScreenSectionDevice(
+	FILE * cf, XF86ConfScreenPtr ptr, const char *const whitespace[])
+{
+	xf86printFields(cf, whitespace, "Device", NULL);
+	fprintf(cf, "\"%s\"\n", ptr->scrn_device_str);
+}
+
+
+/*
+ * xf86printScreenSectionMonitor()
+ *
+ *    Write a Screen section Monitor entry line to the configuration
+ *    file.
+ */
+void
+xf86printScreenSectionMonitor(
+	FILE		* cf,		/* Config file output stream */
+	XF86ConfScrnMonitorEntryPtr mon_ptr, /* Ptr to Monitor entry */
+	const char *const whitespace[])
+{
+	char		monitor_field[64]; /* "Monitor[ <num>]" */
+
+	sprintf(monitor_field,
+		(mon_ptr->scrn_monitor_num_seen) ? "Monitor %d" : "Monitor",
+		mon_ptr->scrn_monitor_num);
+	xf86printFields(cf, whitespace, monitor_field, NULL);
+	fprintf(cf, "\"%s\"\n", mon_ptr->scrn_monitor_name);
+}
+
+
+/*
+ * xf86printScreenSectionDefaultDepth()
+ *
+ *    Write a Screen section DefaultDepth entry to the configuration
+ *    file.
+ */
+void
+xf86printScreenSectionDefaultDepth(
+	FILE * cf, XF86ConfScreenPtr ptr, const char *const whitespace[])
+{
+	xf86printFields(cf, whitespace, "DefaultDepth", NULL);
+	fprintf(cf, "%d\n", ptr->scrn_defaultdepth);
+}
+
+
+/*
+ * xf86printScreenSectionEndSection()
+ *
+ *    Write the Screen section EndSection line to the configuration
+ *    file.
+ */
+void
+xf86printScreenSectionEndSection(
+	FILE * cf, XF86ConfScreenPtr ptr, const char *const whitespace[])
+{
+	fprintf (cf, "EndSection\n");
+}
+
+
+/*
+ * xf86printScreenSection()
+ *
+ *    Write a Screen section to the configuration file.
+ */
+void
+xf86printScreenSection (FILE * cf, XF86ConfScreenPtr ptr)
+{
+	XF86ConfAdaptorLinkPtr aptr;
+	XF86ConfDisplayPtr dptr;
+	XF86ConfScrnMonitorEntryPtr mon_ptr; /* Ptr to a Monitor element */
+
+	while (ptr)
+	{
+		xf86printScreenSectionSection(cf, ptr, xf86whitespace_0);
+		if (ptr->scrn_identifier) {
+			xf86printScreenSectionIdentifier(
+						cf, ptr, xf86whitespace_1);
+		}
+		if (ptr->scrn_obso_driver)
+			fprintf (cf, "\tDriver     \"%s\"\n", ptr->scrn_obso_driver);
+		if (ptr->scrn_device_str) {
+			xf86printScreenSectionDevice(
+						cf, ptr, xf86whitespace_1);
+		}
+		for (mon_ptr = ptr->scrn_monitor_lst;
+			mon_ptr != NULL;
+			mon_ptr = (XF86ConfScrnMonitorEntryPtr)mon_ptr->list.next) {
+			xf86printScreenSectionMonitor(cf, mon_ptr, xf86whitespace_1);
+		}
+		if (ptr->scrn_defaultdepth)
+			xf86printScreenSectionDefaultDepth(cf, ptr, xf86whitespace_1);
+		if (ptr->scrn_defaultbpp)
+			fprintf (cf, "\tDefaultBPP     %d\n",
+					 ptr->scrn_defaultbpp);
+		if (ptr->scrn_defaultfbbpp)
+			fprintf (cf, "\tDefaultFbBPP     %d\n",
+					 ptr->scrn_defaultfbbpp);
+		xf86printOptionList(cf, ptr->scrn_option_lst, xf86whitespace_1);
+		for (aptr = ptr->scrn_adaptor_lst; aptr; aptr = aptr->list.next)
+		{
+			fprintf (cf, "\tVideoAdaptor \"%s\"\n", aptr->al_adaptor_str);
+		}
+
+		/*
+		 * Write each Display subsection to the configuration file
+		 */
+		for (dptr = ptr->scrn_display_lst; dptr; dptr = dptr->list.next)
+		{
+			xf86printDisplaySubsectionSubsection(cf, dptr, xf86whitespace_1);
+			if (dptr->disp_monitor_seen) {
+				xf86printDisplaySubsectionMonitor(cf, dptr, xf86whitespace_1);
+			}
+
+			if (dptr->disp_frameX0 >= 0 || dptr->disp_frameY0 >= 0)
+			{
+				fprintf (cf, "\t\tViewport   %d %d\n",
+						 dptr->disp_frameX0, dptr->disp_frameY0);
+			}
+			if (dptr->disp_virtualX != 0 || dptr->disp_virtualY != 0)
+			{
+				fprintf (cf, "\t\tVirtual   %d %d\n",
+						 dptr->disp_virtualX, dptr->disp_virtualY);
+			}
+			if (dptr->disp_depth)
+			{
+				fprintf (cf, "\t\tDepth     %d\n", dptr->disp_depth);
+			}
+			if (dptr->disp_bpp)
+			{
+				fprintf (cf, "\t\tFbBPP     %d\n", dptr->disp_bpp);
+			}
+			if (dptr->disp_visual)
+			{
+				fprintf (cf, "\t\tVisual    \"%s\"\n", dptr->disp_visual);
+			}
+			if (dptr->disp_weight.red != 0)
+			{
+				fprintf (cf, "\t\tWeight    %d %d %d\n",
+					 dptr->disp_weight.red, dptr->disp_weight.green, dptr->disp_weight.blue);
+			}
+			if (dptr->disp_black.red != -1)
+			{
+				fprintf (cf, "\t\tBlack     0x%04x 0x%04x 0x%04x\n",
+					  dptr->disp_black.red, dptr->disp_black.green, dptr->disp_black.blue);
+			}
+			if (dptr->disp_white.red != -1)
+			{
+				fprintf (cf, "\t\tWhite     0x%04x 0x%04x 0x%04x\n",
+					  dptr->disp_white.red, dptr->disp_white.green, dptr->disp_white.blue);
+			}
+			if (dptr->disp_mode_lst != NULL)
+			{
+				xf86printDisplaySubsectionModes(cf, dptr, xf86whitespace_2);
+			}
+			xf86printOptionList(cf, dptr->disp_option_lst, xf86whitespace_2);
+			xf86printDisplaySubsectionEndSubsection(
+						cf, dptr, xf86whitespace_1);
+		}
+		xf86printScreenSectionEndSection(cf, ptr, xf86whitespace_0);
+		fprintf(cf, "\n");
+		ptr = ptr->list.next;
+	}
+
+}
+
+
+/*
+ * xf86freeScrnMonitorList()
+ *
+ *    Free the list of Monitor entries of a Screen section, and the
+ *    contents of each entry (i.e. Monitor section name string).
+ *
+ *    Note that xf86conffree() (aka free()) accepts NULL pointers.
+ */
+static
+void
+xf86freeScrnMonitorList(XF86ConfScrnMonitorEntryPtr mon_ptr)
+{
+	XF86ConfScrnMonitorEntryPtr next_mon_ptr;
+
+	for ( ; mon_ptr != NULL; mon_ptr = next_mon_ptr) {
+		next_mon_ptr = mon_ptr->list.next;
+		xf86conffree(mon_ptr->scrn_monitor_name);
+		xf86conffree(mon_ptr);
+	}
+}
+
+
+/*
+ * xf86freeScreenList()
+ *
+ *    Free the list of Screen sections, and the contents of each
+ *    section.
+ */
+void
+xf86freeScreenList (XF86ConfScreenPtr ptr)
+{
+	XF86ConfScreenPtr prev;
+
+	while (ptr)
+	{
+		TestFree (ptr->scrn_identifier);
+		TestFree (ptr->scrn_device_str);
+		TestFree (ptr->scrn_comment);
+		xf86optionListFree (ptr->scrn_option_lst);
+		xf86freeScrnMonitorList(ptr->scrn_monitor_lst);
+		xf86freeAdaptorLinkList (ptr->scrn_adaptor_lst);
+		xf86freeDisplayList (ptr->scrn_display_lst);
+		prev = ptr;
+		ptr = ptr->list.next;
+		xf86conffree (prev);
+	}
+}
+
+void
+xf86freeAdaptorLinkList (XF86ConfAdaptorLinkPtr ptr)
+{
+	XF86ConfAdaptorLinkPtr prev;
+
+	while (ptr)
+	{
+		TestFree (ptr->al_adaptor_str);
+		prev = ptr;
+		ptr = ptr->list.next;
+		xf86conffree (prev);
+	}
+}
+
+void
+xf86freeDisplayList (XF86ConfDisplayPtr ptr)
+{
+	XF86ConfDisplayPtr prev;
+
+	while (ptr)
+	{
+		xf86freeModeList (ptr->disp_mode_lst);
+		xf86optionListFree (ptr->disp_option_lst);
+		prev = ptr;
+		ptr = ptr->list.next;
+		xf86conffree (prev);
+	}
+}
+
+void
+xf86freeModeList (XF86ModePtr ptr)
+{
+	XF86ModePtr prev;
+
+	while (ptr)
+	{
+		TestFree (ptr->mode_name);
+		prev = ptr;
+		ptr = ptr->list.next;
+		xf86conffree (prev);
+	}
+}
+
+/*
+ * xf86validateScreen()
+ *
+ *    Validate each Screen section and its subordinate sections.
+ */
+int
+xf86validateScreen (XF86ConfigPtr p)
+{
+	XF86ConfScreenPtr screen = p->conf_screen_lst;
+	XF86ConfScrnMonitorEntryPtr mon_ptr; /* Ptr to a Monitor entry */
+	XF86ConfMonitorPtr monitor;	/* Ptr to a Monitor section */
+	XF86ConfDevicePtr device;
+	XF86ConfAdaptorLinkPtr adaptor;
+
+#if !defined(SMI_FBCONFIG)	/* Missing section will be constructed */
+	if (!screen)
+	{
+		xf86validationError ("At least one Screen section is required.");
+		return (FALSE);
+	}
+
+#endif
+	while (screen)
+	{
+		if (screen->scrn_obso_driver && !screen->scrn_identifier)
+			screen->scrn_identifier = screen->scrn_obso_driver;
+
+		/*
+		 * Process each Monitor entry in this Screen section
+		 */
+		for (mon_ptr = screen->scrn_monitor_lst;
+			mon_ptr != NULL;
+			mon_ptr = (XF86ConfScrnMonitorEntryPtr)mon_ptr->list.next) {
+
+			monitor = xf86findMonitor(mon_ptr->scrn_monitor_name,
+							p->conf_monitor_lst);
+			if (monitor == NULL) {
+				xf86validationError(
+						UNDEFINED_MONITOR_MSG,
+						mon_ptr->scrn_monitor_name,
+						screen->scrn_identifier);
+				return (FALSE);
+			}
+			mon_ptr->scrn_monitor = monitor;
+			if (!xf86validateMonitor(
+					p, screen->scrn_identifier, monitor)) {
+				return (FALSE);
+			}
+		}
+
+		/*
+		 * Make sure the specified Device section can be found
+		 */
+		if (screen->scrn_device_str == NULL) {
+			xf86validationError(UNDEFINED_DEVICE_MSG,
+						 "", screen->scrn_identifier);
+			return (FALSE);
+		}
+		device = xf86findDevice (screen->scrn_device_str, p->conf_device_lst);
+		if (!device)
+		{
+			xf86validationError (UNDEFINED_DEVICE_MSG,
+						  screen->scrn_device_str, screen->scrn_identifier);
+			return (FALSE);
+		}
+		screen->scrn_device = device;
+
+		adaptor = screen->scrn_adaptor_lst;
+		while (adaptor)
+		{
+			adaptor->al_adaptor = xf86findVideoAdaptor (adaptor->al_adaptor_str, p->conf_videoadaptor_lst);
+			if (!adaptor->al_adaptor)
+			{
+				xf86validationError (UNDEFINED_ADAPTOR_MSG, adaptor->al_adaptor_str, screen->scrn_identifier);
+				return (FALSE);
+			}
+			else if (adaptor->al_adaptor->va_fwdref)
+			{
+				xf86validationError (ADAPTOR_REF_TWICE_MSG, adaptor->al_adaptor_str,
+						     adaptor->al_adaptor->va_fwdref);
+				return (FALSE);
+			}
+
+			adaptor->al_adaptor->va_fwdref = xf86configStrdup(screen->scrn_identifier);
+			adaptor = adaptor->list.next;
+		}
+
+		screen = screen->list.next;
+	}
+
+	return (TRUE);
+}
+
+XF86ConfScreenPtr
+xf86findScreen (const char *ident, XF86ConfScreenPtr p)
+{
+	while (p)
+	{
+		if (xf86nameCompare (ident, p->scrn_identifier) == 0)
+			return (p);
+
+		p = p->list.next;
+	}
+	return (NULL);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Vendor.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,258 @@
+/* 
+ * 
+ * Copyright (c) 1997  Metro Link Incorporated
+ * 
+ * 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
+ * THE X CONSORTIUM 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.
+ * 
+ * Except as contained in this notice, the name of the Metro Link shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Metro Link.
+ * 
+ */
+/*
+ * Copyright (c) 1997-2003 by The XFree86 Project, 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
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+
+/* View/edit this file with tab stops set to 4 */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "Configint.h"
+#include "fields.h"		/* Config file output line fields */
+
+extern LexRec val;
+
+static xf86ConfigSymTabRec VendorSubTab[] =
+{
+	{ENDSUBSECTION, "endsubsection"},
+	{IDENTIFIER, "identifier"},
+	{OPTION, "option"},
+	{-1, ""},
+};
+
+#define CLEANUP xf86freeVendorSubList
+
+XF86ConfVendSubPtr
+xf86parseVendorSubSection (void)
+{
+	int has_ident = FALSE;
+	int token;
+	parsePrologue (XF86ConfVendSubPtr, XF86ConfVendSubRec)
+
+	while ((token = xf86getToken (VendorSubTab)) != ENDSUBSECTION)
+	{
+		switch (token)
+		{
+		case COMMENT:
+			ptr->vs_comment = xf86addComment(ptr->vs_comment, val.str);
+			break;
+		case IDENTIFIER:
+			if (xf86getSubToken (&(ptr->vs_comment)))
+				Error (QUOTE_MSG, "Identifier");
+			if (has_ident == TRUE)
+				Error (MULTIPLE_MSG, "Identifier");
+			ptr->vs_identifier = val.str;
+			has_ident = TRUE;
+			break;
+		case OPTION:
+			ptr->vs_option_lst = xf86parseOption(ptr->vs_option_lst);
+			break;
+
+		case EOF_TOKEN:
+			Error (UNEXPECTED_EOF_MSG, NULL);
+			break;
+		default:
+			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
+			break;
+		}
+	}
+
+#ifdef DEBUG
+	printf ("Vendor subsection parsed\n");
+#endif
+
+	return ptr;
+}
+
+#undef CLEANUP
+
+static xf86ConfigSymTabRec VendorTab[] =
+{
+	{ENDSECTION, "endsection"},
+	{IDENTIFIER, "identifier"},
+	{OPTION, "option"},
+	{SUBSECTION, "subsection"},
+	{-1, ""},
+};
+
+#define CLEANUP xf86freeVendorList
+
+XF86ConfVendorPtr
+xf86parseVendorSection (void)
+{
+	int has_ident = FALSE;
+	int token;
+	parsePrologue (XF86ConfVendorPtr, XF86ConfVendorRec)
+
+	while ((token = xf86getToken (VendorTab)) != ENDSECTION)
+	{
+		switch (token)
+		{
+		case COMMENT:
+			ptr->vnd_comment = xf86addComment(ptr->vnd_comment, val.str);
+			break;
+		case IDENTIFIER:
+			if (xf86getSubToken (&(ptr->vnd_comment)) != STRING)
+				Error (QUOTE_MSG, "Identifier");
+			if (has_ident == TRUE)
+				Error (MULTIPLE_MSG, "Identifier");
+			ptr->vnd_identifier = val.str;
+			has_ident = TRUE;
+			break;
+		case OPTION:
+			ptr->vnd_option_lst = xf86parseOption(ptr->vnd_option_lst);
+			break;
+		case SUBSECTION:
+			if (xf86getSubToken (&(ptr->vnd_comment)) != STRING)
+				Error (QUOTE_MSG, "SubSection");
+			{
+				HANDLE_LIST (vnd_sub_lst, xf86parseVendorSubSection,
+							XF86ConfVendSubPtr);
+			}
+			break;
+		case EOF_TOKEN:
+			Error (UNEXPECTED_EOF_MSG, NULL);
+			break;
+		default:
+			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
+			break;
+		}
+
+	}
+
+	if (!has_ident)
+		Error (NO_IDENT_MSG, NULL);
+
+#ifdef DEBUG
+	printf ("Vendor section parsed\n");
+#endif
+
+	return ptr;
+}
+
+#undef CLEANUP
+
+void
+xf86printVendorSection (FILE * cf, XF86ConfVendorPtr ptr)
+{
+	XF86ConfVendSubPtr pptr;
+
+	while (ptr)
+	{
+		fprintf (cf, "Section \"Vendor\"\n");
+		if (ptr->vnd_comment)
+			fprintf (cf, "%s", ptr->vnd_comment);
+		if (ptr->vnd_identifier)
+			fprintf (cf, "\tIdentifier     \"%s\"\n", ptr->vnd_identifier);
+
+		xf86printOptionList(cf, ptr->vnd_option_lst, xf86whitespace_1);
+		for (pptr = ptr->vnd_sub_lst; pptr; pptr = pptr->list.next)
+		{
+			fprintf (cf, "\tSubSection \"Vendor\"\n");
+			if (pptr->vs_comment)
+				fprintf (cf, "%s", pptr->vs_comment);
+			if (pptr->vs_identifier)
+				fprintf (cf, "\t\tIdentifier \"%s\"\n", pptr->vs_identifier);
+			xf86printOptionList(cf, pptr->vs_option_lst, xf86whitespace_2);
+			fprintf (cf, "\tEndSubSection\n");
+		}
+		fprintf (cf, "EndSection\n\n");
+		ptr = ptr->list.next;
+	}
+}
+
+void
+xf86freeVendorList (XF86ConfVendorPtr p)
+{
+	if (p == NULL)
+		return;
+	xf86freeVendorSubList (p->vnd_sub_lst);
+	TestFree (p->vnd_identifier);
+	TestFree (p->vnd_comment);
+	xf86optionListFree (p->vnd_option_lst);
+	xf86conffree (p);
+}
+
+void
+xf86freeVendorSubList (XF86ConfVendSubPtr ptr)
+{
+	XF86ConfVendSubPtr prev;
+
+	while (ptr)
+	{
+		TestFree (ptr->vs_identifier);
+		TestFree (ptr->vs_name);
+		TestFree (ptr->vs_comment);
+		xf86optionListFree (ptr->vs_option_lst);
+		prev = ptr;
+		ptr = ptr->list.next;
+		xf86conffree (prev);
+	}
+}
+
+XF86ConfVendorPtr
+xf86findVendor (const char *name, XF86ConfVendorPtr list)
+{
+	while (list)
+	{
+		if (xf86nameCompare (list->vnd_identifier, name) == 0)
+			return (list);
+		list = list->list.next;
+	}
+	return (NULL);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/Video.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,298 @@
+/* 
+ * 
+ * Copyright (c) 1997  Metro Link Incorporated
+ * 
+ * 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
+ * THE X CONSORTIUM 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.
+ * 
+ * Except as contained in this notice, the name of the Metro Link shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Metro Link.
+ * 
+ */
+/*
+ * Copyright (c) 1997-2003 by The XFree86 Project, 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
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+/* View/edit this file with tab stops set to 4 */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "Configint.h"
+#include "fields.h"		/* Config file output line fields */
+
+extern LexRec val;
+
+static xf86ConfigSymTabRec VideoPortTab[] =
+{
+	{ENDSUBSECTION, "endsubsection"},
+	{IDENTIFIER, "identifier"},
+	{OPTION, "option"},
+	{-1, ""},
+};
+
+#define CLEANUP xf86freeVideoPortList
+
+XF86ConfVideoPortPtr
+xf86parseVideoPortSubSection (void)
+{
+	int has_ident = FALSE;
+	int token;
+	parsePrologue (XF86ConfVideoPortPtr, XF86ConfVideoPortRec)
+
+	while ((token = xf86getToken (VideoPortTab)) != ENDSUBSECTION)
+	{
+		switch (token)
+		{
+		case COMMENT:
+			ptr->vp_comment = xf86addComment(ptr->vp_comment, val.str);
+			break;
+		case IDENTIFIER:
+			if (xf86getSubToken (&(ptr->vp_comment)) != STRING)
+				Error (QUOTE_MSG, "Identifier");
+			if (has_ident == TRUE)
+				Error (MULTIPLE_MSG, "Identifier");
+			ptr->vp_identifier = val.str;
+			has_ident = TRUE;
+			break;
+		case OPTION:
+			ptr->vp_option_lst = xf86parseOption(ptr->vp_option_lst);
+			break;
+
+		case EOF_TOKEN:
+			Error (UNEXPECTED_EOF_MSG, NULL);
+			break;
+		default:
+			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
+			break;
+		}
+	}
+
+#ifdef DEBUG
+	printf ("VideoPort subsection parsed\n");
+#endif
+
+	return ptr;
+}
+
+#undef CLEANUP
+
+static xf86ConfigSymTabRec VideoAdaptorTab[] =
+{
+	{ENDSECTION, "endsection"},
+	{IDENTIFIER, "identifier"},
+	{VENDOR, "vendorname"},
+	{BOARD, "boardname"},
+	{BUSID, "busid"},
+	{DRIVER, "driver"},
+	{OPTION, "option"},
+	{SUBSECTION, "subsection"},
+	{-1, ""},
+};
+
+#define CLEANUP xf86freeVideoAdaptorList
+
+XF86ConfVideoAdaptorPtr
+xf86parseVideoAdaptorSection (void)
+{
+	int has_ident = FALSE;
+	int token;
+
+	parsePrologue (XF86ConfVideoAdaptorPtr, XF86ConfVideoAdaptorRec)
+
+	while ((token = xf86getToken (VideoAdaptorTab)) != ENDSECTION)
+	{
+		switch (token)
+		{
+		case COMMENT:
+			ptr->va_comment = xf86addComment(ptr->va_comment, val.str);
+			break;
+		case IDENTIFIER:
+			if (xf86getSubToken (&(ptr->va_comment)) != STRING)
+				Error (QUOTE_MSG, "Identifier");
+			ptr->va_identifier = val.str;
+			if (has_ident == TRUE)
+				Error (MULTIPLE_MSG, "Identifier");
+			has_ident = TRUE;
+			break;
+		case VENDOR:
+			if (xf86getSubToken (&(ptr->va_comment)) != STRING)
+				Error (QUOTE_MSG, "Vendor");
+			ptr->va_vendor = val.str;
+			break;
+		case BOARD:
+			if (xf86getSubToken (&(ptr->va_comment)) != STRING)
+				Error (QUOTE_MSG, "Board");
+			ptr->va_board = val.str;
+			break;
+		case BUSID:
+			if (xf86getSubToken (&(ptr->va_comment)) != STRING)
+				Error (QUOTE_MSG, "BusID");
+			ptr->va_busid = val.str;
+			break;
+		case DRIVER:
+			if (xf86getSubToken (&(ptr->va_comment)) != STRING)
+				Error (QUOTE_MSG, "Driver");
+			ptr->va_driver = val.str;
+			break;
+		case OPTION:
+			ptr->va_option_lst = xf86parseOption(ptr->va_option_lst);
+			break;
+		case SUBSECTION:
+			if (xf86getSubToken (&(ptr->va_comment)) != STRING)
+				Error (QUOTE_MSG, "SubSection");
+			{
+				HANDLE_LIST (va_port_lst, xf86parseVideoPortSubSection,
+							 XF86ConfVideoPortPtr);
+			}
+			break;
+
+		case EOF_TOKEN:
+			Error (UNEXPECTED_EOF_MSG, NULL);
+			break;
+		default:
+			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
+			break;
+		}
+	}
+
+	if (!has_ident)
+		Error (NO_IDENT_MSG, NULL);
+
+#ifdef DEBUG
+	printf ("VideoAdaptor section parsed\n");
+#endif
+
+	return ptr;
+}
+
+void
+xf86printVideoAdaptorSection (FILE * cf, XF86ConfVideoAdaptorPtr ptr)
+{
+	XF86ConfVideoPortPtr pptr;
+
+	while (ptr)
+	{
+		fprintf (cf, "Section \"VideoAdaptor\"\n");
+		if (ptr->va_comment)
+			fprintf (cf, "%s", ptr->va_comment);
+		if (ptr->va_identifier)
+			fprintf (cf, "\tIdentifier  \"%s\"\n", ptr->va_identifier);
+		if (ptr->va_vendor)
+			fprintf (cf, "\tVendorName  \"%s\"\n", ptr->va_vendor);
+		if (ptr->va_board)
+			fprintf (cf, "\tBoardName   \"%s\"\n", ptr->va_board);
+		if (ptr->va_busid)
+			fprintf (cf, "\tBusID       \"%s\"\n", ptr->va_busid);
+		if (ptr->va_driver)
+			fprintf (cf, "\tDriver      \"%s\"\n", ptr->va_driver);
+		xf86printOptionList(cf, ptr->va_option_lst, xf86whitespace_1);
+		for (pptr = ptr->va_port_lst; pptr; pptr = pptr->list.next)
+		{
+			fprintf (cf, "\tSubSection \"VideoPort\"\n");
+			if (pptr->vp_comment)
+				fprintf (cf, "%s", pptr->vp_comment);
+			if (pptr->vp_identifier)
+				fprintf (cf, "\t\tIdentifier \"%s\"\n", pptr->vp_identifier);
+			xf86printOptionList(cf, pptr->vp_option_lst, xf86whitespace_2);
+			fprintf (cf, "\tEndSubSection\n");
+		}
+		fprintf (cf, "EndSection\n\n");
+		ptr = ptr->list.next;
+	}
+
+}
+
+void
+xf86freeVideoAdaptorList (XF86ConfVideoAdaptorPtr ptr)
+{
+	XF86ConfVideoAdaptorPtr prev;
+
+	while (ptr)
+	{
+		TestFree (ptr->va_identifier);
+		TestFree (ptr->va_vendor);
+		TestFree (ptr->va_board);
+		TestFree (ptr->va_busid);
+		TestFree (ptr->va_driver);
+		TestFree (ptr->va_fwdref);
+		TestFree (ptr->va_comment);
+		xf86freeVideoPortList (ptr->va_port_lst);
+		xf86optionListFree (ptr->va_option_lst);
+		prev = ptr;
+		ptr = ptr->list.next;
+		xf86conffree (prev);
+	}
+}
+
+void
+xf86freeVideoPortList (XF86ConfVideoPortPtr ptr)
+{
+	XF86ConfVideoPortPtr prev;
+
+	while (ptr)
+	{
+		TestFree (ptr->vp_identifier);
+		TestFree (ptr->vp_comment);
+		xf86optionListFree (ptr->vp_option_lst);
+		prev = ptr;
+		ptr = ptr->list.next;
+		xf86conffree (prev);
+	}
+}
+
+XF86ConfVideoAdaptorPtr
+xf86findVideoAdaptor (const char *ident, XF86ConfVideoAdaptorPtr p)
+{
+	while (p)
+	{
+		if (xf86nameCompare (ident, p->va_identifier) == 0)
+			return (p);
+
+		p = p->list.next;
+	}
+	return (NULL);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/configProcs.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,236 @@
+/*
+ * Copyright (c) 1997-2001 by The XFree86 Project, 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
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+
+#ifndef	_CONFIGPROCS_H_
+#define	_CONFIGPROCS_H_
+
+
+/* Private procs.  Public procs are in xf86Parser.h and xf86Optrec.h */
+
+
+#include <stdio.h>		/* FILE */
+
+#include "xf86Parser.h"
+
+
+/* Device.c */
+XF86ConfDevicePtr xf86parseDeviceSection(void);
+void xf86printDeviceSectionSection(
+	FILE *cf, XF86ConfDevicePtr ptr, const char *const whitespace[]);
+void xf86printDeviceSectionIdentifier(
+	FILE *cf, XF86ConfDevicePtr ptr, const char *const whitespace[]);
+void xf86printDeviceSectionDriver(
+	FILE *cf, XF86ConfDevicePtr ptr, const char *const whitespace[]);
+void xf86printDeviceSectionVendorName(
+	FILE *cf, XF86ConfDevicePtr ptr, const char *const whitespace[]);
+void xf86printDeviceSectionBoardName(
+	FILE *cf, XF86ConfDevicePtr ptr, const char *const whitespace[]);
+void xf86printDeviceSectionEndSection(
+	FILE *cf, XF86ConfDevicePtr ptr, const char *const whitespace[]);
+void xf86printDeviceSection(FILE *cf, XF86ConfDevicePtr ptr);
+void xf86freeDeviceList(XF86ConfDevicePtr ptr);
+int xf86validateDevice(XF86ConfigPtr p);
+
+/* Files.c */
+XF86ConfFilesPtr xf86parseFilesSection(void);
+void xf86printFileSection(FILE *cf, XF86ConfFilesPtr ptr);
+void xf86freeFiles(XF86ConfFilesPtr p);
+
+/* Flags.c */
+XF86ConfFlagsPtr xf86parseFlagsSection(void);
+void xf86printServerFlagsSection(FILE *f, XF86ConfFlagsPtr flags);
+void xf86freeFlags(XF86ConfFlagsPtr flags);
+
+/* Input.c */
+XF86ConfInputPtr xf86parseInputSection(void);
+void xf86printInputSection(FILE *f, XF86ConfInputPtr ptr);
+void xf86freeInputList(XF86ConfInputPtr ptr);
+int xf86validateInput (XF86ConfigPtr p);
+
+/* Keyboard.c */
+XF86ConfInputPtr xf86parseKeyboardSection(void);
+
+/* Layout.c */
+XF86ConfLayoutPtr xf86parseLayoutSection(void);
+void xf86printLayoutSection(FILE *cf, XF86ConfLayoutPtr ptr);
+void xf86freeLayoutList(XF86ConfLayoutPtr ptr);
+void xf86freeAdjacencyList(XF86ConfAdjacencyPtr ptr);
+void xf86freeInputrefList(XF86ConfInputrefPtr ptr);
+int xf86validateLayout(XF86ConfigPtr p);
+
+/* Module.c */
+XF86LoadPtr xf86parseModuleSubSection(XF86LoadPtr head, char *name);
+XF86ConfModulePtr xf86parseModuleSection(void);
+void xf86printModuleSection(FILE *cf, XF86ConfModulePtr ptr);
+XF86LoadPtr xf86addNewLoadDirective(XF86LoadPtr head, char *name, int type, XF86OptionPtr opts);
+void xf86freeModules(XF86ConfModulePtr ptr);
+
+/* Monitor.c */
+XF86ConfModeLinePtr xf86parseModeLine(void);
+XF86ConfModeLinePtr xf86parseVerboseMode(void);
+XF86ConfMonitorPtr xf86parseMonitorSection(void);
+XF86ConfModesPtr xf86parseModesSection(void);
+void xf86printMonitorSectionSection(
+	FILE *cf, XF86ConfMonitorPtr ptr, const char * const whitespace[]);
+void xf86printMonitorSectionIdentifier(
+	FILE *cf, XF86ConfMonitorPtr ptr, const char * const whitespace[]);
+void xf86printMonitorSectionUseModes(
+	FILE *cf, XF86ConfModesLinkPtr mptr, const char *const whitespace[]);
+void xf86printMonitorSectionGamma(
+	FILE *cf, XF86ConfMonitorPtr ptr, const char *const whitespace[]);
+void xf86printMonitorSectionEndSection(
+	FILE *cf, XF86ConfMonitorPtr ptr, const char * const whitespace[]);
+#if defined(SMI_FBCONFIG)
+void xf86printMxxxSectionModeDotClock(
+	FILE *cf, XF86ConfModeLinePtr mlptr, const char *const whitespace[]);
+void xf86printMxxxSectionModeHTimings(
+	FILE *cf, XF86ConfModeLinePtr mlptr, const char *const whitespace[]);
+void xf86printMxxxSectionModeVTimings(
+	FILE *cf, XF86ConfModeLinePtr mlptr, const char *const whitespace[]);
+void xf86printMxxxSectionModeFlags(
+	FILE *cf, XF86ConfModeLinePtr mlptr, const char *const whitespace[]);
+void xf86printMxxxSectionModeLine(
+	FILE *cf, XF86ConfModeLinePtr mlptr, const char *const whitespace[]);
+void xf86printMxxxSectionModeHSkew(
+	FILE *cf, XF86ConfModeLinePtr mlptr, const char *const whitespace[]);
+void xf86printMxxxSectionModeVScan(
+	FILE *cf, XF86ConfModeLinePtr mlptr, const char *const whitespace[]);
+#endif
+void xf86printMonitorSection(FILE *cf, XF86ConfMonitorPtr ptr);
+void xf86printModesSection(FILE *cf, XF86ConfModesPtr ptr);
+void xf86freeMonitorList(XF86ConfMonitorPtr ptr);
+void xf86freeModesList(XF86ConfModesPtr ptr);
+void xf86freeModeLineList(XF86ConfModeLinePtr ptr);
+int xf86validateMonitor(
+	XF86ConfigPtr	p,		/* Ptr to configuration stuff */
+	const char *const screen_identifier, /* Name of Screen section */
+	XF86ConfMonitorPtr monitor);	/* Monitor section to validate */
+
+/* Pointer.c */
+XF86ConfInputPtr xf86parsePointerSection(void);
+
+/* Screen.c */
+XF86ConfDisplayPtr xf86parseDisplaySubSection(void);
+XF86ConfScreenPtr xf86parseScreenSection(void);
+void xf86printDisplaySubsectionSubsection(
+	FILE *cf, XF86ConfDisplayPtr dptr, const char *const whitespace[]);
+void xf86printDisplaySubsectionMonitor(
+	FILE *cf, XF86ConfDisplayPtr dptr, const char *const whitespace[]);
+void xf86printDisplaySubsectionModes(
+	FILE *cf, XF86ConfDisplayPtr dptr, const char *const whitespace[]);
+void xf86printDisplaySubsectionEndSubsection(
+	FILE *cf, XF86ConfDisplayPtr dptr, const char *const whitespace[]);
+void xf86printScreenSectionSection(
+	FILE *cf, XF86ConfScreenPtr ptr, const char *const whitespace[]);
+void xf86printScreenSectionIdentifier(
+	FILE *cf, XF86ConfScreenPtr ptr, const char *const whitespace[]);
+void xf86printScreenSectionDevice(
+	FILE *cf, XF86ConfScreenPtr ptr, const char *const whitespace[]);
+void xf86printScreenSectionMonitor(
+	FILE *cf, XF86ConfScrnMonitorEntryPtr mon_ptr,
+	const char *const whitespace[]);
+void xf86printScreenSectionDefaultDepth(
+	FILE * cf, XF86ConfScreenPtr ptr, const char *const whitespace[]);
+void xf86printScreenSectionEndSection(
+	FILE * cf, XF86ConfScreenPtr ptr, const char *const whitespace[]);
+void xf86printScreenSection(FILE *cf, XF86ConfScreenPtr ptr);
+void xf86printDisplaySubsectionModes(
+	FILE *cf, XF86ConfDisplayPtr dptr, const char *const whitespace[]);
+void xf86freeScreenList(XF86ConfScreenPtr ptr);
+void xf86freeAdaptorLinkList(XF86ConfAdaptorLinkPtr ptr);
+void xf86freeDisplayList(XF86ConfDisplayPtr ptr);
+void xf86freeModeList(XF86ModePtr ptr);
+int xf86validateScreen(XF86ConfigPtr p);
+
+/* Vendor.c */
+XF86ConfVendorPtr xf86parseVendorSection(void);
+XF86ConfVendSubPtr xf86parseVendorSubSection (void);
+void xf86freeVendorList(XF86ConfVendorPtr p);
+void xf86printVendorSection(FILE * cf, XF86ConfVendorPtr ptr);
+void xf86freeVendorSubList (XF86ConfVendSubPtr ptr);
+
+/* Video.c */
+XF86ConfVideoPortPtr xf86parseVideoPortSubSection(void);
+XF86ConfVideoAdaptorPtr xf86parseVideoAdaptorSection(void);
+void xf86printVideoAdaptorSection(FILE *cf, XF86ConfVideoAdaptorPtr ptr);
+void xf86freeVideoAdaptorList(XF86ConfVideoAdaptorPtr ptr);
+void xf86freeVideoPortList(XF86ConfVideoPortPtr ptr);
+
+/* read.c */
+#if defined(SMI_FBCONFIG)
+XF86ConfigPtr xf86readNextConfigFile(XF86ConfigPtr ptr);
+#endif
+int xf86validateConfig(XF86ConfigPtr p);
+
+/* scan.c */
+#if defined(SMI_FBCONFIG)
+extern char	*xf86configBuf;		/* Config file line buffer */
+extern int	xf86configBufLen;	/* Line buffer length */
+#endif
+unsigned int xf86strToUL(char *str);
+char *xf86getNextLine(char **configBuf, int *configBufLen, FILE *configFile);
+int xf86getToken(xf86ConfigSymTabRec *tab);
+int xf86getSubToken(char **comment);
+int xf86getSubTokenWithTab(char **comment, xf86ConfigSymTabRec *tab);
+void xf86unGetToken(int token);
+char *xf86tokenString(void);
+void xf86parseError(char *format, ...);
+void xf86parseWarning(char *format, ...);
+void xf86validationError(char *format, ...);
+void xf86setSection(char *section);
+int xf86getStringToken(xf86ConfigSymTabRec *tab);
+
+/* write.c */
+
+/* DRI.c */
+XF86ConfBuffersPtr xf86parseBuffers (void);
+void xf86freeBuffersList (XF86ConfBuffersPtr ptr);
+XF86ConfDRIPtr xf86parseDRISection (void);
+void xf86printDRISection (FILE * cf, XF86ConfDRIPtr ptr);
+void xf86freeDRI (XF86ConfDRIPtr ptr);
+
+/* Extensions.c */
+XF86ConfExtensionsPtr xf86parseExtensionsSection (void);
+void xf86printExtensionsSection (FILE * cf, XF86ConfExtensionsPtr ptr);
+void xf86freeExtensions (XF86ConfExtensionsPtr ptr);
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifndef IN_XSERVER
+#include <stdarg.h>
+
+/* Externally provided functions */
+void ErrorF(const char *f, ...);
+void VErrorF(const char *f, va_list args);
+#endif
+
+
+#endif	/* _CONFIGPROCS_H_ */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/fields.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/* fields - Write aligned whitespace and text fields */
+
+#include <stdarg.h>		/* Variable argument lists */
+#include <stdio.h>		/* fprintf() */
+#include <string.h>		/* strlen() */
+
+#include "fields.h"		/* Config file output line fields */
+
+
+/* Generic line indentation level 0  (e.g. Section line) */
+const char * const xf86whitespace_0[] = {
+	"",
+	" ",
+	" ",
+	NULL
+};
+
+
+/* Generic line indentation level 1  (e.g. section entry line) */
+const char * const xf86whitespace_1[] = {
+	"\t",
+	"\t\t",
+	" ",
+	NULL
+};
+
+/* Generic line indentation level 2  (e.g. subsection entry line) */
+const char * const xf86whitespace_2[] = {
+	"\t\t",
+	"\t\t",
+	" ",
+	NULL
+};
+
+
+/*
+ * xf86printFields()
+ *
+ *    Write whitespace and text fields such that each text field is
+ *    left-aligned with the intended character column.
+ *
+ *    The end of the whitespace[] array is marked by a NULL element.
+ *    The end of the text field string arguments (...) is marked by a
+ *    NULL pointer.  The whitespace[0] string is written before the
+ *    first text field.  The cycle of writing whitespace and text
+ *    strings is terminated once either NULL is reached.
+ */
+
+void
+xf86printFields(
+	FILE		*cf,		/* Config file output stream */
+	const char * const whitespace[], /* Array of whitespace strings */
+	...)				/* NULL-terminated text field args */
+{
+	int		cur_col;	/* Current character column */
+	int		field;		/* Loop counter / array index */
+	int		field_col;	/* Character column of field */
+	va_list		text_arg;	/* Ptr to text string arg */
+	char		*text_ptr;	/* Ptr to text string */
+	const char	*wspace;	/* Ptr into writable whitespace */
+	int		wspace_len;	/* Column with of whitespace char */
+	const char	*wspace_ptr;	/* Ptr into whitespace[] string */
+
+	/*
+	 * Initialize a pointer to the text string field arguments
+	 */
+	va_start(text_arg, whitespace);
+
+	/*
+	 * Repeat for each whitespace and (optional) text field pair
+	 */
+	field_col = 0;
+	cur_col   = 0;
+	text_ptr  = "";
+	for (field = 0; whitespace[field] != NULL; field += 1) {
+		/*
+		 * Determine the column following the text string
+		 */
+		cur_col += strlen(text_ptr); /* Assume no ctrl chars, etc. */
+
+		/*
+		 * Scan the whitespace of the current field
+		 */
+		wspace = whitespace[field];
+		for (wspace_ptr = wspace;
+			*wspace_ptr != '\0';
+			wspace_ptr += 1) {
+			/*
+			 * Ignore whitespace that is displaced by text
+			 */
+			if (field_col <= cur_col) {
+				wspace = wspace_ptr;
+			}
+
+			/*
+			 * Tally the column width of this whitespace character
+			 */
+			wspace_len = 1;	/* Assume it's a Space, not a Tab */
+			if (*wspace_ptr == '\t') {
+				wspace_len = XF86_TAB_WIDTH
+						- (field_col % XF86_TAB_WIDTH);
+			}
+			field_col += wspace_len;
+		}
+
+		/*
+		 * Write the text (if any) and the whitespace that follows
+		 */
+		if ((field > 0) && (field_col <= cur_col)) {
+			wspace = " ";
+			cur_col += 1;
+		} else {
+			cur_col = field_col;
+		}
+		fputs(text_ptr, cf);
+		fputs(wspace, cf);
+
+		/*
+		 * Get the next text string, if any
+		 */
+		text_ptr = va_arg(text_arg, char *);
+		if (text_ptr == NULL) {
+			break;
+		}
+	}
+
+	/*
+	 * Stop pointing to the text string field arguments
+	 */
+	va_end(text_arg);
+
+}	/* xf86printFields() */
+
+
+/* End of fields.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/fields.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/* fields - Write aligned whitespace and text fields */
+
+#pragma ident	"@(#)fields.h	1.1	08/10/10 16:29:28 SMI"
+
+
+#ifndef	 _FIELDS_H
+#define	 _FIELDS_H
+
+
+#include <stdio.h>		/* FILE */
+
+
+#define	XF86_TAB_WIDTH	8		/* Standard 8-column Tabs */
+
+
+extern const char * const xf86whitespace_0[]; /* Indendation level 0 */
+extern const char * const xf86whitespace_1[]; /* Indendation level 1 */
+extern const char * const xf86whitespace_2[]; /* Indendation level 2 */
+
+
+void xf86printFields(
+	FILE		*cf,		/* Config file output stream */
+	const char * const whitespace[], /* Array of whitespace strings */
+	...);				/* NULL-terminated text field args */
+
+
+#endif	/* _FIELDS_H */
+
+
+/* End of fields.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/read.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,383 @@
+/* 
+ * 
+ * Copyright (c) 1997  Metro Link Incorporated
+ * 
+ * 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
+ * THE X CONSORTIUM 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.
+ * 
+ * Except as contained in this notice, the name of the Metro Link shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Metro Link.
+ * 
+ */
+/*
+ * Copyright (c) 1997-2003 by The XFree86 Project, 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
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+
+/* View/edit this file with tab stops set to 4 */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "Configint.h"
+
+extern LexRec val;
+
+static xf86ConfigSymTabRec TopLevelTab[] =
+{
+	{SECTION, "section"},
+	{-1, ""},
+};
+
+
+/*
+ * xf86parseConfigFile()
+ *
+ *    Parse a configuration file, appending it to the current
+ *    configuration data.
+ */
+
+#define	CLEANUP	xf86freeConfig
+
+static
+XF86ConfigPtr
+xf86parseConfigFile(XF86ConfigPtr ptr)
+{
+	int		token;		/* Scanner token code */
+
+	while ((token = xf86getToken (TopLevelTab)) != EOF_TOKEN)
+	{
+		switch (token)
+		{
+		case COMMENT:
+			ptr->conf_comment = xf86addComment(ptr->conf_comment, val.str);
+			break;
+		case SECTION:
+			if (xf86getSubToken (&(ptr->conf_comment)) != STRING)
+			{
+				xf86parseError (QUOTE_MSG, "Section");
+				CLEANUP (ptr);
+				return (NULL);
+			}
+			xf86setSection (val.str);
+			if (xf86nameCompare (val.str, "files") == 0)
+			{
+				xf86conffree(val.str);
+				val.str = NULL;
+				HANDLE_RETURN (conf_files, xf86parseFilesSection ());
+			}
+			else if (xf86nameCompare (val.str, "serverflags") == 0)
+			{
+				xf86conffree(val.str);
+				val.str = NULL;
+				HANDLE_RETURN (conf_flags, xf86parseFlagsSection ());
+			}
+			else if (xf86nameCompare (val.str, "keyboard") == 0)
+			{
+				xf86conffree(val.str);
+				val.str = NULL;
+				HANDLE_LIST (conf_input_lst, xf86parseKeyboardSection,
+							 XF86ConfInputPtr);
+			}
+			else if (xf86nameCompare (val.str, "pointer") == 0)
+			{
+				xf86conffree(val.str);
+				val.str = NULL;
+				HANDLE_LIST (conf_input_lst, xf86parsePointerSection,
+							 XF86ConfInputPtr);
+			}
+			else if (xf86nameCompare (val.str, "videoadaptor") == 0)
+			{
+				xf86conffree(val.str);
+				val.str = NULL;
+				HANDLE_LIST (conf_videoadaptor_lst, xf86parseVideoAdaptorSection,
+							 XF86ConfVideoAdaptorPtr);
+			}
+			else if (xf86nameCompare (val.str, "device") == 0)
+			{
+				xf86conffree(val.str);
+				val.str = NULL;
+				HANDLE_LIST (conf_device_lst, xf86parseDeviceSection,
+							 XF86ConfDevicePtr);
+			}
+			else if (xf86nameCompare (val.str, "monitor") == 0)
+			{
+				xf86conffree(val.str);
+				val.str = NULL;
+				HANDLE_LIST (conf_monitor_lst, xf86parseMonitorSection,
+							 XF86ConfMonitorPtr);
+			}
+			else if (xf86nameCompare (val.str, "modes") == 0)
+			{
+				xf86conffree(val.str);
+				val.str = NULL;
+				HANDLE_LIST (conf_modes_lst, xf86parseModesSection,
+							 XF86ConfModesPtr);
+			}
+			else if (xf86nameCompare (val.str, "screen") == 0)
+			{
+				xf86conffree(val.str);
+				val.str = NULL;
+				HANDLE_LIST (conf_screen_lst, xf86parseScreenSection,
+							 XF86ConfScreenPtr);
+			}
+			else if (xf86nameCompare(val.str, "inputdevice") == 0)
+			{
+				xf86conffree(val.str);
+				val.str = NULL;
+				HANDLE_LIST (conf_input_lst, xf86parseInputSection,
+							 XF86ConfInputPtr);
+			}
+			else if (xf86nameCompare (val.str, "module") == 0)
+			{
+				xf86conffree(val.str);
+				val.str = NULL;
+				HANDLE_RETURN (conf_modules, xf86parseModuleSection ());
+			}
+			else if (xf86nameCompare (val.str, "serverlayout") == 0)
+			{
+				xf86conffree(val.str);
+				val.str = NULL;
+				HANDLE_LIST (conf_layout_lst, xf86parseLayoutSection,
+							 XF86ConfLayoutPtr);
+			}
+			else if (xf86nameCompare (val.str, "vendor") == 0)
+			{
+				xf86conffree(val.str);
+				val.str = NULL;
+				HANDLE_LIST (conf_vendor_lst, xf86parseVendorSection,
+							 XF86ConfVendorPtr);
+			}
+			else if (xf86nameCompare (val.str, "dri") == 0)
+			{
+				xf86conffree(val.str);
+				val.str = NULL;
+				HANDLE_RETURN (conf_dri, xf86parseDRISection ());
+			}
+			else if (xf86nameCompare (val.str, "extensions") == 0)
+			{
+				xf86conffree(val.str);
+				val.str = NULL;
+				HANDLE_RETURN (conf_extensions, xf86parseExtensionsSection ());
+			}
+			else
+			{
+				Error (INVALID_SECTION_MSG, xf86tokenString ());
+				xf86conffree(val.str);
+				val.str = NULL;
+			}
+			break;
+		default:
+			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
+			xf86conffree(val.str);
+			val.str = NULL;
+		}
+	}
+
+	return (ptr);
+}
+
+
+/*
+ * xf86readConfigFile()
+ *
+ *    Read and validate the (initial) configuration file.
+ */
+
+XF86ConfigPtr
+xf86readConfigFile(void)
+{
+	XF86ConfigPtr	ptr;
+
+	if ((ptr = xf86confcalloc (1, sizeof (XF86ConfigRec))) == NULL)
+	{
+		return (NULL);
+	}
+	memset(ptr, 0, sizeof (XF86ConfigRec));	/* Redundant */
+
+	/*
+	 * Read, parse, and validate the configuration
+	 */
+	ptr = xf86parseConfigFile(ptr);
+	if (ptr != NULL) {
+		if (!xf86validateConfig(ptr)) {
+			CLEANUP(ptr);
+			ptr = NULL;
+		}
+	}
+
+	return (ptr);
+}
+
+#if defined(SMI_FBCONFIG)
+
+/*
+ * xf86readNextConfigFile()
+ *
+ *    Read an additional configuration file, appending it to the current
+ *    configuration data.
+ *
+ *    Note that we can't revalidate existing configuration data without
+ *    the possibility of memory leaks involving Screen sections.  For
+ *    our purposes, additional configuration files are expected to
+ *    contain only Modes sections, so revalidation isn't a big concern.
+ */
+
+XF86ConfigPtr
+xf86readNextConfigFile(XF86ConfigPtr ptr)
+{
+
+	ptr = xf86parseConfigFile(ptr);
+	if (ptr != NULL) {
+		if (!xf86validateDevice(ptr) ||
+#if (0)
+				!xf86validateScreen(ptr) ||
+#endif
+				!xf86validateInput(ptr) ||
+				!xf86validateLayout(ptr)) {
+			CLEANUP(ptr);
+			ptr = NULL;
+		}
+	}
+	return (ptr);
+}
+
+#endif
+#undef CLEANUP
+
+
+/* 
+ * This function resolves name references and reports errors if the named
+ * objects cannot be found.
+ */
+int
+xf86validateConfig (XF86ConfigPtr p)
+{
+	if (!xf86validateDevice (p))
+		return FALSE;
+	if (!xf86validateScreen (p))
+		return FALSE;
+	if (!xf86validateInput (p))
+		return FALSE;
+	if (!xf86validateLayout (p))
+		return FALSE;
+
+	return (TRUE);
+}
+
+/* 
+ * adds an item to the end of the linked list. Any record whose first field
+ * is a GenericListRec can be cast to this type and used with this function.
+ * A pointer to the head of the list is returned to handle the addition of
+ * the first item.
+ */
+GenericListPtr
+xf86addListItem (GenericListPtr head, GenericListPtr new)
+{
+	GenericListPtr p = head;
+	GenericListPtr last = NULL;
+
+	while (p)
+	{
+		last = p;
+		p = p->next;
+	}
+
+	if (last)
+	{
+		last->next = new;
+		return (head);
+	}
+	else
+		return (new);
+}
+
+/* 
+ * Test if one chained list contains the other.
+ * In this case both list have the same endpoint (provided they don't loop)
+ */
+int
+xf86itemNotSublist(GenericListPtr list_1, GenericListPtr list_2)
+{
+	GenericListPtr p = list_1;
+	GenericListPtr last_1 = NULL, last_2 = NULL;
+
+	while (p) {
+		last_1 = p;
+		p = p->next;
+	}
+
+	p = list_2;
+	while (p) {
+		last_2 = p;
+		p = p->next;
+	}
+
+	return (!(last_1 == last_2));
+}
+
+void
+xf86freeConfig (XF86ConfigPtr p)
+{
+	if (p == NULL)
+		return;
+
+	xf86freeFiles (p->conf_files);
+	xf86freeModules (p->conf_modules);
+	xf86freeFlags (p->conf_flags);
+	xf86freeMonitorList (p->conf_monitor_lst);
+	xf86freeModesList (p->conf_modes_lst);
+	xf86freeVideoAdaptorList (p->conf_videoadaptor_lst);
+	xf86freeDeviceList (p->conf_device_lst);
+	xf86freeScreenList (p->conf_screen_lst);
+	xf86freeLayoutList (p->conf_layout_lst);
+	xf86freeInputList (p->conf_input_lst);
+	xf86freeVendorList (p->conf_vendor_lst);
+	xf86freeDRI (p->conf_dri);
+	xf86freeExtensions (p->conf_extensions);
+	TestFree(p->conf_comment);
+
+	xf86conffree (p);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/scan.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,1325 @@
+/* 
+ * 
+ * Copyright (c) 1997  Metro Link Incorporated
+ * 
+ * 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
+ * THE X CONSORTIUM 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.
+ * 
+ * Except as contained in this notice, the name of the Metro Link shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Metro Link.
+ * 
+ */
+/*
+ * Copyright (c) 1997-2003 by The XFree86 Project, 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
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+
+/* View/edit this file with tab stops set to 4 */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdarg.h>
+
+#if !defined(X_NOT_POSIX)
+#if defined(_POSIX_SOURCE)
+#include <limits.h>
+#else
+#define _POSIX_SOURCE
+#include <limits.h>
+#undef _POSIX_SOURCE
+#endif /* _POSIX_SOURCE */
+#endif /* !X_NOT_POSIX */
+#if !defined(PATH_MAX)
+#if defined(MAXPATHLEN)
+#define PATH_MAX MAXPATHLEN
+#else
+#define PATH_MAX 1024
+#endif /* MAXPATHLEN */
+#endif /* !PATH_MAX */
+
+#if !defined(MAXHOSTNAMELEN)
+#define MAXHOSTNAMELEN 32
+#endif /* !MAXHOSTNAMELEN */
+
+#include "xf86Parser.h"		/* Public function, etc. declarations */
+#include "Configint.h"
+#include "configProcs.h"	/* Private function, etc. declarations */
+#include "xf86tokens.h"
+
+#if defined(SMI_FBCONFIG)
+#include "fbc_error.h"		/* Error reporting */
+#define	xf86printErrorF fbc_errormsg /* Write prog name & variable fmt error */
+#include "fbc_line_er.h"	/* External Representation of config lines */
+#endif
+
+#if !defined(xf86printErrorF)	/* Could write prog name & variable fmt msg */
+#define	xf86printErrorF ErrorF	/* Write a variable format error message */
+#endif
+
+#define CONFIG_BUF_LEN     1024
+
+static int StringToToken (char *, xf86ConfigSymTabRec *);
+
+static FILE *configFile = NULL;
+static const char **builtinConfig = NULL;
+static int builtinIndex = 0;
+static int configPos = 0;		/* current readers position */
+static int configLineNo = 0;	/* linenumber */
+#if !defined(SMI_FBCONFIG)
+static char *configBuf = NULL;		/* Config file line buffer */
+static int configBufLen = 0;		/* Line buffer length */
+#else
+#define	configBuf	xf86configBuf
+#define	configBufLen	xf86configBufLen
+char *xf86configBuf = NULL;		/* Config file line buffer */
+int xf86configBufLen = 0;		/* Line buffer length */
+#endif
+static char *configRBuf = NULL;		/* Token buffer */
+static int configRBufLen = 0;		/* Token buffer length */
+static char *configPath;		/* path to config file */
+static char *configSection = NULL;	/* name of current section being parsed */
+static int pushToken = LOCK_TOKEN;
+static int eol_seen = 0;		/* private state to handle comments */
+LexRec val;
+
+#ifdef __UNIXOS2__
+extern char *__XOS2RedirRoot(char *path);
+#endif
+
+
+/* 
+ * xf86strToUL --
+ *
+ *  A portable, but restricted, version of strtoul().  It only understands
+ *  hex, octal, and decimal.  But it's good enough for our needs.
+ */
+unsigned int
+xf86strToUL (char *str)
+{
+	int base = 10;
+	char *p = str;
+	unsigned int tot = 0;
+
+	if (*p == '0')
+	{
+		p++;
+		if ((*p == 'x') || (*p == 'X'))
+		{
+			p++;
+			base = 16;
+		}
+		else
+			base = 8;
+	}
+	while (*p)
+	{
+		if ((*p >= '0') && (*p <= ((base == 8) ? '7' : '9')))
+		{
+			tot = tot * base + (*p - '0');
+		}
+		else if ((base == 16) && (*p >= 'a') && (*p <= 'f'))
+		{
+			tot = tot * base + 10 + (*p - 'a');
+		}
+		else if ((base == 16) && (*p >= 'A') && (*p <= 'F'))
+		{
+			tot = tot * base + 10 + (*p - 'A');
+		}
+		else
+		{
+			return (tot);
+		}
+		p++;
+	}
+	return (tot);
+}
+
+/*
+ * xf86getNextLine()
+ *
+ *  Read from the configFile FILE stream until we encounter a newline;
+ *  this is a wrapper for fgets(3) that can handle arbitrarily long
+ *  input lines.
+ *
+ *  Callers, such as xf86getToken(), assume that we will read up to the
+ *  next newline; we need to grow configBuf as necessary to support that.
+ */
+
+char *
+xf86getNextLine(char **configBuf, int *configBufLen, FILE *configFile)
+{
+	char *tmpConfigBuf;
+	int c, i, pos = 0, eolFound = 0;
+	char *ret = NULL;
+
+	/*
+	 * Reallocate the buffer if it was grown last time (i.e., is no
+	 * longer CONFIG_BUF_LEN); we malloc the new buffer first, so
+	 * that if the malloc() fails, we can fall back to use the
+	 * existing buffer.
+	 *
+	 * [Might want to wait and shrink the buffer after reading the line.]
+	 */
+
+	if (*configBufLen != CONFIG_BUF_LEN) {
+
+		tmpConfigBuf = xf86confmalloc(CONFIG_BUF_LEN);
+		if (tmpConfigBuf != NULL) {
+
+			/*
+			 * The malloc() succeeded; free the old buffer and use
+			 * the new buffer.
+			 */
+
+			xf86conffree(configBuf);
+			*configBuf    = tmpConfigBuf;
+			*configBufLen = CONFIG_BUF_LEN;
+		}
+	}
+
+	/* read in another block of chars */
+
+	do {
+		ret = fgets(*configBuf + pos, *configBufLen - pos - 1, configFile);
+		if (ret == NULL) {
+			(*configBuf)[pos] = '\0';
+			break;
+		}
+
+		/* search for EOL in the new block of chars */
+
+		for (i = pos; i < (*configBufLen - 1); i++) {
+			c = (*configBuf)[i];
+
+			if (c == '\0') break;
+
+			if ((c == '\n') || (c == '\r')) {
+				eolFound = 1;
+				break;
+			}
+		}
+
+		/*
+		 * if we didn't find EOL, then grow the buffer and
+		 * read in more
+		 */
+
+		if (!eolFound) {
+
+			tmpConfigBuf = xf86confrealloc(*configBuf, *configBufLen + CONFIG_BUF_LEN);
+			if (tmpConfigBuf == NULL) {
+				/*
+				 * The reallocation failed; we have to fall
+				 * back to the previous configBufLen size and
+				 * use the string we have, even though we don't
+				 * have an EOL.
+				 */
+				break;
+
+			} else {
+
+				/* reallocation succeeded */
+
+				*configBuf = tmpConfigBuf;
+				pos = i;
+				*configBufLen += CONFIG_BUF_LEN;
+			}
+		}
+
+	} while (!eolFound);
+
+	return (ret);
+}
+
+/* 
+ * xf86getToken --
+ *      Read next Token from the config file. Handle the global variable
+ *      pushToken.  If a pointer to a symbol table has been provided
+ *      (tab != NULL), the table may be searched for a match with the
+ *      token.  If all attempts to recognize the token fail, an
+ *      ERROR_TOKEN code is returned.
+ */
+int
+xf86getToken (xf86ConfigSymTabRec * tab)
+{
+	int c, i;
+	char *tmpConfigRBuf;
+
+	/* 
+	 * First check whether pushToken has a different value than LOCK_TOKEN.
+	 * In this case configRBuf[] contains a valid STRING/TOKEN/NUMBER.
+	 * Otherwise the next token must be read from the input.
+	 */
+	if (pushToken == EOF_TOKEN)
+		return (EOF_TOKEN);
+	else if (pushToken == LOCK_TOKEN)
+	{
+		/*
+		 * eol_seen is only set for the first token after a newline.
+		 */
+		eol_seen = 0;
+
+		c = configBuf[configPos];
+
+		/* 
+		 * Get start of next Token. EOF is handled,
+		 * whitespaces are skipped. 
+		 */
+
+again:
+		if (!c)
+		{
+			char *ret;
+			if (configFile != NULL) {
+#if defined(SMI_FBCONFIG)
+				off_t line_pos;	/* File position of line */
+
+				line_pos = ftell(configFile);
+#endif
+				ret = xf86getNextLine(&configBuf, &configBufLen, configFile);
+#if defined(SMI_FBCONFIG)
+				if (ret != NULL) {
+					fbc_save_line_location(configFile, line_pos);
+				}
+#endif
+			} else {
+				if (builtinConfig[builtinIndex] == NULL)
+					ret = NULL;
+				else {
+					ret = strncpy(configBuf, builtinConfig[builtinIndex],
+							CONFIG_BUF_LEN);
+					builtinIndex++;
+				}
+			}
+			if (ret == NULL)
+			{
+				return (pushToken = EOF_TOKEN);
+			}
+			configLineNo++;
+			configPos = 0;
+			eol_seen = 1;
+		}
+
+		/*
+		 * Make the token buffer the same size as the input line
+		 * buffer.  We malloc() the new token buffer first, so
+		 * that if the malloc() fails, we can fall back to use the
+		 * existing token buffer.
+		 */
+
+		if (configRBufLen != configBufLen) {
+
+			tmpConfigRBuf = xf86confmalloc(configBufLen);
+			if (tmpConfigRBuf != NULL) {
+
+				/*
+				 * The malloc() succeeded; free the old buffer
+				 * and use the new buffer.
+				 */
+
+				xf86conffree(configRBuf);
+				configBuf     = tmpConfigRBuf;
+				configRBufLen = configBufLen;
+			}
+		}
+
+		/*
+		 * Start scanning the new token, which may include whitespace
+		 */
+
+		i = 0;
+		for (;;) {
+			c = configBuf[configPos++];
+			configRBuf[i++] = c;
+			switch (c) {
+				case ' ':
+				case '\t':
+				case '\r':
+					continue;
+				case '\n':
+					i = 0;
+					continue;
+			}
+			break;
+		}
+		if (c == '\0')
+			goto again;	/* [Should be a do-while loop] */
+
+		if (c == '#')
+		{
+			do
+			{
+				configRBuf[i++] = (c = configBuf[configPos++]);
+			}
+			while ((c != '\n') && (c != '\r') && (c != '\0'));
+			configRBuf[i] = '\0';
+			/* XXX no private copy.
+			 * Use xf86addComment when setting a comment.
+			 */
+			val.str = configRBuf;
+			return (COMMENT);
+		}
+
+		/* GJA -- handle '-' and ','  * Be careful: "-hsync" is a keyword. */
+		else if ((c == ',') && !isalpha (configBuf[configPos]))
+		{
+			return COMMA;
+		}
+		else if ((c == '-') && !isalpha (configBuf[configPos]))
+		{
+			return DASH;
+		}
+
+		/* 
+		 * Numbers are returned immediately ...
+		 */
+		if (isdigit (c))
+		{
+			int base;
+
+			if (c == '0')
+				if ((configBuf[configPos] == 'x') ||
+					(configBuf[configPos] == 'X'))
+					base = 16;
+				else
+					base = 8;
+			else
+				base = 10;
+
+			configRBuf[0] = c;
+			i = 1;
+			while (isdigit (c = configBuf[configPos++]) ||
+				   (c == '.') || (c == 'x') || (c == 'X') ||
+				   ((base == 16) && (((c >= 'a') && (c <= 'f')) ||
+									 ((c >= 'A') && (c <= 'F')))))
+				configRBuf[i++] = c;
+			configPos--;		/* GJA -- one too far */
+			configRBuf[i] = '\0';
+			val.num = xf86strToUL (configRBuf);
+			val.realnum = atof (configRBuf);
+			return (NUMBER);
+		}
+
+		/* 
+		 * All Strings START with a \" ...
+		 */
+		else if (c == '\"')
+		{
+			i = -1;
+			do
+			{
+				configRBuf[++i] = (c = configBuf[configPos++]);
+			}
+			while ((c != '\"') && (c != '\n') && (c != '\r') && (c != '\0'));
+			configRBuf[i] = '\0';
+			val.str = xf86confmalloc (strlen (configRBuf) + 1);
+			strcpy (val.str, configRBuf);	/* private copy ! */
+			return (STRING);
+		}
+
+		/* 
+		 * ... and now we MUST have a valid token.  The search is
+		 * handled later along with the pushed tokens.
+		 */
+		else
+		{
+			configRBuf[0] = c;
+			i = 0;
+			do
+			{
+				configRBuf[++i] = (c = configBuf[configPos++]);;
+			}
+			while ((c != ' ') && (c != '\t') && (c != '\n') && (c != '\r') && (c != '\0') && (c != '#'));
+			--configPos;
+			configRBuf[i] = '\0';
+			i = 0;
+		}
+
+	}
+	else
+	{
+
+		/* 
+		 * Here we deal with pushed tokens. Reinitialize pushToken again. If
+		 * the pushed token was NUMBER || STRING return them again ...
+		 */
+		int temp = pushToken;
+		pushToken = LOCK_TOKEN;
+
+		if (temp == COMMA || temp == DASH)
+			return (temp);
+		if (temp == NUMBER || temp == STRING)
+			return (temp);
+	}
+
+	/* 
+	 * Joop, at last we have to lookup the token ...
+	 */
+	if (tab)
+	{
+
+		i = 0;
+		while (tab[i].token != -1)
+			if (xf86nameCompare (configRBuf, tab[i].name) == 0)
+				return (tab[i].token);
+			else
+				i++;
+	}
+
+	return (ERROR_TOKEN);		/* Error catcher */
+}
+
+/* 
+ * xf86getSubToken()
+ *
+ *    Read tokens from the configuration file until a non-COMMENT
+ *    token is encountered.  No symbol table is provided for token
+ *    lookup.  Unless no comment pointer is provided by the caller,
+ *    append any COMMENT text to the dynamically grown string of
+ *    comments.  Return the code for the non-COMMENT token.
+ */
+int
+xf86getSubToken (char **comment)
+{
+	int token;
+
+	for (;;) {
+		token = xf86getToken(NULL);
+		if (token == COMMENT) {
+			if (comment)
+				*comment = xf86addComment(*comment, val.str);
+		}
+		else
+			return (token);
+	}
+	/*NOTREACHED*/
+}
+
+/* 
+ * xf86getSubTokenWithTab()
+ *
+ *    Read tokens from the configuration file until a non-COMMENT
+ *    token is encountered.  A symbol table is provided for token
+ *    lookup.  Unless no comment pointer is provided by the caller,
+ *    append any COMMENT text to the dynamically grown string of
+ *    comments.  Return the code for the non-COMMENT token.
+ */
+int
+xf86getSubTokenWithTab (char **comment, xf86ConfigSymTabRec *tab)
+{
+	int token;
+
+	for (;;) {
+		token = xf86getToken(tab);
+		if (token == COMMENT) {
+			if (comment)
+				*comment = xf86addComment(*comment, val.str);
+		}
+		else
+			return (token);
+	}
+	/*NOTREACHED*/
+}
+
+void
+xf86unGetToken (int token)
+{
+	pushToken = token;
+}
+
+char *
+xf86tokenString (void)
+{
+	return configRBuf;
+}
+
+int
+xf86pathIsAbsolute(const char *path)
+{
+	if (path && path[0] == '/')
+		return 1;
+#ifdef __UNIXOS2__
+	if (path && (path[0] == '\\' || (path[1] == ':')))
+		return 1;
+#endif
+	return 0;
+}
+
+/* A path is "safe" if it is relative and if it contains no ".." elements. */
+int
+xf86pathIsSafe(const char *path)
+{
+	if (xf86pathIsAbsolute(path))
+		return 0;
+
+	/* Compare with ".." */
+	if (!strcmp(path, ".."))
+		return 0;
+
+	/* Look for leading "../" */
+	if (!strncmp(path, "../", 3))
+		return 0;
+
+	/* Look for trailing "/.." */
+	if ((strlen(path) > 3) && !strcmp(path + strlen(path) - 3, "/.."))
+		return 0;
+
+	/* Look for "/../" */
+	if (strstr(path, "/../"))
+		return 0;
+
+	return 1;
+}
+
+/*
+ * This function substitutes the following escape sequences:
+ *
+ *    %A    cmdline argument as an absolute path (must be absolute to match)
+ *    %R    cmdline argument as a relative path
+ *    %S    cmdline argument as a "safe" path (relative, and no ".." elements)
+ *    %X    default config file name ("xorg.conf")
+ *    %H    hostname
+ *    %E    config file environment ($XORGCONFIG) as an absolute path
+ *    %F    config file environment ($XORGCONFIG) as a relative path
+ *    %G    config file environment ($XORGCONFIG) as a safe path
+ *    %D    $HOME
+ *    %P    projroot
+ *    %M    major version number
+ *    %%    %
+ *    %&    UNIXOS2 only: prepend X11ROOT env var
+ */
+
+#ifndef XCONFIGFILE
+#define XCONFIGFILE	"xorg.conf"
+#endif
+#ifndef PROJECTROOT
+#define PROJECTROOT	"/usr/X11R6"
+#endif
+#ifndef XCONFENV
+#define XCONFENV	"XORGCONFIG"
+#endif
+#define XFREE86CFGFILE "XF86Config"
+#ifndef XF86_VERSION_MAJOR
+#ifdef XVERSION
+#if XVERSION > 40000000
+#define XF86_VERSION_MAJOR	(XVERSION / 10000000)
+#else
+#define XF86_VERSION_MAJOR	(XVERSION / 1000)
+#endif
+#else
+#define XF86_VERSION_MAJOR	4
+#endif
+#endif
+
+#define BAIL_OUT		do {									\
+							xf86conffree(result);				\
+							return NULL;						\
+						} while (0)
+
+#define CHECK_LENGTH	do {									\
+							if (l > PATH_MAX) {					\
+								BAIL_OUT;						\
+							}									\
+						} while (0)
+
+#define APPEND_STR(s)	do {									\
+							if (strlen(s) + l > PATH_MAX) {		\
+								BAIL_OUT;						\
+							} else {							\
+								strcpy(result + l, s);			\
+								l += strlen(s);					\
+							}									\
+						} while (0)
+
+static char *
+DoSubstitution(const char *template, const char *cmdline, const char *projroot,
+			int *cmdlineUsed, int *envUsed, const char *XConfigFile)
+{
+	char *result;
+	int i, l;
+	static const char *env = NULL, *home = NULL;
+	static char *hostname = NULL;
+	static char majorvers[3] = "";
+#ifdef __UNIXOS2__
+	static char *x11root = NULL;
+#endif
+
+	if (!template)
+		return NULL;
+
+	if (cmdlineUsed)
+		*cmdlineUsed = 0;
+	if (envUsed)
+		*envUsed = 0;
+
+	result = xf86confmalloc(PATH_MAX + 1);
+	l = 0;
+	for (i = 0; template[i]; i++) {
+		if (template[i] != '%') {
+			result[l++] = template[i];
+			CHECK_LENGTH;
+		} else {
+			switch (template[++i]) {
+			case 'A':
+				if (cmdline && xf86pathIsAbsolute(cmdline)) {
+					APPEND_STR(cmdline);
+					if (cmdlineUsed)
+						*cmdlineUsed = 1;
+				} else
+					BAIL_OUT;
+				break;
+			case 'R':
+				if (cmdline && !xf86pathIsAbsolute(cmdline)) {
+					APPEND_STR(cmdline);
+					if (cmdlineUsed)
+						*cmdlineUsed = 1;
+				} else 
+					BAIL_OUT;
+				break;
+			case 'S':
+				if (cmdline && xf86pathIsSafe(cmdline)) {
+					APPEND_STR(cmdline);
+					if (cmdlineUsed)
+						*cmdlineUsed = 1;
+				} else 
+					BAIL_OUT;
+				break;
+			case 'X':
+				APPEND_STR(XConfigFile);
+				break;
+			case 'H':
+				if (!hostname) {
+					if ((hostname = xf86confmalloc(MAXHOSTNAMELEN + 1))) {
+						if (gethostname(hostname, MAXHOSTNAMELEN) == 0) {
+							hostname[MAXHOSTNAMELEN] = '\0';
+						} else {
+							xf86conffree(hostname);
+							hostname = NULL;
+						}
+					}
+				}
+				if (hostname)
+					APPEND_STR(hostname);
+				break;
+			case 'E':
+				if (!env)
+					env = getenv(XCONFENV);
+				if (env && xf86pathIsAbsolute(env)) {
+					APPEND_STR(env);
+					if (envUsed)
+						*envUsed = 1;
+				} else
+					BAIL_OUT;
+				break;
+			case 'F':
+				if (!env)
+					env = getenv(XCONFENV);
+				if (env && !xf86pathIsAbsolute(env)) {
+					APPEND_STR(env);
+					if (envUsed)
+						*envUsed = 1;
+				} else
+					BAIL_OUT;
+				break;
+			case 'G':
+				if (!env)
+					env = getenv(XCONFENV);
+				if (env && xf86pathIsSafe(env)) {
+					APPEND_STR(env);
+					if (envUsed)
+						*envUsed = 1;
+				} else
+					BAIL_OUT;
+				break;
+			case 'D':
+				if (!home)
+					home = getenv("HOME");
+				if (home && xf86pathIsAbsolute(home))
+					APPEND_STR(home);
+				else
+					BAIL_OUT;
+				break;
+			case 'P':
+				if (projroot && xf86pathIsAbsolute(projroot))
+					APPEND_STR(projroot);
+				else
+					BAIL_OUT;
+				break;
+			case 'M':
+				if (!majorvers[0]) {
+					if (XF86_VERSION_MAJOR < 0 || XF86_VERSION_MAJOR > 99) {
+						fprintf(stderr, "XF86_VERSION_MAJOR is out of range\n");
+						BAIL_OUT;
+					} else
+						sprintf(majorvers, "%d", XF86_VERSION_MAJOR);
+				}
+				APPEND_STR(majorvers);
+				break;
+			case '%':
+				result[l++] = '%';
+				CHECK_LENGTH;
+				break;
+#ifdef __UNIXOS2__
+			case '&':
+				if (!x11root)
+					x11root = getenv("X11ROOT");
+				if (x11root)
+					APPEND_STR(x11root);
+				else
+					BAIL_OUT;
+				break;
+#endif
+			default:
+				fprintf(stderr, "invalid escape %%%c found in path template\n",
+						template[i]);
+				BAIL_OUT;
+				break;
+			}
+		}
+	}
+#ifdef DEBUG
+	fprintf(stderr, "Converted `%s' to `%s'\n", template, result);
+#endif
+	result[l] = '\0';
+	return result;
+}
+
+
+/* 
+ * xf86openConfigFileIn()
+ *
+ * This function takes a config file search path (optional), a command-line
+ * specified file name (optional) and the ProjectRoot path (optional) and
+ * locates and opens a config file based on that information.  This
+ * function will fail if a command-line file name is specified and there
+ * is no %A, %R, or %S escape sequence in the effective search path.
+ *
+ * The return value is a pointer to the actual name of the file that was
+ * opened.  When no file is found, the return value is NULL.
+ *
+ * The escape sequences allowed in the search path are defined above.  The
+ * default search path is defined below.
+ */
+
+#ifndef DEFAULT_CONF_PATH
+#define DEFAULT_CONF_PATH	"/etc/X11/%S," \
+							"%P/etc/X11/%S," \
+							"/etc/X11/%G," \
+							"%P/etc/X11/%G," \
+							"/etc/X11/%X-%M," \
+							"/etc/X11/%X," \
+							"/etc/%X," \
+							"%P/etc/X11/%X.%H," \
+							"%P/etc/X11/%X-%M," \
+							"%P/etc/X11/%X," \
+							"%P/lib/X11/%X.%H," \
+							"%P/lib/X11/%X-%M," \
+							"%P/lib/X11/%X"
+#endif
+
+#if !defined(SMI_FBCONFIG)
+static
+#endif
+const char *
+xf86openConfigFileIn(
+	const char	*path,		/* Search path, else NULL */
+	const char	*cmdline,	/* File path (%A,%R,%S), else NULL */
+	const char	*projroot)	/* Project root path (%P), else NULL */
+{
+	const char *const Xfile[] = {
+		XCONFIGFILE,
+		XFREE86CFGFILE,
+		NULL
+	};				/* Substitutions for %X */
+	char *pathcopy;
+	const char *template;
+	int cmdlineUsed = 0;
+	const char *const *XConfigFile;	/* Ptr to current %X filename */
+
+	/* Initialize global variables for the scanner */
+	configPath   = NULL;		/* Config file pathname, else NULL */
+	configFile   = NULL;		/* Config file descriptor, else NULL */
+	configLineNo = 0;		/* Config file current line number */
+	configPos    = 0;		/* Index of current char in line buf */
+	if (configBuf != NULL) {
+		configBuf[0] = '\0';	/* Start with an empty line buffer */
+	}
+	pushToken    = LOCK_TOKEN;
+
+	/* Be sure there's a non-empty search path and a scratch buffer */
+	if (path == NULL || path[0] == '\0') {
+		path = DEFAULT_CONF_PATH;
+	}
+	pathcopy = xf86confmalloc(strlen(path) + 1);
+	if (pathcopy == NULL) {
+		return (NULL);
+	}
+
+	/* Be sure there's a non-empty project root to substitute for %P */
+	if (projroot == NULL || projroot[0] == '\0') {
+		projroot = PROJECTROOT;
+	}
+
+	/* Repeat for each config filename that can be substituted for %X */
+	for (XConfigFile = &Xfile[0]; *XConfigFile != NULL; XConfigFile += 1) {
+
+		/* Repeat for each comma-separated pathname template */
+		strcpy(pathcopy, path);
+		for (template = strtok(pathcopy, ",");
+			template != NULL;
+			template = strtok(NULL, ",")) {
+
+			/* Construct a config pathname from the template */
+			configPath = DoSubstitution(template, cmdline, projroot,
+							&cmdlineUsed, NULL,
+							*XConfigFile);
+			if (configPath == NULL) {
+				continue;	/* No memory */
+			}
+
+			/* Open the path unless a provided name wasn't used */
+			if (cmdline == NULL || cmdlineUsed) {
+				configFile = fopen(configPath, "r");
+				if (configFile != NULL) {
+					break;	/* Success */
+				}
+			}
+
+			/* Discard the failed config pathname */
+			xf86conffree(configPath);
+			configPath = NULL;
+		}
+
+		if (configFile != NULL) {
+			break;			/* Success */
+		}
+	}
+	
+	xf86conffree(pathcopy);
+
+	return (configPath);
+}
+
+
+/* 
+ * xf86openConfigFile()
+ *
+ * This function takes a config file search path (optional), a command-line
+ * specified file name (optional) and the ProjectRoot path (optional) and
+ * locates and opens a config file based on that information.  This
+ * function will fail if a command-line file name is specified and there
+ * is no %A, %R, or %S escape sequence in the effective search path.
+ *
+ * The return value is a pointer to the actual name of the file that was
+ * opened.  When no file is found, the return value is NULL.
+ *
+ * The escape sequences allowed in the search path are defined above.
+ */
+
+const char *
+xf86openConfigFile(const char *path, const char *cmdline, const char *projroot)
+{
+	const char	*configPath;	/* Config file pathname, else NULL */
+
+	configPath    = xf86openConfigFileIn(path, cmdline, projroot);
+
+	configBuf     = xf86confmalloc(CONFIG_BUF_LEN);
+	configRBuf    = xf86confmalloc(CONFIG_BUF_LEN);
+	if (configBuf == NULL || configRBuf == NULL) {
+		return (NULL);
+	}
+	configBufLen  = CONFIG_BUF_LEN;
+	configRBufLen = CONFIG_BUF_LEN;
+	configBuf[0]  = '\0';		/* Start with an empty line buffer */
+
+	return (configPath);
+}
+
+/*
+ * xf86confScanFree()
+ *
+ *    Release all dynamically allocated memory used to scan the
+ *    configuration file.
+ */
+void
+xf86confScanFree(void)
+{
+	xf86conffree (configPath);
+	configPath = NULL;
+	xf86conffree (configRBuf);
+	configRBuf = NULL;
+	xf86conffree (configBuf);
+	configBuf = NULL;
+}
+
+/*
+ * xf86closeConfigFile()
+ *
+ *    Release all dynamically allocated memory used to scan the
+ *    configuration file.  Close the input configuration file, else
+ *    discard the in-memory configuration text.
+ */
+void
+xf86closeConfigFile (void)
+{
+	xf86confScanFree();
+
+	if (configFile != NULL) {
+		fclose(configFile);
+		configFile = NULL;
+	} else {
+		builtinConfig = NULL;
+		builtinIndex = 0;
+	}
+}
+
+void
+xf86setBuiltinConfig(const char *config[])
+{
+	builtinConfig = config;
+	configPath = xf86configStrdup("<builtin configuration>");
+	configBuf     = xf86confmalloc (CONFIG_BUF_LEN);
+	configBufLen  = CONFIG_BUF_LEN;
+	configRBuf    = xf86confmalloc (CONFIG_BUF_LEN);
+	configRBufLen = CONFIG_BUF_LEN;
+	configBuf[0]  = '\0';		/* sanity ... */
+
+}
+
+void
+xf86parseError (char *format,...)
+{
+	va_list ap;
+
+	xf86printErrorF("Parse error on line %d of section %s in file %s\n\t",
+		 configLineNo, configSection, configPath);
+	va_start (ap, format);
+	VErrorF (format, ap);
+	va_end (ap);
+
+	ErrorF ("\n");
+}
+
+void
+xf86parseWarning (char *format,...)
+{
+	va_list ap;
+
+	xf86printErrorF("Parse warning on line %d of section %s in file %s\n\t",
+		 configLineNo, configSection, configPath);
+	va_start (ap, format);
+	VErrorF (format, ap);
+	va_end (ap);
+
+	ErrorF ("\n");
+}
+
+void
+xf86validationError (char *format, ...)
+{
+	va_list ap;
+
+	xf86printErrorF("Error in config file, %s\n\t", configPath);
+	va_start (ap, format);
+	VErrorF (format, ap);
+	va_end (ap);
+
+	ErrorF ("\n");
+}
+
+void
+xf86setSection (char *section)
+{
+	if (configSection)
+		xf86conffree(configSection);
+	configSection = xf86confmalloc(strlen (section) + 1);
+	strcpy (configSection, section);
+}
+
+/* 
+ * xf86getToken --
+ *  Lookup a string if it is actually a token in disguise.
+ */
+int
+xf86getStringToken (xf86ConfigSymTabRec * tab)
+{
+	return StringToToken (val.str, tab);
+}
+
+static int
+StringToToken (char *str, xf86ConfigSymTabRec * tab)
+{
+	int i;
+
+	for (i = 0; tab[i].token != -1; i++)
+	{
+		if (!xf86nameCompare (tab[i].name, str))
+			return tab[i].token;
+	}
+	return (ERROR_TOKEN);
+}
+
+
+/*
+ * xf86nameCompareResumable()
+ *
+ *    Compare two name-like strings pointed to by s1 and s2.  Ignore
+ *    alphabetic case and the characters, '_', ' ', and '\t'.  If s2
+ *    matches the initial characters of s1 then return a pointer to the
+ *    next character of s1 via s1resume (where further comparison could
+ *    be resumed).  Otherwise return NULL via s1resume.  Return the
+ *    conventional negative, zero, or positive value to indicate the
+ *    result of the basic comparison.
+ */
+static int
+xf86nameCompareResumable(
+	const char *s1, const char *s2, const char **s1resume)
+{
+	int		c1;		/* Normalized character from s1 */
+	int		c2;		/* Normalized character from s2 */
+
+	*s1resume = NULL;	/* Comparison has no resumption point yet */
+
+	if ((s1 == NULL) && (s2 == NULL)) {
+		return (0);
+	}
+	if (s1 == NULL) {
+		return (-1);	/* Behave as if NULL < non-NULL */
+	}
+	if (s2 == NULL) {
+		return (1);	/* Behave as if non-NULL > NULL */
+	}
+
+	do {
+		while ((*s1 == '_') || (*s1 == ' ') || (*s1 == '\t')) {
+			s1 += 1;
+		}
+		while ((*s2 == '_') || (*s2 == ' ') || (*s2 == '\t')) {
+			s2 += 1;
+		}
+		if (*s2 == '\0') {
+			/* s1 matches s2 or contains s2 as a prefix */
+			*s1resume = s1;
+			return (0);
+		}
+		c1 = tolower(*s1);
+		c2 = tolower(*s2);
+		s1++;
+		s2++;
+
+	}
+	while (c1 == c2);
+
+	/*
+	 * The strings don't match
+	 */
+	return (c1 - c2);
+}
+
+
+/*
+ * xf86nameCompare()
+ *
+ *    Compare two name-like strings pointed to by s1 and s2.  Ignore
+ *    alphabetic case and the characters, '_', ' ', and '\t'.  Return
+ *    the conventional negative, zero, or positive value to indicate the
+ *    result of the comparison.
+ */
+int
+xf86nameCompare(const char *s1, const char *s2)
+{
+	int		result;		/* Name comparison result */
+	const char	*s1resume;	/* Comparison resumption point */
+
+	/*
+	 * Compare the name strings, s1 and s2
+	 */
+	result = xf86nameCompareResumable(s1, s2, &s1resume);
+	if (result == 0) {
+		/*
+		 * Determine whether s2 matches all of or just part of s1
+		 *
+		 *    Note that s1resume will not be NULL if result is
+		 *    zero.
+		 */
+		result = *s1resume - '\0';
+	}
+
+	/*
+	 * Return the final result of the comparison
+	 */
+	return (result);
+}
+
+
+/*
+ * xf86lookupBoolOption()
+ *
+ *    Look up an option name in an array of known Boolean option names.
+ *    Note that a Boolean option name can have a "No" prefix.  If found,
+ *    return the array subscript of the Boolean option name.  Otherwise
+ *    return -1.
+ */
+static int
+xf86lookupBoolOption(
+	const char *const bool_option_names[], const char *opt_name)
+{
+	int		i;		/* Index into option name array */
+	const char	*s1resume;	/* Comparison resumption point */
+
+	/*
+	 * Look up the option name, which can be negated using a "No" prefix
+	 */
+	for (i = 0; bool_option_names[i] != NULL; i += 1) {
+		/*
+		 * See whether this is a plain instance of the option name
+		 */
+		if (xf86nameCompare(bool_option_names[i], opt_name) == 0) {
+			return (i);	/* Have a match */
+		}
+		
+		/*
+		 * See whether this is a negated instance of the option name
+		 */
+		(void) xf86nameCompareResumable(opt_name, "No", &s1resume);
+		if (s1resume == NULL) {
+			s1resume = opt_name; /* Doesn't have a "No" prefix */
+		}
+		if (xf86nameCompare(bool_option_names[i], s1resume) == 0) {
+			return (i);	/* Have a match */
+		}
+	}
+
+	/*
+	 * Not the name of a known Boolean option
+	 */
+	return (-1);
+}
+
+
+/*
+ * xf86optionNameCompare()
+ *
+ *    Compare two option names pointed to by s1 and s2.  Ignore
+ *    alphabetic case and the characters, '_', ' ', and '\t'.  For names
+ *    of known Boolean options (provided via bool_option_names[]), any
+ *    "No" prefix is ignored.  Return the usual negative, zero, or
+ *    positive values to indicate the results of the comparison.
+ *
+ *    To see why we want a list of known Boolean option names, consider
+ *    these ponderables:
+ *        * Can we tell from this hypothetical example whether "Tables"
+ *          is the name of a Boolean option, which could be negated?
+ *                  Option  "Tables" 1
+ *        * Can we tell whether "Notables" is the opposite of "Tables"?
+ *        * Is the opposite of the documented Boolean option,
+ *          "NoTrapSignals", intended to be "NoNoTrapSignals" or
+ *          "TrapSignals"?  Ditto for "NoPM" and "NoInt10".
+ */
+int
+xf86optionNameCompare(
+	const char *const bool_option_names[], const char *s1, const char *s2)
+{
+	int		i;		/* Index of option name, else -1 */
+
+	i = xf86lookupBoolOption(bool_option_names, s1);
+	if ((i != -1) && (i == xf86lookupBoolOption(bool_option_names, s2))) {
+		return (0);		/* Known Boolean option names match */
+	}
+	return (xf86nameCompare(s1, s2));
+}
+
+
+char *
+xf86addComment(char *cur, char *add)
+{
+	char *str;
+	int len, curlen, iscomment, hasnewline = 0, endnewline;
+
+	if (add == NULL || add[0] == '\0')
+		return (cur);
+
+	if (cur) {
+		curlen = strlen(cur);
+		if (curlen)
+		    hasnewline = cur[curlen - 1] == '\n';
+		eol_seen = 0;
+	}
+	else
+		curlen = 0;
+
+	str = add;
+	iscomment = 0;
+	while (*str) {
+	    if (*str != ' ' && *str != '\t')
+		break;
+	    ++str;
+	}
+	iscomment = (*str == '#');
+
+	len = strlen(add);
+	endnewline = add[len - 1] == '\n';
+	len +=  1 + iscomment + (!hasnewline) + (!endnewline) + eol_seen;
+
+	if ((str = xf86confrealloc(cur, len + curlen)) == NULL)
+		return (cur);
+
+	cur = str;
+
+	if (eol_seen || (curlen && !hasnewline))
+		cur[curlen++] = '\n';
+	if (!iscomment)
+		cur[curlen++] = '#';
+	strcpy(cur + curlen, add);
+	if (!endnewline)
+		strcat(cur, "\n");
+
+	return (cur);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/xf86Optrec.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,129 @@
+/* 
+ * 
+ * Copyright (c) 1997  Metro Link Incorporated
+ * 
+ * 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
+ * THE X CONSORTIUM 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.
+ * 
+ * Except as contained in this notice, the name of the Metro Link shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Metro Link.
+ * 
+ */
+/*
+ * Copyright (c) 1997-2001 by The XFree86 Project, 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
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+
+/* 
+ * This file contains the Option Record that is passed between the Parser,
+ * and Module setup procs.
+ */
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifndef _xf86Optrec_h_
+#define _xf86Optrec_h_
+#include <stdio.h>
+
+/* 
+ * all records that need to be linked lists should contain a GenericList as
+ * their first field.
+ */
+typedef struct generic_list_rec
+{
+	void *next;
+}
+GenericListRec, *GenericListPtr, *glp;
+
+/*
+ * All options are stored using this data type.
+ */
+typedef struct
+{
+	GenericListRec list;
+	char *opt_name;
+	char *opt_val;
+	int opt_used;
+	char *opt_comment;
+#if defined(SMI_FBCONFIG)
+	void *opt_line_er;	/* Config file line External Rep, else undef */
+#endif
+}
+XF86OptionRec, *XF86OptionPtr;
+
+
+#if defined(SMI_FBCONFIG)
+XF86OptionPtr xf86addNewOptionOrValue(
+	XF86OptionPtr	head,		/* Ptr to head of option list */
+	char		*name,		/* Ptr to new option name string */
+	char		*val,		/* Ptr to new option value string */
+	int		used,		/* Not used w/ SMI_FBCONFIG */
+	void		*end_line_er);	/* Ptr to End[Sub]Section, else NULL */
+#endif
+
+XF86OptionPtr xf86addNewOption(XF86OptionPtr head, char *name, char *val);
+XF86OptionPtr xf86optionListDup(XF86OptionPtr opt);
+void xf86optionListFree(XF86OptionPtr opt);
+char *xf86optionName(XF86OptionPtr opt);
+char *xf86optionValue(XF86OptionPtr opt);
+XF86OptionPtr xf86newOption(char *name, char *value);
+XF86OptionPtr xf86nextOption(XF86OptionPtr list);
+XF86OptionPtr xf86findOption(XF86OptionPtr list, const char *name);
+char *xf86findOptionValue(XF86OptionPtr list, const char *name);
+//int xf86findOptionBoolean (XF86OptionPtr, const char *, int);
+XF86OptionPtr xf86optionListCreate(const char **options, int count, int used);
+XF86OptionPtr xf86optionListMerge(XF86OptionPtr head, XF86OptionPtr tail);
+char *xf86configStrdup (const char *s);
+int xf86nameCompare (const char *s1, const char *s2);
+int xf86optionNameCompare (
+	const char * const bool_option_names[], const char *s1, const char *s2);
+char *xf86uLongToString(unsigned long i);
+void xf86debugListOptions(XF86OptionPtr);
+XF86OptionPtr xf86parseOption(XF86OptionPtr head);
+void xf86printOption(
+	FILE *fp, XF86OptionPtr list, const char * const whitespace[]);
+void xf86printOptionList(
+	FILE *fp, XF86OptionPtr list, const char * const whitespace[]);
+
+
+#endif /* _xf86Optrec_h_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/xf86Parser.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,573 @@
+/* 
+ * 
+ * Copyright (c) 1997  Metro Link Incorporated
+ * 
+ * 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
+ * THE X CONSORTIUM 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.
+ * 
+ * Except as contained in this notice, the name of the Metro Link shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Metro Link.
+ * 
+ */
+/*
+ * Copyright (c) 1997-2003 by The XFree86 Project, 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
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+
+/* 
+ * This file contains the external interfaces for the XFree86 configuration
+ * file parser.
+ */
+
+#ifndef _xf86Parser_h_
+#define _xf86Parser_h_
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86Optrec.h"
+
+#if defined(SMI_FBCONFIG)
+#include "fbc_line_er.h"	/* External Representation of config lines */
+#endif
+
+#define HAVE_PARSER_DECLS
+
+typedef struct
+{
+	char *file_logfile;
+	char *file_rgbpath;
+	char *file_modulepath;
+	char *file_inputdevs;
+	char *file_fontpath;
+	char *file_comment;
+}
+XF86ConfFilesRec, *XF86ConfFilesPtr;
+
+/* Values for load_type */
+#define XF86_LOAD_MODULE	0
+#define XF86_LOAD_DRIVER	1
+
+typedef struct
+{
+	GenericListRec list;
+	int load_type;
+	char *load_name;
+	XF86OptionPtr load_opt;
+	char *load_comment;
+        int ignore;
+}
+XF86LoadRec, *XF86LoadPtr;
+
+typedef struct
+{
+	XF86LoadPtr mod_load_lst;
+	char *mod_comment;
+}
+XF86ConfModuleRec, *XF86ConfModulePtr;
+
+#define CONF_IMPLICIT_KEYBOARD	"Implicit Core Keyboard"
+
+#define CONF_IMPLICIT_POINTER	"Implicit Core Pointer"
+
+/*
+ * ModeLine / Mode-EndMode flag mask bits
+ */
+#define XF86CONF_PHSYNC    0x0001
+#define XF86CONF_NHSYNC    0x0002
+#define XF86CONF_PVSYNC    0x0004
+#define XF86CONF_NVSYNC    0x0008
+#define XF86CONF_INTERLACE 0x0010
+#define XF86CONF_DBLSCAN   0x0020
+#define XF86CONF_CSYNC     0x0040
+#define XF86CONF_PCSYNC    0x0080
+#define XF86CONF_NCSYNC    0x0100
+#define XF86CONF_HSKEW     0x0200	/* hskew provided */
+#define XF86CONF_BCAST     0x0400
+#define XF86CONF_CUSTOM    0x0800	/* timing numbers customized by editor */
+#define XF86CONF_VSCAN     0x1000
+
+/*
+ * ModeLine / Mode-EndMode entry
+ */
+typedef struct
+{
+	GenericListRec list;		/* Next ModeLine / Mode-EndMode */
+	char *ml_identifier;		/* Mode name */
+	int ml_clock;			/* DotClock */
+	int ml_hdisplay;		/* HTimings ... */
+	int ml_hsyncstart;
+	int ml_hsyncend;
+	int ml_htotal;
+	int ml_vdisplay;		/* VTimings ... */
+	int ml_vsyncstart;
+	int ml_vsyncend;
+	int ml_vtotal;
+	int ml_vscan;			/* VScan */
+	int ml_flags;			/* Flags */
+	int ml_hskew;			/* HSkew */
+	char *ml_comment;
+	int ml_verbose;			/* FALSE=>ModeLine, TRUE=>Mode */
+#if defined(SMI_FBCONFIG)
+	fbc_line_elem_t	*ml_dotclock_line_er;	/* DotClock line Extnl Rep */
+	fbc_line_elem_t	*ml_htimings_line_er;	/* HTimings line Extnl Rep */
+	fbc_line_elem_t	*ml_vtimings_line_er;	/* VTimings line Extnl Rep */
+	fbc_line_elem_t	*ml_flags_line_er;	/* Flags Ext Rep, else NULL */
+	fbc_line_elem_t	*ml_hskew_line_er;	/* HSkew line External Rep */
+	fbc_line_elem_t	*ml_vscan_line_er;	/* VScan line External Rep */
+	fbc_line_elem_t	*ml_end_line_er;	/* EndMode line Extnl Rep */
+#endif
+}
+XF86ConfModeLineRec, *XF86ConfModeLinePtr;
+
+typedef struct
+{
+	GenericListRec list;
+	char *vp_identifier;
+	XF86OptionPtr vp_option_lst;
+	char *vp_comment;
+}
+XF86ConfVideoPortRec, *XF86ConfVideoPortPtr;
+
+typedef struct
+{
+	GenericListRec list;
+	char *va_identifier;
+	char *va_vendor;
+	char *va_board;
+	char *va_busid;
+	char *va_driver;
+	XF86OptionPtr va_option_lst;
+	XF86ConfVideoPortPtr va_port_lst;
+	char *va_fwdref;
+	char *va_comment;
+}
+XF86ConfVideoAdaptorRec, *XF86ConfVideoAdaptorPtr;
+
+#define CONF_MAX_HSYNC 8
+#define CONF_MAX_VREFRESH 8
+
+typedef struct
+{
+	float hi, lo;
+}
+parser_range;
+
+typedef struct
+{
+	int red, green, blue;
+}
+parser_rgb;
+
+/*
+ * Modes section
+ */
+typedef struct
+{
+	GenericListRec list;
+	char *modes_identifier;
+	XF86ConfModeLinePtr mon_modeline_lst;
+	char *modes_comment;
+#if defined(SMI_FBCONFIG)
+	fbc_line_elem_t	*begin_line_er;	/* Begin section line Extnl Rep */
+	fbc_line_elem_t	*end_line_er;	/* EndSection line Extnl Rep */
+#endif
+}
+XF86ConfModesRec, *XF86ConfModesPtr;
+
+/*
+ * UseModes entry (for Monitor section)
+ */
+typedef struct
+{
+	GenericListRec list;
+	char *ml_modes_str;
+	XF86ConfModesPtr ml_modes;
+#if defined(SMI_FBCONFIG)
+	fbc_line_elem_t	*line_er;	/* UseModes line Extnl Rep */
+#endif
+}
+XF86ConfModesLinkRec, *XF86ConfModesLinkPtr;
+
+/*
+ * Monitor section
+ */
+typedef struct
+{
+	GenericListRec list;
+	char *mon_identifier;
+	char *mon_vendor;
+	char *mon_modelname;
+	int mon_width;				/* in mm */
+	int mon_height;				/* in mm */
+	XF86ConfModeLinePtr mon_modeline_lst;
+	int mon_n_hsync;
+	parser_range mon_hsync[CONF_MAX_HSYNC];
+	int mon_n_vrefresh;
+	parser_range mon_vrefresh[CONF_MAX_VREFRESH];
+	float mon_gamma_red;
+	float mon_gamma_green;
+	float mon_gamma_blue;
+	XF86OptionPtr mon_option_lst;
+	XF86ConfModesLinkPtr mon_modes_sect_lst;
+	char *mon_comment;
+#if defined(SMI_FBCONFIG)
+	fbc_line_elem_t	*mon_gamma_line_er;	/* Gamma Ext Rep, else NULL */
+	fbc_line_elem_t	*mon_usemodes_line_er;	/* UseModes line Extnl Rep */
+	fbc_line_elem_t	*mon_end_line_er;	/* EndSection line Extnl Rep */
+#endif
+}
+XF86ConfMonitorRec, *XF86ConfMonitorPtr;
+
+#define CONF_MAXDACSPEEDS 4
+#define CONF_MAXCLOCKS    128
+
+/*
+ * Device section
+ */
+typedef struct
+{
+	GenericListRec list;
+	char *dev_identifier;
+	char *dev_vendor;
+	char *dev_board;
+	char *dev_chipset;
+	char *dev_busid;
+	char *dev_card;
+	char *dev_driver;
+	char *dev_ramdac;
+	int dev_dacSpeeds[CONF_MAXDACSPEEDS];
+	int dev_videoram;
+	int dev_textclockfreq;
+	unsigned long dev_bios_base;
+	unsigned long dev_mem_base;
+	unsigned long dev_io_base;
+	char *dev_clockchip;
+	int dev_clocks;
+	int dev_clock[CONF_MAXCLOCKS];
+	int dev_chipid;
+	int dev_chiprev;
+	int dev_irq;
+	int dev_screen;
+	XF86OptionPtr dev_option_lst;
+	char *dev_comment;
+#if defined(SMI_FBCONFIG)
+	fbc_line_elem_t	*dev_end_line_er;	/* EndSection line Extnl Rep */
+#endif
+}
+XF86ConfDeviceRec, *XF86ConfDevicePtr;
+
+/*
+ * Modes entry list element of a Display subsection of a Screen section
+ */
+typedef struct
+{
+	GenericListRec list;
+	char *mode_name;
+}
+XF86ModeRec, *XF86ModePtr;
+
+/*
+ * Display subsection of Screen section
+ */
+typedef struct
+{
+	GenericListRec list;
+	int disp_frameX0;
+	int disp_frameY0;
+	int disp_virtualX;
+	int disp_virtualY;
+	int disp_monitor_seen;		/* TRUE => Monitor entry present */
+	int disp_monitor_num;		/* Monitor number */
+	int disp_depth;
+	int disp_bpp;
+	char *disp_visual;
+	parser_rgb disp_weight;
+	parser_rgb disp_black;
+	parser_rgb disp_white;
+	XF86ModePtr disp_mode_lst;
+	XF86OptionPtr disp_option_lst;
+	char *disp_comment;
+#if defined(SMI_FBCONFIG)
+	fbc_line_elem_t	*disp_modes_line_er;	/* Modes line External Rep */
+	fbc_line_elem_t	*disp_end_line_er;	/* EndSubSection Extnl Rep */
+#endif
+}
+XF86ConfDisplayRec, *XF86ConfDisplayPtr;
+
+/*
+ * Monitor entry of Screen section
+ */
+typedef struct
+{
+	GenericListRec list;		/* Ptr to next Monitor entry link */
+	int scrn_monitor_num_seen;	/* TRUE => Monitor number present */
+	int scrn_monitor_num;		/* Monitor number (may be optional) */
+	char *scrn_monitor_name;	/* Name of Monitor section */
+	XF86ConfMonitorPtr scrn_monitor; /* Ptr to named Monitor section */
+}
+XF86ConfScrnMonitorEntryRec, *XF86ConfScrnMonitorEntryPtr;
+
+typedef struct
+{
+	XF86OptionPtr flg_option_lst;
+	char *flg_comment;
+}
+XF86ConfFlagsRec, *XF86ConfFlagsPtr;
+
+/*
+ * VideoAdaptor entry of Screen section
+ */
+typedef struct
+{
+	GenericListRec list;
+	char *al_adaptor_str;
+	XF86ConfVideoAdaptorPtr al_adaptor;
+}
+XF86ConfAdaptorLinkRec, *XF86ConfAdaptorLinkPtr;
+
+/*
+ * Screen section
+ */
+typedef struct
+{
+	GenericListRec list;
+	char *scrn_identifier;
+	char *scrn_obso_driver;
+	int scrn_defaultdepth;
+	int scrn_defaultbpp;
+	int scrn_defaultfbbpp;
+	XF86ConfScrnMonitorEntryPtr scrn_monitor_lst; /* Monitor entry list */
+	char *scrn_device_str;
+	XF86ConfDevicePtr scrn_device;
+	XF86ConfAdaptorLinkPtr scrn_adaptor_lst;
+	XF86ConfDisplayPtr scrn_display_lst;
+	XF86OptionPtr scrn_option_lst;
+	char *scrn_comment;
+#if defined(SMI_FBCONFIG)
+	fbc_line_elem_t	*scrn_defaultdepth_line_er; /* DefaultDepth line ER */
+	fbc_line_elem_t	*scrn_end_line_er;	/* EndSection line Extnl Rep */
+#endif
+}
+XF86ConfScreenRec, *XF86ConfScreenPtr;
+
+typedef struct
+{
+	GenericListRec list;
+	char *inp_identifier;
+	char *inp_driver;
+	XF86OptionPtr inp_option_lst;
+	char *inp_comment;
+}
+XF86ConfInputRec, *XF86ConfInputPtr;
+
+typedef struct
+{
+	GenericListRec list;
+	XF86ConfInputPtr iref_inputdev;
+	char *iref_inputdev_str;
+	XF86OptionPtr iref_option_lst;
+}
+XF86ConfInputrefRec, *XF86ConfInputrefPtr;
+
+/* Values for adj_where */
+#define CONF_ADJ_OBSOLETE	-1
+#define CONF_ADJ_ABSOLUTE	0
+#define CONF_ADJ_RIGHTOF	1
+#define CONF_ADJ_LEFTOF		2
+#define CONF_ADJ_ABOVE		3
+#define CONF_ADJ_BELOW		4
+#define CONF_ADJ_RELATIVE	5
+
+typedef struct
+{
+	GenericListRec list;
+	int adj_scrnum;
+	XF86ConfScreenPtr adj_screen;
+	char *adj_screen_str;
+	XF86ConfScreenPtr adj_top;
+	char *adj_top_str;
+	XF86ConfScreenPtr adj_bottom;
+	char *adj_bottom_str;
+	XF86ConfScreenPtr adj_left;
+	char *adj_left_str;
+	XF86ConfScreenPtr adj_right;
+	char *adj_right_str;
+	int adj_where;
+	int adj_x;
+	int adj_y;
+	char *adj_refscreen;
+}
+XF86ConfAdjacencyRec, *XF86ConfAdjacencyPtr;
+
+typedef struct
+{
+	GenericListRec list;
+	char *inactive_device_str;
+	XF86ConfDevicePtr inactive_device;
+}
+XF86ConfInactiveRec, *XF86ConfInactivePtr;
+
+typedef struct
+{
+	GenericListRec list;
+	char *lay_identifier;
+	XF86ConfAdjacencyPtr lay_adjacency_lst;
+	XF86ConfInactivePtr lay_inactive_lst;
+	XF86ConfInputrefPtr lay_input_lst;
+	XF86OptionPtr lay_option_lst;
+	char *lay_comment;
+}
+XF86ConfLayoutRec, *XF86ConfLayoutPtr;
+
+typedef struct 
+{ 
+	GenericListRec list; 
+	char *vs_name;
+	char *vs_identifier;
+	XF86OptionPtr vs_option_lst;
+	char *vs_comment;
+}
+XF86ConfVendSubRec, *XF86ConfVendSubPtr;
+
+typedef struct
+{
+	GenericListRec list;
+	char *vnd_identifier;
+	XF86OptionPtr vnd_option_lst;
+	XF86ConfVendSubPtr vnd_sub_lst;
+	char *vnd_comment;
+}
+XF86ConfVendorRec, *XF86ConfVendorPtr;
+
+typedef struct
+{
+	GenericListRec list;
+	int buf_count;
+	int buf_size;
+	char *buf_flags;
+	char *buf_comment;
+}
+XF86ConfBuffersRec, *XF86ConfBuffersPtr;
+
+typedef struct
+{
+	char *dri_group_name;
+	int dri_group;
+	int dri_mode;
+	XF86ConfBuffersPtr dri_buffers_lst;
+	char *dri_comment;
+}
+XF86ConfDRIRec, *XF86ConfDRIPtr;
+
+typedef struct
+{
+	XF86OptionPtr ext_option_lst;
+	char *extensions_comment;
+}
+XF86ConfExtensionsRec, *XF86ConfExtensionsPtr;
+
+typedef struct
+{
+	XF86ConfFilesPtr conf_files;
+	XF86ConfModulePtr conf_modules;
+	XF86ConfFlagsPtr conf_flags;
+	XF86ConfVideoAdaptorPtr conf_videoadaptor_lst;
+	XF86ConfModesPtr conf_modes_lst;
+	XF86ConfMonitorPtr conf_monitor_lst;
+	XF86ConfDevicePtr conf_device_lst;
+	XF86ConfScreenPtr conf_screen_lst;
+	XF86ConfInputPtr conf_input_lst;
+	XF86ConfLayoutPtr conf_layout_lst;
+	XF86ConfVendorPtr conf_vendor_lst;
+	XF86ConfDRIPtr conf_dri;
+	XF86ConfExtensionsPtr conf_extensions;
+	char *conf_comment;
+}
+XF86ConfigRec, *XF86ConfigPtr;
+
+typedef struct
+{
+	int token;			/* id of the token */
+	char *name;			/* pointer to the LOWERCASED name */
+}
+xf86ConfigSymTabRec, *xf86ConfigSymTabPtr;
+
+/*
+ * prototypes for public functions
+ */
+extern const char *xf86openConfigFile (const char *, const char *,
+					const char *);
+extern void xf86setBuiltinConfig(const char *config[]);
+extern XF86ConfigPtr xf86readConfigFile (void);
+
+/* scan.c */
+#if defined(SMI_FBCONFIG)
+extern const char *xf86openConfigFileIn(
+	const char *path, const char *cmdline, const char *projroot);
+void xf86confScanFree(void);
+#endif
+extern void xf86closeConfigFile (void);
+extern void xf86freeConfig (XF86ConfigPtr p);
+
+extern int xf86writeConfigFile (const char *, XF86ConfigPtr);
+XF86ConfDevicePtr xf86findDevice(const char *ident, XF86ConfDevicePtr p);
+XF86ConfLayoutPtr xf86findLayout(const char *name, XF86ConfLayoutPtr list);
+XF86ConfMonitorPtr xf86findMonitor(const char *ident, XF86ConfMonitorPtr p);
+XF86ConfModesPtr xf86findModes(const char *ident, XF86ConfModesPtr p);
+XF86ConfModeLinePtr xf86findModeLine(const char *ident, XF86ConfModeLinePtr p);
+XF86ConfScreenPtr xf86findScreen(const char *ident, XF86ConfScreenPtr p);
+XF86ConfInputPtr xf86findInput(const char *ident, XF86ConfInputPtr p);
+XF86ConfInputPtr xf86findInputByDriver(const char *driver, XF86ConfInputPtr p);
+XF86ConfVendorPtr xf86findVendor(const char *name, XF86ConfVendorPtr list);
+XF86ConfVideoAdaptorPtr xf86findVideoAdaptor(const char *ident,
+						XF86ConfVideoAdaptorPtr p);
+
+GenericListPtr xf86addListItem(GenericListPtr head, GenericListPtr c_new);
+int xf86itemNotSublist(GenericListPtr list_1, GenericListPtr list_2);
+
+int xf86pathIsAbsolute(const char *path);
+int xf86pathIsSafe(const char *path);
+char *xf86addComment(char *cur, char *add);
+
+#endif /* _xf86Parser_h_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconf_xorg/xf86/xf86tokens.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,279 @@
+/* 
+ * 
+ * Copyright (c) 1997  Metro Link Incorporated
+ * 
+ * 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
+ * THE X CONSORTIUM 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.
+ * 
+ * Except as contained in this notice, the name of the Metro Link shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Metro Link.
+ * 
+ */
+/*
+ * Copyright (c) 1997-2003 by The XFree86 Project, 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
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifndef _xf86_tokens_h
+#define _xf86_tokens_h
+
+/* Undefine symbols that some OSs might define */
+#undef IOBASE
+
+/* 
+ * Each token should have a unique value regardless of the section
+ * it is used in.
+ */
+
+typedef enum {
+    /* errno-style tokens */
+    EOF_TOKEN		= -4,
+    LOCK_TOKEN		= -3,
+    ERROR_TOKEN		= -2,
+
+    /* value type tokens */
+    NUMBER		= 1,
+    STRING,
+
+    /* Tokens that can appear in many sections */
+    SECTION,
+    SUBSECTION,
+    ENDSECTION,
+    ENDSUBSECTION,
+    IDENTIFIER,
+    VENDOR,
+    DASH,
+    COMMA,
+    OPTION,
+    COMMENT,
+
+    /* Frequency units */
+    HRZ,
+    KHZ,
+    MHZ,
+
+    /* File tokens */
+    FONTPATH,
+    RGBPATH,
+    MODULEPATH,
+    INPUTDEVICES,
+    LOGFILEPATH,
+
+    /* Server Flag tokens.  These are deprecated in favour of generic Options */
+    NOTRAPSIGNALS,
+    DONTZAP,
+    DONTZOOM,
+    DISABLEVIDMODE,
+    ALLOWNONLOCAL,
+    DISABLEMODINDEV,
+    MODINDEVALLOWNONLOCAL,
+    ALLOWMOUSEOPENFAIL,
+    BLANKTIME,
+    STANDBYTIME,
+    SUSPENDTIME,
+    OFFTIME,
+    DEFAULTLAYOUT,
+
+    /* Monitor tokens */
+    MODEL,
+    MODELINE,
+    DISPLAYSIZE,
+    HORIZSYNC,
+    VERTREFRESH,
+    MODE,
+    GAMMA,
+    USEMODES,
+
+    /* Modes tokens */
+    /* no new ones */
+
+    /* Mode tokens */
+    DOTCLOCK,
+    HTIMINGS,
+    VTIMINGS,
+    FLAGS,
+    HSKEW,
+    BCAST,
+    VSCAN,
+    ENDMODE,
+
+    /* Screen tokens */
+    OBSDRIVER,
+    MDEVICE,
+    MONITOR,
+    SCREENNO,
+    DEFAULTDEPTH,
+    DEFAULTBPP,
+    DEFAULTFBBPP,
+    
+    /* VideoAdaptor tokens */
+    VIDEOADAPTOR,
+
+    /* Mode timing tokens */
+    TT_INTERLACE,
+    TT_PHSYNC,
+    TT_NHSYNC,
+    TT_PVSYNC,
+    TT_NVSYNC,
+    TT_CSYNC,
+    TT_PCSYNC,
+    TT_NCSYNC,
+    TT_DBLSCAN,
+    TT_HSKEW,
+    TT_BCAST,
+    TT_VSCAN,
+    TT_CUSTOM,
+
+    /* Module tokens */
+    LOAD,
+    LOAD_DRIVER,
+    
+    /* Device tokens */
+    DRIVER,
+    CHIPSET,
+    CLOCKS,
+    VIDEORAM,
+    BOARD,
+    IOBASE,
+    RAMDAC,
+    DACSPEED,
+    BIOSBASE,
+    MEMBASE,
+    CLOCKCHIP,
+    CHIPID,
+    CHIPREV,
+    CARD,
+    BUSID,
+    TEXTCLOCKFRQ,
+    IRQ,
+
+    /* Keyboard tokens */
+    AUTOREPEAT,
+    XLEDS,
+    KPROTOCOL,
+    XKBKEYMAP,
+    XKBCOMPAT,
+    XKBTYPES,
+    XKBKEYCODES,
+    XKBGEOMETRY,
+    XKBSYMBOLS,
+    XKBDISABLE,
+    PANIX106,
+    XKBRULES,
+    XKBMODEL,
+    XKBLAYOUT,
+    XKBVARIANT,
+    XKBOPTIONS,
+    /* The next two have become ServerFlags options */
+    VTINIT,
+    VTSYSREQ,
+    /* Obsolete keyboard tokens */
+    SERVERNUM,
+    LEFTALT,
+    RIGHTALT,
+    SCROLLLOCK_TOK,
+    RIGHTCTL,
+    /* arguments for the above obsolete tokens */
+    CONF_KM_META,
+    CONF_KM_COMPOSE,
+    CONF_KM_MODESHIFT,
+    CONF_KM_MODELOCK,
+    CONF_KM_SCROLLLOCK,
+    CONF_KM_CONTROL,
+
+    /* Pointer tokens */
+    EMULATE3,
+    BAUDRATE,
+    SAMPLERATE,
+    PRESOLUTION,
+    CLEARDTR,
+    CLEARRTS,
+    CHORDMIDDLE,
+    PROTOCOL,
+    PDEVICE,
+    EM3TIMEOUT,
+    DEVICE_NAME,
+    ALWAYSCORE,
+    PBUTTONS,
+    ZAXISMAPPING,
+
+    /* Pointer Z axis mapping tokens */
+    XAXIS,
+    YAXIS,
+
+    /* Display tokens */
+    MODES,
+    VIEWPORT,
+    VIRTUAL,
+    VISUAL,
+    BLACK_TOK,
+    WHITE_TOK,
+    DEPTH,
+    BPP,
+    WEIGHT,
+    
+    /* Layout Tokens */
+    SCREEN,
+    INACTIVE,
+    INPUTDEVICE,
+
+    /* Adjaceny Tokens */
+    RIGHTOF,
+    LEFTOF,
+    ABOVE,
+    BELOW,
+    RELATIVE,
+    ABSOLUTE,
+
+    /* Vendor Tokens */
+    VENDORNAME,
+
+    /* DRI Tokens */
+    GROUP,
+    BUFFERS
+} ParserTokens;
+
+#endif /* _xf86_tokens_h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconfig/Makefile	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,59 @@
+#
+# Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS 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.
+#
+
+
+BIN	= fbconfig
+INSTALL_BIN_DIR = $(DESTDIR)/usr/sbin
+
+HEADERS	=
+CSOURCES=fbconfig.c
+OBJECTS	=$(CSOURCES:.c=.o)
+
+INCPATHS=-I../gfx_common/include
+CFLAGS += $(INCPATHS)
+
+LIBPATHS=-lscf
+LFLAGS	=
+
+
+all:	$(BIN)
+
+$(BIN):	$(OBJECTS)
+	$(CC) $^ $(LFLAGS) $(LIBPATHS) -o $@
+
+%.o:	%.c
+	$(CC) $(CFLAGS) -c $< -o $@
+
+%.lint: %.c
+	$(LINT.c) -DDEBUG_FB $(CFLAGS) $(LIBPATHS) $<
+
+clean:
+	-rm -f $(OBJECTS)
+
+clobber: clean
+	-rm -f $(BIN)
+
+install: all
+	$(INSTALL) -m 0555 $(BIN) $(INSTALL_BIN_DIR)
+
+# End of Makefile
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/fbconfig/fbconfig.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,1790 @@
+/*
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 <sys/param.h>		/* MAXPATHLEN */
+#include <sys/types.h>
+#include <libscf.h>		/* Service Configuration Facility */
+#include <stdarg.h>		/* va_end(), va_start(), vfprintf() */
+#include <stdio.h>		/* fprintf(), printf() */
+#include <stdlib.h>		/* exit(), free(), malloc() */
+#include <string.h>		/* strerror(), str[l]cpy(), strstr(), ... */
+#include <unistd.h>		/* close(), ioctl() */
+#include <dirent.h>		/* opendir(), readdir(), closedir() */
+#include <sys/stat.h>		/* stat() */
+#include <sys/visual_io.h>	/* VISUAL environment device identifier */
+#include <fcntl.h>		/* open() */
+#include <nl_types.h>
+#include <errno.h>		/* errno */
+
+#include "gfx_common.h"		/* Frame buffer model name */
+
+
+#define	_DEBUG_FB		/* _DEBUG_FB is merely DEBUG_FB disabled */
+
+
+/*
+ * Frame buffer device file names  (/dev/fb[0]?, /dev/fbs/[a-z]fb[0-9][ab]?)
+ */
+#define	DEVICE_SYMLINK_DIR	"/dev"		/* Device symlink directory */
+#define	DEVICE_SYMLINK_NAME	"fb"		/* Device symlink name */
+#define	DEVICE_SYMLINK_NAME_0	DEVICE_SYMLINK_NAME "0"
+#define	DEVICE_SYMLINK_PATH	DEVICE_SYMLINK_DIR "/" DEVICE_SYMLINK_NAME
+#define	DEVICE_SYMLINK_PATH_0	DEVICE_SYMLINK_DIR "/" DEVICE_SYMLINK_NAME_0
+
+#define	DEVICE_DIR		"/dev/fbs"	/* Graphics device directory */
+
+#define	MAX_DEV_PATH_LEN	128		/* Max device path length */
+
+#define	STREAM_SUFFIX_CHARS	"ab"		/* Dev stream suffix chars */
+#define MAX_SUFFIX_LIST_LEN	16		/* Ample room for " [a|b]" */
+
+/*
+ * Frame buffer configuration software directory
+ */
+#define	FBC_LIB_DIR	"/usr/lib/fbconfig"	/* fbconfig software dir */
+
+/*
+ * fbconfig invokes the dcmtool script (which in turn invokes java)
+ */
+#define	DCMTOOL_LOCATION FBC_LIB_DIR "/SUNWdcm/bin/dcmtool"
+
+
+/* globals */
+static nl_catd		catfd;		/* Message catalog fd (obsolete) */
+
+/*
+ * PrintError()
+ *
+ *    Write a variable format error message to stderr, prefixed by the
+ *    program name.
+ */
+
+static
+void
+PrintError(const char *format, ...)
+{
+	va_list		ap;		/* Variable argument pointer */
+
+	va_start(ap, format);
+	fprintf(stderr, "fbconfig: ");
+	vfprintf(stderr, format, ap);
+	fprintf(stderr, "\n");
+	va_end(ap);
+
+}	/* PrintError() */
+
+
+/*
+ * IdentifyXServer()
+ *
+ *    Determine what X server is currently configured (Xsun, Xorg, ...).
+ *
+ *    Note that this is not necessarily the X server that is currently
+ *    running.
+ *
+ *    Related svccfg(1M) "set" and "list" commands:
+ *
+ *        svccfg -s svc:/application/x11/x11-server \
+ *                        setprop options/server=/usr/openwin/bin/Xsun
+ *        svccfg -s svc:/application/x11/x11-server \
+ *                        setprop options/server=/usr/X11/bin/Xorg
+ *
+ *        svccfg -s svc:/application/x11/x11-server listprop 'options/server'
+ */
+
+#define	XSRV_SERVICE_NAME	"application/x11/x11-server"
+#define	XSRV_PROP_GROUP_NAME	"options"
+#define	XSRV_PROP_NAME		"server"
+
+typedef enum {
+	XSERVER_UNKNOWN = -1,		/* No idea */
+	XSERVER_XSUN,			/* Xsun server */
+	XSERVER_XORG			/* Xorg server */
+} xserv_t;
+
+#define GFX_DEV_M64     0x0001
+#define GFX_DEV_FFB	0x0002
+#define GFX_DEV_AFB	0x0004
+#define GFX_DEV_IFB	0x0008
+#define GFX_DEV_JFB	0x0010
+#define GFX_DEV_PFB	0x0100
+#define GFX_DEV_NFB	0x0200
+#define GFX_DEV_EFB	0x0400
+#define GFX_DEV_KFB	0x0800
+#define GFX_DEV_AST	0x1000
+
+#define GFX_DEV_XSUN	GFX_DEV_M64 | GFX_DEV_FFB | GFX_DEV_AFB | GFX_DEV_IFB | \
+			GFX_DEV_JFB | GFX_DEV_PFB | GFX_DEV_NFB | GFX_DEV_EFB | GFX_DEV_KFB
+
+#if OSVER==510
+#define GFX_DEV_XORG	GFX_DEV_PFB | GFX_DEV_NFB | GFX_DEV_EFB | GFX_DEV_AST
+#else
+#define GFX_DEV_XORG	GFX_DEV_PFB | GFX_DEV_NFB | GFX_DEV_EFB | GFX_DEV_KFB | GFX_DEV_AST
+#endif
+
+char *xserver_str[]  = {"Xsun", "Xorg"};
+char *xserver_path[] = {"/usr/openwin/bin/Xsun", "/usr/X11/bin/Xorg"};
+unsigned int xserver_device[] = { GFX_DEV_XSUN, GFX_DEV_XORG };
+
+static
+xserv_t
+IdentifyXServer(void)
+{
+	const char	*filename;	/* Ptr to X server simple filename */
+	char		pathname[MAXPATHLEN]; /* X server pathname */
+	scf_property_t	*prop;		/* SCF property */
+	scf_propertygroup_t *prop_group; /* SCF property group */
+	scf_handle_t	*scf_handle;	/* SCF handle */
+	scf_scope_t	*scope;		/* SCF scope */
+	scf_service_t	*service;	/* SCF service */
+	scf_value_t	*value;		/* SCF property value */
+	xserv_t		x_server;	/* Returned X server identity */
+
+	/*
+	 * X, the unknown
+	 */
+	x_server = XSERVER_UNKNOWN;
+
+	/*
+	 * Allocate and initialize the necessary SCF data structures
+	 */
+	scf_handle = scf_handle_create(SCF_VERSION);
+	scope      = scf_scope_create(scf_handle);
+	service    = scf_service_create(scf_handle);
+	prop_group = scf_pg_create(scf_handle);
+	prop       = scf_property_create(scf_handle);
+	value      = scf_value_create(scf_handle);
+	if ((value      == NULL) ||
+	    (prop       == NULL) ||
+	    (prop_group == NULL) ||
+	    (service    == NULL) ||
+	    (scope      == NULL) ||
+	    (scf_handle == NULL)) {
+#ifdef DEBUG_FB
+		PrintError("SCF resource creation, %s",
+				scf_strerror(scf_error()));
+#endif
+		goto clean_up;
+	}
+
+	/*
+	 * Retrieve the Nul-terminated X server pathname string
+	 */
+	if ((scf_handle_bind(scf_handle)                              == -1) ||
+	    (scf_handle_get_scope(scf_handle, SCF_SCOPE_LOCAL, scope) == -1) ||
+	    (scf_scope_get_service(scope, XSRV_SERVICE_NAME, service) == -1) ||
+	    (scf_service_get_pg(service, XSRV_PROP_GROUP_NAME, prop_group)
+								      == -1) ||
+	    (scf_pg_get_property(prop_group, XSRV_PROP_NAME, prop)    == -1) ||
+	    (scf_property_get_value(prop, value)                      == -1) ||
+	    (scf_value_get_astring(value, pathname, sizeof(pathname)) == -1)) {
+#ifdef DEBUG_FB
+		PrintError("SCF value retrieval, %s",
+				scf_strerror(scf_error()));
+#endif
+		goto clean_up;
+	}
+
+	/*
+	 * Evaluate the simple filename
+	 */
+	filename = strrchr(pathname, '/');
+	if (filename == NULL) {
+		filename = pathname;
+	} else {
+		filename += 1;
+	}
+	if (strcmp(filename, "Xsun") == 0) {
+		x_server = XSERVER_XSUN;
+	} else
+	if (strcmp(filename, "Xorg") == 0) {
+		x_server = XSERVER_XORG;
+	}
+
+	/*
+	 * Destroy our resources
+	 */
+clean_up:
+	if (value != NULL) {
+		scf_value_destroy(value);
+	}
+	if (prop != NULL) {
+		scf_property_destroy(prop);
+	}
+	if (prop_group != NULL) {
+		scf_pg_destroy(prop_group);
+	}
+	if (service != NULL) {
+		scf_service_destroy(service);
+	}
+	if (scope != NULL) {
+		scf_scope_destroy(scope);
+	}
+	if (scf_handle != NULL) {
+		scf_handle_destroy(scf_handle);
+	}
+
+	/*
+	 * Return the identity of the X server
+	 */
+	return (x_server);
+
+}	/* IdentifyXServer() */
+
+
+/*
+ * CallConfigProgram()
+ *
+ *    Become the actual device configuration program, executing it with
+ *    the caller-provided argument vector.  This function does not
+ *    return.
+ */
+
+static
+void
+CallConfigProgram(char **argv)
+{
+#ifdef DEBUG_FB
+	if (argv == NULL) {
+		printf("CallConfigProgram(argv is NULL)\n");
+		exit(1);
+	}
+	{
+		int	i;
+
+		for (i = 0; argv[i] != NULL; i++) {
+			printf("argv[%d]=%s\n", i, argv[i]);
+		}
+	}
+#endif
+
+	if (argv[0] == NULL) {
+		PrintError(catgets(catfd, 1, 1,
+			    "No configuration program pathname"));
+	} else {
+		(void) execvp(argv[0], argv);
+		PrintError("Cannot run config program, %s", strerror(errno));
+	}
+
+	exit(1);
+
+}	/* CallConfigProgram() */
+
+
+/*
+ * get_device_model()
+ *
+ *    Return the frame buffer model name, else an empty string, in the
+ *    caller-supplied device_model[GFX_MAX_MODELNAME_LEN] name buffer.
+ *
+ *    Note that ioctl(GFX_IOCTL_GET_IDENTIFIER) might not be supported
+ *    by older drivers (e.g., Xsun drivers).
+ */
+
+static
+void
+get_device_model(
+	int		device_fd,	/* Device file descriptor number */
+	char		*device_model)	/* Returned device model name */
+{
+	const char *const SUNW_ = "SUNW,"; /* Prefix on model & part strings */
+	struct gfx_identifier gfx_ident; /* Graphics identifier */
+	const char	*model_name;	/* Frame buffer model name */
+
+	/*
+	 * Get the frame buffer model name w/o any leading "SUNW," substring
+	 */
+	model_name = "";
+	if (ioctl(device_fd, GFX_IOCTL_GET_IDENTIFIER, &gfx_ident) == 0) {
+		if (gfx_ident.flags & GFX_IDENT_MODELNAME) {
+			model_name = &gfx_ident.model_name[0];
+			if (strstr(model_name, SUNW_) != NULL) {
+				model_name += strlen(SUNW_);
+			}
+		}
+	}
+
+	/*
+	 * Return the frame buffer model name, else an empty string
+	 */
+	(void) strlcpy(device_model, model_name, GFX_MAX_MODELNAME_LEN);
+
+}	/* get_device_model() */
+
+
+/*
+ * get_device_identification()
+ *
+ *    Given a /dev/fb or /dev/fbs/... pathname, make sure it's for a
+ *    character special file.  If the caller has provided the necessary
+ *    pointer, return the (struct stat).st_rdev value.  Open the file
+ *    and return the VISUAL environment device identifier name.  For
+ *    a device such as "/dev/fbs/jfb0", the identifier name should be
+ *    "SUNWjfb".  If the caller has provided the necessary
+ *    device_model[GFX_MAX_MODELNAME_LEN] name buffer, get and return
+ *    the frame buffer model name.
+ *
+ *    In the event of an error, return an errno-style error code.  An
+ *    EACCES code may be of special interest to the caller.
+ */
+
+/*
+ * Mask for stat_buf.st_rdev member
+ */
+#define	MINOR_MASK	0xFFFF		/* Invert to get major/type bits */
+
+static
+int
+get_device_identification(
+	const char	*device_path,	/* Device pathname */
+	int		*st_rdev,	/* Optionally returned st_rdev value */
+	struct vis_identifier *vis_ident, /* Returned VISUAL env identifier */
+	char		*device_model)	/* Optionally returned model name */
+{
+	int		error_code;	/* Returned errno-style error code */
+	int		device_fd;	/* Frame buffer file descriptor # */
+	struct stat	stat_buf;	/* stat() buffer for device file */
+
+	/*
+	 * Make sure this is a character special file
+	 */
+	if (stat(device_path, &stat_buf) != 0) {
+	        return (errno);
+	}
+	if ((stat_buf.st_mode & S_IFCHR) == 0) {
+		return (ENODEV);	/* "No such device" almost says it */
+	}
+
+	/*
+	 * Return the st_rdev value if the caller wants it
+	 */
+	if (st_rdev != NULL) {
+		*st_rdev = stat_buf.st_rdev;
+	}
+
+	/*
+	 * Open the existing device file
+	 */
+	device_fd = open(device_path, O_RDONLY);
+	if (device_fd == -1) {
+		return (errno);		/* Error code, e.g. EACCES */
+	}
+
+	/*
+	 * Get the VISUAL environment device identifier name
+	 */
+	error_code = 0;
+	if (ioctl(device_fd, VIS_GETIDENTIFIER, vis_ident) == -1) {
+		error_code = errno;
+	}
+
+	/*
+	 * If the caller wants it, return the frame buffer model name
+	 */
+	if (device_model != NULL) {
+		get_device_model(device_fd, device_model);
+	}
+
+	close(device_fd);
+
+	return (error_code);
+
+}	/* get_device_identification() */
+
+
+typedef struct {
+	char		*pathname;	/* Full pathname   (e.g. "/dev/fb") */
+	char		*filename;	/* Simple filename (e.g. "fb")      */
+} path_file_t;
+
+static const path_file_t default_device[] = {
+	{ DEVICE_SYMLINK_PATH,    DEVICE_SYMLINK_NAME	},
+	{ DEVICE_SYMLINK_PATH_0,  DEVICE_SYMLINK_NAME_0	},
+	{ NULL,			  NULL			}
+};
+
+
+/*
+ * GetDefaultDevicePathname()
+ *
+ *    This function looks for a default device and returns the pathname
+ *    of the first default frame buffer device that is found and can be
+ *    opened and provide a VISUAL environment device identifier.  The
+ *    possible return values are:
+ *         Zero   - Success; a default device exists and can be accessed
+ *         ENOENT - No frame buffer device was found
+ *         EACCES - Something was found, but the user can't access it
+ */
+
+static
+int
+GetDefaultDevicePathname(
+	char		**device_path)	/* Returned default device pathname */
+{
+	const path_file_t *default_dev;	/* Ptr to a default_device[] element */
+	int		err_code;	/* get_device_identification() code */
+	int		error_code;	/* Return EACCES, ENOENT, or zero */
+	struct vis_identifier vis_ident; /* Device vis identifier */
+
+	*device_path = NULL;
+	error_code   = ENOENT;
+
+	/*
+	 * See whether any default device will open and identify itself
+	 */
+	for (default_dev = &default_device[0];
+	     default_dev->pathname != NULL;
+	     default_dev += 1) {
+		err_code = get_device_identification(
+				default_dev->pathname, NULL, &vis_ident, NULL);
+		if (err_code == 0) {
+			*device_path = default_dev->pathname;
+			return (0);	/* At least one FB device exists */
+		}
+		if (err_code == EACCES) {
+			error_code = EACCES; /* Caller may have to complain */
+			if (*device_path == NULL) {
+				*device_path = default_dev->pathname;
+			}
+		}
+	}
+
+	return (error_code);
+
+}	/* GetDefaultDevicePathname() */
+
+
+/*
+ * GetDevicePathname()
+ *
+ *    Given the pathname or simple filename of a real or default frame
+ *    buffer device, return the fully qualified pathname.
+ *
+ *    Partial pathnames will be treated arbitrarily in nonsense-in,
+ *    nonsense-out fashion.
+ *
+ *    The caller-supplied buffer will be used if it is necessary to
+ *    construct a fully qualified pathname from path components.
+ */
+
+static
+char *
+GetDevicePathname(
+	char		*device_name,	/* Free-form device name */
+	char		*device_path_buf, /* Ptr to device pathname buffer */
+	size_t		device_path_buflen) /* Device path buffer length */
+{
+	const path_file_t *default_dev;	/* Ptr to a default_device[] element */
+
+#if (0)	/* Currently unused */
+	/*
+	 * If there's no device name, return the most likely default pathname
+	 */
+	if (device_name == NULL) {
+		(void) GetDefaultDevicePathname(&device_name);
+		if (device_name == NULL) {
+			device_name = default_device[0].pathname;
+		}
+		return (device_name);
+	}
+
+#endif	/* Currently unused */
+	/*
+	 * Convert a default device name to a full pathname
+	 */
+	for (default_dev = &default_device[0];
+	     default_dev->pathname != NULL;
+	     default_dev += 1) {
+		if ((strcmp(device_name, default_dev->pathname) == 0) ||
+		    (strcmp(device_name, default_dev->filename) == 0)) {
+			return (default_dev->pathname);
+		}
+	}
+
+	/*
+	 * Try to convert a real device filename to a full pathname
+	 */
+	if (*device_name != '/') {
+		const char *const device_dir = DEVICE_DIR "/";
+
+		if (strlen(device_dir) + strlen(device_name)
+						< device_path_buflen) {
+			strcpy(device_path_buf, device_dir);
+			strcat(device_path_buf, device_name);
+			device_name = device_path_buf;
+		}
+	}
+
+	/*
+	 * Return the full pathname or whatever
+	 */
+	return (device_name);
+
+}	/* GetDevicePathname() */
+
+
+/*
+ * GetConfigProgramPath()
+ *
+ *    Given the current X server and the identifier for the frame buffer
+ *    device, construct the full pathname of the relevant configuration
+ *    program.  Return the program pathname and a sense of whether it
+ *    exists (ENOENT), is accessible (EACCES), etc.
+ *
+ *    The caller is responsible for freeing the returned pathname
+ *    string.
+ */
+
+static
+int
+GetConfigProgramPath(
+	xserv_t		x_server,	/* X server: Xsun, Xorg, ... */
+	const char	*vis_ident_name, /* VISUAL env device identifier */
+	char		**config_prog_path) /* Returned config program path */
+{
+	const char *const xsun_prog_fmt  = FBC_LIB_DIR "/%s_config";
+	const char *const xorg_prog_fmt  = FBC_LIB_DIR "/%s_conf";
+	const char *const xorg_lib_fmt   = FBC_LIB_DIR "/lib%s_conf.so";
+	const char *const xorg_prog_path = FBC_LIB_DIR "/fbconf_xorg";
+	int		error_code;	/* Error code (see errno.h) */
+	size_t		len;		/* String length temp */
+	size_t		len_ident;	/* Length of device identifier name */
+	size_t		len_path;	/* Max length of path memory needed */
+
+	*config_prog_path = NULL;
+	error_code        = 0;
+
+	/*
+	 * Build server-specific pathnames of config programs
+	 */
+	len_ident = strlen(vis_ident_name);
+
+	switch (x_server) {
+
+	default:
+		/*
+		 * Commandeer EINVAL to indicate that the X server is unknown
+		 */
+		return (EINVAL);	/* Invalid x_server argument */
+
+	case XSERVER_XSUN:
+		*config_prog_path = malloc(strlen(xsun_prog_fmt) + len_ident);
+		if (*config_prog_path == NULL) {
+			return (ENOMEM);
+		}
+		sprintf(*config_prog_path, xsun_prog_fmt, vis_ident_name);
+		break;
+
+	case XSERVER_XORG:
+		/*
+		 * Allocate memory to contain any one of the pathnames:
+		 *    * any device-specific config program
+		 *    * the device-specific library used by fbconf_xorg
+		 *    * the multi-device config program, fbconf_xorg
+		 *
+		 *    Note that the two-character "%s" conversion spec
+		 *    in the sprintf() format string is replaced by the
+		 *    vis_ident_name string.  Its trifling length could
+		 *    be ignored but we'll count it against the length
+		 *    of the Nul terminator.
+		 */
+		len_path = strlen(xorg_lib_fmt);
+		len      = strlen(xorg_prog_fmt);
+		if (len_path < len) {
+			len_path = len;
+		}
+		len_path += len_ident;
+		len = strlen(xorg_prog_path) + 1;
+		if (len_path < len) {
+			len_path = len;
+		}
+
+		*config_prog_path = malloc(len_path);
+		if (*config_prog_path == NULL) {
+			return (ENOMEM);
+		}
+
+		/*
+		 * See if a config program exists, accessible or not
+		 */
+		sprintf(*config_prog_path, xorg_prog_fmt, vis_ident_name);
+		if (access(*config_prog_path, X_OK) == 0) {
+			return (0);	/* Have a device-specific program */
+		}
+		if (errno != ENOENT) {
+			return (errno);	/* Have a program w/ encumbrances */
+		}
+
+		/*
+		 * Make a note of whether a device-specific library exists
+		 *
+		 *    We'll return the multi-device config program path
+		 *    in any case.  The caller can decide, based on the
+		 *    error code, whether and how it could be useful.
+		 */
+		sprintf(*config_prog_path, xorg_lib_fmt, vis_ident_name);
+		if (access(*config_prog_path, X_OK) != 0) {
+			error_code = errno;
+		}
+
+		/*
+		 * Construct the multi-device config program pathname
+		 *
+		 *    It's assumed that the states of existence and
+		 *    accessibility of the config program, fbconf_xorg,
+		 *    also hold true for its common library,
+		 *    libfbconf_xorg.so.
+		 */
+		strcpy(*config_prog_path, xorg_prog_path);
+		break;
+	}
+
+	/*
+	 * See if the config program exists and allows the user to execute it
+	 */
+	if (access(*config_prog_path, X_OK) != 0) {
+		if (error_code != ENOENT) {
+			error_code = errno; /* Supersede an Xorg lib error */
+		}
+	}
+
+	return (error_code);
+
+}	/* GetConfigProgramPath() */
+
+
+/*
+ * FindConfigProgram()
+ *
+ *    Return the full pathname of the configuration program associated
+ *    with this X server and fully qualified device pathname.
+ *
+ *    In the event of an error, an error code from errno.h space will be
+ *    returned, along with a NULL pathname pointer.
+ *
+ *    The caller is responsible for freeing the returned pathname
+ *    string.
+ */
+static
+int
+FindConfigProgram(
+	xserv_t		x_server,	/* X server: Xsun, Xorg, ... */
+	const char	*device_path,	/* Device pathname */
+	char		**config_prog_path) /* Returned config program path */
+{
+	int		error_code;	/* Error code (see errno.h) */
+	struct vis_identifier vis_ident; /* VISUAL env device identifier */
+
+	*config_prog_path = NULL;
+
+	/*
+	 * Validate the device and get its VISUAL environment identifier
+	 */
+	error_code = get_device_identification(
+					device_path, NULL, &vis_ident, NULL);
+	if (error_code != 0) {
+		PrintError("%s, %s", strerror(error_code), device_path);
+		if (error_code != EACCES) {
+			PrintError(catgets(catfd, 12, 1,
+				    "Not a configurable device. "
+				    " Use -list to show valid devices."));
+		}
+		return (error_code);
+	}
+
+	/*
+	 * Get the config program to use with this X server and device type
+	 */
+	error_code = GetConfigProgramPath(
+				x_server, vis_ident.name, config_prog_path);
+	if (error_code != 0) {
+		PrintError("%s, %s", strerror(error_code),
+				(*config_prog_path == NULL) ?
+					"config program" : *config_prog_path);
+		free(*config_prog_path);	/* Release any memory */
+		*config_prog_path = NULL;
+	}
+
+	return (error_code);
+
+}	/* FindConfigProgram() */
+
+
+/*
+ * PathToGUI()
+ *
+ *    Return the pathname of the DCM Tool GUI script and an errno-style
+ *    error code indicating whether the pathname is useable.
+ */
+
+static
+int
+PathToGUI(
+	const char	**gui_path)	/* Returned GUI script pathname */
+{
+	int		error_code;	/* Error code (see errno.h) */
+
+	*gui_path  = DCMTOOL_LOCATION;
+	error_code = 0;
+	if (access(*gui_path, X_OK) < 0) {
+		error_code = errno;
+#ifdef DEBUG_FB
+		printf("PathToGUI: %s\n", strerror(error_code));
+#endif
+	}
+	return (error_code);
+
+}	/* PathToGUI() */
+
+
+/*
+ * PrintHelp()
+ *
+ *    Display this program's command line syntax.  Include the -gui
+ *    option only if PathToGUI() returns a non-zero error code,
+ *    indicating that the returned GUI pathname is useable.  Then invoke
+ *    the actual device configuration program, iff known, to display its
+ *    own -help text.  (The device configuration program must implement
+ *    the -dev and the -help option.)
+ */
+
+static
+void
+PrintHelp(
+	xserv_t		x_server,	/* X server: Xsun, Xorg, ... */
+	char		*device_path)	/* Device pathname */
+{
+	char		*config_prog_path; /* Device config program pathname */
+	int		error_code;	/* Error code from PathToGUI() */
+	const char	*gui_path;	/* DCM Tool GUI pathname (ignored) */
+	const char	*gui_synopsis;	/* -gui synopsis text, if any */
+
+	/*
+	 * Decide whether to show the -gui option synopsis and description
+	 */
+	gui_synopsis = "";
+#if (1)	/* ??? Cover for temporarily absent functionality ??? */
+	error_code = EINVAL;
+	if (x_server == XSERVER_XSUN) {
+#endif
+	error_code = PathToGUI(&gui_path);
+	if (error_code == 0) {
+		gui_synopsis = catgets(catfd, 13, 1, " [-gui]");
+	}
+#if (1)	/* ??? Cover for temporarily absent functionality ??? */
+	}
+#endif
+
+	/*
+	 * Display synopsis (usage) and description text
+	 */
+	printf(catgets(catfd, 2, 1,
+		"Usage:\n"
+		"\tfbconfig [-dev devname] [-help] [-list]%s\n"
+		"\t         [device-specific-options]\n"
+		"\t-dev\t\tSpecify the frame buffer device file name.\n"
+		"\t-help\t\tDisplay this help text.\n"
+		"\t-list\t\tList installed and configurable frame buffers.\n"
+		"\t-xserver [Xorg | Xsun]\tConfigure the Xserver to the specified program.\n"),
+		gui_synopsis);
+	if (error_code == 0) {
+		printf(catgets(catfd, 15, 1,
+		    "\t-gui\t\tInvoke Graphical User Interface (SUNWdcm)\n"
+		    "\t\t\tto configure devices and update Xservers file.\n"));
+	}
+	printf("\n"
+		"\tdevice-specific-options are implemented by the device\n"
+		"\t\t\tconfiguration program.\n"
+		"\n");
+
+	/*
+	 * Invoke the device config program to display its own -help text
+	 */
+	if (device_path != NULL) {
+		static char *argv[] = { NULL, "-dev", NULL, "-help", NULL };
+
+		(void) FindConfigProgram(
+				x_server, device_path, &config_prog_path);
+		if (config_prog_path != NULL) {
+			argv[0] = config_prog_path;
+			argv[2] = device_path;
+			CallConfigProgram(argv);
+		}
+	}
+
+}	/* PrintHelp() */
+
+
+/*
+ * ListDevices_StreamCheck()
+ *
+ *    See whether the specified "device" name and "stream" name are in
+ *    fact a device file and a stream file for the same device.  (It is
+ *    possible that the device file is actually a stream for a previous
+ *    device.  The stream file could be any frame buffer entity.)  If a
+ *    device/stream relationship exists, return the stream suffix
+ *    character.  Return a Nul character otherwise.
+ */
+static
+char
+ListDevices_StreamCheck(
+	const char	*device_name,	/* Device file name */
+	int		device_rdev,	/* st_rdev value returned by stat() */
+	struct vis_identifier *device_vis_ident, /* Device VIS identifier */
+	const char	*stream_name)	/* Potential stream file name */
+{
+	size_t		device_len;	/* Length of device file name */
+	size_t		stream_len;	/* Length of potential stream name */
+	char		stream_path[MAX_DEV_PATH_LEN]; /* Stream pathname */
+	int		stream_rdev;	/* st_rdev value returned by stat() */
+	struct vis_identifier stream_vis_ident; /* Stream VIS env identifier */
+
+	/*
+	 * See if the potential stream name is the device name w/ a stream char
+	 */
+	device_len = strlen(device_name);
+	stream_len = strlen(stream_name);
+	if ((stream_len != device_len + 1) ||
+	    (strncmp(stream_name, device_name, device_len) != 0) ||
+	    (strchr(STREAM_SUFFIX_CHARS, *(stream_name + device_len))
+						== NULL)) {
+		return ('\0');		/* The name strings are unrelated */
+	}
+
+	/*
+	 * See if the potential stream has the same device identifiers
+	 *
+	 *    Note that our caller, ListDevices(), has compared
+	 *    this pathname length to the buffer length.  Oversized
+	 *    names were rejected.
+	 */
+	strcpy(stream_path, DEVICE_DIR "/");
+	strcat(stream_path, stream_name);
+	if (get_device_identification(
+		    stream_path, &stream_rdev, &stream_vis_ident, NULL) != 0) {
+		return ('\0');		/* Decline to pursue this */
+	}
+	if (((stream_rdev & ~MINOR_MASK) != (device_rdev & ~MINOR_MASK)) ||
+	    (strcmp(stream_vis_ident.name, device_vis_ident->name) != 0)) {
+		return ('\0');		/* Device identifiers don't match */
+	}
+
+	/*
+	 * Return with the stream suffix character
+	 */
+	return (*(stream_name + device_len));
+
+}	/* ListDevices_StreamCheck() */
+
+
+/*
+ * ListDevices()
+ *
+ *    In response to the -list option, display the frame buffer device
+ *    files found in the /dev/fbs directory, along with the frame
+ *    buffer configuration program appropriate for the type of device.
+ *    If there is some obvious problem with the device or the config
+ *    program, a diagnostic message may be displayed instead of the
+ *    program file name.
+ *
+ *    Illustrative -list output, assuming Xorg is configured:
+ *
+ *      Device File Name            Device Model     Config Program
+ *      ----------------            ------------     --------------
+ *      /dev/fbs/cgsix0                              not configurable
+ *      /dev/fbs/ffb0                                not configurable
+ *      /dev/fbs/ffb1                                not configurable
+ *      /dev/fbs/kfb0               XVR-2500         SUNWkfb_config
+ *      /dev/fbs/kfb1               XVR-2500         SUNWkfb_config
+ *      /dev/fbs/m640                                not configurable
+ *      /dev/fbs/nfb0 [a|b]         XVR-300          not configurable
+ *      /dev/fbs/pfb0 [a|b]         XVR-100          not configurable
+ *      /dev/fbs/efb0               XVR-300          SUNWefb_config
+ *      /dev/fbs/efb1               XVR-100          SUNWefb_config
+ *      /dev/fbx/ast0		    AST-2100         SUNWast_config
+ *
+ *    This and the FindConfigurableDevices() function are similar and
+ *    can be maintained together.
+ */
+
+/* Entry in a sorted, singly-linked list of potential device names */
+typedef struct devent_st {
+	struct devent_st *next;		/* Ptr to next device entry in list */
+	char		name[1];	/* Name of potential device file */
+} dev_ent_t;
+
+static
+unsigned int
+get_device_mask(char * device_path)
+{
+	if (strstr(device_path, "ast")) {
+		return GFX_DEV_AST;
+	} else if (strstr(device_path, "efb")) {
+		return (GFX_DEV_EFB | GFX_DEV_NFB | GFX_DEV_PFB);
+	} else if (strstr(device_path, "nfb")) {
+		return GFX_DEV_NFB;
+	} else if (strstr(device_path, "pfb")) {
+		return GFX_DEV_PFB;
+	} else if (strstr(device_path, "kfb")) {
+		return GFX_DEV_KFB;
+	} else if (strstr(device_path, "ifb")) {
+		return GFX_DEV_IFB;
+	} else if (strstr(device_path, "jfb")) {
+		return GFX_DEV_JFB;
+	} else if (strstr(device_path, "ffb")) {
+		return GFX_DEV_FFB;
+	} else if (strstr(device_path, "m64")) {
+		return GFX_DEV_M64;
+	} else {
+		return 0;
+	}
+}
+
+static
+void
+ListDevices(
+	xserv_t		x_server,	/* Xserver: Xsun, Xorg */
+	boolean_t	probe_only,	/* 1 - probe the devices only, no output */
+	unsigned int	*device_mask)	/* bit set for each listed device */
+{
+	char		device_model[GFX_MAX_MODELNAME_LEN]; /* Model_name */
+	char		device_path[MAX_DEV_PATH_LEN + MAX_SUFFIX_LIST_LEN];
+	struct dirent	*dir_entry;	/* Device directory entry */
+	DIR		*dir_fd;	/* Device directory file descriptor */
+	size_t		dir_len;	/* Length of "/dev/fbs/" */
+	dev_ent_t	*dev_list;	/* Head of device name list */
+	dev_ent_t	*dev_entry;	/* Ptr to current device name entry */
+	dev_ent_t	**dev_ent_pptr;	/* Ptr to ptr to current entry */
+	dev_ent_t	*dev_next;	/* Ptr to next device name entry */
+	size_t		file_len;	/* Length of simple filename */
+	boolean_t	found = B_FALSE; /* TRUE => Device(s) displayed */
+
+	/*
+	 * Open the /dev/fbs device directory
+	 */
+	dir_fd = opendir(DEVICE_DIR);
+	if (dir_fd == NULL) {
+		PrintError(catgets(catfd, 6, 1,
+				"Cannot open the " DEVICE_DIR " directory"));
+		exit(1);
+	}
+
+	/*
+	 * Insert each file name in the /dev/fbs directory into a sorted list
+	 */
+	dir_len  = strlen(DEVICE_DIR "/");
+	dev_list = NULL;
+	for (;;) {
+		/*
+		 * Read the next directory entry
+		 */
+		dir_entry = readdir(dir_fd);
+		if (dir_entry == NULL) {
+			if ((errno != 0) && (errno != ENOENT)) {
+				PrintError("%s, while reading " DEVICE_DIR,
+						strerror(errno));
+			}
+			break;
+		}
+
+		/*
+		 * Ignore anything that clearly isn't a device name
+		 */
+		if ((strcmp(dir_entry->d_name, ".") == 0) ||
+		    (strcmp(dir_entry->d_name, "..") == 0)) {
+			continue;	/* Directories aren't devices */
+		}
+		file_len = strlen(dir_entry->d_name);
+		if (dir_len + file_len >= MAX_DEV_PATH_LEN) {
+			continue;	/* Too long for a device pathname */
+		}
+
+		/*
+		 * Create a list entry for this potential device name
+		 */
+		dev_entry = malloc(sizeof(dev_ent_t) + file_len);
+		if (dev_entry == NULL) {
+			PrintError("Insufficient memory, %s",
+					dir_entry->d_name);
+			exit(1);
+		}
+		strcpy(dev_entry->name, dir_entry->d_name);
+
+		/*
+		 * Insert the new name into the sorted list of names
+		 */
+		for (dev_ent_pptr = &dev_list;
+		    ;
+		    dev_ent_pptr = &dev_next->next) {
+			dev_next = *dev_ent_pptr;
+			if ((dev_next == NULL) ||
+			    (strcmp(dev_entry->name, dev_next->name) < 0)) {
+				dev_entry->next = dev_next;
+				*dev_ent_pptr   = dev_entry;
+				break;
+			}
+		}
+	}
+
+	closedir(dir_fd);
+
+	/*
+	 * Display information for each list entry that looks like a device
+	 */
+	strncpy(device_path, DEVICE_DIR "/", MAX_DEV_PATH_LEN);
+	for (dev_entry = dev_list; dev_entry != NULL; dev_entry = dev_next) {
+		char	*config_prog_path; /* Device config program pathname */
+		int	error_code;	/* Error code (see errno.h) */
+		const char *program_field; /* Config prog name or msg text */
+		char	suffix_char;	/* Stream suffix char, else Nul */
+		char	*suffix_ptr;	/* Suffix list ptr in dev path buf */
+		char	suffix_punct;	/* Punctuation for suffix char list */
+		int	st_rdev;	/* st_rdev value returned by stat() */
+		struct vis_identifier vis_ident; /* Device vis identifier */
+
+		/*
+		 * Construct the full pathname for this potential device
+		 *
+		 *    Note that this pathname length was compared to the
+		 *    buffer length in the previous loop.  Oversized
+		 *    names were rejected.
+		 */
+		file_len = strlen(dev_entry->name);
+		strcpy(&device_path[dir_len], dev_entry->name);
+
+		/*
+		 * Discard this list entry
+		 */
+		dev_next = dev_entry->next;
+		free(dev_entry);
+
+		/*
+		 * See if this file is a device and get its identifications
+		 */
+		error_code = get_device_identification(
+				device_path,
+				&st_rdev, &vis_ident, &device_model[0]);
+
+		if (error_code == 0) {
+			*device_mask |= get_device_mask(device_path);
+		}
+
+		if (probe_only == B_TRUE)
+			continue;
+
+		/*
+		 * Determine the "Config Program" field contents
+		 */
+		config_prog_path = NULL;	/* For free() */
+		program_field    = "";		/* For falling thru cracks */
+		if (error_code != 0) {
+			if (error_code != EACCES) {
+				continue;	/* Not a convincing device */
+			}
+			/* No VISUAL env identifier with which to proceed */
+			program_field = "device access denied";
+		} else {
+			/*
+			 * Get the config program pathname for this device
+			 */
+			error_code = GetConfigProgramPath(x_server,
+							vis_ident.name,
+							&config_prog_path);
+			if (error_code != 0) {
+				/*
+				 * Provide a diagnostic message
+				 */
+				switch (error_code) {
+				case EINVAL:	/* Invalid x_server value */
+					program_field = catgets(catfd, 7, 1,
+						"X server not known");
+					break;
+				case ENOENT:	/* Config program not found */
+					program_field = catgets(catfd, 7, 1,
+						"program not available");
+					break;
+				case EACCES:	/* User can't access program */
+					program_field =
+						"program access denied";
+					break;
+				default:	/* Some other mischief */
+					program_field = strerror(error_code);
+					break;
+				}
+			} else {
+				/*
+				 * Find the simple filename of the config prog
+				 */
+				program_field = strrchr(config_prog_path, '/');
+				if (program_field == NULL) {
+					program_field = config_prog_path;
+				} else {
+					program_field += 1;
+				}
+			}
+		}
+
+		/*
+		 * Check for streams that can be consolidated with this device
+		 *
+		 *    It is assumed that the device name list is sorted
+		 *    such that all names for a given device are
+		 *    adjacent, with the plain device name first and any
+		 *    stream-suffixed names following.  It's also
+		 *    assumed that a stream name is the device name with
+		 *    a one-character suffix from the set,
+		 *    STREAM_SUFFIX_CHARS.
+		 */
+		suffix_ptr   = &device_path[dir_len + file_len]; /* The Nul */
+		suffix_punct = '[';
+		while (dev_next != NULL) {
+			/*
+			 * See if the next list entry has a related stream name
+			 */
+			dev_entry = dev_next;
+			suffix_char = ListDevices_StreamCheck(
+						&device_path[dir_len],
+						st_rdev,
+						&vis_ident,
+						dev_entry->name);
+			if (suffix_char == '\0') {
+				break;		/* Not a related stream name */
+			}
+
+			/*
+			 * Append this stream suffix character to the substring
+			 */
+			*(suffix_ptr+1) = suffix_punct;	/* '[' or '|' */
+			*(suffix_ptr+2) = suffix_char;	/* 'a', 'b', ... */
+			suffix_ptr += 2;
+			suffix_punct = '|';
+
+			/*
+			 * Free this now-consolidated stream entry
+			 */
+			dev_next = dev_entry->next;
+			free(dev_entry);
+		}
+		if (suffix_punct != '[') {
+			/*
+			 * Terminate the non-empty stream suffix char substring
+			 */
+			*(suffix_ptr+1) = ']';
+			*(suffix_ptr+2) = '\0';
+
+			/*
+			 * Append the stream suffix character substring
+			 */
+			device_path[dir_len + file_len] = ' '; /* Was Nul */
+		}
+
+		/*
+		 * Display the file & any streams, model, and config prog field
+		 */
+		if (!found) {
+			found = B_TRUE;
+#ifdef DEBUG_FB	/* Show VISUAL environment identifier also */
+			printf("  -------");
+#endif
+			printf(catgets(catfd, 8, 1,
+	"  Device File Name            Device Model     Config Program\n"
+	"  ----------------            ------------     --------------\n"));
+		}
+#ifdef DEBUG_FB	/* Show VISUAL environment identifier also */
+		printf("  %-7.7s", vis_ident.name);
+#endif
+		printf("  %-27.27s %-16.16s %s\n",
+			device_path, device_model, program_field);
+
+		free(config_prog_path);
+	}
+
+	/*
+	 * If nothing was found then say so (before returning and terminating)
+	 */
+	if (!probe_only && !found) {
+		printf(catgets(catfd, 9, 1,
+				"No configurable devices found in "
+					DEVICE_DIR " directory\n"));
+	}
+
+}	/* ListDevices() */
+
+
+/*
+ * FindConfigurableDevices()
+ *
+ *    This function checks /dev/fb and searches /dev/fbs until a
+ *    frame buffer device is found that can be opened and provide a
+ *    VISUAL environment device identifier.  The possible return values
+ *    are:
+ *         Zero   - Success; at least one device exists and can be accessed
+ *         ENOENT - No frame buffer device was found
+ *         EACCES - Something was found, but the user can't access it
+ *
+ *    The -gui option will not launch the DCM Tool if this function
+ *    returns a non-zero value.
+ *
+ *    This and the ListDevices() function are similar and can be
+ *    maintained together.
+ */
+
+static
+int
+FindConfigurableDevices(void)
+{
+	char		*default_path;	/* Default device pathname (dummy) */
+	char		device_path[MAX_DEV_PATH_LEN];
+	struct dirent	*dir_entry;	/* Device directory entry */
+	DIR		*dir_fd;	/* Device directory file descriptor */
+	size_t		dir_len;	/* Length of "/dev/fbs/" */
+	int		err_code;	/* Error code (see errno.h) */
+	int		error_code;	/* Return EACCES, ENOENT, or zero */
+	size_t		file_len;	/* Length of simple filename */
+	struct vis_identifier vis_ident; /* Device VISUAL env identifier */
+
+	error_code = ENOENT;
+
+	/*
+	 * See whether any default device will open and identify itself
+	 */
+	err_code = GetDefaultDevicePathname(&default_path);
+	if (err_code == 0) {
+		return (0);		/* At least one FB device exists */
+	}
+	if (err_code == EACCES) {
+		error_code = EACCES;	/* Caller may have to complain */
+	}
+
+	/*
+	 * Open the /dev/fbs device directory
+	 */
+	dir_fd = opendir(DEVICE_DIR);
+	if (dir_fd == NULL) {
+		PrintError(catgets(catfd, 6, 1,
+				"Cannot open the " DEVICE_DIR " directory"));
+		exit(1);
+	}
+
+	/*
+	 * Examine each file in /dev/fbs until a working FB device is found
+	 */
+	dir_len = strlen(DEVICE_DIR "/");
+	for (;;) {
+		/*
+		 * Read the next directory entry
+		 */
+		dir_entry = readdir(dir_fd);
+		if (dir_entry == NULL) {
+			if ((errno != 0) && (errno != ENOENT)) {
+				PrintError("%s, while reading " DEVICE_DIR,
+						strerror(errno));
+			}
+			break;
+		}
+
+		/*
+		 * Ignore anything that clearly isn't a device
+		 */
+		if ((strcmp(dir_entry->d_name, ".") == 0) ||
+		    (strcmp(dir_entry->d_name, "..") == 0)) {
+			continue;	/* Directories aren't devices */
+		}
+		file_len = strlen(dir_entry->d_name);
+		if (dir_len + file_len >= MAX_DEV_PATH_LEN) {
+			continue;	/* Too long for a device pathname */
+		}
+
+		/*
+		 * Construct the full pathname for the device
+		 */
+		strcpy(&device_path[dir_len], dir_entry->d_name);
+
+		/*
+		 * See if this file is a frame buffer device
+		 */
+		err_code = get_device_identification(
+					device_path, NULL, &vis_ident, NULL);
+		if (err_code == 0) {
+			error_code = 0;
+			break;		/* At least one FB device exists */
+		}
+		if (err_code == EACCES) {
+			error_code = EACCES; /* Caller may have to complain */
+		}
+	}
+
+	closedir(dir_fd);
+
+	return (error_code);
+
+}	/* FindConfigurableDevices() */
+
+
+/*
+ * InvokeGUI()
+ *
+ *    Implement the -gui option:
+ *      -gui  Executes the Graphics User Interface program DCMTool
+ *	      if it is available.
+ *
+ *    This is done by invoking:
+ *        pfexec /usr/lib/fbconfig/SUNWdcm/bin/dcmtool
+ *	  (RBAC's exec_attr entry makes that program setuid root.)
+ *
+ *    If successful, this function does not return.  A non-zero exit
+ *    code is returned otherwise.
+ */
+
+static
+int
+InvokeGUI(void)
+{
+	const char	*pfexec_path = "/usr/bin/pfexec";
+	const char	*gui_path;	/* DCM Tool GUI script pathname */
+	int		error_code;	/* Error code (see errno.h) */
+
+	/*
+	 * Make sure the GUI will have at least one device
+	 *
+	 *    The error_code returned by FindConfigurableDevices()
+	 *    will be EACCES, ENOENT, or zero.
+	 */
+	error_code = FindConfigurableDevices();
+	if (error_code != 0) {
+		if (error_code == EACCES) {
+			PrintError(catgets(catfd, 21, 2,
+			    "You do not have access to configure"
+			    " graphics devices on this system.\n"
+			    "You will have access if you log in"
+			    " to the console or you are superuser (root)."));
+			return (2);
+		}
+		printf(catgets(catfd, 9, 1,
+			"No configurable devices found in "
+			DEVICE_DIR " directory\n"));
+		return (1);
+	}
+
+	/*
+	 * Get the pathname of the DCM Tool GUI script
+	 */
+	error_code = PathToGUI(&gui_path);
+	if (error_code != 0) {
+		if (error_code == ENOENT) {
+			PrintError(catgets(catfd, 20, 1,
+				"GUI not present. Install SUNWdcm package."));
+		} else {
+			PrintError("%s, %s", strerror(error_code), gui_path);
+		}
+		return (1);
+	}
+
+	(void) execl(pfexec_path, pfexec_path, gui_path, NULL);
+
+	/* execl() should not return; if it did, it failed */
+#ifdef DEBUG_FB
+	PrintError("execl() failed, errno=%d: %s", errno, strerror(errno));
+#endif
+	return (2);
+
+}	/* InvokeGUI() */
+
+
+static
+int
+IsXserverSupported(xserv_t xserver_arg, unsigned int device_mask)
+{
+	struct stat	stat_buf;	/* stat() buffer for device file */
+
+	if (stat(xserver_path[xserver_arg], &stat_buf) != 0) {
+		printf("Fails to configure xserver to %s, no such file\n", xserver_path[xserver_arg]);
+		return 0;
+	}
+
+	if (device_mask & ~xserver_device[xserver_arg]) {
+		printf("Fails to configure xserver to %s, not all graphics devices in the system can be configured to run with this xserver\n",
+				xserver_path[xserver_arg]);
+		return 0;
+	}
+
+	return 1;
+}
+
+static
+void
+SetXServer(xserv_t x_server, xserv_t xserver_arg, unsigned int device_mask)
+{
+	struct stat	stat_buf;	/* stat() buffer for device file */
+	char efb_path[40] = "/kernel/drv/sparcv9/efb";	
+	char nfb_path[40] = "/kernel/drv/sparcv9/nfb";	
+	char pfb_path[40] = "/kernel/drv/sparcv9/pfb";	
+
+	if (xserver_arg == XSERVER_XORG) {
+
+		/*
+		 * First check if all the listed devices supports Xorg. 
+		 * If not, setting to Xorg will be denied.
+		 */
+		if (!IsXserverSupported(xserver_arg, device_mask)) {
+			return;
+		}
+
+		/*
+		 * If there is a XVR-50, XVR-100, XVR-300, check if efb driver exists
+		 */
+		if (device_mask & (GFX_DEV_NFB | GFX_DEV_PFB | GFX_DEV_EFB)) {
+			if (stat(efb_path, &stat_buf) != 0) {
+				printf("Fails to configure xserver to %s, efb driver is not installed\n",
+						xserver_path[xserver_arg]);
+				return;
+			}
+		}
+
+		system("svccfg -s svc:/application/x11/x11-server setprop options/server=/usr/X11/bin/Xorg");
+
+		if (stat(efb_path, &stat_buf) == 0) {
+			system("rem_drv nfb 2>/dev/null&");
+			system("rem_drv pfb 2>/dev/null&");
+			system("add_drv -n -m '* 0666 root sys' -i \"SUNW,XVR-50 SUNW,XVR-100 SUNW,XVR-300\" efb 2>/dev/null&");
+			printf("A reboot needs to be performed to complete the reconfiguration to run Xorg\n");
+		} else {
+			printf("Fails to switch to efb driver. Please check to see if SUNWefb is installed.\n");
+		}
+
+	} else if (xserver_arg == XSERVER_XSUN) {
+
+		int pfb_exists = 0;
+
+		/*
+		 * First check if all the listed devices supports Xsun. 
+		 * If not, setting to Xsun will be denied.
+		 */
+		if (!IsXserverSupported(xserver_arg, device_mask)) {
+			return;
+		}
+
+#if OSVER==510
+		if ((stat("/platform/sun4u/kernel/drv/sparcv9/pfb", &stat_buf) == 0) ||
+		    (stat("/platform/sun4v/kernel/drv/sparcv9/pfb", &stat_buf) == 0) ||
+		    (stat("/platform/sun4us/kernel/drv/sparcv9/pfb", &stat_buf) == 0)) {
+			pfb_exists = 1;
+		}
+#else
+		if (stat(pfb_path, &stat_buf) == 0) {
+			pfb_exists = 1;
+}
+#endif
+
+		/*
+		 * If there is a XVR-300, check if nfb driver exists
+		 */
+		if (device_mask & GFX_DEV_NFB) {
+			if (stat(nfb_path, &stat_buf) != 0) {
+				printf("Fails to configure xserver to %s, nfb driver is not installed\n",
+						xserver_path[xserver_arg]);
+				return;
+			}
+		}
+
+		/*
+		 * If there is a XVR-50, XVR-100, check if pfb driver exists
+		 */
+		if (device_mask & GFX_DEV_PFB) {
+			if (pfb_exists == 0) {
+				printf("Fails to configure xserver to %s, pfb driver is not installed\n",
+						xserver_path[xserver_arg]);
+				return;
+			}
+		}
+
+		system("svccfg -s svc:/application/x11/x11-server setprop options/server=/usr/openwin/bin/Xsun");
+
+		if (stat(efb_path, &stat_buf) == 0) {
+			system("rem_drv efb 2>/dev/null&");
+		}
+
+		if (stat(nfb_path, &stat_buf) == 0) {
+			system("add_drv -n -m '* 0666 root sys' -i \"SUNW,XVR-300\" nfb 2>/dev/null&");
+		}
+
+		if (pfb_exists) {
+			system("add_drv -n -m '* 0666 root sys' -i \"SUNW,XVR-50 SUNW,XVR-100\" pfb 2>/dev/null&");
+		}
+
+		printf("A reboot needs to be performed to complete the reconfiguration to run Xsun\n");
+
+	} else {
+		printf("Default Xserver: %s\n", xserver_path[x_server]);
+	}
+}	/* SetXServer() */
+
+
+/*
+ * main() for fbconfig(1M)
+ *
+ *    Do exactly one of the following, in order of precedence, depending
+ *    on options in the program command line (argv[]):
+ *      * Display fbconfig(1M) help text (-help) along with any
+ *        configuration program help text (-dev, -help) and then
+ *        terminate.
+ *      * Display the installed frame buffer devices and the
+ *        corresponding configuration program for each (-list) and then
+ *        terminate.
+ *      * Become the dcmtool GUI (-gui).
+ *      * Repackage the program argument vector and become the
+ *        appropriate device configuration program (-dev).
+ *      * Report a fatal error and terminate.
+ */
+
+int
+main(
+	int		argc,		/* Program argument count */
+	char		*argv[])	/* Program argument vector */
+{
+#define	CFG_ARG_1	3		/* Index of initial cfg_argv[] arg */
+	boolean_t	dev_opt  = B_FALSE; /* TRUE => Found -dev  option */
+	boolean_t	help_opt = B_FALSE; /* TRUE => Found -help option */
+	boolean_t	list_opt = B_FALSE; /* TRUE => Found -list option */
+	boolean_t	gui_opt  = B_FALSE; /* TRUE => Found -gui  option */
+	boolean_t	xserver_opt  = B_FALSE; /* TRUE => Found -xserver  option */
+	char		**cfg_argv;	/* Config program argument vector */
+	char		*config_prog_path; /* Config program pathname */
+	char		*device_path;	/* Device pathname */
+	char		device_path_buf[MAX_DEV_PATH_LEN];
+	int		i;		/* argv[] argument vector index */
+	int		n;		/* cfg_argv[] argument vector index */
+	xserv_t		x_server;	/* X server: Xsun, Xorg, ... */
+	xserv_t		xserver_arg;	/* -xserver arg: Xsun, Xorg, ... */
+	unsigned int	device_mask = 0;
+
+	catfd = catopen("fbconfig", 0);
+
+	/*
+	 * Allocate an argument vector to pass to the device config program
+	 *
+	 *    The config program (child) argument vector must be large
+	 *    enough to hold:
+	 *      * The config program pathname      (     1 pointer )
+	 *      * A default "-dev /dev/fb" option  (     2 pointers)
+	 *      * The fbconfig(1M) arguments       (argc-1 pointers)
+	 *      * A NULL terminator                (     1 pointer )
+	 */
+	cfg_argv = malloc((2 + argc + 1) * sizeof (char *));
+	if (cfg_argv == NULL) {
+		PrintError("Insufficient memory for new argument vector");
+		return (1);
+	}
+
+	/*
+	 * Process the fbconfig(1M) program command line arguments
+	 *
+	 *    Leave room in the child's argument vector to prepend these
+	 *    three (CFG_ARG_1) strings:
+	 *      * The pathname of the child config program
+	 *      * A -dev option and a default frame buffer name
+	 */
+	n = CFG_ARG_1;
+	for (i = 1; i < argc; i += 1) {
+		/* Look for -help (for which -dev can be a modifier) */
+		if (strncmp(argv[i], "-help", 6) == 0) {
+			help_opt = B_TRUE;
+			continue;	/* Option isn't passed to child */
+		}
+
+		/* Look for a -list option and don't copy it */
+		if (strncmp(argv[i], "-list", 6) == 0) {
+			list_opt = B_TRUE;
+			continue;	/* Option isn't passed to child */
+		}
+
+		/* Look for a -list option and don't copy it */
+		if (strncmp(argv[i], "-xserver", 9) == 0) {
+			xserver_opt = B_TRUE;
+			xserver_arg = XSERVER_UNKNOWN;
+
+			i++;
+			if (i < argc) {
+				if (strncasecmp(argv[i], "Xsun", 4) == 0) {
+					xserver_arg = XSERVER_XSUN;
+				} else if (strncasecmp(argv[i], "Xorg", 4) == 0) {
+					xserver_arg = XSERVER_XORG;
+				}
+			}
+			continue;	/* Option isn't passed to child */
+		}
+
+		/* Look for a -gui option and don't copy it */
+		if (strncmp(argv[i], "-gui", 5) == 0) {
+			gui_opt = B_TRUE;
+			continue;	/* Option isn't passed to child */
+		}
+
+		/* Look for -dev and save the full device pathname */
+		if (strncmp(argv[i], "-dev", 5) == 0) {
+			/*
+			 * Check for -dev option errors
+			 */
+			i += 1;
+			if (i >= argc) {
+				PrintError(catgets(catfd, 11, 1,
+					    "Option requires a value, -dev"));
+				return (1);
+			}
+			if (dev_opt) {
+				PrintError(catgets(catfd, 10, 1,
+						"Duplicate option, -dev %s"),
+					    argv[i]);
+				return (1);
+			}
+			dev_opt = B_TRUE;
+
+			/*
+			 * Get the fully qualified device pathname
+			 */
+			device_path = GetDevicePathname(
+						argv[i],
+						device_path_buf,
+						sizeof (device_path_buf));
+
+			/*
+			 * Copy the -dev option to the new argument vector
+			 */
+			cfg_argv[n  ] = argv[i-1];
+			cfg_argv[n+1] = device_path;
+			n += 2;
+
+			continue;
+		}
+
+		/*
+		 * Copy this string to the arg vector for the config program
+		 */
+		cfg_argv[n] = argv[i];
+		n += 1;
+	}
+	cfg_argv[n] = NULL;
+
+	/*
+	 * Find out which X server is configured (Xsun, Xorg, ...)
+	 *
+	 *    If the X server isn't known, the GetConfigProgramPath()
+	 *    function can't return a configuration program pathname.
+	 *    Options such as -help and -list might still be useful,
+	 *    however (and someday -gui will work too).
+	 */
+	x_server = IdentifyXServer();
+	if (x_server == XSERVER_UNKNOWN) {
+		PrintError("Unable to identify the configured X server");
+	}
+
+	/*
+	 * Try to make sure the frame buffer device pathname is known
+	 */
+	if (!dev_opt) {
+		(void) GetDefaultDevicePathname(&device_path);
+	}
+
+	/*
+	 * If -help was specified or implied, display help text and exit
+	 *
+	 *    The -help option is implied iff there is no -list or -gui
+	 *    option and no option or argument intended for a device
+	 *    configuration program (n > CFG_ARG_1).  The -dev option is
+	 *    either a modifier for the explicit -help option or is an
+	 *    option for the device configuration program.
+	 */
+	if (help_opt || !(list_opt || xserver_opt || gui_opt || (n > CFG_ARG_1))) {
+		PrintHelp(x_server, device_path);
+		return (0);
+	}
+
+	/*
+	 * If -list was specified, display the frame buffer devices and exit
+	 */
+	if (list_opt) {
+		ListDevices(x_server, B_FALSE, &device_mask);
+		return (0);
+	}
+
+	/*
+	 *
+	 */
+	if (xserver_opt) {
+		ListDevices(x_server, B_TRUE, &device_mask);
+		SetXServer(x_server, xserver_arg, device_mask);
+		return (0);
+	}
+
+	/*
+	 * If -gui was specified, try to become the GUI (else exit)
+	 */
+	if (gui_opt) {
+		/*
+		 * Invoke the GUI (w/o returning), else exit unsuccessfully
+		 */
+#if (1)	/* ??? Cover for temporarily absent functionality ??? */
+		if (x_server != XSERVER_XSUN) {
+			PrintError(
+		"A GUI interface is available only with the Xsun server");
+			return (1);
+		}
+#endif
+		return (InvokeGUI());
+	}
+
+	/*
+	 * Identify and invoke the device configuration program
+	 *
+	 *    The default -dev option, if any, should be prepended
+	 *    rather than appended to the argument vector.  If the
+	 *    user-supplied argument vector ends badly (e.g. the last
+	 *    option's argument is missing), the child config program
+	 *    should be able to diagnose and report the problem
+	 *    correctly, without tripping over an appended -dev option.
+	 */
+	if ((device_path != NULL) &&
+	    (FindConfigProgram(x_server, device_path, &config_prog_path) == 0)
+				) {
+		n = 2;			/* Index for config program pathname */
+		if (!dev_opt) {
+			n = 0;		/* Index for config program pathname */
+			cfg_argv[1] = "-dev";
+			cfg_argv[2] = device_path;
+		}
+		cfg_argv[n] = config_prog_path;
+		CallConfigProgram(&cfg_argv[n]);
+	} else {
+		PrintError("Unable to find a default device");
+	}
+
+	catclose(catfd);	/* Needn't have passed this to a child */
+
+	return (1);		/* Exit unsuccessfully */
+
+}	/* main() */
+
+
+/* End of fbconfig.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/gfx_common/config/gfx_gamma_pack.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,1311 @@
+/*
+ * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 <stdio.h>		/* fprintf */
+#include <stdlib.h>		/* malloc */
+#include <strings.h>		/* strpbrk strchr strlen */ 
+#include <sys/types.h>		/* uint16_t (indirectly) */
+
+#include <gfx_gamma_pack.h>
+
+
+
+typedef enum {
+	PackSingle,
+	PackTinyGroup
+} PackTableStateType;
+
+
+
+/*
+ *************  Strings for Integer pack and unpack  ****************
+ *
+ *	Note you need to escape " with \"  and  \ with \\
+ *
+ */
+
+#define GammaIntStartPacked ('|')   /* 0x7c - Packed Region Start Token */
+#define GammaIntReserved1   ('~')   /* 0x7e - reserved, for future use */
+#define GammaIntReserved2   ('\"')  /* Hard to pack into OWconfig */
+#define GammaIntReserved3   ('\\')  /* Hard to pack into OWconfig */
+#define GammaIntReserved4   (' ')   /* Space might get whitespace altered */
+
+static  char gamma_tbl_int_pos[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+                                   ":;?!@#$%^&,.";
+static  char gamma_tbl_int_neg[] = "abcdefghijklmnopqrstuvwxyz";
+static  char gamma_tbl_int_lsb[] = "[]{}()<>'`+-/*=_";
+
+
+
+
+/*
+ *************  Packed data conversion table  ****************
+ *
+ *	Table is machine generated.
+ *	Table create code is in gamma_test.c
+ *
+ */
+
+typedef struct {
+	char	ascii;    /* packed ASCII character */
+	char	len;      /* number of bytes in sequence */
+	char	term;     /* Does this terminate a sequence */
+	int	val[4];   /* Up to 4 packed values */
+} ascii_to_four_ddel;
+
+#define DeltaTableMin      (0x21)
+#define DeltaTableMax      (0x7e)
+
+#define DeltaTableBase_4X  (0x21)
+#define DeltaTableBase_2X  (0x72)
+#define DeltaTableBase_1X  (0x7b)
+#define DeltaTableBase_0X  (0x7e)
+
+static ascii_to_four_ddel  delta_table[] = {
+    /* ! */	{ 0x21, 4, 0, {-1, -1, -1, -1} },  /* 4X */
+    /* " */	{ 0x22, 4, 0, {-1, -1, -1,  0} },
+    /* # */	{ 0x23, 4, 0, {-1, -1, -1,  1} },
+    /* $ */	{ 0x24, 4, 0, {-1, -1,  0, -1} },
+    /* % */	{ 0x25, 4, 0, {-1, -1,  0,  0} },
+    /* & */	{ 0x26, 4, 0, {-1, -1,  0,  1} },
+    /* ' */	{ 0x27, 4, 0, {-1, -1,  1, -1} },
+    /* ( */	{ 0x28, 4, 0, {-1, -1,  1,  0} },
+    /* ) */	{ 0x29, 4, 0, {-1, -1,  1,  1} },
+    /* * */	{ 0x2a, 4, 0, {-1,  0, -1, -1} },
+    /* + */	{ 0x2b, 4, 0, {-1,  0, -1,  0} },
+    /* , */	{ 0x2c, 4, 0, {-1,  0, -1,  1} },
+    /* - */	{ 0x2d, 4, 0, {-1,  0,  0, -1} },
+    /* . */	{ 0x2e, 4, 0, {-1,  0,  0,  0} },
+    /* / */	{ 0x2f, 4, 0, {-1,  0,  0,  1} },
+    /* 0 */	{ 0x30, 4, 0, {-1,  0,  1, -1} },
+    /* 1 */	{ 0x31, 4, 0, {-1,  0,  1,  0} },
+    /* 2 */	{ 0x32, 4, 0, {-1,  0,  1,  1} },
+    /* 3 */	{ 0x33, 4, 0, {-1,  1, -1, -1} },
+    /* 4 */	{ 0x34, 4, 0, {-1,  1, -1,  0} },
+    /* 5 */	{ 0x35, 4, 0, {-1,  1, -1,  1} },
+    /* 6 */	{ 0x36, 4, 0, {-1,  1,  0, -1} },
+    /* 7 */	{ 0x37, 4, 0, {-1,  1,  0,  0} },
+    /* 8 */	{ 0x38, 4, 0, {-1,  1,  0,  1} },
+    /* 9 */	{ 0x39, 4, 0, {-1,  1,  1, -1} },
+    /* : */	{ 0x3a, 4, 0, {-1,  1,  1,  0} },
+    /* ; */	{ 0x3b, 4, 0, {-1,  1,  1,  1} },
+    /* < */	{ 0x3c, 4, 0, { 0, -1, -1, -1} },
+    /* = */	{ 0x3d, 4, 0, { 0, -1, -1,  0} },
+    /* > */	{ 0x3e, 4, 0, { 0, -1, -1,  1} },
+    /* ? */	{ 0x3f, 4, 0, { 0, -1,  0, -1} },
+    /* @ */	{ 0x40, 4, 0, { 0, -1,  0,  0} },
+    /* A */	{ 0x41, 4, 0, { 0, -1,  0,  1} },
+    /* B */	{ 0x42, 4, 0, { 0, -1,  1, -1} },
+    /* C */	{ 0x43, 4, 0, { 0, -1,  1,  0} },
+    /* D */	{ 0x44, 4, 0, { 0, -1,  1,  1} },
+    /* E */	{ 0x45, 4, 0, { 0,  0, -1, -1} },
+    /* F */	{ 0x46, 4, 0, { 0,  0, -1,  0} },
+    /* G */	{ 0x47, 4, 0, { 0,  0, -1,  1} },
+    /* H */	{ 0x48, 4, 0, { 0,  0,  0, -1} },
+    /* I */	{ 0x49, 4, 0, { 0,  0,  0,  0} },
+    /* J */	{ 0x4a, 4, 0, { 0,  0,  0,  1} },
+    /* K */	{ 0x4b, 4, 0, { 0,  0,  1, -1} },
+    /* L */	{ 0x4c, 4, 0, { 0,  0,  1,  0} },
+    /* M */	{ 0x4d, 4, 0, { 0,  0,  1,  1} },
+    /* N */	{ 0x4e, 4, 0, { 0,  1, -1, -1} },
+    /* O */	{ 0x4f, 4, 0, { 0,  1, -1,  0} },
+    /* P */	{ 0x50, 4, 0, { 0,  1, -1,  1} },
+    /* Q */	{ 0x51, 4, 0, { 0,  1,  0, -1} },
+    /* R */	{ 0x52, 4, 0, { 0,  1,  0,  0} },
+    /* S */	{ 0x53, 4, 0, { 0,  1,  0,  1} },
+    /* T */	{ 0x54, 4, 0, { 0,  1,  1, -1} },
+    /* U */	{ 0x55, 4, 0, { 0,  1,  1,  0} },
+    /* V */	{ 0x56, 4, 0, { 0,  1,  1,  1} },
+    /* W */	{ 0x57, 4, 0, { 1, -1, -1, -1} },
+    /* X */	{ 0x58, 4, 0, { 1, -1, -1,  0} },
+    /* Y */	{ 0x59, 4, 0, { 1, -1, -1,  1} },
+    /* Z */	{ 0x5a, 4, 0, { 1, -1,  0, -1} },
+    /* [ */	{ 0x5b, 4, 0, { 1, -1,  0,  0} },
+    /* \ */	{ 0x5c, 4, 0, { 1, -1,  0,  1} },
+    /* ] */	{ 0x5d, 4, 0, { 1, -1,  1, -1} },
+    /* ^ */	{ 0x5e, 4, 0, { 1, -1,  1,  0} },
+    /* _ */	{ 0x5f, 4, 0, { 1, -1,  1,  1} },
+    /* ` */	{ 0x60, 4, 0, { 1,  0, -1, -1} },
+    /* a */	{ 0x61, 4, 0, { 1,  0, -1,  0} },
+    /* b */	{ 0x62, 4, 0, { 1,  0, -1,  1} },
+    /* c */	{ 0x63, 4, 0, { 1,  0,  0, -1} },
+    /* d */	{ 0x64, 4, 0, { 1,  0,  0,  0} },
+    /* e */	{ 0x65, 4, 0, { 1,  0,  0,  1} },
+    /* f */	{ 0x66, 4, 0, { 1,  0,  1, -1} },
+    /* g */	{ 0x67, 4, 0, { 1,  0,  1,  0} },
+    /* h */	{ 0x68, 4, 0, { 1,  0,  1,  1} },
+    /* i */	{ 0x69, 4, 0, { 1,  1, -1, -1} },
+    /* j */	{ 0x6a, 4, 0, { 1,  1, -1,  0} },
+    /* k */	{ 0x6b, 4, 0, { 1,  1, -1,  1} },
+    /* l */	{ 0x6c, 4, 0, { 1,  1,  0, -1} },
+    /* m */	{ 0x6d, 4, 0, { 1,  1,  0,  0} },
+    /* n */	{ 0x6e, 4, 0, { 1,  1,  0,  1} },
+    /* o */	{ 0x6f, 4, 0, { 1,  1,  1, -1} },
+    /* p */	{ 0x70, 4, 0, { 1,  1,  1,  0} },
+    /* q */	{ 0x71, 4, 0, { 1,  1,  1,  1} },
+    /* r */	{ 0x72, 2, 0, {-1, -1, 99, 99} },  /* 2X */
+    /* s */	{ 0x73, 2, 0, {-1,  0, 99, 99} },
+    /* t */	{ 0x74, 2, 0, {-1,  1, 99, 99} },
+    /* u */	{ 0x75, 2, 0, { 0, -1, 99, 99} },
+    /* v */	{ 0x76, 2, 0, { 0,  0, 99, 99} },
+    /* w */	{ 0x77, 2, 0, { 0,  1, 99, 99} },
+    /* x */	{ 0x78, 2, 0, { 1, -1, 99, 99} },
+    /* y */	{ 0x79, 2, 0, { 1,  0, 99, 99} },
+    /* z */	{ 0x7a, 2, 0, { 1,  1, 99, 99} },
+    /* { */	{ 0x7b, 1, 1, {-1, 99, 99, 99} },  /* 1X */
+    /* | */	{ 0x7c, 1, 1, { 0, 99, 99, 99} },
+    /* } */	{ 0x7d, 1, 1, { 1, 99, 99, 99} },
+    /* ~ */	{ 0x7e, 0, 1, {99, 99, 99, 99} }   /* 0X */
+};
+
+
+
+/*
+ *****************************************************************************
+ *****************************************************************************
+ *
+ *	Multibyte pack routines.
+ *
+ *	The functions pack a series of values in the range
+ *	of {-1, 0 1}.   These values are typical of the
+ *	second derivative of smooth curves.
+ *	It packs sequences of up to 4 of these in a row.
+ *	There are also codes for sequences of 2 and 1.
+ *	One byte sequences are always at the end, and
+ *	terminate the string.  There's also a "zero byte"
+ *	termination code for even length strings.
+ *	
+ *****************************************************************************
+ *****************************************************************************
+ */
+		
+
+/*
+ ***********************  pack_tiny_bytes()  **********************
+ *
+ *	This packs up to four values in array "data" and
+ *	sets the result into the string character pointed
+ *	to by "byte".   It returns the number of values
+ *	that it packed (that were consumed from "data").
+ *
+ *	If no sequences are found, it stores a terminator
+ *	into "byte", and returns zero ints consumed.
+ *	It's up to the calling routine to determine
+ *	whether to keep the terminator or ignore it.
+ *	If you are currently packing a valid sequence,
+ *	it's the terminator.   If your trying to find
+ *	the begining of a new section, you'd ignore it.
+ *	
+ *	This function does not search the delta_table,
+ *	but assumes a certain mathematical sequence.
+ *	That's why that table was originally computer
+ *	generated to achieve the data (used in unpack).
+ *
+ */
+
+
+static int
+pack_tiny_bytes (char *byte, int *data, int max_len)
+{
+	int            good_len;
+	int            pack_len;
+	int            p;
+	unsigned int   pack_byte;
+	unsigned int   base_byte;
+
+	if (max_len < 0) return(-1);
+	if (max_len > 4) max_len = 4;
+
+/******	See how many of the next 4 elements are in range.
+ */
+
+	for (good_len=0 ; good_len<max_len ; good_len++) {
+		if (data[good_len] < -1) break;
+		if (data[good_len] >  1) break;
+	}
+
+/******	Pack 1, 2, or 4 bytes  (3 end up as 2,1)
+ *	Zero is special, since 4 and 2 are not
+ *	terminators. So even length sequences
+ *	require an extra terminator of zero length.
+ *	One element sequences will always end a section
+ *	of odd length, so it's assumed to be a terminator.
+ */
+
+	switch (good_len) {
+	    case 4:
+		pack_len = 4;
+		base_byte = DeltaTableBase_4X;
+		break;
+	    case 3:
+	    case 2:
+		pack_len = 2;
+		base_byte = DeltaTableBase_2X;
+		break;
+	    case 1:
+		pack_len = 1;
+		base_byte = DeltaTableBase_1X ;
+		break;
+	    case 0:
+		*byte     = DeltaTableBase_0X ;
+		return(0);          /* end of section */
+		break;
+	};
+
+/******	Pack the elements using base 3 arithmetic.
+ */
+
+	pack_byte = 0;
+	for (p=0 ; p<pack_len ; p++) {
+		pack_byte *= 3;
+		pack_byte += data[p] + 1;  /* bias [-1,1] to [0,2] */
+	}
+	pack_byte += base_byte;
+
+	*byte = (char) pack_byte;
+
+	return (pack_len);
+}
+
+
+/*
+ ***********************  unpack_tiny_bytes()  **********************
+ *
+ *	This unpacks up to four values into array "data"
+ *	from the string character pointed to by "byte".
+ *
+ *	It returns the number of values that it unpacked 
+ *	(that were filled into "data").  It will not
+ *	fill in the "data" table past element "max_len"
+ *	(this gives a warning in DEBUG mode).
+ *	
+ *	The unpacking info is contained in delta_table[].
+ *
+ */
+
+
+static int
+unpack_tiny_bytes (char byte, int *data, int max_len)
+{
+	int    w;
+	int    offs;
+	int   *tbl;
+	char   endtb;
+	char   words;
+	char   asc_b;
+
+	if (byte < DeltaTableMin) return(0);
+	if (byte > DeltaTableMax) return(0);
+
+	offs = byte - DeltaTableMin;
+
+	words = delta_table[offs].len;
+	asc_b = delta_table[offs].ascii;
+	endtb = delta_table[offs].term;
+	tbl   = delta_table[offs].val;
+
+#ifdef DEBUG
+	if (asc_b != byte) {
+		fprintf(stderr, "unpack_tiny_bytes: offset wrong\n");
+	}
+#endif
+
+	if (words == 0) {
+		return (0);
+	}
+
+	if (words > max_len) {
+		words = max_len;
+#ifdef DEBUG
+		fprintf(stderr, "unpack_tiny_bytes: length mismatch\n");
+#endif
+	}
+
+	for (w=0 ; w < words ; w++) {
+		data[w] = tbl[w];
+	}
+
+	return(words);
+}
+
+
+
+
+/*
+ *****************************************************************************
+ *****************************************************************************
+ *
+ *	Integer Pack Routines (and wrappers).
+ *
+ *	These functions pack an arbitrary integer into
+ *	a series of bytes.   Small values (positive and neg)
+ *	are packed into a single byte.  Larger values pack
+ *	some of the "bits" into the first byte, and then
+ *	calls this function recursively to pack the rest,
+ *	until the number gets within the "small" range.
+ *
+ *	The core functions below are passed in the ranges
+ *	for the positive, negative, and low order "bits".
+ *	The also compute arbitrariily big numbers
+ *	  (as big as your compiler's int range).
+ *	These should be wrapped by functions that setup the
+ *	tables to tune these ranges for a particular
+ *	application (bias toward small/large, or pos/neg).
+ *
+ *	The wrappers far below are tuned for 8-10 bit gamma
+ *	tables and their second derivitive's range.
+ *
+ *****************************************************************************
+ *****************************************************************************
+ */
+
+
+/*
+ ***********************  pack_int_core()  **********************
+ *
+ *	This packs the integer "data" into a series of bytes.
+ *	The bytes are filled in starting at the location
+ *	pointed to by "byte".   It's up to the caller to
+ *	make sure there is enough space for this to fit.
+ *	The number of bytes packed is returned to caller.
+ *	
+ *	The three _tbl strings control what byte values
+ *	are used to pack the integers. pos_tbl and neg_tbl are
+ *	used to pack small positive and negative integers.
+ *	The length of these strings determine the range
+ *	of small integers before it goes to multibyte packing.
+ *	lsb_tbl is used for the "extra" bytes for both 
+ *	positive and negative values in a multibyte sequence.
+ *	The extra bytes come first, until a "small" byte
+ *	actually terminates the sequence (and determines
+ *	if it's positive or negative).
+ *	These three strings must not contain any duplicate
+ *	characters within or between the strings.
+ *
+ */
+
+#if defined(DEBUG) && 0    /* Use "1" for more debug */
+#define Dprintf printf
+#else
+static void Dprintf(char*d,...){}
+#endif
+
+static int
+pack_int_core(
+	char *byte,
+	int   data,
+	char *pos_tbl,
+	char *neg_tbl,
+	char *lsb_tbl  )
+{
+	int  msb;
+	int  lsb;
+	int  da2;
+	int  rc;
+	int  max_pos_lim;
+	int  min_neg_lim;
+	int  lsb_range;
+	char *ovlap;
+
+	Dprintf("\npack_int: ====> val=%d\n", data);
+
+	max_pos_lim =   strlen(pos_tbl) - 1;  /*  0 to n-1 */
+	min_neg_lim = - strlen(neg_tbl);      /* -1 to  -n */
+	lsb_range   =   strlen(lsb_tbl);      /* n values  */
+
+/******	Make sure that we don't have any bytes overlapping
+ *	in the three packing sequence strings.  This would
+ *	cause unpacking to be ambiguous (impossible).
+ */
+
+#ifdef DEBUG
+	ovlap = strpbrk(pos_tbl, neg_tbl);
+	if (ovlap != NULL) {
+	  fprintf(stderr, "pack_int_core: overlap(pn)=\'%c\'\n", *ovlap);
+	}
+	ovlap = strpbrk(neg_tbl ,lsb_tbl);
+	if (ovlap != NULL) {
+	  fprintf(stderr, "pack_int_core: overlap(nl)=\'%c\'\n", *ovlap);
+	}
+	ovlap = strpbrk(lsb_tbl ,pos_tbl);
+	if (ovlap != NULL) {
+	  fprintf(stderr, "pack_int_core: overlap(lp)=\'%c\'\n", *ovlap);
+	}
+#endif 
+
+
+
+	if (data >= 0) {
+
+/**************	Positive small value.
+ *		Pack the value from the Pos table
+ *		as a single byte.
+ */
+		if (data <= max_pos_lim) {
+			*byte = pos_tbl[data];
+
+			Dprintf(" Pos(small) = %d, ",       data);
+			Dprintf("\tbyte=\'%c\'=0x%02x\n\n", *byte, *byte);
+
+			return (1);
+
+/**************	Positive large value.
+ *		Find the least significant portion, and then
+ *		call recursively to find the rest of it.
+ *		
+ *		First, bias or origin past the end of the
+ *		range of "small" positive int's.
+ *		Then divide by the lsb range and pack
+ *		the remainder in this byte.
+ *		Call recursively until it's finally
+ *		small int, and then back out counting
+ *		the bytes in the return value.
+ *
+ */
+		} else {
+			da2   = data - (max_pos_lim + 1);
+			msb   =       da2/lsb_range;
+			lsb   = da2 - msb*lsb_range;
+			*byte = lsb_tbl[lsb];
+
+			Dprintf(" Pos(large,Da2)=%d\n",    da2);
+			Dprintf(" Pos(large,MSB)=%d\n",    msb);
+			Dprintf("    (large,LSB)=%d, ",    lsb);
+			Dprintf("\tbyte=\'%c\'=0x%02x\n",  *byte, *byte);
+
+			rc = pack_int_core (byte+1,  msb,
+			                    pos_tbl, neg_tbl, lsb_tbl  );
+
+			Dprintf("Done: Pos(large) bytes=%d", (rc+1));
+			Dprintf(" ====> val=%d\n",           data);
+
+			return (1 + rc);
+		}
+
+	} else {
+
+/**************	Negative small value.
+ *		Pack the value from the Neg table
+ *		as a single byte (backward from -1).
+ */
+		if (data >= min_neg_lim) {
+			*byte = neg_tbl[ (-data-1) ] ;
+
+			Dprintf(" Neg(small) = %d, ",       data);
+			Dprintf("\tbyte=\'%c\'=0x%02x\n\n", *byte, *byte);
+
+			return (1);
+			
+/**************	Negative large value.
+ *		Find the least significant portion, and then
+ *		call recursively to find the rest of it.
+ *		
+ *		First, bias or origin past the end of the
+ *		range of "small" negative int's.
+ *		Then divide by the lsb range and pack
+ *		the remainder in this byte.
+ *		Call recursively until it's finally
+ *		small int, and then back out counting
+ *		the bytes in the return code.
+ *
+ */
+		} else {
+			da2   = data - (min_neg_lim - 1);
+			msb   =       da2/lsb_range - 1;
+			lsb   = da2 - msb*lsb_range - 1;
+			*byte = lsb_tbl[lsb];
+
+			Dprintf(" Neg(large,Da2)=%d\n",   da2);
+			Dprintf(" Neg(large,MSB)=%d\n",   msb);
+			Dprintf("    (large,LSB)=%d, ",   lsb);
+			Dprintf("\tbyte=\'%c\'=0x%02x\n", *byte, *byte);
+
+			rc = pack_int_core (byte+1,  msb,
+			                    pos_tbl, neg_tbl, lsb_tbl  );
+
+			Dprintf("Done: Neg(large) bytes=%d", (rc+1));
+			Dprintf(" ====> val=%d\n", data);
+
+			return (1 + rc);
+		}
+
+	}
+}
+
+
+
+
+/*
+ ***********************  unpack_int_core()  **********************
+ *
+ *	This unpacks the integer "data" from a series of bytes.
+ *	The bytes are scanned starting at the location
+ *	pointed to by "inp_str".  The result is stored using
+ *	the pointer "data" (normally pointing somewhere
+ *	into the middle of an array in the caller).
+ *	
+ *	The three _tbl strings control the unpacking
+ *	the same way as the unpack function above.
+ *	
+ *	It returns the number of bytes needed to
+ *	unpack the value (consumed from inp_str).
+ *
+ */
+
+
+#if defined(DEBUG) && 0    /* Use "1" for more debug */
+#define Cprintf printf
+#else
+static void Cprintf(char*d,...){}
+#endif
+
+
+#define UnpackTypeIntPos (0x1)
+#define UnpackTypeIntNeg (0x2)
+#define UnpackTypeIntLSB (0x4)
+
+
+static int
+unpack_int_core(
+	char *inp_str,
+	int  *data,
+	char *pos_tbl,
+	char *neg_tbl,
+	char *lsb_tbl  )
+{
+	int  rc;
+	int  msb;
+	int  lsb;
+	int  valu;
+	int  max_pos_lim;
+	int  min_neg_lim;
+	int  lsb_range;
+	int  unpack_type;
+	char *index_p;
+
+
+	if( inp_str == NULL) return(0);
+	if(*inp_str == 0   ) return(0);
+
+	max_pos_lim =   strlen(pos_tbl) - 1;  /*  0 to n-1 */
+	min_neg_lim = - strlen(neg_tbl);      /* -1 to  -n */
+	lsb_range   =   strlen(lsb_tbl);      /* n values  */
+
+
+
+/******	Search the three strings, and find the index
+ *	of the next character (should only be in one
+ *	of these, but try all 3 for error checking).
+ *	Compute the value of the small int, or the
+ *	partial piece for use later.
+ *	Compute a mask defining which string we found
+ *	our byte in (hopefully only one).
+ */
+
+	unpack_type = 0;
+
+	index_p = strchr (lsb_tbl, *inp_str);
+	if (index_p != NULL) {
+		valu         = index_p - lsb_tbl;
+		unpack_type |= UnpackTypeIntLSB;
+	}
+
+	index_p = strchr (neg_tbl, *inp_str);
+	if (index_p != NULL) {
+		valu         = neg_tbl - index_p - 1;
+		unpack_type |= UnpackTypeIntNeg;
+	}
+
+	index_p = strchr (pos_tbl, *inp_str);
+	if (index_p != NULL) {
+		valu         = index_p - pos_tbl;
+		unpack_type |= UnpackTypeIntPos;
+	}
+
+
+
+	switch(unpack_type) {
+
+/********** These are small integers.
+ *	    We already computed the value above.
+ *	    Store it, and return 1 byte consumed.
+ */
+
+	    case UnpackTypeIntPos:
+	    case UnpackTypeIntNeg:
+		*data = valu;
+		Cprintf("unpack_int: 0x%2x, \'%c\' ====> %d\n",
+		        *inp_str, *inp_str, *data);
+		return (1);
+		break;
+
+/********** This is for large multibyte sequences.
+ *	    Since the least significant piece is first,
+ *	    we recursively call ourselves till we finally
+ *	    find a small "byte" to terminate sequence.
+ *	    That last byte will also determine if it's
+ *	    positive or negative.   Then we build up
+ *	    the integer as we unwrap the recursive calls.
+ *	    The return code also counts up the number
+ *	    of bytes consumed.
+ */
+
+	    case UnpackTypeIntLSB:
+		Cprintf("unpack_int: 0x%2x, \'%c\' LSB %d\n",
+		        *inp_str, *inp_str, valu);
+		rc = unpack_int_core (inp_str+1,
+		                      &msb,
+		                      pos_tbl, neg_tbl, lsb_tbl  );
+		if (rc > 0) {
+			Cprintf("unpack_int: 0x%2x, \'%c\' MSB %d\n",
+			        *inp_str, *inp_str, msb);
+			if (msb >=0) {
+				lsb   = valu + max_pos_lim + 1;
+				*data = msb * lsb_range + lsb;
+			} else {
+				lsb   = valu + min_neg_lim + lsb_range;
+				*data = (msb-1) * lsb_range + lsb;
+			}
+			Cprintf("unpack_int: 0x%2x, \'%c\' combined %d\n",
+			        *inp_str, *inp_str, *data);
+		}
+		return (1 + rc);
+		break;
+
+/********** Error cases.  Return 0 bytes consumed.
+ *	    Print warning in debug more for:
+ *	      - Byte not found in any string
+ *	      - Byte found in multiple strings
+ */
+
+	    case 0:
+#ifdef DEBUG
+		fprintf(stderr, "unpack_int_core: ");
+		fprintf(stderr, "invalid byte = 0x%2x\n", *inp_str);
+#endif
+		return(0);
+		break;
+
+	    default:
+#ifdef DEBUG
+		fprintf(stderr, "unpack_int_core: ");
+		fprintf(stderr, "range overlap, mask=0x%x\n",
+		                 unpack_type);
+		fprintf(stderr, "  Check wrapper function\n");
+#endif
+		return(0);
+		break;
+
+	};
+}
+
+
+
+/*
+ ***********************    pack_gam_int()  **********************
+ *                        unpack_gam_int()
+ *
+ *	Wrappers to un/pack one integer into the output string.
+ *	Returns the number of bytes inserted.
+ *	Strings are optimized for small integers,
+ *	which are typical of the second derivative
+ *	of smooth curves like gamma functions.
+ *
+ *	If you typically packed larger integers, you could
+ *	make different wrappers.   For those, you'd make the
+ *	LSB strings bigger, so you wouldn't have to extend
+ *	as much (you have a lower chance to getting it
+ *	done in one byte, though).  If you didn't expect
+ *	negative numbers, you could make that string
+ *	very short (even one byte, didn't debug zero)
+ *	so you can spend you codes on the other two.
+ *	
+ */
+
+#ifndef INT_TEST  /* only export for validation, or make better name */
+static
+#endif
+int
+pack_gam_int(char *byte, int data)
+{
+	int rc;
+
+	rc = pack_int_core(byte, data, gamma_tbl_int_pos,
+	                               gamma_tbl_int_neg,
+	                               gamma_tbl_int_lsb  );
+	return (rc);
+}
+
+
+#ifndef INT_TEST  /* only export for validation, or make better name */
+static
+#endif
+int
+unpack_gam_int(char *byte, int *data)
+{
+	int rc;
+
+	rc = unpack_int_core(byte, data, gamma_tbl_int_pos,
+	                                 gamma_tbl_int_neg,
+	                                 gamma_tbl_int_lsb  );
+	return (rc);
+}
+
+
+
+
+/*
+ *****************************************************************************
+ *****************************************************************************
+ *
+ *	Integer table to string Pack routines
+ *
+ *	This section packs and unpacks groups of integers.
+ *	It's tuned for the second derivitive of smooth
+ *	curves, which typically have integers that are
+ *	1, 0, or +1.  It tries to match longs strings of
+ *	these and pack them into a single byte.
+ *	Otherwise, it packs a single integer into one
+ *	or more bytes using a different algorithm
+ *	until it can get back to strings of [-1, +1].
+ *	
+ *****************************************************************************
+ *****************************************************************************
+ */
+
+
+
+/*
+ ***********************  pack_tbl_to_string()  **********************
+ *
+ *	Pack an integer table into a string.
+ *
+ *	The calling function must make sure the string
+ *	is large enough to pack the entire table.
+ *	This is mostly based on pack_gam_int() which
+ *	should be 8 bytes for a maximum range int_32.
+ *	   (I suppose you could implement a "try" mode
+ *	    if str_data was NULL, and you modified this
+ *	    function and pack_tiny_bytes() not to store
+ *	    values and just count.   Gamma tables aren't
+ *	    that big, though, so I'm just making it "big"
+ *	    in the calling function, for now)
+ *
+ *	The return value is the number of bytes filled into
+ *	the result string.
+ *
+ *	This is optimized to looks for sequences of
+ *	  these three tiny numbers:  -1, 0 +1
+ *	If these are not found, it packs the integers
+ *	  into one or more bytes individually.
+ *	The "state" variable keeps track of switching
+ *	  between the two packing methods
+ *
+ */
+
+#if defined(DEBUG) && 0    /* Use "1" for more debug */
+#define Eprintf printf
+#else
+static void Eprintf(char*d,...){}
+#endif
+
+
+static int
+pack_tbl_to_string (char       *str_data
+                   ,int         str_len
+                   ,int        *tbl
+                   ,int         tbl_len
+                   )
+{
+	int                 g;
+	int                 pw;
+	int                 str_count;
+	PackTableStateType  state;
+
+	if (str_data == NULL) return(0);
+	if (tbl      == NULL) return(0);
+
+	str_count = 0;
+	state     = PackSingle;
+
+
+	for (g=0 ; g<tbl_len ; ) {
+	    Eprintf("\n{%d,%d,%d,%d}\n",tbl[g],tbl[g+1],tbl[g+2],tbl[g+3]);
+
+/********** Make sure we don't overrun table.
+ */
+	    if (str_count+4 >= str_len) {
+		return(0);
+	    }
+
+/********** Try to pack multiple tiny values,
+ *	    and see if we succeeded.
+ */
+	    pw = pack_tiny_bytes (str_data+str_count, 
+		                  tbl+g,
+		                  tbl_len-g);
+	    Eprintf("pw=%d\n", pw);
+
+
+	    switch(state) {
+
+
+/************** Here we've been packing full sized integer, and
+ *		are trying to find a group of 4 tiny ones.
+ *
+ *		If we haven't found them yet, pack a single int
+ *		and continue the search till we do.
+ *		
+ *		If we've just found a new tiny sequence,
+ *		then insert the transition token, switch
+ *		to the packing multiple values.  Don't
+ *		move the gamma pointer (g) so we re-run
+ *		the current position in the other state.
+ *		
+ *		In all sections, make sure we have enough room
+ *		in the results string for worst case results,
+ *		or return that we failed (zero words packed).
+ */
+	        case PackSingle:
+		    if (pw < 4) {
+			Eprintf("Val = %d\n", tbl[g]);
+			if (str_count+8 >= str_len)  return(0);
+			str_count += pack_gam_int(str_data+str_count, tbl[g]);
+			g++;
+		    } else {
+			if (str_count+1 >= str_len)  return(0);
+			str_data[str_count]=0x7c;
+			str_count++;
+			state = PackTinyGroup;
+			Eprintf("Start Compressed\n");
+		    }
+		    break;
+
+/************** Here we've already been packing multiple tiny values.
+ *		Adjust pointer to move past what we've just packed.
+ *		When pw = 0,1 means we've reached the end of a
+ *		section of tiny values.   Switch back to packing
+ *		full integer values.
+ */
+	        case PackTinyGroup:
+		    if (pw >= 0) {
+			g += pw;
+			str_count++;
+			if (pw <= 1) {
+				state = PackSingle;
+				Eprintf("End Compressed\n");
+			}
+		    } else {
+			return (0);  /* shouldn't happen, error ? */
+		    }
+		    break;
+
+	    };
+
+#ifdef Eprintf
+	    str_data[str_count]=0;
+	    Eprintf("%s\n", str_data);
+#endif
+
+	}
+
+/******	Add a final terminator if section ended
+ *	at a boundary that's not a terminator.
+ */
+	if (pw >= 2) {
+		if (str_count+1 >= str_len)  return(0);
+		pack_tiny_bytes (str_data+str_count, NULL, 0);
+		str_count++;
+	}
+
+
+/******	Terminate the C string.
+ *
+ */
+	if (str_count+1 >= str_len)  return(0);
+	str_data[str_count]=0;
+
+	return(str_count);
+}
+
+
+
+/*
+ ***********************  unpack_string_to_tbl()  **********************
+ *
+ *	This function unpacks the string back into a table
+ *
+ *	The integer output table has to be allocated in
+ *	the caller to the correct length.
+ *
+ *	The return value is the number of values unpacked.
+ */
+
+#if defined(DEBUG) && 0    /* Use "1" for more debug */
+#define Uprintf printf
+#else
+static void Uprintf(char*d,...){}
+#endif
+
+
+static int
+unpack_string_to_tbl (char       *packed_string
+                     ,int        *tbl
+                     ,int         tbl_len
+                     )
+{
+	int                  tb;
+	int                  ll;
+	int                  tcount;
+	char                *sp;
+	PackTableStateType   state;
+
+
+	if ( packed_string == NULL) return(0);
+	if (*packed_string == 0   ) return(0);
+	sp = packed_string;
+
+	tcount = 0;
+	state     = PackSingle;
+
+
+	while (*sp != 0) {
+	    if (tcount >= tbl_len) {
+
+		/* ignore a zero length terminator at the end */
+		if (*sp != DeltaTableBase_0X) {
+#ifdef DEBUG
+			fprintf(stderr, "unpack: Length Mismatch\n");
+#endif
+			return (0);
+		}
+
+	    }
+
+	    switch(state) {
+
+/************** Here we single integer values till we find
+ *		the token to switch into multiple unpack mode.
+ */
+		case PackSingle:
+		    if (*sp == 0x7c) {
+			sp++;
+			state = PackTinyGroup;
+			Uprintf("unpack: Start Compressed\n");
+		    } else {
+			ll = unpack_gam_int(sp, tbl+tcount);
+			if (ll == 0) {
+				return (0);
+			} else {
+				sp += ll;
+				tcount++;
+			}
+		    }
+		    break;
+
+/************** Here we unpack multiple tiny values.
+ *		When tb = 0,1 means we've reached the end of a
+ *		section of tiny values.   Switch back to packing
+ *		full integer values.
+ */
+		case PackTinyGroup:
+
+		    tb = unpack_tiny_bytes (*sp, tbl+tcount, tbl_len-tcount);
+
+		    sp++;
+		    tcount += tb;
+
+		    if ( (tb == 0) || (tb == 1) ) {
+			state = PackSingle;
+			Uprintf("unpack: End Compressed\n");
+		    }
+
+		    break;
+
+	    };
+
+	}
+
+	return (tcount);
+}
+
+
+
+
+
+/*
+ *****************************************************************************
+ *****************************************************************************
+ *
+ *	Gamma table routines
+ *
+ *	These are the high level routines that deal with
+ *	the gamma table packing.   These actually take
+ *	the second derivitive of the data table.
+ *	Since most gamma tables are ver smooth, this
+ *	should produce very small numbers.
+ *	Typically you only get values of -1, 0, +1
+ *	in the bulk of the table after a little
+ *	transient instability at the start of the table.
+ *	A header is also added, including a version
+ *	number and a length.
+ *
+ *****************************************************************************
+ *****************************************************************************
+ */
+
+
+
+
+/*
+ ***********************  pack_gamma_string()  **********************
+ *
+ *	Pack integer tbl[tbl_len] into a string.
+ *	The string is malloc'd and the pointer is returned.
+ *	This space must be free'd up by the caller.
+ *
+ *	This is an inner helper function that just
+ *	packs the array (typically the 2nd derivitive),
+ *	and should be called by an appropriate wrapper
+ *	that performs the high level functions and
+ *	converts to an int array.
+ *
+ */
+
+
+
+
+static int
+pack_gamma_string (char      **packed_string
+                  ,int        *tbl
+                  ,int         tbl_len
+                  )
+{
+	int    rc;
+
+	int    str_alloc;
+	char  *str_data;
+	int    str_count;
+	int    str_left;
+
+
+/******	Allocate a string that big enough for a
+ *	worst case input.  This is way too big,
+ *	but we'll copy it and trim it off below.
+ */
+	str_alloc  = tbl_len*8 + 20; /* worst case */
+	str_data   = malloc(str_alloc);
+	str_count  = 0;
+
+
+/******	Add a "gamma" header to the string,
+ *	including version numbers for future expansion.
+ *	Pack the table length is for:
+ *	    Error checking on unpack
+ *	    Unpacker can malloc data table up front
+ *	      since it knows the size.
+ */
+	str_data[str_count++]  =  'G'; /* Gamma packing type */
+	str_data[str_count++]  =  '0'; /* Major Rev */
+	str_data[str_count++]  =  '0'; /* Minor Rev */
+
+	str_count += pack_gam_int(str_data+str_count, tbl_len);
+
+
+/******	Move past the header.
+ *	Pack the array into the string,
+ *	  and check for errors.
+ *	Find the new end of the string.
+ */
+	str_left = str_alloc - str_count;
+
+	rc = pack_tbl_to_string (str_data+str_count,
+	                         str_left, tbl, tbl_len);
+
+	if (rc <= 0) {
+		return (rc);
+	} else {
+		str_count += rc;
+	}
+
+
+/******	Make a new (much shorter) copy to return.
+ *	Free temporary workspace.
+ */
+	*packed_string = strdup(str_data);
+	free(str_data);
+
+	return(str_count);
+}
+
+
+
+/*
+ ***********************  gfx_pack_gamma_string_16()  **********************
+ *
+ *	This is the wrapper for 16-bit unsigned int
+ *	gamma tables.  
+ *
+ *	It packs gamma_entries elements in array gt_data[].  
+ *
+ *	It returns a pointer to the the resulting string, 
+ *	which is dynamically allocated.
+ *	This space must be free'd up by the caller.
+ *	
+ *	This function converts the uint16_t table
+ *	elements into int's as it's computing
+ *	the second derivitive.  It then calls
+ *	pack_gamma_string() to process the data.
+ *
+ */
+
+
+int
+gfx_pack_gamma_string_16 (char      **gamma_string
+                         ,int         gamma_entries
+                         ,uint16_t   *gt_data
+                         )
+{
+	int    g;
+	int    curr_val;
+	int    last_val;
+	int    curr_del;
+	int    last_del;
+	int   *ddel;
+	int    rc;
+
+	ddel = (int *) malloc( gamma_entries * sizeof(int) );
+
+
+	last_val = 0;
+	last_del = 0;
+
+	for (g=0 ; g<gamma_entries ; g++) {
+		curr_val = gt_data[g];
+		curr_del = curr_val - last_val;
+		ddel[g]  = curr_del - last_del;
+#if 0
+		printf("ix=%4d  val=%4d,%03x  del=%4d  ddel=%4d\n", 
+		        g, curr_val, curr_val, curr_del, ddel[g] );
+#endif
+		last_val = curr_val;
+		last_del = curr_del;
+	}
+
+
+	rc = pack_gamma_string (gamma_string, ddel, gamma_entries);
+
+	free(ddel);
+
+	return (rc);
+
+}
+
+
+/*
+ ***********************  gfx_unpack_gamma_string_16()  **********************
+ *
+ *	This function takes a gamma string and
+ *	unpacks it into a unsigned 16-bit integer array.
+ *
+ *	The results array is filled in up to max_entries
+ *	elements (a warning is given for a length mismatch
+ *	when compiled in DEBUG mode).
+ *
+ *	It first checks the header and allocates a temp array.
+ *	Then it unpacks the string, and undoes the second
+ *	derivative by integrating (accumulating) the table.
+ *
+ */
+
+
+int
+gfx_unpack_gamma_string_16 (char       *str
+                           ,int         max_entries
+                           ,uint16_t   *gt_data
+                           )
+{
+	int    g;
+	int    curr_val;
+	int    last_val;
+	int    curr_del;
+	int    last_del;
+	int   *ddel;
+	int    str_entries;
+	int    rc;
+	int    str_count;
+
+
+	if (str == NULL) return (-1);
+
+	str_count=0;
+	if (str[str_count++] != 'G') return (-1);
+	if (str[str_count++] != '0') return (-1);
+	if (str[str_count++] != '0') return (-1);
+
+	rc = unpack_gam_int(str+str_count, &str_entries);
+	if (rc <= 0) {
+		return (rc);
+	} else {
+		str_count += rc;
+	}
+
+#ifdef DEBUG
+	if (str_entries != max_entries) {
+		fprintf(stderr, "\nstr_entries = %d\n", str_entries);
+		fprintf(stderr, "max_entries = %d\n\n", max_entries);
+	}
+#endif
+
+	ddel = (int *) malloc( str_entries * sizeof(int) );
+
+	for (g=0 ; g<str_entries ; g++) {
+		ddel[g] = 0;
+	}
+
+
+	rc = unpack_string_to_tbl (str+str_count, ddel, str_entries);
+
+	last_val = 0;
+	last_del = 0;
+
+	for (g=0 ; g<max_entries ; g++) {
+		curr_del   = ddel[g]  + last_del;
+		curr_val   = curr_del + last_val;
+		gt_data[g] = (uint16_t) curr_val;
+
+#if 0
+		printf("ix=%4d  val=%4d,%03x  del=%4d  ddel=%4d\n", 
+		        g, curr_val, curr_val, curr_del, ddel[g] );
+#endif
+		last_val = curr_val;
+		last_del = curr_del;
+	}
+
+
+	free(ddel);
+
+	return (rc);
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/gfx_common/config/gfx_res_util.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,489 @@
+/*
+ * Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 <stdio.h>
+#include <math.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <search.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <X11/Sunowconfig.h>		/* for OWconfig routines */
+
+#include <gfx_res_util.h>		/* our definitions */
+#include <gfx_list_util.h>
+
+
+static char	   *owvid_class    = "XVIDEOTIMING";
+static void        *res_table_root =  NULL;
+
+
+typedef enum {
+    video_Hact        ,
+    video_Hfp         ,
+    video_Hsw         ,
+    video_Hbp         ,
+    video_Hsrp        ,
+
+    video_Vact        ,
+    video_Vfp         ,
+    video_Vsw         ,
+    video_Vse         ,
+    video_Vbp         ,
+
+    video_Pclk        ,
+    video_Fint        ,
+    video_Fseq        ,
+    video_Fst         ,
+
+    video_Stype       ,
+    video_SonG        ,
+    video_SHpol       ,
+    video_SVpol       ,
+    video_SGpol       ,
+
+    video_EncodStd    ,
+    video_HUndScan    ,
+    video_VUndScan    ,
+
+    res_label_last
+} GFXResLabel;
+
+
+
+static OWConfigTableEntry GFXResTable[] = {
+    { video_Hact        , "HorizActive"               },
+    { video_Hfp         , "HorizFrontPorch"           },
+    { video_Hsw         , "HorizSyncWidth"            },
+    { video_Hbp         , "HorizBackPorch"            },
+    { video_Hsrp        , "HorizSyncWidthDVS"         },
+
+    { video_Vact        , "VertActive"                },
+    { video_Vfp         , "VertFrontPorch"            },
+    { video_Vsw         , "VertSyncWidth"             },
+    { video_Vse         , "VertSyncExtension"         },
+    { video_Vbp         , "VertBackPorch"             },
+
+    { video_Pclk        , "PixelClock"                },
+    { video_Fint        , "Interlace"                 },
+    { video_Fseq        , "FieldSeq"                  },
+    { video_Fst         , "Stereo"                    },
+
+    { video_Stype       , "SyncType"                  },
+    { video_SonG        , "SyncOnG"                   },
+    { video_SHpol       , "SyncHorizPolarity"         },
+    { video_SVpol       , "SyncVertPolarity"          },
+    { video_SGpol       , "SyncGreenPolarity"         },
+
+    { video_EncodStd    , "EncoderStandard"           },
+    { video_HUndScan    , "EncoderHorizUnderscan"     },
+    { video_VUndScan    , "EncoderVertUnderscan"      },
+
+    { res_label_last    ,  NULL                       }
+};
+
+
+
+
+
+
+/* attribute values used in OWconfig file */
+static char *yes = "YES";
+static char *no  = "NO";
+
+
+#ifndef TRUE
+#define TRUE 1
+#define FALSE 0
+#endif
+
+
+
+
+
+
+/*
+ *  This function loads a video resolution from the file,
+ *  and fills in the generic SunVideoTiming structure.
+ *  It returns an error code if a problem occurs.
+ *
+ *  This function requires a wrapper to fill in optional
+ *  fields that may not be in the file.
+ *  A minimal one is provided below: sun_get_ow_video_values_raw().
+ *  Another one fills in the values for 1152x900 as
+ *  a fallback in case the file read totally fails,
+ *  it will always return something valid (for X windows).
+ *
+ */
+
+static int
+sun_get_ow_video_values_file (char             *timingname,
+	                      SunVideoTiming   *vidtiming   )
+{
+	OWconfigAttribute  *ap;
+	OWconfigAttribute  *inst_ptr;
+	OWConfigTableEntry *entry;
+	int                 attr_cnt;
+	int                 i;
+
+	if (timingname==NULL || *timingname==0) {
+#ifdef DEBUG1
+	    fprintf( stderr, "Timing Name was empty or NULL.\n");
+#endif
+	    return -1;
+	}
+
+
+	/* get all the attributes for our class and instance */
+
+	inst_ptr = OWconfigGetInstance(owvid_class, timingname, &attr_cnt);
+	if (!inst_ptr) {
+#ifdef DEBUG1
+	    fprintf( stderr, "Video Timing Information was missing in file.\n");
+	    fprintf( stderr, "    Requested Resolution: (%s)\n", timingname);
+#endif
+	    return -1;
+	} else {
+	    vidtiming->id_string = strdup(timingname);
+	}
+
+	ow_table_init(&res_table_root, GFXResTable);
+
+	/* now extract the values we're interested in */
+	for (ap = inst_ptr, i = 0; i < attr_cnt; ap++, i++) {
+	    entry = ow_table_find(&res_table_root, ap->attribute);
+	    if ( entry == NULL ) {
+#ifdef DEBUG1
+	        fprintf( stderr, "OWconfig entry invalid: %s\n", ap->attribute);
+#endif
+	    } else {
+#ifdef DEBUG1
+#if 0           /* Helpful for intense debugging of file problems */
+	        fprintf(stderr, "%s, %s %d\n",
+	                ap->attribute, entry->name, entry->label);
+#endif
+#endif
+	        switch (entry->label) {
+	          case   video_Hact:
+	            vidtiming->Hact = atoi(ap->value);
+	            break;
+	          case   video_Hfp:
+	            vidtiming->Hfp  = atoi(ap->value);
+	            break;
+	          case   video_Hsw:
+	            vidtiming->Hsw  = atoi(ap->value);
+	            break;
+	          case   video_Hbp:
+	            vidtiming->Hbp  = atoi(ap->value);
+	            break;
+	          case   video_Hsrp:
+	            vidtiming->Hsrp = atoi(ap->value);
+	            break;
+
+	          case   video_Vact:
+	            vidtiming->Vact = atoi(ap->value);
+	            break;
+	          case   video_Vfp:
+	            vidtiming->Vfp  = atoi(ap->value);
+	            break;
+	          case   video_Vsw:
+	            vidtiming->Vsw  = atoi(ap->value);
+	            break;
+	          case   video_Vse:
+	            vidtiming->Vse  = atoi(ap->value);
+	            break;
+	          case   video_Vbp:
+	            vidtiming->Vbp  = atoi(ap->value);
+	            break;
+	          case   video_Pclk:
+	            vidtiming->Pclk = atoi(ap->value);
+	            break;
+	          case   video_Fint:
+	            vidtiming->Fint =
+	                (!strncasecmp(ap->value,  yes , 3)) ? TRUE : FALSE;
+	            break;
+	          case   video_Fseq:
+	            vidtiming->Fseq =
+	                (!strncasecmp(ap->value,  yes , 3)) ? TRUE : FALSE;
+	            break;
+	          case   video_Fst:
+	            vidtiming->Fst =
+	                (!strncasecmp(ap->value,  yes , 3)) ? TRUE : FALSE;
+	            break;
+	          case   video_Stype:
+	            vidtiming->Stype =
+	                (!strncasecmp(ap->value, "sep", 3)) ? TRUE : FALSE;
+	            break;
+	          case   video_SonG:
+	            vidtiming->SonG  =
+	                (!strncasecmp(ap->value,  yes , 3)) ? TRUE : FALSE;
+	            break;
+	          case   video_SHpol:
+	            vidtiming->SHpol =
+	                (!strncasecmp(ap->value, "pos", 3)) ? TRUE : FALSE;
+	            break;
+	          case   video_SVpol:
+	            vidtiming->SVpol =
+	                (!strncasecmp(ap->value, "pos", 3)) ? TRUE : FALSE;
+	            break;
+	          case   video_SGpol:
+	            vidtiming->SGpol =
+	                (!strncasecmp(ap->value, "pos", 3)) ? TRUE : FALSE;
+	            break;
+	          case video_EncodStd:
+	            if ( !strcasecmp(ap->value, "ntsc") ) {
+	              vidtiming->Encod = SunVideoEncodingNTSC;
+	            }
+	            if ( !strcasecmp(ap->value, "pal") ) {
+	              vidtiming->Encod = SunVideoEncodingPAL;
+	            }
+	            break;
+	          case video_HUndScan:
+	            vidtiming->Hund = (double)atof(ap->value);
+	            break;
+	          case video_VUndScan:
+	            vidtiming->Vund = (double)atof(ap->value);
+	            break;
+	          default:
+#ifdef DEBUG1
+                    fprintf(stderr, "Timing: Invalid attribute: %s = %s\n",
+                            ap->attribute, entry->name);
+#endif
+	            break;
+	        }
+
+	    }
+	}
+
+	/* free up attribute memory */
+	OWconfigFreeInstance(inst_ptr, attr_cnt);
+
+	return 0;
+}
+
+
+
+/*
+ *  This function loads a video resolution from the file.
+ *  It returns an error code if a problem occurs.
+ *
+ *  This wrapper fills in optional fields, and
+ *  it flags an error if required fields are missing.
+ *
+ */
+
+int
+sun_get_ow_video_values_raw (char             *timingname,
+	                     SunVideoTiming   *vidtiming   )
+{
+	if (timingname==NULL || *timingname==0) {
+#ifdef DEBUG1
+	    fprintf( stderr, "Timing Name was empty or NULL.\n");
+#endif
+	    return -1;
+	}
+
+	/* Default values if field is missing (optional) in the file */
+	/*    Fields set to -1 hear are mandatory                    */
+
+	vidtiming->Hact      =    -1 ;
+	vidtiming->Hfp       =    -1 ;
+	vidtiming->Hsw       =    -1 ;
+	vidtiming->Hbp       =    -1 ;
+	vidtiming->Hsrp      =     0 ; /* Default to OFF, zero */
+	vidtiming->Vact      =    -1 ;
+	vidtiming->Vfp       =    -1 ;
+	vidtiming->Vsw       =    -1 ;
+	vidtiming->Vse       =     0 ;
+	vidtiming->Vbp       =    -1 ;
+	vidtiming->Pclk      =    -1 ;
+	vidtiming->Fint      = FALSE ; /* Defaults, if not specified */
+	vidtiming->Fseq      = FALSE ;
+	vidtiming->Fst       = FALSE ;
+	vidtiming->Stype     = FALSE ; /* Default composite */
+	vidtiming->SonG      = FALSE ;
+	vidtiming->SHpol     = FALSE ; /* Default negative */
+	vidtiming->SVpol     = FALSE ; /* Default negative */
+	vidtiming->SGpol     = FALSE ; /* Default negative */
+	vidtiming->Encod     = SunVideoEncodingNone;
+	vidtiming->Hund      =   0.0 ;
+	vidtiming->Vund      =   0.0 ;
+
+
+
+	if ( sun_get_ow_video_values_file (timingname, vidtiming) != 0 ) {
+#ifdef DEBUG1
+	    fprintf( stderr, "Video Timing Information was missing in file\n");
+	    fprintf( stderr, "    Requested Resolution: %s\n", timingname);
+#endif
+	    return -1;
+	}
+
+
+	/* Make sure all mandatory fields got read from file */
+
+	if (vidtiming->Hact == -1) return -1;
+	if (vidtiming->Hfp  == -1) return -1;
+	if (vidtiming->Hsw  == -1) return -1;
+	if (vidtiming->Hbp  == -1) return -1;
+	if (vidtiming->Vact == -1) return -1;
+	if (vidtiming->Vfp  == -1) return -1;
+	if (vidtiming->Vsw  == -1) return -1;
+	if (vidtiming->Vbp  == -1) return -1;
+	if (vidtiming->Pclk == -1) return -1;
+
+	return 0;
+}
+
+
+/*
+ *  This functions looks up a video resolutions in OWconfig,
+ *  and fills in the generic SunVideoTiming structure.
+ *
+ *  This is the "nice" version that prints out error
+ *  messages on stderr (non debug ones, that is).
+ *  It also returns one hardcoded resolution (1152x900x66),
+ *  if things fail, just so you can always see that something
+ *  has gone wrong (for corrupt or missing resolution files).
+ *  Each card writer should consider whether this is a 
+ *  reasonable default resolution.  If not they should 
+ *  make thier own version of this wrapper, and call the
+ *  raw version of this function.  This may also be
+ *  required if printing messages on stderr is a problem
+ *  while not doing debugging (even for fatal errors).
+ *
+ */
+
+int
+sun_get_ow_video_values_1152 (char             *timingname,
+	                      SunVideoTiming   *vidtiming   )
+{
+	/* fallback values */
+
+	vidtiming->Hact      =  1152 ; /* 1152x900x66 is default resolution */
+	vidtiming->Hfp       =    40 ;
+	vidtiming->Hsw       =   128 ;
+	vidtiming->Hbp       =   208 ;
+	vidtiming->Hsrp      =     0 ; /* Default to OFF, zero */
+	vidtiming->Vact      =   900 ;
+	vidtiming->Vfp       =     2 ;
+	vidtiming->Vsw       =     4 ;
+	vidtiming->Vbp       =    31 ;
+	vidtiming->Pclk      = 94500 ;
+	vidtiming->Fint      = FALSE ; /* Defaults, if not specified */
+	vidtiming->Fseq      = FALSE ;
+	vidtiming->Fst       = FALSE ;
+	vidtiming->Stype     = FALSE ; /* Default composite */
+	vidtiming->SonG      = FALSE ;
+	vidtiming->SHpol     = FALSE ; /* Default negative */
+	vidtiming->SVpol     = FALSE ; /* Default negative */
+	vidtiming->SGpol     = FALSE ; /* Default negative */
+	vidtiming->Encod     = SunVideoEncodingNone;
+	vidtiming->Hund      = 0.0;
+	vidtiming->Vund      = 0.0;
+
+	if (timingname==NULL || *timingname==0) {
+	    vidtiming->id_string = strdup("FALLBACK_1152x900x66");
+#ifdef DEBUG1
+	    fprintf( stderr, "Timing Name was empty or NULL.\n");
+	    fprintf( stderr, "Using Fallback  Resolution: 1152x900x66 (hardcoded)\n");
+#endif
+
+	    return 0;        /* not an error for this wrapper */
+	}
+
+	if ( sun_get_ow_video_values_file (timingname, vidtiming) != 0 ) {
+	    vidtiming->id_string = strdup("FALLBACK_1152x900x66");
+
+#ifdef DEBUG1  /* Don't print this twice in debug mode */
+	    fprintf( stderr, "Video Timing Information was missing in file\n");
+	    fprintf( stderr, "    Requested Resolution: %s\n", timingname);
+	    fprintf( stderr, "    Fallback  Resolution: 1152x900x66 (hardcoded)\n");
+	    fprintf( stderr, "Recheck the resolution name with fbconfig,\n");
+	    fprintf( stderr, "  or reinstall package SUNWvid.\n");
+#endif
+
+	    return 0;   /* not an error for this wrapper */
+	}
+
+   	return 0;
+}
+
+
+
+
+char **
+sun_get_ow_video_timing_names	( )
+{
+	char **name_list;
+
+	name_list = OWconfigGetClassNames(owvid_class);
+   	if (name_list == NULL) {
+#ifdef DEBUG1
+	    fprintf( stderr, "Timing Names are inaccessable in OWconfig\n" );
+	    fprintf( stderr, "   Class Name  = %s\n", owvid_class          );
+#endif
+	}
+
+	return name_list;
+}
+
+
+
+
+
+
+#ifdef MAIN_TEST
+
+#include <ow_file_util.h>
+
+main( int argc ,char **argv )
+{
+        char    **video_names ;
+        char    *video_name ;
+        int     i;
+
+	sun_gfx_load_owconfig( OWCONFIG_SYSTEM, OWCONFIG_MACHINE );
+
+	video_names = sun_get_ow_video_timing_names( );
+
+	if (video_names != NULL) {
+	    for (i=0 ;  ; i++) {
+	        video_name = video_names[i];
+	        if (video_name == NULL) {
+	            break;
+	        } else {
+	             printf( "Video Name (%2d) = %s\n", i, video_name);
+	        }
+	    }
+	}
+}
+
+#endif /* MAIN_TEST */
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/gfx_common/include/gfx_common.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 _GFX_COMMON_H
+#define _GFX_COMMON_H
+
+#include <sys/types.h>
+
+#define GFXIOC					('g' << 8)
+
+#define GFX_IOCTL_GET_IDENTIFIER		(GFXIOC | 1)
+#define GFX_IOCTL_GET_CURRENT_VIDEO_MODE	(GFXIOC | 2)
+#define GFX_IOCTL_GET_PCI_CONFIG		(GFXIOC | 3)
+#define GFX_IOCTL_SET_VIDEO_MODE		(GFXIOC | 4)
+#define GFX_IOCTL_GET_EDID_LENGTH		(GFXIOC | 5)
+#define GFX_IOCTL_GET_EDID			(GFXIOC | 6)
+
+#define GFX_MAX_MODELNAME_LEN			36
+#define GFX_MAX_PARTNUM_LEN			36
+#define GFX_MAX_VMODE_LEN			48
+
+#define GFX_IDENT_VERSION			1
+#define GFX_IDENT_MODELNAME			0x01
+#define GFX_IDENT_PARTNUM			0x02
+
+#define GFX_EDID_VERSION			1
+#define GFX_EDID_BLOCK_SIZE			128
+#define GFX_EDID_HEAD_ONE			1
+#define GFX_EDID_HEAD_TWO			2
+#define GFX_EDID_HEAD_THREE			3
+#define GFX_EDID_HEAD_FOUR			4
+
+
+typedef struct	gfx_identifier {
+	uint32_t	version;
+	uint32_t	flags;
+	char		model_name[GFX_MAX_MODELNAME_LEN];
+	char		part_number[GFX_MAX_PARTNUM_LEN];
+	char		pad[100];
+} gfx_identifier_t;
+
+
+typedef struct  gfx_video_mode {
+	char		mode_name[GFX_MAX_VMODE_LEN];
+	uint32_t	vRefresh;
+	char		pad[96];
+} gfx_video_mode_t;
+
+
+typedef struct  gfx_pci_cfg {
+	uint16_t 	VendorID;
+	uint16_t 	DeviceID;
+	uint16_t 	Command;
+	uint16_t 	Status;
+	uint8_t  	RevisionID;
+	uint8_t  	ProgIF;
+	uint8_t  	SubClass;
+	uint8_t  	BaseClass;
+
+	uint8_t  	CacheLineSize;
+	uint8_t  	LatencyTimer;
+	uint8_t  	HeaderType;
+	uint8_t  	BIST;
+
+	uint32_t 	bar[6];
+	uint32_t   	CIS;
+	uint16_t 	SubVendorID;
+	uint16_t 	SubSystemID;
+	uint32_t   	ROMBaseAddress;
+
+	uint8_t  	CapabilitiesPtr;
+	uint8_t  	Reserved_1[3];
+	uint32_t   	Reserved_2;
+
+	uint8_t  	InterruptLine;
+	uint8_t  	InterruptPin;
+	uint8_t  	MinimumGrant;
+	uint8_t  	MaximumLatency;
+
+	uint8_t  	pad[100];
+} gfx_pci_cfg_t;
+
+
+typedef struct gfx_edid {
+	uint32_t	version;
+	uint32_t	head;
+#ifndef _LP64 
+	uint32_t	pad;
+#endif
+	caddr_t		data;		/* pointer to the buffer that receives data */
+	uint32_t	length;		/* length of the buffer. */
+} gfx_edid_t;
+
+#endif /* _GFX_COMMON_H */
+	
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/gfx_common/include/gfx_gamma_pack.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 _SUNGFX_GAMMA_PACK_H
+#define _SUNGFX_GAMMA_PACK_H
+
+/*
+ * gfx_gamma_pack.h:  Declarations for gamma string packing.
+ */
+
+
+#include <sys/types.h>
+
+
+
+/* Function Prototypes */
+
+extern int
+gfx_pack_gamma_string_16 (char     **gamma_string,
+                          int        gamma_entries,
+                          uint16_t  *gt_data);
+
+
+extern int
+gfx_unpack_gamma_string_16 (char      *str,
+                            int        max_entries,
+                            uint16_t  *gt_data);
+
+
+
+#endif /* _SUNGFX_GAMMA_PACK_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/gfx_common/include/gfx_list_util.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 _GFX_LIST_UTIL_H
+#define	_GFX_LIST_UTIL_H
+
+/*
+ * gfx_list_util.h: declarations for generic list processing routines.
+ */
+
+
+typedef struct {
+    int                  label;
+    char                *name;
+} OWConfigTableEntry;
+
+typedef struct {
+	int        alloc_type;
+	int        max_len_bytes;
+	int       *data;
+} OWConfigLabelList;
+
+#define OWCONFIG_LABEL_LIST_ALLOC_STATIC 0
+#define OWCONFIG_LABEL_LIST_ALLOC_MALLOC 1
+#define OWCONFIG_LABEL_LIST_END_LABEL    0
+
+extern void                ow_table_init        (void**, OWConfigTableEntry*);
+extern OWConfigTableEntry* ow_table_find        (void**, char*);
+extern int                 ow_search_label_list (int, OWConfigLabelList*);
+extern int                 ow_extend_label_list (int, OWConfigLabelList*);
+#endif /* _GFX_LIST_UTIL_H */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/gfx_common/include/gfx_res_util.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 _GFX_RES_UTIL_H
+#define	_GFX_RES_UTIL_H
+
+/*
+ * gfx_res_util.h: declarations for generic resolution file routines.
+ */
+
+typedef enum {
+	SunVideoEncoding_NOTSET = 0,
+	SunVideoEncodingNone,
+	SunVideoEncodingNTSC,
+	SunVideoEncodingPAL
+} SunVideoEncoding;
+
+
+/*
+ * Table of generic Sun video timing information
+ */
+typedef struct sun_video_timing {
+	char		*id_string;
+	unsigned int	Hact;	/* horizontal active width in pixels	*/
+	unsigned int	Hfp;	/* horizontal front porch  in pixels	*/
+	unsigned int	Hsw;	/* horizontal sync width   in pixels	*/
+	unsigned int	Hbp;	/* horizontal back porch   in pixels	*/
+	unsigned int	Hsrp;	/* horizontal serration    in pixels	*/
+	unsigned int	Vact;	/* vertical active height  in scanlines	*/
+	unsigned int	Vfp;	/* vertical front porch    in scanlines	*/
+	unsigned int	Vsw;	/* vertical sync width     in scanlines	*/
+	unsigned int	Vse;	/* vsync extension for multifield #1	*/
+	unsigned int	Vbp;	/* vertical back porch     in scanlines	*/
+	unsigned int	Pclk;	/* pixel clock frequency in khz		*/
+	unsigned int	Fint;	/* interlaced       video enabled	*/ 
+	unsigned int	Fseq;	/* field sequential video enabled	*/ 
+	unsigned int	Fst;	/* stereo           video enabled	*/ 
+	unsigned int	Stype;	/* sync type (separate, combined)	*/ 
+	unsigned int	SHpol;	/* sync polarity horizontal		*/ 
+	unsigned int	SVpol;	/* sync polarity vertical		*/ 
+	unsigned int	SonG;	/* sync on green - enabled		*/ 
+	unsigned int	SGpol;	/* sync on green - polarity		*/
+	SunVideoEncoding Encod; /* Video Encoding Standard              */
+	double          Hund;   /* horizontal underscan                 */
+	double          Vund;   /* vertical   underscan                 */
+} SunVideoTiming;
+
+
+
+extern int sun_get_ow_video_values_raw  (char*, SunVideoTiming*);
+extern int sun_get_ow_video_values_1152 (char*, SunVideoTiming*);
+extern char** sun_get_ow_video_timing_names();
+
+
+
+#endif /* _GFX_RES_UTIL_H */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/gfx_common/vts/gfx_vts.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,275 @@
+#pragma ident "@(#)gfx_vts.c	1.1 09/04/01 SMI"
+
+/*
+ * Copyright (c) 2006, 2008-2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 <stdarg.h>		/* va_end(), va_start(), vfprintf() */
+#include <stdio.h>		/* fprintf() */
+#include <stdlib.h>		/* free(), getenv(), malloc() */
+#include <string.h>		/* strdup() */
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+#include "graphicstest.h"
+#include "gfx_vts.h"		/* VTS Graphics Tests common routines */
+
+
+int	gfx_vts_debug_mask = VTS_DEBUG_OFF; /* Debugging categories bit mask */
+
+
+/*
+ * gfx_vts_set_debug_mask()
+ *
+ *    Set the gfx_vts_debug_mask bits according to environment variables.
+ */
+
+void
+gfx_vts_set_debug_mask(void)
+{
+
+	gfx_vts_debug_mask = VTS_DEBUG_OFF;
+	if (getenv("GRAPHICS_VTS_DEBUG")) {
+	    gfx_vts_debug_mask |= VTS_DEBUG;
+	}
+	if (getenv("GRAPHICS_VTS_DEV")) {
+	    gfx_vts_debug_mask |= GRAPHICS_VTS_DEV;
+	}
+	if (getenv("GRAPHICS_VTS_MEM_OFF")) {
+	    gfx_vts_debug_mask |= GRAPHICS_VTS_MEM_OFF;
+	}
+	if (getenv("GRAPHICS_VTS_CHIP_OFF")) {
+	    gfx_vts_debug_mask |= GRAPHICS_VTS_CHIP_OFF;
+	}
+	if (getenv("GRAPHICS_VTS_SLOCK_OFF")) {
+	    gfx_vts_debug_mask |= GRAPHICS_VTS_SLOCK_OFF;
+	}
+
+}	/* gfx_vts_set_debug_mask() */
+
+
+/*
+ * TraceMessage()
+ *
+ *    Write a variable format debug message to stderr, prefixed by the
+ *    calling function name.
+ */
+
+void
+TraceMessage(
+	int		flags,		/* Current debug categories bit mask */
+	const char	*func,		/* Name of function to report */
+	const char	*format,	/* printf()-style format string */
+			...)		/* printf()-style variable arguments */
+{
+	va_list		ap;		/* Variable argument pointer */
+
+	va_start(ap, format);
+	if (flags & gfx_vts_debug_mask) {
+	    fprintf(stderr, "%s: ", func);
+	    vfprintf(stderr, format, ap);
+	}
+	va_end(ap);
+
+}	/* TraceMessage() */
+
+
+/*
+ * gfx_vts_add_message()
+ *
+ *    Add a message to the existing VTS test return packet.
+ *    Grow the arrays (this doesn't happen often enough to call for
+ *    linked lists).
+ *
+ */
+
+static
+int
+gfx_vts_add_message(
+	return_packet	*rp,		/* VTS test return packet */
+	int		count,
+	int		mesg_num,
+	char		*string)	/* Message string, else NULL */
+{
+	int		i;
+	int		*tmp_codes;
+	char		**tmp_strings;
+
+	if (rp != NULL) {
+	    rp->message_count += count;
+	    if (mesg_num >= 6000) {
+		rp->error_count += count;
+	    }
+
+	    rp->number_of_message_codes += 1;
+	    tmp_codes   = rp->message_codes;
+	    tmp_strings = rp->message_strings;
+	    rp->message_codes =
+		(int *)malloc(sizeof (int) * rp->number_of_message_codes);
+	    rp->message_strings =
+		(char **)malloc(sizeof (char *) * rp->number_of_message_codes);
+
+	    for (i = 0; i < rp->number_of_message_codes - 1; i += 1) {
+		rp->message_codes[i]   = tmp_codes[i];
+		rp->message_strings[i] = tmp_strings[i];
+	    }
+	    free(tmp_codes);
+	    free(tmp_strings);
+
+	    rp->message_codes[i] = mesg_num;
+
+	    rp->message_strings[i] = NULL;
+	    if ((string != NULL) && (*string != '\0')) {
+		rp->message_strings[i] = strdup(string);
+	    }
+	}
+
+}	/* gfx_vts_add_message() */
+
+
+/*
+ * gfx_vts_set_message()
+ *
+ *    Initialize the message in the VTS test return packet.
+ *    The "count" parameter allows for reporting the number of messages
+ *    encountered, whereas the array size allows for multiple messages.
+ */
+
+int
+gfx_vts_set_message(
+	return_packet	*rp,		/* VTS test return packet */
+	int		count,
+	int		mesg_num,
+	char		*string)	/* Message string, else NULL */
+{
+
+	if (rp != NULL) {
+	    if (rp->number_of_message_codes > 0) {
+		add_message(rp, count, mesg_num, string);
+	    } else {
+		rp->message_count = count;
+		if (mesg_num >= 6000) {
+		    rp->error_count = 1;
+		}
+		rp->number_of_message_codes = 1;
+		rp->message_codes    = (int *)malloc(sizeof (int));
+		rp->message_codes[0] = mesg_num;
+		rp->message_strings  = (char **)malloc(sizeof (char *));
+
+		rp->message_strings[0] = NULL;
+		if ((string != NULL) && (*string != '\0')) {
+		    rp->message_strings[0] = strdup(string);
+		}
+	    }
+	}
+
+}	/* gfx_vts_set_message() */
+
+
+/*
+ * gfx_vts_check_fd()
+ *
+ *    See whether the specified file descriptor number looks valid.  If
+ *    invalid, prepare a message in the return packet and return 1.
+ *    Otherwise return zero.
+ */
+
+int
+gfx_vts_check_fd(
+	int		fd,		/* File descriptor number */
+	return_packet	*rp)		/* VTS test return packet */
+{
+
+	if (fd < 0) {
+	    gfx_vts_set_message(rp, 1, GRAPHICS_ERR_OPEN, NULL);
+	    return (1);
+	}
+	return (0);
+
+}	/* gfx_vts_check_fd() */
+
+
+/*
+ * gfx_vts_free_tests()
+ *
+ *    Free any and all dynamically allocated memory to which the test
+ *    structure points.
+ */
+
+void
+gfx_vts_free_tests(gfxtest_info *tests)
+{
+
+	if (tests != NULL) {
+	    free(tests->this_test_mask);
+	    tests->this_test_mask = NULL;
+
+	    free(tests->this_test_mesg);
+	    tests->this_test_mesg = NULL;
+
+	    free(tests->this_test_function);
+	    tests->this_test_function = NULL;
+	}
+
+}	/* gfx_vts_free_tests() */
+
+
+/*
+ * gfx_vts_console_interrupt()
+ *
+ *    See whether a console interrupt (Ctrl-C or ^C) has been typed.
+ *    If so, send a SIGINT signal to our own PID.  Otherwise just
+ *    return.
+ */
+
+void
+gfx_vts_console_interrupt(
+	Display		*dpy)		/* Connection to the X server */
+{
+#define	CTRL_C	'\003'			/* Ctrl-C (^C) */
+
+	if (dpy != NULL) {
+	    while (XPending(dpy)) {
+		XEvent	event;		/* Key event structure */
+		int	i;		/* Loop counter / keystr[] index */
+		char	keystr[5] = "";	/* Buffer for returned string */
+		int	len;		/* Length of returned string */
+
+		XNextEvent(dpy, &event);
+		if (event.type == KeyPress) {
+		    len = XLookupString((XKeyEvent *)&event,
+					keystr, sizeof (keystr),
+					NULL, NULL);
+		    for (i = 0; i < len; i += 1) {
+			if (keystr[i] == CTRL_C) {
+			    kill(getpid(), SIGINT);
+			    graphicstest_finish(0);
+			}
+		    }
+		}
+	    }
+	}
+
+}	/* gfx_vts_console_interrupt() */
+
+
+/* End of gfx_vts_common.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/gfx_common/vts/include/gfx_vts.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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	_GFX_VTS_H
+#define	_GFX_VTS_H
+
+
+#include "libvtsSUNWxfb.h"	/* VTS library definitions for ast device */
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+
+/*
+ * Debug & trace flags used with TraceMessage() and gfx_vts_debug_mask
+ */
+#define	VTS_DEBUG_OFF		0x0000
+#define	VTS_DEBUG		0x0001
+#define	VTS_TEST_STATUS		0x0002
+#define	GRAPHICS_VTS_MEM_OFF	0x0004
+#define	GRAPHICS_VTS_CHIP_OFF	0x0008
+#define	GRAPHICS_VTS_SLOCK_OFF	0x0010
+#define	GRAPHICS_VTS_DEV	0x0020
+
+extern int	gfx_vts_debug_mask;	/* Debugging categories bit mask */
+
+
+void gfx_vts_set_debug_mask(void);
+
+void TraceMessage(
+	int		flags,		/* Current debug categories bit mask */
+	const char	*func,		/* Name of function to report */
+	const char	*format,	/* printf()-style format string */
+			...);		/* printf()-style variable arguments */
+
+int gfx_vts_set_message(
+	return_packet	*rp,		/* VTS test return packet */
+	int		count,
+	int		mesg_num,
+	char		*string);	/* Message string, else NULL */
+
+int gfx_vts_check_fd(
+	int		fd,		/* File descriptor number */
+	return_packet	*rp);		/* VTS test return packet */
+
+void gfx_vts_free_tests(
+	gfxtest_info	*tests);
+
+void gfx_vts_console_interrupt(
+	Display		*dpy);		/* Connection to the X server */
+
+
+#endif	/* _GFX_VTS_H */
+
+
+/* End of gfx_vts.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/gfx_common/vts/include/graphicstest.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 <sys/param.h>
+#include <kvm.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+
+#define TEST_ERROR 1	/*A non-zero exit value signals fatal error. */
+
+extern int process_args();	/* These two functions are externs so */
+extern int test_usage();	/* that test_init() can use them to   */
+int runtest();              
+				/* initialize the test environment.   */
+
+#define GRAPHICS_ERROR 1
+
+
+/* define Message IDs */
+#define TEST_RUN_VMSG 	1
+#define	TEST_USAGE_INFOMSG 	2000
+#define	GRAPHICS_SUB_TESTS   	2001
+#define	GRAPHICS_TEST_INFO_1 	2002
+#define	GRAPHICS_TEST_INFO_2 	2003
+
+#define	TEST_ARGUMENT_ERRMSG  	6000	
+#define	BAD_OPTIONS_ERRMSG 	6001
+#define	SUBTEST_ERRMSG  	6002 
+#define	TEST_SAMPLE_ERRMSG  	6003
+#define	TEST_FINAL_ERRMSG 	6004
+
+
+#define GRAPHICS_INFO_UNKNOWN_MESSAGE     2114
+#define GRAPHICS_INFO_MESSAGE_STRING      2115
+#define GRAPHICS_INFO_ENV_MSG             2116
+#define GRAPHICS_OPEN_LIBRARY             2117
+
+/* standard test messages */
+#define GRAPHICS_TEST_OPEN_MESG	2900
+#define GRAPHICS_TEST_DMA_MESG	2901
+#define GRAPHICS_TEST_MEM_MESG	2902
+#define GRAPHICS_TEST_CHIP_MESG	2903
+#define GRAPHICS_TEST_VIDEO_MESG	2904
+#define GRAPHICS_TEST_EMPTY_MESG	2910
+
+#define GRAPHICS_INFO_MEM_TEST_0   3328  /* -------- Random Data Test -------- */
+#define GRAPHICS_INFO_MEM_TEST_1   3329  /* ---------- Address Test ---------- */
+#define GRAPHICS_INFO_MEM_TEST_2   3330  /* --------- Increment Test --------- */
+
+#define	TEST_WARNMSG 	      4000
+#define GRAPHICS_WARN_DMA_CMP      4001
+#define GRAPHICS_WARN_DMA_SAVE     4002
+#define GRAPHICS_WARN_DMA_REF_OPEN 4003
+
+/*
+ * ERRORs
+ */
+#define	GRAPHICS_ERR_RESET				        6107
+#define	GRAPHICS_ERR_LOAD				        6108
+#define	GRAPHICS_ERR_OPEN_LIBRARY			        6109
+#define	GRAPHICS_ERR_NULL_CODES				        6110
+#define	GRAPHICS_ERR_NULL_STRING			        6111
+#define	GRAPHICS_ERR_MMAP			                6112
+#define GRAPHICS_ERR_DMA_CMP 				        6204
+#define GRAPHICS_ERR_OPEN_MSG 				        6205
+#define GRAPHICS_ERR_DMA_MSG 				        6206
+#define GRAPHICS_ERR_MEMORY_MSG 			        6207
+#define GRAPHICS_ERR_CHIP_MSG 				        6208
+#define GRAPHICS_ERR_OPEN 				        6209
+#define GRAPHICS_ERR_DMA 				        6210
+#define GRAPHICS_ERR_MEMORY 				        6211
+#define GRAPHICS_ERR_CHIP 				        6212
+#define GRAPHICS_ERR_CONNECTIVITY 			        6213
+#define GRAPHICS_ERR_CONNECTIVITY_MSG 			        6214
+
+
+#define GRAPHICS_ERR_1           7681  /* Error: @ x=, y=, expected, read  */
+#define GRAPHICS_ERR_FILE        7682  /* Couldn't open file on host for writing */
+#define GRAPHICS_ERR_2           7683  /* Error: @ x=, y=, expected, read  */
+#define GRAPHICS_ERR_3           7684  /* More errors!!! */
+#define GRAPHICS_ERR_BITS_1      7687  /* Bit: Package U / IO / Pin */
+#define GRAPHICS_ERR_BITS_2      7688  /* Bit: Package U / IO / Pin */
+#define GRAPHICS_ERR_MALLOC_FAIL 7689  /* !!!! malloc() failed!!!! */
+#define GRAPHICS_ERR_ABORT       7690  /* Errors detected -- aborting*/
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/gfx_common/vts/include/libvtsSUNWxfb.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 _LIBXFBVTS_H
+#define _LIBXFBVTS_H
+
+/**************************************************/
+/* library header file for an Example Framebuffer */
+/*
+ * When implementing new graphics framebuffers, you
+ * must use the below interfaces.
+ * If you change them, then you need to update the
+ * mapfile and the graphics_svts.c dlopen to use the
+ * new 'version'. See Solaris docs on the Linker for
+ * more info on doing this: docs.eng.sun.com     
+ */
+
+
+/* standard test masks */
+#define GRAPHICS_TEST_OPEN  0x00000001
+#define GRAPHICS_TEST_DMA   0x00000002
+#define GRAPHICS_TEST_MEM   0x00000004
+#define GRAPHICS_TEST_CHIP  0x00000008
+#define GRAPHICS_TEST_MASK  0x0000000f
+
+#define CONNECTIVITY_TEST -1
+
+/* Return Packet */
+/* this is a standard return type for all test functions */
+typedef struct return_packet_t {
+    int error_count; /* number of errors encountered before test abort */
+    int message_count; /* total number of messages */
+	int number_of_message_codes; /* the array length */
+	int *message_codes;  /* the message codes */
+	char **message_strings; /* the string to stick into the  mesg */
+} return_packet;
+
+
+typedef return_packet *(*gfxtest_function)(int); /* function ptr declaration */
+/*: gfxtest_function(int filedescription) returning ptr to return_packet */
+
+/* Test Info */
+/* This structure has these members:
+   - count  : the number of tests defined
+   - this_test_mask : the test mask for test[0..count-1]
+   - this_test_mesg : the test verbose message for test[0..count-1]
+   - this_test_function : the actual test for test[0..count-1]
+
+ An example:
+  count = 1;
+  this_test_mask = 0x1;
+  this_test_mesg = VTS_DEFINED_VERBOSE_MESG_SUBTEST_VIDEO;
+  this_test_function = subtest_video; 
+  */
+
+typedef struct gfxtest_info_t {
+	int count;
+	int *this_test_mask;
+	int *this_test_mesg;
+	gfxtest_function *this_test_function;
+	gfxtest_function connection_test_function;
+} gfxtest_info;
+
+typedef int (*gfxtest_func_ptr)(gfxtest_info *);
+
+/* You Must Implement these functions */
+/* Get Tests:
+   copies the array of masks, messages, and function ptrs into the
+   gfxtest_info structure. The library does the malloc, so call cleanup
+   before exit.
+   Return: 0 for success, errno for failure.
+   */
+extern int get_tests(gfxtest_info *tests);
+/* Cleanup Tests:
+   free any memory allocated
+   call to avoid memory leaks
+   */
+extern int cleanup_tests(gfxtest_info *tests);
+
+#endif /* _LIBXFBVTS_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/Makefile.common	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,80 @@
+#
+# Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS 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.
+#
+
+GFX_COMMON = ../../gfx_common
+INSTALL_LIB_DIR = $(DESTDIR)/usr/lib/sparcv9
+
+#
+# Compilation flags
+#
+#DEBUG	= -g $(SBFLAG)
+#DEFS	=
+DEFS	= -DVTS_STUBS
+INCL	=  -I ../common/include
+INCL    += -I ${GFX_COMMON}/include
+INCL	+= -I ${GFX_COMMON}/vts/include
+
+CFLAGS	+= ${DEBUG} -m64 -xCC ${DEFS} -DSUN__${DEV} -Dsun -Dsparc -DSVR4 \
+ -DSYSV -D__EXTENSIONS__ -DDPMSExtension -DXRECORD -DEVI -DSHAPE -DXINPUT \
+ -DXKB -DLBX -DXAPPGROUP -DXCSECURITY -DTOGCUP -DPANORAMIX -DNEED_DBE_BUF_BITS \
+ -DNEED_DBE_BUF_VALIDATE -DPIXPRIV -DFBPM -DSUNSOFT -DSUNSOFT_BUYBACK -DXDPS \
+ -DNEED_LINEHELPER -DINCLUDE_ALLOCA_H -DMITSHM -DNODBBS
+
+LIB_CSRCS = libvtsSUNW${Dev}.c ${GFX_COMMON}/vts/gfx_vts.c tools.c \
+	mapper.c memory.c chip.c ${DEV_CSRCS}
+LIB_OBJS = libvtsSUNW${Dev}.o gfx_vts.o tools.o mapper.o memory.o chip.o \
+	 ${DEV_OBJS}
+
+#
+# Build rules
+#
+
+all: libvtsSUNW${Dev}.so.1
+
+libvtsSUNW${Dev}.so.1: $(LIB_OBJS) mapfile
+	${CC} ${CFLAGS} -M mapfile -G -lXext -lX11 -lm $(LIB_OBJS) -o $@
+
+gfx_vts.o: ${GFX_COMMON}/vts/gfx_vts.c $(HDRS)
+	${CC} ${CFLAGS} -c ${INCL} -Kpic -xregs=no%appl ${GFX_COMMON}/vts/gfx_vts.c -o $@
+
+xfb_uselib64: ${GFX_COMMON}/vts/xfb_uselib.c $(HDRS)
+	${CC} ${CFLAGS} ${INCL} ${GFX_COMMON}/vts/xfb_uselib.c -ldl -lXext -lX11 -lm -L . -o $@
+
+${Dev}_uselib64: xfb_uselib64
+	rm -f $@
+	ln -s xfb_uselib64 $@
+
+%.o:	%.c $(HDRS)
+	${CC} ${CFLAGS} -c ${INCL} -Kpic -xregs=no%appl -o $@ $<
+
+clean:
+	rm -f ${Dev}_uselib64 xfb_uselib64 libvtsSUNW${Dev}.so.1 $(LIB_OBJS)
+
+tidy:
+	rm -f *~
+
+install: $(INSTALL_LIB_DIR)/libvtsSUNW${Dev}.so.1
+
+$(INSTALL_LIB_DIR)/libvtsSUNW${Dev}.so.1: libvtsSUNW${Dev}.so.1
+	$(INSTALL) -m 0755 $? $@
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/ast/Makefile	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,33 @@
+#
+# Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS 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.
+#
+
+#
+# Target device
+#
+DEV	= AST
+Dev	= ast
+
+DEV_CSRCS = dma.c
+DEV_OBJS = dma.o
+
+include ../Makefile.common
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/ast/ast.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,305 @@
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 AST_H
+#define AST_H
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <sys/mman.h>
+
+#include "gfx_common.h"		/* GFX Common definitions */
+#include "graphicstest.h"
+#include "libvtsSUNWast.h"	/* Common VTS library definitions */
+
+#include "X11/Xlib.h"
+#include "gfx_vts.h"		/* VTS Graphics Test common routines */
+
+#define AST_REG_SIZE_LOG2	18
+
+struct pci_info {
+	unsigned long	memBase[6];
+	unsigned long	ioBase[6];
+	unsigned int	type [6];
+	unsigned int	size [6];
+};
+
+
+#define PKT_NULL_CMD				0x00009561
+
+#define PKT_SINGLE_LENGTH			8
+#define PKT_SINGLE_CMD_HEADER			0x00009562
+
+typedef struct  _PKT_SC
+{
+	unsigned int	header;
+	unsigned int	data[1];
+} PKT_SC, *PPKT_SC;
+
+
+#define CMD_QUEUE_GUARD_BAND			0x20
+
+typedef struct {
+
+	unsigned long   ulCMDQSize;
+	unsigned long	ulCMDQType;
+   
+	unsigned long	ulCMDQOffset;
+	unsigned char   *pjCMDQvaddr;
+   
+	unsigned char   *pjCmdQBasePort;
+	unsigned char   *pjWritePort;
+	unsigned char   *pjReadPort;
+	unsigned char   *pjEngStatePort;
+
+	unsigned long   ulCMDQMask;
+	unsigned long   ulCMDQueueLen;
+
+	unsigned long   ulWritePointer;
+	unsigned long   ulReadPointer;
+	unsigned long   ulReadPointer_OK;               /* for Eng_DBGChk */
+
+} CMDQINFO, *PCMDQINFO;
+
+
+typedef unsigned int (*PFNRead32)  (unsigned char *);
+typedef void         (*PFNWrite32) (unsigned char *, unsigned int);
+
+struct ast_info {
+	int		fd;
+
+	int		screenWidth;
+	int		screenHeight;
+	int		screenPitch;
+	int		bytesPerPixel;
+
+	int		MMIO2D;
+
+	unsigned long	FBPhysAddr;
+	unsigned long	MMIOPhysAddr;
+	unsigned long	RelocateIO;
+
+	int		FBMapSize;
+	int		MMIOMapSize;
+
+	unsigned char	*FBvaddr;
+	unsigned char	*MMIOvaddr;
+
+	CMDQINFO	CMDQInfo;
+	unsigned long	cmdreg;
+
+	unsigned int	save_dst_base;
+	unsigned int	save_line_xy;
+	unsigned int	save_line_err;
+	unsigned int	save_line_width;
+	unsigned int	save_line_k1;
+	unsigned int	save_line_k2;
+	unsigned int	save_mono_pat1;
+	unsigned int	save_mono_pat2;
+
+        PFNRead32       read32;
+        PFNWrite32      write32;
+};
+
+#define PCI_MAP_MEMORY                  0x00000000
+#define PCI_MAP_IO			0x00000001
+
+#define PCI_MAP_MEMORY_TYPE             0x00000007
+#define PCI_MAP_IO_TYPE                 0x00000003
+
+#define PCI_MAP_MEMORY_TYPE_32BIT       0x00000000
+#define PCI_MAP_MEMORY_TYPE_32BIT_1M    0x00000002
+#define PCI_MAP_MEMORY_TYPE_64BIT       0x00000004
+#define PCI_MAP_MEMORY_TYPE_MASK        0x00000006
+#define PCI_MAP_MEMORY_CACHABLE         0x00000008
+#define PCI_MAP_MEMORY_ATTR_MASK        0x0000000e
+#define PCI_MAP_MEMORY_ADDRESS_MASK     0xfffffff0
+
+#define PCI_MAP_IO_ATTR_MASK		0x00000003
+#define PCI_MAP_IS_IO(b)		((b) & PCI_MAP_IO)
+#define PCI_MAP_IO_ADDRESS_MASK		0xfffffffc
+
+#define PCIGETIO(b)			((b) & PCI_MAP_IO_ADDRESS_MASK)
+
+#define PCI_MAP_IS64BITMEM(b)   \
+        (((b) & PCI_MAP_MEMORY_TYPE) == PCI_MAP_MEMORY_TYPE_64BIT)
+
+#define PCIGETMEMORY(b)         	((b) & PCI_MAP_MEMORY_ADDRESS_MASK)
+
+#define PCI_REGION_BASE(_pcidev, _b, _type)             \
+    (((_type) == REGION_MEM) ? (_pcidev)->memBase[(_b)] \
+                             : (_pcidev)->ioBase[(_b)])
+
+#define AR_PORT_WRITE           0x40
+#define MISC_PORT_WRITE         0x42
+#define SEQ_PORT                0x44
+#define DAC_INDEX_READ          0x47
+#define DAC_INDEX_WRITE         0x48
+#define DAC_DATA                0x49
+#define GR_PORT                 0x4E
+#define CRTC_PORT               0x54
+#define INPUT_STATUS1_READ      0x5A
+#define MISC_PORT_READ          0x4C
+
+#define AST_MMIO_SIZE		0x00020000
+#define AST_VRAM_SIZE_08M	0x00800000
+#define AST_VRAM_SIZE_16M	0x01000000
+#define AST_VRAM_SIZE_32M	0x02000000
+#define AST_VRAM_SIZE_64M	0x04000000
+#define AST_VRAM_SIZE_128M	0x08000000
+
+
+#define MASK_SRC_PITCH          0x1FFF
+#define MASK_DST_PITCH          0x1FFF
+#define MASK_DST_HEIGHT         0x7FF
+#define MASK_SRC_X              0xFFF
+#define MASK_SRC_Y              0xFFF
+#define MASK_DST_X              0xFFF
+#define MASK_DST_Y              0xFFF
+#define MASK_RECT_WIDTH         0x7FF
+#define MASK_RECT_HEIGHT        0x7FF
+#define MASK_CLIP               0xFFF
+
+#define MASK_LINE_X             0xFFF
+#define MASK_LINE_Y             0xFFF
+#define MASK_LINE_ERR           0x3FFFFF
+#define MASK_LINE_WIDTH         0x7FF
+#define MASK_LINE_K1            0x3FFFFF
+#define MASK_LINE_K2            0x3FFFFF
+#define MASK_AIPLINE_X          0xFFF
+#define MASK_AIPLINE_Y          0xFFF
+
+
+/* CMDQ Reg */
+#define CMDQREG_SRC_BASE        (0x00 << 24)
+#define CMDQREG_SRC_PITCH       (0x01 << 24)
+#define CMDQREG_DST_BASE        (0x02 << 24)
+#define CMDQREG_DST_PITCH       (0x03 << 24)
+#define CMDQREG_DST_XY          (0x04 << 24)
+#define CMDQREG_SRC_XY          (0x05 << 24)
+#define CMDQREG_RECT_XY         (0x06 << 24)
+#define CMDQREG_FG              (0x07 << 24)
+#define CMDQREG_BG              (0x08 << 24)
+#define CMDQREG_FG_SRC          (0x09 << 24)
+#define CMDQREG_BG_SRC          (0x0A << 24)
+#define CMDQREG_MONO1           (0x0B << 24)
+#define CMDQREG_MONO2           (0x0C << 24)
+#define CMDQREG_CLIP1           (0x0D << 24)
+#define CMDQREG_CLIP2           (0x0E << 24)
+#define CMDQREG_CMD             (0x0F << 24)
+#define CMDQREG_PAT             (0x40 << 24)
+
+#define CMDQREG_LINE_XY         (0x04 << 24)
+#define CMDQREG_LINE_Err        (0x05 << 24)
+#define CMDQREG_LINE_WIDTH      (0x06 << 24)
+#define CMDQREG_LINE_K1         (0x09 << 24)
+#define CMDQREG_LINE_K2         (0x0A << 24)
+#define CMDQREG_LINE_STYLE1     (0x0B << 24)
+#define CMDQREG_LINE_STYLE2     (0x0C << 24)
+#define CMDQREG_LINE_XY2        (0x05 << 24)
+#define CMDQREG_LINE_NUMBER     (0x06 << 24)
+
+#define	CMD_BITBLT                            0x00000000
+#define CMD_LINEDRAW                          0x00000001
+#define CMD_COLOREXP                          0x00000002
+#define CMD_ENHCOLOREXP                       0x00000003
+#define CMD_TRANSPARENTBLT                    0x00000004
+#define CMD_MASK                              0x00000007
+
+#define CMD_DISABLE_CLIP                      0x00000000
+#define CMD_ENABLE_CLIP                       0x00000008
+
+#define CMD_COLOR_08                          0x00000000
+#define CMD_COLOR_16                          0x00000010
+#define CMD_COLOR_32                          0x00000020
+
+#define CMD_SRC_SIQ                           0x00000040
+
+#define CMD_TRANSPARENT                       0x00000080
+
+#define CMD_PAT_FGCOLOR                       0x00000000
+#define CMD_PAT_MONOMASK                      0x00010000
+#define CMD_PAT_PATREG                        0x00020000
+
+#define CMD_OPAQUE                            0x00000000
+#define CMD_FONT_TRANSPARENT                  0x00040000
+
+#define CMD_X_INC                             0x00000000
+#define CMD_X_DEC                             0x00200000
+
+#define CMD_Y_INC                             0x00000000
+#define CMD_Y_DEC                             0x00100000
+
+#define CMD_NT_LINE                           0x00000000
+#define CMD_NORMAL_LINE                       0x00400000
+
+#define CMD_DRAW_LAST_PIXEL                   0x00000000
+#define CMD_NOT_DRAW_LAST_PIXEL               0x00800000
+
+#define CMD_DISABLE_LINE_STYLE                0x00000000
+#define CMD_ENABLE_LINE_STYLE                 0x40000000
+
+#define CMD_RESET_STYLE_COUNTER               0x80000000
+#define CMD_NOT_RESET_STYLE_COUNTER           0x00000000
+
+#define BURST_FORCE_CMD                       0x80000000
+
+#define MMIOREG_DST_BASE        (pAST->MMIOvaddr + 0x8008)
+#define MMIOREG_DST_PITCH       (pAST->MMIOvaddr + 0x800C)
+#define MMIOREG_DST_XY          (pAST->MMIOvaddr + 0x8010)
+#define MMIOREG_SRC_XY          (pAST->MMIOvaddr + 0x8014)
+#define MMIOREG_RECT_XY         (pAST->MMIOvaddr + 0x8018)
+#define MMIOREG_FG              (pAST->MMIOvaddr + 0x801C)
+#define MMIOREG_BG              (pAST->MMIOvaddr + 0x8020)
+#define MMIOREG_MONO1           (pAST->MMIOvaddr + 0x802C)
+#define MMIOREG_MONO2           (pAST->MMIOvaddr + 0x8030)
+#define MMIOREG_CLIP1           (pAST->MMIOvaddr + 0x8034)
+#define MMIOREG_CLIP2           (pAST->MMIOvaddr + 0x8038)
+#define MMIOREG_CMD             (pAST->MMIOvaddr + 0x803C)
+#define MMIOREG_PAT             (pAST->MMIOvaddr + 0x8100)
+
+#define MMIOREG_LINE_XY         (pAST->MMIOvaddr + 0x8010)
+#define MMIOREG_LINE_Err        (pAST->MMIOvaddr + 0x8014)
+#define MMIOREG_LINE_WIDTH      (pAST->MMIOvaddr + 0x8018)
+#define MMIOREG_LINE_K1         (pAST->MMIOvaddr + 0x8024)
+#define MMIOREG_LINE_K2         (pAST->MMIOvaddr + 0x8028)
+
+
+int ast_get_pci_info(int fd, struct pci_info *pci_info); 
+int ast_get_mem_info(struct pci_info *pci_info, struct ast_info *pAST); 
+int ast_map_mem(struct ast_info *pAST, return_packet *rp, int test);
+int ast_unmap_mem(struct ast_info *pAST, return_packet *rp, int test);
+
+void ASTSetReg(int fd, int offset, int value);
+void ASTGetReg(int fd, int offset, int *value);
+void ASTSetIndexReg(int fd, int offset, int index, unsigned char value);
+void ASTGetIndexReg(int fd, int offset, int index, unsigned char *value);
+void ASTSetIndexRegMask(int fd, int offset, int index, int and, unsigned char value);
+void ASTGetIndexRegMask(int fd, int offset, int index, int and, unsigned char *value);
+void ASTOpenKey(int fd);
+unsigned int ASTMMIORead32(unsigned char *addr);
+void ASTMMIOWrite32(unsigned char *addr, unsigned int data);
+
+int ast_init_info(struct ast_info *);
+
+#endif /* AST_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/ast/astio.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 <sys/types.h>
+#include <sys/fbio.h>
+
+#define ASTIOC			('Y' << 8)
+
+#define AST_SET_IO_REG		(ASTIOC | 1)
+#define AST_GET_IO_REG		(ASTIOC | 2)
+#define AST_ENABLE_ROM		(ASTIOC | 3)
+#define AST_DISABLE_ROM		(ASTIOC | 4)
+#define AST_DEBUG_VIS_TEST	(ASTIOC | 5)
+#define AST_DEBUG_GET_VIS_BUF	(ASTIOC | 6)
+#define AST_DEBUG_GET_VIS_IMAGE	(ASTIOC | 7)
+#define AST_DEBUG_TEST		(ASTIOC | 8)
+#define AST_GET_STATUS_FLAGS	(ASTIOC | 10)
+
+#define AST_STATUS_HW_INITIALIZED	0x01
+
+
+typedef struct {
+	uchar_t offset;
+	uchar_t value;
+} ast_io_reg;
+
+struct ast_vis_cmd_buf {
+	int                     cmd;
+	int                     row;
+	int                     col;
+	int                     width;
+	int                     height;
+	int			pad0;
+	unsigned long		word1;
+	unsigned long		word2;
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/ast/chip.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,242 @@
+
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 <sys/types.h>
+#include <errno.h>
+#include <signal.h>		/* signal() */
+#include <stdio.h>
+#include <stropts.h>		/* ioctl() */
+#include <unistd.h>		/* ioctl(), sleep() */
+#include <sys/mman.h>
+
+#include "gfx_common.h"		/* VTS Graphics Test common routines */
+#include "graphicstest.h"
+#include "gfx_vts.h"		/* VTS Graphics Test common routines */
+#include "ast.h"		
+
+void
+box(struct ast_info *pAST, int x1, int y1, int x2, int y2, unsigned int color)
+{
+	int		tmp;
+	int		width;
+	int		height;
+
+	if (x2 < x1) {
+	    tmp = x2;
+	    x2  = x1;
+	    x1  = tmp;
+	}
+	if (y2 < y1) {
+	    tmp = y2;
+	    y2  = y1;
+	    y1  = tmp;
+	}
+
+	width  = x2 - x1;
+	height = y2 - y1;
+
+	ASTSetupForSolidFill(pAST, color, 0xf0);
+	ASTSolidFillRect(pAST, x1, y1, width, height);
+
+}	/* box() */
+
+void
+line(struct ast_info *pAST,
+	int		x1,
+	int		y1,
+	int		x2,
+	int		y2,
+	unsigned int	color
+	)
+{
+	ASTSetupForSolidLine(pAST, color, 0xf0);
+	ASTSolidLine(pAST, x1, y1, x2, y2);
+
+}	/* line() */
+
+
+void
+draw_cascaded_box(struct ast_info *pAST, int width, int height)
+{
+	unsigned int	x1;
+	unsigned int	y1;
+	unsigned int	x2;
+	unsigned int	y2;
+	unsigned int	w;
+	unsigned int	h;
+	int		i;
+	unsigned int	k = 0;
+
+	for (i = 0; i < 256; i++) {
+
+	    x1 = (unsigned int)((width * i) / 512);
+	    x2 = width - x1;
+	    w  = x2 - x1;
+
+	    y1 = (unsigned int)((height * i) / 512);
+	    y2 = height - y1;
+
+	    k = (i<<24 | i<<16 | i<<8 | i);
+
+	    box(pAST, x1, y1, x2, y2, k);
+	}
+
+}	/* draw_cascaded_box() */
+
+
+void
+draw_lines(struct ast_info *pAST, int width, int height)
+{
+	unsigned int	x1;
+	unsigned int	y1;
+	unsigned int	x2;
+	unsigned int	y2;
+	int		k;
+	int		i;
+	int		nlines = 128;
+
+	k = 0;
+	for (i = 0; i < nlines; i++) {
+	    k  = 0x00af0000 | (i << 8) | i;
+
+	    x1 = (unsigned int)((width * i) / nlines);
+	    x2 = x1;
+	    y1 = 0;
+	    y2 = height;
+
+	    line(pAST, x1, y1, x2, y2, k);
+	}
+
+	for (i = 0; i < nlines; i++) {
+	    k  = 0x00af0000 | (i << 8) | i;
+
+	    x1 = 0;
+	    x2 = width;
+	    y1 = (unsigned int)((height * i) / nlines);
+	    y2 = y1;
+
+	    line(pAST, x1, y1, x2, y2, k);
+	}
+}
+
+void
+chip_test(return_packet *rp, int fd)
+{
+        struct ast_info  ast_info;
+        struct ast_info  *pAST;
+        unsigned int red;
+        unsigned char *fbaddr;
+        int i;
+        int bytepp;
+        int fb_offset, fb_pitch, fb_height, fb_width;
+
+        pAST = &ast_info;
+        pAST->fd = fd;
+
+        /*
+         * map the registers & frame buffers memory
+         */
+        if (ast_map_mem(pAST, rp, GRAPHICS_ERR_CHIP) == -1) {
+            return;
+        }
+
+        /*
+         * initialize ast info
+         */
+        if (ast_init_info(pAST) == -1) {
+            return;
+        }
+
+	/*
+	 * only support 32 bits depth for now
+	 */
+	if (pAST->bytesPerPixel == 1) {
+	    goto done;
+	}
+
+	/*
+	 * enable 2D, initialize command queue
+	 */
+        ASTEnable2D(pAST);
+
+        if (ASTInitCMDQ(pAST) == -1) {
+	    pAST->MMIO2D = 1;
+	} else {;
+            ASTEnableCMDQ(pAST);
+	}
+
+	ASTSaveState(pAST);
+
+	/*
+	 * set clipping rectangle
+	 */
+	ASTSetClippingRectangle(pAST, 0, 0, pAST->screenWidth, pAST->screenHeight);
+
+	/* 
+	 * Clear screen 
+	 */
+	box(pAST, 0, 0, pAST->screenWidth, pAST->screenHeight, 0);
+	ASTWaitEngIdle(pAST);
+
+	/*
+	 * line test
+	 */
+	draw_lines(pAST, pAST->screenWidth, pAST->screenHeight);
+	ASTWaitEngIdle(pAST);
+	sleep(2);
+
+	/*
+	 * fill test
+	 */
+	draw_cascaded_box(pAST, pAST->screenWidth, pAST->screenHeight);
+	ASTWaitEngIdle(pAST);
+	sleep(2);
+
+	/* 
+	 * Clear screen 
+	 */
+	box(pAST, 0, 0, pAST->screenWidth, pAST->screenHeight, 0xff);
+	ASTWaitEngIdle(pAST);
+	sleep(2);
+
+	ASTResetState(pAST);
+
+done:
+        /*
+         * Unmap the registers & frame buffers memory
+         */
+        if (ast_unmap_mem(pAST, rp, GRAPHICS_ERR_CHIP) == -1) {
+            return;
+        }
+
+
+	if (close(fd) == -1) {
+	    gfx_vts_set_message(rp, 1, GRAPHICS_ERR_CHIP, "error closing device\n");
+	    return;
+	}
+
+}	/* chip_test() */
+
+
+/* End of chip.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/ast/chip.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,41 @@
+
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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	_CHIP_H
+#define	_CHIP_H
+
+
+#include "libvtsSUNWxfb.h"	/* Common VTS library definitions */
+
+
+void chip_test_reset(void);
+
+void chip_test(return_packet *rp, int fd);
+
+
+#endif	/* _CHIP_H */
+
+
+/* End of chip.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/ast/dma.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,118 @@
+
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 <sys/types.h>
+#include <errno.h>		/* errno */
+#include <stdio.h>
+#include <string.h>		/* strerror() */
+#include <stropts.h>		/* ioctl() */
+#include <unistd.h>		/* ioctl() */
+#include <sys/mman.h>
+#include <stdlib.h>
+
+#include "gfx_common.h"
+#include "graphicstest.h"
+#include "libvtsSUNWxfb.h"	/* Common VTS library definitions */
+#include "gfx_vts.h"		/* VTS Graphics Test common routines */
+#include "ast.h"
+
+static int
+cmp_value(struct ast_info *pAST, int x, int y)
+{
+	unsigned char *addr;
+	unsigned int  val;
+
+	addr = pAST->FBvaddr + (y-1) * pAST->screenPitch + x * pAST->bytesPerPixel;
+	val = read32(addr);
+	if ((val != 0x0) && (val != 0x00ffffff)) {
+	    printf("value at [%d %d] is different...0x%x\n", x, y, val);
+	    return -1;
+	}
+
+	return 0;
+}
+
+
+void
+dma_test(return_packet *rp, int fd)
+{
+        struct ast_info  ast_info;
+        struct ast_info  *pAST;
+	unsigned int red;
+	unsigned char *fbaddr;
+	int i;
+	int bytepp;
+	int fb_offset, fb_pitch, fb_height, fb_width;
+
+        pAST = &ast_info;
+        pAST->fd = fd;
+
+        /*
+         * map the registers & frame buffers memory
+         */
+        if (ast_map_mem(pAST, rp, GRAPHICS_ERR_DMA) == -1) {
+            return;
+        }
+
+	/*
+	 * initialize ast info
+	 */
+	if (ast_init_info(pAST) == -1) {
+	    return;
+	}
+
+	/*
+	 * for now, disable dma test when running on 8 bits
+	 */
+	if (pAST->bytesPerPixel == 1) {
+	    goto done;
+	}
+
+
+	ASTEnable2D(pAST);
+
+	if (ASTInitCMDQ(pAST) == -1) {
+	    pAST->MMIO2D = 1;
+	} else {
+	    ASTEnableCMDQ(pAST);
+	}
+
+	ASTSetupForMonoPatternFill(pAST, 0x77ddbbee, 0x77ddbbee, 0, 0xffffff, 0xf0);
+	ASTMonoPatternFill(pAST, 0x77ddbbee, 0x77ddbbee, 0, 0, 
+				pAST->screenWidth, pAST->screenHeight);
+	ASTWaitEngIdle(pAST);
+
+	sleep(1);
+
+done:
+        /*
+         * Unmap the registers & frame buffers memory
+         */
+        if (ast_unmap_mem(pAST, rp, GRAPHICS_ERR_DMA) == -1) {
+            return;
+        }
+}	/* dma_test() */
+
+
+/* End of dma.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/ast/libvtsSUNWast.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,534 @@
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 <sys/types.h>
+#include <sys/param.h>		/* MAXPATHLEN */
+#include <errno.h>
+#include <pwd.h>		/* getpwuid() */
+#include <signal.h>
+#include <stdio.h>		/* snprintf() */
+#include <stdlib.h>		/* exit(), malloc() */
+#include <string.h>		/* strcat(), strcpy() */
+#include <unistd.h>		/* sleep() */
+#include <sys/fbio.h>
+#include <sys/mman.h>
+#include <sys/systeminfo.h>	/* sysinfo() */
+#include <sys/visual_io.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+#include "graphicstest.h"
+#include "gfx_vts.h"		/* VTS Graphics Test common routines */
+
+#include "libvtsSUNWast.h"	/* VTS library definitions for ast device */
+
+
+#if (0)	/* Unused */
+#define	NO_DMA			0
+#define	USE_DMA			1
+#endif
+
+#define	MAX_DISPLAY_LEN		261
+
+
+static int		no_window = 1;
+static gfxtest_info	*tests_info;
+static int		received_control_c = 0;
+static int		need_screen_lock = 1;
+static Display		*dpy = NULL;
+
+
+/* Declarations needed for get_tests() */
+
+static unsigned int ast_mask_list[] = {
+	GRAPHICS_TEST_OPEN,
+	GRAPHICS_TEST_DMA,
+	GRAPHICS_TEST_MEM,
+	GRAPHICS_TEST_CHIP
+};
+
+static unsigned int ast_mesg_list[] = {
+	GRAPHICS_TEST_OPEN_MESG,
+	GRAPHICS_TEST_DMA_MESG,
+	GRAPHICS_TEST_MEM_MESG,
+	GRAPHICS_TEST_CHIP_MESG
+};
+
+static gfxtest_function ast_test_list[] = {
+	ast_test_open,
+	ast_test_dma,
+	ast_test_memory,
+	ast_test_chip
+};
+
+
+static void
+disable_pm(Display *dpy)
+{
+	int		dummy;
+
+	XSetScreenSaver(dpy, 0, 0, 0, 0);
+	if (DPMSQueryExtension(dpy, &dummy, &dummy)) {
+	    DPMSDisable(dpy);
+	}
+	if (FBPMQueryExtension(dpy, &dummy, &dummy)) {
+	    FBPMDisable(dpy);
+	}
+
+}	/* disable_pm() */
+
+
+int
+lock_display(int fd, Display** current_display)
+{
+	char		env_buf[5 + MAXPATHLEN]; /* "HOME=<pw_dir>" */
+	int		i;
+	int		screen;
+	Display		*dpy;
+	Window		win;
+	XSetWindowAttributes xswa;
+	char		hostname[MAX_DISPLAY_LEN];
+	char		display[MAX_DISPLAY_LEN];
+	struct sigaction act;
+	int		current_screen;
+	struct hostent	*Host;
+	struct passwd	*pw_entry;
+	int		status;
+	char		no_bits[] = { 0 };
+	XColor		dumcolor;
+	Pixmap		lockc;
+	Pixmap		lockm;
+	Cursor		cursor;
+
+	pw_entry = getpwuid(0);
+	if (strlen(pw_entry->pw_dir) >= MAXPATHLEN) {
+	    TraceMessage(VTS_DEBUG, __func__,
+			    "HOME= directory path is too long\n");
+	    return (1);
+	}
+	strcpy(env_buf, "HOME=");
+	strcat(env_buf, pw_entry->pw_dir);
+	if (putenv(env_buf) != 0) {
+	    TraceMessage(VTS_DEBUG, __func__,
+			    "putenv( HOME= ) failed, errno:%d\n", errno);
+	    return (1);
+	}
+
+	dpy = NULL;
+
+	if (gfx_vts_debug_mask & GRAPHICS_VTS_SLOCK_OFF) {
+	    TraceMessage(VTS_DEBUG, __func__, "lock_display() DISABLED\n");
+	    need_screen_lock = 0;
+	    *current_display = NULL;
+	    return (0);
+	}
+
+	current_screen = 0;
+
+	TraceMessage(VTS_DEBUG, __func__, "locking X screen %d\n",
+		    current_screen);
+
+#if (0)
+	/* Get the host machine name */
+	if (sysinfo(SI_HOSTNAME, hostname, MAX_DISPLAY_LEN) == -1) {
+	    TraceMessage(VTS_DEBUG, __func__,
+			"sysinfo(2) failed getting hostname\n");
+	    hostname[0] = '\0';
+	}
+#else
+	hostname[0] = '\0';
+#endif
+
+	snprintf(display, sizeof (display), "%s:0.%d",
+		hostname, current_screen);
+	dpy = XOpenDisplay(display);
+	TraceMessage(VTS_DEBUG, __func__,
+		    "XOpenDisplay, display = %s, dpy = 0x%p\n", display, dpy);
+
+	if (dpy == NULL) {
+	    TraceMessage(VTS_DEBUG, __func__, "Assuming no window_system\n");
+	    return (0);
+	}
+
+	TraceMessage(VTS_DEBUG, __func__,
+		    "XOpenDisplay successful, display = %s, dpy = 0x%p\n",
+		    display, dpy);
+
+	screen = DefaultScreen(dpy);
+
+	/*
+	 * Flush request buffer and wait for all requests to be processed
+	 */
+	XSync(dpy, False);
+
+	/* Tell server to report events as they occur */
+	XSynchronize(dpy, True);
+
+	disable_pm(dpy);
+
+	/* Create a blank cursor */
+	lockc = XCreateBitmapFromData(dpy, RootWindow(dpy, 0),
+					no_bits, 1, 1);
+	lockm = XCreateBitmapFromData(dpy, RootWindow(dpy, 0),
+					no_bits, 1, 1);
+	cursor = XCreatePixmapCursor(dpy, lockc, lockm, &dumcolor,
+					&dumcolor, 0, 0);
+
+	XFreePixmap(dpy, lockc);
+	XFreePixmap(dpy, lockm);
+
+	xswa.cursor = cursor;
+	xswa.override_redirect = True;
+	xswa.event_mask = (KeyPressMask | KeyReleaseMask | ExposureMask);
+	no_window = 0;
+	win = XCreateWindow(dpy,
+			    RootWindow(dpy, screen),
+			    0, 0,
+			    DisplayWidth(dpy, current_screen),
+			    DisplayHeight(dpy, current_screen),
+			    0,
+			    CopyFromParent,
+			    InputOutput,
+			    CopyFromParent,
+			    CWOverrideRedirect | CWEventMask, &xswa);
+
+	TraceMessage(VTS_DEBUG, __func__, " XCreateWindow win=%d\n", win);
+
+	XMapWindow(dpy, win);
+	XRaiseWindow(dpy, win);
+	TraceMessage(VTS_DEBUG, __func__, " no_window=%d\n", no_window);
+
+	if (!no_window) {
+	    /* Disable server from handling any requests */
+	    XGrabServer(dpy);
+	    /* Gain control of keyboard */
+	    status = XGrabKeyboard(dpy, win, False, GrabModeAsync,
+				   GrabModeAsync, CurrentTime);
+
+	    if (status != GrabSuccess) {
+		TraceMessage(VTS_DEBUG, __func__,
+			    "Cannot gain control of keyboard\n");
+	    }
+
+	    status = XGrabPointer(dpy,
+				win,
+				False,
+				ResizeRedirectMask,
+				GrabModeAsync,
+				GrabModeAsync,
+				None,
+				cursor,
+				CurrentTime);
+	    if (status != GrabSuccess) {
+		TraceMessage(VTS_DEBUG, __func__,
+			    "Cannot gain control of pointer\n");
+	    }
+	}
+
+	sleep(2);
+	*current_display = dpy;
+	return (0);
+
+}	/* lock_display() */
+
+void
+unlock_display(Display *dpy)
+{
+	if (dpy) {
+		XUngrabPointer(dpy, CurrentTime);
+		XUngrabKeyboard(dpy, CurrentTime);
+		XUngrabServer(dpy);
+	}
+}
+
+
+/* *** PUBLIC *** */
+
+/* These library functions are public and are expected to exist */
+
+int
+get_tests(gfxtest_info *tests)
+{
+	return_packet *ast_test_open(int fd);
+
+	/*
+	 * Set the gfx_vts_debug_mask bits according to environment variables
+	 */
+	gfx_vts_set_debug_mask();
+
+	/*
+	 * Disable screen lock by default
+	 */
+	gfx_vts_debug_mask |= GRAPHICS_VTS_SLOCK_OFF;
+
+	/*
+	 * Construct the list of tests to be performed
+	 */
+	tests->count = sizeof (ast_test_list) / sizeof (gfxtest_function);
+	tests->this_test_mask = (int *)malloc(sizeof (ast_mask_list));
+	tests->this_test_mesg = (int *)malloc(sizeof (ast_mesg_list));
+	tests->this_test_function =
+			(gfxtest_function *)malloc(sizeof (ast_test_list));
+
+	if ((tests->this_test_mask     == NULL) ||
+	    (tests->this_test_mesg     == NULL) ||
+	    (tests->this_test_function == NULL)) {
+	    gfx_vts_free_tests(tests);
+	    return (GRAPHICS_ERR_MALLOC_FAIL);
+	}
+
+	tests->connection_test_function = ast_test_open;
+
+	memcpy(tests->this_test_mask, ast_mask_list, sizeof (ast_mask_list));
+	memcpy(tests->this_test_mesg, ast_mesg_list, sizeof (ast_mesg_list));
+	memcpy(tests->this_test_function, ast_test_list,
+						sizeof (ast_test_list));
+
+	tests_info = tests;
+	return (0);
+
+}	/* get_tests() */
+
+
+int
+cleanup_tests(gfxtest_info *tests)
+{
+
+	TraceMessage(VTS_DEBUG, __func__, "call cleanup_tests\n");
+	gfx_vts_free_tests(tests);
+
+	if (need_screen_lock) {
+	    unlock_display(dpy);
+	}
+
+}	/* cleanup_tests() */
+
+
+/*
+ * ast_test_open()
+ *
+ *    This test will open the device, read and write some registers
+ *    after mmaping in the register and frame buffer spaces.
+ */
+
+return_packet *
+ast_test_open(int fd)
+{
+	static return_packet rp;
+	int		rc = 0;
+	struct vis_identifier vis_identifier;
+
+	if (need_screen_lock) {
+	    lock_display(fd, &dpy);
+	}
+
+	/* setup */
+	memset(&rp, 0, sizeof (return_packet));
+
+	if (gfx_vts_check_fd(fd, &rp)) {
+	    return (&rp);
+	}
+
+	TraceMessage(VTS_TEST_STATUS, __func__, "check_fd passed.\n");
+
+	/* vis identifier will do this */
+	rc = ioctl(fd, VIS_GETIDENTIFIER, &vis_identifier);
+
+	TraceMessage(VTS_TEST_STATUS, __func__, "rc = %d\n", rc);
+
+	if (rc != 0) {
+	    gfx_vts_set_message(&rp, 1, GRAPHICS_ERR_OPEN, NULL);
+	    return (&rp);
+	}
+
+	if (strncmp(vis_identifier.name, "SUNWast", 7) != 0) {
+	    gfx_vts_set_message(&rp, 1, GRAPHICS_ERR_OPEN, NULL);
+	    return (&rp);
+	}
+
+	map_me(&rp, fd);
+
+	TraceMessage(VTS_DEBUG, __func__, "Open completed OK\n");
+
+	check4abort(dpy);
+	return (&rp);
+
+}	/* ast_test_open() */
+
+
+/*
+ * ast_test_dma
+ *
+ *    This test will open the device, allocate the dma buffers to
+ *    separate memory spaces, and read/write the data, verifying it.
+ */
+
+return_packet *
+ast_test_dma(int fd)
+{
+	static return_packet rp;
+	int		i;
+
+	TraceMessage(VTS_DEBUG, __func__, "ast_test_dma running\n");
+
+	if (need_screen_lock) {
+	    lock_display(fd, &dpy);
+	}
+
+	dma_test(&rp, fd);
+
+	TraceMessage(VTS_DEBUG, __func__, " ast_test_dma completed\n");
+
+	check4abort(dpy);
+	return (&rp);
+
+}	/* ast_test_dma() */
+
+
+/*
+ * ast_test_memory()
+ *
+ *    This test will open the device and read and write to all memory
+ *    addresses.
+ */
+
+return_packet *
+ast_test_memory(int fd)
+{
+	static return_packet rp;
+
+	TraceMessage(VTS_DEBUG, __func__, " ast_test_memory running\n");
+
+	if (gfx_vts_debug_mask & GRAPHICS_VTS_MEM_OFF) {
+	    return (&rp);
+	}
+
+	if (need_screen_lock) {
+	    lock_display(fd, &dpy);
+	}
+
+	memory_test(&rp, fd);
+
+	TraceMessage(VTS_DEBUG, __func__, " ast_test_memory completed\n");
+
+	check4abort(dpy);
+	return (&rp);
+
+}	/* ast_test_memory() */
+
+
+/*
+ * ast_test_chip()
+ *
+ *    Test Chip, functional tests.
+ */
+
+return_packet *
+ast_test_chip(int fd)
+{
+	static return_packet rp;
+
+	if (gfx_vts_debug_mask & GRAPHICS_VTS_CHIP_OFF) {
+	    return (&rp);
+	}
+	TraceMessage(VTS_DEBUG, __func__, " ast_test_chip running\n");
+
+	if (need_screen_lock) {
+	    lock_display(fd, &dpy);
+	}
+
+	chip_test(&rp, fd);
+
+	TraceMessage(VTS_DEBUG, __func__, " ast_test_chip completed\n");
+
+	check4abort(dpy);
+	return (&rp);
+
+}	/* ast_test_chip() */
+
+
+void
+graphicstest_finish(int flag)
+{
+
+	TraceMessage(VTS_DEBUG, __func__, "call graphicstest_finish\n");
+
+	TraceMessage(VTS_DEBUG, __func__, "call reset_memory_state\n");
+
+	cleanup_tests(tests_info);
+
+	exit(0);
+
+}	/* graphicstest_finish() */
+
+
+/*
+ * check4abort()
+ *
+ *    This function sends a KILL signal to the program if it detects
+ *    that the user has pressed ^C.  This functionality is usually
+ *    performed by the Command Tool which spawned a program, but in this
+ *    case we need to do it because we have grabbed all keyboard events.
+ *    It should be called anywhere where it's safe to end the program.
+ */
+
+void
+check4abort(Display *dpy)
+{
+#define	CTRL_C	'\003'			/* Ctrl-C (^C) */
+
+	/*
+	 * If necessary, restore the original state following a test
+	 */
+#if !defined(VTS_STUBS)
+	chip_test_reset();
+#endif
+
+	if (dpy != NULL) {
+#if !defined(VTS_STUBS)
+	    while (XPending(dpy)) {
+		XEvent	event;		/* Key event structure */
+		int	i;		/* Loop counter / keystr[] index */
+		char	keystr[5] = "";	/* Buffer for returned string */
+		int	len;		/* Length of returned string */
+
+		XNextEvent(dpy, &event);
+		if (event.type == KeyPress) {
+		    len = XLookupString((XKeyEvent *)&event,
+					keystr, sizeof (keystr),
+					NULL, NULL);
+		    for (i = 0; i < len; i++) {
+			if (keystr[i] == CTRL_C) {
+			    kill(getpid(), SIGINT);
+			    graphicstest_finish(0);
+			}
+		    }
+		}
+	    }
+#endif	/* VTS_STUBS */
+	}
+
+}	/* check4abort() */
+
+
+/* End of libvtsSUNWast.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/ast/libvtsSUNWast.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,57 @@
+
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 _LIBVTSSUNWAST_H
+#define	_LIBVTSSUNWAST_H
+
+
+#include "libvtsSUNWxfb.h"	/* Common VTS library definitions */
+#include "astio.h"
+
+
+/* Test Open, initialization & read back; basic ability to talk to device */
+return_packet *ast_test_open(int fd);
+
+/* Test DMA, read/write via dma, memory and, chip tests will use DMA */
+return_packet *ast_test_dma(int fd);
+
+/* Test Memory, various address, data, and, random patterns */
+return_packet *ast_test_memory(int fd);
+
+/* Test Chip, functional tests */
+return_packet *ast_test_chip(int fd);
+
+void check4abort();
+int get_processHandle(int, void **);
+
+extern int backup_clut_init;
+extern struct fbcmap backup_clut;
+extern int myfd;
+
+
+#endif	/* _LIBVTSSUNWAST_H */
+
+
+/* End of libvtsSUNWast.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/ast/mapfile	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,7 @@
+SUNW_1.1 {
+		global:
+			get_tests;
+			cleanup_tests;
+		local:
+				*;
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/ast/mapper.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,107 @@
+
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 <sys/types.h>
+#include <stdio.h>
+#include <sys/mman.h>
+
+#include "gfx_common.h"		/* GFX Common definitions */
+#include "graphicstest.h"
+#include "libvtsSUNWast.h"	/* Common VTS library definitions */
+
+#include "X11/Xlib.h"
+#include "gfx_vts.h"		/* VTS Graphics Test common routines */
+#include "ast.h"
+
+
+/*
+ * map_me()
+ */
+
+void
+map_me(return_packet *rp, int fd)
+{
+	struct ast_info  ast_info;
+	struct ast_info  *pAST;
+	unsigned int	 value, chipType;
+	
+
+	pAST = &ast_info;
+	pAST->fd = fd;
+
+	/*
+	 * map the registers & frame buffers memory
+	 */
+	if (ast_map_mem(pAST, rp, GRAPHICS_ERR_OPEN) == -1) {
+	    return;
+	}
+
+        if (ast_init_info(pAST) == -1) {
+            return;
+        }
+
+	/*
+	 * 32 bits support only for now
+	 */
+	if (pAST->bytesPerPixel == 1) {
+	    goto done;
+	}
+	
+	/*
+	 * Write some registers
+	 */
+	pAST->write32(pAST->MMIOvaddr + 0xF004, 0x1e6e0000);
+	value = pAST->read32(pAST->MMIOvaddr + 0xF004);
+	if (value != 0x1e6e0000) {
+	    gfx_vts_set_message(rp, 1, GRAPHICS_ERR_OPEN, "write/read registers failed");
+	    return;
+	}
+
+	pAST->write32(pAST->MMIOvaddr + 0xF000, 0x1);
+	value = pAST->read32(pAST->MMIOvaddr + 0xF000);
+	if (value != 0x1) {
+	    gfx_vts_set_message(rp, 1, GRAPHICS_ERR_OPEN, "write/read registers failed");
+	    return;
+	}
+
+
+	value = pAST->read32(pAST->MMIOvaddr + 0x1207c);
+	chipType = value & 0x0300;
+#if DEBUG
+	printf("chipType = 0x%x\n", chipType);
+#endif
+
+
+done:
+	/*
+	 * Unmap the registers & frame buffers memory
+	 */
+	if (ast_unmap_mem(pAST, rp, GRAPHICS_ERR_OPEN) == -1) {
+	    return;
+	}
+
+}	/* map_me() */
+
+
+/* End of mapper.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/ast/memory.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,352 @@
+
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 <sys/types.h>
+#include <errno.h>		/* errno */
+#include <stdio.h>
+#include <string.h>		/* strerror() */
+#include <stropts.h>		/* ioctl() */
+#include <unistd.h>		/* ioctl() */
+#include <sys/mman.h>
+#include <stdlib.h>
+
+#include "gfx_common.h"
+#include "graphicstest.h"
+#include "libvtsSUNWxfb.h"	/* Common VTS library definitions */
+#include "gfx_vts.h"		/* VTS Graphics Test common routines */
+#include "ast.h"
+
+typedef union MemType {
+	uint64_t	val[8];
+	uint32_t	word[16];
+	uint16_t	halfwd[32];
+	uint8_t		byte[64];
+} MemType;
+
+static const int access_mode[] = {
+	1, 2, 4, 8, 0
+};
+static const char *const access_tname[] = {
+	"\tverifying byte access mode...",
+	"\tverifying short access mode...",
+	"\tverifying word access mode...",
+	"\tverifying long long access mode...",
+};
+
+void
+Write8(void *addr, uint8_t data) {
+	*(uint8_t *)addr = data;
+}
+
+void
+Write16(void *addr, uint16_t data) {
+	*(uint16_t *)addr = data;
+}
+
+void
+Write32(void *addr, uint32_t data) {
+	*(uint32_t *)addr = data;
+}
+
+void
+Write64(void *addr, uint64_t data) {
+	*(uint64_t *)addr = data;
+}
+
+uint8_t
+read8(void *addr) {
+	return (*(uint8_t *)addr);
+}
+
+uint16_t
+read16(void *addr) {
+	return (*(uint16_t *)addr);
+}
+
+uint32_t
+read32(void *addr) {
+	return (*(uint32_t *)addr);
+}
+
+uint64_t
+read64(void *addr) {
+	return (*(uint64_t *)addr);
+}
+
+
+u_int
+test_data() {
+	u_int ret;
+
+	ret = (u_int)mrand48();
+	return (ret);
+}
+
+MemType *data;
+MemType *cdata;
+
+
+void
+plane_change(int num_planes_, caddr_t base_, int sh, int sw)
+{
+	int		num_planes = num_planes_;
+	caddr_t		base = base_;
+	int		i;
+	int		j;
+
+	int pix_per_write, old_pix_per_write;
+
+	/* Get memory to store data */
+
+	int memcount = num_planes * 8;
+
+	if (data)  free(data);
+	if (cdata) free(cdata);
+
+	data  = (MemType *)memalign(64, memcount * sizeof (MemType));
+	cdata = (MemType *)memalign(64, memcount * sizeof (MemType));
+
+	/* Write data to memory */
+	for (i = 0; i < memcount; i++) {
+	    for (j = 0; j < 8; j++) {
+		/* Figure out the value to write */
+		data[i].val[j] = ((unsigned long long)test_data() << 32)
+					| test_data();
+		cdata[i].val[j] = ~data[i].val[j];
+	    }
+	}
+
+}	/* plane_change() */
+
+
+boolean_t
+write_read(int xoff, int yoff, boolean_t complement, int access_mode,
+	boolean_t pass, int fb_pitch, int bytepp, caddr_t base)
+{
+	MemType		*dp;
+	int		pitch = fb_pitch;
+	int		x;
+	int		y;
+	int		i;
+	caddr_t		mem_addr;
+	caddr_t		dp_addr;
+	u_int		second_rdval;
+	MemType		*rdval;
+	int		subscr = 0;
+
+	if (complement) {
+	    dp = cdata;
+	} else {
+	    dp = data;
+	}
+
+	/* Write Data to Screen */
+	for (y = yoff; y < yoff + 64; y++) {
+	    for (x = xoff * bytepp, i = 0;
+		x < ((xoff + 64) *bytepp);
+		x += access_mode, i++) {
+		mem_addr = (y*pitch*bytepp) + x + base;
+		/* Check which access mode to use for write */
+		switch (access_mode) {
+		case 8:	/* long long (8-byte) access mode */
+			Write64(mem_addr, dp[subscr].val[i]);
+			break;
+		case 4:	/* word (4-byte) access mode */
+			Write32(mem_addr, dp[subscr].word[i]);
+			break;
+		case 2:	/* short (2-byte) access mode */
+			Write16(mem_addr, dp[subscr].halfwd[i]);
+			break;
+		default: /* default to byte access */
+			Write8(mem_addr, dp[subscr].byte[i]);
+			break;
+		}
+	    }
+	    subscr++;
+	}
+
+	/* Read the Data From the Screen */
+
+	rdval = (MemType *)memalign(64, (sizeof (MemType) * bytepp));
+
+	for (y = yoff; y < yoff + 64; y++) {
+	    for (x = xoff * bytepp, i = 0;
+		x < ((xoff + 64) * bytepp);
+		x += access_mode, i++) {
+		mem_addr = (y*pitch*bytepp) + x + base;
+
+		switch (access_mode) {
+		case 8:	/* long long (8-byte) access mode */
+			rdval->val[i] = read64(mem_addr);
+			break;
+		case 4:	/* word (4-byte) access mode */
+			rdval->word[i] = read32(mem_addr);
+			break;
+		case 2:	/* short (2-byte) access mode */
+			rdval->halfwd[i] = read16(mem_addr);
+			break;
+		default: /* default to byte access */
+			rdval->byte[i] = read8(mem_addr);
+			break;
+		}
+	    }
+
+	    /* TODO: verification */
+	    if (memcmp(rdval, dp[subscr].byte, 64 * bytepp) != 0) {
+		switch (access_mode) {
+		case 8:	/* long long (8-byte) access mode */
+			for (i = 0; i < (16 * bytepp); i++) {
+			    if (rdval->word[i] != dp[subscr].word[i]) {
+				free(rdval);
+				return (B_FALSE);
+			    }
+			}
+			break;
+		case 4:	/* word (4-byte) access mode */
+			for (i = 0; i < (16  * bytepp); i++) {
+			    if (rdval->word[i] != dp[subscr].word[i]) {
+				free(rdval);
+				return (B_FALSE);
+			    }
+			}
+			break;
+		case 2:	/* short (2-byte) access mode */
+			for (i = 0; i < (32 * bytepp); i++) {
+			    if (rdval->halfwd[i] != dp[subscr].halfwd[i]) {
+				    free(rdval);
+				    return (B_FALSE);
+			    }
+			}
+			break;
+		default: /* default to byte access */
+			for (i = 0; i < (64 * bytepp); i++) {
+			    if (rdval->byte[i] != dp[subscr].byte[i]) {
+				free(rdval);
+				return (B_FALSE);
+			    }
+			}
+			break;
+		}
+	    }
+	    subscr ++;
+	}
+
+	return (B_TRUE);
+
+}	/* write_read() */
+
+
+void
+check_plane(int num_planes, int access_mode, char *test_name,
+	    int fb_offset, int fb_pitch, int fb_height,
+	    int fb_width, int bytepp, caddr_t base)
+{
+	int		x;
+	int		y;
+	int		complement;
+
+	/* Set up raster for this plane group */
+	plane_change(num_planes,  base + fb_offset, fb_width, fb_height);
+
+	/* Cover each 64x64 chunk of screen space */
+	y = 0;
+	while (y < fb_height) {
+	    x = 0;
+	    while (x < fb_width) {
+		if (x + 63 > fb_width) x = fb_width - 64;
+		if (y + 63 > fb_height) y = fb_height - 64;
+
+		/* Do each chunk twice - once normal, once complement */
+		for (complement = B_FALSE;
+		    	complement <= B_TRUE;
+		    	complement++) {
+		    write_read(x, y,
+				(boolean_t)complement,
+				access_mode,
+				B_TRUE,
+				fb_pitch,
+				bytepp,
+				base) ||
+			    write_read(x, y,
+				(boolean_t)complement,
+				access_mode,
+				B_FALSE,
+				fb_pitch,
+				bytepp,
+				base);
+		}
+
+		/* Move over one 64x64 chunk */
+		x += 64;
+	    }
+
+	    /* Move down one 64x64 chunk */
+	    y += 64;
+	}
+
+}	/* check_plane() */
+
+
+void
+memory_test(return_packet *rp, int fd)
+{
+        struct ast_info  ast_info;
+        struct ast_info  *pAST;
+	unsigned int red;
+	unsigned char *fbaddr;
+	int i;
+	int bytepp;
+	int fb_offset, fb_pitch, fb_height, fb_width;
+
+        pAST = &ast_info;
+        pAST->fd = fd;
+
+        /*
+         * map the registers & frame buffers memory
+         */
+        if (ast_map_mem(pAST, rp, GRAPHICS_ERR_MEMORY_MSG) == -1) {
+            return;
+        }
+
+	if (ast_init_info(pAST) == -1) {
+	    return;
+	}
+
+	for (i = 0; access_mode[i] != 0; i++) {
+	    check_plane((size_t) 8*pAST->bytesPerPixel, access_mode[i], 
+			(char *)"Memory Test", 
+			0, pAST->screenWidth, pAST->screenHeight, pAST->screenWidth,
+			pAST->bytesPerPixel, (caddr_t)pAST->FBvaddr);
+	}
+
+        /*
+         * Unmap the registers & frame buffers memory
+         */
+        if (ast_unmap_mem(pAST, rp, GRAPHICS_ERR_MEMORY_MSG) == -1) {
+            return;
+        }
+}	/* memory_test() */
+
+
+/* End of memory.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/ast/tools.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,1005 @@
+
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 <sys/types.h>
+#include <stdio.h>
+#include <sys/mman.h>
+
+#include "gfx_common.h"		/* GFX Common definitions */
+#include "graphicstest.h"
+#include "libvtsSUNWast.h"	/* Common VTS library definitions */
+
+#include "X11/Xlib.h"
+#include "gfx_vts.h"		/* VTS Graphics Test common routines */
+#include "ast.h"
+
+void
+ASTSetReg(int fd, int offset, int value)
+{
+	ast_io_reg	io_reg;
+	
+	io_reg.offset = offset;
+	io_reg.value = value;
+	ioctl(fd, AST_SET_IO_REG, &io_reg);
+}
+
+void
+ASTGetReg(int fd, int offset, int *value)
+{
+	ast_io_reg	io_reg;
+	
+	io_reg.offset = offset;
+	ioctl(fd, AST_GET_IO_REG, &io_reg);
+	*value = io_reg.value;
+}
+
+void
+ASTSetIndexReg(int fd, int offset, int index, unsigned char value)
+{
+	ast_io_reg	io_reg;
+
+	io_reg.offset = offset;
+	io_reg.value = index;
+	ioctl(fd, AST_SET_IO_REG, &io_reg);
+	io_reg.offset = offset + 1;
+	io_reg.value = value;
+	ioctl(fd, AST_SET_IO_REG, &io_reg);
+}
+
+void
+ASTGetIndexReg(int fd, int offset, int index, unsigned char *value)
+{
+	ast_io_reg	io_reg;
+
+	io_reg.offset = offset;
+	io_reg.value = index;
+	ioctl(fd, AST_SET_IO_REG, &io_reg);
+	io_reg.offset = offset + 1;
+	ioctl(fd, AST_GET_IO_REG, &io_reg);
+	*value = io_reg.value;
+}
+
+void
+ASTSetIndexRegMask(int fd, int offset, int index, int and, unsigned char value)
+{
+	ast_io_reg	io_reg;
+	unsigned char	temp;
+
+	io_reg.offset = offset;
+	io_reg.value = index;
+	ioctl(fd, AST_SET_IO_REG, &io_reg);
+	io_reg.offset = offset + 1;
+	ioctl(fd, AST_GET_IO_REG, &io_reg);
+	temp = (io_reg.value & and) | value;
+	io_reg.offset = offset;
+	io_reg.value = index;
+	ioctl(fd, AST_SET_IO_REG, &io_reg);
+	io_reg.offset = offset + 1;
+	io_reg.value = temp;
+	ioctl(fd, AST_SET_IO_REG, &io_reg);
+}
+
+void
+ASTGetIndexRegMask(int fd, int offset, int index, int and, unsigned char *value)
+{
+	ast_io_reg	io_reg;
+	unsigned char	temp;
+
+	io_reg.offset = offset;
+	io_reg.value = index;
+	ioctl(fd, AST_SET_IO_REG, &io_reg);
+	io_reg.offset = offset + 1;
+	ioctl(fd, AST_GET_IO_REG, &io_reg);
+	*value = io_reg.value & and;
+}
+
+void
+ASTOpenKey(int fd)
+{
+	ASTSetIndexReg(fd, CRTC_PORT, 0x80, 0xA8);
+}
+
+unsigned int 
+ASTMMIORead32(unsigned char *addr)
+{
+	return (*(volatile unsigned int *)(addr));
+}
+
+void 
+ASTMMIOWrite32(unsigned char *addr, unsigned int data)
+{
+	*(unsigned int *)(addr) = data;
+}
+
+
+unsigned int 
+ASTMMIORead32_8pp(unsigned char *addr)
+{
+    union
+    {
+        unsigned int   ul;
+        unsigned char  b[4];
+    } data;
+
+    unsigned int m;
+
+    data.ul = *((volatile unsigned int *)(addr));
+
+    m = (((unsigned int)data.b[3]) << 24) |
+                (((unsigned int)data.b[2]) << 16) |
+                (((unsigned int)data.b[1]) << 8) |
+                (((unsigned int)data.b[0]));
+    return (m);
+}
+
+void 
+ASTMMIOWrite32_8pp(unsigned char *addr, unsigned int val)
+{
+    union
+    {
+        unsigned int   ul;
+        unsigned char  b[4];
+    } data;
+
+    unsigned int m;
+
+    data.ul = val;
+    m = (((unsigned int)data.b[3]) << 24) |
+                (((unsigned int)data.b[2]) << 16) |
+                (((unsigned int)data.b[1]) << 8) |
+                (((unsigned int)data.b[0]));
+
+    *(unsigned int*)(addr) = m;
+}
+
+void
+ASTWaitEngIdle(struct ast_info *pAST)
+{
+	unsigned int ulEngState, ulEngState2;
+	unsigned char reg;
+	unsigned int ulEngCheckSetting;
+
+
+	if (pAST->MMIO2D)
+	    return;
+
+	ulEngCheckSetting = 0x80000000;
+
+	ASTGetIndexRegMask(pAST->fd, CRTC_PORT, 0xA4, 0x01, &reg);
+	if (!reg) {
+	    printf("2d disabled\n");
+	    return;
+	}
+
+	ASTGetIndexRegMask(pAST->fd, CRTC_PORT, 0xA3, 0x0F, &reg);
+	if (!reg) {
+	    printf("2d not work if in std mode\n");
+	    return;
+	}
+
+	do
+	{
+	    ulEngState   = pAST->read32((pAST->CMDQInfo.pjEngStatePort));
+	    ulEngState2   = pAST->read32((pAST->CMDQInfo.pjEngStatePort));
+	    ulEngState2   = pAST->read32((pAST->CMDQInfo.pjEngStatePort));
+	    ulEngState2   = pAST->read32((pAST->CMDQInfo.pjEngStatePort));
+	    ulEngState2   = pAST->read32((pAST->CMDQInfo.pjEngStatePort));
+	    ulEngState2   = pAST->read32((pAST->CMDQInfo.pjEngStatePort));
+	    ulEngState   &= 0xFFFC0000;
+	    ulEngState2  &= 0xFFFC0000;
+	} while ((ulEngState & ulEngCheckSetting) || (ulEngState != ulEngState2));
+}
+
+void
+ASTSaveState(struct ast_info *pAST)
+{
+	pAST->save_dst_base   = pAST->read32(MMIOREG_DST_BASE);
+	pAST->save_line_xy    = pAST->read32(MMIOREG_LINE_XY);
+	pAST->save_line_err   = pAST->read32(MMIOREG_LINE_Err);
+	pAST->save_line_width = pAST->read32(MMIOREG_LINE_WIDTH);
+	pAST->save_line_k1    = pAST->read32(MMIOREG_LINE_K1);
+	pAST->save_line_k2    = pAST->read32(MMIOREG_LINE_K2);
+	pAST->save_mono_pat1  = pAST->read32(MMIOREG_MONO1);
+	pAST->save_mono_pat2  = pAST->read32(MMIOREG_MONO2);
+}
+
+void
+ASTResetState(struct ast_info *pAST)
+{
+	pAST->write32(MMIOREG_DST_BASE,   pAST->save_dst_base);
+	pAST->write32(MMIOREG_LINE_XY,    pAST->save_line_xy);
+	pAST->write32(MMIOREG_LINE_Err,   pAST->save_line_err);
+	pAST->write32(MMIOREG_LINE_WIDTH, pAST->save_line_width);
+	pAST->write32(MMIOREG_LINE_K1,    pAST->save_line_k1);
+	pAST->write32(MMIOREG_LINE_K2,    pAST->save_line_k2);
+	pAST->write32(MMIOREG_MONO1,      pAST->save_mono_pat1);
+	pAST->write32(MMIOREG_MONO2,      pAST->save_mono_pat2);
+}
+
+int
+ASTInitCMDQ(struct ast_info *pAST)
+{
+	int availableLen;
+
+	availableLen = pAST->FBMapSize - 
+			(pAST->screenWidth * pAST->bytesPerPixel * pAST->screenHeight);
+
+	if (availableLen < 0x100000) {
+
+#if DEBUG
+	    printf("Not enough memory to initialize CMDQ, fallback to MMIO\n");
+#endif
+	    return -1;
+	}
+
+	pAST->CMDQInfo.pjCmdQBasePort	= pAST->MMIOvaddr + 0x8044;
+	pAST->CMDQInfo.pjWritePort	= pAST->MMIOvaddr + 0x8048;
+	pAST->CMDQInfo.pjReadPort	= pAST->MMIOvaddr + 0x804C;
+	pAST->CMDQInfo.pjEngStatePort	= pAST->MMIOvaddr + 0x804C;
+
+	pAST->CMDQInfo.ulCMDQSize 	= 0x40000;			/* byte */
+	pAST->CMDQInfo.ulCMDQOffset 	= 
+			(pAST->screenWidth * pAST->bytesPerPixel * pAST->screenHeight);
+	pAST->CMDQInfo.pjCMDQvaddr 	= pAST->FBvaddr + pAST->CMDQInfo.ulCMDQOffset;
+	pAST->CMDQInfo.ulCMDQueueLen 	= pAST->CMDQInfo.ulCMDQSize - CMD_QUEUE_GUARD_BAND;
+	pAST->CMDQInfo.ulCMDQMask 	= pAST->CMDQInfo.ulCMDQSize - 1;
+
+
+	pAST->CMDQInfo.ulWritePointer = 0;
+
+	return 0;
+}
+
+ASTEnableCMDQ(struct ast_info *pAST) 
+{
+	unsigned int ulVMCmdQBasePort = 0;
+	
+	ASTWaitEngIdle(pAST);
+
+	ulVMCmdQBasePort = pAST->CMDQInfo.ulCMDQOffset >> 3;
+
+	/*
+	 * set CMDQ Threshold 
+	 */
+	ulVMCmdQBasePort |= 0xF0000000;
+
+	pAST->write32((pAST->CMDQInfo.pjCmdQBasePort), ulVMCmdQBasePort);
+	pAST->CMDQInfo.ulWritePointer = pAST->read32((pAST->CMDQInfo.pjWritePort));
+	pAST->CMDQInfo.ulWritePointer <<= 3;	/* byte offset */
+}
+
+
+ASTEnable2D(struct ast_info *pAST)
+{
+	unsigned int ulData;
+
+	pAST->write32((pAST->MMIOvaddr + 0xF004), 0x1e6e0000);
+	pAST->write32((pAST->MMIOvaddr + 0xF000), 0x1);
+
+	ulData = pAST->read32((pAST->MMIOvaddr + 0x1200c));
+	pAST->write32((pAST->MMIOvaddr + 0x1200c), (ulData & 0xFFFFFFFD));
+
+	ASTSetIndexRegMask(pAST->fd, CRTC_PORT, 0xA4, 0xFE, 0x01);
+}
+
+unsigned int
+ASTGetCMDQLength(struct ast_info *pAST, unsigned int ulWritePointer, unsigned int ulCMDQMask)
+{
+	unsigned long ulReadPointer, ulReadPointer2;
+
+	do {
+	    ulReadPointer  = pAST->read32((pAST->CMDQInfo.pjReadPort));
+	    ulReadPointer2 = pAST->read32((pAST->CMDQInfo.pjReadPort));
+	    ulReadPointer2 = pAST->read32((pAST->CMDQInfo.pjReadPort));
+	    ulReadPointer2 = pAST->read32((pAST->CMDQInfo.pjReadPort));
+	    ulReadPointer2 = pAST->read32((pAST->CMDQInfo.pjReadPort));
+	    ulReadPointer2 = pAST->read32((pAST->CMDQInfo.pjReadPort));
+	    ulReadPointer  &= 0x3FFFF;
+	    ulReadPointer2 &= 0x3FFFF;
+	} while (ulReadPointer != ulReadPointer2);
+
+	return ((ulReadPointer << 3) - ulWritePointer - CMD_QUEUE_GUARD_BAND) & ulCMDQMask;
+}
+ 
+PKT_SC *
+ASTRequestCMDQ(struct ast_info *pAST, int ncmd)
+{
+	unsigned char   *pjBuffer;
+	unsigned long   i, ulWritePointer, ulCMDQMask, ulCurCMDQLen, ulContinueCMDQLen;
+	unsigned long	ulDataLen;
+	
+	ulDataLen = ncmd * 2 * 4;
+	ulWritePointer = pAST->CMDQInfo.ulWritePointer;
+	ulContinueCMDQLen = pAST->CMDQInfo.ulCMDQSize - ulWritePointer;
+	ulCMDQMask = pAST->CMDQInfo.ulCMDQMask;
+
+	if (ulContinueCMDQLen >= ulDataLen)
+	{
+	    /* Get CMDQ Buffer */
+	    if (pAST->CMDQInfo.ulCMDQueueLen >= ulDataLen)
+	    {
+	        ;
+	    }
+	    else
+	    {
+	        do
+	        {
+	            ulCurCMDQLen = ASTGetCMDQLength(pAST, ulWritePointer, ulCMDQMask);
+	        } while (ulCurCMDQLen < ulDataLen);
+
+	        pAST->CMDQInfo.ulCMDQueueLen = ulCurCMDQLen;
+
+	    }
+
+	    pjBuffer = pAST->CMDQInfo.pjCMDQvaddr + ulWritePointer;
+	    pAST->CMDQInfo.ulCMDQueueLen -= ulDataLen;
+	    pAST->CMDQInfo.ulWritePointer = (ulWritePointer + ulDataLen) & ulCMDQMask;
+	    return (PKT_SC *)pjBuffer;
+	}
+	else
+	{        /* Fill NULL CMD to the last of the CMDQ */
+	    if (pAST->CMDQInfo.ulCMDQueueLen >= ulContinueCMDQLen)
+	    {
+	        ;
+	    }
+	    else
+	    {
+    
+	        do
+	        {
+	            ulCurCMDQLen = ASTGetCMDQLength(pAST, ulWritePointer, ulCMDQMask);
+	        } while (ulCurCMDQLen < ulContinueCMDQLen);
+	
+	        pAST->CMDQInfo.ulCMDQueueLen = ulCurCMDQLen;
+	
+	    }
+	
+	    pjBuffer = pAST->CMDQInfo.pjCMDQvaddr + ulWritePointer;
+	    for (i = 0; i<ulContinueCMDQLen/8; i++, pjBuffer+=8)
+	    {
+	        pAST->write32(pjBuffer , (unsigned long) PKT_NULL_CMD);
+	        pAST->write32((pjBuffer+4) , 0);
+    	
+	    }
+	    pAST->CMDQInfo.ulCMDQueueLen -= ulContinueCMDQLen;
+	    pAST->CMDQInfo.ulWritePointer = ulWritePointer = 0;
+	
+	    /* Get CMDQ Buffer */
+	    if (pAST->CMDQInfo.ulCMDQueueLen >= ulDataLen)
+	    {
+	        ;
+	    }
+	    else
+	    {
+	
+	        do
+	        {
+	            ulCurCMDQLen = ASTGetCMDQLength(pAST, ulWritePointer, ulCMDQMask);
+	        } while (ulCurCMDQLen < ulDataLen);
+	
+	        pAST->CMDQInfo.ulCMDQueueLen = ulCurCMDQLen;
+	
+	    }
+
+	    pAST->CMDQInfo.ulCMDQueueLen -= ulDataLen;
+	    pjBuffer = pAST->CMDQInfo.pjCMDQvaddr + ulWritePointer;
+	    pAST->CMDQInfo.ulWritePointer = (ulWritePointer + ulDataLen) & ulCMDQMask;
+	    return (PKT_SC *)pjBuffer;
+	}
+}
+
+void
+ASTUpdateWritePointer(struct ast_info *pAST)
+{
+	pAST->write32((pAST->CMDQInfo.pjWritePort), (pAST->CMDQInfo.ulWritePointer >> 3));
+}
+
+
+void
+ASTSetupCmdArg1(struct ast_info *pAST, PKT_SC *pCMD, unsigned int header, unsigned int arg)
+{
+	pAST->write32((unsigned char *)&pCMD->header, PKT_SINGLE_CMD_HEADER + header);
+	pAST->write32((unsigned char *)pCMD->data, arg);
+	return;
+}
+
+void
+ASTSetupCmdArg2(struct ast_info *pAST, PKT_SC *pCMD, unsigned int header, 
+			unsigned int arg1, unsigned int arg2, 
+			unsigned int shift1, unsigned int shift2)
+{
+	unsigned int ul;
+
+	pAST->write32((unsigned char *)&pCMD->header, PKT_SINGLE_CMD_HEADER + header);
+	ul = (arg1 << shift1) | (arg2 << shift2);
+	pAST->write32((unsigned char *)pCMD->data, ul);
+	return;
+}
+
+
+void
+ASTSetupMMIOArg1(struct ast_info *pAST, unsigned char *addr, unsigned int arg)
+{
+	unsigned int argr;
+
+	do {
+	    pAST->write32(addr, arg);
+	    argr = pAST->read32(addr);
+	} while (arg != argr);
+
+	return;
+}
+
+void
+ASTSetupMMIOArg2(struct ast_info *pAST, unsigned char *addr,
+			unsigned int arg1, unsigned int arg2, 
+			unsigned int shift1, unsigned int shift2)
+{
+	unsigned int ul;
+	unsigned int ulr;
+
+	ul = (arg1 << shift1) | (arg2 << shift2);
+
+	do {
+	    pAST->write32(addr, ul);
+	    ulr = pAST->read32(addr);
+	} while (ul != ulr);
+
+	return;
+}
+
+
+void *
+ASTSetupForMonoPatternFill(struct ast_info *pAST, int patx, int paty, int fg, int bg, int rop)
+{
+	unsigned int cmdreg;
+	unsigned int ul;
+	PKT_SC *pCMD;
+    	
+	cmdreg = CMD_BITBLT | CMD_PAT_MONOMASK;
+	switch (pAST->bytesPerPixel) {
+	    case 1:
+	        cmdreg |= CMD_COLOR_08;
+		break;
+	    case 2:
+	        cmdreg |= CMD_COLOR_16;
+		break;
+	    case 3:
+	    case 4:
+	    default:
+	        cmdreg |= CMD_COLOR_32;
+		break;
+	}
+
+	cmdreg |= rop << 8;
+	pAST->cmdreg = cmdreg;
+
+	if (!pAST->MMIO2D) {
+	    pCMD = ASTRequestCMDQ(pAST, 5);
+
+	    ASTSetupCmdArg2(pAST, pCMD, CMDQREG_DST_PITCH, pAST->screenPitch, MASK_DST_HEIGHT, 16, 0);
+	    pCMD++;
+
+	    ASTSetupCmdArg1(pAST, pCMD, CMDQREG_FG, fg);
+	    pCMD++;
+
+	    ASTSetupCmdArg1(pAST, pCMD, CMDQREG_BG, bg);
+	    pCMD++;
+
+	    ASTSetupCmdArg1(pAST, pCMD, CMDQREG_MONO1, patx);
+	    pCMD++;
+
+	    ASTSetupCmdArg1(pAST, pCMD, CMDQREG_MONO2, paty);
+	
+	} else {
+	    ASTSetupMMIOArg2(pAST, MMIOREG_DST_PITCH, pAST->screenPitch, MASK_DST_HEIGHT, 16, 0);
+	    ASTSetupMMIOArg1(pAST, MMIOREG_FG, fg);
+	    ASTSetupMMIOArg1(pAST, MMIOREG_BG, bg);
+	    ASTSetupMMIOArg1(pAST, MMIOREG_MONO1, patx);
+	    ASTSetupMMIOArg1(pAST, MMIOREG_MONO2, paty);
+	}
+}
+
+void
+ASTMonoPatternFill(struct ast_info *pAST, int patx, int paty, int x, int y,
+			int width, int height)
+{
+	unsigned int cmdreg;
+	PKT_SC *pCMD;
+
+	cmdreg = pAST->cmdreg;
+
+	if (!pAST->MMIO2D) {
+
+	    pCMD = ASTRequestCMDQ(pAST, 4);
+	
+	    ASTSetupCmdArg1(pAST, pCMD, CMDQREG_DST_BASE, 0);
+	    pCMD++;
+
+	    ASTSetupCmdArg2(pAST, pCMD, CMDQREG_DST_XY, x, y, 16, 0);
+	    pCMD++;
+	
+	    ASTSetupCmdArg2(pAST, pCMD, CMDQREG_RECT_XY, width, height, 16, 0);
+	    pCMD++;
+	
+	    ASTSetupCmdArg1(pAST, pCMD, CMDQREG_CMD, cmdreg);
+
+	    ASTUpdateWritePointer(pAST);
+
+	} else {
+
+	    ASTSetupMMIOArg1(pAST, MMIOREG_DST_BASE, 0);
+	    ASTSetupMMIOArg2(pAST, MMIOREG_DST_XY, x, y, 16, 0);
+	    ASTSetupMMIOArg2(pAST, MMIOREG_RECT_XY, width, height, 16, 0);
+	    ASTSetupMMIOArg1(pAST, MMIOREG_CMD, cmdreg);
+	}
+}
+
+void
+ASTSetupForSolidFill(struct ast_info *pAST, int color, int rop)
+{
+	unsigned int cmdreg;
+	unsigned int ul;
+	PKT_SC *pCMD;
+    	
+	cmdreg = CMD_BITBLT | CMD_PAT_FGCOLOR;
+	switch (pAST->bytesPerPixel) {
+	    case 1:
+	        cmdreg |= CMD_COLOR_08;
+		break;
+	    case 2:
+	        cmdreg |= CMD_COLOR_16;
+		break;
+	    case 3:
+	    case 4:
+	    default:
+	        cmdreg |= CMD_COLOR_32;
+		break;
+	}
+
+	cmdreg |= rop << 8;
+	pAST->cmdreg = cmdreg;
+
+	if (!pAST->MMIO2D) {
+
+	    pCMD = ASTRequestCMDQ(pAST, 2);
+
+	    ASTSetupCmdArg2(pAST, pCMD, CMDQREG_DST_PITCH, pAST->screenPitch, MASK_DST_HEIGHT, 16, 0);
+	    pCMD++;
+
+	    ASTSetupCmdArg1(pAST, pCMD, CMDQREG_FG, color);
+	    pCMD++;
+
+	} else {
+
+	    ASTSetupMMIOArg2(pAST, MMIOREG_DST_PITCH, pAST->screenPitch, MASK_DST_HEIGHT, 16, 0);
+	    ASTSetupMMIOArg1(pAST, MMIOREG_FG, color);
+	}
+}
+
+void
+ASTSolidFillRect(struct ast_info *pAST, int x, int y, int width, int height)
+{
+	unsigned int cmdreg;
+	unsigned int ul;
+	PKT_SC *pCMD;
+
+	cmdreg = pAST->cmdreg;
+
+
+	if (!pAST->MMIO2D) {
+
+	    pCMD = ASTRequestCMDQ(pAST, 4);
+
+	    ASTSetupCmdArg1(pAST, pCMD, CMDQREG_DST_BASE, 0);
+	    pCMD++;
+
+	    ASTSetupCmdArg2(pAST, pCMD, CMDQREG_DST_XY, x, y, 16, 0);
+	    pCMD++;
+
+	    ASTSetupCmdArg2(pAST, pCMD, CMDQREG_RECT_XY, width, height, 16, 0);
+	    pCMD++;
+
+	    ASTSetupCmdArg1(pAST, pCMD, CMDQREG_CMD, cmdreg);
+	    pCMD++;
+
+	    ASTUpdateWritePointer(pAST);
+	
+	} else {
+
+	    ASTSetupMMIOArg1(pAST, MMIOREG_DST_BASE, 0);
+	    ASTSetupMMIOArg2(pAST, MMIOREG_DST_XY, x, y, 16, 0);
+	    ASTSetupMMIOArg2(pAST, MMIOREG_RECT_XY, width, height, 16, 0);
+	    ASTSetupMMIOArg1(pAST, MMIOREG_CMD, cmdreg);
+	}
+}
+
+void
+ASTSetupForSolidLine(struct ast_info *pAST, int color, int rop)
+{
+	unsigned int cmdreg;
+	unsigned int ul;
+	PKT_SC *pCMD;
+    	
+	cmdreg = CMD_BITBLT;
+	switch (pAST->bytesPerPixel) {
+	    case 1:
+	        cmdreg |= CMD_COLOR_08;
+		break;
+	    case 2:
+	        cmdreg |= CMD_COLOR_16;
+		break;
+	    case 3:
+	    case 4:
+	    default:
+	        cmdreg |= CMD_COLOR_32;
+		break;
+	}
+
+	cmdreg |= rop << 8;
+	pAST->cmdreg = cmdreg;
+
+	if (!pAST->MMIO2D) {
+
+	    pCMD = ASTRequestCMDQ(pAST, 3);
+
+	    ASTSetupCmdArg2(pAST, pCMD, CMDQREG_DST_PITCH, pAST->screenPitch, MASK_DST_HEIGHT, 16, 0);
+	    pCMD++;
+
+	    ASTSetupCmdArg1(pAST, pCMD, CMDQREG_FG, color);
+	    pCMD++;
+
+	    ASTSetupCmdArg1(pAST, pCMD, CMDQREG_BG, 0);
+	    pCMD++;
+
+	} else {
+
+	    ASTSetupMMIOArg2(pAST, MMIOREG_DST_PITCH, pAST->screenPitch, MASK_DST_HEIGHT, 16, 0);
+	    ASTSetupMMIOArg1(pAST, MMIOREG_FG, color);
+	    ASTSetupMMIOArg1(pAST, MMIOREG_BG, 0);
+	}
+}
+
+void
+ASTSolidLine(struct ast_info *pAST, int x1, int y1, int x2, int y2)
+{
+	unsigned int cmdreg;
+	unsigned int ul;
+	PKT_SC   *pCMD;
+	int	 GAbsX, GAbsY;
+	int      MM, mm, err, k1, k2, xm;
+	int	 width, height;
+
+	cmdreg = (pAST->cmdreg & (~CMD_MASK)) | CMD_ENABLE_CLIP | CMD_NOT_DRAW_LAST_PIXEL;
+
+	GAbsX = abs(x1 - x2);
+	GAbsY = abs(y1 - y2);
+
+	cmdreg |= CMD_LINEDRAW; 
+
+	if (GAbsX >= GAbsY) {
+	    MM = GAbsX;
+	    mm = GAbsY;
+	    xm = 1;
+	} else {
+	    MM = GAbsY;
+	    mm = GAbsX;
+	    xm = 0;
+	} 
+
+	if (x1 >= x2) {
+	    cmdreg |= CMD_X_DEC;
+	}
+
+	if (y1 >= y2) {
+	    cmdreg |= CMD_Y_DEC;
+	}
+
+	err = (signed) (2 * mm - MM);
+	k1 = 2 * mm;
+	k2 = (signed) 2 * mm - 2 * MM;
+	
+
+	if (!pAST->MMIO2D) {
+
+	    pCMD = ASTRequestCMDQ(pAST, 7);
+
+	    ASTSetupCmdArg1(pAST, pCMD, CMDQREG_DST_BASE, 0);
+	    pCMD++;
+
+	    ASTSetupCmdArg2(pAST, pCMD, CMDQREG_LINE_XY, x1, y1, 16, 0);
+	    pCMD++;
+
+	    ASTSetupCmdArg2(pAST, pCMD, CMDQREG_LINE_Err, xm, (err & MASK_LINE_ERR), 24, 0);
+	    pCMD++;
+
+	    ASTSetupCmdArg2(pAST, pCMD, CMDQREG_LINE_WIDTH, (MM & MASK_LINE_WIDTH), 0, 16, 0);
+	    pCMD++;
+
+	    ASTSetupCmdArg1(pAST, pCMD, CMDQREG_LINE_K1, (k1 & MASK_LINE_K1));
+	    pCMD++;
+
+	    ASTSetupCmdArg1(pAST, pCMD, CMDQREG_LINE_K2, (k2 & MASK_LINE_K2));
+	    pCMD++;
+
+	    ASTSetupCmdArg1(pAST, pCMD, CMDQREG_CMD, cmdreg);
+	    pCMD++;
+
+	    ASTUpdateWritePointer(pAST);
+
+	    ASTWaitEngIdle(pAST);
+
+	} else {
+
+	    ASTSetupMMIOArg1(pAST, MMIOREG_DST_BASE, 0);
+	    ASTSetupMMIOArg2(pAST, MMIOREG_LINE_XY, x1, y1, 16, 0);
+	    ASTSetupMMIOArg2(pAST, MMIOREG_LINE_Err, xm, (err & MASK_LINE_ERR), 24, 0);
+	    ASTSetupMMIOArg2(pAST, MMIOREG_LINE_WIDTH, (MM & MASK_LINE_WIDTH), 0, 16, 0);
+	    ASTSetupMMIOArg1(pAST, MMIOREG_LINE_K1, (k1 & MASK_LINE_K1));
+	    ASTSetupMMIOArg1(pAST, MMIOREG_LINE_K2, (k1 & MASK_LINE_K2));
+	    ASTSetupMMIOArg1(pAST, MMIOREG_CMD, cmdreg);
+	}
+}
+
+void
+ASTSetClippingRectangle(struct ast_info *pAST, int left, int top, int right, int bottom)
+{
+	PKT_SC *pCMD;
+    	
+	if (!pAST->MMIO2D) {
+
+	    pCMD = ASTRequestCMDQ(pAST, 2);
+
+	    ASTSetupCmdArg2(pAST, pCMD, CMDQREG_CLIP1, (left & MASK_CLIP), (top & MASK_CLIP), 16, 0);
+	    pCMD++;
+
+	    ASTSetupCmdArg2(pAST, pCMD, CMDQREG_CLIP2, (right & MASK_CLIP), (bottom & MASK_CLIP), 16, 0);
+	    ASTUpdateWritePointer(pAST);
+	
+	} else {
+
+	    ASTSetupMMIOArg2(pAST, MMIOREG_CLIP1, (left & MASK_CLIP), (top & MASK_CLIP), 16, 0);
+	    ASTSetupMMIOArg2(pAST, MMIOREG_CLIP2, (right & MASK_CLIP), (bottom & MASK_CLIP), 16, 0);
+	}
+}
+
+int
+ast_get_pci_info(int fd, struct pci_info *pciInfo)
+{
+	struct gfx_pci_cfg pciCfg;
+	int i;
+	unsigned int bar;
+
+	if (ioctl(fd, GFX_IOCTL_GET_PCI_CONFIG, &pciCfg) == -1) {
+		return -1;
+	}
+
+	for (i = 0; i < 6; i++) {
+	    bar = pciCfg.bar[i];
+	    if (bar != 0) {
+		if (bar & PCI_MAP_IO) {
+		    pciInfo->ioBase[i] = PCIGETIO(bar);
+		    pciInfo->type[i] = bar & PCI_MAP_IO_ATTR_MASK;
+		} else {
+		    pciInfo->type[i] = bar & PCI_MAP_MEMORY_ATTR_MASK;
+		    pciInfo->memBase[i] = PCIGETMEMORY(bar);
+		    if (PCI_MAP_IS64BITMEM(bar)) {
+			if (i == 5) {
+			    pciInfo->memBase[i] = 0;
+			} else {
+			    int bar_hi = pciCfg.bar[i+1];
+			    pciInfo->memBase[i] |= (bar_hi << 32);
+			    ++i;
+			}
+		    }
+		    pciInfo->size[i] = AST_REG_SIZE_LOG2;
+		}
+	    }
+	}
+
+	return 0;
+}
+
+int
+ast_get_mem_info(struct pci_info *pci_info, struct ast_info *pAST) 
+{
+	unsigned char reg;
+
+	pAST->FBPhysAddr = pci_info->memBase[0] & 0xfff00000;
+	pAST->FBMapSize = 0;
+
+	pAST->MMIOPhysAddr = pci_info->memBase[1] & 0xffff0000;
+	pAST->MMIOMapSize =  AST_MMIO_SIZE;
+
+	pAST->RelocateIO = pci_info->ioBase[2];
+
+	ASTOpenKey(pAST->fd);
+	ASTGetIndexRegMask(pAST->fd, CRTC_PORT, 0xAA, 0xFF, &reg);
+	switch (reg & 0x03)
+	{
+	    case 0x00:
+		pAST->FBMapSize = AST_VRAM_SIZE_08M;
+		break;
+	    case 0x01:
+		pAST->FBMapSize = AST_VRAM_SIZE_16M;
+		break;
+	    case 0x02:
+		pAST->FBMapSize = AST_VRAM_SIZE_32M;
+		break;
+	    case 0x03:
+		pAST->FBMapSize = AST_VRAM_SIZE_64M;
+		break;
+	    default:
+		pAST->FBMapSize = AST_VRAM_SIZE_08M;
+		break;
+	}
+
+#if DEBUG
+	printf("FBPhysAddr=0x%x FBMapSize=0x%x\n", pAST->FBPhysAddr, pAST->FBMapSize);
+	printf("MMIOPhysAddr=0x%x MMIOMapSize=0x%x\n", pAST->MMIOPhysAddr, pAST->MMIOMapSize);
+	printf("RelocateIO=0x%x\n", pAST->RelocateIO);
+#endif
+
+	return 0;
+}
+
+
+int
+ast_init_info(struct ast_info *pAST)
+{
+	unsigned char val;
+	unsigned int  status = 0;
+
+	/* 
+	 * first check if the hardware is already initialized.
+	 * If not, abort
+	 */
+	ioctl(pAST->fd, AST_GET_STATUS_FLAGS, &status);
+	if (!(status & AST_STATUS_HW_INITIALIZED))
+		return -1;
+
+	pAST->MMIO2D = 0;
+
+	ASTOpenKey(pAST->fd);
+	
+	/*
+	 * get the VDE
+	 */
+	ASTGetIndexRegMask(pAST->fd, CRTC_PORT, 0x01, 0xff, &val);
+	pAST->screenWidth = ((int)(val + 1)) << 3;
+
+	switch (pAST->screenWidth) {
+	case 1920:
+	case 1600:
+		pAST->screenHeight = 1200;
+		break;
+	case 1280:
+		pAST->screenHeight = 1024;
+		break;
+	case 1024:
+		pAST->screenHeight = 768;
+		break;
+	case 800:
+		pAST->screenHeight = 600;
+		break;
+	case 640:
+	default:
+		pAST->screenHeight = 480;
+		break;
+	}
+
+	/*
+	 * get the display depth info 
+	 */
+	ASTGetIndexRegMask(pAST->fd, CRTC_PORT, 0xA2, 0xff, &val);
+	if (val & 0x80) {
+		/* 32 bits */
+		pAST->bytesPerPixel = 4;
+		pAST->read32	    = (PFNRead32)  ASTMMIORead32;
+		pAST->write32	    = (PFNWrite32) ASTMMIOWrite32;
+	
+	} else {
+		pAST->bytesPerPixel = 1;
+		pAST->read32	    = (PFNRead32)  ASTMMIORead32_8pp;
+		pAST->write32	    = (PFNWrite32) ASTMMIOWrite32_8pp;
+	}
+
+	pAST->screenPitch = pAST->screenWidth * pAST->bytesPerPixel;
+
+	/*
+	 * Enable MMIO
+	 */
+	ASTSetIndexRegMask(pAST->fd, CRTC_PORT, 0xA1, 0xff, 0x04);
+
+	return 0;
+}
+
+int
+ast_map_mem(struct ast_info *pAST, return_packet *rp, int test)
+{
+        struct pci_info  pci_info;
+        int              pageSize, size;
+	int		 fd = pAST->fd;
+
+        if (ast_get_pci_info(fd, &pci_info) == -1) {
+            gfx_vts_set_message(rp, 1, test, "get pci info failed");
+            return -1;
+        }
+
+
+        if (ast_get_mem_info(&pci_info, pAST) == -1) {
+            gfx_vts_set_message(rp, 1, test, "get mem info failed");
+            return -1;
+        }
+
+        /*
+         * Map framebuffer
+         */
+        pageSize = getpagesize();
+        size = pAST->FBMapSize + (pageSize - 1) & (~(pageSize - 1));
+
+        pAST->FBvaddr = (unsigned char *)mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED,
+                                        fd, pAST->FBPhysAddr);
+
+        if (pAST->FBvaddr == MAP_FAILED) {
+            gfx_vts_set_message(rp, 1, test, "map framebuffer failed");
+            return -1;
+        }
+
+
+        /*
+         * Map MMIO
+         */
+        size = pAST->MMIOMapSize + (pageSize - 1) & (~(pageSize - 1));
+
+        pAST->MMIOvaddr = (unsigned char *)mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED,
+                                        fd, pAST->MMIOPhysAddr);
+
+        if (pAST->MMIOvaddr == MAP_FAILED) {
+            gfx_vts_set_message(rp, 1, test, "map MMIO failed");
+            return -1;
+        }
+
+	return 0;
+}
+
+int
+ast_unmap_mem(struct ast_info *pAST, return_packet *rp, int test)
+{
+        /*
+         * Unmap Frame Buffer
+         */
+
+        if (munmap((void *)pAST->FBvaddr, pAST->FBMapSize) == -1) {
+            gfx_vts_set_message(rp, 1, test, "unmap framebuffer failed");
+            return -1;
+        }
+
+        if (munmap((void *)pAST->MMIOvaddr, pAST->MMIOMapSize) == -1) {
+            gfx_vts_set_message(rp, 1, test, "unmap MMIO failed");
+            return -1;
+        }
+
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/efb/Makefile	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,31 @@
+#
+# Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS 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.
+#
+
+#
+# Target device
+#
+DEV	= EFB
+Dev	= efb
+
+include ../Makefile.common
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/efb/chip.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,336 @@
+
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 <sys/types.h>
+#include <errno.h>
+#include <signal.h>		/* signal() */
+#include <stdio.h>
+#include <stropts.h>		/* ioctl() */
+#include <unistd.h>		/* ioctl(), sleep() */
+#include <sys/mman.h>
+
+#include "gfx_common.h"		/* VTS Graphics Test common routines */
+#include "graphicstest.h"
+#include "gfx_vts.h"		/* VTS Graphics Test common routines */
+#include "efb.h"		
+
+void
+box(struct efb_info *pEFB, int x1, int y1, int x2, int y2, unsigned int color)
+{
+	int		tmp;
+	int		width;
+	int		height;
+	unsigned int	v;
+
+	width  = x2 - x1;
+	height = y2 - y1;
+
+	if ((width <= 0) || (height <= 0)) {
+#ifdef DEBUG
+		printf("x1=%d x2=%d y1=%d y2=%d\n", x1, x2, y1, y2);
+#endif
+		return;
+	}
+
+	efb_wait_for_fifo(pEFB, 5);
+
+	REGW(RADEON_DP_WRITE_MASK, 0xffffffff);
+	REGW(RADEON_DP_CNTL,	
+		(RADEON_DST_X_LEFT_TO_RIGHT | RADEON_DST_Y_TOP_TO_BOTTOM));
+
+	REGW(RADEON_DP_BRUSH_FRGD_CLR, color);
+        REGW(DST_Y_X,  x1 << DST_Y_X__DST_X__SHIFT |
+                       y1 << DST_Y_X__DST_Y__SHIFT) ;
+        REGW(DST_WIDTH_HEIGHT,
+              height << DST_WIDTH_HEIGHT__DST_HEIGHT__SHIFT |
+              width << DST_WIDTH_HEIGHT__DST_WIDTH__SHIFT ) ;
+
+}	/* box() */
+
+void
+line(struct efb_info *pEFB,
+	int		x1,
+	int		y1,
+	int		x2,
+	int		y2,
+	unsigned int	color
+	)
+{
+	efb_wait_for_fifo(pEFB, 5);
+
+	REGW(RADEON_DP_WRITE_MASK, 0xffffffff);
+	REGW(RADEON_DP_CNTL,	
+		(RADEON_DST_X_LEFT_TO_RIGHT | RADEON_DST_Y_TOP_TO_BOTTOM));
+
+	REGW(RADEON_DP_BRUSH_FRGD_CLR, color);
+        REGW(DST_LINE_START,  
+		(x1 << DST_LINE_START__DST_START_X__SHIFT | y1 << DST_LINE_START__DST_START_Y__SHIFT));
+        REGW(DST_LINE_END,  
+		(x2 << DST_LINE_END__DST_END_X__SHIFT | y2 << DST_LINE_END__DST_END_Y__SHIFT));
+
+}	/* line() */
+
+#define NBOX 100
+
+void
+draw_cascaded_box(struct efb_info *pEFB, int width, int height)
+{
+	unsigned int	x1;
+	unsigned int	y1;
+	unsigned int	x2;
+	unsigned int	y2;
+	unsigned int	w;
+	unsigned int	h;
+	unsigned int	i, j;
+	unsigned int	k = 0;
+	unsigned int    cinc = 0;
+	unsigned int	xinc, yinc;
+
+	cinc = 256 / NBOX;
+	xinc = width / (NBOX * 2);
+	yinc = height / (NBOX * 2);
+	x1 = y1 = 0;
+
+	for (i = 0; i < NBOX; i++) {
+
+	    x2 = width - x1;
+	    y2 = height - y1;
+
+	    j = i * cinc;
+
+	    k = (j<<24 | j<<16 | j<<8 | j);
+
+	    box(pEFB, x1, y1, x2, y2, k);
+
+	    x1 += xinc;
+	    y1 += yinc;
+	}
+
+}	/* draw_cascaded_box() */
+
+
+#define NLINE 128
+
+void
+draw_lines(struct efb_info *pEFB, int width, int height)
+{
+	unsigned int	x1;
+	unsigned int	y1;
+	unsigned int	x2;
+	unsigned int	y2;
+	int		k;
+	int		i;
+	unsigned int	xinc, yinc;
+
+	xinc = width / NLINE;
+	yinc = height / NLINE;
+	x1 = y1 = 0;
+
+
+	k = 0;
+	x1 = 0;
+	y1 = 0;
+	y2 = height;
+	for (i = 0; i < NLINE; i++) {
+	    k  = 0x00af0000 | (i << 8) | i;
+
+	    x2 = x1;
+
+	    line(pEFB, x1, y1, x2, y2, k);
+	
+	    x1 += xinc;
+	}
+
+	x1 = 0;
+	x2 = width;
+	y1 = 0;
+
+	for (i = 0; i < NLINE; i++) {
+	    k  = 0x00af0000 | (i << 8) | i;
+
+	    y2 = y1;
+
+	    line(pEFB, x1, y1, x2, y2, k);
+
+	    y1 += yinc;
+	}
+}
+
+int
+efb_init_2D(struct efb_info *pEFB)
+{
+	unsigned int pitch_offset;
+	unsigned int pitch;
+	unsigned int offset;
+	unsigned int bytepp;
+	unsigned int gmc_bpp;
+	unsigned int dp_datatype;
+	unsigned int v;
+	int i;
+
+	switch (pEFB->bitsPerPixel) {
+	case 8:
+		gmc_bpp = GMC_DST_8BPP;
+		dp_datatype = DST_8BPP | BRUSH_SOLIDCOLOR | SRC_DSTCOLOR;
+		bytepp = 1;
+		break;
+	case 32:
+		gmc_bpp = GMC_DST_32BPP;
+		dp_datatype = DST_32BPP | BRUSH_SOLIDCOLOR | SRC_DSTCOLOR;
+		bytepp = 4;
+		break;
+	}
+
+	offset = REGR(CRTC_OFFSET) & 0x7ffffff;
+	pitch = REGR(CRTC_PITCH) & 0x7ff;
+
+	pitch = pitch * 8;	// was in groups of 8 pixels
+
+	pitch_offset = 
+		((pitch * bytepp / 64) << 22) |
+		(offset / 1024);
+
+        /*
+         * Initialize GUI engine
+         */
+        efb_wait_for_idle(pEFB);
+
+	efb_wait_for_fifo(pEFB, 5);
+
+
+        REGW(DEFAULT_PITCH_OFFSET, pitch_offset);
+        REGW(RADEON_DST_PITCH_OFFSET, pitch_offset);
+        REGW(RADEON_SRC_PITCH_OFFSET, pitch_offset);
+
+        REGW(DEFAULT_SC_BOTTOM_RIGHT,  
+		(pEFB->screenHeight << 16) |
+		(pEFB->screenWidth));
+
+        v = (
+	    GMC_SRC_PITCH_OFFSET_DEFAULT |
+	    GMC_DST_PITCH_OFFSET_LEAVE |
+	    GMC_SRC_CLIP_DEFAULT	|
+	    GMC_DST_CLIP_DEFAULT	|
+            GMC_BRUSH_SOLIDCOLOR        |
+            gmc_bpp                     |
+            GMC_SRC_DSTCOLOR            |
+            RADEON_ROP3_P               |
+            GMC_WRITE_MASK_LEAVE);
+
+        REGW(RADEON_DP_GUI_MASTER_CNTL,  v);
+
+#ifdef DEBUG
+	printf("v=0x%x\n", v);
+#endif
+}
+
+
+
+
+void
+chip_test(return_packet *rp, int fd)
+{
+        struct efb_info  efb_info;
+        struct efb_info  *pEFB;
+        unsigned int red;
+        unsigned char *fbaddr;
+        int i;
+        int bytepp;
+        int fb_offset, fb_pitch, fb_height, fb_width;
+
+        pEFB = &efb_info;
+        pEFB->fd = fd;
+
+        /*
+         * map the registers & frame buffers memory
+         */
+        if (efb_map_mem(pEFB, rp, GRAPHICS_ERR_CHIP) == -1) {
+            return;
+        }
+
+        /*
+         * initialize efb info
+         */
+        if (efb_init_info(pEFB) == -1) {
+            return;
+        }
+
+	if (efb_init_2D(pEFB) == -1) {
+	    return;
+	}
+
+
+	/* 
+	 * Clear screen 
+	 */
+	box(pEFB, 0, 0, pEFB->screenWidth, pEFB->screenHeight, 0);
+	efb_wait_for_idle(pEFB);
+	efb_flush_pixel_cache(pEFB);
+	sleep(2);
+
+	/*
+	 * line test
+	 */
+	draw_lines(pEFB, pEFB->screenWidth, pEFB->screenHeight);
+	efb_wait_for_idle(pEFB);
+	efb_flush_pixel_cache(pEFB);
+	sleep(1);
+
+	/*
+	 * fill test
+	 */
+	draw_cascaded_box(pEFB, pEFB->screenWidth, pEFB->screenHeight);
+	efb_wait_for_idle(pEFB);
+	efb_flush_pixel_cache(pEFB);
+	sleep(1);
+	efb_wait_for_idle(pEFB);
+	efb_flush_pixel_cache(pEFB);
+
+	/* 
+	 * Clear screen 
+	 */
+	box(pEFB, 0, 0, pEFB->screenWidth, pEFB->screenHeight, 0xff);
+	efb_wait_for_idle(pEFB);
+	efb_flush_pixel_cache(pEFB);
+	sleep(2);
+
+
+done:
+        /*
+         * Unmap the registers & frame buffers memory
+         */
+        if (efb_unmap_mem(pEFB, rp, GRAPHICS_ERR_CHIP) == -1) {
+            return;
+        }
+
+
+	if (close(fd) == -1) {
+	    gfx_vts_set_message(rp, 1, GRAPHICS_ERR_CHIP, "error closing device\n");
+	    return;
+	}
+
+}	/* chip_test() */
+
+
+/* End of chip.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/efb/chip.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,41 @@
+
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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	_CHIP_H
+#define	_CHIP_H
+
+
+#include "libvtsSUNWxfb.h"	/* Common VTS library definitions */
+
+
+void chip_test_reset(void);
+
+void chip_test(return_packet *rp, int fd);
+
+
+#endif	/* _CHIP_H */
+
+
+/* End of chip.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/efb/efb.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 EFB_H
+#define EFB_H
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <sys/mman.h>
+
+#include "gfx_common.h"		/* GFX Common definitions */
+#include "graphicstest.h"
+#include "libvtsSUNWefb.h"	/* Common VTS library definitions */
+
+#include "X11/Xlib.h"
+#include "gfx_vts.h"		/* VTS Graphics Test common routines */
+#include "radeon_reg.h"
+#include "efb_reg.h"
+
+#define EFB_REG_SIZE_LOG2	18
+
+struct pci_info {
+	unsigned long	memBase[6];
+	unsigned long	ioBase[6];
+	unsigned int	type [6];
+	unsigned int	size [6];
+	unsigned int	deviceID;
+};
+
+
+#define READ_MMIO_UINT(addr)		*((unsigned int *)(addr))
+#define WRITE_MMIO_UINT(addr, val)	*((unsigned int *)(addr)) = (val)
+
+#define INREG(offset)		READ_MMIO_UINT(pEFB->MMIOvaddr + (offset))
+#define REGW(offset, value)	WRITE_MMIO_UINT(pEFB->MMIOvaddr + (offset), (value))
+#define REGR(offset)		READ_MMIO_UINT(pEFB->MMIOvaddr + (offset))
+
+typedef unsigned int (*PFNRead32)  (unsigned char *);
+typedef void         (*PFNWrite32) (unsigned char *, unsigned int);
+
+struct efb_info {
+	int		fd;
+
+	int		screenWidth;
+	int		screenHeight;
+	int		screenPitch;
+	int		bitsPerPixel;
+
+	unsigned int	ChipSet;
+
+	unsigned long	FBPhysAddr;
+	unsigned long	MMIOPhysAddr;
+	unsigned long	RelocateIO;
+	unsigned long	fbLocation;
+
+	int		FBMapSize;
+	int		MMIOMapSize;
+
+	unsigned char	*FBvaddr;
+	unsigned char	*MMIOvaddr;
+};
+
+#define PCI_MAP_MEMORY                  0x00000000
+#define PCI_MAP_IO			0x00000001
+
+#define PCI_MAP_MEMORY_TYPE             0x00000007
+#define PCI_MAP_IO_TYPE                 0x00000003
+
+#define PCI_MAP_MEMORY_TYPE_32BIT       0x00000000
+#define PCI_MAP_MEMORY_TYPE_32BIT_1M    0x00000002
+#define PCI_MAP_MEMORY_TYPE_64BIT       0x00000004
+#define PCI_MAP_MEMORY_TYPE_MASK        0x00000006
+#define PCI_MAP_MEMORY_CACHABLE         0x00000008
+#define PCI_MAP_MEMORY_ATTR_MASK        0x0000000e
+#define PCI_MAP_MEMORY_ADDRESS_MASK     0xfffffff0
+
+#define PCI_MAP_IO_ATTR_MASK		0x00000003
+#define PCI_MAP_IS_IO(b)		((b) & PCI_MAP_IO)
+#define PCI_MAP_IO_ADDRESS_MASK		0xfffffffc
+
+#define PCIGETIO(b)			((b) & PCI_MAP_IO_ADDRESS_MASK)
+
+#define PCI_MAP_IS64BITMEM(b)   \
+        (((b) & PCI_MAP_MEMORY_TYPE) == PCI_MAP_MEMORY_TYPE_64BIT)
+
+#define PCIGETMEMORY(b)         	((b) & PCI_MAP_MEMORY_ADDRESS_MASK)
+
+#define PCI_REGION_BASE(_pcidev, _b, _type)             \
+    (((_type) == REGION_MEM) ? (_pcidev)->memBase[(_b)] \
+                             : (_pcidev)->ioBase[(_b)])
+
+int efb_get_pci_info(int fd, struct pci_info *pci_info); 
+int efb_get_mem_info(struct pci_info *pci_info, struct efb_info *pEFB); 
+int efb_map_mem(struct efb_info *pEFB, return_packet *rp, int test);
+int efb_unmap_mem(struct efb_info *pEFB, return_packet *rp, int test);
+int efb_init_info(struct efb_info *);
+
+#endif /* EFB_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/efb/efb_reg.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,367 @@
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 _EFB_REG_H
+#define _EFB_REG_H
+
+#define RADEON_GMC_DST_8BPP				(2 << 8)	
+
+#define GMC_SRC_MONO					0x00000000
+#define GMC_SRC_MONO_LBKGD				0x00001000
+#define GMC_SRC_DSTCOLOR				0x00003000
+#define GMC_WRITE_MASK_LEAVE				0x00000000
+
+#define GMC_SRC_CLIP_DEFAULT				0x00000000
+#define GMC_DST_CLIP_DEFAULT				0x00000000
+#define GMC_SRC_CLIP_LEAVE				0x00000004
+#define GMC_DST_CLIP_LEAVE				0x00000008
+
+#define GMC_SRC_PITCH_OFFSET_DEFAULT			0x00000000
+#define GMC_DST_PITCH_OFFSET_DEFAULT			0x00000000
+#define GMC_SRC_PITCH_OFFSET_LEAVE			0x00000001
+#define GMC_DST_PITCH_OFFSET_LEAVE			0x00000002
+
+#define GMC_BYTE_ORDER_MSB_TO_LSB                  	0x00000000
+
+#define DP_GUI_MASTER_CNTL__GMC_DST_DATATYPE__SHIFT     0x00000008
+
+
+
+#define DST_X_LEFT_TO_RIGHT				0x00000001
+#define DST_Y_TOP_TO_BOTTOM				0x00000002
+#define DST_Y_BOTTOM_TO_TOP				0x00000000
+#define DST_X_RIGHT_TO_LEFT				0x00000000
+
+
+/* CRTC_PITCH */
+#define CRTC_PITCH__CRTC_PITCH_MASK			0x000007ff
+#define CRTC_PITCH__CRTC_PITCH_RIGHT_MASK		0x07ff0000
+
+/* CRTC_H_TOTAL_DISP */
+#define CRTC_H_TOTAL_DISP__CRTC_H_TOTAL_MASK		0x000003ffL
+#define CRTC_H_TOTAL_DISP__CRTC_H_DISP_MASK		0x01ff0000L
+
+/* CRTC_V_TOTAL_DISP */
+#define CRTC_V_TOTAL_DISP__CRTC_V_TOTAL_MASK		0x00000fffL
+#define CRTC_V_TOTAL_DISP__CRTC_V_DISP_MASK		0x0fff0000L
+
+// CRTC_H_TOTAL_DISP
+#define CRTC_H_TOTAL_DISP__CRTC_H_TOTAL__SHIFT		0x00000000
+#define CRTC_H_TOTAL_DISP__CRTC_H_DISP__SHIFT		0x00000010
+
+// CRTC_V_TOTAL_DISP
+#define CRTC_V_TOTAL_DISP__CRTC_V_TOTAL__SHIFT		0x00000000
+#define CRTC_V_TOTAL_DISP__CRTC_V_DISP__SHIFT		0x00000010
+
+
+// DEFAULT_PITCH_OFFSET
+#define DEFAULT_PITCH_OFFSET__DEFAULT_OFFSET__SHIFT	0x00000000
+#define DEFAULT_PITCH_OFFSET__DEFAULT_PITCH__SHIFT	0x00000016
+#define DEFAULT_PITCH_OFFSET__DEFAULT_TILE__SHIFT	0x0000001e
+
+#define DEFAULT_PITCH_OFFSET__DEFAULT_OFFSET_MASK       0x003fffffL
+#define DEFAULT_PITCH_OFFSET__DEFAULT_PITCH_MASK        0x3fc00000L
+#define DEFAULT_PITCH_OFFSET__DEFAULT_TILE_MASK         0xc0000000L
+
+
+// SRC_PITCH_OFFSET
+#define SRC_PITCH_OFFSET__SRC_OFFSET__SHIFT             0x00000000
+#define SRC_PITCH_OFFSET__SRC_PITCH__SHIFT              0x00000016
+#define SRC_PITCH_OFFSET__SRC_TILE__SHIFT               0x0000001e
+
+// DST_PITCH_OFFSET
+#define DST_PITCH_OFFSET__DST_OFFSET__SHIFT             0x00000000
+#define DST_PITCH_OFFSET__DST_PITCH__SHIFT              0x00000016
+#define DST_PITCH_OFFSET__DST_TILE__SHIFT               0x0000001e
+
+
+// DEFAULT_SC_BOTTOM_RIGHT
+#define DEFAULT_SC_BOTTOM_RIGHT__DEFAULT_SC_RIGHT__SHIFT   0x00000000
+#define DEFAULT_SC_BOTTOM_RIGHT__DEFAULT_SC_BOTTOM__SHIFT  0x00000010
+
+// SRC_SC_BOTTOM_RIGHT
+#define SRC_SC_BOTTOM_RIGHT__SC_RIGHT__SHIFT            0x00000000
+#define SRC_SC_BOTTOM_RIGHT__SC_BOTTOM__SHIFT           0x00000010
+
+/* CRTC_GEN_CNTL */
+#define CRTC_GEN_CNTL__CRTC_DBL_SCAN_EN_MASK		0x00000001L
+#define CRTC_GEN_CNTL__CRTC_DBL_SCAN_EN			0x00000001L
+#define CRTC_GEN_CNTL__CRTC_INTERLACE_EN_MASK		0x00000002L
+#define CRTC_GEN_CNTL__CRTC_INTERLACE_EN		0x00000002L
+#define CRTC_GEN_CNTL__CRTC_C_SYNC_EN_MASK		0x00000010L
+#define CRTC_GEN_CNTL__CRTC_C_SYNC_EN			0x00000010L
+#define CRTC_GEN_CNTL__CRTC_PIX_WIDTH_MASK		0x00000f00L
+#define CRTC_GEN_CNTL__CRTC_MODE9_COLOR_ORDER_MASK	0x00001000L
+#define CRTC_GEN_CNTL__CRTC_MODE9_COLOR_ORDER		0x00001000L
+#define CRTC_GEN_CNTL__CRTC_ICON_EN_MASK		0x00008000L
+#define CRTC_GEN_CNTL__CRTC_ICON_EN			0x00008000L
+#define CRTC_GEN_CNTL__CRTC_CUR_EN_MASK			0x00010000L
+#define CRTC_GEN_CNTL__CRTC_CUR_EN			0x00010000L
+#define CRTC_GEN_CNTL__CRTC_VSTAT_MODE_MASK		0x00060000L
+#define CRTC_GEN_CNTL__CRTC_CUR_MODE_MASK		0x00700000L
+#define CRTC_GEN_CNTL__CRTC_EXT_DISP_EN_MASK		0x01000000L
+#define CRTC_GEN_CNTL__CRTC_EXT_DISP_EN			0x01000000L
+#define CRTC_GEN_CNTL__CRTC_EN_MASK			0x02000000L
+#define CRTC_GEN_CNTL__CRTC_EN				0x02000000L
+#define CRTC_GEN_CNTL__CRTC_DISP_REQ_EN_B_MASK		0x04000000L
+#define CRTC_GEN_CNTL__CRTC_DISP_REQ_EN_B		0x04000000L
+
+#define CRTC_GEN_CNTL__CRTC_DBL_SCAN_EN__SHIFT		0x00000000
+#define CRTC_GEN_CNTL__CRTC_INTERLACE_EN__SHIFT		0x00000001
+#define CRTC_GEN_CNTL__CRTC_C_SYNC_EN__SHIFT		0x00000004
+#define CRTC_GEN_CNTL__CRTC_PIX_WIDTH__SHIFT		0x00000008
+#define CRTC_GEN_CNTL__CRTC_MODE9_COLOR_ORDER__SHIFT	0x0000000c
+#define CRTC_GEN_CNTL__CRTC_ICON_EN__SHIFT		0x0000000f
+#define CRTC_GEN_CNTL__CRTC_CUR_EN__SHIFT		0x00000010
+#define CRTC_GEN_CNTL__CRTC_VSTAT_MODE__SHIFT		0x00000011
+#define CRTC_GEN_CNTL__CRTC_CUR_MODE__SHIFT		0x00000014
+#define CRTC_GEN_CNTL__CRTC_EXT_DISP_EN__SHIFT		0x00000018
+#define CRTC_GEN_CNTL__CRTC_EN__SHIFT			0x00000019
+#define CRTC_GEN_CNTL__CRTC_DISP_REQ_EN_B__SHIFT	0x0000001a
+
+/* PALETTE_INDEX */
+#define PALETTE_INDEX__PALETTE_W_INDEX_MASK		0x000000ffL
+#define PALETTE_INDEX__PALETTE_R_INDEX_MASK		0x00ff0000L
+
+/* PALETTE_DATA */
+#define PALETTE_DATA__PALETTE_DATA_B_MASK		0x000000ffL
+#define PALETTE_DATA__PALETTE_DATA_G_MASK		0x0000ff00L
+#define PALETTE_DATA__PALETTE_DATA_R_MASK		0x00ff0000L
+
+/* PALETTE_30_DATA */
+#define PALETTE_30_DATA__PALETTE_DATA_B_MASK		0x000003ffL
+#define PALETTE_30_DATA__PALETTE_DATA_G_MASK		0x000ffc00L
+#define PALETTE_30_DATA__PALETTE_DATA_R_MASK		0x3ff00000L
+
+// PALETTE_INDEX
+#define PALETTE_INDEX__PALETTE_W_INDEX__SHIFT		0x00000000
+#define PALETTE_INDEX__PALETTE_R_INDEX__SHIFT		0x00000010
+
+// PALETTE_DATA
+#define PALETTE_DATA__PALETTE_DATA_B__SHIFT		0x00000000
+#define PALETTE_DATA__PALETTE_DATA_G__SHIFT		0x00000008
+#define PALETTE_DATA__PALETTE_DATA_R__SHIFT		0x00000010
+
+// PALETTE_30_DATA
+#define PALETTE_30_DATA__PALETTE_DATA_B__SHIFT		0x00000000
+#define PALETTE_30_DATA__PALETTE_DATA_G__SHIFT		0x0000000a
+#define PALETTE_30_DATA__PALETTE_DATA_R__SHIFT		0x00000014
+
+/* DP_DATATYPE bit constants */
+#define DST_8BPP					0x00000002
+#define DST_15BPP					0x00000003
+#define DST_16BPP					0x00000004
+#define DST_24BPP					0x00000005
+#define DST_32BPP					0x00000006
+#define DST_8BPP_RGB332					0x00000007
+#define DST_8BPP_Y8					0x00000008
+#define DST_8BPP_RGB8					0x00000009
+#define DST_16BPP_VYUY422				0x0000000b
+#define DST_16BPP_YVYU422				0x0000000c
+#define DST_32BPP_AYUV444				0x0000000e
+#define DST_16BPP_ARGB4444				0x0000000f
+#define BRUSH_8x8MONO					0x00000000
+#define BRUSH_8x8MONO_LBKGD				0x00000100
+#define GMC_DST_8BPP					0x00000200
+#define GMC_DST_15BPP					0x00000300
+#define GMC_DST_16BPP					0x00000400
+#define GMC_DST_24BPP					0x00000500
+#define GMC_DST_32BPP					0x00000600
+
+#define GMC_BRUSH_SOLIDCOLOR				0x000000d0
+#define GMC_SRC_DSTCOLOR				0x00003000
+#define GMC_DP_SRC_RECT					0x02000000
+#define GMC_DST_CLR_CMP_FCN_CLEAR			0x10000000
+#define GMC_WRITE_MASK_SET				0x40000000
+
+#define ROP3_P						0x00f00000
+#define ROP3_PATCOPY               			0x00f00000
+
+
+// Registers from BIF block
+
+#define CRTC_GEN_CNTL					0x050
+#define CRTC_EXT_CNTL					0x054
+#define CRTC2_GEN_CNTL					0x3F8			
+
+// Registers from DISPLAY block
+
+#define GPIO_DDC1					0x60
+#define GPIO_DDC2					0x64
+#define GPIO_DDC3					0x68
+#define PALETTE_INDEX					0xB0
+#define PALETTE_DATA					0xB4
+#define PALETTE_30_DATA					0xB8
+#define DAC_CNTL2					0x7C
+
+#define CRTC_H_TOTAL_DISP				0x200
+#define CRTC_H_SYNC_STRT_WID				0x204
+#define CRTC_V_TOTAL_DISP				0x208
+#define CRTC_V_SYNC_STRT_WID				0x20C
+#define CRTC_VLINE_CRNT_VLINE				0x210
+#define CRTC_CRNT_FRAME					0x214
+#define CRTC_GUI_TRIG_VLINE				0x218
+#define CRTC_DEBUG					0x21C
+#define CRTC_OFFSET_RIGHT				0x220
+#define CRTC_OFFSET					0x224
+#define CRTC_OFFSET_CNTL				0x228
+#define CRTC_PITCH					0x22C
+#define DISPLAY_BASE_ADDR				0x23C
+
+#define CRTC2_H_TOTAL_DISP				0x300
+#define CRTC2_H_SYNC_STRT_WID				0x304
+#define CRTC2_V_TOTAL_DISP				0x308
+#define CRTC2_V_SYNC_STRT_WID				0x30C
+#define CRTC2_VLINE_CRNT_VLINE				0x310
+#define CRTC2_CRNT_FRAME				0x314
+#define CRTC2_GUI_TRIG_VLINE				0x318
+#define CRTC2_DEBUG					0x31C
+#define CRTC2_OFFSET_RIGHT				0x320
+#define CRTC2_OFFSET					0x324
+#define CRTC2_OFFSET_CNTL				0x328
+#define CRTC2_PITCH					0x32C
+
+
+
+// Registers from E2 block
+
+#define DST_OFFSET					0x1404
+#define DST_PITCH					0x1408
+#define DST_TILE					0x1700
+#define DST_PITCH_OFFSET				0x142C
+#define DST_X						0x141C
+#define DST_Y						0x1420
+#define DST_X_Y						0x1594
+#define DST_Y_X						0x1438
+#define DST_WIDTH					0x140C
+#define DST_HEIGHT					0x1410
+#define DST_WIDTH_HEIGHT				0x1598
+#define DST_HEIGHT_WIDTH				0x143C
+#define DST_HEIGHT_WIDTH_8				0x158C
+#define DST_HEIGHT_Y					0x15A0
+#define DST_WIDTH_X					0x1588
+#define DST_WIDTH_X_INCY				0x159C
+#define DST_LINE_START					0x1600
+#define DST_LINE_END					0x1604
+#define DST_LINE_PATCOUNT				0x1608
+#define DP_DST_ENDIAN					0x15D0
+#define DEFAULT_PITCH_OFFSET				0x16E0
+#define DEFAULT_SC_BOTTOM_RIGHT				0x16E8
+#define SRC_OFFSET					0x15AC
+#define SRC_PITCH					0x15B0
+#define SRC_TILE					0x1704
+#define SRC_PITCH_OFFSET				0x1428
+#define SRC_X						0x1414
+#define SRC_Y						0x1418
+#define SRC_X_Y						0x1590
+#define SRC_Y_X						0x1434
+#define SRC_CLUT_ADDRESS				0x1780
+#define SRC_CLUT_DATA					0x1784
+#define SRC_CLUT_DATA_RD				0x1788
+#define DP_CNTL						0x16C0
+#define DP_CNTL_XDIR_YDIR_YMAJOR			0x16D0
+#define DP_DATATYPE					0x16C4
+#define DP_MIX						0x16C8
+#define DP_WRITE_MSK					0x16CC
+#define DP_XOP						0x17F8
+#define CLR_CMP_CLR_SRC					0x15C4
+#define CLR_CMP_CLR_DST					0x15C8
+#define CLR_CMP_CNTL					0x15C0
+#define CLR_CMP_MSK					0x15CC
+#define DSTCACHE_MODE					0x1710
+#define DSTCACHE_CTLSTAT				0x1714
+
+
+// DST_Y_X
+#define DST_Y_X__DST_X__SHIFT                           0x00000000
+#define DST_Y_X__DST_Y__SHIFT                           0x00000010
+
+// DST_WIDTH_HEIGHT
+#define DST_WIDTH_HEIGHT__DST_HEIGHT__SHIFT             0x00000000
+#define DST_WIDTH_HEIGHT__DST_WIDTH__SHIFT              0x00000010
+
+// DST_LINE_START
+#define DST_LINE_START__DST_START_X__SHIFT              0x00000000
+#define DST_LINE_START__DST_START_Y__SHIFT              0x00000010
+
+// DST_LINE_END
+#define DST_LINE_END__DST_END_X__SHIFT                  0x00000000
+#define DST_LINE_END__DST_END_Y__SHIFT                  0x00000010
+
+
+
+/* DAC_CNTL2 */
+#define DAC_CNTL2__PALETTE_ACCESS_CNTL_MASK		0x00000020L
+#define DAC_CNTL2__PALETTE_ACCESS_CNTL			0x00000020L
+
+
+// Registers from RBBM block
+
+#define RBBM_GUICNTL					0x172C
+#define RBBM_STATUS					0xE40
+#define RBBM_CNTL					0xEC
+#define RBBM_SOFT_RESET					0xF0
+
+// RBBM_SOFT_RESET
+
+#define RBBM_SOFT_RESET__SOFT_RESET_CP_MASK		0x00000001L
+#define RBBM_SOFT_RESET__SOFT_RESET_CP			0x00000001L
+#define RBBM_SOFT_RESET__SOFT_RESET_E2_MASK		0x00000020L
+#define RBBM_SOFT_RESET__SOFT_RESET_E2			0x00000020L
+
+/* RBBM_STATUS */
+#define RBBM_STATUS__CMDFIFO_AVAIL_MASK			0x0000007fL
+
+#define GUI_ACTIVE					0x80000000
+
+
+// Registers from MC block
+
+#define MC_FB_LOCATION					0x148
+
+// Registers from HDP block
+
+#define HOST_PATH_CNTL					0x130
+
+
+#define RB3D_CNTL					0x1C3C
+
+
+/* defines for Coherent Console stuff for S11 and above */
+#define SRC_DSTCOLOR					0x00030000
+#define DP_SRC_RECT					0x00000200
+#define ROP3_SRCCOPY					0x00cc0000
+#define BRUSH_SOLIDCOLOR				0x00000d00
+
+#define DDC_DATA_OUTPUT					0x00000001
+#define DDC_CLK_OUTPUT					0x00000002
+#define DDC_DATA_INPUT					0x00000100
+#define DDC_CLK_INPUT					0x00000200
+#define DDC_DATA_OUT_EN					0x00010000
+#define DDC_CLK_OUT_EN					0x00020000
+
+#define DDC_DATA_INPUT_SHIFT				0x00000008
+#define DDC_CLK_INPUT_SHIFT				0x00000009
+
+
+#endif /* _EFB_REG_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/efb/libvtsSUNWefb.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,530 @@
+/*
+ * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 <sys/types.h>
+#include <sys/param.h>		/* MAXPATHLEN */
+#include <errno.h>
+#include <pwd.h>		/* getpwuid() */
+#include <signal.h>
+#include <stdio.h>		/* snprintf() */
+#include <stdlib.h>		/* exit(), malloc() */
+#include <string.h>		/* strcat(), strcpy() */
+#include <unistd.h>		/* sleep() */
+#include <sys/fbio.h>
+#include <sys/mman.h>
+#include <sys/systeminfo.h>	/* sysinfo() */
+#include <sys/visual_io.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+#include "graphicstest.h"
+#include "gfx_vts.h"		/* VTS Graphics Test common routines */
+
+#include "libvtsSUNWefb.h"	/* VTS library definitions for efb device */
+
+
+#if (0)	/* Unused */
+#define	NO_DMA			0
+#define	USE_DMA			1
+#endif
+
+#define	MAX_DISPLAY_LEN		261
+
+
+static int		no_window = 1;
+static gfxtest_info	*tests_info;
+static int		received_control_c = 0;
+static int		need_screen_lock = 1;
+static Display		*dpy = NULL;
+
+
+/* Declarations needed for get_tests() */
+
+static unsigned int efb_mask_list[] = {
+	GRAPHICS_TEST_OPEN,
+	GRAPHICS_TEST_DMA,
+	GRAPHICS_TEST_MEM,
+	GRAPHICS_TEST_CHIP
+};
+
+static unsigned int efb_mesg_list[] = {
+	GRAPHICS_TEST_OPEN_MESG,
+	GRAPHICS_TEST_DMA_MESG,
+	GRAPHICS_TEST_MEM_MESG,
+	GRAPHICS_TEST_CHIP_MESG
+};
+
+static gfxtest_function efb_test_list[] = {
+	efb_test_open,
+	efb_test_dma,
+	efb_test_memory,
+	efb_test_chip
+};
+
+
+static void
+disable_pm(Display *dpy)
+{
+	int		dummy;
+
+	XSetScreenSaver(dpy, 0, 0, 0, 0);
+	if (DPMSQueryExtension(dpy, &dummy, &dummy)) {
+	    DPMSDisable(dpy);
+	}
+	if (FBPMQueryExtension(dpy, &dummy, &dummy)) {
+	    FBPMDisable(dpy);
+	}
+
+}	/* disable_pm() */
+
+
+int
+lock_display(int fd, Display** current_display)
+{
+	char		env_buf[5 + MAXPATHLEN]; /* "HOME=<pw_dir>" */
+	int		i;
+	int		screen;
+	Display		*dpy;
+	Window		win;
+	XSetWindowAttributes xswa;
+	char		hostname[MAX_DISPLAY_LEN];
+	char		display[MAX_DISPLAY_LEN];
+	struct sigaction act;
+	int		current_screen;
+	struct hostent	*Host;
+	struct passwd	*pw_entry;
+	int		status;
+	char		no_bits[] = { 0 };
+	XColor		dumcolor;
+	Pixmap		lockc;
+	Pixmap		lockm;
+	Cursor		cursor;
+
+	pw_entry = getpwuid(0);
+	if (strlen(pw_entry->pw_dir) >= MAXPATHLEN) {
+	    TraceMessage(VTS_DEBUG, __func__,
+			    "HOME= directory path is too long\n");
+	    return (1);
+	}
+	strcpy(env_buf, "HOME=");
+	strcat(env_buf, pw_entry->pw_dir);
+	if (putenv(env_buf) != 0) {
+	    TraceMessage(VTS_DEBUG, __func__,
+			    "putenv( HOME= ) failed, errno:%d\n", errno);
+	    return (1);
+	}
+
+	dpy = NULL;
+
+	if (gfx_vts_debug_mask & GRAPHICS_VTS_SLOCK_OFF) {
+	    TraceMessage(VTS_DEBUG, __func__, "lock_display() DISABLED\n");
+	    need_screen_lock = 0;
+	    *current_display = NULL;
+	    return (0);
+	}
+
+	current_screen = 0;
+
+	TraceMessage(VTS_DEBUG, __func__, "locking X screen %d\n",
+		    current_screen);
+
+#if (0)
+	/* Get the host machine name */
+	if (sysinfo(SI_HOSTNAME, hostname, MAX_DISPLAY_LEN) == -1) {
+	    TraceMessage(VTS_DEBUG, __func__,
+			"sysinfo(2) failed getting hostname\n");
+	    hostname[0] = '\0';
+	}
+#else
+	hostname[0] = '\0';
+#endif
+
+	snprintf(display, sizeof (display), "%s:0.%d",
+		hostname, current_screen);
+	dpy = XOpenDisplay(display);
+	TraceMessage(VTS_DEBUG, __func__,
+		    "XOpenDisplay, display = %s, dpy = 0x%p\n", display, dpy);
+
+	if (dpy == NULL) {
+	    TraceMessage(VTS_DEBUG, __func__, "Assuming no window_system\n");
+	    return (0);
+	}
+
+	TraceMessage(VTS_DEBUG, __func__,
+		    "XOpenDisplay successful, display = %s, dpy = 0x%p\n",
+		    display, dpy);
+
+	screen = DefaultScreen(dpy);
+
+	/*
+	 * Flush request buffer and wait for all requests to be processed
+	 */
+	XSync(dpy, False);
+
+	/* Tell server to report events as they occur */
+	XSynchronize(dpy, True);
+
+	disable_pm(dpy);
+
+	/* Create a blank cursor */
+	lockc = XCreateBitmapFromData(dpy, RootWindow(dpy, 0),
+					no_bits, 1, 1);
+	lockm = XCreateBitmapFromData(dpy, RootWindow(dpy, 0),
+					no_bits, 1, 1);
+	cursor = XCreatePixmapCursor(dpy, lockc, lockm, &dumcolor,
+					&dumcolor, 0, 0);
+
+	XFreePixmap(dpy, lockc);
+	XFreePixmap(dpy, lockm);
+
+	xswa.cursor = cursor;
+	xswa.override_redirect = True;
+	xswa.event_mask = (KeyPressMask | KeyReleaseMask | ExposureMask);
+	no_window = 0;
+	win = XCreateWindow(dpy,
+			    RootWindow(dpy, screen),
+			    0, 0,
+			    DisplayWidth(dpy, current_screen),
+			    DisplayHeight(dpy, current_screen),
+			    0,
+			    CopyFromParent,
+			    InputOutput,
+			    CopyFromParent,
+			    CWOverrideRedirect | CWEventMask, &xswa);
+
+	TraceMessage(VTS_DEBUG, __func__, " XCreateWindow win=%d\n", win);
+
+	XMapWindow(dpy, win);
+	XRaiseWindow(dpy, win);
+	TraceMessage(VTS_DEBUG, __func__, " no_window=%d\n", no_window);
+
+	if (!no_window) {
+	    /* Disable server from handling any requests */
+	    XGrabServer(dpy);
+	    /* Gain control of keyboard */
+	    status = XGrabKeyboard(dpy, win, False, GrabModeAsync,
+				   GrabModeAsync, CurrentTime);
+
+	    if (status != GrabSuccess) {
+		TraceMessage(VTS_DEBUG, __func__,
+			    "Cannot gain control of keyboard\n");
+	    }
+
+	    status = XGrabPointer(dpy,
+				win,
+				False,
+				ResizeRedirectMask,
+				GrabModeAsync,
+				GrabModeAsync,
+				None,
+				cursor,
+				CurrentTime);
+	    if (status != GrabSuccess) {
+		TraceMessage(VTS_DEBUG, __func__,
+			    "Cannot gain control of pointer\n");
+	    }
+	}
+
+	sleep(4);
+	*current_display = dpy;
+	return (0);
+
+}	/* lock_display() */
+
+void
+unlock_display(Display *dpy)
+{
+	if (dpy) {
+		XUngrabPointer(dpy, CurrentTime);
+		XUngrabKeyboard(dpy, CurrentTime);
+		XUngrabServer(dpy);
+	}
+}
+
+
+/* *** PUBLIC *** */
+
+/* These library functions are public and are expected to exist */
+
+int
+get_tests(gfxtest_info *tests)
+{
+	return_packet *efb_test_open(int fd);
+
+	/*
+	 * Set the gfx_vts_debug_mask bits according to environment variables
+	 */
+	gfx_vts_set_debug_mask();
+
+	/*
+	 * Disable screen lock by default
+	 */
+	gfx_vts_debug_mask |= GRAPHICS_VTS_SLOCK_OFF;
+
+	/*
+	 * Construct the list of tests to be performed
+	 */
+	tests->count = sizeof (efb_test_list) / sizeof (gfxtest_function);
+	tests->this_test_mask = (int *)malloc(sizeof (efb_mask_list));
+	tests->this_test_mesg = (int *)malloc(sizeof (efb_mesg_list));
+	tests->this_test_function =
+			(gfxtest_function *)malloc(sizeof (efb_test_list));
+
+	if ((tests->this_test_mask     == NULL) ||
+	    (tests->this_test_mesg     == NULL) ||
+	    (tests->this_test_function == NULL)) {
+	    gfx_vts_free_tests(tests);
+	    return (GRAPHICS_ERR_MALLOC_FAIL);
+	}
+
+	tests->connection_test_function = efb_test_open;
+
+	memcpy(tests->this_test_mask, efb_mask_list, sizeof (efb_mask_list));
+	memcpy(tests->this_test_mesg, efb_mesg_list, sizeof (efb_mesg_list));
+	memcpy(tests->this_test_function, efb_test_list,
+						sizeof (efb_test_list));
+
+	tests_info = tests;
+	return (0);
+
+}	/* get_tests() */
+
+
+int
+cleanup_tests(gfxtest_info *tests)
+{
+
+	TraceMessage(VTS_DEBUG, __func__, "call cleanup_tests\n");
+	gfx_vts_free_tests(tests);
+
+	if (need_screen_lock) {
+	    unlock_display(dpy);
+	}
+
+}	/* cleanup_tests() */
+
+
+/*
+ * efb_test_open()
+ *
+ *    This test will open the device, read and write some registers
+ *    after mmaping in the register and frame buffer spaces.
+ */
+
+return_packet *
+efb_test_open(int fd)
+{
+	static return_packet rp;
+	int		rc = 0;
+	struct vis_identifier vis_identifier;
+
+	if (need_screen_lock) {
+	    lock_display(fd, &dpy);
+	}
+
+	/* setup */
+	memset(&rp, 0, sizeof (return_packet));
+
+	if (gfx_vts_check_fd(fd, &rp)) {
+	    return (&rp);
+	}
+
+	TraceMessage(VTS_TEST_STATUS, __func__, "check_fd passed.\n");
+
+	/* vis identifier will do this */
+	rc = ioctl(fd, VIS_GETIDENTIFIER, &vis_identifier);
+
+	TraceMessage(VTS_TEST_STATUS, __func__, "rc = %d\n", rc);
+
+	if (rc != 0) {
+	    gfx_vts_set_message(&rp, 1, GRAPHICS_ERR_OPEN, NULL);
+	    return (&rp);
+	}
+
+	if (strncmp(vis_identifier.name, "SUNWefb", 7) != 0) {
+	    gfx_vts_set_message(&rp, 1, GRAPHICS_ERR_OPEN, NULL);
+	    return (&rp);
+	}
+
+	map_me(&rp, fd);
+
+	TraceMessage(VTS_DEBUG, __func__, "Open completed OK\n");
+
+	check4abort(dpy);
+	return (&rp);
+
+}	/* efb_test_open() */
+
+
+/*
+ * efb_test_dma
+ *
+ *    This test will open the device, allocate the dma buffers to
+ *    separate memory spaces, and read/write the data, verifying it.
+ */
+
+return_packet *
+efb_test_dma(int fd)
+{
+	static return_packet rp;
+	int		i;
+
+	TraceMessage(VTS_DEBUG, __func__, "Not a DMA device\n");
+
+	check4abort(dpy);
+	return (&rp);
+
+}	/* efb_test_dma() */
+
+
+/*
+ * efb_test_memory()
+ *
+ *    This test will open the device and read and write to all memory
+ *    addresses.
+ */
+
+return_packet *
+efb_test_memory(int fd)
+{
+	static return_packet rp;
+
+	TraceMessage(VTS_DEBUG, __func__, " efb_test_memory running\n");
+
+	if (gfx_vts_debug_mask & GRAPHICS_VTS_MEM_OFF) {
+	    return (&rp);
+	}
+
+	if (need_screen_lock) {
+	    lock_display(fd, &dpy);
+	}
+
+	memory_test(&rp, fd);
+
+	TraceMessage(VTS_DEBUG, __func__, " efb_test_memory completed\n");
+
+	sleep(2);
+
+	check4abort(dpy);
+	return (&rp);
+
+}	/* efb_test_memory() */
+
+
+/*
+ * efb_test_chip()
+ *
+ *    Test Chip, functional tests.
+ */
+
+return_packet *
+efb_test_chip(int fd)
+{
+	static return_packet rp;
+
+	if (gfx_vts_debug_mask & GRAPHICS_VTS_CHIP_OFF) {
+	    return (&rp);
+	}
+	TraceMessage(VTS_DEBUG, __func__, " efb_test_chip running\n");
+
+	if (need_screen_lock) {
+	    lock_display(fd, &dpy);
+	}
+
+	chip_test(&rp, fd);
+
+	TraceMessage(VTS_DEBUG, __func__, " efb_test_chip completed\n");
+
+	sleep(2);
+
+	check4abort(dpy);
+	return (&rp);
+
+}	/* efb_test_chip() */
+
+
+void
+graphicstest_finish(int flag)
+{
+
+	TraceMessage(VTS_DEBUG, __func__, "call graphicstest_finish\n");
+
+	TraceMessage(VTS_DEBUG, __func__, "call reset_memory_state\n");
+
+	cleanup_tests(tests_info);
+
+	exit(0);
+
+}	/* graphicstest_finish() */
+
+
+/*
+ * check4abort()
+ *
+ *    This function sends a KILL signal to the program if it detects
+ *    that the user has pressed ^C.  This functionality is usually
+ *    performed by the Command Tool which spawned a program, but in this
+ *    case we need to do it because we have grabbed all keyboard events.
+ *    It should be called anywhere where it's safe to end the program.
+ */
+
+void
+check4abort(Display *dpy)
+{
+#define	CTRL_C	'\003'			/* Ctrl-C (^C) */
+
+	/*
+	 * If necessary, restore the original state following a test
+	 */
+#if !defined(VTS_STUBS)
+	chip_test_reset();
+#endif
+
+	if (dpy != NULL) {
+#if !defined(VTS_STUBS)
+	    while (XPending(dpy)) {
+		XEvent	event;		/* Key event structure */
+		int	i;		/* Loop counter / keystr[] index */
+		char	keystr[5] = "";	/* Buffer for returned string */
+		int	len;		/* Length of returned string */
+
+		XNextEvent(dpy, &event);
+		if (event.type == KeyPress) {
+		    len = XLookupString((XKeyEvent *)&event,
+					keystr, sizeof (keystr),
+					NULL, NULL);
+		    for (i = 0; i < len; i++) {
+			if (keystr[i] == CTRL_C) {
+			    kill(getpid(), SIGINT);
+			    graphicstest_finish(0);
+			}
+		    }
+		}
+	    }
+#endif	/* VTS_STUBS */
+	}
+
+}	/* check4abort() */
+
+
+/* End of libvtsSUNWefb.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/efb/libvtsSUNWefb.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,56 @@
+
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 _LIBVTSSUNWEFB_H
+#define	_LIBVTSSUNWEFB_H
+
+
+#include "libvtsSUNWxfb.h"	/* Common VTS library definitions */
+
+
+/* Test Open, initialization & read back; basic ability to talk to device */
+return_packet *efb_test_open(int fd);
+
+/* Test DMA, read/write via dma, memory and, chip tests will use DMA */
+return_packet *efb_test_dma(int fd);
+
+/* Test Memory, various address, data, and, random patterns */
+return_packet *efb_test_memory(int fd);
+
+/* Test Chip, functional tests */
+return_packet *efb_test_chip(int fd);
+
+void check4abort();
+int get_processHandle(int, void **);
+
+extern int backup_clut_init;
+extern struct fbcmap backup_clut;
+extern int myfd;
+
+
+#endif	/* _LIBVTSSUNWEFB_H */
+
+
+/* End of libvtsSUNWefb.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/efb/mapfile	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,7 @@
+SUNW_1.1 {
+		global:
+			get_tests;
+			cleanup_tests;
+		local:
+				*;
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/efb/mapper.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,71 @@
+
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 <sys/types.h>
+#include <stdio.h>
+#include <sys/mman.h>
+
+#include "gfx_common.h"		/* GFX Common definitions */
+#include "graphicstest.h"
+#include "libvtsSUNWefb.h"	/* Common VTS library definitions */
+
+#include "X11/Xlib.h"
+#include "gfx_vts.h"		/* VTS Graphics Test common routines */
+#include "efb.h"
+
+
+/*
+ * map_me()
+ */
+
+void
+map_me(return_packet *rp, int fd)
+{
+	struct efb_info  efb_info;
+	struct efb_info  *pEFB;
+	unsigned int	 value, chipType;
+	
+
+	pEFB = &efb_info;
+	pEFB->fd = fd;
+
+	/*
+	 * map the registers & frame buffers memory
+	 */
+	if (efb_map_mem(pEFB, rp, GRAPHICS_ERR_OPEN) == -1) {
+	    return;
+	}
+
+done:
+	/*
+	 * Unmap the registers & frame buffers memory
+	 */
+	if (efb_unmap_mem(pEFB, rp, GRAPHICS_ERR_OPEN) == -1) {
+	    return;
+	}
+
+}	/* map_me() */
+
+
+/* End of mapper.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/efb/memory.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,353 @@
+
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 <sys/types.h>
+#include <errno.h>		/* errno */
+#include <stdio.h>
+#include <string.h>		/* strerror() */
+#include <stropts.h>		/* ioctl() */
+#include <unistd.h>		/* ioctl() */
+#include <sys/mman.h>
+#include <stdlib.h>
+
+#include "gfx_common.h"
+#include "graphicstest.h"
+#include "libvtsSUNWxfb.h"	/* Common VTS library definitions */
+#include "gfx_vts.h"		/* VTS Graphics Test common routines */
+#include "efb.h"
+
+typedef union MemType {
+	uint64_t	val[8];
+	uint32_t	word[16];
+	uint16_t	halfwd[32];
+	uint8_t		byte[64];
+} MemType;
+
+static const int access_mode[] = {
+	1, 2, 4, 8, 0
+};
+
+static const char *const access_tname[] = {
+	"\tverifying byte access mode...",
+	"\tverifying short access mode...",
+	"\tverifying word access mode...",
+	"\tverifying long long access mode...",
+};
+
+void
+Write8(void *addr, uint8_t data) {
+	*(uint8_t *)addr = data;
+}
+
+void
+Write16(void *addr, uint16_t data) {
+	*(uint16_t *)addr = data;
+}
+
+void
+Write32(void *addr, uint32_t data) {
+	*(uint32_t *)addr = data;
+}
+
+void
+Write64(void *addr, uint64_t data) {
+	*(uint64_t *)addr = data;
+}
+
+uint8_t
+read8(void *addr) {
+	return (*(uint8_t *)addr);
+}
+
+uint16_t
+read16(void *addr) {
+	return (*(uint16_t *)addr);
+}
+
+uint32_t
+read32(void *addr) {
+	return (*(uint32_t *)addr);
+}
+
+uint64_t
+read64(void *addr) {
+	return (*(uint64_t *)addr);
+}
+
+
+u_int
+test_data() {
+	u_int ret;
+
+	ret = (u_int)mrand48();
+	return (ret);
+}
+
+MemType *data;
+MemType *cdata;
+
+
+void
+plane_change(int num_planes_, caddr_t base_, int sh, int sw)
+{
+	int		num_planes = num_planes_;
+	caddr_t		base = base_;
+	int		i;
+	int		j;
+
+	int pix_per_write, old_pix_per_write;
+
+	/* Get memory to store data */
+
+	int memcount = num_planes * 8;
+
+	if (data)  free(data);
+	if (cdata) free(cdata);
+
+	data  = (MemType *)memalign(64, memcount * sizeof (MemType));
+	cdata = (MemType *)memalign(64, memcount * sizeof (MemType));
+
+	/* Write data to memory */
+	for (i = 0; i < memcount; i++) {
+	    for (j = 0; j < 8; j++) {
+		/* Figure out the value to write */
+		data[i].val[j] = ((unsigned long long)test_data() << 32)
+					| test_data();
+		cdata[i].val[j] = ~data[i].val[j];
+	    }
+	}
+
+}	/* plane_change() */
+
+
+boolean_t
+write_read(int xoff, int yoff, boolean_t complement, int access_mode,
+	boolean_t pass, int fb_pitch, int bytepp, caddr_t base)
+{
+	MemType		*dp;
+	int		pitch = fb_pitch;
+	int		x;
+	int		y;
+	int		i;
+	caddr_t		mem_addr;
+	caddr_t		dp_addr;
+	u_int		second_rdval;
+	MemType		*rdval;
+	int		subscr = 0;
+
+	if (complement) {
+	    dp = cdata;
+	} else {
+	    dp = data;
+	}
+
+	/* Write Data to Screen */
+	for (y = yoff; y < yoff + 64; y++) {
+	    for (x = xoff * bytepp, i = 0;
+		x < ((xoff + 64) *bytepp);
+		x += access_mode, i++) {
+		mem_addr = (y*pitch*bytepp) + x + base;
+		/* Check which access mode to use for write */
+		switch (access_mode) {
+		case 8:	/* long long (8-byte) access mode */
+			Write64(mem_addr, dp[subscr].val[i]);
+			break;
+		case 4:	/* word (4-byte) access mode */
+			Write32(mem_addr, dp[subscr].word[i]);
+			break;
+		case 2:	/* short (2-byte) access mode */
+			Write16(mem_addr, dp[subscr].halfwd[i]);
+			break;
+		default: /* default to byte access */
+			Write8(mem_addr, dp[subscr].byte[i]);
+			break;
+		}
+	    }
+	    subscr++;
+	}
+
+	/* Read the Data From the Screen */
+
+	rdval = (MemType *)memalign(64, (sizeof (MemType) * bytepp));
+
+	for (y = yoff; y < yoff + 64; y++) {
+	    for (x = xoff * bytepp, i = 0;
+		x < ((xoff + 64) * bytepp);
+		x += access_mode, i++) {
+		mem_addr = (y*pitch*bytepp) + x + base;
+
+		switch (access_mode) {
+		case 8:	/* long long (8-byte) access mode */
+			rdval->val[i] = read64(mem_addr);
+			break;
+		case 4:	/* word (4-byte) access mode */
+			rdval->word[i] = read32(mem_addr);
+			break;
+		case 2:	/* short (2-byte) access mode */
+			rdval->halfwd[i] = read16(mem_addr);
+			break;
+		default: /* default to byte access */
+			rdval->byte[i] = read8(mem_addr);
+			break;
+		}
+	    }
+
+	    /* TODO: verification */
+	    if (memcmp(rdval, dp[subscr].byte, 64 * bytepp) != 0) {
+		switch (access_mode) {
+		case 8:	/* long long (8-byte) access mode */
+			for (i = 0; i < (16 * bytepp); i++) {
+			    if (rdval->word[i] != dp[subscr].word[i]) {
+				free(rdval);
+				return (B_FALSE);
+			    }
+			}
+			break;
+		case 4:	/* word (4-byte) access mode */
+			for (i = 0; i < (16  * bytepp); i++) {
+			    if (rdval->word[i] != dp[subscr].word[i]) {
+				free(rdval);
+				return (B_FALSE);
+			    }
+			}
+			break;
+		case 2:	/* short (2-byte) access mode */
+			for (i = 0; i < (32 * bytepp); i++) {
+			    if (rdval->halfwd[i] != dp[subscr].halfwd[i]) {
+				    free(rdval);
+				    return (B_FALSE);
+			    }
+			}
+			break;
+		default: /* default to byte access */
+			for (i = 0; i < (64 * bytepp); i++) {
+			    if (rdval->byte[i] != dp[subscr].byte[i]) {
+				free(rdval);
+				return (B_FALSE);
+			    }
+			}
+			break;
+		}
+	    }
+	    subscr ++;
+	}
+
+	return (B_TRUE);
+
+}	/* write_read() */
+
+
+void
+check_plane(int num_planes, int access_mode, char *test_name,
+	    int fb_offset, int fb_pitch, int fb_height,
+	    int fb_width, int bytepp, caddr_t base)
+{
+	int		x;
+	int		y;
+	int		complement;
+
+	/* Set up refber for this plane group */
+	plane_change(num_planes,  base + fb_offset, fb_width, fb_height);
+
+	/* Cover each 64x64 chunk of screen space */
+	y = 0;
+	while (y < fb_height) {
+	    x = 0;
+	    while (x < fb_width) {
+		if (x + 63 > fb_width) x = fb_width - 64;
+		if (y + 63 > fb_height) y = fb_height - 64;
+
+		/* Do each chunk twice - once normal, once complement */
+		for (complement = B_FALSE;
+		    	complement <= B_TRUE;
+		    	complement++) {
+		    write_read(x, y,
+				(boolean_t)complement,
+				access_mode,
+				B_TRUE,
+				fb_pitch,
+				bytepp,
+				base) ||
+			    write_read(x, y,
+				(boolean_t)complement,
+				access_mode,
+				B_FALSE,
+				fb_pitch,
+				bytepp,
+				base);
+		}
+
+		/* Move over one 64x64 chunk */
+		x += 64;
+	    }
+
+	    /* Move down one 64x64 chunk */
+	    y += 64;
+	}
+
+}	/* check_plane() */
+
+
+void
+memory_test(return_packet *rp, int fd)
+{
+        struct efb_info  efb_info;
+        struct efb_info  *pEFB;
+	unsigned int red;
+	unsigned char *fbaddr;
+	int i;
+	int bytepp;
+	int fb_offset, fb_pitch, fb_height, fb_width;
+
+        pEFB = &efb_info;
+        pEFB->fd = fd;
+
+        /*
+         * map the registers & frame buffers memory
+         */
+        if (efb_map_mem(pEFB, rp, GRAPHICS_ERR_MEMORY_MSG) == -1) {
+            return;
+        }
+
+	if (efb_init_info(pEFB) == -1) {
+	    return;
+	}
+
+	for (i = 0; access_mode[i] != 0; i++) {
+	    check_plane((size_t) pEFB->bitsPerPixel, access_mode[i], 
+			(char *)"Memory Test", 
+			0, pEFB->screenWidth, pEFB->screenHeight, pEFB->screenWidth,
+			pEFB->bitsPerPixel/8, (caddr_t)pEFB->FBvaddr);
+	}
+
+        /*
+         * Unmap the registers & frame buffers memory
+         */
+        if (efb_unmap_mem(pEFB, rp, GRAPHICS_ERR_MEMORY_MSG) == -1) {
+            return;
+        }
+}	/* memory_test() */
+
+
+/* End of memory.c */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/efb/radeon_reg.h	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,4026 @@
+/*
+ * Copyright 2000 ATI Technologies Inc., Markham, Ontario, and
+ *                VA Linux Systems Inc., Fremont, 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 on 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
+ * NON-INFRINGEMENT.  IN NO EVENT SHALL ATI, VA LINUX SYSTEMS AND/OR
+ * THEIR 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:
+ *   Kevin E. Martin <[email protected]>
+ *   Rickard E. Faith <[email protected]>
+ *   Alan Hourihane <[email protected]>
+ *
+ * References:
+ *
+ * !!!! FIXME !!!!
+ *   RAGE 128 VR/ RAGE 128 GL Register Reference Manual (Technical
+ *   Reference Manual P/N RRG-G04100-C Rev. 0.04), ATI Technologies: April
+ *   1999.
+ *
+ * !!!! FIXME !!!!
+ *   RAGE 128 Software Development Manual (Technical Reference Manual P/N
+ *   SDK-G04000 Rev. 0.01), ATI Technologies: June 1999.
+ *
+ */
+
+/* !!!! FIXME !!!!  NOTE: THIS FILE HAS BEEN CONVERTED FROM r128_reg.h
+ * AND CONTAINS REGISTERS AND REGISTER DEFINITIONS THAT ARE NOT CORRECT
+ * ON THE RADEON.  A FULL AUDIT OF THIS CODE IS NEEDED!  */
+
+#ifndef _RADEON_REG_H_
+#define _RADEON_REG_H_
+
+#define ATI_DATATYPE_VQ				0
+#define ATI_DATATYPE_CI4			1
+#define ATI_DATATYPE_CI8			2
+#define ATI_DATATYPE_ARGB1555			3
+#define ATI_DATATYPE_RGB565			4
+#define ATI_DATATYPE_RGB888			5
+#define ATI_DATATYPE_ARGB8888			6
+#define ATI_DATATYPE_RGB332			7
+#define ATI_DATATYPE_Y8				8
+#define ATI_DATATYPE_RGB8			9
+#define ATI_DATATYPE_CI16			10
+#define ATI_DATATYPE_VYUY_422			11
+#define ATI_DATATYPE_YVYU_422			12
+#define ATI_DATATYPE_AYUV_444			14
+#define ATI_DATATYPE_ARGB4444			15
+
+				/* Registers for 2D/Video/Overlay */
+#define RADEON_ADAPTER_ID                   0x0f2c /* PCI */
+#define RADEON_AGP_BASE                     0x0170
+#define RADEON_AGP_CNTL                     0x0174
+#       define RADEON_AGP_APER_SIZE_256MB   (0x00 << 0)
+#       define RADEON_AGP_APER_SIZE_128MB   (0x20 << 0)
+#       define RADEON_AGP_APER_SIZE_64MB    (0x30 << 0)
+#       define RADEON_AGP_APER_SIZE_32MB    (0x38 << 0)
+#       define RADEON_AGP_APER_SIZE_16MB    (0x3c << 0)
+#       define RADEON_AGP_APER_SIZE_8MB     (0x3e << 0)
+#       define RADEON_AGP_APER_SIZE_4MB     (0x3f << 0)
+#       define RADEON_AGP_APER_SIZE_MASK    (0x3f << 0)
+#define RADEON_STATUS_PCI_CONFIG            0x06
+#       define RADEON_CAP_LIST              0x100000
+#define RADEON_CAPABILITIES_PTR_PCI_CONFIG  0x34 /* offset in PCI config*/
+#       define RADEON_CAP_PTR_MASK          0xfc /* mask off reserved bits of CAP_PTR */
+#       define RADEON_CAP_ID_NULL           0x00 /* End of capability list */
+#       define RADEON_CAP_ID_AGP            0x02 /* AGP capability ID */
+#       define RADEON_CAP_ID_EXP            0x10 /* PCI Express */
+#define RADEON_AGP_COMMAND                  0x0f60 /* PCI */
+#define RADEON_AGP_COMMAND_PCI_CONFIG       0x0060 /* offset in PCI config*/
+#       define RADEON_AGP_ENABLE            (1<<8)
+#define RADEON_AGP_PLL_CNTL                 0x000b /* PLL */
+#define RADEON_AGP_STATUS                   0x0f5c /* PCI */
+#       define RADEON_AGP_1X_MODE           0x01
+#       define RADEON_AGP_2X_MODE           0x02
+#       define RADEON_AGP_4X_MODE           0x04
+#       define RADEON_AGP_FW_MODE           0x10
+#       define RADEON_AGP_MODE_MASK         0x17
+#       define RADEON_AGPv3_MODE            0x08
+#       define RADEON_AGPv3_4X_MODE         0x01
+#       define RADEON_AGPv3_8X_MODE         0x02
+#define RADEON_ATTRDR                       0x03c1 /* VGA */
+#define RADEON_ATTRDW                       0x03c0 /* VGA */
+#define RADEON_ATTRX                        0x03c0 /* VGA */
+#define RADEON_AUX_SC_CNTL                  0x1660
+#       define RADEON_AUX1_SC_EN            (1 << 0)
+#       define RADEON_AUX1_SC_MODE_OR       (0 << 1)
+#       define RADEON_AUX1_SC_MODE_NAND     (1 << 1)
+#       define RADEON_AUX2_SC_EN            (1 << 2)
+#       define RADEON_AUX2_SC_MODE_OR       (0 << 3)
+#       define RADEON_AUX2_SC_MODE_NAND     (1 << 3)
+#       define RADEON_AUX3_SC_EN            (1 << 4)
+#       define RADEON_AUX3_SC_MODE_OR       (0 << 5)
+#       define RADEON_AUX3_SC_MODE_NAND     (1 << 5)
+#define RADEON_AUX1_SC_BOTTOM               0x1670
+#define RADEON_AUX1_SC_LEFT                 0x1664
+#define RADEON_AUX1_SC_RIGHT                0x1668
+#define RADEON_AUX1_SC_TOP                  0x166c
+#define RADEON_AUX2_SC_BOTTOM               0x1680
+#define RADEON_AUX2_SC_LEFT                 0x1674
+#define RADEON_AUX2_SC_RIGHT                0x1678
+#define RADEON_AUX2_SC_TOP                  0x167c
+#define RADEON_AUX3_SC_BOTTOM               0x1690
+#define RADEON_AUX3_SC_LEFT                 0x1684
+#define RADEON_AUX3_SC_RIGHT                0x1688
+#define RADEON_AUX3_SC_TOP                  0x168c
+#define RADEON_AUX_WINDOW_HORZ_CNTL         0x02d8
+#define RADEON_AUX_WINDOW_VERT_CNTL         0x02dc
+
+#define RADEON_BASE_CODE                    0x0f0b
+#define RADEON_BIOS_0_SCRATCH               0x0010
+#       define RADEON_FP_PANEL_SCALABLE     (1 << 16)
+#       define RADEON_FP_PANEL_SCALE_EN     (1 << 17)
+#       define RADEON_FP_CHIP_SCALE_EN      (1 << 18)
+#       define RADEON_DRIVER_BRIGHTNESS_EN  (1 << 26)
+#       define RADEON_DISPLAY_ROT_MASK      (3 << 28)
+#       define RADEON_DISPLAY_ROT_00        (0 << 28)
+#       define RADEON_DISPLAY_ROT_90        (1 << 28)
+#       define RADEON_DISPLAY_ROT_180       (2 << 28)
+#       define RADEON_DISPLAY_ROT_270       (3 << 28)
+#define RADEON_BIOS_1_SCRATCH               0x0014
+#define RADEON_BIOS_2_SCRATCH               0x0018
+#define RADEON_BIOS_3_SCRATCH               0x001c
+#define RADEON_BIOS_4_SCRATCH               0x0020
+#       define RADEON_CRT1_ATTACHED_MASK    (3 << 0)
+#       define RADEON_CRT1_ATTACHED_MONO    (1 << 0)
+#       define RADEON_CRT1_ATTACHED_COLOR   (2 << 0)
+#       define RADEON_LCD1_ATTACHED         (1 << 2)
+#       define RADEON_DFP1_ATTACHED         (1 << 3)
+#       define RADEON_TV1_ATTACHED_MASK     (3 << 4)
+#       define RADEON_TV1_ATTACHED_COMP     (1 << 4)
+#       define RADEON_TV1_ATTACHED_SVIDEO   (2 << 4)
+#       define RADEON_CRT2_ATTACHED_MASK    (3 << 8)
+#       define RADEON_CRT2_ATTACHED_MONO    (1 << 8)
+#       define RADEON_CRT2_ATTACHED_COLOR   (2 << 8)
+#       define RADEON_DFP2_ATTACHED         (1 << 11)
+#define RADEON_BIOS_5_SCRATCH               0x0024
+#       define RADEON_LCD1_ON               (1 << 0)
+#       define RADEON_CRT1_ON               (1 << 1)
+#       define RADEON_TV1_ON                (1 << 2)
+#       define RADEON_DFP1_ON               (1 << 3)
+#       define RADEON_CRT2_ON               (1 << 5)
+#       define RADEON_CV1_ON                (1 << 6)
+#       define RADEON_DFP2_ON               (1 << 7)
+#       define RADEON_LCD1_CRTC_MASK        (1 << 8)
+#       define RADEON_LCD1_CRTC_SHIFT       8
+#       define RADEON_CRT1_CRTC_MASK        (1 << 9)
+#       define RADEON_CRT1_CRTC_SHIFT       9
+#       define RADEON_TV1_CRTC_MASK         (1 << 10)
+#       define RADEON_TV1_CRTC_SHIFT        10
+#       define RADEON_DFP1_CRTC_MASK        (1 << 11)
+#       define RADEON_DFP1_CRTC_SHIFT       11
+#       define RADEON_CRT2_CRTC_MASK        (1 << 12)
+#       define RADEON_CRT2_CRTC_SHIFT       12
+#       define RADEON_CV1_CRTC_MASK         (1 << 13)
+#       define RADEON_CV1_CRTC_SHIFT        13
+#       define RADEON_DFP2_CRTC_MASK        (1 << 14)
+#       define RADEON_DFP2_CRTC_SHIFT       14
+#define RADEON_BIOS_6_SCRATCH               0x0028
+#       define RADEON_ACC_MODE_CHANGE       (1 << 2)
+#       define RADEON_EXT_DESKTOP_MODE      (1 << 3)
+#       define RADEON_LCD_DPMS_ON           (1 << 20)
+#       define RADEON_CRT_DPMS_ON           (1 << 21)
+#       define RADEON_TV_DPMS_ON            (1 << 22)
+#       define RADEON_DFP_DPMS_ON           (1 << 23)
+#       define RADEON_DPMS_MASK             (3 << 24)
+#       define RADEON_DPMS_ON               (0 << 24)
+#       define RADEON_DPMS_STANDBY          (1 << 24)
+#       define RADEON_DPMS_SUSPEND          (2 << 24)
+#       define RADEON_DPMS_OFF              (3 << 24)
+#       define RADEON_SCREEN_BLANKING       (1 << 26)
+#       define RADEON_DRIVER_CRITICAL       (1 << 27)
+#       define RADEON_DISPLAY_SWITCHING_DIS (1 << 30)
+#define RADEON_BIOS_7_SCRATCH               0x002c
+#       define RADEON_SYS_HOTKEY            (1 << 10)
+#       define RADEON_DRV_LOADED            (1 << 12)
+#define RADEON_BIOS_ROM                     0x0f30 /* PCI */
+#define RADEON_BIST                         0x0f0f /* PCI */
+#define RADEON_BRUSH_DATA0                  0x1480
+#define RADEON_BRUSH_DATA1                  0x1484
+#define RADEON_BRUSH_DATA10                 0x14a8
+#define RADEON_BRUSH_DATA11                 0x14ac
+#define RADEON_BRUSH_DATA12                 0x14b0
+#define RADEON_BRUSH_DATA13                 0x14b4
+#define RADEON_BRUSH_DATA14                 0x14b8
+#define RADEON_BRUSH_DATA15                 0x14bc
+#define RADEON_BRUSH_DATA16                 0x14c0
+#define RADEON_BRUSH_DATA17                 0x14c4
+#define RADEON_BRUSH_DATA18                 0x14c8
+#define RADEON_BRUSH_DATA19                 0x14cc
+#define RADEON_BRUSH_DATA2                  0x1488
+#define RADEON_BRUSH_DATA20                 0x14d0
+#define RADEON_BRUSH_DATA21                 0x14d4
+#define RADEON_BRUSH_DATA22                 0x14d8
+#define RADEON_BRUSH_DATA23                 0x14dc
+#define RADEON_BRUSH_DATA24                 0x14e0
+#define RADEON_BRUSH_DATA25                 0x14e4
+#define RADEON_BRUSH_DATA26                 0x14e8
+#define RADEON_BRUSH_DATA27                 0x14ec
+#define RADEON_BRUSH_DATA28                 0x14f0
+#define RADEON_BRUSH_DATA29                 0x14f4
+#define RADEON_BRUSH_DATA3                  0x148c
+#define RADEON_BRUSH_DATA30                 0x14f8
+#define RADEON_BRUSH_DATA31                 0x14fc
+#define RADEON_BRUSH_DATA32                 0x1500
+#define RADEON_BRUSH_DATA33                 0x1504
+#define RADEON_BRUSH_DATA34                 0x1508
+#define RADEON_BRUSH_DATA35                 0x150c
+#define RADEON_BRUSH_DATA36                 0x1510
+#define RADEON_BRUSH_DATA37                 0x1514
+#define RADEON_BRUSH_DATA38                 0x1518
+#define RADEON_BRUSH_DATA39                 0x151c
+#define RADEON_BRUSH_DATA4                  0x1490
+#define RADEON_BRUSH_DATA40                 0x1520
+#define RADEON_BRUSH_DATA41                 0x1524
+#define RADEON_BRUSH_DATA42                 0x1528
+#define RADEON_BRUSH_DATA43                 0x152c
+#define RADEON_BRUSH_DATA44                 0x1530
+#define RADEON_BRUSH_DATA45                 0x1534
+#define RADEON_BRUSH_DATA46                 0x1538
+#define RADEON_BRUSH_DATA47                 0x153c
+#define RADEON_BRUSH_DATA48                 0x1540
+#define RADEON_BRUSH_DATA49                 0x1544
+#define RADEON_BRUSH_DATA5                  0x1494
+#define RADEON_BRUSH_DATA50                 0x1548
+#define RADEON_BRUSH_DATA51                 0x154c
+#define RADEON_BRUSH_DATA52                 0x1550
+#define RADEON_BRUSH_DATA53                 0x1554
+#define RADEON_BRUSH_DATA54                 0x1558
+#define RADEON_BRUSH_DATA55                 0x155c
+#define RADEON_BRUSH_DATA56                 0x1560
+#define RADEON_BRUSH_DATA57                 0x1564
+#define RADEON_BRUSH_DATA58                 0x1568
+#define RADEON_BRUSH_DATA59                 0x156c
+#define RADEON_BRUSH_DATA6                  0x1498
+#define RADEON_BRUSH_DATA60                 0x1570
+#define RADEON_BRUSH_DATA61                 0x1574
+#define RADEON_BRUSH_DATA62                 0x1578
+#define RADEON_BRUSH_DATA63                 0x157c
+#define RADEON_BRUSH_DATA7                  0x149c
+#define RADEON_BRUSH_DATA8                  0x14a0
+#define RADEON_BRUSH_DATA9                  0x14a4
+#define RADEON_BRUSH_SCALE                  0x1470
+#define RADEON_BRUSH_Y_X                    0x1474
+#define RADEON_BUS_CNTL                     0x0030
+#       define RADEON_BUS_MASTER_DIS         (1 << 6)
+#       define RADEON_BUS_RD_DISCARD_EN      (1 << 24)
+#       define RADEON_BUS_RD_ABORT_EN        (1 << 25)
+#       define RADEON_BUS_MSTR_DISCONNECT_EN (1 << 28)
+#       define RADEON_BUS_WRT_BURST          (1 << 29)
+#       define RADEON_BUS_READ_BURST         (1 << 30)
+#define RADEON_BUS_CNTL1                    0x0034
+#       define RADEON_BUS_WAIT_ON_LOCK_EN    (1 << 4)
+
+#define RADEON_CACHE_CNTL                   0x1724
+#define RADEON_CACHE_LINE                   0x0f0c /* PCI */
+#define RADEON_CAPABILITIES_ID              0x0f50 /* PCI */
+#define RADEON_CAPABILITIES_PTR             0x0f34 /* PCI */
+#define RADEON_CLK_PIN_CNTL                 0x0001 /* PLL */
+#       define RADEON_SCLK_DYN_START_CNTL   (1 << 15)
+#define RADEON_CLOCK_CNTL_DATA              0x000c
+#define RADEON_CLOCK_CNTL_INDEX             0x0008
+#       define RADEON_PLL_WR_EN             (1 << 7)
+#       define RADEON_PLL_DIV_SEL           (3 << 8)
+#       define RADEON_PLL2_DIV_SEL_MASK     ~(3 << 8)
+#define RADEON_CLK_PWRMGT_CNTL              0x0014
+#       define RADEON_ENGIN_DYNCLK_MODE     (1 << 12)
+#       define RADEON_ACTIVE_HILO_LAT_MASK  (3 << 13)
+#       define RADEON_ACTIVE_HILO_LAT_SHIFT 13
+#       define RADEON_DISP_DYN_STOP_LAT_MASK (1 << 12)
+#       define RADEON_MC_BUSY               (1 << 16)
+#       define RADEON_DLL_READY             (1 << 19)
+#       define RADEON_CG_NO1_DEBUG_0        (1 << 24)
+#       define RADEON_CG_NO1_DEBUG_MASK     (0x1f << 24)
+#       define RADEON_DYN_STOP_MODE_MASK    (7 << 21)
+#       define RADEON_TVPLL_PWRMGT_OFF      (1 << 30)
+#       define RADEON_TVCLK_TURNOFF         (1 << 31)
+#define RADEON_PLL_PWRMGT_CNTL              0x0015
+#       define RADEON_TCL_BYPASS_DISABLE    (1 << 20)
+#define RADEON_CLR_CMP_CLR_3D               0x1a24
+#define RADEON_CLR_CMP_CLR_DST              0x15c8
+#define RADEON_CLR_CMP_CLR_SRC              0x15c4
+#define RADEON_CLR_CMP_CNTL                 0x15c0
+#       define RADEON_SRC_CMP_EQ_COLOR      (4 <<  0)
+#       define RADEON_SRC_CMP_NEQ_COLOR     (5 <<  0)
+#       define RADEON_CLR_CMP_SRC_SOURCE    (1 << 24)
+#define RADEON_CLR_CMP_MASK                 0x15cc
+#       define RADEON_CLR_CMP_MSK           0xffffffff
+#define RADEON_CLR_CMP_MASK_3D              0x1A28
+#define RADEON_COMMAND                      0x0f04 /* PCI */
+#define RADEON_COMPOSITE_SHADOW_ID          0x1a0c
+#define RADEON_CONFIG_APER_0_BASE           0x0100
+#define RADEON_CONFIG_APER_1_BASE           0x0104
+#define RADEON_CONFIG_APER_SIZE             0x0108
+#define RADEON_CONFIG_BONDS                 0x00e8
+#define RADEON_CONFIG_CNTL                  0x00e0
+#       define RADEON_CFG_ATI_REV_A11       (0   << 16)
+#       define RADEON_CFG_ATI_REV_A12       (1   << 16)
+#       define RADEON_CFG_ATI_REV_A13       (2   << 16)
+#       define RADEON_CFG_ATI_REV_ID_MASK   (0xf << 16)
+#define RADEON_CONFIG_MEMSIZE               0x00f8
+#define RADEON_CONFIG_MEMSIZE_EMBEDDED      0x0114
+#define RADEON_CONFIG_REG_1_BASE            0x010c
+#define RADEON_CONFIG_REG_APER_SIZE         0x0110
+#define RADEON_CONFIG_XSTRAP                0x00e4
+#define RADEON_CONSTANT_COLOR_C             0x1d34
+#       define RADEON_CONSTANT_COLOR_MASK   0x00ffffff
+#       define RADEON_CONSTANT_COLOR_ONE    0x00ffffff
+#       define RADEON_CONSTANT_COLOR_ZERO   0x00000000
+#define RADEON_CRC_CMDFIFO_ADDR             0x0740
+#define RADEON_CRC_CMDFIFO_DOUT             0x0744
+#define RADEON_GRPH_BUFFER_CNTL             0x02f0
+#       define RADEON_GRPH_START_REQ_MASK          (0x7f)
+#       define RADEON_GRPH_START_REQ_SHIFT         0
+#       define RADEON_GRPH_STOP_REQ_MASK           (0x7f<<8)
+#       define RADEON_GRPH_STOP_REQ_SHIFT          8
+#       define RADEON_GRPH_CRITICAL_POINT_MASK     (0x7f<<16)
+#       define RADEON_GRPH_CRITICAL_POINT_SHIFT    16
+#       define RADEON_GRPH_CRITICAL_CNTL           (1<<28)
+#       define RADEON_GRPH_BUFFER_SIZE             (1<<29)
+#       define RADEON_GRPH_CRITICAL_AT_SOF         (1<<30)
+#       define RADEON_GRPH_STOP_CNTL               (1<<31)
+#define RADEON_GRPH2_BUFFER_CNTL            0x03f0
+#       define RADEON_GRPH2_START_REQ_MASK         (0x7f)
+#       define RADEON_GRPH2_START_REQ_SHIFT         0
+#       define RADEON_GRPH2_STOP_REQ_MASK          (0x7f<<8)
+#       define RADEON_GRPH2_STOP_REQ_SHIFT         8
+#       define RADEON_GRPH2_CRITICAL_POINT_MASK    (0x7f<<16)
+#       define RADEON_GRPH2_CRITICAL_POINT_SHIFT   16
+#       define RADEON_GRPH2_CRITICAL_CNTL          (1<<28)
+#       define RADEON_GRPH2_BUFFER_SIZE            (1<<29)
+#       define RADEON_GRPH2_CRITICAL_AT_SOF        (1<<30)
+#       define RADEON_GRPH2_STOP_CNTL              (1<<31)
+#define RADEON_CRTC_CRNT_FRAME              0x0214
+#define RADEON_CRTC_EXT_CNTL                0x0054
+#       define RADEON_CRTC_VGA_XOVERSCAN    (1 <<  0)
+#       define RADEON_VGA_ATI_LINEAR        (1 <<  3)
+#       define RADEON_XCRT_CNT_EN           (1 <<  6)
+#       define RADEON_CRTC_HSYNC_DIS        (1 <<  8)
+#       define RADEON_CRTC_VSYNC_DIS        (1 <<  9)
+#       define RADEON_CRTC_DISPLAY_DIS      (1 << 10)
+#       define RADEON_CRTC_SYNC_TRISTAT     (1 << 11)
+#       define RADEON_CRTC_CRT_ON           (1 << 15)
+#define RADEON_CRTC_EXT_CNTL_DPMS_BYTE      0x0055
+#       define RADEON_CRTC_HSYNC_DIS_BYTE   (1 <<  0)
+#       define RADEON_CRTC_VSYNC_DIS_BYTE   (1 <<  1)
+#       define RADEON_CRTC_DISPLAY_DIS_BYTE (1 <<  2)
+#define RADEON_CRTC_GEN_CNTL                0x0050
+#       define RADEON_CRTC_DBL_SCAN_EN      (1 <<  0)
+#       define RADEON_CRTC_INTERLACE_EN     (1 <<  1)
+#       define RADEON_CRTC_CSYNC_EN         (1 <<  4)
+#       define RADEON_CRTC_ICON_EN          (1 << 15)
+#       define RADEON_CRTC_CUR_EN           (1 << 16)
+#       define RADEON_CRTC_CUR_MODE_MASK    (7 << 20)
+#       define RADEON_CRTC_EXT_DISP_EN      (1 << 24)
+#       define RADEON_CRTC_EN               (1 << 25)
+#       define RADEON_CRTC_DISP_REQ_EN_B    (1 << 26)
+#define RADEON_CRTC2_GEN_CNTL               0x03f8
+#       define RADEON_CRTC2_DBL_SCAN_EN     (1 <<  0)
+#       define RADEON_CRTC2_INTERLACE_EN    (1 <<  1)
+#       define RADEON_CRTC2_SYNC_TRISTAT    (1 <<  4)
+#       define RADEON_CRTC2_HSYNC_TRISTAT   (1 <<  5)
+#       define RADEON_CRTC2_VSYNC_TRISTAT   (1 <<  6)
+#       define RADEON_CRTC2_CRT2_ON         (1 <<  7)
+#       define RADEON_CRTC2_PIX_WIDTH_SHIFT 8
+#       define RADEON_CRTC2_PIX_WIDTH_MASK  (0xf << 8)
+#       define RADEON_CRTC2_ICON_EN         (1 << 15)
+#       define RADEON_CRTC2_CUR_EN          (1 << 16)
+#       define RADEON_CRTC2_CUR_MODE_MASK   (7 << 20)
+#       define RADEON_CRTC2_DISP_DIS        (1 << 23)
+#       define RADEON_CRTC2_EN              (1 << 25)
+#       define RADEON_CRTC2_DISP_REQ_EN_B   (1 << 26)
+#       define RADEON_CRTC2_CSYNC_EN        (1 << 27)
+#       define RADEON_CRTC2_HSYNC_DIS       (1 << 28)
+#       define RADEON_CRTC2_VSYNC_DIS       (1 << 29)
+#define RADEON_CRTC_MORE_CNTL               0x27c
+#       define RADEON_CRTC_AUTO_HORZ_CENTER_EN (1<<2)
+#       define RADEON_CRTC_AUTO_VERT_CENTER_EN (1<<3)
+#       define RADEON_CRTC_H_CUTOFF_ACTIVE_EN (1<<4)
+#       define RADEON_CRTC_V_CUTOFF_ACTIVE_EN (1<<5)
+#define RADEON_CRTC_GUI_TRIG_VLINE          0x0218
+#define RADEON_CRTC_H_SYNC_STRT_WID         0x0204
+#       define RADEON_CRTC_H_SYNC_STRT_PIX        (0x07  <<  0)
+#       define RADEON_CRTC_H_SYNC_STRT_CHAR       (0x3ff <<  3)
+#       define RADEON_CRTC_H_SYNC_STRT_CHAR_SHIFT 3
+#       define RADEON_CRTC_H_SYNC_WID             (0x3f  << 16)
+#       define RADEON_CRTC_H_SYNC_WID_SHIFT       16
+#       define RADEON_CRTC_H_SYNC_POL             (1     << 23)
+#define RADEON_CRTC2_H_SYNC_STRT_WID        0x0304
+#       define RADEON_CRTC2_H_SYNC_STRT_PIX        (0x07  <<  0)
+#       define RADEON_CRTC2_H_SYNC_STRT_CHAR       (0x3ff <<  3)
+#       define RADEON_CRTC2_H_SYNC_STRT_CHAR_SHIFT 3
+#       define RADEON_CRTC2_H_SYNC_WID             (0x3f  << 16)
+#       define RADEON_CRTC2_H_SYNC_WID_SHIFT       16
+#       define RADEON_CRTC2_H_SYNC_POL             (1     << 23)
+#define RADEON_CRTC_H_TOTAL_DISP            0x0200
+#       define RADEON_CRTC_H_TOTAL          (0x03ff << 0)
+#       define RADEON_CRTC_H_TOTAL_SHIFT    0
+#       define RADEON_CRTC_H_DISP           (0x01ff << 16)
+#       define RADEON_CRTC_H_DISP_SHIFT     16
+#define RADEON_CRTC2_H_TOTAL_DISP           0x0300
+#       define RADEON_CRTC2_H_TOTAL         (0x03ff << 0)
+#       define RADEON_CRTC2_H_TOTAL_SHIFT   0
+#       define RADEON_CRTC2_H_DISP          (0x01ff << 16)
+#       define RADEON_CRTC2_H_DISP_SHIFT    16
+
+#define RADEON_CRTC_OFFSET_RIGHT	    0x0220
+#define RADEON_CRTC_OFFSET                  0x0224
+#	define RADEON_CRTC_OFFSET__GUI_TRIG_OFFSET (1<<30)
+#	define RADEON_CRTC_OFFSET__OFFSET_LOCK 	   (1<<31)
+
+#define RADEON_CRTC2_OFFSET                 0x0324
+#	define RADEON_CRTC2_OFFSET__GUI_TRIG_OFFSET (1<<30)
+#	define RADEON_CRTC2_OFFSET__OFFSET_LOCK	    (1<<31)
+#define RADEON_CRTC_OFFSET_CNTL             0x0228
+#       define RADEON_CRTC_TILE_LINE_SHIFT              0
+#       define RADEON_CRTC_TILE_LINE_RIGHT_SHIFT        4
+#	define R300_CRTC_X_Y_MODE_EN_RIGHT		(1 << 6)
+#	define R300_CRTC_MICRO_TILE_BUFFER_RIGHT_MASK   (3 << 7)
+#	define R300_CRTC_MICRO_TILE_BUFFER_RIGHT_AUTO   (0 << 7)
+#	define R300_CRTC_MICRO_TILE_BUFFER_RIGHT_SINGLE (1 << 7)
+#	define R300_CRTC_MICRO_TILE_BUFFER_RIGHT_DOUBLE (2 << 7)
+#	define R300_CRTC_MICRO_TILE_BUFFER_RIGHT_DIS    (3 << 7)
+#	define R300_CRTC_X_Y_MODE_EN			(1 << 9)
+#	define R300_CRTC_MICRO_TILE_BUFFER_MASK   	(3 << 10)
+#	define R300_CRTC_MICRO_TILE_BUFFER_AUTO   	(0 << 10)
+#	define R300_CRTC_MICRO_TILE_BUFFER_SINGLE 	(1 << 10)
+#	define R300_CRTC_MICRO_TILE_BUFFER_DOUBLE 	(2 << 10)
+#	define R300_CRTC_MICRO_TILE_BUFFER_DIS    	(3 << 10)
+#	define R300_CRTC_MICRO_TILE_EN_RIGHT		(1 << 12)
+#	define R300_CRTC_MICRO_TILE_EN			(1 << 13)
+#	define R300_CRTC_MACRO_TILE_EN_RIGHT		(1 << 14)
+#       define R300_CRTC_MACRO_TILE_EN                  (1 << 15)
+#       define RADEON_CRTC_TILE_EN_RIGHT                (1 << 14)
+#       define RADEON_CRTC_TILE_EN                      (1 << 15)
+#       define RADEON_CRTC_OFFSET_FLIP_CNTL             (1 << 16)
+#       define RADEON_CRTC_STEREO_OFFSET_EN             (1 << 17)
+
+#define R300_CRTC_TILE_X0_Y0	            0x0350
+#define R300_CRTC2_TILE_X0_Y0	            0x0358
+
+#define RADEON_CRTC2_OFFSET_CNTL            0x0328
+#       define RADEON_CRTC2_OFFSET_FLIP_CNTL (1 << 16)
+#       define RADEON_CRTC2_TILE_EN         (1 << 15)
+#define RADEON_CRTC_PITCH                   0x022c
+#	define RADEON_CRTC_PITCH__SHIFT		 0
+#	define RADEON_CRTC_PITCH__RIGHT_SHIFT	16
+
+#define RADEON_CRTC2_PITCH                  0x032c
+#define RADEON_CRTC_STATUS                  0x005c
+#       define RADEON_CRTC_VBLANK_SAVE      (1 <<  1)
+#       define RADEON_CRTC_VBLANK_SAVE_CLEAR  (1 <<  1)
+#define RADEON_CRTC2_STATUS                  0x03fc
+#       define RADEON_CRTC2_VBLANK_SAVE      (1 <<  1)
+#       define RADEON_CRTC2_VBLANK_SAVE_CLEAR  (1 <<  1)
+#define RADEON_CRTC_V_SYNC_STRT_WID         0x020c
+#       define RADEON_CRTC_V_SYNC_STRT        (0x7ff <<  0)
+#       define RADEON_CRTC_V_SYNC_STRT_SHIFT  0
+#       define RADEON_CRTC_V_SYNC_WID         (0x1f  << 16)
+#       define RADEON_CRTC_V_SYNC_WID_SHIFT   16
+#       define RADEON_CRTC_V_SYNC_POL         (1     << 23)
+#define RADEON_CRTC2_V_SYNC_STRT_WID        0x030c
+#       define RADEON_CRTC2_V_SYNC_STRT       (0x7ff <<  0)
+#       define RADEON_CRTC2_V_SYNC_STRT_SHIFT 0
+#       define RADEON_CRTC2_V_SYNC_WID        (0x1f  << 16)
+#       define RADEON_CRTC2_V_SYNC_WID_SHIFT  16
+#       define RADEON_CRTC2_V_SYNC_POL        (1     << 23)
+#define RADEON_CRTC_V_TOTAL_DISP            0x0208
+#       define RADEON_CRTC_V_TOTAL          (0x07ff << 0)
+#       define RADEON_CRTC_V_TOTAL_SHIFT    0
+#       define RADEON_CRTC_V_DISP           (0x07ff << 16)
+#       define RADEON_CRTC_V_DISP_SHIFT     16
+#define RADEON_CRTC2_V_TOTAL_DISP           0x0308
+#       define RADEON_CRTC2_V_TOTAL         (0x07ff << 0)
+#       define RADEON_CRTC2_V_TOTAL_SHIFT   0
+#       define RADEON_CRTC2_V_DISP          (0x07ff << 16)
+#       define RADEON_CRTC2_V_DISP_SHIFT    16
+#define RADEON_CRTC_VLINE_CRNT_VLINE        0x0210
+#       define RADEON_CRTC_CRNT_VLINE_MASK  (0x7ff << 16)
+#define RADEON_CRTC2_CRNT_FRAME             0x0314
+#define RADEON_CRTC2_GUI_TRIG_VLINE         0x0318
+#define RADEON_CRTC2_STATUS                 0x03fc
+#define RADEON_CRTC2_VLINE_CRNT_VLINE       0x0310
+#define RADEON_CRTC8_DATA                   0x03d5 /* VGA, 0x3b5 */
+#define RADEON_CRTC8_IDX                    0x03d4 /* VGA, 0x3b4 */
+#define RADEON_CUR_CLR0                     0x026c
+#define RADEON_CUR_CLR1                     0x0270
+#define RADEON_CUR_HORZ_VERT_OFF            0x0268
+#define RADEON_CUR_HORZ_VERT_POSN           0x0264
+#define RADEON_CUR_OFFSET                   0x0260
+#       define RADEON_CUR_LOCK              (1 << 31)
+#define RADEON_CUR2_CLR0                    0x036c
+#define RADEON_CUR2_CLR1                    0x0370
+#define RADEON_CUR2_HORZ_VERT_OFF           0x0368
+#define RADEON_CUR2_HORZ_VERT_POSN          0x0364
+#define RADEON_CUR2_OFFSET                  0x0360
+#       define RADEON_CUR2_LOCK             (1 << 31)
+
+#define RADEON_DAC_CNTL                     0x0058
+#       define RADEON_DAC_RANGE_CNTL        (3 <<  0)
+#       define RADEON_DAC_RANGE_CNTL_PS2    (2 <<  0)
+#       define RADEON_DAC_RANGE_CNTL_MASK   0x03
+#       define RADEON_DAC_BLANKING          (1 <<  2)
+#       define RADEON_DAC_CMP_EN            (1 <<  3)
+#       define RADEON_DAC_CMP_OUTPUT        (1 <<  7)
+#       define RADEON_DAC_8BIT_EN           (1 <<  8)
+#       define RADEON_DAC_TVO_EN            (1 << 10)
+#       define RADEON_DAC_VGA_ADR_EN        (1 << 13)
+#       define RADEON_DAC_PDWN              (1 << 15)
+#       define RADEON_DAC_MASK_ALL          (0xff << 24)
+#define RADEON_DAC_CNTL2                    0x007c
+#       define RADEON_DAC2_TV_CLK_SEL       (0 <<  1)
+#       define RADEON_DAC2_DAC_CLK_SEL      (1 <<  0)
+#       define RADEON_DAC2_DAC2_CLK_SEL     (1 <<  1)
+#       define RADEON_DAC2_PALETTE_ACC_CTL  (1 <<  5)
+#       define RADEON_DAC2_CMP_EN           (1 <<  7)
+#       define RADEON_DAC2_CMP_OUT_R        (1 <<  8)
+#       define RADEON_DAC2_CMP_OUT_G        (1 <<  9)
+#       define RADEON_DAC2_CMP_OUT_B        (1 << 10)
+#       define RADEON_DAC2_CMP_OUTPUT       (1 << 11)
+#define RADEON_DAC_EXT_CNTL                 0x0280
+#       define RADEON_DAC2_FORCE_BLANK_OFF_EN (1 << 0)
+#       define RADEON_DAC2_FORCE_DATA_EN      (1 << 1)
+#       define RADEON_DAC_FORCE_BLANK_OFF_EN  (1 << 4)
+#       define RADEON_DAC_FORCE_DATA_EN       (1 << 5)
+#       define RADEON_DAC_FORCE_DATA_SEL_MASK (3 << 6)
+#       define RADEON_DAC_FORCE_DATA_SEL_R    (0 << 6)
+#       define RADEON_DAC_FORCE_DATA_SEL_G    (1 << 6)
+#       define RADEON_DAC_FORCE_DATA_SEL_B    (2 << 6)
+#       define RADEON_DAC_FORCE_DATA_SEL_RGB  (3 << 6)
+#       define RADEON_DAC_FORCE_DATA_MASK   0x0003ff00
+#       define RADEON_DAC_FORCE_DATA_SHIFT  8
+#define RADEON_DAC_MACRO_CNTL               0x0d04
+#       define RADEON_DAC_PDWN_R            (1 << 16)
+#       define RADEON_DAC_PDWN_G            (1 << 17)
+#       define RADEON_DAC_PDWN_B            (1 << 18)
+#define RADEON_TV_DAC_CNTL                  0x088c
+#       define RADEON_TV_DAC_NBLANK         (1 << 0)
+#       define RADEON_TV_DAC_NHOLD          (1 << 1)
+#       define RADEON_TV_DAC_PEDESTAL       (1 <<  2)
+#       define RADEON_TV_MONITOR_DETECT_EN  (1 <<  4)
+#       define RADEON_TV_DAC_CMPOUT         (1 <<  5)
+#       define RADEON_TV_DAC_STD_MASK       (3 <<  8)
+#       define RADEON_TV_DAC_STD_PAL        (0 <<  8)
+#       define RADEON_TV_DAC_STD_NTSC       (1 <<  8)
+#       define RADEON_TV_DAC_STD_PS2        (2 <<  8)
+#       define RADEON_TV_DAC_STD_RS343      (3 <<  8)
+#       define RADEON_TV_DAC_BGSLEEP        (1 <<  6)
+#       define RADEON_TV_DAC_BGADJ_MASK     (0xf <<  16)
+#       define RADEON_TV_DAC_BGADJ_SHIFT    16
+#       define RADEON_TV_DAC_DACADJ_MASK    (0xf <<  20)
+#       define RADEON_TV_DAC_DACADJ_SHIFT   20
+#       define RADEON_TV_DAC_RDACPD         (1 <<  24)
+#       define RADEON_TV_DAC_GDACPD         (1 <<  25)
+#       define RADEON_TV_DAC_BDACPD         (1 <<  26)
+#       define RADEON_TV_DAC_RDACDET        (1 << 29)
+#       define RADEON_TV_DAC_GDACDET        (1 << 30)
+#       define RADEON_TV_DAC_BDACDET        (1 << 31)
+#       define R420_TV_DAC_DACADJ_MASK      (0x1f <<  20)
+#       define R420_TV_DAC_RDACPD           (1 <<  25)
+#       define R420_TV_DAC_GDACPD           (1 <<  26)
+#       define R420_TV_DAC_BDACPD           (1 <<  27)
+#       define R420_TV_DAC_TVENABLE         (1 <<  28)
+#define RADEON_DISP_HW_DEBUG                0x0d14
+#       define RADEON_CRT2_DISP1_SEL        (1 <<  5)
+#define RADEON_DISP_OUTPUT_CNTL             0x0d64
+#       define RADEON_DISP_DAC_SOURCE_MASK  0x03
+#       define RADEON_DISP_DAC2_SOURCE_MASK  0x0c
+#       define RADEON_DISP_DAC_SOURCE_CRTC2 0x01
+#       define RADEON_DISP_DAC_SOURCE_RMX   0x02
+#       define RADEON_DISP_DAC_SOURCE_LTU   0x03
+#       define RADEON_DISP_DAC2_SOURCE_CRTC2 0x04
+#       define RADEON_DISP_TVDAC_SOURCE_MASK  (0x03 << 2)
+#       define RADEON_DISP_TVDAC_SOURCE_CRTC  0x0
+#       define RADEON_DISP_TVDAC_SOURCE_CRTC2 (0x01 << 2)
+#       define RADEON_DISP_TVDAC_SOURCE_RMX   (0x02 << 2)
+#       define RADEON_DISP_TVDAC_SOURCE_LTU   (0x03 << 2)
+#       define RADEON_DISP_TRANS_MATRIX_MASK  (0x03 << 4)
+#       define RADEON_DISP_TRANS_MATRIX_ALPHA_MSB (0x00 << 4)
+#       define RADEON_DISP_TRANS_MATRIX_GRAPHICS  (0x01 << 4)
+#       define RADEON_DISP_TRANS_MATRIX_VIDEO     (0x02 << 4)
+#       define RADEON_DISP_TV_SOURCE_CRTC   (1 << 16) /* crtc1 or crtc2 */
+#       define RADEON_DISP_TV_SOURCE_LTU    (0 << 16) /* linear transform unit */
+#define RADEON_DISP_TV_OUT_CNTL             0x0d6c
+#       define RADEON_DISP_TV_PATH_SRC_CRTC2 (1 << 16)
+#       define RADEON_DISP_TV_PATH_SRC_CRTC1 (0 << 16)
+#define RADEON_DAC_CRC_SIG                  0x02cc
+#define RADEON_DAC_DATA                     0x03c9 /* VGA */
+#define RADEON_DAC_MASK                     0x03c6 /* VGA */
+#define RADEON_DAC_R_INDEX                  0x03c7 /* VGA */
+#define RADEON_DAC_W_INDEX                  0x03c8 /* VGA */
+#define RADEON_DDA_CONFIG                   0x02e0
+#define RADEON_DDA_ON_OFF                   0x02e4
+#define RADEON_DEFAULT_OFFSET               0x16e0
+#define RADEON_DEFAULT_PITCH                0x16e4
+#define RADEON_DEFAULT_SC_BOTTOM_RIGHT      0x16e8
+#       define RADEON_DEFAULT_SC_RIGHT_MAX  (0x1fff <<  0)
+#       define RADEON_DEFAULT_SC_BOTTOM_MAX (0x1fff << 16)
+#define RADEON_DESTINATION_3D_CLR_CMP_VAL   0x1820
+#define RADEON_DESTINATION_3D_CLR_CMP_MSK   0x1824
+#define RADEON_DEVICE_ID                    0x0f02 /* PCI */
+#define RADEON_DISP_MISC_CNTL               0x0d00
+#define RADEON_DISP_MISC_CNTL__SOFT_RESET_GRPH_PP	0x00000001L
+#       define RADEON_SOFT_RESET_GRPH_PP    (1 << 0)
+#define RADEON_DISP_MERGE_CNTL		  0x0d60
+#       define RADEON_DISP_ALPHA_MODE_MASK  0x03
+#       define RADEON_DISP_ALPHA_MODE_KEY   0
+#       define RADEON_DISP_ALPHA_MODE_PER_PIXEL 1
+#       define RADEON_DISP_ALPHA_MODE_GLOBAL 2
+#       define RADEON_DISP_RGB_OFFSET_EN    (1 << 8)
+#       define RADEON_DISP_GRPH_ALPHA_MASK  (0xff << 16)
+#       define RADEON_DISP_OV0_ALPHA_MASK   (0xff << 24)
+#	define RADEON_DISP_LIN_TRANS_BYPASS (0x01 << 9)
+#define RADEON_DISP2_MERGE_CNTL		    0x0d68
+#       define RADEON_DISP2_RGB_OFFSET_EN   (1 << 8)
+#define RADEON_DISP_LIN_TRANS_GRPH_A        0x0d80
+#define RADEON_DISP_LIN_TRANS_GRPH_B        0x0d84
+#define RADEON_DISP_LIN_TRANS_GRPH_C        0x0d88
+#define RADEON_DISP_LIN_TRANS_GRPH_D        0x0d8c
+#define RADEON_DISP_LIN_TRANS_GRPH_E        0x0d90
+#define RADEON_DISP_LIN_TRANS_GRPH_F        0x0d98
+#define RADEON_DP_BRUSH_BKGD_CLR            0x1478
+#define RADEON_DP_BRUSH_FRGD_CLR            0x147c
+#define RADEON_DP_CNTL                      0x16c0
+#       define RADEON_DST_X_LEFT_TO_RIGHT   (1 <<  0)
+#       define RADEON_DST_Y_TOP_TO_BOTTOM   (1 <<  1)
+#       define RADEON_DP_DST_TILE_LINEAR    (0 <<  3)
+#       define RADEON_DP_DST_TILE_MACRO     (1 <<  3)
+#       define RADEON_DP_DST_TILE_MICRO     (2 <<  3)
+#       define RADEON_DP_DST_TILE_BOTH      (3 <<  3)
+#define RADEON_DP_CNTL_XDIR_YDIR_YMAJOR     0x16d0
+#       define RADEON_DST_Y_MAJOR             (1 <<  2)
+#       define RADEON_DST_Y_DIR_TOP_TO_BOTTOM (1 << 15)
+#       define RADEON_DST_X_DIR_LEFT_TO_RIGHT (1 << 31)
+#define RADEON_DP_DATATYPE                  0x16c4
+#       define RADEON_HOST_BIG_ENDIAN_EN    (1 << 29)
+#define RADEON_DP_GUI_MASTER_CNTL           0x146c
+#       define RADEON_GMC_SRC_PITCH_OFFSET_CNTL   (1    <<  0)
+#       define RADEON_GMC_DST_PITCH_OFFSET_CNTL   (1    <<  1)
+#       define RADEON_GMC_SRC_CLIPPING            (1    <<  2)
+#       define RADEON_GMC_DST_CLIPPING            (1    <<  3)
+#       define RADEON_GMC_BRUSH_DATATYPE_MASK     (0x0f <<  4)
+#       define RADEON_GMC_BRUSH_8X8_MONO_FG_BG    (0    <<  4)
+#       define RADEON_GMC_BRUSH_8X8_MONO_FG_LA    (1    <<  4)
+#       define RADEON_GMC_BRUSH_1X8_MONO_FG_BG    (4    <<  4)
+#       define RADEON_GMC_BRUSH_1X8_MONO_FG_LA    (5    <<  4)
+#       define RADEON_GMC_BRUSH_32x1_MONO_FG_BG   (6    <<  4)
+#       define RADEON_GMC_BRUSH_32x1_MONO_FG_LA   (7    <<  4)
+#       define RADEON_GMC_BRUSH_32x32_MONO_FG_BG  (8    <<  4)
+#       define RADEON_GMC_BRUSH_32x32_MONO_FG_LA  (9    <<  4)
+#       define RADEON_GMC_BRUSH_8x8_COLOR         (10   <<  4)
+#       define RADEON_GMC_BRUSH_1X8_COLOR         (12   <<  4)
+#       define RADEON_GMC_BRUSH_SOLID_COLOR       (13   <<  4)
+#       define RADEON_GMC_BRUSH_NONE              (15   <<  4)
+#       define RADEON_GMC_DST_8BPP_CI             (2    <<  8)
+#       define RADEON_GMC_DST_15BPP               (3    <<  8)
+#       define RADEON_GMC_DST_16BPP               (4    <<  8)
+#       define RADEON_GMC_DST_24BPP               (5    <<  8)
+#       define RADEON_GMC_DST_32BPP               (6    <<  8)
+#       define RADEON_GMC_DST_8BPP_RGB            (7    <<  8)
+#       define RADEON_GMC_DST_Y8                  (8    <<  8)
+#       define RADEON_GMC_DST_RGB8                (9    <<  8)
+#       define RADEON_GMC_DST_VYUY                (11   <<  8)
+#       define RADEON_GMC_DST_YVYU                (12   <<  8)
+#       define RADEON_GMC_DST_AYUV444             (14   <<  8)
+#       define RADEON_GMC_DST_ARGB4444            (15   <<  8)
+#       define RADEON_GMC_DST_DATATYPE_MASK       (0x0f <<  8)
+#       define RADEON_GMC_DST_DATATYPE_SHIFT      8
+#       define RADEON_GMC_SRC_DATATYPE_MASK       (3    << 12)
+#       define RADEON_GMC_SRC_DATATYPE_MONO_FG_BG (0    << 12)
+#       define RADEON_GMC_SRC_DATATYPE_MONO_FG_LA (1    << 12)
+#       define RADEON_GMC_SRC_DATATYPE_COLOR      (3    << 12)
+#       define RADEON_GMC_BYTE_PIX_ORDER          (1    << 14)
+#       define RADEON_GMC_BYTE_MSB_TO_LSB         (0    << 14)
+#       define RADEON_GMC_BYTE_LSB_TO_MSB         (1    << 14)
+#       define RADEON_GMC_CONVERSION_TEMP         (1    << 15)
+#       define RADEON_GMC_CONVERSION_TEMP_6500    (0    << 15)
+#       define RADEON_GMC_CONVERSION_TEMP_9300    (1    << 15)
+#       define RADEON_GMC_ROP3_MASK               (0xff << 16)
+#       define RADEON_DP_SRC_SOURCE_MASK          (7    << 24)
+#       define RADEON_DP_SRC_SOURCE_MEMORY        (2    << 24)
+#       define RADEON_DP_SRC_SOURCE_HOST_DATA     (3    << 24)
+#       define RADEON_GMC_3D_FCN_EN               (1    << 27)
+#       define RADEON_GMC_CLR_CMP_CNTL_DIS        (1    << 28)
+#       define RADEON_GMC_AUX_CLIP_DIS            (1    << 29)
+#       define RADEON_GMC_WR_MSK_DIS              (1    << 30)
+#       define RADEON_GMC_LD_BRUSH_Y_X            (1    << 31)
+#       define RADEON_ROP3_ZERO             0x00000000
+#       define RADEON_ROP3_DSa              0x00880000
+#       define RADEON_ROP3_SDna             0x00440000
+#       define RADEON_ROP3_S                0x00cc0000
+#       define RADEON_ROP3_DSna             0x00220000
+#       define RADEON_ROP3_D                0x00aa0000
+#       define RADEON_ROP3_DSx              0x00660000
+#       define RADEON_ROP3_DSo              0x00ee0000
+#       define RADEON_ROP3_DSon             0x00110000
+#       define RADEON_ROP3_DSxn             0x00990000
+#       define RADEON_ROP3_Dn               0x00550000
+#       define RADEON_ROP3_SDno             0x00dd0000
+#       define RADEON_ROP3_Sn               0x00330000
+#       define RADEON_ROP3_DSno             0x00bb0000
+#       define RADEON_ROP3_DSan             0x00770000
+#       define RADEON_ROP3_ONE              0x00ff0000
+#       define RADEON_ROP3_DPa              0x00a00000
+#       define RADEON_ROP3_PDna             0x00500000
+#       define RADEON_ROP3_P                0x00f00000
+#       define RADEON_ROP3_DPna             0x000a0000
+#       define RADEON_ROP3_D                0x00aa0000
+#       define RADEON_ROP3_DPx              0x005a0000
+#       define RADEON_ROP3_DPo              0x00fa0000
+#       define RADEON_ROP3_DPon             0x00050000
+#       define RADEON_ROP3_PDxn             0x00a50000
+#       define RADEON_ROP3_PDno             0x00f50000
+#       define RADEON_ROP3_Pn               0x000f0000
+#       define RADEON_ROP3_DPno             0x00af0000
+#       define RADEON_ROP3_DPan             0x005f0000
+#define RADEON_DP_GUI_MASTER_CNTL_C         0x1c84
+#define RADEON_DP_MIX                       0x16c8
+#define RADEON_DP_SRC_BKGD_CLR              0x15dc
+#define RADEON_DP_SRC_FRGD_CLR              0x15d8
+#define RADEON_DP_WRITE_MASK                0x16cc
+#define RADEON_DST_BRES_DEC                 0x1630
+#define RADEON_DST_BRES_ERR                 0x1628
+#define RADEON_DST_BRES_INC                 0x162c
+#define RADEON_DST_BRES_LNTH                0x1634
+#define RADEON_DST_BRES_LNTH_SUB            0x1638
+#define RADEON_DST_HEIGHT                   0x1410
+#define RADEON_DST_HEIGHT_WIDTH             0x143c
+#define RADEON_DST_HEIGHT_WIDTH_8           0x158c
+#define RADEON_DST_HEIGHT_WIDTH_BW          0x15b4
+#define RADEON_DST_HEIGHT_Y                 0x15a0
+#define RADEON_DST_LINE_START               0x1600
+#define RADEON_DST_LINE_END                 0x1604
+#define RADEON_DST_LINE_PATCOUNT            0x1608
+#       define RADEON_BRES_CNTL_SHIFT       8
+#define RADEON_DST_OFFSET                   0x1404
+#define RADEON_DST_PITCH                    0x1408
+#define RADEON_DST_PITCH_OFFSET             0x142c
+#define RADEON_DST_PITCH_OFFSET_C           0x1c80
+#       define RADEON_PITCH_SHIFT           21
+#       define RADEON_DST_TILE_LINEAR       (0 << 30)
+#       define RADEON_DST_TILE_MACRO        (1 << 30)
+#       define RADEON_DST_TILE_MICRO        (2 << 30)
+#       define RADEON_DST_TILE_BOTH         (3 << 30)
+#define RADEON_DST_WIDTH                    0x140c
+#define RADEON_DST_WIDTH_HEIGHT             0x1598
+#define RADEON_DST_WIDTH_X                  0x1588
+#define RADEON_DST_WIDTH_X_INCY             0x159c
+#define RADEON_DST_X                        0x141c
+#define RADEON_DST_X_SUB                    0x15a4
+#define RADEON_DST_X_Y                      0x1594
+#define RADEON_DST_Y                        0x1420
+#define RADEON_DST_Y_SUB                    0x15a8
+#define RADEON_DST_Y_X                      0x1438
+
+#define RADEON_FCP_CNTL                     0x0910
+#      define RADEON_FCP0_SRC_PCICLK             0
+#      define RADEON_FCP0_SRC_PCLK               1
+#      define RADEON_FCP0_SRC_PCLKb              2
+#      define RADEON_FCP0_SRC_HREF               3
+#      define RADEON_FCP0_SRC_GND                4
+#      define RADEON_FCP0_SRC_HREFb              5
+#define RADEON_FLUSH_1                      0x1704
+#define RADEON_FLUSH_2                      0x1708
+#define RADEON_FLUSH_3                      0x170c
+#define RADEON_FLUSH_4                      0x1710
+#define RADEON_FLUSH_5                      0x1714
+#define RADEON_FLUSH_6                      0x1718
+#define RADEON_FLUSH_7                      0x171c
+#define RADEON_FOG_3D_TABLE_START           0x1810
+#define RADEON_FOG_3D_TABLE_END             0x1814
+#define RADEON_FOG_3D_TABLE_DENSITY         0x181c
+#define RADEON_FOG_TABLE_INDEX              0x1a14
+#define RADEON_FOG_TABLE_DATA               0x1a18
+#define RADEON_FP_CRTC_H_TOTAL_DISP         0x0250
+#define RADEON_FP_CRTC_V_TOTAL_DISP         0x0254
+#       define RADEON_FP_CRTC_H_TOTAL_MASK      0x000003ff
+#       define RADEON_FP_CRTC_H_DISP_MASK       0x01ff0000
+#       define RADEON_FP_CRTC_V_TOTAL_MASK      0x00000fff
+#       define RADEON_FP_CRTC_V_DISP_MASK       0x0fff0000
+#       define RADEON_FP_H_SYNC_STRT_CHAR_MASK  0x00001ff8
+#       define RADEON_FP_H_SYNC_WID_MASK        0x003f0000
+#       define RADEON_FP_V_SYNC_STRT_MASK       0x00000fff
+#       define RADEON_FP_V_SYNC_WID_MASK        0x001f0000
+#       define RADEON_FP_CRTC_H_TOTAL_SHIFT     0x00000000
+#       define RADEON_FP_CRTC_H_DISP_SHIFT      0x00000010
+#       define RADEON_FP_CRTC_V_TOTAL_SHIFT     0x00000000
+#       define RADEON_FP_CRTC_V_DISP_SHIFT      0x00000010
+#       define RADEON_FP_H_SYNC_STRT_CHAR_SHIFT 0x00000003
+#       define RADEON_FP_H_SYNC_WID_SHIFT       0x00000010
+#       define RADEON_FP_V_SYNC_STRT_SHIFT      0x00000000
+#       define RADEON_FP_V_SYNC_WID_SHIFT       0x00000010
+#define RADEON_FP_GEN_CNTL                  0x0284
+#       define RADEON_FP_FPON                  (1 <<  0)
+#       define RADEON_FP_BLANK_EN              (1 <<  1)
+#       define RADEON_FP_TMDS_EN               (1 <<  2)
+#       define RADEON_FP_PANEL_FORMAT          (1 <<  3)
+#       define RADEON_FP_EN_TMDS               (1 <<  7)
+#       define RADEON_FP_DETECT_SENSE          (1 <<  8)
+#       define R200_FP_SOURCE_SEL_MASK         (3 <<  10)
+#       define R200_FP_SOURCE_SEL_CRTC1        (0 <<  10)
+#       define R200_FP_SOURCE_SEL_CRTC2        (1 <<  10)
+#       define R200_FP_SOURCE_SEL_RMX          (2 <<  10)
+#       define R200_FP_SOURCE_SEL_TRANS        (3 <<  10)
+#       define RADEON_FP_SEL_CRTC1             (0 << 13)
+#       define RADEON_FP_SEL_CRTC2             (1 << 13)
+#       define RADEON_FP_CRTC_DONT_SHADOW_HPAR (1 << 15)
+#       define RADEON_FP_CRTC_DONT_SHADOW_VPAR (1 << 16)
+#       define RADEON_FP_CRTC_DONT_SHADOW_HEND (1 << 17)
+#       define RADEON_FP_CRTC_USE_SHADOW_VEND  (1 << 18)
+#       define RADEON_FP_RMX_HVSYNC_CONTROL_EN (1 << 20)
+#       define RADEON_FP_DFP_SYNC_SEL          (1 << 21)
+#       define RADEON_FP_CRTC_LOCK_8DOT        (1 << 22)
+#       define RADEON_FP_CRT_SYNC_SEL          (1 << 23)
+#       define RADEON_FP_USE_SHADOW_EN         (1 << 24)
+#       define RADEON_FP_CRT_SYNC_ALT          (1 << 26)
+#define RADEON_FP2_GEN_CNTL                 0x0288
+#       define RADEON_FP2_BLANK_EN             (1 <<  1)
+#       define RADEON_FP2_ON                   (1 <<  2)
+#       define RADEON_FP2_PANEL_FORMAT         (1 <<  3)
+#       define RADEON_FP2_DETECT_SENSE         (1 <<  8)
+#       define R200_FP2_SOURCE_SEL_MASK        (3 << 10)
+#       define R200_FP2_SOURCE_SEL_CRTC1       (0 << 10)
+#       define R200_FP2_SOURCE_SEL_CRTC2       (1 << 10)
+#       define R200_FP2_SOURCE_SEL_RMX         (2 << 10)
+#       define R200_FP2_SOURCE_SEL_TRANS_UNIT  (3 << 10)
+#       define RADEON_FP2_SRC_SEL_MASK         (3 << 13)
+#       define RADEON_FP2_SRC_SEL_CRTC2        (1 << 13)
+#       define RADEON_FP2_FP_POL               (1 << 16)
+#       define RADEON_FP2_LP_POL               (1 << 17)
+#       define RADEON_FP2_SCK_POL              (1 << 18)
+#       define RADEON_FP2_LCD_CNTL_MASK        (7 << 19)
+#       define RADEON_FP2_PAD_FLOP_EN          (1 << 22)
+#       define RADEON_FP2_CRC_EN               (1 << 23)
+#       define RADEON_FP2_CRC_READ_EN          (1 << 24)
+#       define RADEON_FP2_DVO_EN               (1 << 25)
+#       define RADEON_FP2_DVO_RATE_SEL_SDR     (1 << 26)
+#       define R200_FP2_DVO_RATE_SEL_SDR       (1 << 27)
+#       define R300_FP2_DVO_CLOCK_MODE_SINGLE  (1 << 28)
+#       define R300_FP2_DVO_DUAL_CHANNEL_EN    (1 << 29)
+#define RADEON_FP_H_SYNC_STRT_WID           0x02c4
+#define RADEON_FP_H2_SYNC_STRT_WID          0x03c4
+#define RADEON_FP_HORZ_STRETCH              0x028c
+#define RADEON_FP_HORZ2_STRETCH             0x038c
+#       define RADEON_HORZ_STRETCH_RATIO_MASK 0xffff
+#       define RADEON_HORZ_STRETCH_RATIO_MAX  4096
+#       define RADEON_HORZ_PANEL_SIZE         (0x1ff   << 16)
+#       define RADEON_HORZ_PANEL_SHIFT        16
+#       define RADEON_HORZ_STRETCH_PIXREP     (0      << 25)
+#       define RADEON_HORZ_STRETCH_BLEND      (1      << 26)
+#       define RADEON_HORZ_STRETCH_ENABLE     (1      << 25)
+#       define RADEON_HORZ_AUTO_RATIO         (1      << 27)
+#       define RADEON_HORZ_FP_LOOP_STRETCH    (0x7    << 28)
+#       define RADEON_HORZ_AUTO_RATIO_INC     (1      << 31)
+#define RADEON_FP_HORZ_VERT_ACTIVE          0x0278
+#define RADEON_FP_V_SYNC_STRT_WID           0x02c8
+#define RADEON_FP_VERT_STRETCH              0x0290
+#define RADEON_FP_V2_SYNC_STRT_WID          0x03c8
+#define RADEON_FP_VERT2_STRETCH             0x0390
+#       define RADEON_VERT_PANEL_SIZE          (0xfff << 12)
+#       define RADEON_VERT_PANEL_SHIFT         12
+#       define RADEON_VERT_STRETCH_RATIO_MASK  0xfff
+#       define RADEON_VERT_STRETCH_RATIO_SHIFT 0
+#       define RADEON_VERT_STRETCH_RATIO_MAX   4096
+#       define RADEON_VERT_STRETCH_ENABLE      (1     << 25)
+#       define RADEON_VERT_STRETCH_LINEREP     (0     << 26)
+#       define RADEON_VERT_STRETCH_BLEND       (1     << 26)
+#       define RADEON_VERT_AUTO_RATIO_EN       (1     << 27)
+#       define RADEON_VERT_STRETCH_RESERVED    0xf1000000
+
+#define RADEON_GEN_INT_CNTL                 0x0040
+#define RADEON_GEN_INT_STATUS               0x0044
+#       define RADEON_VSYNC_INT_AK          (1 <<  2)
+#       define RADEON_VSYNC_INT             (1 <<  2)
+#       define RADEON_VSYNC2_INT_AK         (1 <<  6)
+#       define RADEON_VSYNC2_INT            (1 <<  6)
+#define RADEON_GENENB                       0x03c3 /* VGA */
+#define RADEON_GENFC_RD                     0x03ca /* VGA */
+#define RADEON_GENFC_WT                     0x03da /* VGA, 0x03ba */
+#define RADEON_GENMO_RD                     0x03cc /* VGA */
+#define RADEON_GENMO_WT                     0x03c2 /* VGA */
+#define RADEON_GENS0                        0x03c2 /* VGA */
+#define RADEON_GENS1                        0x03da /* VGA, 0x03ba */
+#define RADEON_GPIO_MONID                   0x0068 /* DDC interface via I2C */
+#define RADEON_GPIO_MONIDB                  0x006c
+#define RADEON_GPIO_CRT2_DDC                0x006c
+#define RADEON_GPIO_DVI_DDC                 0x0064
+#define RADEON_GPIO_VGA_DDC                 0x0060
+#       define RADEON_GPIO_A_0              (1 <<  0)
+#       define RADEON_GPIO_A_1              (1 <<  1)
+#       define RADEON_GPIO_Y_0              (1 <<  8)
+#       define RADEON_GPIO_Y_1              (1 <<  9)
+#       define RADEON_GPIO_Y_SHIFT_0        8
+#       define RADEON_GPIO_Y_SHIFT_1        9
+#       define RADEON_GPIO_EN_0             (1 << 16)
+#       define RADEON_GPIO_EN_1             (1 << 17)
+#       define RADEON_GPIO_MASK_0           (1 << 24) /*??*/
+#       define RADEON_GPIO_MASK_1           (1 << 25) /*??*/
+#define RADEON_GRPH8_DATA                   0x03cf /* VGA */
+#define RADEON_GRPH8_IDX                    0x03ce /* VGA */
+#define RADEON_GUI_SCRATCH_REG0             0x15e0
+#define RADEON_GUI_SCRATCH_REG1             0x15e4
+#define RADEON_GUI_SCRATCH_REG2             0x15e8
+#define RADEON_GUI_SCRATCH_REG3             0x15ec
+#define RADEON_GUI_SCRATCH_REG4             0x15f0
+#define RADEON_GUI_SCRATCH_REG5             0x15f4
+
+#define RADEON_HEADER                       0x0f0e /* PCI */
+#define RADEON_HOST_DATA0                   0x17c0
+#define RADEON_HOST_DATA1                   0x17c4
+#define RADEON_HOST_DATA2                   0x17c8
+#define RADEON_HOST_DATA3                   0x17cc
+#define RADEON_HOST_DATA4                   0x17d0
+#define RADEON_HOST_DATA5                   0x17d4
+#define RADEON_HOST_DATA6                   0x17d8
+#define RADEON_HOST_DATA7                   0x17dc
+#define RADEON_HOST_DATA_LAST               0x17e0
+#define RADEON_HOST_PATH_CNTL               0x0130
+#       define RADEON_HDP_SOFT_RESET        (1 << 26)
+#       define RADEON_HDP_APER_CNTL         (1 << 23)
+#define RADEON_HTOTAL_CNTL                  0x0009 /* PLL */
+#       define RADEON_HTOT_CNTL_VGA_EN      (1 << 28)
+#define RADEON_HTOTAL2_CNTL                 0x002e /* PLL */
+
+       /* Multimedia I2C bus */
+#define RADEON_I2C_CNTL_0		    0x0090
+#define RADEON_I2C_DONE (1<<0)
+#define RADEON_I2C_NACK (1<<1)
+#define RADEON_I2C_HALT (1<<2)
+#define RADEON_I2C_SOFT_RST (1<<5)
+#define RADEON_I2C_DRIVE_EN (1<<6)
+#define RADEON_I2C_DRIVE_SEL (1<<7)
+#define RADEON_I2C_START (1<<8)
+#define RADEON_I2C_STOP (1<<9)
+#define RADEON_I2C_RECEIVE (1<<10)
+#define RADEON_I2C_ABORT (1<<11)
+#define RADEON_I2C_GO (1<<12)
+#define RADEON_I2C_CNTL_1                   0x0094
+#define RADEON_I2C_SEL         (1<<16)
+#define RADEON_I2C_EN          (1<<17)
+#define RADEON_I2C_DATA			    0x0098
+
+#define RADEON_DVI_I2C_CNTL_0		    0x02e0
+#define RADEON_DVI_I2C_CNTL_1               0x02e4 /* ? */
+#define RADEON_DVI_I2C_DATA		    0x02e8
+
+#define RADEON_INTERRUPT_LINE               0x0f3c /* PCI */
+#define RADEON_INTERRUPT_PIN                0x0f3d /* PCI */
+#define RADEON_IO_BASE                      0x0f14 /* PCI */
+
+#define RADEON_LATENCY                      0x0f0d /* PCI */
+#define RADEON_LEAD_BRES_DEC                0x1608
+#define RADEON_LEAD_BRES_LNTH               0x161c
+#define RADEON_LEAD_BRES_LNTH_SUB           0x1624
+#define RADEON_LVDS_GEN_CNTL                0x02d0
+#       define RADEON_LVDS_ON               (1   <<  0)
+#       define RADEON_LVDS_DISPLAY_DIS      (1   <<  1)
+#       define RADEON_LVDS_PANEL_TYPE       (1   <<  2)
+#       define RADEON_LVDS_PANEL_FORMAT     (1   <<  3)
+#       define RADEON_LVDS_RST_FM           (1   <<  6)
+#       define RADEON_LVDS_EN               (1   <<  7)
+#       define RADEON_LVDS_BL_MOD_LEVEL_SHIFT 8
+#       define RADEON_LVDS_BL_MOD_LEVEL_MASK (0xff << 8)
+#       define RADEON_LVDS_BL_MOD_EN        (1   << 16)
+#       define RADEON_LVDS_DIGON            (1   << 18)
+#       define RADEON_LVDS_BLON             (1   << 19)
+#       define RADEON_LVDS_SEL_CRTC2        (1   << 23)
+#define RADEON_LVDS_PLL_CNTL                0x02d4
+#       define RADEON_HSYNC_DELAY_SHIFT     28
+#       define RADEON_HSYNC_DELAY_MASK      (0xf << 28)
+#       define RADEON_LVDS_PLL_EN           (1   << 16)
+#       define RADEON_LVDS_PLL_RESET        (1   << 17)
+#       define R300_LVDS_SRC_SEL_MASK       (3   << 18)
+#       define R300_LVDS_SRC_SEL_CRTC1      (0   << 18)
+#       define R300_LVDS_SRC_SEL_CRTC2      (1   << 18)
+#       define R300_LVDS_SRC_SEL_RMX        (2   << 18)
+
+#define RADEON_MAX_LATENCY                  0x0f3f /* PCI */
+#define RADEON_MC_AGP_LOCATION              0x014c
+#define RADEON_MC_FB_LOCATION               0x0148
+#define RADEON_DISPLAY_BASE_ADDR            0x23c
+#define RADEON_DISPLAY2_BASE_ADDR           0x33c
+#define RADEON_OV0_BASE_ADDR                0x43c
+#define RADEON_NB_TOM                       0x15c
+#define R300_MC_INIT_MISC_LAT_TIMER         0x180
+#define RADEON_MCLK_CNTL                    0x0012 /* PLL */
+#       define RADEON_FORCEON_MCLKA         (1 << 16)
+#       define RADEON_FORCEON_MCLKB         (1 << 17)
+#       define RADEON_FORCEON_YCLKA         (1 << 18)
+#       define RADEON_FORCEON_YCLKB         (1 << 19)
+#       define RADEON_FORCEON_MC            (1 << 20)
+#       define RADEON_FORCEON_AIC           (1 << 21)
+#       define R300_DISABLE_MC_MCLKA        (1 << 21)
+#       define R300_DISABLE_MC_MCLKB        (1 << 21)
+#define RADEON_MCLK_MISC                    0x001f /* PLL */
+#       define RADEON_MC_MCLK_MAX_DYN_STOP_LAT (1 << 12)
+#       define RADEON_IO_MCLK_MAX_DYN_STOP_LAT (1 << 13)
+#       define RADEON_MC_MCLK_DYN_ENABLE    (1 << 14)
+#       define RADEON_IO_MCLK_DYN_ENABLE    (1 << 15)
+#define RADEON_LCD_GPIO_MASK                0x01a0
+#define RADEON_LCD_GPIO_Y_REG               0x01a4
+#define RADEON_MDGPIO_A_REG                 0x01ac
+#define RADEON_MDGPIO_EN_REG                0x01b0
+#define RADEON_MDGPIO_MASK                  0x0198
+#define RADEON_GPIOPAD_A		    0x019c
+#define RADEON_MDGPIO_Y_REG                 0x01b4
+#define RADEON_MEM_ADDR_CONFIG              0x0148
+#define RADEON_MEM_BASE                     0x0f10 /* PCI */
+#define RADEON_MEM_CNTL                     0x0140
+#       define RADEON_MEM_NUM_CHANNELS_MASK 0x01
+#       define RADEON_MEM_USE_B_CH_ONLY     (1 <<  1)
+#       define RV100_HALF_MODE              (1 <<  3)
+#       define R300_MEM_NUM_CHANNELS_MASK   0x03
+#       define R300_MEM_USE_CD_CH_ONLY      (1 <<  2)
+#define RADEON_MEM_TIMING_CNTL              0x0144 /* EXT_MEM_CNTL */
+#define RADEON_MEM_INIT_LAT_TIMER           0x0154
+#define RADEON_MEM_INTF_CNTL                0x014c
+#define RADEON_MEM_SDRAM_MODE_REG           0x0158
+#       define RADEON_SDRAM_MODE_MASK       0xffff0000
+#       define RADEON_B3MEM_RESET_MASK      0x6fffffff
+#define RADEON_MEM_STR_CNTL                 0x0150
+#       define RADEON_MEM_PWRUP_COMPL_A     (1 <<  0)
+#       define RADEON_MEM_PWRUP_COMPL_B     (1 <<  1)
+#       define R300_MEM_PWRUP_COMPL_C       (1 <<  2)
+#       define R300_MEM_PWRUP_COMPL_D       (1 <<  3)
+#       define RADEON_MEM_PWRUP_COMPLETE    0x03
+#       define R300_MEM_PWRUP_COMPLETE      0x0f
+#define RADEON_MC_STATUS                    0x0150
+#       define RADEON_MC_IDLE               (1 << 2)
+#       define R300_MC_IDLE                 (1 << 4)
+#define RADEON_MEM_VGA_RP_SEL               0x003c
+#define RADEON_MEM_VGA_WP_SEL               0x0038
+#define RADEON_MIN_GRANT                    0x0f3e /* PCI */
+#define RADEON_MM_DATA                      0x0004
+#define RADEON_MM_INDEX                     0x0000
+#define RADEON_MPLL_CNTL                    0x000e /* PLL */
+#define RADEON_MPP_TB_CONFIG                0x01c0 /* ? */
+#define RADEON_MPP_GP_CONFIG                0x01c8 /* ? */
+#define R300_MC_IND_INDEX                   0x01f8
+#       define R300_MC_IND_ADDR_MASK        0x3f
+#       define R300_MC_IND_WR_EN            (1 << 8)
+#define R300_MC_IND_DATA                    0x01fc
+#define R300_MC_READ_CNTL_AB                0x017c
+#       define R300_MEM_RBS_POSITION_A_MASK 0x03
+#define R300_MC_READ_CNTL_CD_mcind	    0x24
+#       define R300_MEM_RBS_POSITION_C_MASK 0x03
+
+#define RADEON_N_VIF_COUNT                  0x0248
+
+#define RADEON_OV0_AUTO_FLIP_CNTL           0x0470
+#       define  RADEON_OV0_AUTO_FLIP_CNTL_SOFT_BUF_NUM        0x00000007
+#       define  RADEON_OV0_AUTO_FLIP_CNTL_SOFT_REPEAT_FIELD   0x00000008
+#       define  RADEON_OV0_AUTO_FLIP_CNTL_SOFT_BUF_ODD        0x00000010
+#       define  RADEON_OV0_AUTO_FLIP_CNTL_IGNORE_REPEAT_FIELD 0x00000020
+#       define  RADEON_OV0_AUTO_FLIP_CNTL_SOFT_EOF_TOGGLE     0x00000040
+#       define  RADEON_OV0_AUTO_FLIP_CNTL_VID_PORT_SELECT     0x00000300
+#       define  RADEON_OV0_AUTO_FLIP_CNTL_P1_FIRST_LINE_EVEN  0x00010000
+#       define  RADEON_OV0_AUTO_FLIP_CNTL_SHIFT_EVEN_DOWN     0x00040000
+#       define  RADEON_OV0_AUTO_FLIP_CNTL_SHIFT_ODD_DOWN      0x00080000
+#       define  RADEON_OV0_AUTO_FLIP_CNTL_FIELD_POL_SOURCE    0x00800000
+
+#define RADEON_OV0_COLOUR_CNTL              0x04E0
+#define RADEON_OV0_DEINTERLACE_PATTERN      0x0474
+#define RADEON_OV0_EXCLUSIVE_HORZ           0x0408
+#       define  RADEON_EXCL_HORZ_START_MASK        0x000000ff
+#       define  RADEON_EXCL_HORZ_END_MASK          0x0000ff00
+#       define  RADEON_EXCL_HORZ_BACK_PORCH_MASK   0x00ff0000
+#       define  RADEON_EXCL_HORZ_EXCLUSIVE_EN      0x80000000
+#define RADEON_OV0_EXCLUSIVE_VERT           0x040C
+#       define  RADEON_EXCL_VERT_START_MASK        0x000003ff
+#       define  RADEON_EXCL_VERT_END_MASK          0x03ff0000
+#define RADEON_OV0_FILTER_CNTL              0x04A0
+#       define RADEON_FILTER_PROGRAMMABLE_COEF            0x0
+#       define RADEON_FILTER_HC_COEF_HORZ_Y               0x1
+#       define RADEON_FILTER_HC_COEF_HORZ_UV              0x2
+#       define RADEON_FILTER_HC_COEF_VERT_Y               0x4
+#       define RADEON_FILTER_HC_COEF_VERT_UV              0x8
+#       define RADEON_FILTER_HARDCODED_COEF               0xf
+#       define RADEON_FILTER_COEF_MASK                    0xf
+
+#define RADEON_OV0_FOUR_TAP_COEF_0          0x04B0
+#define RADEON_OV0_FOUR_TAP_COEF_1          0x04B4
+#define RADEON_OV0_FOUR_TAP_COEF_2          0x04B8
+#define RADEON_OV0_FOUR_TAP_COEF_3          0x04BC
+#define RADEON_OV0_FOUR_TAP_COEF_4          0x04C0
+#define RADEON_OV0_FLAG_CNTL                0x04DC
+#define RADEON_OV0_GAMMA_000_00F            0x0d40
+#define RADEON_OV0_GAMMA_010_01F            0x0d44
+#define RADEON_OV0_GAMMA_020_03F            0x0d48
+#define RADEON_OV0_GAMMA_040_07F            0x0d4c
+#define RADEON_OV0_GAMMA_080_0BF            0x0e00
+#define RADEON_OV0_GAMMA_0C0_0FF            0x0e04
+#define RADEON_OV0_GAMMA_100_13F            0x0e08
+#define RADEON_OV0_GAMMA_140_17F            0x0e0c
+#define RADEON_OV0_GAMMA_180_1BF            0x0e10
+#define RADEON_OV0_GAMMA_1C0_1FF            0x0e14
+#define RADEON_OV0_GAMMA_200_23F            0x0e18
+#define RADEON_OV0_GAMMA_240_27F            0x0e1c
+#define RADEON_OV0_GAMMA_280_2BF            0x0e20
+#define RADEON_OV0_GAMMA_2C0_2FF            0x0e24
+#define RADEON_OV0_GAMMA_300_33F            0x0e28
+#define RADEON_OV0_GAMMA_340_37F            0x0e2c
+#define RADEON_OV0_GAMMA_380_3BF            0x0d50
+#define RADEON_OV0_GAMMA_3C0_3FF            0x0d54
+#define RADEON_OV0_GRAPHICS_KEY_CLR_LOW     0x04EC
+#define RADEON_OV0_GRAPHICS_KEY_CLR_HIGH    0x04F0
+#define RADEON_OV0_H_INC                    0x0480
+#define RADEON_OV0_KEY_CNTL                 0x04F4
+#       define  RADEON_VIDEO_KEY_FN_MASK    0x00000003L
+#       define  RADEON_VIDEO_KEY_FN_FALSE   0x00000000L
+#       define  RADEON_VIDEO_KEY_FN_TRUE    0x00000001L
+#       define  RADEON_VIDEO_KEY_FN_EQ      0x00000002L
+#       define  RADEON_VIDEO_KEY_FN_NE      0x00000003L
+#       define  RADEON_GRAPHIC_KEY_FN_MASK  0x00000030L
+#       define  RADEON_GRAPHIC_KEY_FN_FALSE 0x00000000L
+#       define  RADEON_GRAPHIC_KEY_FN_TRUE  0x00000010L
+#       define  RADEON_GRAPHIC_KEY_FN_EQ    0x00000020L
+#       define  RADEON_GRAPHIC_KEY_FN_NE    0x00000030L
+#       define  RADEON_CMP_MIX_MASK         0x00000100L
+#       define  RADEON_CMP_MIX_OR           0x00000000L
+#       define  RADEON_CMP_MIX_AND          0x00000100L
+#define RADEON_OV0_LIN_TRANS_A              0x0d20
+#define RADEON_OV0_LIN_TRANS_B              0x0d24
+#define RADEON_OV0_LIN_TRANS_C              0x0d28
+#define RADEON_OV0_LIN_TRANS_D              0x0d2c
+#define RADEON_OV0_LIN_TRANS_E              0x0d30
+#define RADEON_OV0_LIN_TRANS_F              0x0d34
+#define RADEON_OV0_P1_BLANK_LINES_AT_TOP    0x0430
+#       define  RADEON_P1_BLNK_LN_AT_TOP_M1_MASK   0x00000fffL
+#       define  RADEON_P1_ACTIVE_LINES_M1          0x0fff0000L
+#define RADEON_OV0_P1_H_ACCUM_INIT          0x0488
+#define RADEON_OV0_P1_V_ACCUM_INIT          0x0428
+#       define  RADEON_OV0_P1_MAX_LN_IN_PER_LN_OUT 0x00000003L
+#       define  RADEON_OV0_P1_V_ACCUM_INIT_MASK    0x01ff8000L
+#define RADEON_OV0_P1_X_START_END           0x0494
+#define RADEON_OV0_P2_X_START_END           0x0498
+#define RADEON_OV0_P23_BLANK_LINES_AT_TOP   0x0434
+#       define  RADEON_P23_BLNK_LN_AT_TOP_M1_MASK  0x000007ffL
+#       define  RADEON_P23_ACTIVE_LINES_M1         0x07ff0000L
+#define RADEON_OV0_P23_H_ACCUM_INIT         0x048C
+#define RADEON_OV0_P23_V_ACCUM_INIT         0x042C
+#define RADEON_OV0_P3_X_START_END           0x049C
+#define RADEON_OV0_REG_LOAD_CNTL            0x0410
+#       define  RADEON_REG_LD_CTL_LOCK                 0x00000001L
+#       define  RADEON_REG_LD_CTL_VBLANK_DURING_LOCK   0x00000002L
+#       define  RADEON_REG_LD_CTL_STALL_GUI_UNTIL_FLIP 0x00000004L
+#       define  RADEON_REG_LD_CTL_LOCK_READBACK        0x00000008L
+#       define  RADEON_REG_LD_CTL_FLIP_READBACK        0x00000010L
+#define RADEON_OV0_SCALE_CNTL               0x0420
+#       define  RADEON_SCALER_HORZ_PICK_NEAREST    0x00000004L
+#       define  RADEON_SCALER_VERT_PICK_NEAREST    0x00000008L
+#       define  RADEON_SCALER_SIGNED_UV            0x00000010L
+#       define  RADEON_SCALER_GAMMA_SEL_MASK       0x00000060L
+#       define  RADEON_SCALER_GAMMA_SEL_BRIGHT     0x00000000L
+#       define  RADEON_SCALER_GAMMA_SEL_G22        0x00000020L
+#       define  RADEON_SCALER_GAMMA_SEL_G18        0x00000040L
+#       define  RADEON_SCALER_GAMMA_SEL_G14        0x00000060L
+#       define  RADEON_SCALER_COMCORE_SHIFT_UP_ONE 0x00000080L
+#       define  RADEON_SCALER_SURFAC_FORMAT        0x00000f00L
+#       define  RADEON_SCALER_SOURCE_15BPP         0x00000300L
+#       define  RADEON_SCALER_SOURCE_16BPP         0x00000400L
+#       define  RADEON_SCALER_SOURCE_32BPP         0x00000600L
+#       define  RADEON_SCALER_SOURCE_YUV9          0x00000900L
+#       define  RADEON_SCALER_SOURCE_YUV12         0x00000A00L
+#       define  RADEON_SCALER_SOURCE_VYUY422       0x00000B00L
+#       define  RADEON_SCALER_SOURCE_YVYU422       0x00000C00L
+#       define  RADEON_SCALER_ADAPTIVE_DEINT       0x00001000L
+#       define  RADEON_SCALER_TEMPORAL_DEINT       0x00002000L
+#       define  RADEON_SCALER_CRTC_SEL             0x00004000L
+#       define  RADEON_SCALER_SMART_SWITCH         0x00008000L
+#       define  RADEON_SCALER_BURST_PER_PLANE      0x007F0000L
+#       define  RADEON_SCALER_DOUBLE_BUFFER        0x01000000L
+#       define  RADEON_SCALER_DIS_LIMIT            0x08000000L
+#       define  RADEON_SCALER_LIN_TRANS_BYPASS     0x10000000L
+#       define  RADEON_SCALER_INT_EMU              0x20000000L
+#       define  RADEON_SCALER_ENABLE               0x40000000L
+#       define  RADEON_SCALER_SOFT_RESET           0x80000000L
+#define RADEON_OV0_STEP_BY                  0x0484
+#define RADEON_OV0_TEST                     0x04F8
+#define RADEON_OV0_V_INC                    0x0424
+#define RADEON_OV0_VID_BUF_PITCH0_VALUE     0x0460
+#define RADEON_OV0_VID_BUF_PITCH1_VALUE     0x0464
+#define RADEON_OV0_VID_BUF0_BASE_ADRS       0x0440
+#       define  RADEON_VIF_BUF0_PITCH_SEL          0x00000001L
+#       define  RADEON_VIF_BUF0_TILE_ADRS          0x00000002L
+#       define  RADEON_VIF_BUF0_BASE_ADRS_MASK     0x03fffff0L
+#       define  RADEON_VIF_BUF0_1ST_LINE_LSBS_MASK 0x48000000L
+#define RADEON_OV0_VID_BUF1_BASE_ADRS       0x0444
+#       define  RADEON_VIF_BUF1_PITCH_SEL          0x00000001L
+#       define  RADEON_VIF_BUF1_TILE_ADRS          0x00000002L
+#       define  RADEON_VIF_BUF1_BASE_ADRS_MASK     0x03fffff0L
+#       define  RADEON_VIF_BUF1_1ST_LINE_LSBS_MASK 0x48000000L
+#define RADEON_OV0_VID_BUF2_BASE_ADRS       0x0448
+#       define  RADEON_VIF_BUF2_PITCH_SEL          0x00000001L
+#       define  RADEON_VIF_BUF2_TILE_ADRS          0x00000002L
+#       define  RADEON_VIF_BUF2_BASE_ADRS_MASK     0x03fffff0L
+#       define  RADEON_VIF_BUF2_1ST_LINE_LSBS_MASK 0x48000000L
+#define RADEON_OV0_VID_BUF3_BASE_ADRS       0x044C
+#define RADEON_OV0_VID_BUF4_BASE_ADRS       0x0450
+#define RADEON_OV0_VID_BUF5_BASE_ADRS       0x0454
+#define RADEON_OV0_VIDEO_KEY_CLR_HIGH       0x04E8
+#define RADEON_OV0_VIDEO_KEY_CLR_LOW        0x04E4
+#define RADEON_OV0_Y_X_START                0x0400
+#define RADEON_OV0_Y_X_END                  0x0404
+#define RADEON_OV1_Y_X_START                0x0600
+#define RADEON_OV1_Y_X_END                  0x0604
+#define RADEON_OVR_CLR                      0x0230
+#define RADEON_OVR_WID_LEFT_RIGHT           0x0234
+#define RADEON_OVR_WID_TOP_BOTTOM           0x0238
+
+/* first capture unit */
+
+#define RADEON_CAP0_BUF0_OFFSET           0x0920
+#define RADEON_CAP0_BUF1_OFFSET           0x0924
+#define RADEON_CAP0_BUF0_EVEN_OFFSET      0x0928
+#define RADEON_CAP0_BUF1_EVEN_OFFSET      0x092C
+
+#define RADEON_CAP0_BUF_PITCH             0x0930
+#define RADEON_CAP0_V_WINDOW              0x0934
+#define RADEON_CAP0_H_WINDOW              0x0938
+#define RADEON_CAP0_VBI0_OFFSET           0x093C
+#define RADEON_CAP0_VBI1_OFFSET           0x0940
+#define RADEON_CAP0_VBI_V_WINDOW          0x0944
+#define RADEON_CAP0_VBI_H_WINDOW          0x0948
+#define RADEON_CAP0_PORT_MODE_CNTL        0x094C
+#define RADEON_CAP0_TRIG_CNTL             0x0950
+#define RADEON_CAP0_DEBUG                 0x0954
+#define RADEON_CAP0_CONFIG                0x0958
+#       define RADEON_CAP0_CONFIG_CONTINUOS          0x00000001
+#       define RADEON_CAP0_CONFIG_START_FIELD_EVEN   0x00000002
+#       define RADEON_CAP0_CONFIG_START_BUF_GET      0x00000004
+#       define RADEON_CAP0_CONFIG_START_BUF_SET      0x00000008
+#       define RADEON_CAP0_CONFIG_BUF_TYPE_ALT       0x00000010
+#       define RADEON_CAP0_CONFIG_BUF_TYPE_FRAME     0x00000020
+#       define RADEON_CAP0_CONFIG_ONESHOT_MODE_FRAME 0x00000040
+#       define RADEON_CAP0_CONFIG_BUF_MODE_DOUBLE    0x00000080
+#       define RADEON_CAP0_CONFIG_BUF_MODE_TRIPLE    0x00000100
+#       define RADEON_CAP0_CONFIG_MIRROR_EN          0x00000200
+#       define RADEON_CAP0_CONFIG_ONESHOT_MIRROR_EN  0x00000400
+#       define RADEON_CAP0_CONFIG_VIDEO_SIGNED_UV    0x00000800
+#       define RADEON_CAP0_CONFIG_ANC_DECODE_EN      0x00001000
+#       define RADEON_CAP0_CONFIG_VBI_EN             0x00002000
+#       define RADEON_CAP0_CONFIG_SOFT_PULL_DOWN_EN  0x00004000
+#       define RADEON_CAP0_CONFIG_VIP_EXTEND_FLAG_EN 0x00008000
+#       define RADEON_CAP0_CONFIG_FAKE_FIELD_EN      0x00010000
+#       define RADEON_CAP0_CONFIG_ODD_ONE_MORE_LINE  0x00020000
+#       define RADEON_CAP0_CONFIG_EVEN_ONE_MORE_LINE 0x00040000
+#       define RADEON_CAP0_CONFIG_HORZ_DIVIDE_2      0x00080000
+#       define RADEON_CAP0_CONFIG_HORZ_DIVIDE_4      0x00100000
+#       define RADEON_CAP0_CONFIG_VERT_DIVIDE_2      0x00200000
+#       define RADEON_CAP0_CONFIG_VERT_DIVIDE_4      0x00400000
+#       define RADEON_CAP0_CONFIG_FORMAT_BROOKTREE   0x00000000
+#       define RADEON_CAP0_CONFIG_FORMAT_CCIR656     0x00800000
+#       define RADEON_CAP0_CONFIG_FORMAT_ZV          0x01000000
+#       define RADEON_CAP0_CONFIG_FORMAT_VIP         0x01800000
+#       define RADEON_CAP0_CONFIG_FORMAT_TRANSPORT   0x02000000
+#       define RADEON_CAP0_CONFIG_HORZ_DECIMATOR     0x04000000
+#       define RADEON_CAP0_CONFIG_VIDEO_IN_YVYU422   0x00000000
+#       define RADEON_CAP0_CONFIG_VIDEO_IN_VYUY422   0x20000000
+#       define RADEON_CAP0_CONFIG_VBI_DIVIDE_2       0x40000000
+#       define RADEON_CAP0_CONFIG_VBI_DIVIDE_4       0x80000000
+#define RADEON_CAP0_ANC_ODD_OFFSET        0x095C
+#define RADEON_CAP0_ANC_EVEN_OFFSET       0x0960
+#define RADEON_CAP0_ANC_H_WINDOW          0x0964
+#define RADEON_CAP0_VIDEO_SYNC_TEST       0x0968
+#define RADEON_CAP0_ONESHOT_BUF_OFFSET    0x096C
+#define RADEON_CAP0_BUF_STATUS            0x0970
+/* #define RADEON_CAP0_DWNSC_XRATIO       0x0978 */
+/* #define RADEON_CAP0_XSHARPNESS                 0x097C */
+#define RADEON_CAP0_VBI2_OFFSET           0x0980
+#define RADEON_CAP0_VBI3_OFFSET           0x0984
+#define RADEON_CAP0_ANC2_OFFSET           0x0988
+#define RADEON_CAP0_ANC3_OFFSET           0x098C
+#define RADEON_VID_BUFFER_CONTROL         0x0900
+
+/* second capture unit */
+
+#define RADEON_CAP1_BUF0_OFFSET           0x0990
+#define RADEON_CAP1_BUF1_OFFSET           0x0994
+#define RADEON_CAP1_BUF0_EVEN_OFFSET      0x0998
+#define RADEON_CAP1_BUF1_EVEN_OFFSET      0x099C
+
+#define RADEON_CAP1_BUF_PITCH             0x09A0
+#define RADEON_CAP1_V_WINDOW              0x09A4
+#define RADEON_CAP1_H_WINDOW              0x09A8
+#define RADEON_CAP1_VBI_ODD_OFFSET        0x09AC
+#define RADEON_CAP1_VBI_EVEN_OFFSET       0x09B0
+#define RADEON_CAP1_VBI_V_WINDOW                  0x09B4
+#define RADEON_CAP1_VBI_H_WINDOW                  0x09B8
+#define RADEON_CAP1_PORT_MODE_CNTL        0x09BC
+#define RADEON_CAP1_TRIG_CNTL             0x09C0
+#define RADEON_CAP1_DEBUG                         0x09C4
+#define RADEON_CAP1_CONFIG                0x09C8
+#define RADEON_CAP1_ANC_ODD_OFFSET        0x09CC
+#define RADEON_CAP1_ANC_EVEN_OFFSET       0x09D0
+#define RADEON_CAP1_ANC_H_WINDOW                  0x09D4
+#define RADEON_CAP1_VIDEO_SYNC_TEST       0x09D8
+#define RADEON_CAP1_ONESHOT_BUF_OFFSET    0x09DC
+#define RADEON_CAP1_BUF_STATUS            0x09E0
+#define RADEON_CAP1_DWNSC_XRATIO                  0x09E8
+#define RADEON_CAP1_XSHARPNESS            0x09EC
+
+/* misc multimedia registers */
+
+#define RADEON_IDCT_RUNS                  0x1F80
+#define RADEON_IDCT_LEVELS                0x1F84
+#define RADEON_IDCT_CONTROL               0x1FBC
+#define RADEON_IDCT_AUTH_CONTROL          0x1F88
+#define RADEON_IDCT_AUTH                  0x1F8C
+
+#define RADEON_P2PLL_CNTL                   0x002a /* P2PLL */
+#       define RADEON_P2PLL_RESET                (1 <<  0)
+#       define RADEON_P2PLL_SLEEP                (1 <<  1)
+#       define RADEON_P2PLL_PVG_MASK             (7 << 11)
+#       define RADEON_P2PLL_PVG_SHIFT            11
+#       define RADEON_P2PLL_ATOMIC_UPDATE_EN     (1 << 16)
+#       define RADEON_P2PLL_VGA_ATOMIC_UPDATE_EN (1 << 17)
+#       define RADEON_P2PLL_ATOMIC_UPDATE_VSYNC  (1 << 18)
+#define RADEON_P2PLL_DIV_0                  0x002c
+#       define RADEON_P2PLL_FB0_DIV_MASK    0x07ff
+#       define RADEON_P2PLL_POST0_DIV_MASK  0x00070000
+#define RADEON_P2PLL_REF_DIV                0x002B /* PLL */
+#       define RADEON_P2PLL_REF_DIV_MASK    0x03ff
+#       define RADEON_P2PLL_ATOMIC_UPDATE_R (1 << 15) /* same as _W */
+#       define RADEON_P2PLL_ATOMIC_UPDATE_W (1 << 15) /* same as _R */
+#       define R300_PPLL_REF_DIV_ACC_MASK   (0x3ff << 18)
+#       define R300_PPLL_REF_DIV_ACC_SHIFT  18
+#define RADEON_PALETTE_DATA                 0x00b4
+#define RADEON_PALETTE_30_DATA              0x00b8
+#define RADEON_PALETTE_INDEX                0x00b0
+#define RADEON_PCI_GART_PAGE                0x017c
+#define RADEON_PIXCLKS_CNTL                 0x002d
+#       define RADEON_PIX2CLK_SRC_SEL_MASK     0x03
+#       define RADEON_PIX2CLK_SRC_SEL_CPUCLK   0x00
+#       define RADEON_PIX2CLK_SRC_SEL_PSCANCLK 0x01
+#       define RADEON_PIX2CLK_SRC_SEL_BYTECLK  0x02
+#       define RADEON_PIX2CLK_SRC_SEL_P2PLLCLK 0x03
+#       define RADEON_PIX2CLK_ALWAYS_ONb       (1<<6)
+#       define RADEON_PIX2CLK_DAC_ALWAYS_ONb   (1<<7)
+#       define RADEON_PIXCLK_TV_SRC_SEL        (1 << 8)
+#       define RADEON_DISP_TVOUT_PIXCLK_TV_ALWAYS_ONb (1 << 9)
+#       define R300_DVOCLK_ALWAYS_ONb          (1 << 10)
+#       define RADEON_PIXCLK_BLEND_ALWAYS_ONb  (1 << 11)
+#       define RADEON_PIXCLK_GV_ALWAYS_ONb     (1 << 12)
+#       define RADEON_PIXCLK_DIG_TMDS_ALWAYS_ONb (1 << 13)
+#       define R300_PIXCLK_DVO_ALWAYS_ONb      (1 << 13)
+#       define RADEON_PIXCLK_LVDS_ALWAYS_ONb   (1 << 14)
+#       define RADEON_PIXCLK_TMDS_ALWAYS_ONb   (1 << 15)
+#       define R300_PIXCLK_TRANS_ALWAYS_ONb    (1 << 16)
+#       define R300_PIXCLK_TVO_ALWAYS_ONb      (1 << 17)
+#       define R300_P2G2CLK_ALWAYS_ONb         (1 << 18)
+#       define R300_P2G2CLK_DAC_ALWAYS_ONb     (1 << 19)
+#       define R300_DISP_DAC_PIXCLK_DAC2_BLANK_OFF (1 << 23)
+#define RADEON_PLANE_3D_MASK_C              0x1d44
+#define RADEON_PLL_TEST_CNTL                0x0013 /* PLL */
+#       define RADEON_PLL_MASK_READ_B          (1 << 9)
+#define RADEON_PMI_CAP_ID                   0x0f5c /* PCI */
+#define RADEON_PMI_DATA                     0x0f63 /* PCI */
+#define RADEON_PMI_NXT_CAP_PTR              0x0f5d /* PCI */
+#define RADEON_PMI_PMC_REG                  0x0f5e /* PCI */
+#define RADEON_PMI_PMCSR_REG                0x0f60 /* PCI */
+#define RADEON_PMI_REGISTER                 0x0f5c /* PCI */
+#define RADEON_PPLL_CNTL                    0x0002 /* PLL */
+#       define RADEON_PPLL_RESET                (1 <<  0)
+#       define RADEON_PPLL_SLEEP                (1 <<  1)
+#       define RADEON_PPLL_PVG_MASK             (7 << 11)
+#       define RADEON_PPLL_PVG_SHIFT            11
+#       define RADEON_PPLL_ATOMIC_UPDATE_EN     (1 << 16)
+#       define RADEON_PPLL_VGA_ATOMIC_UPDATE_EN (1 << 17)
+#       define RADEON_PPLL_ATOMIC_UPDATE_VSYNC  (1 << 18)
+#define RADEON_PPLL_DIV_0                   0x0004 /* PLL */
+#define RADEON_PPLL_DIV_1                   0x0005 /* PLL */
+#define RADEON_PPLL_DIV_2                   0x0006 /* PLL */
+#define RADEON_PPLL_DIV_3                   0x0007 /* PLL */
+#       define RADEON_PPLL_FB3_DIV_MASK     0x07ff
+#       define RADEON_PPLL_POST3_DIV_MASK   0x00070000
+#define RADEON_PPLL_REF_DIV                 0x0003 /* PLL */
+#       define RADEON_PPLL_REF_DIV_MASK     0x03ff
+#       define RADEON_PPLL_ATOMIC_UPDATE_R  (1 << 15) /* same as _W */
+#       define RADEON_PPLL_ATOMIC_UPDATE_W  (1 << 15) /* same as _R */
+#define RADEON_PWR_MNGMT_CNTL_STATUS        0x0f60 /* PCI */
+
+#define RADEON_RBBM_GUICNTL                 0x172c
+#       define RADEON_HOST_DATA_SWAP_NONE   (0 << 0)
+#       define RADEON_HOST_DATA_SWAP_16BIT  (1 << 0)
+#       define RADEON_HOST_DATA_SWAP_32BIT  (2 << 0)
+#       define RADEON_HOST_DATA_SWAP_HDW    (3 << 0)
+#define RADEON_RBBM_SOFT_RESET              0x00f0
+#       define RADEON_SOFT_RESET_CP         (1 <<  0)
+#       define RADEON_SOFT_RESET_HI         (1 <<  1)
+#       define RADEON_SOFT_RESET_SE         (1 <<  2)
+#       define RADEON_SOFT_RESET_RE         (1 <<  3)
+#       define RADEON_SOFT_RESET_PP         (1 <<  4)
+#       define RADEON_SOFT_RESET_E2         (1 <<  5)
+#       define RADEON_SOFT_RESET_RB         (1 <<  6)
+#       define RADEON_SOFT_RESET_HDP        (1 <<  7)
+#define RADEON_RBBM_STATUS                  0x0e40
+#       define RADEON_RBBM_FIFOCNT_MASK     0x007f
+#       define RADEON_RBBM_ACTIVE           (1 << 31)
+#define RADEON_RB2D_DSTCACHE_CTLSTAT        0x342c
+#       define RADEON_RB2D_DC_FLUSH         (3 << 0)
+#       define RADEON_RB2D_DC_FREE          (3 << 2)
+#       define RADEON_RB2D_DC_FLUSH_ALL     0xf
+#       define RADEON_RB2D_DC_BUSY          (1 << 31)
+#define RADEON_RB2D_DSTCACHE_MODE           0x3428
+
+#define RADEON_RB3D_ZCACHE_MODE             0x3250
+#define RADEON_RB3D_ZCACHE_CTLSTAT          0x3254
+#       define RADEON_RB3D_ZC_FLUSH_ALL     0x5
+#define RADEON_RB3D_DSTCACHE_MODE           0x3258
+# define RADEON_RB3D_DC_CACHE_ENABLE            (0)
+# define RADEON_RB3D_DC_2D_CACHE_DISABLE        (1)
+# define RADEON_RB3D_DC_3D_CACHE_DISABLE        (2)
+# define RADEON_RB3D_DC_CACHE_DISABLE           (3)
+# define RADEON_RB3D_DC_2D_CACHE_LINESIZE_128   (1 << 2)
+# define RADEON_RB3D_DC_3D_CACHE_LINESIZE_128   (2 << 2)
+# define RADEON_RB3D_DC_2D_CACHE_AUTOFLUSH      (1 << 8)
+# define RADEON_RB3D_DC_3D_CACHE_AUTOFLUSH      (2 << 8)
+# define R200_RB3D_DC_2D_CACHE_AUTOFREE         (1 << 10)
+# define R200_RB3D_DC_3D_CACHE_AUTOFREE         (2 << 10)
+# define RADEON_RB3D_DC_FORCE_RMW               (1 << 16)
+# define RADEON_RB3D_DC_DISABLE_RI_FILL         (1 << 24)
+# define RADEON_RB3D_DC_DISABLE_RI_READ         (1 << 25)
+
+#define RADEON_RB3D_DSTCACHE_CTLSTAT            0x325C
+# define RADEON_RB3D_DC_FLUSH                   (3 << 0)
+# define RADEON_RB3D_DC_FREE                    (3 << 2)
+# define RADEON_RB3D_DC_FLUSH_ALL               0xf
+# define RADEON_RB3D_DC_BUSY                    (1 << 31)
+
+#define RADEON_REG_BASE                     0x0f18 /* PCI */
+#define RADEON_REGPROG_INF                  0x0f09 /* PCI */
+#define RADEON_REVISION_ID                  0x0f08 /* PCI */
+
+#define RADEON_SC_BOTTOM                    0x164c
+#define RADEON_SC_BOTTOM_RIGHT              0x16f0
+#define RADEON_SC_BOTTOM_RIGHT_C            0x1c8c
+#define RADEON_SC_LEFT                      0x1640
+#define RADEON_SC_RIGHT                     0x1644
+#define RADEON_SC_TOP                       0x1648
+#define RADEON_SC_TOP_LEFT                  0x16ec
+#define RADEON_SC_TOP_LEFT_C                0x1c88
+#       define RADEON_SC_SIGN_MASK_LO       0x8000
+#       define RADEON_SC_SIGN_MASK_HI       0x80000000
+#define RADEON_SCLK_CNTL                    0x000d /* PLL */
+#       define RADEON_SCLK_SRC_SEL_MASK     0x0007
+#       define RADEON_DYN_STOP_LAT_MASK     0x00007ff8
+#       define RADEON_CP_MAX_DYN_STOP_LAT   0x0008
+#       define RADEON_SCLK_FORCEON_MASK     0xffff8000
+#       define RADEON_SCLK_FORCE_DISP2      (1<<15)
+#       define RADEON_SCLK_FORCE_CP         (1<<16)
+#       define RADEON_SCLK_FORCE_HDP        (1<<17)
+#       define RADEON_SCLK_FORCE_DISP1      (1<<18)
+#       define RADEON_SCLK_FORCE_TOP        (1<<19)
+#       define RADEON_SCLK_FORCE_E2         (1<<20)
+#       define RADEON_SCLK_FORCE_SE         (1<<21)
+#       define RADEON_SCLK_FORCE_IDCT       (1<<22)
+#       define RADEON_SCLK_FORCE_VIP        (1<<23)
+#       define RADEON_SCLK_FORCE_RE         (1<<24)
+#       define RADEON_SCLK_FORCE_PB         (1<<25)
+#       define RADEON_SCLK_FORCE_TAM        (1<<26)
+#       define RADEON_SCLK_FORCE_TDM        (1<<27)
+#       define RADEON_SCLK_FORCE_RB         (1<<28)
+#       define RADEON_SCLK_FORCE_TV_SCLK    (1<<29)
+#       define RADEON_SCLK_FORCE_SUBPIC     (1<<30)
+#       define RADEON_SCLK_FORCE_OV0        (1<<31)
+#       define R300_SCLK_FORCE_VAP          (1<<21)
+#       define R300_SCLK_FORCE_SR           (1<<25)
+#       define R300_SCLK_FORCE_PX           (1<<26)
+#       define R300_SCLK_FORCE_TX           (1<<27)
+#       define R300_SCLK_FORCE_US           (1<<28)
+#       define R300_SCLK_FORCE_SU           (1<<30)
+#define R300_SCLK_CNTL2                     0x1e   /* PLL */
+#       define R300_SCLK_TCL_MAX_DYN_STOP_LAT (1<<10)
+#       define R300_SCLK_GA_MAX_DYN_STOP_LAT  (1<<11)
+#       define R300_SCLK_CBA_MAX_DYN_STOP_LAT (1<<12)
+#       define R300_SCLK_FORCE_TCL          (1<<13)
+#       define R300_SCLK_FORCE_CBA          (1<<14)
+#       define R300_SCLK_FORCE_GA           (1<<15)
+#define RADEON_SCLK_MORE_CNTL               0x0035 /* PLL */
+#       define RADEON_SCLK_MORE_MAX_DYN_STOP_LAT 0x0007
+#       define RADEON_SCLK_MORE_FORCEON     0x0700
+#define RADEON_SDRAM_MODE_REG               0x0158
+#define RADEON_SEQ8_DATA                    0x03c5 /* VGA */
+#define RADEON_SEQ8_IDX                     0x03c4 /* VGA */
+#define RADEON_SNAPSHOT_F_COUNT             0x0244
+#define RADEON_SNAPSHOT_VH_COUNTS           0x0240
+#define RADEON_SNAPSHOT_VIF_COUNT           0x024c
+#define RADEON_SRC_OFFSET                   0x15ac
+#define RADEON_SRC_PITCH                    0x15b0
+#define RADEON_SRC_PITCH_OFFSET             0x1428
+#define RADEON_SRC_SC_BOTTOM                0x165c
+#define RADEON_SRC_SC_BOTTOM_RIGHT          0x16f4
+#define RADEON_SRC_SC_RIGHT                 0x1654
+#define RADEON_SRC_X                        0x1414
+#define RADEON_SRC_X_Y                      0x1590
+#define RADEON_SRC_Y                        0x1418
+#define RADEON_SRC_Y_X                      0x1434
+#define RADEON_STATUS                       0x0f06 /* PCI */
+#define RADEON_SUBPIC_CNTL                  0x0540 /* ? */
+#define RADEON_SUB_CLASS                    0x0f0a /* PCI */
+#define RADEON_SURFACE_CNTL                 0x0b00
+#       define RADEON_SURF_TRANSLATION_DIS  (1 << 8)
+#       define RADEON_NONSURF_AP0_SWP_16BPP (1 << 20)
+#       define RADEON_NONSURF_AP0_SWP_32BPP (1 << 21)
+#       define RADEON_NONSURF_AP1_SWP_16BPP (1 << 22)
+#       define RADEON_NONSURF_AP1_SWP_32BPP (1 << 23)
+#define RADEON_SURFACE0_INFO                0x0b0c
+#       define RADEON_SURF_TILE_COLOR_MACRO (0 << 16)
+#       define RADEON_SURF_TILE_COLOR_BOTH  (1 << 16)
+#       define RADEON_SURF_TILE_DEPTH_32BPP (2 << 16)
+#       define RADEON_SURF_TILE_DEPTH_16BPP (3 << 16)
+#       define R200_SURF_TILE_NONE          (0 << 16)
+#       define R200_SURF_TILE_COLOR_MACRO   (1 << 16)
+#       define R200_SURF_TILE_COLOR_MICRO   (2 << 16)
+#       define R200_SURF_TILE_COLOR_BOTH    (3 << 16)
+#       define R200_SURF_TILE_DEPTH_32BPP   (4 << 16)
+#       define R200_SURF_TILE_DEPTH_16BPP   (5 << 16)
+#       define R300_SURF_TILE_NONE          (0 << 16)
+#       define R300_SURF_TILE_COLOR_MACRO   (1 << 16)
+#       define R300_SURF_TILE_DEPTH_32BPP   (2 << 16)
+#       define RADEON_SURF_AP0_SWP_16BPP    (1 << 20)
+#       define RADEON_SURF_AP0_SWP_32BPP    (1 << 21)
+#       define RADEON_SURF_AP1_SWP_16BPP    (1 << 22)
+#       define RADEON_SURF_AP1_SWP_32BPP    (1 << 23)
+#define RADEON_SURFACE0_LOWER_BOUND         0x0b04
+#define RADEON_SURFACE0_UPPER_BOUND         0x0b08
+#define RADEON_SURFACE1_INFO                0x0b1c
+#define RADEON_SURFACE1_LOWER_BOUND         0x0b14
+#define RADEON_SURFACE1_UPPER_BOUND         0x0b18
+#define RADEON_SURFACE2_INFO                0x0b2c
+#define RADEON_SURFACE2_LOWER_BOUND         0x0b24
+#define RADEON_SURFACE2_UPPER_BOUND         0x0b28
+#define RADEON_SURFACE3_INFO                0x0b3c
+#define RADEON_SURFACE3_LOWER_BOUND         0x0b34
+#define RADEON_SURFACE3_UPPER_BOUND         0x0b38
+#define RADEON_SURFACE4_INFO                0x0b4c
+#define RADEON_SURFACE4_LOWER_BOUND         0x0b44
+#define RADEON_SURFACE4_UPPER_BOUND         0x0b48
+#define RADEON_SURFACE5_INFO                0x0b5c
+#define RADEON_SURFACE5_LOWER_BOUND         0x0b54
+#define RADEON_SURFACE5_UPPER_BOUND         0x0b58
+#define RADEON_SURFACE6_INFO                0x0b6c
+#define RADEON_SURFACE6_LOWER_BOUND         0x0b64
+#define RADEON_SURFACE6_UPPER_BOUND         0x0b68
+#define RADEON_SURFACE7_INFO                0x0b7c
+#define RADEON_SURFACE7_LOWER_BOUND         0x0b74
+#define RADEON_SURFACE7_UPPER_BOUND         0x0b78
+#define RADEON_SW_SEMAPHORE                 0x013c
+
+#define RADEON_TEST_DEBUG_CNTL              0x0120
+#define RADEON_TEST_DEBUG_CNTL__TEST_DEBUG_OUT_EN 0x00000001
+
+#define RADEON_TEST_DEBUG_MUX               0x0124
+#define RADEON_TEST_DEBUG_OUT               0x012c
+#define RADEON_TMDS_PLL_CNTL                0x02a8
+#define RADEON_TMDS_TRANSMITTER_CNTL        0x02a4
+#       define RADEON_TMDS_TRANSMITTER_PLLEN  1
+#       define RADEON_TMDS_TRANSMITTER_PLLRST 2
+#define RADEON_TRAIL_BRES_DEC               0x1614
+#define RADEON_TRAIL_BRES_ERR               0x160c
+#define RADEON_TRAIL_BRES_INC               0x1610
+#define RADEON_TRAIL_X                      0x1618
+#define RADEON_TRAIL_X_SUB                  0x1620
+
+#define RADEON_VCLK_ECP_CNTL                0x0008 /* PLL */
+#       define RADEON_VCLK_SRC_SEL_MASK     0x03
+#       define RADEON_VCLK_SRC_SEL_CPUCLK   0x00
+#       define RADEON_VCLK_SRC_SEL_PSCANCLK 0x01
+#       define RADEON_VCLK_SRC_SEL_BYTECLK  0x02
+#       define RADEON_VCLK_SRC_SEL_PPLLCLK  0x03
+#       define RADEON_PIXCLK_ALWAYS_ONb     (1<<6)
+#       define RADEON_PIXCLK_DAC_ALWAYS_ONb (1<<7)
+#       define R300_DISP_DAC_PIXCLK_DAC_BLANK_OFF (1<<23)
+
+#define RADEON_VENDOR_ID                    0x0f00 /* PCI */
+#define RADEON_VGA_DDA_CONFIG               0x02e8
+#define RADEON_VGA_DDA_ON_OFF               0x02ec
+#define RADEON_VID_BUFFER_CONTROL           0x0900
+#define RADEON_VIDEOMUX_CNTL                0x0190
+
+                 /* VIP bus */
+#define RADEON_VIPH_CH0_DATA                0x0c00
+#define RADEON_VIPH_CH1_DATA                0x0c04
+#define RADEON_VIPH_CH2_DATA                0x0c08
+#define RADEON_VIPH_CH3_DATA                0x0c0c
+#define RADEON_VIPH_CH0_ADDR                0x0c10
+#define RADEON_VIPH_CH1_ADDR                0x0c14
+#define RADEON_VIPH_CH2_ADDR                0x0c18
+#define RADEON_VIPH_CH3_ADDR                0x0c1c
+#define RADEON_VIPH_CH0_SBCNT               0x0c20
+#define RADEON_VIPH_CH1_SBCNT               0x0c24
+#define RADEON_VIPH_CH2_SBCNT               0x0c28
+#define RADEON_VIPH_CH3_SBCNT               0x0c2c
+#define RADEON_VIPH_CH0_ABCNT               0x0c30
+#define RADEON_VIPH_CH1_ABCNT               0x0c34
+#define RADEON_VIPH_CH2_ABCNT               0x0c38
+#define RADEON_VIPH_CH3_ABCNT               0x0c3c
+#define RADEON_VIPH_CONTROL                 0x0c40
+#       define RADEON_VIP_BUSY 0
+#       define RADEON_VIP_IDLE 1
+#       define RADEON_VIP_RESET 2
+#define RADEON_VIPH_DV_LAT                  0x0c44
+#define RADEON_VIPH_BM_CHUNK                0x0c48
+#define RADEON_VIPH_DV_INT                  0x0c4c
+#define RADEON_VIPH_TIMEOUT_STAT            0x0c50
+#define RADEON_VIPH_TIMEOUT_STAT__VIPH_REG_STAT 0x00000010
+#define RADEON_VIPH_TIMEOUT_STAT__VIPH_REG_AK   0x00000010
+#define RADEON_VIPH_TIMEOUT_STAT__VIPH_REGR_DIS 0x01000000
+
+#define RADEON_VIPH_REG_DATA                0x0084
+#define RADEON_VIPH_REG_ADDR                0x0080
+
+
+#define RADEON_WAIT_UNTIL                   0x1720
+#       define RADEON_WAIT_CRTC_PFLIP       (1 << 0)
+#       define RADEON_WAIT_2D_IDLECLEAN     (1 << 16)
+#       define RADEON_WAIT_3D_IDLECLEAN     (1 << 17)
+#       define RADEON_WAIT_HOST_IDLECLEAN   (1 << 18)
+
+#define RADEON_X_MPLL_REF_FB_DIV            0x000a /* PLL */
+#define RADEON_XCLK_CNTL                    0x000d /* PLL */
+#define RADEON_XDLL_CNTL                    0x000c /* PLL */
+#define RADEON_XPLL_CNTL                    0x000b /* PLL */
+
+
+
+				/* Registers for 3D/TCL */
+#define RADEON_PP_BORDER_COLOR_0            0x1d40
+#define RADEON_PP_BORDER_COLOR_1            0x1d44
+#define RADEON_PP_BORDER_COLOR_2            0x1d48
+#define RADEON_PP_CNTL                      0x1c38
+#       define RADEON_STIPPLE_ENABLE        (1 <<  0)
+#       define RADEON_SCISSOR_ENABLE        (1 <<  1)
+#       define RADEON_PATTERN_ENABLE        (1 <<  2)
+#       define RADEON_SHADOW_ENABLE         (1 <<  3)
+#       define RADEON_TEX_ENABLE_MASK       (0xf << 4)
+#       define RADEON_TEX_0_ENABLE          (1 <<  4)
+#       define RADEON_TEX_1_ENABLE          (1 <<  5)
+#       define RADEON_TEX_2_ENABLE          (1 <<  6)
+#       define RADEON_TEX_3_ENABLE          (1 <<  7)
+#       define RADEON_TEX_BLEND_ENABLE_MASK (0xf << 12)
+#       define RADEON_TEX_BLEND_0_ENABLE    (1 << 12)
+#       define RADEON_TEX_BLEND_1_ENABLE    (1 << 13)
+#       define RADEON_TEX_BLEND_2_ENABLE    (1 << 14)
+#       define RADEON_TEX_BLEND_3_ENABLE    (1 << 15)
+#       define RADEON_PLANAR_YUV_ENABLE     (1 << 20)
+#       define RADEON_SPECULAR_ENABLE       (1 << 21)
+#       define RADEON_FOG_ENABLE            (1 << 22)
+#       define RADEON_ALPHA_TEST_ENABLE     (1 << 23)
+#       define RADEON_ANTI_ALIAS_NONE       (0 << 24)
+#       define RADEON_ANTI_ALIAS_LINE       (1 << 24)
+#       define RADEON_ANTI_ALIAS_POLY       (2 << 24)
+#       define RADEON_ANTI_ALIAS_LINE_POLY  (3 << 24)
+#       define RADEON_BUMP_MAP_ENABLE       (1 << 26)
+#       define RADEON_BUMPED_MAP_T0         (0 << 27)
+#       define RADEON_BUMPED_MAP_T1         (1 << 27)
+#       define RADEON_BUMPED_MAP_T2         (2 << 27)
+#       define RADEON_TEX_3D_ENABLE_0       (1 << 29)
+#       define RADEON_TEX_3D_ENABLE_1       (1 << 30)
+#       define RADEON_MC_ENABLE             (1 << 31)
+#define RADEON_PP_FOG_COLOR                 0x1c18
+#       define RADEON_FOG_COLOR_MASK        0x00ffffff
+#       define RADEON_FOG_VERTEX            (0 << 24)
+#       define RADEON_FOG_TABLE             (1 << 24)
+#       define RADEON_FOG_USE_DEPTH         (0 << 25)
+#       define RADEON_FOG_USE_DIFFUSE_ALPHA (2 << 25)
+#       define RADEON_FOG_USE_SPEC_ALPHA    (3 << 25)
+#define RADEON_PP_LUM_MATRIX                0x1d00
+#define RADEON_PP_MISC                      0x1c14
+#       define RADEON_REF_ALPHA_MASK        0x000000ff
+#       define RADEON_ALPHA_TEST_FAIL       (0 << 8)
+#       define RADEON_ALPHA_TEST_LESS       (1 << 8)
+#       define RADEON_ALPHA_TEST_LEQUAL     (2 << 8)
+#       define RADEON_ALPHA_TEST_EQUAL      (3 << 8)
+#       define RADEON_ALPHA_TEST_GEQUAL     (4 << 8)
+#       define RADEON_ALPHA_TEST_GREATER    (5 << 8)
+#       define RADEON_ALPHA_TEST_NEQUAL     (6 << 8)
+#       define RADEON_ALPHA_TEST_PASS       (7 << 8)
+#       define RADEON_ALPHA_TEST_OP_MASK    (7 << 8)
+#       define RADEON_CHROMA_FUNC_FAIL      (0 << 16)
+#       define RADEON_CHROMA_FUNC_PASS      (1 << 16)
+#       define RADEON_CHROMA_FUNC_NEQUAL    (2 << 16)
+#       define RADEON_CHROMA_FUNC_EQUAL     (3 << 16)
+#       define RADEON_CHROMA_KEY_NEAREST    (0 << 18)
+#       define RADEON_CHROMA_KEY_ZERO       (1 << 18)
+#       define RADEON_SHADOW_ID_AUTO_INC    (1 << 20)
+#       define RADEON_SHADOW_FUNC_EQUAL     (0 << 21)
+#       define RADEON_SHADOW_FUNC_NEQUAL    (1 << 21)
+#       define RADEON_SHADOW_PASS_1         (0 << 22)
+#       define RADEON_SHADOW_PASS_2         (1 << 22)
+#       define RADEON_RIGHT_HAND_CUBE_D3D   (0 << 24)
+#       define RADEON_RIGHT_HAND_CUBE_OGL   (1 << 24)
+#define RADEON_PP_ROT_MATRIX_0              0x1d58
+#define RADEON_PP_ROT_MATRIX_1              0x1d5c
+#define RADEON_PP_TXFILTER_0                0x1c54
+#define RADEON_PP_TXFILTER_1                0x1c6c
+#define RADEON_PP_TXFILTER_2                0x1c84
+#       define RADEON_MAG_FILTER_NEAREST                   (0  <<  0)
+#       define RADEON_MAG_FILTER_LINEAR                    (1  <<  0)
+#       define RADEON_MAG_FILTER_MASK                      (1  <<  0)
+#       define RADEON_MIN_FILTER_NEAREST                   (0  <<  1)
+#       define RADEON_MIN_FILTER_LINEAR                    (1  <<  1)
+#       define RADEON_MIN_FILTER_NEAREST_MIP_NEAREST       (2  <<  1)
+#       define RADEON_MIN_FILTER_NEAREST_MIP_LINEAR        (3  <<  1)
+#       define RADEON_MIN_FILTER_LINEAR_MIP_NEAREST        (6  <<  1)
+#       define RADEON_MIN_FILTER_LINEAR_MIP_LINEAR         (7  <<  1)
+#       define RADEON_MIN_FILTER_ANISO_NEAREST             (8  <<  1)
+#       define RADEON_MIN_FILTER_ANISO_LINEAR              (9  <<  1)
+#       define RADEON_MIN_FILTER_ANISO_NEAREST_MIP_NEAREST (10 <<  1)
+#       define RADEON_MIN_FILTER_ANISO_NEAREST_MIP_LINEAR  (11 <<  1)
+#       define RADEON_MIN_FILTER_MASK                      (15 <<  1)
+#       define RADEON_MAX_ANISO_1_TO_1                     (0  <<  5)
+#       define RADEON_MAX_ANISO_2_TO_1                     (1  <<  5)
+#       define RADEON_MAX_ANISO_4_TO_1                     (2  <<  5)
+#       define RADEON_MAX_ANISO_8_TO_1                     (3  <<  5)
+#       define RADEON_MAX_ANISO_16_TO_1                    (4  <<  5)
+#       define RADEON_MAX_ANISO_MASK                       (7  <<  5)
+#       define RADEON_LOD_BIAS_MASK                        (0xff <<  8)
+#       define RADEON_LOD_BIAS_SHIFT                       8
+#       define RADEON_MAX_MIP_LEVEL_MASK                   (0x0f << 16)
+#       define RADEON_MAX_MIP_LEVEL_SHIFT                  16
+#       define RADEON_YUV_TO_RGB                           (1  << 20)
+#       define RADEON_YUV_TEMPERATURE_COOL                 (0  << 21)
+#       define RADEON_YUV_TEMPERATURE_HOT                  (1  << 21)
+#       define RADEON_YUV_TEMPERATURE_MASK                 (1  << 21)
+#       define RADEON_WRAPEN_S                             (1  << 22)
+#       define RADEON_CLAMP_S_WRAP                         (0  << 23)
+#       define RADEON_CLAMP_S_MIRROR                       (1  << 23)
+#       define RADEON_CLAMP_S_CLAMP_LAST                   (2  << 23)
+#       define RADEON_CLAMP_S_MIRROR_CLAMP_LAST            (3  << 23)
+#       define RADEON_CLAMP_S_CLAMP_BORDER                 (4  << 23)
+#       define RADEON_CLAMP_S_MIRROR_CLAMP_BORDER          (5  << 23)
+#       define RADEON_CLAMP_S_CLAMP_GL                     (6  << 23)
+#       define RADEON_CLAMP_S_MIRROR_CLAMP_GL              (7  << 23)
+#       define RADEON_CLAMP_S_MASK                         (7  << 23)
+#       define RADEON_WRAPEN_T                             (1  << 26)
+#       define RADEON_CLAMP_T_WRAP                         (0  << 27)
+#       define RADEON_CLAMP_T_MIRROR                       (1  << 27)
+#       define RADEON_CLAMP_T_CLAMP_LAST                   (2  << 27)
+#       define RADEON_CLAMP_T_MIRROR_CLAMP_LAST            (3  << 27)
+#       define RADEON_CLAMP_T_CLAMP_BORDER                 (4  << 27)
+#       define RADEON_CLAMP_T_MIRROR_CLAMP_BORDER          (5  << 27)
+#       define RADEON_CLAMP_T_CLAMP_GL                     (6  << 27)
+#       define RADEON_CLAMP_T_MIRROR_CLAMP_GL              (7  << 27)
+#       define RADEON_CLAMP_T_MASK                         (7  << 27)
+#       define RADEON_BORDER_MODE_OGL                      (0  << 31)
+#       define RADEON_BORDER_MODE_D3D                      (1  << 31)
+#define RADEON_PP_TXFORMAT_0                0x1c58
+#define RADEON_PP_TXFORMAT_1                0x1c70
+#define RADEON_PP_TXFORMAT_2                0x1c88
+#       define RADEON_TXFORMAT_I8                 (0  <<  0)
+#       define RADEON_TXFORMAT_AI88               (1  <<  0)
+#       define RADEON_TXFORMAT_RGB332             (2  <<  0)
+#       define RADEON_TXFORMAT_ARGB1555           (3  <<  0)
+#       define RADEON_TXFORMAT_RGB565             (4  <<  0)
+#       define RADEON_TXFORMAT_ARGB4444           (5  <<  0)
+#       define RADEON_TXFORMAT_ARGB8888           (6  <<  0)
+#       define RADEON_TXFORMAT_RGBA8888           (7  <<  0)
+#       define RADEON_TXFORMAT_Y8                 (8  <<  0)
+#       define RADEON_TXFORMAT_VYUY422            (10 <<  0)
+#       define RADEON_TXFORMAT_YVYU422            (11 <<  0)
+#       define RADEON_TXFORMAT_DXT1               (12 <<  0)
+#       define RADEON_TXFORMAT_DXT23              (14 <<  0)
+#       define RADEON_TXFORMAT_DXT45              (15 <<  0)
+#       define RADEON_TXFORMAT_FORMAT_MASK        (31 <<  0)
+#       define RADEON_TXFORMAT_FORMAT_SHIFT       0
+#       define RADEON_TXFORMAT_APPLE_YUV_MODE     (1  <<  5)
+#       define RADEON_TXFORMAT_ALPHA_IN_MAP       (1  <<  6)
+#       define RADEON_TXFORMAT_NON_POWER2         (1  <<  7)
+#       define RADEON_TXFORMAT_WIDTH_MASK         (15 <<  8)
+#       define RADEON_TXFORMAT_WIDTH_SHIFT        8
+#       define RADEON_TXFORMAT_HEIGHT_MASK        (15 << 12)
+#       define RADEON_TXFORMAT_HEIGHT_SHIFT       12
+#       define RADEON_TXFORMAT_F5_WIDTH_MASK      (15 << 16)
+#       define RADEON_TXFORMAT_F5_WIDTH_SHIFT     16
+#       define RADEON_TXFORMAT_F5_HEIGHT_MASK     (15 << 20)
+#       define RADEON_TXFORMAT_F5_HEIGHT_SHIFT    20
+#       define RADEON_TXFORMAT_ST_ROUTE_STQ0      (0  << 24)
+#       define RADEON_TXFORMAT_ST_ROUTE_MASK      (3  << 24)
+#       define RADEON_TXFORMAT_ST_ROUTE_STQ1      (1  << 24)
+#       define RADEON_TXFORMAT_ST_ROUTE_STQ2      (2  << 24)
+#       define RADEON_TXFORMAT_ENDIAN_NO_SWAP     (0  << 26)
+#       define RADEON_TXFORMAT_ENDIAN_16BPP_SWAP  (1  << 26)
+#       define RADEON_TXFORMAT_ENDIAN_32BPP_SWAP  (2  << 26)
+#       define RADEON_TXFORMAT_ENDIAN_HALFDW_SWAP (3  << 26)
+#       define RADEON_TXFORMAT_ALPHA_MASK_ENABLE  (1  << 28)
+#       define RADEON_TXFORMAT_CHROMA_KEY_ENABLE  (1  << 29)
+#       define RADEON_TXFORMAT_CUBIC_MAP_ENABLE   (1  << 30)
+#       define RADEON_TXFORMAT_PERSPECTIVE_ENABLE (1  << 31)
+#define RADEON_PP_CUBIC_FACES_0             0x1d24
+#define RADEON_PP_CUBIC_FACES_1             0x1d28
+#define RADEON_PP_CUBIC_FACES_2             0x1d2c
+#       define RADEON_FACE_WIDTH_1_SHIFT          0
+#       define RADEON_FACE_HEIGHT_1_SHIFT         4
+#       define RADEON_FACE_WIDTH_1_MASK           (0xf << 0)
+#       define RADEON_FACE_HEIGHT_1_MASK          (0xf << 4)
+#       define RADEON_FACE_WIDTH_2_SHIFT          8
+#       define RADEON_FACE_HEIGHT_2_SHIFT         12
+#       define RADEON_FACE_WIDTH_2_MASK           (0xf << 8)
+#       define RADEON_FACE_HEIGHT_2_MASK          (0xf << 12)
+#       define RADEON_FACE_WIDTH_3_SHIFT          16
+#       define RADEON_FACE_HEIGHT_3_SHIFT         20
+#       define RADEON_FACE_WIDTH_3_MASK           (0xf << 16)
+#       define RADEON_FACE_HEIGHT_3_MASK          (0xf << 20)
+#       define RADEON_FACE_WIDTH_4_SHIFT          24
+#       define RADEON_FACE_HEIGHT_4_SHIFT         28
+#       define RADEON_FACE_WIDTH_4_MASK           (0xf << 24)
+#       define RADEON_FACE_HEIGHT_4_MASK          (0xf << 28)
+
+#define RADEON_PP_TXOFFSET_0                0x1c5c
+#define RADEON_PP_TXOFFSET_1                0x1c74
+#define RADEON_PP_TXOFFSET_2                0x1c8c
+#       define RADEON_TXO_ENDIAN_NO_SWAP     (0 << 0)
+#       define RADEON_TXO_ENDIAN_BYTE_SWAP   (1 << 0)
+#       define RADEON_TXO_ENDIAN_WORD_SWAP   (2 << 0)
+#       define RADEON_TXO_ENDIAN_HALFDW_SWAP (3 << 0)
+#       define RADEON_TXO_MACRO_LINEAR       (0 << 2)
+#       define RADEON_TXO_MACRO_TILE         (1 << 2)
+#       define RADEON_TXO_MICRO_LINEAR       (0 << 3)
+#       define RADEON_TXO_MICRO_TILE_X2      (1 << 3)
+#       define RADEON_TXO_MICRO_TILE_OPT     (2 << 3)
+#       define RADEON_TXO_OFFSET_MASK        0xffffffe0
+#       define RADEON_TXO_OFFSET_SHIFT       5
+
+#define RADEON_PP_CUBIC_OFFSET_T0_0         0x1dd0  /* bits [31:5] */
+#define RADEON_PP_CUBIC_OFFSET_T0_1         0x1dd4
+#define RADEON_PP_CUBIC_OFFSET_T0_2         0x1dd8
+#define RADEON_PP_CUBIC_OFFSET_T0_3         0x1ddc
+#define RADEON_PP_CUBIC_OFFSET_T0_4         0x1de0
+#define RADEON_PP_CUBIC_OFFSET_T1_0         0x1e00
+#define RADEON_PP_CUBIC_OFFSET_T1_1         0x1e04
+#define RADEON_PP_CUBIC_OFFSET_T1_2         0x1e08
+#define RADEON_PP_CUBIC_OFFSET_T1_3         0x1e0c
+#define RADEON_PP_CUBIC_OFFSET_T1_4         0x1e10
+#define RADEON_PP_CUBIC_OFFSET_T2_0         0x1e14
+#define RADEON_PP_CUBIC_OFFSET_T2_1         0x1e18
+#define RADEON_PP_CUBIC_OFFSET_T2_2         0x1e1c
+#define RADEON_PP_CUBIC_OFFSET_T2_3         0x1e20
+#define RADEON_PP_CUBIC_OFFSET_T2_4         0x1e24
+
+#define RADEON_PP_TEX_SIZE_0                0x1d04  /* NPOT */
+#define RADEON_PP_TEX_SIZE_1                0x1d0c
+#define RADEON_PP_TEX_SIZE_2                0x1d14
+#       define RADEON_TEX_USIZE_MASK        (0x7ff << 0)
+#       define RADEON_TEX_USIZE_SHIFT       0
+#       define RADEON_TEX_VSIZE_MASK        (0x7ff << 16)
+#       define RADEON_TEX_VSIZE_SHIFT       16
+#       define RADEON_SIGNED_RGB_MASK       (1 << 30)
+#       define RADEON_SIGNED_RGB_SHIFT      30
+#       define RADEON_SIGNED_ALPHA_MASK     (1 << 31)
+#       define RADEON_SIGNED_ALPHA_SHIFT    31
+#define RADEON_PP_TEX_PITCH_0               0x1d08  /* NPOT */
+#define RADEON_PP_TEX_PITCH_1               0x1d10  /* NPOT */
+#define RADEON_PP_TEX_PITCH_2               0x1d18  /* NPOT */
+/* note: bits 13-5: 32 byte aligned stride of texture map */
+
+#define RADEON_PP_TXCBLEND_0                0x1c60
+#define RADEON_PP_TXCBLEND_1                0x1c78
+#define RADEON_PP_TXCBLEND_2                0x1c90
+#       define RADEON_COLOR_ARG_A_SHIFT          0
+#       define RADEON_COLOR_ARG_A_MASK           (0x1f << 0)
+#       define RADEON_COLOR_ARG_A_ZERO           (0    << 0)
+#       define RADEON_COLOR_ARG_A_CURRENT_COLOR  (2    << 0)
+#       define RADEON_COLOR_ARG_A_CURRENT_ALPHA  (3    << 0)
+#       define RADEON_COLOR_ARG_A_DIFFUSE_COLOR  (4    << 0)
+#       define RADEON_COLOR_ARG_A_DIFFUSE_ALPHA  (5    << 0)
+#       define RADEON_COLOR_ARG_A_SPECULAR_COLOR (6    << 0)
+#       define RADEON_COLOR_ARG_A_SPECULAR_ALPHA (7    << 0)
+#       define RADEON_COLOR_ARG_A_TFACTOR_COLOR  (8    << 0)
+#       define RADEON_COLOR_ARG_A_TFACTOR_ALPHA  (9    << 0)
+#       define RADEON_COLOR_ARG_A_T0_COLOR       (10   << 0)
+#       define RADEON_COLOR_ARG_A_T0_ALPHA       (11   << 0)
+#       define RADEON_COLOR_ARG_A_T1_COLOR       (12   << 0)
+#       define RADEON_COLOR_ARG_A_T1_ALPHA       (13   << 0)
+#       define RADEON_COLOR_ARG_A_T2_COLOR       (14   << 0)
+#       define RADEON_COLOR_ARG_A_T2_ALPHA       (15   << 0)
+#       define RADEON_COLOR_ARG_A_T3_COLOR       (16   << 0)
+#       define RADEON_COLOR_ARG_A_T3_ALPHA       (17   << 0)
+#       define RADEON_COLOR_ARG_B_SHIFT          5
+#       define RADEON_COLOR_ARG_B_MASK           (0x1f << 5)
+#       define RADEON_COLOR_ARG_B_ZERO           (0    << 5)
+#       define RADEON_COLOR_ARG_B_CURRENT_COLOR  (2    << 5)
+#       define RADEON_COLOR_ARG_B_CURRENT_ALPHA  (3    << 5)
+#       define RADEON_COLOR_ARG_B_DIFFUSE_COLOR  (4    << 5)
+#       define RADEON_COLOR_ARG_B_DIFFUSE_ALPHA  (5    << 5)
+#       define RADEON_COLOR_ARG_B_SPECULAR_COLOR (6    << 5)
+#       define RADEON_COLOR_ARG_B_SPECULAR_ALPHA (7    << 5)
+#       define RADEON_COLOR_ARG_B_TFACTOR_COLOR  (8    << 5)
+#       define RADEON_COLOR_ARG_B_TFACTOR_ALPHA  (9    << 5)
+#       define RADEON_COLOR_ARG_B_T0_COLOR       (10   << 5)
+#       define RADEON_COLOR_ARG_B_T0_ALPHA       (11   << 5)
+#       define RADEON_COLOR_ARG_B_T1_COLOR       (12   << 5)
+#       define RADEON_COLOR_ARG_B_T1_ALPHA       (13   << 5)
+#       define RADEON_COLOR_ARG_B_T2_COLOR       (14   << 5)
+#       define RADEON_COLOR_ARG_B_T2_ALPHA       (15   << 5)
+#       define RADEON_COLOR_ARG_B_T3_COLOR       (16   << 5)
+#       define RADEON_COLOR_ARG_B_T3_ALPHA       (17   << 5)
+#       define RADEON_COLOR_ARG_C_SHIFT          10
+#       define RADEON_COLOR_ARG_C_MASK           (0x1f << 10)
+#       define RADEON_COLOR_ARG_C_ZERO           (0    << 10)
+#       define RADEON_COLOR_ARG_C_CURRENT_COLOR  (2    << 10)
+#       define RADEON_COLOR_ARG_C_CURRENT_ALPHA  (3    << 10)
+#       define RADEON_COLOR_ARG_C_DIFFUSE_COLOR  (4    << 10)
+#       define RADEON_COLOR_ARG_C_DIFFUSE_ALPHA  (5    << 10)
+#       define RADEON_COLOR_ARG_C_SPECULAR_COLOR (6    << 10)
+#       define RADEON_COLOR_ARG_C_SPECULAR_ALPHA (7    << 10)
+#       define RADEON_COLOR_ARG_C_TFACTOR_COLOR  (8    << 10)
+#       define RADEON_COLOR_ARG_C_TFACTOR_ALPHA  (9    << 10)
+#       define RADEON_COLOR_ARG_C_T0_COLOR       (10   << 10)
+#       define RADEON_COLOR_ARG_C_T0_ALPHA       (11   << 10)
+#       define RADEON_COLOR_ARG_C_T1_COLOR       (12   << 10)
+#       define RADEON_COLOR_ARG_C_T1_ALPHA       (13   << 10)
+#       define RADEON_COLOR_ARG_C_T2_COLOR       (14   << 10)
+#       define RADEON_COLOR_ARG_C_T2_ALPHA       (15   << 10)
+#       define RADEON_COLOR_ARG_C_T3_COLOR       (16   << 10)
+#       define RADEON_COLOR_ARG_C_T3_ALPHA       (17   << 10)
+#       define RADEON_COMP_ARG_A                 (1 << 15)
+#       define RADEON_COMP_ARG_A_SHIFT           15
+#       define RADEON_COMP_ARG_B                 (1 << 16)
+#       define RADEON_COMP_ARG_B_SHIFT           16
+#       define RADEON_COMP_ARG_C                 (1 << 17)
+#       define RADEON_COMP_ARG_C_SHIFT           17
+#       define RADEON_BLEND_CTL_MASK             (7 << 18)
+#       define RADEON_BLEND_CTL_ADD              (0 << 18)
+#       define RADEON_BLEND_CTL_SUBTRACT         (1 << 18)
+#       define RADEON_BLEND_CTL_ADDSIGNED        (2 << 18)
+#       define RADEON_BLEND_CTL_BLEND            (3 << 18)
+#       define RADEON_BLEND_CTL_DOT3             (4 << 18)
+#       define RADEON_SCALE_SHIFT                21
+#       define RADEON_SCALE_MASK                 (3 << 21)
+#       define RADEON_SCALE_1X                   (0 << 21)
+#       define RADEON_SCALE_2X                   (1 << 21)
+#       define RADEON_SCALE_4X                   (2 << 21)
+#       define RADEON_CLAMP_TX                   (1 << 23)
+#       define RADEON_T0_EQ_TCUR                 (1 << 24)
+#       define RADEON_T1_EQ_TCUR                 (1 << 25)
+#       define RADEON_T2_EQ_TCUR                 (1 << 26)
+#       define RADEON_T3_EQ_TCUR                 (1 << 27)
+#       define RADEON_COLOR_ARG_MASK             0x1f
+#       define RADEON_COMP_ARG_SHIFT             15
+#define RADEON_PP_TXABLEND_0                0x1c64
+#define RADEON_PP_TXABLEND_1                0x1c7c
+#define RADEON_PP_TXABLEND_2                0x1c94
+#       define RADEON_ALPHA_ARG_A_SHIFT          0
+#       define RADEON_ALPHA_ARG_A_MASK           (0xf << 0)
+#       define RADEON_ALPHA_ARG_A_ZERO           (0   << 0)
+#       define RADEON_ALPHA_ARG_A_CURRENT_ALPHA  (1   << 0)
+#       define RADEON_ALPHA_ARG_A_DIFFUSE_ALPHA  (2   << 0)
+#       define RADEON_ALPHA_ARG_A_SPECULAR_ALPHA (3   << 0)
+#       define RADEON_ALPHA_ARG_A_TFACTOR_ALPHA  (4   << 0)
+#       define RADEON_ALPHA_ARG_A_T0_ALPHA       (5   << 0)
+#       define RADEON_ALPHA_ARG_A_T1_ALPHA       (6   << 0)
+#       define RADEON_ALPHA_ARG_A_T2_ALPHA       (7   << 0)
+#       define RADEON_ALPHA_ARG_A_T3_ALPHA       (8   << 0)
+#       define RADEON_ALPHA_ARG_B_SHIFT          4
+#       define RADEON_ALPHA_ARG_B_MASK           (0xf << 4)
+#       define RADEON_ALPHA_ARG_B_ZERO           (0   << 4)
+#       define RADEON_ALPHA_ARG_B_CURRENT_ALPHA  (1   << 4)
+#       define RADEON_ALPHA_ARG_B_DIFFUSE_ALPHA  (2   << 4)
+#       define RADEON_ALPHA_ARG_B_SPECULAR_ALPHA (3   << 4)
+#       define RADEON_ALPHA_ARG_B_TFACTOR_ALPHA  (4   << 4)
+#       define RADEON_ALPHA_ARG_B_T0_ALPHA       (5   << 4)
+#       define RADEON_ALPHA_ARG_B_T1_ALPHA       (6   << 4)
+#       define RADEON_ALPHA_ARG_B_T2_ALPHA       (7   << 4)
+#       define RADEON_ALPHA_ARG_B_T3_ALPHA       (8   << 4)
+#       define RADEON_ALPHA_ARG_C_SHIFT          8
+#       define RADEON_ALPHA_ARG_C_MASK           (0xf << 8)
+#       define RADEON_ALPHA_ARG_C_ZERO           (0   << 8)
+#       define RADEON_ALPHA_ARG_C_CURRENT_ALPHA  (1   << 8)
+#       define RADEON_ALPHA_ARG_C_DIFFUSE_ALPHA  (2   << 8)
+#       define RADEON_ALPHA_ARG_C_SPECULAR_ALPHA (3   << 8)
+#       define RADEON_ALPHA_ARG_C_TFACTOR_ALPHA  (4   << 8)
+#       define RADEON_ALPHA_ARG_C_T0_ALPHA       (5   << 8)
+#       define RADEON_ALPHA_ARG_C_T1_ALPHA       (6   << 8)
+#       define RADEON_ALPHA_ARG_C_T2_ALPHA       (7   << 8)
+#       define RADEON_ALPHA_ARG_C_T3_ALPHA       (8   << 8)
+#       define RADEON_DOT_ALPHA_DONT_REPLICATE   (1   << 9)
+#       define RADEON_ALPHA_ARG_MASK             0xf
+
+#define RADEON_PP_TFACTOR_0                 0x1c68
+#define RADEON_PP_TFACTOR_1                 0x1c80
+#define RADEON_PP_TFACTOR_2                 0x1c98
+
+#define RADEON_RB3D_BLENDCNTL               0x1c20
+#       define RADEON_COMB_FCN_MASK                    (3  << 12)
+#       define RADEON_COMB_FCN_ADD_CLAMP               (0  << 12)
+#       define RADEON_COMB_FCN_ADD_NOCLAMP             (1  << 12)
+#       define RADEON_COMB_FCN_SUB_CLAMP               (2  << 12)
+#       define RADEON_COMB_FCN_SUB_NOCLAMP             (3  << 12)
+#       define RADEON_SRC_BLEND_GL_ZERO                (32 << 16)
+#       define RADEON_SRC_BLEND_GL_ONE                 (33 << 16)
+#       define RADEON_SRC_BLEND_GL_SRC_COLOR           (34 << 16)
+#       define RADEON_SRC_BLEND_GL_ONE_MINUS_SRC_COLOR (35 << 16)
+#       define RADEON_SRC_BLEND_GL_DST_COLOR           (36 << 16)
+#       define RADEON_SRC_BLEND_GL_ONE_MINUS_DST_COLOR (37 << 16)
+#       define RADEON_SRC_BLEND_GL_SRC_ALPHA           (38 << 16)
+#       define RADEON_SRC_BLEND_GL_ONE_MINUS_SRC_ALPHA (39 << 16)
+#       define RADEON_SRC_BLEND_GL_DST_ALPHA           (40 << 16)
+#       define RADEON_SRC_BLEND_GL_ONE_MINUS_DST_ALPHA (41 << 16)
+#       define RADEON_SRC_BLEND_GL_SRC_ALPHA_SATURATE  (42 << 16)
+#       define RADEON_SRC_BLEND_MASK                   (63 << 16)
+#       define RADEON_DST_BLEND_GL_ZERO                (32 << 24)
+#       define RADEON_DST_BLEND_GL_ONE                 (33 << 24)
+#       define RADEON_DST_BLEND_GL_SRC_COLOR           (34 << 24)
+#       define RADEON_DST_BLEND_GL_ONE_MINUS_SRC_COLOR (35 << 24)
+#       define RADEON_DST_BLEND_GL_DST_COLOR           (36 << 24)
+#       define RADEON_DST_BLEND_GL_ONE_MINUS_DST_COLOR (37 << 24)
+#       define RADEON_DST_BLEND_GL_SRC_ALPHA           (38 << 24)
+#       define RADEON_DST_BLEND_GL_ONE_MINUS_SRC_ALPHA (39 << 24)
+#       define RADEON_DST_BLEND_GL_DST_ALPHA           (40 << 24)
+#       define RADEON_DST_BLEND_GL_ONE_MINUS_DST_ALPHA (41 << 24)
+#       define RADEON_DST_BLEND_MASK                   (63 << 24)
+#define RADEON_RB3D_CNTL                    0x1c3c
+#       define RADEON_ALPHA_BLEND_ENABLE       (1  <<  0)
+#       define RADEON_PLANE_MASK_ENABLE        (1  <<  1)
+#       define RADEON_DITHER_ENABLE            (1  <<  2)
+#       define RADEON_ROUND_ENABLE             (1  <<  3)
+#       define RADEON_SCALE_DITHER_ENABLE      (1  <<  4)
+#       define RADEON_DITHER_INIT              (1  <<  5)
+#       define RADEON_ROP_ENABLE               (1  <<  6)
+#       define RADEON_STENCIL_ENABLE           (1  <<  7)
+#       define RADEON_Z_ENABLE                 (1  <<  8)
+#       define RADEON_DEPTH_XZ_OFFEST_ENABLE   (1  <<  9)
+#       define RADEON_COLOR_FORMAT_ARGB1555    (3  << 10)
+#       define RADEON_COLOR_FORMAT_RGB565      (4  << 10)
+#       define RADEON_COLOR_FORMAT_ARGB8888    (6  << 10)
+#       define RADEON_COLOR_FORMAT_RGB332      (7  << 10)
+#       define RADEON_COLOR_FORMAT_Y8          (8  << 10)
+#       define RADEON_COLOR_FORMAT_RGB8        (9  << 10)
+#       define RADEON_COLOR_FORMAT_YUV422_VYUY (11 << 10)
+#       define RADEON_COLOR_FORMAT_YUV422_YVYU (12 << 10)
+#       define RADEON_COLOR_FORMAT_aYUV444     (14 << 10)
+#       define RADEON_COLOR_FORMAT_ARGB4444    (15 << 10)
+#       define RADEON_CLRCMP_FLIP_ENABLE       (1  << 14)
+#define RADEON_RB3D_COLOROFFSET             0x1c40
+#       define RADEON_COLOROFFSET_MASK      0xfffffff0
+#define RADEON_RB3D_COLORPITCH              0x1c48
+#       define RADEON_COLORPITCH_MASK         0x000001ff8
+#       define RADEON_COLOR_TILE_ENABLE       (1 << 16)
+#       define RADEON_COLOR_MICROTILE_ENABLE  (1 << 17)
+#       define RADEON_COLOR_ENDIAN_NO_SWAP    (0 << 18)
+#       define RADEON_COLOR_ENDIAN_WORD_SWAP  (1 << 18)
+#       define RADEON_COLOR_ENDIAN_DWORD_SWAP (2 << 18)
+#define RADEON_RB3D_DEPTHOFFSET             0x1c24
+#define RADEON_RB3D_DEPTHPITCH              0x1c28
+#       define RADEON_DEPTHPITCH_MASK         0x00001ff8
+#       define RADEON_DEPTH_ENDIAN_NO_SWAP    (0 << 18)
+#       define RADEON_DEPTH_ENDIAN_WORD_SWAP  (1 << 18)
+#       define RADEON_DEPTH_ENDIAN_DWORD_SWAP (2 << 18)
+#define RADEON_RB3D_PLANEMASK               0x1d84
+#define RADEON_RB3D_ROPCNTL                 0x1d80
+#       define RADEON_ROP_MASK              (15 << 8)
+#       define RADEON_ROP_CLEAR             (0  << 8)
+#       define RADEON_ROP_NOR               (1  << 8)
+#       define RADEON_ROP_AND_INVERTED      (2  << 8)
+#       define RADEON_ROP_COPY_INVERTED     (3  << 8)
+#       define RADEON_ROP_AND_REVERSE       (4  << 8)
+#       define RADEON_ROP_INVERT            (5  << 8)
+#       define RADEON_ROP_XOR               (6  << 8)
+#       define RADEON_ROP_NAND              (7  << 8)
+#       define RADEON_ROP_AND               (8  << 8)
+#       define RADEON_ROP_EQUIV             (9  << 8)
+#       define RADEON_ROP_NOOP              (10 << 8)
+#       define RADEON_ROP_OR_INVERTED       (11 << 8)
+#       define RADEON_ROP_COPY              (12 << 8)
+#       define RADEON_ROP_OR_REVERSE        (13 << 8)
+#       define RADEON_ROP_OR                (14 << 8)
+#       define RADEON_ROP_SET               (15 << 8)
+#define RADEON_RB3D_STENCILREFMASK          0x1d7c
+#       define RADEON_STENCIL_REF_SHIFT       0
+#       define RADEON_STENCIL_REF_MASK        (0xff << 0)
+#       define RADEON_STENCIL_MASK_SHIFT      16
+#       define RADEON_STENCIL_VALUE_MASK      (0xff << 16)
+#       define RADEON_STENCIL_WRITEMASK_SHIFT 24
+#       define RADEON_STENCIL_WRITE_MASK      (0xff << 24)
+#define RADEON_RB3D_ZSTENCILCNTL            0x1c2c
+#       define RADEON_DEPTH_FORMAT_MASK          (0xf << 0)
+#       define RADEON_DEPTH_FORMAT_16BIT_INT_Z   (0  <<  0)
+#       define RADEON_DEPTH_FORMAT_24BIT_INT_Z   (2  <<  0)
+#       define RADEON_DEPTH_FORMAT_24BIT_FLOAT_Z (3  <<  0)
+#       define RADEON_DEPTH_FORMAT_32BIT_INT_Z   (4  <<  0)
+#       define RADEON_DEPTH_FORMAT_32BIT_FLOAT_Z (5  <<  0)
+#       define RADEON_DEPTH_FORMAT_16BIT_FLOAT_W (7  <<  0)
+#       define RADEON_DEPTH_FORMAT_24BIT_FLOAT_W (9  <<  0)
+#       define RADEON_DEPTH_FORMAT_32BIT_FLOAT_W (11 <<  0)
+#       define RADEON_Z_TEST_NEVER               (0  <<  4)
+#       define RADEON_Z_TEST_LESS                (1  <<  4)
+#       define RADEON_Z_TEST_LEQUAL              (2  <<  4)
+#       define RADEON_Z_TEST_EQUAL               (3  <<  4)
+#       define RADEON_Z_TEST_GEQUAL              (4  <<  4)
+#       define RADEON_Z_TEST_GREATER             (5  <<  4)
+#       define RADEON_Z_TEST_NEQUAL              (6  <<  4)
+#       define RADEON_Z_TEST_ALWAYS              (7  <<  4)
+#       define RADEON_Z_TEST_MASK                (7  <<  4)
+#       define RADEON_STENCIL_TEST_NEVER         (0  << 12)
+#       define RADEON_STENCIL_TEST_LESS          (1  << 12)
+#       define RADEON_STENCIL_TEST_LEQUAL        (2  << 12)
+#       define RADEON_STENCIL_TEST_EQUAL         (3  << 12)
+#       define RADEON_STENCIL_TEST_GEQUAL        (4  << 12)
+#       define RADEON_STENCIL_TEST_GREATER       (5  << 12)
+#       define RADEON_STENCIL_TEST_NEQUAL        (6  << 12)
+#       define RADEON_STENCIL_TEST_ALWAYS        (7  << 12)
+#       define RADEON_STENCIL_TEST_MASK          (0x7 << 12)
+#       define RADEON_STENCIL_FAIL_KEEP          (0  << 16)
+#       define RADEON_STENCIL_FAIL_ZERO          (1  << 16)
+#       define RADEON_STENCIL_FAIL_REPLACE       (2  << 16)
+#       define RADEON_STENCIL_FAIL_INC           (3  << 16)
+#       define RADEON_STENCIL_FAIL_DEC           (4  << 16)
+#       define RADEON_STENCIL_FAIL_INVERT        (5  << 16)
+#       define RADEON_STENCIL_FAIL_MASK          (0x7 << 16)
+#       define RADEON_STENCIL_ZPASS_KEEP         (0  << 20)
+#       define RADEON_STENCIL_ZPASS_ZERO         (1  << 20)
+#       define RADEON_STENCIL_ZPASS_REPLACE      (2  << 20)
+#       define RADEON_STENCIL_ZPASS_INC          (3  << 20)
+#       define RADEON_STENCIL_ZPASS_DEC          (4  << 20)
+#       define RADEON_STENCIL_ZPASS_INVERT       (5  << 20)
+#       define RADEON_STENCIL_ZPASS_MASK         (0x7 << 20)
+#       define RADEON_STENCIL_ZFAIL_KEEP         (0  << 24)
+#       define RADEON_STENCIL_ZFAIL_ZERO         (1  << 24)
+#       define RADEON_STENCIL_ZFAIL_REPLACE      (2  << 24)
+#       define RADEON_STENCIL_ZFAIL_INC          (3  << 24)
+#       define RADEON_STENCIL_ZFAIL_DEC          (4  << 24)
+#       define RADEON_STENCIL_ZFAIL_INVERT       (5  << 24)
+#       define RADEON_STENCIL_ZFAIL_MASK         (0x7 << 24)
+#       define RADEON_Z_COMPRESSION_ENABLE       (1  << 28)
+#       define RADEON_FORCE_Z_DIRTY              (1  << 29)
+#       define RADEON_Z_WRITE_ENABLE             (1  << 30)
+#define RADEON_RE_LINE_PATTERN              0x1cd0
+#       define RADEON_LINE_PATTERN_MASK             0x0000ffff
+#       define RADEON_LINE_REPEAT_COUNT_SHIFT       16
+#       define RADEON_LINE_PATTERN_START_SHIFT      24
+#       define RADEON_LINE_PATTERN_LITTLE_BIT_ORDER (0 << 28)
+#       define RADEON_LINE_PATTERN_BIG_BIT_ORDER    (1 << 28)
+#       define RADEON_LINE_PATTERN_AUTO_RESET       (1 << 29)
+#define RADEON_RE_LINE_STATE                0x1cd4
+#       define RADEON_LINE_CURRENT_PTR_SHIFT   0
+#       define RADEON_LINE_CURRENT_COUNT_SHIFT 8
+#define RADEON_RE_MISC                      0x26c4
+#       define RADEON_STIPPLE_COORD_MASK       0x1f
+#       define RADEON_STIPPLE_X_OFFSET_SHIFT   0
+#       define RADEON_STIPPLE_X_OFFSET_MASK    (0x1f << 0)
+#       define RADEON_STIPPLE_Y_OFFSET_SHIFT   8
+#       define RADEON_STIPPLE_Y_OFFSET_MASK    (0x1f << 8)
+#       define RADEON_STIPPLE_LITTLE_BIT_ORDER (0 << 16)
+#       define RADEON_STIPPLE_BIG_BIT_ORDER    (1 << 16)
+#define RADEON_RE_SOLID_COLOR               0x1c1c
+#define RADEON_RE_TOP_LEFT                  0x26c0
+#       define RADEON_RE_LEFT_SHIFT         0
+#       define RADEON_RE_TOP_SHIFT          16
+#define RADEON_RE_WIDTH_HEIGHT              0x1c44
+#       define RADEON_RE_WIDTH_SHIFT        0
+#       define RADEON_RE_HEIGHT_SHIFT       16
+
+#define RADEON_SE_CNTL                      0x1c4c
+#       define RADEON_FFACE_CULL_CW          (0 <<  0)
+#       define RADEON_FFACE_CULL_CCW         (1 <<  0)
+#       define RADEON_FFACE_CULL_DIR_MASK    (1 <<  0)
+#       define RADEON_BFACE_CULL             (0 <<  1)
+#       define RADEON_BFACE_SOLID            (3 <<  1)
+#       define RADEON_FFACE_CULL             (0 <<  3)
+#       define RADEON_FFACE_SOLID            (3 <<  3)
+#       define RADEON_FFACE_CULL_MASK        (3 <<  3)
+#       define RADEON_BADVTX_CULL_DISABLE    (1 <<  5)
+#       define RADEON_FLAT_SHADE_VTX_0       (0 <<  6)
+#       define RADEON_FLAT_SHADE_VTX_1       (1 <<  6)
+#       define RADEON_FLAT_SHADE_VTX_2       (2 <<  6)
+#       define RADEON_FLAT_SHADE_VTX_LAST    (3 <<  6)
+#       define RADEON_DIFFUSE_SHADE_SOLID    (0 <<  8)
+#       define RADEON_DIFFUSE_SHADE_FLAT     (1 <<  8)
+#       define RADEON_DIFFUSE_SHADE_GOURAUD  (2 <<  8)
+#       define RADEON_DIFFUSE_SHADE_MASK     (3 <<  8)
+#       define RADEON_ALPHA_SHADE_SOLID      (0 << 10)
+#       define RADEON_ALPHA_SHADE_FLAT       (1 << 10)
+#       define RADEON_ALPHA_SHADE_GOURAUD    (2 << 10)
+#       define RADEON_ALPHA_SHADE_MASK       (3 << 10)
+#       define RADEON_SPECULAR_SHADE_SOLID   (0 << 12)
+#       define RADEON_SPECULAR_SHADE_FLAT    (1 << 12)
+#       define RADEON_SPECULAR_SHADE_GOURAUD (2 << 12)
+#       define RADEON_SPECULAR_SHADE_MASK    (3 << 12)
+#       define RADEON_FOG_SHADE_SOLID        (0 << 14)
+#       define RADEON_FOG_SHADE_FLAT         (1 << 14)
+#       define RADEON_FOG_SHADE_GOURAUD      (2 << 14)
+#       define RADEON_FOG_SHADE_MASK         (3 << 14)
+#       define RADEON_ZBIAS_ENABLE_POINT     (1 << 16)
+#       define RADEON_ZBIAS_ENABLE_LINE      (1 << 17)
+#       define RADEON_ZBIAS_ENABLE_TRI       (1 << 18)
+#       define RADEON_WIDELINE_ENABLE        (1 << 20)
+#       define RADEON_VPORT_XY_XFORM_ENABLE  (1 << 24)
+#       define RADEON_VPORT_Z_XFORM_ENABLE   (1 << 25)
+#       define RADEON_VTX_PIX_CENTER_D3D     (0 << 27)
+#       define RADEON_VTX_PIX_CENTER_OGL     (1 << 27)
+#       define RADEON_ROUND_MODE_TRUNC       (0 << 28)
+#       define RADEON_ROUND_MODE_ROUND       (1 << 28)
+#       define RADEON_ROUND_MODE_ROUND_EVEN  (2 << 28)
+#       define RADEON_ROUND_MODE_ROUND_ODD   (3 << 28)
+#       define RADEON_ROUND_PREC_16TH_PIX    (0 << 30)
+#       define RADEON_ROUND_PREC_8TH_PIX     (1 << 30)
+#       define RADEON_ROUND_PREC_4TH_PIX     (2 << 30)
+#       define RADEON_ROUND_PREC_HALF_PIX    (3 << 30)
+#define R200_RE_CNTL				0x1c50 
+#       define R200_STIPPLE_ENABLE		0x1
+#       define R200_SCISSOR_ENABLE		0x2
+#       define R200_PATTERN_ENABLE		0x4
+#       define R200_PERSPECTIVE_ENABLE		0x8
+#       define R200_POINT_SMOOTH		0x20
+#       define R200_VTX_STQ0_D3D		0x00010000
+#       define R200_VTX_STQ1_D3D		0x00040000
+#       define R200_VTX_STQ2_D3D		0x00100000
+#       define R200_VTX_STQ3_D3D		0x00400000
+#       define R200_VTX_STQ4_D3D		0x01000000
+#       define R200_VTX_STQ5_D3D		0x04000000
+#define RADEON_SE_CNTL_STATUS               0x2140
+#       define RADEON_VC_NO_SWAP            (0 << 0)
+#       define RADEON_VC_16BIT_SWAP         (1 << 0)
+#       define RADEON_VC_32BIT_SWAP         (2 << 0)
+#       define RADEON_VC_HALF_DWORD_SWAP    (3 << 0)
+#       define RADEON_TCL_BYPASS            (1 << 8)
+#define RADEON_SE_COORD_FMT                 0x1c50
+#       define RADEON_VTX_XY_PRE_MULT_1_OVER_W0  (1 <<  0)
+#       define RADEON_VTX_Z_PRE_MULT_1_OVER_W0   (1 <<  1)
+#       define RADEON_VTX_ST0_NONPARAMETRIC      (1 <<  8)
+#       define RADEON_VTX_ST1_NONPARAMETRIC      (1 <<  9)
+#       define RADEON_VTX_ST2_NONPARAMETRIC      (1 << 10)
+#       define RADEON_VTX_ST3_NONPARAMETRIC      (1 << 11)
+#       define RADEON_VTX_W0_NORMALIZE           (1 << 12)
+#       define RADEON_VTX_W0_IS_NOT_1_OVER_W0    (1 << 16)
+#       define RADEON_VTX_ST0_PRE_MULT_1_OVER_W0 (1 << 17)
+#       define RADEON_VTX_ST1_PRE_MULT_1_OVER_W0 (1 << 19)
+#       define RADEON_VTX_ST2_PRE_MULT_1_OVER_W0 (1 << 21)
+#       define RADEON_VTX_ST3_PRE_MULT_1_OVER_W0 (1 << 23)
+#       define RADEON_TEX1_W_ROUTING_USE_W0      (0 << 26)
+#       define RADEON_TEX1_W_ROUTING_USE_Q1      (1 << 26)
+#define RADEON_SE_LINE_WIDTH                0x1db8
+#define RADEON_SE_TCL_LIGHT_MODEL_CTL       0x226c
+#       define RADEON_LIGHTING_ENABLE              (1 << 0)
+#       define RADEON_LIGHT_IN_MODELSPACE          (1 << 1)
+#       define RADEON_LOCAL_VIEWER                 (1 << 2)
+#       define RADEON_NORMALIZE_NORMALS            (1 << 3)
+#       define RADEON_RESCALE_NORMALS              (1 << 4)
+#       define RADEON_SPECULAR_LIGHTS              (1 << 5)
+#       define RADEON_DIFFUSE_SPECULAR_COMBINE     (1 << 6)
+#       define RADEON_LIGHT_ALPHA                  (1 << 7)
+#       define RADEON_LOCAL_LIGHT_VEC_GL           (1 << 8)
+#       define RADEON_LIGHT_NO_NORMAL_AMBIENT_ONLY (1 << 9)
+#       define RADEON_LM_SOURCE_STATE_PREMULT      0
+#       define RADEON_LM_SOURCE_STATE_MULT         1
+#       define RADEON_LM_SOURCE_VERTEX_DIFFUSE     2
+#       define RADEON_LM_SOURCE_VERTEX_SPECULAR    3
+#       define RADEON_EMISSIVE_SOURCE_SHIFT        16
+#       define RADEON_AMBIENT_SOURCE_SHIFT         18
+#       define RADEON_DIFFUSE_SOURCE_SHIFT         20
+#       define RADEON_SPECULAR_SOURCE_SHIFT        22
+#define RADEON_SE_TCL_MATERIAL_AMBIENT_RED     0x2220
+#define RADEON_SE_TCL_MATERIAL_AMBIENT_GREEN   0x2224
+#define RADEON_SE_TCL_MATERIAL_AMBIENT_BLUE    0x2228
+#define RADEON_SE_TCL_MATERIAL_AMBIENT_ALPHA   0x222c
+#define RADEON_SE_TCL_MATERIAL_DIFFUSE_RED     0x2230
+#define RADEON_SE_TCL_MATERIAL_DIFFUSE_GREEN   0x2234
+#define RADEON_SE_TCL_MATERIAL_DIFFUSE_BLUE    0x2238
+#define RADEON_SE_TCL_MATERIAL_DIFFUSE_ALPHA   0x223c
+#define RADEON_SE_TCL_MATERIAL_EMMISSIVE_RED   0x2210
+#define RADEON_SE_TCL_MATERIAL_EMMISSIVE_GREEN 0x2214
+#define RADEON_SE_TCL_MATERIAL_EMMISSIVE_BLUE  0x2218
+#define RADEON_SE_TCL_MATERIAL_EMMISSIVE_ALPHA 0x221c
+#define RADEON_SE_TCL_MATERIAL_SPECULAR_RED    0x2240
+#define RADEON_SE_TCL_MATERIAL_SPECULAR_GREEN  0x2244
+#define RADEON_SE_TCL_MATERIAL_SPECULAR_BLUE   0x2248
+#define RADEON_SE_TCL_MATERIAL_SPECULAR_ALPHA  0x224c
+#define RADEON_SE_TCL_MATRIX_SELECT_0       0x225c
+#       define RADEON_MODELVIEW_0_SHIFT        0
+#       define RADEON_MODELVIEW_1_SHIFT        4
+#       define RADEON_MODELVIEW_2_SHIFT        8
+#       define RADEON_MODELVIEW_3_SHIFT        12
+#       define RADEON_IT_MODELVIEW_0_SHIFT     16
+#       define RADEON_IT_MODELVIEW_1_SHIFT     20
+#       define RADEON_IT_MODELVIEW_2_SHIFT     24
+#       define RADEON_IT_MODELVIEW_3_SHIFT     28
+#define RADEON_SE_TCL_MATRIX_SELECT_1       0x2260
+#       define RADEON_MODELPROJECT_0_SHIFT     0
+#       define RADEON_MODELPROJECT_1_SHIFT     4
+#       define RADEON_MODELPROJECT_2_SHIFT     8
+#       define RADEON_MODELPROJECT_3_SHIFT     12
+#       define RADEON_TEXMAT_0_SHIFT           16
+#       define RADEON_TEXMAT_1_SHIFT           20
+#       define RADEON_TEXMAT_2_SHIFT           24
+#       define RADEON_TEXMAT_3_SHIFT           28
+
+
+#define RADEON_SE_TCL_OUTPUT_VTX_FMT        0x2254
+#       define RADEON_TCL_VTX_W0                 (1 <<  0)
+#       define RADEON_TCL_VTX_FP_DIFFUSE         (1 <<  1)
+#       define RADEON_TCL_VTX_FP_ALPHA           (1 <<  2)
+#       define RADEON_TCL_VTX_PK_DIFFUSE         (1 <<  3)
+#       define RADEON_TCL_VTX_FP_SPEC            (1 <<  4)
+#       define RADEON_TCL_VTX_FP_FOG             (1 <<  5)
+#       define RADEON_TCL_VTX_PK_SPEC            (1 <<  6)
+#       define RADEON_TCL_VTX_ST0                (1 <<  7)
+#       define RADEON_TCL_VTX_ST1                (1 <<  8)
+#       define RADEON_TCL_VTX_Q1                 (1 <<  9)
+#       define RADEON_TCL_VTX_ST2                (1 << 10)
+#       define RADEON_TCL_VTX_Q2                 (1 << 11)
+#       define RADEON_TCL_VTX_ST3                (1 << 12)
+#       define RADEON_TCL_VTX_Q3                 (1 << 13)
+#       define RADEON_TCL_VTX_Q0                 (1 << 14)
+#       define RADEON_TCL_VTX_WEIGHT_COUNT_SHIFT 15
+#       define RADEON_TCL_VTX_NORM0              (1 << 18)
+#       define RADEON_TCL_VTX_XY1                (1 << 27)
+#       define RADEON_TCL_VTX_Z1                 (1 << 28)
+#       define RADEON_TCL_VTX_W1                 (1 << 29)
+#       define RADEON_TCL_VTX_NORM1              (1 << 30)
+#       define RADEON_TCL_VTX_Z0                 (1 << 31)
+
+#define RADEON_SE_TCL_OUTPUT_VTX_SEL        0x2258
+#       define RADEON_TCL_COMPUTE_XYZW           (1 << 0)
+#       define RADEON_TCL_COMPUTE_DIFFUSE        (1 << 1)
+#       define RADEON_TCL_COMPUTE_SPECULAR       (1 << 2)
+#       define RADEON_TCL_FORCE_NAN_IF_COLOR_NAN (1 << 3)
+#       define RADEON_TCL_FORCE_INORDER_PROC     (1 << 4)
+#       define RADEON_TCL_TEX_INPUT_TEX_0        0
+#       define RADEON_TCL_TEX_INPUT_TEX_1        1
+#       define RADEON_TCL_TEX_INPUT_TEX_2        2
+#       define RADEON_TCL_TEX_INPUT_TEX_3        3
+#       define RADEON_TCL_TEX_COMPUTED_TEX_0     8
+#       define RADEON_TCL_TEX_COMPUTED_TEX_1     9
+#       define RADEON_TCL_TEX_COMPUTED_TEX_2     10
+#       define RADEON_TCL_TEX_COMPUTED_TEX_3     11
+#       define RADEON_TCL_TEX_0_OUTPUT_SHIFT     16
+#       define RADEON_TCL_TEX_1_OUTPUT_SHIFT     20
+#       define RADEON_TCL_TEX_2_OUTPUT_SHIFT     24
+#       define RADEON_TCL_TEX_3_OUTPUT_SHIFT     28
+
+#define RADEON_SE_TCL_PER_LIGHT_CTL_0       0x2270
+#       define RADEON_LIGHT_0_ENABLE               (1 <<  0)
+#       define RADEON_LIGHT_0_ENABLE_AMBIENT       (1 <<  1)
+#       define RADEON_LIGHT_0_ENABLE_SPECULAR      (1 <<  2)
+#       define RADEON_LIGHT_0_IS_LOCAL             (1 <<  3)
+#       define RADEON_LIGHT_0_IS_SPOT              (1 <<  4)
+#       define RADEON_LIGHT_0_DUAL_CONE            (1 <<  5)
+#       define RADEON_LIGHT_0_ENABLE_RANGE_ATTEN   (1 <<  6)
+#       define RADEON_LIGHT_0_CONSTANT_RANGE_ATTEN (1 <<  7)
+#       define RADEON_LIGHT_0_SHIFT                0
+#       define RADEON_LIGHT_1_ENABLE               (1 << 16)
+#       define RADEON_LIGHT_1_ENABLE_AMBIENT       (1 << 17)
+#       define RADEON_LIGHT_1_ENABLE_SPECULAR      (1 << 18)
+#       define RADEON_LIGHT_1_IS_LOCAL             (1 << 19)
+#       define RADEON_LIGHT_1_IS_SPOT              (1 << 20)
+#       define RADEON_LIGHT_1_DUAL_CONE            (1 << 21)
+#       define RADEON_LIGHT_1_ENABLE_RANGE_ATTEN   (1 << 22)
+#       define RADEON_LIGHT_1_CONSTANT_RANGE_ATTEN (1 << 23)
+#       define RADEON_LIGHT_1_SHIFT                16
+#define RADEON_SE_TCL_PER_LIGHT_CTL_1       0x2274
+#       define RADEON_LIGHT_2_SHIFT            0
+#       define RADEON_LIGHT_3_SHIFT            16
+#define RADEON_SE_TCL_PER_LIGHT_CTL_2       0x2278
+#       define RADEON_LIGHT_4_SHIFT            0
+#       define RADEON_LIGHT_5_SHIFT            16
+#define RADEON_SE_TCL_PER_LIGHT_CTL_3       0x227c
+#       define RADEON_LIGHT_6_SHIFT            0
+#       define RADEON_LIGHT_7_SHIFT            16
+
+#define RADEON_SE_TCL_SHININESS             0x2250
+
+#define RADEON_SE_TCL_TEXTURE_PROC_CTL      0x2268
+#       define RADEON_TEXGEN_TEXMAT_0_ENABLE      (1 << 0)
+#       define RADEON_TEXGEN_TEXMAT_1_ENABLE      (1 << 1)
+#       define RADEON_TEXGEN_TEXMAT_2_ENABLE      (1 << 2)
+#       define RADEON_TEXGEN_TEXMAT_3_ENABLE      (1 << 3)
+#       define RADEON_TEXMAT_0_ENABLE             (1 << 4)
+#       define RADEON_TEXMAT_1_ENABLE             (1 << 5)
+#       define RADEON_TEXMAT_2_ENABLE             (1 << 6)
+#       define RADEON_TEXMAT_3_ENABLE             (1 << 7)
+#       define RADEON_TEXGEN_INPUT_MASK           0xf
+#       define RADEON_TEXGEN_INPUT_TEXCOORD_0     0
+#       define RADEON_TEXGEN_INPUT_TEXCOORD_1     1
+#       define RADEON_TEXGEN_INPUT_TEXCOORD_2     2
+#       define RADEON_TEXGEN_INPUT_TEXCOORD_3     3
+#       define RADEON_TEXGEN_INPUT_OBJ            4
+#       define RADEON_TEXGEN_INPUT_EYE            5
+#       define RADEON_TEXGEN_INPUT_EYE_NORMAL     6
+#       define RADEON_TEXGEN_INPUT_EYE_REFLECT    7
+#       define RADEON_TEXGEN_INPUT_EYE_NORMALIZED 8
+#       define RADEON_TEXGEN_0_INPUT_SHIFT        16
+#       define RADEON_TEXGEN_1_INPUT_SHIFT        20
+#       define RADEON_TEXGEN_2_INPUT_SHIFT        24
+#       define RADEON_TEXGEN_3_INPUT_SHIFT        28
+
+#define RADEON_SE_TCL_UCP_VERT_BLEND_CTL    0x2264
+#       define RADEON_UCP_IN_CLIP_SPACE            (1 <<  0)
+#       define RADEON_UCP_IN_MODEL_SPACE           (1 <<  1)
+#       define RADEON_UCP_ENABLE_0                 (1 <<  2)
+#       define RADEON_UCP_ENABLE_1                 (1 <<  3)
+#       define RADEON_UCP_ENABLE_2                 (1 <<  4)
+#       define RADEON_UCP_ENABLE_3                 (1 <<  5)
+#       define RADEON_UCP_ENABLE_4                 (1 <<  6)
+#       define RADEON_UCP_ENABLE_5                 (1 <<  7)
+#       define RADEON_TCL_FOG_MASK                 (3 <<  8)
+#       define RADEON_TCL_FOG_DISABLE              (0 <<  8)
+#       define RADEON_TCL_FOG_EXP                  (1 <<  8)
+#       define RADEON_TCL_FOG_EXP2                 (2 <<  8)
+#       define RADEON_TCL_FOG_LINEAR               (3 <<  8)
+#       define RADEON_RNG_BASED_FOG                (1 << 10)
+#       define RADEON_LIGHT_TWOSIDE                (1 << 11)
+#       define RADEON_BLEND_OP_COUNT_MASK          (7 << 12)
+#       define RADEON_BLEND_OP_COUNT_SHIFT         12
+#       define RADEON_POSITION_BLEND_OP_ENABLE     (1 << 16)
+#       define RADEON_NORMAL_BLEND_OP_ENABLE       (1 << 17)
+#       define RADEON_VERTEX_BLEND_SRC_0_PRIMARY   (1 << 18)
+#       define RADEON_VERTEX_BLEND_SRC_0_SECONDARY (1 << 18)
+#       define RADEON_VERTEX_BLEND_SRC_1_PRIMARY   (1 << 19)
+#       define RADEON_VERTEX_BLEND_SRC_1_SECONDARY (1 << 19)
+#       define RADEON_VERTEX_BLEND_SRC_2_PRIMARY   (1 << 20)
+#       define RADEON_VERTEX_BLEND_SRC_2_SECONDARY (1 << 20)
+#       define RADEON_VERTEX_BLEND_SRC_3_PRIMARY   (1 << 21)
+#       define RADEON_VERTEX_BLEND_SRC_3_SECONDARY (1 << 21)
+#       define RADEON_VERTEX_BLEND_WGT_MINUS_ONE   (1 << 22)
+#       define RADEON_CULL_FRONT_IS_CW             (0 << 28)
+#       define RADEON_CULL_FRONT_IS_CCW            (1 << 28)
+#       define RADEON_CULL_FRONT                   (1 << 29)
+#       define RADEON_CULL_BACK                    (1 << 30)
+#       define RADEON_FORCE_W_TO_ONE               (1 << 31)
+
+#define RADEON_SE_VPORT_XSCALE              0x1d98
+#define RADEON_SE_VPORT_XOFFSET             0x1d9c
+#define RADEON_SE_VPORT_YSCALE              0x1da0
+#define RADEON_SE_VPORT_YOFFSET             0x1da4
+#define RADEON_SE_VPORT_ZSCALE              0x1da8
+#define RADEON_SE_VPORT_ZOFFSET             0x1dac
+#define RADEON_SE_ZBIAS_FACTOR              0x1db0
+#define RADEON_SE_ZBIAS_CONSTANT            0x1db4
+
+#define RADEON_SE_VTX_FMT                   0x2080
+#       define RADEON_SE_VTX_FMT_XY         0x00000000
+#       define RADEON_SE_VTX_FMT_W0         0x00000001
+#       define RADEON_SE_VTX_FMT_FPCOLOR    0x00000002
+#       define RADEON_SE_VTX_FMT_FPALPHA    0x00000004
+#       define RADEON_SE_VTX_FMT_PKCOLOR    0x00000008
+#       define RADEON_SE_VTX_FMT_FPSPEC     0x00000010
+#       define RADEON_SE_VTX_FMT_FPFOG      0x00000020
+#       define RADEON_SE_VTX_FMT_PKSPEC     0x00000040
+#       define RADEON_SE_VTX_FMT_ST0        0x00000080
+#       define RADEON_SE_VTX_FMT_ST1        0x00000100
+#       define RADEON_SE_VTX_FMT_Q1         0x00000200
+#       define RADEON_SE_VTX_FMT_ST2        0x00000400
+#       define RADEON_SE_VTX_FMT_Q2         0x00000800
+#       define RADEON_SE_VTX_FMT_ST3        0x00001000
+#       define RADEON_SE_VTX_FMT_Q3         0x00002000
+#       define RADEON_SE_VTX_FMT_Q0         0x00004000
+#       define RADEON_SE_VTX_FMT_BLND_WEIGHT_CNT_MASK  0x00038000
+#       define RADEON_SE_VTX_FMT_N0         0x00040000
+#       define RADEON_SE_VTX_FMT_XY1        0x08000000
+#       define RADEON_SE_VTX_FMT_Z1         0x10000000
+#       define RADEON_SE_VTX_FMT_W1         0x20000000
+#       define RADEON_SE_VTX_FMT_N1         0x40000000
+#       define RADEON_SE_VTX_FMT_Z          0x80000000
+
+#define RADEON_SE_VF_CNTL                             0x2084
+#       define RADEON_VF_PRIM_TYPE_POINT_LIST         1
+#       define RADEON_VF_PRIM_TYPE_LINE_LIST          2
+#       define RADEON_VF_PRIM_TYPE_LINE_STRIP         3
+#       define RADEON_VF_PRIM_TYPE_TRIANGLE_LIST      4
+#       define RADEON_VF_PRIM_TYPE_TRIANGLE_FAN       5
+#       define RADEON_VF_PRIM_TYPE_TRIANGLE_STRIP     6
+#       define RADEON_VF_PRIM_TYPE_TRIANGLE_FLAG      7
+#       define RADEON_VF_PRIM_TYPE_RECTANGLE_LIST     8
+#       define RADEON_VF_PRIM_TYPE_POINT_LIST_3       9
+#       define RADEON_VF_PRIM_TYPE_LINE_LIST_3        10
+#       define RADEON_VF_PRIM_TYPE_SPIRIT_LIST        11
+#       define RADEON_VF_PRIM_TYPE_LINE_LOOP          12
+#       define RADEON_VF_PRIM_TYPE_QUAD_LIST          13
+#       define RADEON_VF_PRIM_TYPE_QUAD_STRIP         14
+#       define RADEON_VF_PRIM_TYPE_POLYGON            15
+#       define RADEON_VF_PRIM_WALK_STATE              (0<<4)
+#       define RADEON_VF_PRIM_WALK_INDEX              (1<<4)
+#       define RADEON_VF_PRIM_WALK_LIST               (2<<4)
+#       define RADEON_VF_PRIM_WALK_DATA               (3<<4)
+#       define RADEON_VF_COLOR_ORDER_RGBA             (1<<6)
+#       define RADEON_VF_RADEON_MODE                  (1<<8)
+#       define RADEON_VF_TCL_OUTPUT_CTL_ENA           (1<<9)
+#       define RADEON_VF_PROG_STREAM_ENA              (1<<10)
+#       define RADEON_VF_INDEX_SIZE_SHIFT             11
+#       define RADEON_VF_NUM_VERTICES_SHIFT           16
+
+#define RADEON_SE_PORT_DATA0			0x2000
+ 
+#define R200_SE_VAP_CNTL			0x2080
+#       define R200_VAP_TCL_ENABLE		0x00000001
+#       define R200_VAP_SINGLE_BUF_STATE_ENABLE	0x00000010
+#       define R200_VAP_FORCE_W_TO_ONE		0x00010000
+#       define R200_VAP_D3D_TEX_DEFAULT		0x00020000
+#       define R200_VAP_VF_MAX_VTX_NUM__SHIFT	18
+#       define R200_VAP_VF_MAX_VTX_NUM		(9 << 18)
+#       define R200_VAP_DX_CLIP_SPACE_DEF	0x00400000
+#define R200_VF_MAX_VTX_INDX			0x210c
+#define R200_VF_MIN_VTX_INDX			0x2110
+#define R200_SE_VTE_CNTL			0x20b0
+#       define R200_VPORT_X_SCALE_ENA			0x00000001
+#       define R200_VPORT_X_OFFSET_ENA			0x00000002
+#       define R200_VPORT_Y_SCALE_ENA			0x00000004
+#       define R200_VPORT_Y_OFFSET_ENA			0x00000008
+#       define R200_VPORT_Z_SCALE_ENA			0x00000010
+#       define R200_VPORT_Z_OFFSET_ENA			0x00000020
+#       define R200_VTX_XY_FMT				0x00000100
+#       define R200_VTX_Z_FMT				0x00000200
+#       define R200_VTX_W0_FMT				0x00000400
+#       define R200_VTX_W0_NORMALIZE			0x00000800
+#       define R200_VTX_ST_DENORMALIZED		0x00001000
+#define R200_SE_VAP_CNTL_STATUS			0x2140
+#       define R200_VC_NO_SWAP			(0 << 0)
+#       define R200_VC_16BIT_SWAP		(1 << 0)
+#       define R200_VC_32BIT_SWAP		(2 << 0)
+#define R200_PP_TXFILTER_0			0x2c00 
+#define R200_PP_TXFILTER_1			0x2c20
+#define R200_PP_TXFILTER_2			0x2c40
+#define R200_PP_TXFILTER_3			0x2c60
+#define R200_PP_TXFILTER_4			0x2c80
+#define R200_PP_TXFILTER_5			0x2ca0
+#       define R200_MAG_FILTER_NEAREST		(0  <<  0)
+#       define R200_MAG_FILTER_LINEAR		(1  <<  0)
+#       define R200_MAG_FILTER_MASK		(1  <<  0)
+#       define R200_MIN_FILTER_NEAREST		(0  <<  1)
+#       define R200_MIN_FILTER_LINEAR		(1  <<  1)
+#       define R200_MIN_FILTER_NEAREST_MIP_NEAREST (2  <<  1)
+#       define R200_MIN_FILTER_NEAREST_MIP_LINEAR (3  <<  1)
+#       define R200_MIN_FILTER_LINEAR_MIP_NEAREST (6  <<  1)
+#       define R200_MIN_FILTER_LINEAR_MIP_LINEAR (7  <<  1)
+#       define R200_MIN_FILTER_ANISO_NEAREST	(8  <<  1)
+#       define R200_MIN_FILTER_ANISO_LINEAR	(9  <<  1)
+#       define R200_MIN_FILTER_ANISO_NEAREST_MIP_NEAREST (10 <<  1)
+#       define R200_MIN_FILTER_ANISO_NEAREST_MIP_LINEAR (11 <<  1)
+#       define R200_MIN_FILTER_MASK		(15 <<  1)
+#       define R200_MAX_ANISO_1_TO_1		(0  <<  5)
+#       define R200_MAX_ANISO_2_TO_1		(1  <<  5)
+#       define R200_MAX_ANISO_4_TO_1		(2  <<  5)
+#       define R200_MAX_ANISO_8_TO_1		(3  <<  5)
+#       define R200_MAX_ANISO_16_TO_1		(4  <<  5)
+#       define R200_MAX_ANISO_MASK		(7  <<  5)
+#       define R200_MAX_MIP_LEVEL_MASK		(0x0f << 16)
+#       define R200_MAX_MIP_LEVEL_SHIFT		16
+#       define R200_YUV_TO_RGB			(1  << 20)
+#       define R200_YUV_TEMPERATURE_COOL	(0  << 21)
+#       define R200_YUV_TEMPERATURE_HOT		(1  << 21)
+#       define R200_YUV_TEMPERATURE_MASK	(1  << 21)
+#       define R200_WRAPEN_S			(1  << 22)
+#       define R200_CLAMP_S_WRAP		(0  << 23)
+#       define R200_CLAMP_S_MIRROR		(1  << 23)
+#       define R200_CLAMP_S_CLAMP_LAST		(2  << 23)
+#       define R200_CLAMP_S_MIRROR_CLAMP_LAST	(3  << 23)
+#       define R200_CLAMP_S_CLAMP_BORDER	(4  << 23)
+#       define R200_CLAMP_S_MIRROR_CLAMP_BORDER	(5  << 23)
+#       define R200_CLAMP_S_CLAMP_GL		(6  << 23)
+#       define R200_CLAMP_S_MIRROR_CLAMP_GL	(7  << 23)
+#       define R200_CLAMP_S_MASK		(7  << 23)
+#       define R200_WRAPEN_T			(1  << 26)
+#       define R200_CLAMP_T_WRAP		(0  << 27)
+#       define R200_CLAMP_T_MIRROR		(1  << 27)
+#       define R200_CLAMP_T_CLAMP_LAST		(2  << 27)
+#       define R200_CLAMP_T_MIRROR_CLAMP_LAST	(3  << 27)
+#       define R200_CLAMP_T_CLAMP_BORDER	(4  << 27)
+#       define R200_CLAMP_T_MIRROR_CLAMP_BORDER	(5  << 27)
+#       define R200_CLAMP_T_CLAMP_GL		(6  << 27)
+#       define R200_CLAMP_T_MIRROR_CLAMP_GL	(7  << 27)
+#       define R200_CLAMP_T_MASK		(7  << 27)
+#       define R200_KILL_LT_ZERO		(1  << 30)
+#       define R200_BORDER_MODE_OGL		(0  << 31)
+#       define R200_BORDER_MODE_D3D		(1  << 31)
+#define R200_PP_TXFORMAT_0			0x2c04
+#define R200_PP_TXFORMAT_1			0x2c24
+#define R200_PP_TXFORMAT_2			0x2c44
+#define R200_PP_TXFORMAT_3			0x2c64
+#define R200_PP_TXFORMAT_4			0x2c84
+#define R200_PP_TXFORMAT_5			0x2ca4
+#       define R200_TXFORMAT_I8			(0 << 0)
+#       define R200_TXFORMAT_AI88		(1 << 0)
+#       define R200_TXFORMAT_RGB332		(2 << 0)
+#       define R200_TXFORMAT_ARGB1555		(3 << 0)
+#       define R200_TXFORMAT_RGB565		(4 << 0)
+#       define R200_TXFORMAT_ARGB4444		(5 << 0)
+#       define R200_TXFORMAT_ARGB8888		(6 << 0)
+#       define R200_TXFORMAT_RGBA8888		(7 << 0)
+#       define R200_TXFORMAT_Y8			(8 << 0)
+#       define R200_TXFORMAT_AVYU4444		(9 << 0)
+#       define R200_TXFORMAT_VYUY422		(10 << 0)
+#       define R200_TXFORMAT_YVYU422		(11 << 0)
+#       define R200_TXFORMAT_DXT1		(12 << 0)
+#       define R200_TXFORMAT_DXT23		(14 << 0)
+#       define R200_TXFORMAT_DXT45		(15 << 0)
+#       define R200_TXFORMAT_ABGR8888		(22 << 0)
+#       define R200_TXFORMAT_FORMAT_MASK	(31 <<	0)
+#       define R200_TXFORMAT_FORMAT_SHIFT	0
+#       define R200_TXFORMAT_ALPHA_IN_MAP	(1 << 6)
+#       define R200_TXFORMAT_NON_POWER2		(1 << 7)
+#       define R200_TXFORMAT_WIDTH_MASK		(15 <<	8)
+#       define R200_TXFORMAT_WIDTH_SHIFT	8
+#       define R200_TXFORMAT_HEIGHT_MASK	(15 << 12)
+#       define R200_TXFORMAT_HEIGHT_SHIFT	12
+#       define R200_TXFORMAT_F5_WIDTH_MASK	(15 << 16)	/* cube face 5 */
+#       define R200_TXFORMAT_F5_WIDTH_SHIFT	16
+#       define R200_TXFORMAT_F5_HEIGHT_MASK	(15 << 20)
+#       define R200_TXFORMAT_F5_HEIGHT_SHIFT	20
+#       define R200_TXFORMAT_ST_ROUTE_STQ0	(0 << 24)
+#       define R200_TXFORMAT_ST_ROUTE_STQ1	(1 << 24)
+#       define R200_TXFORMAT_ST_ROUTE_STQ2	(2 << 24)
+#       define R200_TXFORMAT_ST_ROUTE_STQ3	(3 << 24)
+#       define R200_TXFORMAT_ST_ROUTE_STQ4	(4 << 24)
+#       define R200_TXFORMAT_ST_ROUTE_STQ5	(5 << 24)
+#       define R200_TXFORMAT_ST_ROUTE_MASK	(7 << 24)
+#       define R200_TXFORMAT_ST_ROUTE_SHIFT	24
+#       define R200_TXFORMAT_ALPHA_MASK_ENABLE	(1 << 28)
+#       define R200_TXFORMAT_CHROMA_KEY_ENABLE	(1 << 29)
+#       define R200_TXFORMAT_CUBIC_MAP_ENABLE		(1 << 30)
+#define R200_PP_TXFORMAT_X_0                    0x2c08
+#define R200_PP_TXFORMAT_X_1                    0x2c28
+#define R200_PP_TXFORMAT_X_2                    0x2c48
+#define R200_PP_TXFORMAT_X_3                    0x2c68
+#define R200_PP_TXFORMAT_X_4                    0x2c88
+#define R200_PP_TXFORMAT_X_5                    0x2ca8
+
+#define R200_PP_TXSIZE_0			0x2c0c /* NPOT only */
+#define R200_PP_TXSIZE_1			0x2c2c /* NPOT only */
+#define R200_PP_TXSIZE_2			0x2c4c /* NPOT only */
+#define R200_PP_TXSIZE_3			0x2c6c /* NPOT only */
+#define R200_PP_TXSIZE_4			0x2c8c /* NPOT only */
+#define R200_PP_TXSIZE_5			0x2cac /* NPOT only */
+
+#define R200_PP_TXPITCH_0                       0x2c10 /* NPOT only */
+#define R200_PP_TXPITCH_1			0x2c30 /* NPOT only */
+#define R200_PP_TXPITCH_2			0x2c50 /* NPOT only */
+#define R200_PP_TXPITCH_3			0x2c70 /* NPOT only */
+#define R200_PP_TXPITCH_4			0x2c90 /* NPOT only */
+#define R200_PP_TXPITCH_5			0x2cb0 /* NPOT only */
+
+#define R200_PP_TXOFFSET_0			0x2d00
+#       define R200_TXO_ENDIAN_NO_SWAP		(0 << 0)
+#       define R200_TXO_ENDIAN_BYTE_SWAP	(1 << 0)
+#       define R200_TXO_ENDIAN_WORD_SWAP	(2 << 0)
+#       define R200_TXO_ENDIAN_HALFDW_SWAP	(3 << 0)
+#       define R200_TXO_MACRO_LINEAR		(0 << 2)
+#       define R200_TXO_MACRO_TILE		(1 << 2)
+#       define R200_TXO_MICRO_LINEAR		(0 << 3)
+#       define R200_TXO_MICRO_TILE		(1 << 3)
+#       define R200_TXO_OFFSET_MASK		0xffffffe0
+#       define R200_TXO_OFFSET_SHIFT		5
+#define R200_PP_TXOFFSET_1			0x2d18
+#define R200_PP_TXOFFSET_2			0x2d30
+#define R200_PP_TXOFFSET_3			0x2d48
+#define R200_PP_TXOFFSET_4			0x2d60
+#define R200_PP_TXOFFSET_5			0x2d78
+
+#define R200_PP_TFACTOR_0			0x2ee0
+#define R200_PP_TFACTOR_1			0x2ee4
+#define R200_PP_TFACTOR_2			0x2ee8
+#define R200_PP_TFACTOR_3			0x2eec
+#define R200_PP_TFACTOR_4			0x2ef0
+#define R200_PP_TFACTOR_5			0x2ef4
+
+#define R200_PP_TXCBLEND_0			0x2f00
+#       define R200_TXC_ARG_A_ZERO		(0)
+#       define R200_TXC_ARG_A_CURRENT_COLOR	(2)
+#       define R200_TXC_ARG_A_CURRENT_ALPHA	(3)
+#       define R200_TXC_ARG_A_DIFFUSE_COLOR	(4)
+#       define R200_TXC_ARG_A_DIFFUSE_ALPHA	(5)
+#       define R200_TXC_ARG_A_SPECULAR_COLOR	(6)
+#       define R200_TXC_ARG_A_SPECULAR_ALPHA	(7)
+#       define R200_TXC_ARG_A_TFACTOR_COLOR	(8)
+#       define R200_TXC_ARG_A_TFACTOR_ALPHA	(9)
+#       define R200_TXC_ARG_A_R0_COLOR		(10)
+#       define R200_TXC_ARG_A_R0_ALPHA		(11)
+#       define R200_TXC_ARG_A_R1_COLOR		(12)
+#       define R200_TXC_ARG_A_R1_ALPHA		(13)
+#       define R200_TXC_ARG_A_R2_COLOR		(14)
+#       define R200_TXC_ARG_A_R2_ALPHA		(15)
+#       define R200_TXC_ARG_A_R3_COLOR		(16)
+#       define R200_TXC_ARG_A_R3_ALPHA		(17)
+#       define R200_TXC_ARG_A_R4_COLOR		(18)
+#       define R200_TXC_ARG_A_R4_ALPHA		(19)
+#       define R200_TXC_ARG_A_R5_COLOR		(20)
+#       define R200_TXC_ARG_A_R5_ALPHA		(21)
+#       define R200_TXC_ARG_A_TFACTOR1_COLOR	(26)
+#       define R200_TXC_ARG_A_TFACTOR1_ALPHA	(27)
+#       define R200_TXC_ARG_A_MASK		(31 << 0)
+#       define R200_TXC_ARG_A_SHIFT		0
+#       define R200_TXC_ARG_B_ZERO		(0 << 5)
+#       define R200_TXC_ARG_B_CURRENT_COLOR	(2 << 5)
+#       define R200_TXC_ARG_B_CURRENT_ALPHA	(3 << 5)
+#       define R200_TXC_ARG_B_DIFFUSE_COLOR	(4 << 5)
+#       define R200_TXC_ARG_B_DIFFUSE_ALPHA	(5 << 5)
+#       define R200_TXC_ARG_B_SPECULAR_COLOR	(6 << 5)
+#       define R200_TXC_ARG_B_SPECULAR_ALPHA	(7 << 5)
+#       define R200_TXC_ARG_B_TFACTOR_COLOR	(8 << 5)
+#       define R200_TXC_ARG_B_TFACTOR_ALPHA	(9 << 5)
+#       define R200_TXC_ARG_B_R0_COLOR		(10 << 5)
+#       define R200_TXC_ARG_B_R0_ALPHA		(11 << 5)
+#       define R200_TXC_ARG_B_R1_COLOR		(12 << 5)
+#       define R200_TXC_ARG_B_R1_ALPHA		(13 << 5)
+#       define R200_TXC_ARG_B_R2_COLOR		(14 << 5)
+#       define R200_TXC_ARG_B_R2_ALPHA		(15 << 5)
+#       define R200_TXC_ARG_B_R3_COLOR		(16 << 5)
+#       define R200_TXC_ARG_B_R3_ALPHA		(17 << 5)
+#       define R200_TXC_ARG_B_R4_COLOR		(18 << 5)
+#       define R200_TXC_ARG_B_R4_ALPHA		(19 << 5)
+#       define R200_TXC_ARG_B_R5_COLOR		(20 << 5)
+#       define R200_TXC_ARG_B_R5_ALPHA		(21 << 5)
+#       define R200_TXC_ARG_B_TFACTOR1_COLOR	(26 << 5)
+#       define R200_TXC_ARG_B_TFACTOR1_ALPHA	(27 << 5)
+#       define R200_TXC_ARG_B_MASK		(31 << 5)
+#       define R200_TXC_ARG_B_SHIFT		5
+#       define R200_TXC_ARG_C_ZERO		(0 << 10)
+#       define R200_TXC_ARG_C_CURRENT_COLOR	(2 << 10)
+#       define R200_TXC_ARG_C_CURRENT_ALPHA	(3 << 10)
+#       define R200_TXC_ARG_C_DIFFUSE_COLOR	(4 << 10)
+#       define R200_TXC_ARG_C_DIFFUSE_ALPHA	(5 << 10)
+#       define R200_TXC_ARG_C_SPECULAR_COLOR	(6 << 10)
+#       define R200_TXC_ARG_C_SPECULAR_ALPHA	(7 << 10)
+#       define R200_TXC_ARG_C_TFACTOR_COLOR	(8 << 10)
+#       define R200_TXC_ARG_C_TFACTOR_ALPHA	(9 << 10)
+#       define R200_TXC_ARG_C_R0_COLOR		(10 << 10)
+#       define R200_TXC_ARG_C_R0_ALPHA		(11 << 10)
+#       define R200_TXC_ARG_C_R1_COLOR		(12 << 10)
+#       define R200_TXC_ARG_C_R1_ALPHA		(13 << 10)
+#       define R200_TXC_ARG_C_R2_COLOR		(14 << 10)
+#       define R200_TXC_ARG_C_R2_ALPHA		(15 << 10)
+#       define R200_TXC_ARG_C_R3_COLOR		(16 << 10)
+#       define R200_TXC_ARG_C_R3_ALPHA		(17 << 10)
+#       define R200_TXC_ARG_C_R4_COLOR		(18 << 10)
+#       define R200_TXC_ARG_C_R4_ALPHA		(19 << 10)
+#       define R200_TXC_ARG_C_R5_COLOR		(20 << 10)
+#       define R200_TXC_ARG_C_R5_ALPHA		(21 << 10)
+#       define R200_TXC_ARG_C_TFACTOR1_COLOR	(26 << 10)
+#       define R200_TXC_ARG_C_TFACTOR1_ALPHA	(27 << 10)
+#       define R200_TXC_ARG_C_MASK		(31 << 10)
+#       define R200_TXC_ARG_C_SHIFT		10
+#       define R200_TXC_COMP_ARG_A		(1 << 16)
+#       define R200_TXC_COMP_ARG_A_SHIFT	(16)
+#       define R200_TXC_BIAS_ARG_A		(1 << 17)
+#       define R200_TXC_SCALE_ARG_A		(1 << 18)
+#       define R200_TXC_NEG_ARG_A		(1 << 19)
+#       define R200_TXC_COMP_ARG_B		(1 << 20)
+#       define R200_TXC_COMP_ARG_B_SHIFT	(20)
+#       define R200_TXC_BIAS_ARG_B		(1 << 21)
+#       define R200_TXC_SCALE_ARG_B		(1 << 22)
+#       define R200_TXC_NEG_ARG_B		(1 << 23)
+#       define R200_TXC_COMP_ARG_C		(1 << 24)
+#       define R200_TXC_COMP_ARG_C_SHIFT	(24)
+#       define R200_TXC_BIAS_ARG_C		(1 << 25)
+#       define R200_TXC_SCALE_ARG_C		(1 << 26)
+#       define R200_TXC_NEG_ARG_C		(1 << 27)
+#       define R200_TXC_OP_MADD			(0 << 28)
+#       define R200_TXC_OP_CND0			(2 << 28)
+#       define R200_TXC_OP_LERP			(3 << 28)
+#       define R200_TXC_OP_DOT3			(4 << 28)
+#       define R200_TXC_OP_DOT4			(5 << 28)
+#       define R200_TXC_OP_CONDITIONAL		(6 << 28)
+#       define R200_TXC_OP_DOT2_ADD		(7 << 28)
+#       define R200_TXC_OP_MASK			(7 << 28)
+#define R200_PP_TXCBLEND2_0		0x2f04
+#       define R200_TXC_TFACTOR_SEL_SHIFT	0
+#       define R200_TXC_TFACTOR_SEL_MASK	0x7
+#       define R200_TXC_TFACTOR1_SEL_SHIFT	4
+#       define R200_TXC_TFACTOR1_SEL_MASK	(0x7 << 4)
+#       define R200_TXC_SCALE_SHIFT		8
+#       define R200_TXC_SCALE_MASK		(7 << 8)
+#       define R200_TXC_SCALE_1X		(0 << 8)
+#       define R200_TXC_SCALE_2X		(1 << 8)
+#       define R200_TXC_SCALE_4X		(2 << 8)
+#       define R200_TXC_SCALE_8X		(3 << 8)
+#       define R200_TXC_SCALE_INV2		(5 << 8)
+#       define R200_TXC_SCALE_INV4		(6 << 8)
+#       define R200_TXC_SCALE_INV8		(7 << 8)
+#       define R200_TXC_CLAMP_SHIFT		12
+#       define R200_TXC_CLAMP_MASK		(3 << 12)
+#       define R200_TXC_CLAMP_WRAP		(0 << 12)
+#       define R200_TXC_CLAMP_0_1		(1 << 12)
+#       define R200_TXC_CLAMP_8_8		(2 << 12)
+#       define R200_TXC_OUTPUT_REG_MASK		(7 << 16)
+#       define R200_TXC_OUTPUT_REG_NONE		(0 << 16)
+#       define R200_TXC_OUTPUT_REG_R0		(1 << 16)
+#       define R200_TXC_OUTPUT_REG_R1		(2 << 16)
+#       define R200_TXC_OUTPUT_REG_R2		(3 << 16)
+#       define R200_TXC_OUTPUT_REG_R3		(4 << 16)
+#       define R200_TXC_OUTPUT_REG_R4		(5 << 16)
+#       define R200_TXC_OUTPUT_REG_R5		(6 << 16)
+#       define R200_TXC_OUTPUT_MASK_MASK	(7 << 20)
+#       define R200_TXC_OUTPUT_MASK_RGB		(0 << 20)
+#       define R200_TXC_OUTPUT_MASK_RG		(1 << 20)
+#       define R200_TXC_OUTPUT_MASK_RB		(2 << 20)
+#       define R200_TXC_OUTPUT_MASK_R		(3 << 20)
+#       define R200_TXC_OUTPUT_MASK_GB		(4 << 20)
+#       define R200_TXC_OUTPUT_MASK_G		(5 << 20)
+#       define R200_TXC_OUTPUT_MASK_B		(6 << 20)
+#       define R200_TXC_OUTPUT_MASK_NONE	(7 << 20)
+#       define R200_TXC_REPL_NORMAL		0
+#       define R200_TXC_REPL_RED		1
+#       define R200_TXC_REPL_GREEN		2
+#       define R200_TXC_REPL_BLUE		3
+#       define R200_TXC_REPL_ARG_A_SHIFT	26
+#       define R200_TXC_REPL_ARG_A_MASK		(3 << 26)
+#       define R200_TXC_REPL_ARG_B_SHIFT	28
+#       define R200_TXC_REPL_ARG_B_MASK		(3 << 28)
+#       define R200_TXC_REPL_ARG_C_SHIFT	30
+#       define R200_TXC_REPL_ARG_C_MASK		(3 << 30)
+#define R200_PP_TXABLEND_0			0x2f08
+#       define R200_TXA_ARG_A_ZERO		(0)
+#       define R200_TXA_ARG_A_CURRENT_ALPHA	(2) /* guess */
+#       define R200_TXA_ARG_A_CURRENT_BLUE	(3) /* guess */
+#       define R200_TXA_ARG_A_DIFFUSE_ALPHA	(4)
+#       define R200_TXA_ARG_A_DIFFUSE_BLUE	(5)
+#       define R200_TXA_ARG_A_SPECULAR_ALPHA	(6)
+#       define R200_TXA_ARG_A_SPECULAR_BLUE	(7)
+#       define R200_TXA_ARG_A_TFACTOR_ALPHA	(8)
+#       define R200_TXA_ARG_A_TFACTOR_BLUE	(9)
+#       define R200_TXA_ARG_A_R0_ALPHA		(10)
+#       define R200_TXA_ARG_A_R0_BLUE		(11)
+#       define R200_TXA_ARG_A_R1_ALPHA		(12)
+#       define R200_TXA_ARG_A_R1_BLUE		(13)
+#       define R200_TXA_ARG_A_R2_ALPHA		(14)
+#       define R200_TXA_ARG_A_R2_BLUE		(15)
+#       define R200_TXA_ARG_A_R3_ALPHA		(16)
+#       define R200_TXA_ARG_A_R3_BLUE		(17)
+#       define R200_TXA_ARG_A_R4_ALPHA		(18)
+#       define R200_TXA_ARG_A_R4_BLUE		(19)
+#       define R200_TXA_ARG_A_R5_ALPHA		(20)
+#       define R200_TXA_ARG_A_R5_BLUE		(21)
+#       define R200_TXA_ARG_A_TFACTOR1_ALPHA	(26)
+#       define R200_TXA_ARG_A_TFACTOR1_BLUE	(27)
+#       define R200_TXA_ARG_A_MASK		(31 << 0)
+#       define R200_TXA_ARG_A_SHIFT		0
+#       define R200_TXA_ARG_B_ZERO		(0 << 5)
+#       define R200_TXA_ARG_B_CURRENT_ALPHA	(2 << 5) /* guess */
+#       define R200_TXA_ARG_B_CURRENT_BLUE	(3 << 5) /* guess */
+#       define R200_TXA_ARG_B_DIFFUSE_ALPHA	(4 << 5)
+#       define R200_TXA_ARG_B_DIFFUSE_BLUE	(5 << 5)
+#       define R200_TXA_ARG_B_SPECULAR_ALPHA	(6 << 5)
+#       define R200_TXA_ARG_B_SPECULAR_BLUE	(7 << 5)
+#       define R200_TXA_ARG_B_TFACTOR_ALPHA	(8 << 5)
+#       define R200_TXA_ARG_B_TFACTOR_BLUE	(9 << 5)
+#       define R200_TXA_ARG_B_R0_ALPHA		(10 << 5)
+#       define R200_TXA_ARG_B_R0_BLUE		(11 << 5)
+#       define R200_TXA_ARG_B_R1_ALPHA		(12 << 5)
+#       define R200_TXA_ARG_B_R1_BLUE		(13 << 5)
+#       define R200_TXA_ARG_B_R2_ALPHA		(14 << 5)
+#       define R200_TXA_ARG_B_R2_BLUE		(15 << 5)
+#       define R200_TXA_ARG_B_R3_ALPHA		(16 << 5)
+#       define R200_TXA_ARG_B_R3_BLUE		(17 << 5)
+#       define R200_TXA_ARG_B_R4_ALPHA		(18 << 5)
+#       define R200_TXA_ARG_B_R4_BLUE		(19 << 5)
+#       define R200_TXA_ARG_B_R5_ALPHA		(20 << 5)
+#       define R200_TXA_ARG_B_R5_BLUE		(21 << 5)
+#       define R200_TXA_ARG_B_TFACTOR1_ALPHA	(26 << 5)
+#       define R200_TXA_ARG_B_TFACTOR1_BLUE	(27 << 5)
+#       define R200_TXA_ARG_B_MASK		(31 << 5)
+#       define R200_TXA_ARG_B_SHIFT			5
+#       define R200_TXA_ARG_C_ZERO		(0 << 10)
+#       define R200_TXA_ARG_C_CURRENT_ALPHA	(2 << 10) /* guess */
+#       define R200_TXA_ARG_C_CURRENT_BLUE	(3 << 10) /* guess */
+#       define R200_TXA_ARG_C_DIFFUSE_ALPHA	(4 << 10)
+#       define R200_TXA_ARG_C_DIFFUSE_BLUE	(5 << 10)
+#       define R200_TXA_ARG_C_SPECULAR_ALPHA	(6 << 10)
+#       define R200_TXA_ARG_C_SPECULAR_BLUE	(7 << 10)
+#       define R200_TXA_ARG_C_TFACTOR_ALPHA	(8 << 10)
+#       define R200_TXA_ARG_C_TFACTOR_BLUE	(9 << 10)
+#       define R200_TXA_ARG_C_R0_ALPHA		(10 << 10)
+#       define R200_TXA_ARG_C_R0_BLUE		(11 << 10)
+#       define R200_TXA_ARG_C_R1_ALPHA		(12 << 10)
+#       define R200_TXA_ARG_C_R1_BLUE		(13 << 10)
+#       define R200_TXA_ARG_C_R2_ALPHA		(14 << 10)
+#       define R200_TXA_ARG_C_R2_BLUE		(15 << 10)
+#       define R200_TXA_ARG_C_R3_ALPHA		(16 << 10)
+#       define R200_TXA_ARG_C_R3_BLUE		(17 << 10)
+#       define R200_TXA_ARG_C_R4_ALPHA		(18 << 10)
+#       define R200_TXA_ARG_C_R4_BLUE		(19 << 10)
+#       define R200_TXA_ARG_C_R5_ALPHA		(20 << 10)
+#       define R200_TXA_ARG_C_R5_BLUE		(21 << 10)
+#       define R200_TXA_ARG_C_TFACTOR1_ALPHA	(26 << 10)
+#       define R200_TXA_ARG_C_TFACTOR1_BLUE	(27 << 10)
+#       define R200_TXA_ARG_C_MASK		(31 << 10)
+#       define R200_TXA_ARG_C_SHIFT		10
+#       define R200_TXA_COMP_ARG_A		(1 << 16)
+#       define R200_TXA_COMP_ARG_A_SHIFT	(16)
+#       define R200_TXA_BIAS_ARG_A		(1 << 17)
+#       define R200_TXA_SCALE_ARG_A		(1 << 18)
+#       define R200_TXA_NEG_ARG_A		(1 << 19)
+#       define R200_TXA_COMP_ARG_B		(1 << 20)
+#       define R200_TXA_COMP_ARG_B_SHIFT	(20)
+#       define R200_TXA_BIAS_ARG_B		(1 << 21)
+#       define R200_TXA_SCALE_ARG_B		(1 << 22)
+#       define R200_TXA_NEG_ARG_B		(1 << 23)
+#       define R200_TXA_COMP_ARG_C		(1 << 24)
+#       define R200_TXA_COMP_ARG_C_SHIFT	(24)
+#       define R200_TXA_BIAS_ARG_C		(1 << 25)
+#       define R200_TXA_SCALE_ARG_C		(1 << 26)
+#       define R200_TXA_NEG_ARG_C		(1 << 27)
+#       define R200_TXA_OP_MADD			(0 << 28)
+#       define R200_TXA_OP_CND0			(2 << 28)
+#       define R200_TXA_OP_LERP			(3 << 28)
+#       define R200_TXA_OP_CONDITIONAL		(6 << 28)
+#       define R200_TXA_OP_MASK			(7 << 28)
+#define R200_PP_TXABLEND2_0			0x2f0c
+#       define R200_TXA_TFACTOR_SEL_SHIFT	0
+#       define R200_TXA_TFACTOR_SEL_MASK	0x7
+#       define R200_TXA_TFACTOR1_SEL_SHIFT	4
+#       define R200_TXA_TFACTOR1_SEL_MASK	(0x7 << 4)
+#       define R200_TXA_SCALE_SHIFT		8
+#       define R200_TXA_SCALE_MASK		(7 << 8)
+#       define R200_TXA_SCALE_1X		(0 << 8)
+#       define R200_TXA_SCALE_2X		(1 << 8)
+#       define R200_TXA_SCALE_4X		(2 << 8)
+#       define R200_TXA_SCALE_8X		(3 << 8)
+#       define R200_TXA_SCALE_INV2		(5 << 8)
+#       define R200_TXA_SCALE_INV4		(6 << 8)
+#       define R200_TXA_SCALE_INV8		(7 << 8)
+#       define R200_TXA_CLAMP_SHIFT		12
+#       define R200_TXA_CLAMP_MASK		(3 << 12)
+#       define R200_TXA_CLAMP_WRAP		(0 << 12)
+#       define R200_TXA_CLAMP_0_1		(1 << 12)
+#       define R200_TXA_CLAMP_8_8		(2 << 12)
+#       define R200_TXA_OUTPUT_REG_MASK		(7 << 16)
+#       define R200_TXA_OUTPUT_REG_NONE		(0 << 16)
+#       define R200_TXA_OUTPUT_REG_R0		(1 << 16)
+#       define R200_TXA_OUTPUT_REG_R1		(2 << 16)
+#       define R200_TXA_OUTPUT_REG_R2		(3 << 16)
+#       define R200_TXA_OUTPUT_REG_R3		(4 << 16)
+#       define R200_TXA_OUTPUT_REG_R4		(5 << 16)
+#       define R200_TXA_OUTPUT_REG_R5		(6 << 16)
+#       define R200_TXA_DOT_ALPHA		(1 << 20)
+#       define R200_TXA_REPL_NORMAL		0
+#       define R200_TXA_REPL_RED		1
+#       define R200_TXA_REPL_GREEN		2
+#       define R200_TXA_REPL_ARG_A_SHIFT	26
+#       define R200_TXA_REPL_ARG_A_MASK		(3 << 26)
+#       define R200_TXA_REPL_ARG_B_SHIFT	28
+#       define R200_TXA_REPL_ARG_B_MASK		(3 << 28)
+#       define R200_TXA_REPL_ARG_C_SHIFT	30
+#       define R200_TXA_REPL_ARG_C_MASK		(3 << 30)
+
+#define R200_SE_VTX_FMT_0			0x2088
+#       define R200_VTX_XY			0 /* always have xy */
+#       define R200_VTX_Z0			(1<<0)
+#       define R200_VTX_W0			(1<<1)
+#       define R200_VTX_WEIGHT_COUNT_SHIFT	(2)
+#       define R200_VTX_PV_MATRIX_SEL		(1<<5)
+#       define R200_VTX_N0			(1<<6)
+#       define R200_VTX_POINT_SIZE		(1<<7)
+#       define R200_VTX_DISCRETE_FOG		(1<<8)
+#       define R200_VTX_SHININESS_0		(1<<9)
+#       define R200_VTX_SHININESS_1		(1<<10)
+#       define   R200_VTX_COLOR_NOT_PRESENT	0
+#       define   R200_VTX_PK_RGBA		1
+#       define   R200_VTX_FP_RGB		2
+#       define   R200_VTX_FP_RGBA		3
+#       define   R200_VTX_COLOR_MASK		3
+#       define R200_VTX_COLOR_0_SHIFT		11
+#       define R200_VTX_COLOR_1_SHIFT		13
+#       define R200_VTX_COLOR_2_SHIFT		15
+#       define R200_VTX_COLOR_3_SHIFT		17
+#       define R200_VTX_COLOR_4_SHIFT		19
+#       define R200_VTX_COLOR_5_SHIFT		21
+#       define R200_VTX_COLOR_6_SHIFT		23
+#       define R200_VTX_COLOR_7_SHIFT		25
+#       define R200_VTX_XY1			(1<<28)
+#       define R200_VTX_Z1			(1<<29)
+#       define R200_VTX_W1			(1<<30)
+#       define R200_VTX_N1			(1<<31)
+#define R200_SE_VTX_FMT_1			0x208c
+#       define R200_VTX_TEX0_COMP_CNT_SHIFT	0
+#       define R200_VTX_TEX1_COMP_CNT_SHIFT	3
+#       define R200_VTX_TEX2_COMP_CNT_SHIFT	6
+#       define R200_VTX_TEX3_COMP_CNT_SHIFT	9
+#       define R200_VTX_TEX4_COMP_CNT_SHIFT	12
+#       define R200_VTX_TEX5_COMP_CNT_SHIFT	15
+
+#define R200_SE_TCL_OUTPUT_VTX_FMT_0		0x2090
+#define R200_SE_TCL_OUTPUT_VTX_FMT_1		0x2094
+#define R200_SE_TCL_OUTPUT_VTX_COMP_SEL		0x2250
+#       define R200_OUTPUT_XYZW			(1<<0)
+#       define R200_OUTPUT_COLOR_0		(1<<8)
+#       define R200_OUTPUT_COLOR_1		(1<<9)
+#       define R200_OUTPUT_TEX_0		(1<<16)
+#       define R200_OUTPUT_TEX_1		(1<<17)
+#       define R200_OUTPUT_TEX_2		(1<<18)
+#       define R200_OUTPUT_TEX_3		(1<<19)
+#       define R200_OUTPUT_TEX_4		(1<<20)
+#       define R200_OUTPUT_TEX_5		(1<<21)
+#       define R200_OUTPUT_TEX_MASK		(0x3f<<16)
+#       define R200_OUTPUT_DISCRETE_FOG		(1<<24)
+#       define R200_OUTPUT_PT_SIZE		(1<<25)
+#       define R200_FORCE_INORDER_PROC		(1<<31)
+#define R200_PP_CNTL_X				0x2cc4
+#define R200_PP_TXMULTI_CTL_0			0x2c1c
+#define R200_SE_VTX_STATE_CNTL			0x2180
+#       define R200_UPDATE_USER_COLOR_0_ENA_MASK (1<<16)
+
+				/* Registers for CP and Microcode Engine */
+#define RADEON_CP_ME_RAM_ADDR               0x07d4
+#define RADEON_CP_ME_RAM_RADDR              0x07d8
+#define RADEON_CP_ME_RAM_DATAH              0x07dc
+#define RADEON_CP_ME_RAM_DATAL              0x07e0
+
+#define RADEON_CP_RB_BASE                   0x0700
+#define RADEON_CP_RB_CNTL                   0x0704
+#define RADEON_CP_RB_RPTR_ADDR              0x070c
+#define RADEON_CP_RB_RPTR                   0x0710
+#define RADEON_CP_RB_WPTR                   0x0714
+
+#define RADEON_CP_IB_BASE                   0x0738
+#define RADEON_CP_IB_BUFSZ                  0x073c
+
+#define RADEON_CP_CSQ_CNTL                  0x0740
+#       define RADEON_CSQ_CNT_PRIMARY_MASK     (0xff << 0)
+#       define RADEON_CSQ_PRIDIS_INDDIS        (0    << 28)
+#       define RADEON_CSQ_PRIPIO_INDDIS        (1    << 28)
+#       define RADEON_CSQ_PRIBM_INDDIS         (2    << 28)
+#       define RADEON_CSQ_PRIPIO_INDBM         (3    << 28)
+#       define RADEON_CSQ_PRIBM_INDBM          (4    << 28)
+#       define RADEON_CSQ_PRIPIO_INDPIO        (15   << 28)
+#define RADEON_CP_CSQ_STAT                  0x07f8
+#       define RADEON_CSQ_RPTR_PRIMARY_MASK    (0xff <<  0)
+#       define RADEON_CSQ_WPTR_PRIMARY_MASK    (0xff <<  8)
+#       define RADEON_CSQ_RPTR_INDIRECT_MASK   (0xff << 16)
+#       define RADEON_CSQ_WPTR_INDIRECT_MASK   (0xff << 24)
+#define RADEON_CP_CSQ_ADDR                  0x07f0
+#define RADEON_CP_CSQ_DATA                  0x07f4
+#define RADEON_CP_CSQ_APER_PRIMARY          0x1000
+#define RADEON_CP_CSQ_APER_INDIRECT         0x1300
+
+#define RADEON_CP_RB_WPTR_DELAY             0x0718
+#       define RADEON_PRE_WRITE_TIMER_SHIFT    0
+#       define RADEON_PRE_WRITE_LIMIT_SHIFT    23
+
+#define RADEON_AIC_CNTL                     0x01d0
+#       define RADEON_PCIGART_TRANSLATE_EN     (1 << 0)
+#define RADEON_AIC_LO_ADDR                  0x01dc
+
+
+
+				/* Constants */
+#define RADEON_LAST_FRAME_REG               RADEON_GUI_SCRATCH_REG0
+#define RADEON_LAST_CLEAR_REG               RADEON_GUI_SCRATCH_REG2
+
+
+
+				/* CP packet types */
+#define RADEON_CP_PACKET0                           0x00000000
+#define RADEON_CP_PACKET1                           0x40000000
+#define RADEON_CP_PACKET2                           0x80000000
+#define RADEON_CP_PACKET3                           0xC0000000
+#       define RADEON_CP_PACKET_MASK                0xC0000000
+#       define RADEON_CP_PACKET_COUNT_MASK          0x3fff0000
+#       define RADEON_CP_PACKET_MAX_DWORDS          (1 << 12)
+#       define RADEON_CP_PACKET0_REG_MASK           0x000007ff
+#       define RADEON_CP_PACKET1_REG0_MASK          0x000007ff
+#       define RADEON_CP_PACKET1_REG1_MASK          0x003ff800
+
+#define RADEON_CP_PACKET0_ONE_REG_WR                0x00008000
+
+#define RADEON_CP_PACKET3_NOP                       0xC0001000
+#define RADEON_CP_PACKET3_NEXT_CHAR                 0xC0001900
+#define RADEON_CP_PACKET3_PLY_NEXTSCAN              0xC0001D00
+#define RADEON_CP_PACKET3_SET_SCISSORS              0xC0001E00
+#define RADEON_CP_PACKET3_3D_RNDR_GEN_INDX_PRIM     0xC0002300
+#define RADEON_CP_PACKET3_LOAD_MICROCODE            0xC0002400
+#define RADEON_CP_PACKET3_WAIT_FOR_IDLE             0xC0002600
+#define RADEON_CP_PACKET3_3D_DRAW_VBUF              0xC0002800
+#define RADEON_CP_PACKET3_3D_DRAW_IMMD              0xC0002900
+#define RADEON_CP_PACKET3_3D_DRAW_INDX              0xC0002A00
+#define RADEON_CP_PACKET3_LOAD_PALETTE              0xC0002C00
+#define R200_CP_PACKET3_3D_DRAW_IMMD_2              0xc0003500
+#define RADEON_CP_PACKET3_3D_LOAD_VBPNTR            0xC0002F00
+#define RADEON_CP_PACKET3_CNTL_PAINT                0xC0009100
+#define RADEON_CP_PACKET3_CNTL_BITBLT               0xC0009200
+#define RADEON_CP_PACKET3_CNTL_SMALLTEXT            0xC0009300
+#define RADEON_CP_PACKET3_CNTL_HOSTDATA_BLT         0xC0009400
+#define RADEON_CP_PACKET3_CNTL_POLYLINE             0xC0009500
+#define RADEON_CP_PACKET3_CNTL_POLYSCANLINES        0xC0009800
+#define RADEON_CP_PACKET3_CNTL_PAINT_MULTI          0xC0009A00
+#define RADEON_CP_PACKET3_CNTL_BITBLT_MULTI         0xC0009B00
+#define RADEON_CP_PACKET3_CNTL_TRANS_BITBLT         0xC0009C00
+
+
+#define RADEON_CP_VC_FRMT_XY                        0x00000000
+#define RADEON_CP_VC_FRMT_W0                        0x00000001
+#define RADEON_CP_VC_FRMT_FPCOLOR                   0x00000002
+#define RADEON_CP_VC_FRMT_FPALPHA                   0x00000004
+#define RADEON_CP_VC_FRMT_PKCOLOR                   0x00000008
+#define RADEON_CP_VC_FRMT_FPSPEC                    0x00000010
+#define RADEON_CP_VC_FRMT_FPFOG                     0x00000020
+#define RADEON_CP_VC_FRMT_PKSPEC                    0x00000040
+#define RADEON_CP_VC_FRMT_ST0                       0x00000080
+#define RADEON_CP_VC_FRMT_ST1                       0x00000100
+#define RADEON_CP_VC_FRMT_Q1                        0x00000200
+#define RADEON_CP_VC_FRMT_ST2                       0x00000400
+#define RADEON_CP_VC_FRMT_Q2                        0x00000800
+#define RADEON_CP_VC_FRMT_ST3                       0x00001000
+#define RADEON_CP_VC_FRMT_Q3                        0x00002000
+#define RADEON_CP_VC_FRMT_Q0                        0x00004000
+#define RADEON_CP_VC_FRMT_BLND_WEIGHT_CNT_MASK      0x00038000
+#define RADEON_CP_VC_FRMT_N0                        0x00040000
+#define RADEON_CP_VC_FRMT_XY1                       0x08000000
+#define RADEON_CP_VC_FRMT_Z1                        0x10000000
+#define RADEON_CP_VC_FRMT_W1                        0x20000000
+#define RADEON_CP_VC_FRMT_N1                        0x40000000
+#define RADEON_CP_VC_FRMT_Z                         0x80000000
+
+#define RADEON_CP_VC_CNTL_PRIM_TYPE_NONE            0x00000000
+#define RADEON_CP_VC_CNTL_PRIM_TYPE_POINT           0x00000001
+#define RADEON_CP_VC_CNTL_PRIM_TYPE_LINE            0x00000002
+#define RADEON_CP_VC_CNTL_PRIM_TYPE_LINE_STRIP      0x00000003
+#define RADEON_CP_VC_CNTL_PRIM_TYPE_TRI_LIST        0x00000004
+#define RADEON_CP_VC_CNTL_PRIM_TYPE_TRI_FAN         0x00000005
+#define RADEON_CP_VC_CNTL_PRIM_TYPE_TRI_STRIP       0x00000006
+#define RADEON_CP_VC_CNTL_PRIM_TYPE_TRI_TYPE_2      0x00000007
+#define RADEON_CP_VC_CNTL_PRIM_TYPE_RECT_LIST       0x00000008
+#define RADEON_CP_VC_CNTL_PRIM_TYPE_3VRT_POINT_LIST 0x00000009
+#define RADEON_CP_VC_CNTL_PRIM_TYPE_3VRT_LINE_LIST  0x0000000a
+#define RADEON_CP_VC_CNTL_PRIM_WALK_IND             0x00000010
+#define RADEON_CP_VC_CNTL_PRIM_WALK_LIST            0x00000020
+#define RADEON_CP_VC_CNTL_PRIM_WALK_RING            0x00000030
+#define RADEON_CP_VC_CNTL_COLOR_ORDER_BGRA          0x00000000
+#define RADEON_CP_VC_CNTL_COLOR_ORDER_RGBA          0x00000040
+#define RADEON_CP_VC_CNTL_MAOS_ENABLE               0x00000080
+#define RADEON_CP_VC_CNTL_VTX_FMT_NON_RADEON_MODE   0x00000000
+#define RADEON_CP_VC_CNTL_VTX_FMT_RADEON_MODE       0x00000100
+#define RADEON_CP_VC_CNTL_TCL_DISABLE               0x00000000
+#define RADEON_CP_VC_CNTL_TCL_ENABLE                0x00000200
+#define RADEON_CP_VC_CNTL_NUM_SHIFT                 16
+
+#define RADEON_VS_MATRIX_0_ADDR                   0
+#define RADEON_VS_MATRIX_1_ADDR                   4
+#define RADEON_VS_MATRIX_2_ADDR                   8
+#define RADEON_VS_MATRIX_3_ADDR                  12
+#define RADEON_VS_MATRIX_4_ADDR                  16
+#define RADEON_VS_MATRIX_5_ADDR                  20
+#define RADEON_VS_MATRIX_6_ADDR                  24
+#define RADEON_VS_MATRIX_7_ADDR                  28
+#define RADEON_VS_MATRIX_8_ADDR                  32
+#define RADEON_VS_MATRIX_9_ADDR                  36
+#define RADEON_VS_MATRIX_10_ADDR                 40
+#define RADEON_VS_MATRIX_11_ADDR                 44
+#define RADEON_VS_MATRIX_12_ADDR                 48
+#define RADEON_VS_MATRIX_13_ADDR                 52
+#define RADEON_VS_MATRIX_14_ADDR                 56
+#define RADEON_VS_MATRIX_15_ADDR                 60
+#define RADEON_VS_LIGHT_AMBIENT_ADDR             64
+#define RADEON_VS_LIGHT_DIFFUSE_ADDR             72
+#define RADEON_VS_LIGHT_SPECULAR_ADDR            80
+#define RADEON_VS_LIGHT_DIRPOS_ADDR              88
+#define RADEON_VS_LIGHT_HWVSPOT_ADDR             96
+#define RADEON_VS_LIGHT_ATTENUATION_ADDR        104
+#define RADEON_VS_MATRIX_EYE2CLIP_ADDR          112
+#define RADEON_VS_UCP_ADDR                      116
+#define RADEON_VS_GLOBAL_AMBIENT_ADDR           122
+#define RADEON_VS_FOG_PARAM_ADDR                123
+#define RADEON_VS_EYE_VECTOR_ADDR               124
+
+#define RADEON_SS_LIGHT_DCD_ADDR                  0
+#define RADEON_SS_LIGHT_SPOT_EXPONENT_ADDR        8
+#define RADEON_SS_LIGHT_SPOT_CUTOFF_ADDR         16
+#define RADEON_SS_LIGHT_SPECULAR_THRESH_ADDR     24
+#define RADEON_SS_LIGHT_RANGE_CUTOFF_ADDR        32
+#define RADEON_SS_VERT_GUARD_CLIP_ADJ_ADDR       48
+#define RADEON_SS_VERT_GUARD_DISCARD_ADJ_ADDR    49
+#define RADEON_SS_HORZ_GUARD_CLIP_ADJ_ADDR       50
+#define RADEON_SS_HORZ_GUARD_DISCARD_ADJ_ADDR    51
+#define RADEON_SS_SHININESS                      60
+
+#define RADEON_TV_MASTER_CNTL                    0x0800
+#       define RADEON_TV_ASYNC_RST               (1 <<  0)
+#       define RADEON_CRT_ASYNC_RST              (1 <<  1)
+#       define RADEON_RESTART_PHASE_FIX          (1 <<  3)
+#	define RADEON_TV_FIFO_ASYNC_RST		 (1 <<  4)
+#	define RADEON_VIN_ASYNC_RST		 (1 <<  5)
+#	define RADEON_AUD_ASYNC_RST		 (1 <<  6)
+#	define RADEON_DVS_ASYNC_RST		 (1 <<  7)
+#       define RADEON_CRT_FIFO_CE_EN             (1 <<  9)
+#       define RADEON_TV_FIFO_CE_EN              (1 << 10)
+#       define RADEON_RE_SYNC_NOW_SEL_MASK       (3 << 14)
+#       define RADEON_TVCLK_ALWAYS_ONb           (1 << 30)
+#	define RADEON_TV_ON			 (1 << 31)
+#define RADEON_TV_PRE_DAC_MUX_CNTL               0x0888
+#       define RADEON_Y_RED_EN                   (1 << 0)
+#       define RADEON_C_GRN_EN                   (1 << 1)
+#       define RADEON_CMP_BLU_EN                 (1 << 2)
+#       define RADEON_DAC_DITHER_EN              (1 << 3)
+#       define RADEON_RED_MX_FORCE_DAC_DATA      (6 << 4)
+#       define RADEON_GRN_MX_FORCE_DAC_DATA      (6 << 8)
+#       define RADEON_BLU_MX_FORCE_DAC_DATA      (6 << 12)
+#       define RADEON_TV_FORCE_DAC_DATA_SHIFT    16
+#define RADEON_TV_RGB_CNTL                           0x0804
+#       define RADEON_SWITCH_TO_BLUE		  (1 <<  4)
+#       define RADEON_RGB_DITHER_EN		  (1 <<  5)
+#       define RADEON_RGB_SRC_SEL_MASK		  (3 <<  8)
+#       define RADEON_RGB_SRC_SEL_CRTC1		  (0 <<  8)
+#       define RADEON_RGB_SRC_SEL_RMX		  (1 <<  8)
+#       define RADEON_RGB_SRC_SEL_CRTC2		  (2 <<  8)
+#       define RADEON_RGB_CONVERT_BY_PASS	  (1 << 10)
+#       define RADEON_UVRAM_READ_MARGIN_SHIFT	  16
+#       define RADEON_FIFORAM_FFMACRO_READ_MARGIN_SHIFT	  20
+#	define RADEON_TVOUT_SCALE_EN 		  (1 << 26)
+#define RADEON_TV_SYNC_CNTL                          0x0808
+#       define RADEON_SYNC_OE                     (1 <<  0)
+#       define RADEON_SYNC_OUT                    (1 <<  1)
+#       define RADEON_SYNC_IN                     (1 <<  2)
+#       define RADEON_SYNC_PUB                    (1 <<  3)
+#       define RADEON_SYNC_PD                     (1 <<  4)
+#       define RADEON_TV_SYNC_IO_DRIVE            (1 <<  5)
+#define RADEON_TV_HTOTAL                             0x080c
+#define RADEON_TV_HDISP                              0x0810
+#define RADEON_TV_HSTART                             0x0818
+#define RADEON_TV_HCOUNT                             0x081C
+#define RADEON_TV_VTOTAL                             0x0820
+#define RADEON_TV_VDISP                              0x0824
+#define RADEON_TV_VCOUNT                             0x0828
+#define RADEON_TV_FTOTAL                             0x082c
+#define RADEON_TV_FCOUNT                             0x0830
+#define RADEON_TV_FRESTART                           0x0834
+#define RADEON_TV_HRESTART                           0x0838
+#define RADEON_TV_VRESTART                           0x083c
+#define RADEON_TV_HOST_READ_DATA                     0x0840
+#define RADEON_TV_HOST_WRITE_DATA                    0x0844
+#define RADEON_TV_HOST_RD_WT_CNTL                    0x0848
+#	define RADEON_HOST_FIFO_RD		 (1 << 12)
+#	define RADEON_HOST_FIFO_RD_ACK		 (1 << 13)
+#	define RADEON_HOST_FIFO_WT		 (1 << 14)
+#	define RADEON_HOST_FIFO_WT_ACK		 (1 << 15)
+#define RADEON_TV_VSCALER_CNTL1                      0x084c
+#       define RADEON_UV_INC_MASK                0xffff
+#       define RADEON_UV_INC_SHIFT               0
+#       define RADEON_Y_W_EN			 (1 << 24)
+#       define RADEON_RESTART_FIELD              (1 << 29) /* restart on field 0 */
+#       define RADEON_Y_DEL_W_SIG_SHIFT          26
+#define RADEON_TV_TIMING_CNTL                        0x0850
+#       define RADEON_H_INC_MASK                 0xfff
+#       define RADEON_H_INC_SHIFT                0
+#       define RADEON_REQ_Y_FIRST                (1 << 19)
+#       define RADEON_FORCE_BURST_ALWAYS         (1 << 21)
+#       define RADEON_UV_POST_SCALE_BYPASS       (1 << 23)
+#       define RADEON_UV_OUTPUT_POST_SCALE_SHIFT 24
+#define RADEON_TV_VSCALER_CNTL2                      0x0854
+#       define RADEON_DITHER_MODE                (1 <<  0)
+#       define RADEON_Y_OUTPUT_DITHER_EN         (1 <<  1)
+#       define RADEON_UV_OUTPUT_DITHER_EN        (1 <<  2)
+#       define RADEON_UV_TO_BUF_DITHER_EN        (1 <<  3)
+#define RADEON_TV_Y_FALL_CNTL                        0x0858
+#       define RADEON_Y_FALL_PING_PONG           (1 << 16)
+#       define RADEON_Y_COEF_EN                  (1 << 17)
+#define RADEON_TV_Y_RISE_CNTL                        0x085c
+#       define RADEON_Y_RISE_PING_PONG           (1 << 16)
+#define RADEON_TV_Y_SAW_TOOTH_CNTL                   0x0860
+#define RADEON_TV_UPSAMP_AND_GAIN_CNTL               0x0864
+#	define RADEON_YUPSAMP_EN		 (1 <<  0)
+#	define RADEON_UVUPSAMP_EN		 (1 <<  2)
+#define RADEON_TV_GAIN_LIMIT_SETTINGS                0x0868
+#       define RADEON_Y_GAIN_LIMIT_SHIFT         0
+#       define RADEON_UV_GAIN_LIMIT_SHIFT        16
+#define RADEON_TV_LINEAR_GAIN_SETTINGS               0x086c
+#       define RADEON_Y_GAIN_SHIFT               0
+#       define RADEON_UV_GAIN_SHIFT              16
+#define RADEON_TV_MODULATOR_CNTL1                    0x0870
+#	define RADEON_YFLT_EN			 (1 <<  2)
+#	define RADEON_UVFLT_EN			 (1 <<  3)
+#       define RADEON_ALT_PHASE_EN               (1 <<  6)
+#       define RADEON_SYNC_TIP_LEVEL             (1 <<  7)
+#       define RADEON_BLANK_LEVEL_SHIFT          8
+#       define RADEON_SET_UP_LEVEL_SHIFT         16
+#	define RADEON_SLEW_RATE_LIMIT		 (1 << 23)
+#       define RADEON_CY_FILT_BLEND_SHIFT        28
+#define RADEON_TV_MODULATOR_CNTL2                    0x0874
+#       define RADEON_TV_U_BURST_LEVEL_MASK     0x1ff
+#       define RADEON_TV_V_BURST_LEVEL_MASK     0x1ff
+#       define RADEON_TV_V_BURST_LEVEL_SHIFT    16
+#define RADEON_TV_CRC_CNTL                           0x0890
+#define RADEON_TV_UV_ADR                             0x08ac
+#	define RADEON_MAX_UV_ADR_MASK		 0x000000ff
+#	define RADEON_MAX_UV_ADR_SHIFT		 0
+#	define RADEON_TABLE1_BOT_ADR_MASK	 0x0000ff00
+#	define RADEON_TABLE1_BOT_ADR_SHIFT	 8
+#	define RADEON_TABLE3_TOP_ADR_MASK	 0x00ff0000
+#	define RADEON_TABLE3_TOP_ADR_SHIFT	 16
+#	define RADEON_HCODE_TABLE_SEL_MASK	 0x06000000
+#	define RADEON_HCODE_TABLE_SEL_SHIFT	 25
+#	define RADEON_VCODE_TABLE_SEL_MASK	 0x18000000
+#	define RADEON_VCODE_TABLE_SEL_SHIFT	 27
+#	define RADEON_TV_MAX_FIFO_ADDR		 0x1a7
+#	define RADEON_TV_MAX_FIFO_ADDR_INTERNAL	 0x1ff
+#define RADEON_TV_PLL_FINE_CNTL			     0x0020	/* PLL */
+#define RADEON_TV_PLL_CNTL                           0x0021	/* PLL */
+#       define RADEON_TV_M0LO_MASK               0xff
+#       define RADEON_TV_M0HI_MASK               0x7
+#       define RADEON_TV_M0HI_SHIFT              18
+#       define RADEON_TV_N0LO_MASK               0x1ff
+#       define RADEON_TV_N0LO_SHIFT              8
+#       define RADEON_TV_N0HI_MASK               0x3
+#       define RADEON_TV_N0HI_SHIFT              21
+#       define RADEON_TV_P_MASK                  0xf
+#       define RADEON_TV_P_SHIFT                 24
+#       define RADEON_TV_SLIP_EN                 (1 << 23)
+#       define RADEON_TV_DTO_EN                  (1 << 28)
+#define RADEON_TV_PLL_CNTL1                          0x0022	/* PLL */
+#       define RADEON_TVPLL_RESET                (1 <<  1)
+#       define RADEON_TVPLL_SLEEP                (1 <<  3)
+#       define RADEON_TVPLL_REFCLK_SEL           (1 <<  4)
+#       define RADEON_TVPCP_SHIFT                8
+#       define RADEON_TVPCP_MASK                 (7 << 8)
+#       define RADEON_TVPVG_SHIFT                11
+#       define RADEON_TVPVG_MASK                 (7 << 11)
+#       define RADEON_TVPDC_SHIFT                14
+#       define RADEON_TVPDC_MASK                 (3 << 14)
+#       define RADEON_TVPLL_TEST_DIS             (1 << 31)
+#       define RADEON_TVCLK_SRC_SEL_TVPLL        (1 << 30)
+
+#define RADEON_RS480_UNK_e30			0xe30
+#define RADEON_RS480_UNK_e34			0xe34
+#define RADEON_RS480_UNK_e38			0xe38
+#define RADEON_RS480_UNK_e3c			0xe3c
+
+#define RS690_MC_INDEX				0x78
+#	define RS690_MC_INDEX_MASK		0x1ff
+#	define RS690_MC_INDEX_WR_EN		(1 << 9)
+#	define RS690_MC_INDEX_WR_ACK		0x7f
+#define RS690_MC_DATA				0x7c
+
+#define RS690_MC_FB_LOCATION			0x100
+#define RS690_MC_AGP_LOCATION			0x101
+#define RS690_MC_AGP_BASE			0x102
+#define RS690_MC_STATUS                         0x90
+#define RS690_MC_STATUS_IDLE                     (1 << 0)
+
+#define AVIVO_MC_INDEX						0x0070
+#define R520_MC_STATUS 0x00
+#define R520_MC_STATUS_IDLE (1<<1)
+#define RV515_MC_STATUS 0x08
+#define RV515_MC_STATUS_IDLE (1<<4)
+#define AVIVO_MC_DATA						0x0074
+
+#define RV515_MC_FB_LOCATION 0x1
+#define RV515_MC_AGP_LOCATION 0x2
+#define R520_MC_FB_LOCATION 0x4
+#define R520_MC_AGP_LOCATION 0x5
+
+#define AVIVO_HDP_FB_LOCATION 0x134
+
+#define AVIVO_D1VGA_CONTROL					0x0330
+#       define AVIVO_DVGA_CONTROL_MODE_ENABLE (1<<0)
+#       define AVIVO_DVGA_CONTROL_TIMING_SELECT (1<<8)
+#       define AVIVO_DVGA_CONTROL_SYNC_POLARITY_SELECT (1<<9)
+#       define AVIVO_DVGA_CONTROL_OVERSCAN_TIMING_SELECT (1<<10)
+#       define AVIVO_DVGA_CONTROL_OVERSCAN_COLOR_EN (1<<16)
+#       define AVIVO_DVGA_CONTROL_ROTATE (1<<24)
+#define AVIVO_D2VGA_CONTROL					0x0338
+
+#define AVIVO_EXT1_PPLL_REF_DIV_SRC                             0x400
+#define AVIVO_EXT1_PPLL_REF_DIV                                 0x404
+#define AVIVO_EXT1_PPLL_UPDATE_LOCK                             0x408
+#define AVIVO_EXT1_PPLL_UPDATE_CNTL                             0x40c
+
+#define AVIVO_EXT2_PPLL_REF_DIV_SRC                             0x410
+#define AVIVO_EXT2_PPLL_REF_DIV                                 0x414
+#define AVIVO_EXT2_PPLL_UPDATE_LOCK                             0x418
+#define AVIVO_EXT2_PPLL_UPDATE_CNTL                             0x41c
+
+#define AVIVO_EXT1_PPLL_FB_DIV                                   0x430
+#define AVIVO_EXT2_PPLL_FB_DIV                                   0x434
+
+#define AVIVO_EXT1_PPLL_POST_DIV_SRC                                 0x438
+#define AVIVO_EXT1_PPLL_POST_DIV                                     0x43c
+
+#define AVIVO_EXT2_PPLL_POST_DIV_SRC                                 0x440
+#define AVIVO_EXT2_PPLL_POST_DIV                                     0x444
+
+#define AVIVO_EXT1_PPLL_CNTL                                    0x448
+#define AVIVO_EXT2_PPLL_CNTL                                    0x44c
+
+#define AVIVO_P1PLL_CNTL                                        0x450
+#define AVIVO_P2PLL_CNTL                                        0x454
+#define AVIVO_P1PLL_INT_SS_CNTL                                 0x458
+#define AVIVO_P2PLL_INT_SS_CNTL                                 0x45c
+#define AVIVO_P1PLL_TMDSA_CNTL                                  0x460
+#define AVIVO_P2PLL_LVTMA_CNTL                                  0x464
+
+#define AVIVO_PCLK_CRTC1_CNTL                                   0x480
+#define AVIVO_PCLK_CRTC2_CNTL                                   0x484
+
+#define AVIVO_D1CRTC_H_TOTAL					0x6000
+#define AVIVO_D1CRTC_H_BLANK_START_END                          0x6004
+#define AVIVO_D1CRTC_H_SYNC_A                                   0x6008
+#define AVIVO_D1CRTC_H_SYNC_A_CNTL                              0x600c
+#define AVIVO_D1CRTC_H_SYNC_B                                   0x6010
+#define AVIVO_D1CRTC_H_SYNC_B_CNTL                              0x6014
+
+#define AVIVO_D1CRTC_V_TOTAL					0x6020
+#define AVIVO_D1CRTC_V_BLANK_START_END                          0x6024
+#define AVIVO_D1CRTC_V_SYNC_A                                   0x6028
+#define AVIVO_D1CRTC_V_SYNC_A_CNTL                              0x602c
+#define AVIVO_D1CRTC_V_SYNC_B                                   0x6030
+#define AVIVO_D1CRTC_V_SYNC_B_CNTL                              0x6034
+
+#define AVIVO_D1CRTC_CONTROL                                    0x6080
+#       define AVIVO_CRTC_EN                            (1<<0)
+#define AVIVO_D1CRTC_BLANK_CONTROL                              0x6084
+#define AVIVO_D1CRTC_INTERLACE_CONTROL                          0x6088
+#define AVIVO_D1CRTC_INTERLACE_STATUS                           0x608c
+#define AVIVO_D1CRTC_STEREO_CONTROL                             0x60c4
+
+/* master controls */
+#define AVIVO_DC_CRTC_MASTER_EN                                 0x60f8
+#define AVIVO_DC_CRTC_TV_CONTROL                                0x60fc
+
+#define AVIVO_D1GRPH_ENABLE                                     0x6100
+#define AVIVO_D1GRPH_CONTROL                                    0x6104
+#       define AVIVO_D1GRPH_CONTROL_DEPTH_8BPP          (0<<0)
+#       define AVIVO_D1GRPH_CONTROL_DEPTH_16BPP         (1<<0)
+#       define AVIVO_D1GRPH_CONTROL_DEPTH_32BPP         (2<<0)
+#       define AVIVO_D1GRPH_CONTROL_DEPTH_64BPP         (3<<0)
+
+#       define AVIVO_D1GRPH_CONTROL_8BPP_INDEXED        (0<<8)
+
+#       define AVIVO_D1GRPH_CONTROL_16BPP_ARGB1555      (0<<8)
+#       define AVIVO_D1GRPH_CONTROL_16BPP_RGB565        (1<<8)
+#       define AVIVO_D1GRPH_CONTROL_16BPP_ARGB4444      (2<<8)
+#       define AVIVO_D1GRPH_CONTROL_16BPP_AI88          (3<<8)
+#       define AVIVO_D1GRPH_CONTROL_16BPP_MONO16        (4<<8)
+
+#       define AVIVO_D1GRPH_CONTROL_32BPP_ARGB8888      (0<<8)
+#       define AVIVO_D1GRPH_CONTROL_32BPP_ARGB2101010   (1<<8)
+#       define AVIVO_D1GRPH_CONTROL_32BPP_DIGITAL       (2<<8)
+#       define AVIVO_D1GRPH_CONTROL_32BPP_8B_ARGB2101010 (3<<8)
+
+
+#       define AVIVO_D1GRPH_CONTROL_64BPP_ARGB16161616  (0<<8)
+
+#       define AVIVO_D1GRPH_SWAP_RB                     (1<<16)
+#       define AVIVO_D1GRPH_TILED                       (1<<20)
+#       define AVIVO_D1GRPH_MACRO_ADDRESS_MODE          (1<<21)
+
+#define AVIVO_D1GRPH_LUT_SEL                                    0x6108
+#define AVIVO_D1GRPH_PRIMARY_SURFACE_ADDRESS                    0x6110
+#define AVIVO_D1GRPH_SECONDARY_SURFACE_ADDRESS                  0x6118
+#define AVIVO_D1GRPH_PITCH                                      0x6120
+#define AVIVO_D1GRPH_SURFACE_OFFSET_X                           0x6124
+#define AVIVO_D1GRPH_SURFACE_OFFSET_Y                           0x6128
+#define AVIVO_D1GRPH_X_START                                    0x612c
+#define AVIVO_D1GRPH_Y_START                                    0x6130
+#define AVIVO_D1GRPH_X_END                                      0x6134
+#define AVIVO_D1GRPH_Y_END                                      0x6138
+#define AVIVO_D1GRPH_UPDATE                                     0x6144
+#       define AVIVO_D1GRPH_UPDATE_LOCK                 (1<<16)
+#define AVIVO_D1GRPH_FLIP_CONTROL                               0x6148
+
+#define AVIVO_D1CUR_CONTROL                     0x6400
+#       define AVIVO_D1CURSOR_EN           (1<<0)
+#       define AVIVO_D1CURSOR_MODE_SHIFT  8
+#       define AVIVO_D1CURSOR_MODE_MASK   (0x3<<8)
+#       define AVIVO_D1CURSOR_MODE_24BPP  (0x2)
+#define AVIVO_D1CUR_SURFACE_ADDRESS             0x6408
+#define AVIVO_D1CUR_SIZE                        0x6410
+#define AVIVO_D1CUR_POSITION                    0x6414
+#define AVIVO_D1CUR_HOT_SPOT                    0x6418
+
+#define AVIVO_DC_LUT_RW_SELECT                  0x6480
+#define AVIVO_DC_LUT_RW_MODE                    0x6484
+#define AVIVO_DC_LUT_RW_INDEX                   0x6488
+#define AVIVO_DC_LUT_SEQ_COLOR                  0x648c
+#define AVIVO_DC_LUT_PWL_DATA                   0x6490
+#define AVIVO_DC_LUT_30_COLOR                   0x6494
+#define AVIVO_DC_LUT_READ_PIPE_SELECT           0x6498
+#define AVIVO_DC_LUT_WRITE_EN_MASK              0x649c
+#define AVIVO_DC_LUT_AUTOFILL                   0x64a0
+
+#define AVIVO_DC_LUTA_CONTROL                   0x64c0
+#define AVIVO_DC_LUTA_BLACK_OFFSET_BLUE         0x64c4
+#define AVIVO_DC_LUTA_BLACK_OFFSET_GREEN        0x64c8
+#define AVIVO_DC_LUTA_BLACK_OFFSET_RED          0x64cc
+#define AVIVO_DC_LUTA_WHITE_OFFSET_BLUE         0x64d0
+#define AVIVO_DC_LUTA_WHITE_OFFSET_GREEN        0x64d4
+#define AVIVO_DC_LUTA_WHITE_OFFSET_RED          0x64d8
+
+
+#define AVIVO_D1MODE_DESKTOP_HEIGHT             0x652C
+#define AVIVO_D1MODE_VIEWPORT_START             0x6580
+#define AVIVO_D1MODE_VIEWPORT_SIZE              0x6584
+#define AVIVO_D1MODE_EXT_OVERSCAN_LEFT_RIGHT    0x6588
+#define AVIVO_D1MODE_EXT_OVERSCAN_TOP_BOTTOM    0x658c
+
+#define AVIVO_D1SCL_SCALER_ENABLE               0x6590
+#define AVIVO_D1SCL_SCALER_TAP_CONTROL	 	0x6594
+#define AVIVO_D1SCL_UPDATE                      0x65cc
+#       define AVIVO_D1SCL_UPDATE_LOCK         (1<<16)
+
+/* second crtc */
+#define AVIVO_D2CRTC_H_TOTAL					0x6800
+#define AVIVO_D2CRTC_H_BLANK_START_END                          0x6804
+#define AVIVO_D2CRTC_H_SYNC_A                                   0x6808
+#define AVIVO_D2CRTC_H_SYNC_A_CNTL                              0x680c
+#define AVIVO_D2CRTC_H_SYNC_B                                   0x6810
+#define AVIVO_D2CRTC_H_SYNC_B_CNTL                              0x6814
+
+#define AVIVO_D2CRTC_V_TOTAL					0x6820
+#define AVIVO_D2CRTC_V_BLANK_START_END                          0x6824
+#define AVIVO_D2CRTC_V_SYNC_A                                   0x6828
+#define AVIVO_D2CRTC_V_SYNC_A_CNTL                              0x682c
+#define AVIVO_D2CRTC_V_SYNC_B                                   0x6830
+#define AVIVO_D2CRTC_V_SYNC_B_CNTL                              0x6834
+
+#define AVIVO_D2CRTC_CONTROL                                    0x6880
+#define AVIVO_D2CRTC_BLANK_CONTROL                              0x6884
+#define AVIVO_D2CRTC_INTERLACE_CONTROL                          0x6888
+#define AVIVO_D2CRTC_INTERLACE_STATUS                           0x688c
+#define AVIVO_D2CRTC_STEREO_CONTROL                             0x68c4
+
+#define AVIVO_D2GRPH_ENABLE                                     0x6900
+#define AVIVO_D2GRPH_CONTROL                                    0x6904
+#define AVIVO_D2GRPH_LUT_SEL                                    0x6908
+#define AVIVO_D2GRPH_PRIMARY_SURFACE_ADDRESS                    0x6910
+#define AVIVO_D2GRPH_SECONDARY_SURFACE_ADDRESS                  0x6918
+#define AVIVO_D2GRPH_PITCH                                      0x6920
+#define AVIVO_D2GRPH_SURFACE_OFFSET_X                           0x6924
+#define AVIVO_D2GRPH_SURFACE_OFFSET_Y                           0x6928
+#define AVIVO_D2GRPH_X_START                                    0x692c
+#define AVIVO_D2GRPH_Y_START                                    0x6930
+#define AVIVO_D2GRPH_X_END                                      0x6934
+#define AVIVO_D2GRPH_Y_END                                      0x6938
+#define AVIVO_D2GRPH_UPDATE                                     0x6944
+#define AVIVO_D2GRPH_FLIP_CONTROL                               0x6948
+
+#define AVIVO_D2CUR_CONTROL                     0x6c00
+#define AVIVO_D2CUR_SURFACE_ADDRESS             0x6c08
+#define AVIVO_D2CUR_SIZE                        0x6c10
+#define AVIVO_D2CUR_POSITION                    0x6c14
+
+#define AVIVO_D2MODE_VIEWPORT_START             0x6d80
+#define AVIVO_D2MODE_VIEWPORT_SIZE              0x6d84
+#define AVIVO_D2MODE_EXT_OVERSCAN_LEFT_RIGHT    0x6d88
+#define AVIVO_D2MODE_EXT_OVERSCAN_TOP_BOTTOM    0x6d8c
+
+#define AVIVO_D2SCL_SCALER_ENABLE               0x6d90
+#define AVIVO_D2SCL_SCALER_TAP_CONTROL	 	0x6d94
+
+#define AVIVO_DACA_ENABLE					0x7800
+#	define AVIVO_DAC_ENABLE				(1 << 0)
+#define AVIVO_DACA_SOURCE_SELECT				0x7804
+#       define AVIVO_DAC_SOURCE_CRTC1                   (0 << 0)
+#       define AVIVO_DAC_SOURCE_CRTC2                   (1 << 0)
+#       define AVIVO_DAC_SOURCE_TV                      (2 << 0)
+
+#define AVIVO_DACA_FORCE_OUTPUT_CNTL				0x783c
+# define AVIVO_DACA_FORCE_OUTPUT_CNTL_FORCE_DATA_EN             (1 << 0)
+# define AVIVO_DACA_FORCE_OUTPUT_CNTL_DATA_SEL_SHIFT            (8)
+# define AVIVO_DACA_FORCE_OUTPUT_CNTL_DATA_SEL_BLUE             (1 << 0)
+# define AVIVO_DACA_FORCE_OUTPUT_CNTL_DATA_SEL_GREEN            (1 << 1)
+# define AVIVO_DACA_FORCE_OUTPUT_CNTL_DATA_SEL_RED              (1 << 2)
+# define AVIVO_DACA_FORCE_OUTPUT_CNTL_DATA_ON_BLANKB_ONLY       (1 << 24)
+#define AVIVO_DACA_POWERDOWN					0x7850
+# define AVIVO_DACA_POWERDOWN_POWERDOWN                         (1 << 0)
+# define AVIVO_DACA_POWERDOWN_BLUE                              (1 << 8)
+# define AVIVO_DACA_POWERDOWN_GREEN                             (1 << 16)
+# define AVIVO_DACA_POWERDOWN_RED                               (1 << 24)
+
+#define AVIVO_DACB_ENABLE					0x7a00
+#define AVIVO_DACB_SOURCE_SELECT				0x7a04
+#define AVIVO_DACB_FORCE_OUTPUT_CNTL				0x7a3c
+# define AVIVO_DACB_FORCE_OUTPUT_CNTL_FORCE_DATA_EN             (1 << 0)
+# define AVIVO_DACB_FORCE_OUTPUT_CNTL_DATA_SEL_SHIFT            (8)
+# define AVIVO_DACB_FORCE_OUTPUT_CNTL_DATA_SEL_BLUE             (1 << 0)
+# define AVIVO_DACB_FORCE_OUTPUT_CNTL_DATA_SEL_GREEN            (1 << 1)
+# define AVIVO_DACB_FORCE_OUTPUT_CNTL_DATA_SEL_RED              (1 << 2)
+# define AVIVO_DACB_FORCE_OUTPUT_CNTL_DATA_ON_BLANKB_ONLY       (1 << 24)
+#define AVIVO_DACB_POWERDOWN					0x7a50
+# define AVIVO_DACB_POWERDOWN_POWERDOWN                         (1 << 0)
+# define AVIVO_DACB_POWERDOWN_BLUE                              (1 << 8)
+# define AVIVO_DACB_POWERDOWN_GREEN                             (1 << 16)
+# define AVIVO_DACB_POWERDOWN_RED 
+
+#define AVIVO_TMDSA_CNTL                    0x7880
+#   define AVIVO_TMDSA_CNTL_ENABLE               (1 << 0)
+#   define AVIVO_TMDSA_CNTL_HPD_MASK             (1 << 4)
+#   define AVIVO_TMDSA_CNTL_HPD_SELECT           (1 << 8)
+#   define AVIVO_TMDSA_CNTL_SYNC_PHASE           (1 << 12)
+#   define AVIVO_TMDSA_CNTL_PIXEL_ENCODING       (1 << 16)
+#   define AVIVO_TMDSA_CNTL_DUAL_LINK_ENABLE     (1 << 24)
+#   define AVIVO_TMDSA_CNTL_SWAP                 (1 << 28)
+#define AVIVO_TMDSA_SOURCE_SELECT				0x7884
+/* 78a8 appears to be some kind of (reasonably tolerant) clock?
+ * 78d0 definitely hits the transmitter, definitely clock. */
+/* MYSTERY1 This appears to control dithering? */
+#define AVIVO_TMDSA_BIT_DEPTH_CONTROL		0x7894
+#   define AVIVO_TMDS_BIT_DEPTH_CONTROL_TRUNCATE_EN           (1 << 0)
+#   define AVIVO_TMDS_BIT_DEPTH_CONTROL_TRUNCATE_DEPTH        (1 << 4)
+#   define AVIVO_TMDS_BIT_DEPTH_CONTROL_SPATIAL_DITHER_EN     (1 << 8)
+#   define AVIVO_TMDS_BIT_DEPTH_CONTROL_SPATIAL_DITHER_DEPTH  (1 << 12)
+#   define AVIVO_TMDS_BIT_DEPTH_CONTROL_TEMPORAL_DITHER_EN    (1 << 16)
+#   define AVIVO_TMDS_BIT_DEPTH_CONTROL_TEMPORAL_DITHER_DEPTH (1 << 20)
+#   define AVIVO_TMDS_BIT_DEPTH_CONTROL_TEMPORAL_LEVEL        (1 << 24)
+#   define AVIVO_TMDS_BIT_DEPTH_CONTROL_TEMPORAL_DITHER_RESET (1 << 26)
+#define AVIVO_TMDSA_DCBALANCER_CONTROL                  0x78d0
+#   define AVIVO_TMDSA_DCBALANCER_CONTROL_EN                  (1 << 0)
+#   define AVIVO_TMDSA_DCBALANCER_CONTROL_TEST_EN             (1 << 8)
+#   define AVIVO_TMDSA_DCBALANCER_CONTROL_TEST_IN_SHIFT       (16)
+#   define AVIVO_TMDSA_DCBALANCER_CONTROL_FORCE               (1 << 24)
+#define AVIVO_TMDSA_DATA_SYNCHRONIZATION                0x78d8
+#   define AVIVO_TMDSA_DATA_SYNCHRONIZATION_DSYNSEL           (1 << 0)
+#   define AVIVO_TMDSA_DATA_SYNCHRONIZATION_PFREQCHG          (1 << 8)
+#define AVIVO_TMDSA_CLOCK_ENABLE            0x7900
+#define AVIVO_TMDSA_TRANSMITTER_ENABLE              0x7904
+#   define AVIVO_TMDSA_TRANSMITTER_ENABLE_TX0_ENABLE          (1 << 0)
+#   define AVIVO_TMDSA_TRANSMITTER_ENABLE_LNKC0EN             (1 << 1)
+#   define AVIVO_TMDSA_TRANSMITTER_ENABLE_LNKD00EN            (1 << 2)
+#   define AVIVO_TMDSA_TRANSMITTER_ENABLE_LNKD01EN            (1 << 3)
+#   define AVIVO_TMDSA_TRANSMITTER_ENABLE_LNKD02EN            (1 << 4)
+#   define AVIVO_TMDSA_TRANSMITTER_ENABLE_TX1_ENABLE          (1 << 8)
+#   define AVIVO_TMDSA_TRANSMITTER_ENABLE_LNKD10EN            (1 << 10)
+#   define AVIVO_TMDSA_TRANSMITTER_ENABLE_LNKD11EN            (1 << 11)
+#   define AVIVO_TMDSA_TRANSMITTER_ENABLE_LNKD12EN            (1 << 12)
+#   define AVIVO_TMDSA_TRANSMITTER_ENABLE_TX_ENABLE_HPD_MASK  (1 << 16)
+#   define AVIVO_TMDSA_TRANSMITTER_ENABLE_LNKCEN_HPD_MASK     (1 << 17)
+#   define AVIVO_TMDSA_TRANSMITTER_ENABLE_LNKDEN_HPD_MASK     (1 << 18)
+
+#define AVIVO_TMDSA_TRANSMITTER_CONTROL				0x7910
+#	define AVIVO_TMDSA_TRANSMITTER_CONTROL_PLL_ENABLE	(1 << 0)
+#	define AVIVO_TMDSA_TRANSMITTER_CONTROL_PLL_RESET  	(1 << 1)
+#	define AVIVO_TMDSA_TRANSMITTER_CONTROL_PLL_HPD_MASK_SHIFT	(2)
+#	define AVIVO_TMDSA_TRANSMITTER_CONTROL_IDSCKSEL	        (1 << 4)
+#       define AVIVO_TMDSA_TRANSMITTER_CONTROL_BGSLEEP          (1 << 5)
+#	define AVIVO_TMDSA_TRANSMITTER_CONTROL_PLL_PWRUP_SEQ_EN	(1 << 6)
+#	define AVIVO_TMDSA_TRANSMITTER_CONTROL_TMCLK	        (1 << 8)
+#	define AVIVO_TMDSA_TRANSMITTER_CONTROL_TMCLK_FROM_PADS	(1 << 13)
+#	define AVIVO_TMDSA_TRANSMITTER_CONTROL_TDCLK	        (1 << 14)
+#	define AVIVO_TMDSA_TRANSMITTER_CONTROL_TDCLK_FROM_PADS	(1 << 15)
+#       define AVIVO_TMDSA_TRANSMITTER_CONTROL_CLK_PATTERN_SHIFT (16)
+#	define AVIVO_TMDSA_TRANSMITTER_CONTROL_BYPASS_PLL	(1 << 28)
+#       define AVIVO_TMDSA_TRANSMITTER_CONTROL_USE_CLK_DATA     (1 << 29)
+#	define AVIVO_TMDSA_TRANSMITTER_CONTROL_INPUT_TEST_CLK_SEL	(1 << 31)
+
+#define AVIVO_LVTMA_CNTL					0x7a80
+#   define AVIVO_LVTMA_CNTL_ENABLE               (1 << 0)
+#   define AVIVO_LVTMA_CNTL_HPD_MASK             (1 << 4)
+#   define AVIVO_LVTMA_CNTL_HPD_SELECT           (1 << 8)
+#   define AVIVO_LVTMA_CNTL_SYNC_PHASE           (1 << 12)
+#   define AVIVO_LVTMA_CNTL_PIXEL_ENCODING       (1 << 16)
+#   define AVIVO_LVTMA_CNTL_DUAL_LINK_ENABLE     (1 << 24)
+#   define AVIVO_LVTMA_CNTL_SWAP                 (1 << 28)
+#define AVIVO_LVTMA_SOURCE_SELECT                               0x7a84
+#define AVIVO_LVTMA_COLOR_FORMAT                                0x7a88
+#define AVIVO_LVTMA_BIT_DEPTH_CONTROL                           0x7a94
+#   define AVIVO_LVTMA_BIT_DEPTH_CONTROL_TRUNCATE_EN           (1 << 0)
+#   define AVIVO_LVTMA_BIT_DEPTH_CONTROL_TRUNCATE_DEPTH        (1 << 4)
+#   define AVIVO_LVTMA_BIT_DEPTH_CONTROL_SPATIAL_DITHER_EN     (1 << 8)
+#   define AVIVO_LVTMA_BIT_DEPTH_CONTROL_SPATIAL_DITHER_DEPTH  (1 << 12)
+#   define AVIVO_LVTMA_BIT_DEPTH_CONTROL_TEMPORAL_DITHER_EN    (1 << 16)
+#   define AVIVO_LVTMA_BIT_DEPTH_CONTROL_TEMPORAL_DITHER_DEPTH (1 << 20)
+#   define AVIVO_LVTMA_BIT_DEPTH_CONTROL_TEMPORAL_LEVEL        (1 << 24)
+#   define AVIVO_LVTMA_BIT_DEPTH_CONTROL_TEMPORAL_DITHER_RESET (1 << 26)
+
+
+
+#define AVIVO_LVTMA_DCBALANCER_CONTROL                  0x7ad0
+#   define AVIVO_LVTMA_DCBALANCER_CONTROL_EN                  (1 << 0)
+#   define AVIVO_LVTMA_DCBALANCER_CONTROL_TEST_EN             (1 << 8)
+#   define AVIVO_LVTMA_DCBALANCER_CONTROL_TEST_IN_SHIFT       (16)
+#   define AVIVO_LVTMA_DCBALANCER_CONTROL_FORCE               (1 << 24)
+
+#define AVIVO_LVTMA_DATA_SYNCHRONIZATION                0x78d8
+#   define AVIVO_LVTMA_DATA_SYNCHRONIZATION_DSYNSEL           (1 << 0)
+#   define AVIVO_LVTMA_DATA_SYNCHRONIZATION_PFREQCHG          (1 << 8)
+#define R500_LVTMA_CLOCK_ENABLE			0x7b00
+#define R600_LVTMA_CLOCK_ENABLE			0x7b04
+
+#define R500_LVTMA_TRANSMITTER_ENABLE              0x7b04
+#define R600_LVTMA_TRANSMITTER_ENABLE              0x7b08
+#   define AVIVO_LVTMA_TRANSMITTER_ENABLE_LNKC0EN             (1 << 1)
+#   define AVIVO_LVTMA_TRANSMITTER_ENABLE_LNKD00EN            (1 << 2)
+#   define AVIVO_LVTMA_TRANSMITTER_ENABLE_LNKD01EN            (1 << 3)
+#   define AVIVO_LVTMA_TRANSMITTER_ENABLE_LNKD02EN            (1 << 4)
+#   define AVIVO_LVTMA_TRANSMITTER_ENABLE_LNKD03EN            (1 << 5)
+#   define AVIVO_LVTMA_TRANSMITTER_ENABLE_LNKC1EN             (1 << 9)
+#   define AVIVO_LVTMA_TRANSMITTER_ENABLE_LNKD10EN            (1 << 10)
+#   define AVIVO_LVTMA_TRANSMITTER_ENABLE_LNKD11EN            (1 << 11)
+#   define AVIVO_LVTMA_TRANSMITTER_ENABLE_LNKD12EN            (1 << 12)
+#   define AVIVO_LVTMA_TRANSMITTER_ENABLE_LNKCEN_HPD_MASK     (1 << 17)
+#   define AVIVO_LVTMA_TRANSMITTER_ENABLE_LNKDEN_HPD_MASK     (1 << 18)
+
+#define R500_LVTMA_TRANSMITTER_CONTROL			        0x7b10
+#define R600_LVTMA_TRANSMITTER_CONTROL			        0x7b14
+#	define AVIVO_LVTMA_TRANSMITTER_CONTROL_PLL_ENABLE	  (1 << 0)
+#	define AVIVO_LVTMA_TRANSMITTER_CONTROL_PLL_RESET  	  (1 << 1)
+#	define AVIVO_LVTMA_TRANSMITTER_CONTROL_PLL_HPD_MASK_SHIFT (2)
+#	define AVIVO_LVTMA_TRANSMITTER_CONTROL_IDSCKSEL	          (1 << 4)
+#       define AVIVO_LVTMA_TRANSMITTER_CONTROL_BGSLEEP            (1 << 5)
+#	define AVIVO_LVTMA_TRANSMITTER_CONTROL_PLL_PWRUP_SEQ_EN	  (1 << 6)
+#	define AVIVO_LVTMA_TRANSMITTER_CONTROL_TMCLK	          (1 << 8)
+#	define AVIVO_LVTMA_TRANSMITTER_CONTROL_TMCLK_FROM_PADS	  (1 << 13)
+#	define AVIVO_LVTMA_TRANSMITTER_CONTROL_TDCLK	          (1 << 14)
+#	define AVIVO_LVTMA_TRANSMITTER_CONTROL_TDCLK_FROM_PADS	  (1 << 15)
+#       define AVIVO_LVTMA_TRANSMITTER_CONTROL_CLK_PATTERN_SHIFT  (16)
+#	define AVIVO_LVTMA_TRANSMITTER_CONTROL_BYPASS_PLL	  (1 << 28)
+#       define AVIVO_LVTMA_TRANSMITTER_CONTROL_USE_CLK_DATA       (1 << 29)
+#	define AVIVO_LVTMA_TRANSMITTER_CONTROL_INPUT_TEST_CLK_SEL (1 << 31)
+
+#define R500_LVTMA_PWRSEQ_CNTL						0x7af0
+#define R600_LVTMA_PWRSEQ_CNTL						0x7af4
+#	define AVIVO_LVTMA_PWRSEQ_EN					    (1 << 0)
+#	define AVIVO_LVTMA_PWRSEQ_PLL_ENABLE_MASK			    (1 << 2)
+#	define AVIVO_LVTMA_PWRSEQ_PLL_RESET_MASK			    (1 << 3)
+#	define AVIVO_LVTMA_PWRSEQ_TARGET_STATE				    (1 << 4)
+#	define AVIVO_LVTMA_SYNCEN					    (1 << 8)
+#	define AVIVO_LVTMA_SYNCEN_OVRD					    (1 << 9)
+#	define AVIVO_LVTMA_SYNCEN_POL					    (1 << 10)
+#	define AVIVO_LVTMA_DIGON					    (1 << 16)
+#	define AVIVO_LVTMA_DIGON_OVRD					    (1 << 17)
+#	define AVIVO_LVTMA_DIGON_POL					    (1 << 18)
+#	define AVIVO_LVTMA_BLON						    (1 << 24)
+#	define AVIVO_LVTMA_BLON_OVRD					    (1 << 25)
+#	define AVIVO_LVTMA_BLON_POL					    (1 << 26)
+
+#define R500_LVTMA_PWRSEQ_STATE                        0x7af4
+#define R600_LVTMA_PWRSEQ_STATE                        0x7af8
+#       define AVIVO_LVTMA_PWRSEQ_STATE_TARGET_STATE_R          (1 << 0)
+#       define AVIVO_LVTMA_PWRSEQ_STATE_DIGON                   (1 << 1)
+#       define AVIVO_LVTMA_PWRSEQ_STATE_SYNCEN                  (1 << 2)
+#       define AVIVO_LVTMA_PWRSEQ_STATE_BLON                    (1 << 3)
+#       define AVIVO_LVTMA_PWRSEQ_STATE_DONE                    (1 << 4)
+#       define AVIVO_LVTMA_PWRSEQ_STATE_STATUS_SHIFT            (8)
+
+#define AVIVO_LVDS_BACKLIGHT_CNTL			0x7af8
+#	define AVIVO_LVDS_BACKLIGHT_CNTL_EN			(1 << 0)
+#	define AVIVO_LVDS_BACKLIGHT_LEVEL_MASK		0x0000ff00
+#	define AVIVO_LVDS_BACKLIGHT_LEVEL_SHIFT		8
+
+#define AVIVO_GPIO_0                        0x7e30
+#define AVIVO_GPIO_1                        0x7e40
+#define AVIVO_GPIO_2                        0x7e50
+#define AVIVO_GPIO_3                        0x7e60
+
+#define AVIVO_DC_GPIO_HPD_Y                 0x7e9c
+
+#define AVIVO_I2C_STATUS					0x7d30
+#	define AVIVO_I2C_STATUS_DONE				(1 << 0)
+#	define AVIVO_I2C_STATUS_NACK				(1 << 1)
+#	define AVIVO_I2C_STATUS_HALT				(1 << 2)
+#	define AVIVO_I2C_STATUS_GO				(1 << 3)
+#	define AVIVO_I2C_STATUS_MASK				0x7
+/* If radeon_mm_i2c is to be believed, this is HALT, NACK, and maybe
+ * DONE? */
+#	define AVIVO_I2C_STATUS_CMD_RESET			0x7
+#	define AVIVO_I2C_STATUS_CMD_WAIT			(1 << 3)
+#define AVIVO_I2C_STOP						0x7d34
+#define AVIVO_I2C_START_CNTL				0x7d38
+#	define AVIVO_I2C_START						(1 << 8)
+#	define AVIVO_I2C_CONNECTOR0					(0 << 16)
+#	define AVIVO_I2C_CONNECTOR1					(1 << 16)
+#define R520_I2C_START (1<<0)
+#define R520_I2C_STOP (1<<1)
+#define R520_I2C_RX (1<<2)
+#define R520_I2C_EN (1<<8)
+#define R520_I2C_DDC1 (0<<16)
+#define R520_I2C_DDC2 (1<<16)
+#define R520_I2C_DDC3 (2<<16)
+#define R520_I2C_DDC_MASK (3<<16)
+#define AVIVO_I2C_CONTROL2					0x7d3c
+#	define AVIVO_I2C_7D3C_SIZE_SHIFT			8
+#	define AVIVO_I2C_7D3C_SIZE_MASK				(0xf << 8)
+#define AVIVO_I2C_CONTROL3						0x7d40
+/* Reading is done 4 bytes at a time: read the bottom 8 bits from
+ * 7d44, four times in a row.
+ * Writing is a little more complex.  First write DATA with
+ * 0xnnnnnnzz, then 0xnnnnnnyy, where nnnnnn is some non-deterministic
+ * magic number, zz is, I think, the slave address, and yy is the byte
+ * you want to write. */
+#define AVIVO_I2C_DATA						0x7d44
+#define R520_I2C_ADDR_COUNT_MASK (0x7)
+#define R520_I2C_DATA_COUNT_SHIFT (8)
+#define R520_I2C_DATA_COUNT_MASK (0xF00)
+#define AVIVO_I2C_CNTL						0x7d50
+#	define AVIVO_I2C_EN							(1 << 0)
+#	define AVIVO_I2C_RESET						(1 << 8)
+
+#define R600_MC_VM_FB_LOCATION                                     0x2180
+#define R600_MC_VM_AGP_TOP                                         0x2184
+#define R600_MC_VM_AGP_BOT                                         0x2188
+#define R600_MC_VM_AGP_BASE                                        0x218c
+#define R600_MC_VM_SYSTEM_APERTURE_LOW_ADDR                        0x2190
+#define R600_MC_VM_SYSTEM_APERTURE_HIGH_ADDR                       0x2194
+#define R600_MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR                    0x2198
+
+#define R600_HDP_NONSURFACE_BASE                                0x2c04
+
+#define R600_BUS_CNTL                                           0x5420
+#define R600_CONFIG_CNTL                                        0x5424
+#define R600_CONFIG_MEMSIZE                                     0x5428
+#define R600_CONFIG_F0_BASE                                     0x542C
+#define R600_CONFIG_APER_SIZE                                   0x5430
+
+#define R600_BIOS_0_SCRATCH               0x1724
+#define R600_BIOS_1_SCRATCH               0x1728
+#define R600_BIOS_2_SCRATCH               0x172c
+#define R600_BIOS_3_SCRATCH               0x1730
+#define R600_BIOS_4_SCRATCH               0x1734
+#define R600_BIOS_5_SCRATCH               0x1738
+#define R600_BIOS_6_SCRATCH               0x173c
+#define R600_BIOS_7_SCRATCH               0x1740
+
+#define R300_GB_TILE_CONFIG				0x4018
+#define R300_GB_SELECT				        0x401c
+#define R300_GB_ENABLE				        0x4008
+#define R300_GB_AA_CONFIG				0x4020
+#define R300_GB_MSPOS0				        0x4010
+#define R300_GB_MSPOS1				        0x4014
+
+#define R300_GA_POLY_MODE				0x4288
+#define R300_GA_ROUND_MODE				0x428c
+#define R300_GA_COLOR_CONTROL			        0x4278
+#define R300_GA_OFFSET				        0x4290
+
+#define R300_VAP_CNTL_STATUS				0x2140
+#define R300_VAP_PVS_STATE_FLUSH_REG		        0x2284
+#define R300_VAP_CNTL				        0x2080
+#define R300_VAP_VTE_CNTL				0x20B0
+#define R300_VAP_PSC_SGN_NORM_CNTL		        0x21DC
+#define R300_VAP_PROG_STREAM_CNTL_0		        0x2150
+#define R300_VAP_PROG_STREAM_CNTL_1		        0x2154
+#define R300_VAP_PROG_STREAM_CNTL_EXT_0	                0x21e0
+#define R300_VAP_PROG_STREAM_CNTL_EXT_1	                0x21e4
+#define R300_VAP_PVS_CODE_CNTL_0			0x22D0
+#define R300_VAP_PVS_CODE_CNTL_1			0x22D8
+#define R300_VAP_PVS_VECTOR_INDX_REG		        0x2200
+#define R300_VAP_PVS_VECTOR_DATA_REG		        0x2204
+#define R300_VAP_PVS_FLOW_CNTL_OPC		        0x22DC
+#define R300_VAP_OUT_VTX_FMT_0			        0x2090
+#define R300_VAP_OUT_VTX_FMT_1			        0x2094
+#define R300_VAP_VTX_SIZE				0x20b4
+#define R300_VAP_GB_VERT_CLIP_ADJ		        0x2220
+#define R300_VAP_GB_VERT_DISC_ADJ		        0x2224
+#define R300_VAP_GB_HORZ_CLIP_ADJ		        0x2228
+#define R300_VAP_GB_HORZ_DISC_ADJ		        0x222c
+#define R300_VAP_CLIP_CNTL				0x221c
+
+#define R300_SU_TEX_WRAP				0x42a0
+#define R300_SU_POLY_OFFSET_ENABLE		        0x42b4
+#define R300_SU_CULL_MODE				0x42b8
+#define R300_SU_DEPTH_SCALE				0x42c0
+#define R300_SU_DEPTH_OFFSET			        0x42c4
+
+#define R300_RS_COUNT				        0x4300
+#define R300_RS_IP_0				        0x4310
+#define R300_RS_INST_COUNT				0x4304
+#define R300_RS_INST_0				        0x4330
+
+#define R300_TX_INVALTAGS				0x4100
+#define R300_TX_FILTER0_0				0x4400
+#       define R300_TX_MAG_FILTER_NEAREST               (1 << 9)
+#       define R300_TX_MIN_FILTER_NEAREST               (1 << 11)
+#       define R300_TX_MAG_FILTER_LINEAR                (2 << 9)
+#       define R300_TX_MIN_FILTER_LINEAR                (2 << 11)
+#define R300_TX_FILTER1_0				0x4440
+#define R300_TX_FORMAT0_0				0x4480
+#       define R300_TXWIDTH_SHIFT                       0
+#       define R300_TXHEIGHT_SHIFT                      11
+#       define R300_NUM_LEVELS_SHIFT                    26
+#       define R300_NUM_LEVELS_MASK                     0x
+#       define R300_TXPROJECTED                         (1 << 30)
+#       define R300_TXPITCH_EN                          (1 << 31)
+#define R300_TX_FORMAT1_0				0x44c0
+#	define R300_TX_FORMAT_X8		    0x0
+#	define R300_TX_FORMAT_X16		    0x1
+#	define R300_TX_FORMAT_Y4X4		    0x2
+#	define R300_TX_FORMAT_Y8X8		    0x3
+#	define R300_TX_FORMAT_Y16X16		    0x4
+#	define R300_TX_FORMAT_Z3Y3X2		    0x5
+#	define R300_TX_FORMAT_Z5Y6X5		    0x6
+#	define R300_TX_FORMAT_Z6Y5X5		    0x7
+#	define R300_TX_FORMAT_Z11Y11X10		    0x8
+#	define R300_TX_FORMAT_Z10Y11X11		    0x9
+#	define R300_TX_FORMAT_W4Z4Y4X4		    0xA
+#	define R300_TX_FORMAT_W1Z5Y5X5		    0xB
+#	define R300_TX_FORMAT_W8Z8Y8X8		    0xC
+#	define R300_TX_FORMAT_W2Z10Y10X10	    0xD
+#	define R300_TX_FORMAT_W16Z16Y16X16	    0xE
+#	define R300_TX_FORMAT_DXT1	    	    0xF
+#	define R300_TX_FORMAT_DXT3	    	    0x10
+#	define R300_TX_FORMAT_DXT5	    	    0x11
+#	define R300_TX_FORMAT_D3DMFT_CxV8U8	    0x12     /* no swizzle */
+#	define R300_TX_FORMAT_A8R8G8B8	    	    0x13     /* no swizzle */
+#	define R300_TX_FORMAT_B8G8_B8G8	    	    0x14     /* no swizzle */
+#	define R300_TX_FORMAT_G8R8_G8B8	    	    0x15     /* no swizzle */
+#	define R300_TX_FORMAT_X24_Y8	    	    0x1e
+#	define R300_TX_FORMAT_X32	    	    0x1e
+	/* Floating point formats */
+	/* Note - hardware supports both 16 and 32 bit floating point */
+#	define R300_TX_FORMAT_FL_I16	    	    0x18
+#	define R300_TX_FORMAT_FL_I16A16	    	    0x19
+#	define R300_TX_FORMAT_FL_R16G16B16A16	    0x1A
+#	define R300_TX_FORMAT_FL_I32	    	    0x1B
+#	define R300_TX_FORMAT_FL_I32A32	    	    0x1C
+#	define R300_TX_FORMAT_FL_R32G32B32A32	    0x1D
+	/* alpha modes, convenience mostly */
+	/* if you have alpha, pick constant appropriate to the
+	   number of channels (1 for I8, 2 for I8A8, 4 for R8G8B8A8, etc */
+# 	define R300_TX_FORMAT_ALPHA_1CH		    0x000
+# 	define R300_TX_FORMAT_ALPHA_2CH		    0x200
+# 	define R300_TX_FORMAT_ALPHA_4CH		    0x600
+# 	define R300_TX_FORMAT_ALPHA_NONE	    0xA00
+	/* Swizzling */
+	/* constants */
+#	define R300_TX_FORMAT_X		0
+#	define R300_TX_FORMAT_Y		1
+#	define R300_TX_FORMAT_Z		2
+#	define R300_TX_FORMAT_W		3
+#	define R300_TX_FORMAT_ZERO	4
+#	define R300_TX_FORMAT_ONE	5
+	/* 2.0*Z, everything above 1.0 is set to 0.0 */
+#	define R300_TX_FORMAT_CUT_Z	6
+	/* 2.0*W, everything above 1.0 is set to 0.0 */
+#	define R300_TX_FORMAT_CUT_W	7
+
+#	define R300_TX_FORMAT_B_SHIFT	18
+#	define R300_TX_FORMAT_G_SHIFT	15
+#	define R300_TX_FORMAT_R_SHIFT	12
+#	define R300_TX_FORMAT_A_SHIFT	9
+
+	/* Convenience macro to take care of layout and swizzling */
+#	define R300_EASY_TX_FORMAT(B, G, R, A, FMT)	(		\
+		((R300_TX_FORMAT_##B)<<R300_TX_FORMAT_B_SHIFT)		\
+		| ((R300_TX_FORMAT_##G)<<R300_TX_FORMAT_G_SHIFT)	\
+		| ((R300_TX_FORMAT_##R)<<R300_TX_FORMAT_R_SHIFT)	\
+		| ((R300_TX_FORMAT_##A)<<R300_TX_FORMAT_A_SHIFT)	\
+		| (R300_TX_FORMAT_##FMT)				\
+		)
+
+#define R300_TX_FORMAT2_0				0x4500
+#define R300_TX_OFFSET_0				0x4540
+#       define R300_ENDIAN_SWAP_16_BIT                  (1 << 0)
+#       define R300_ENDIAN_SWAP_32_BIT                  (2 << 0)
+#       define R300_ENDIAN_SWAP_HALF_DWORD              (3 << 0)
+#       define R300_MACRO_TILE                          (1 << 2);
+
+#define R300_TX_ENABLE				        0x4104
+#       define R300_TEX_0_ENABLE                        (1 << 0)
+#       define R300_TEX_1_ENABLE                        (1 << 1)
+
+#define R300_US_W_FMT				        0x46b4
+#define R300_US_OUT_FMT_1				0x46a8
+#define R300_US_OUT_FMT_2				0x46ac
+#define R300_US_OUT_FMT_3				0x46b0
+#define R300_US_OUT_FMT_0				0x46a4
+#define R300_US_CONFIG				        0x4600
+#define R300_US_PIXSIZE				        0x4604
+#define R300_US_CODE_OFFSET				0x4608
+#define R300_US_CODE_ADDR_0				0x4610
+#define R300_US_CODE_ADDR_1				0x4614
+#define R300_US_CODE_ADDR_2				0x4618
+#define R300_US_CODE_ADDR_3				0x461c
+#define R300_US_TEX_INST_0				0x4620
+#define R300_US_ALU_RGB_ADDR_0			        0x46c0
+#define R300_US_ALU_RGB_INST_0			        0x48c0
+#define R300_US_ALU_ALPHA_ADDR_0		        0x47c0
+#define R300_US_ALU_ALPHA_INST_0		        0x49c0
+
+#define R300_FG_DEPTH_SRC				0x4bd8
+#define R300_FG_FOG_BLEND				0x4bc0
+#define R300_FG_ALPHA_FUNC				0x4bd4
+
+#define R300_RB3D_DSTCACHE_CTLSTAT		        0x4e4c
+#define R300_RB3D_ZCACHE_CTLSTAT			0x4f18
+#define R300_WAIT_UNTIL				        0x1720
+#define R300_RB3D_ZSTENCILCNTL			        0x4f04
+#define R300_RB3D_ZCACHE_CTLSTAT		        0x4f18
+#define R300_RB3D_BW_CNTL				0x4f1c
+#define R300_RB3D_ZCNTL				        0x4f00
+#define R300_RB3D_ZTOP				        0x4f14
+#define R300_RB3D_ROPCNTL				0x4e18
+#define R300_RB3D_BLENDCNTL				0x4e04
+#define R300_RB3D_ABLENDCNTL			        0x4e08
+#define R300_RB3D_DSTCACHE_CTLSTAT		        0x4e4c
+#define R300_RB3D_COLOROFFSET0			        0x4e28
+#define R300_RB3D_COLORPITCH0			        0x4e38
+#       define R300_COLORTILE                           (1 << 16)
+#       define R300_COLORENDIAN_WORD                    (1 << 19)
+#       define R300_COLORENDIAN_DWORD                   (2 << 19)
+#       define R300_COLORENDIAN_HALF_DWORD              (3 << 19)
+#       define R300_COLORFORMAT_ARGB1555                (3 << 21)
+#       define R300_COLORFORMAT_RGB565                  (4 << 21)
+#       define R300_COLORFORMAT_ARGB8888                (6 << 21)
+#       define R300_COLORFORMAT_ARGB32323232            (7 << 21)
+#       define R300_COLORFORMAT_I8                      (9 << 21)
+#       define R300_COLORFORMAT_ARGB16161616            (10 << 21)
+#       define R300_COLORFORMAT_VYUY                    (11 << 21)
+#       define R300_COLORFORMAT_YVYU                    (12 << 21)
+#       define R300_COLORFORMAT_UV88                    (13 << 21)
+#       define R300_COLORFORMAT_ARGB4444                (15 << 21)
+
+#define R300_RB3D_AARESOLVE_CTL			        0x4e88
+#define R300_RB3D_COLOR_CHANNEL_MASK	                0x4e0c
+#define R300_RB3D_COLOR_CLEAR_VALUE                     0x4e14
+#define R300_RB3D_DSTCACHE_CTLSTAT		        0x4e4c
+#define R300_RB3D_CCTL				        0x4e00
+#define R300_RB3D_DITHER_CTL			        0x4e50
+
+#define R300_SC_EDGERULE				0x43a8
+#define R300_SC_SCISSOR0				0x43e0
+#define R300_SC_SCISSOR1				0x43e4
+#define R300_SC_CLIP_0_A				0x43b0
+#define R300_SC_CLIP_0_B				0x43b4
+#define R300_SC_CLIP_RULE				0x43d0
+#define R300_SC_SCREENDOOR				0x43e8
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/app/gfx-utils/sun-src/vts/efb/tools.c	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,339 @@
+
+/*
+ * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 <sys/types.h>
+#include <stdio.h>
+#include <sys/mman.h>
+
+#include "gfx_common.h"		/* GFX Common definitions */
+#include "graphicstest.h"
+#include "libvtsSUNWefb.h"	/* Common VTS library definitions */
+
+#include "X11/Xlib.h"
+#include "gfx_vts.h"		/* VTS Graphics Test common routines */
+#include "efb.h"
+
+
+int
+efb_get_pci_info(int fd, struct pci_info *pciInfo)
+{
+	struct gfx_pci_cfg pciCfg;
+	int i;
+	unsigned int bar;
+
+	if (ioctl(fd, GFX_IOCTL_GET_PCI_CONFIG, &pciCfg) == -1) {
+		return -1;
+	}
+
+        pciInfo->deviceID = pciCfg.DeviceID;
+
+	for (i = 0; i < 6; i++) {
+	    bar = pciCfg.bar[i];
+	    if (bar != 0) {
+		if (bar & PCI_MAP_IO) {
+		    pciInfo->ioBase[i] = PCIGETIO(bar);
+		    pciInfo->type[i] = bar & PCI_MAP_IO_ATTR_MASK;
+		} else {
+		    pciInfo->type[i] = bar & PCI_MAP_MEMORY_ATTR_MASK;
+		    pciInfo->memBase[i] = PCIGETMEMORY(bar);
+		    if (PCI_MAP_IS64BITMEM(bar)) {
+			if (i == 5) {
+			    pciInfo->memBase[i] = 0;
+			} else {
+			    int bar_hi = pciCfg.bar[i+1];
+			    pciInfo->memBase[i] |= (bar_hi << 32);
+			    ++i;
+			}
+		    }
+		    pciInfo->size[i] = EFB_REG_SIZE_LOG2;
+		}
+	    }
+	}
+
+	return 0;
+}
+
+int
+efb_get_mem_info(struct pci_info *pci_info, struct efb_info *pEFB) 
+{
+	unsigned char reg;
+
+	pEFB->FBPhysAddr = pci_info->memBase[0] & 0xfff00000;
+	pEFB->FBMapSize = 0;
+
+	pEFB->MMIOPhysAddr = pci_info->memBase[2] & 0xffff0000;
+	pEFB->MMIOMapSize =  1 << pci_info->size[2];
+
+	pEFB->RelocateIO = pci_info->ioBase[1];
+
+	pEFB->ChipSet = pci_info->deviceID;
+
+#ifdef DEBUG
+	printf("FBPhysAddr=0x%x FBMapSize=0x%x\n", pEFB->FBPhysAddr, pEFB->FBMapSize);
+	printf("MMIOPhysAddr=0x%x MMIOMapSize=0x%x\n", pEFB->MMIOPhysAddr, pEFB->MMIOMapSize);
+	printf("RelocateIO=0x%x\n", pEFB->RelocateIO);
+#endif
+
+	return 0;
+}
+
+
+int
+efb_init_info(struct efb_info *pEFB)
+{
+	unsigned int v, v2;
+	unsigned int status = 0;
+
+        
+#if 0
+	/* 
+	 * first check if the hardware is already initialized.
+	 * If not, abort
+	 */
+	ioctl(pEFB->fd, EFB_GET_STATUS_FLAGS, &status);
+	if (!(status & EFB_STATUS_HW_INITIALIZED))
+		return -1;
+#endif
+
+
+        v = REGR(CRTC_GEN_CNTL);
+	v2 = (v & CRTC_GEN_CNTL__CRTC_PIX_WIDTH_MASK) >> CRTC_GEN_CNTL__CRTC_PIX_WIDTH__SHIFT;
+	if (v2 <= 2)
+        	pEFB->bitsPerPixel = 8;
+	else if (v2 <= 4)
+		pEFB->bitsPerPixel = 16;
+	else 
+		pEFB->bitsPerPixel = 32;
+
+
+        v = REGR(CRTC_H_TOTAL_DISP);
+	v2 = (v & CRTC_H_TOTAL_DISP__CRTC_H_DISP_MASK) >> CRTC_H_TOTAL_DISP__CRTC_H_DISP__SHIFT;
+	pEFB->screenWidth = (v2 + 1) * 8;
+
+        v = REGR(CRTC_V_TOTAL_DISP);
+	v2 = (v & CRTC_V_TOTAL_DISP__CRTC_V_DISP_MASK) >> CRTC_V_TOTAL_DISP__CRTC_V_DISP__SHIFT;
+	pEFB->screenHeight = (v2 + 1);
+	pEFB->screenPitch = pEFB->screenWidth * pEFB->bitsPerPixel / 8;
+
+
+	pEFB->fbLocation = REGR(RADEON_MC_FB_LOCATION);
+
+#ifdef DEBUG
+	printf("bpp=%d width=%d height=%d pitch=%d fbLoc=0x%x\n", 
+		pEFB->bitsPerPixel, pEFB->screenWidth, pEFB->screenHeight, pEFB->screenPitch, 
+		pEFB->fbLocation);
+#endif
+	return 0;
+}
+
+int
+efb_map_mem(struct efb_info *pEFB, return_packet *rp, int test)
+{
+        struct pci_info  pci_info;
+        int              pageSize, size;
+	int		 fd = pEFB->fd;
+
+        if (efb_get_pci_info(fd, &pci_info) == -1) {
+            TraceMessage(VTS_DEBUG, __func__, "get pci info failed\n");
+            gfx_vts_set_message(rp, 1, test, "get pci info failed");
+            return -1;
+        }
+
+
+        if (efb_get_mem_info(&pci_info, pEFB) == -1) {
+            TraceMessage(VTS_DEBUG, __func__, "get mem info failed\n");
+            gfx_vts_set_message(rp, 1, test, "get mem info failed");
+            return -1;
+        }
+
+        /*
+         * Map MMIO
+         */
+        pageSize = getpagesize();
+        size = pEFB->MMIOMapSize + (pageSize - 1) & (~(pageSize - 1));
+
+        pEFB->MMIOvaddr = (unsigned char *)mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED,
+                                        fd, pEFB->MMIOPhysAddr);
+
+        if (pEFB->MMIOvaddr == MAP_FAILED) {
+            TraceMessage(VTS_DEBUG, __func__, "map MMIO failed\n");
+            gfx_vts_set_message(rp, 1, test, "map MMIO failed");
+            return -1;
+        }
+
+
+
+	switch (pEFB->ChipSet) {
+	case 20825:
+	case 20830:
+	case 23396:
+		pEFB->FBMapSize = REGR(RADEON_CONFIG_MEMSIZE);
+		break;
+	default:
+		pEFB->FBMapSize = REGR(R600_CONFIG_MEMSIZE);
+		break;
+	}
+	
+
+        /*
+         * Map framebuffer
+         */
+        pageSize = getpagesize();
+        size = pEFB->FBMapSize + (pageSize - 1) & (~(pageSize - 1));
+
+        pEFB->FBvaddr = (unsigned char *)mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED,
+                                        fd, pEFB->FBPhysAddr);
+
+        if (pEFB->FBvaddr == MAP_FAILED) {
+            TraceMessage(VTS_DEBUG, __func__, "map framebuffer failed\n");
+            gfx_vts_set_message(rp, 1, test, "map framebuffer failed");
+            return -1;
+        }
+
+
+	return 0;
+}
+
+int
+efb_unmap_mem(struct efb_info *pEFB, return_packet *rp, int test)
+{
+        /*
+         * Unmap Frame Buffer
+         */
+
+        if (munmap((void *)pEFB->FBvaddr, pEFB->FBMapSize) == -1) {
+            TraceMessage(VTS_DEBUG, __func__, "unmap framebuffer failed\n");
+            gfx_vts_set_message(rp, 1, test, "unmap framebuffer failed");
+            return -1;
+        }
+
+        if (munmap((void *)pEFB->MMIOvaddr, pEFB->MMIOMapSize) == -1) {
+            TraceMessage(VTS_DEBUG, __func__, "unmap MMIO failed\n");
+            gfx_vts_set_message(rp, 1, test, "unmap MMIO failed");
+            return -1;
+        }
+
+	return 0;
+}
+
+
+#define MASK    RBBM_STATUS__CMDFIFO_AVAIL_MASK
+
+uint32_t
+getBPPValue (int bpp)
+{
+	switch (bpp) {
+            case 8:     return (DST_8BPP);
+            case 15:    return (DST_15BPP);
+            case 16:    return (DST_16BPP);
+            case 32:    return (DST_32BPP);
+            default:    return (0);
+    	}
+}
+
+void 
+efb_flush_pixel_cache(struct efb_info *pEFB)
+{
+	int i ;
+
+	// initiate flush
+	REGW(RADEON_RB2D_DSTCACHE_CTLSTAT, REGR(RADEON_RB2D_DSTCACHE_CTLSTAT) | 0xf);
+
+	// check for completion but limit looping to 16384 reads
+	i = 16384;
+	while((REGR(RADEON_RB2D_DSTCACHE_CTLSTAT) & RADEON_RB2D_DC_BUSY) == RADEON_RB2D_DC_BUSY &&
+                --i >= 0 ) ;
+}
+
+void 
+efb_reset_engine (struct efb_info *pEFB)
+{
+	uint32_t save_genresetcntl, save_clockcntlindex, save_mclkcntl;
+	long term_count;
+
+	efb_flush_pixel_cache(pEFB) ;
+
+	save_clockcntlindex = REGR(RADEON_CLOCK_CNTL_INDEX);
+
+	// save GEN_RESET_CNTL register
+	save_genresetcntl = REGR(RADEON_DISP_MISC_CNTL);
+
+	// reset by setting bit, add read delay, then clear bit, 
+	// add read delay
+	REGW(RADEON_DISP_MISC_CNTL, save_genresetcntl |
+      	     RADEON_DISP_MISC_CNTL__SOFT_RESET_GRPH_PP);
+	REGR(RADEON_DISP_MISC_CNTL);
+	REGW(RADEON_DISP_MISC_CNTL, save_genresetcntl &
+             ~(RADEON_DISP_MISC_CNTL__SOFT_RESET_GRPH_PP));
+	REGR(RADEON_DISP_MISC_CNTL);
+
+	// restore the two registers we changed
+	REGW(RADEON_CLOCK_CNTL_INDEX, save_clockcntlindex);
+	REGW(RADEON_DISP_MISC_CNTL, save_genresetcntl);
+
+	term_count++;     // for monitoring engine hangs
+}
+
+void 
+efb_wait_for_fifo(struct efb_info *pEFB, int c)
+{
+	uint32_t i;
+	long limit;
+
+	/* First a short loop, just in case fifo clears out quickly */
+	for(limit=100; (REGR(RBBM_STATUS) & MASK) < c && --limit > 0; ) ;
+
+	if((REGR(RBBM_STATUS) & MASK) < c ) {
+    		hrtime_t timeout = gethrtime() + (hrtime_t)3000000000;
+            	while((REGR(RBBM_STATUS) & MASK) < c && 
+					gethrtime() < timeout )
+        	    yield();
+
+       	    	if((REGR(RBBM_STATUS) & MASK) < c )
+      	    	    efb_reset_engine(pEFB) ;
+	}
+}
+
+void 
+efb_wait_for_idle(struct efb_info *pEFB)
+{
+	uint32_t i;
+	long limit;
+
+	efb_wait_for_fifo(pEFB, 64) ;
+
+	for(limit=10000; (REGR(RBBM_STATUS) & GUI_ACTIVE) && --limit > 0; ) ;
+
+	if( REGR(RBBM_STATUS) & GUI_ACTIVE ) {
+    	    hrtime_t timeout = gethrtime() + (hrtime_t)3000000000;
+    	    while( (REGR(RBBM_STATUS) & GUI_ACTIVE) && 
+				gethrtime() < timeout )
+        	yield();
+
+            if( (REGR(RBBM_STATUS) & GUI_ACTIVE) != 0 )
+      		efb_reset_engine(pEFB) ;
+	}
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pkg/legacy/SUNWastfbcf.p5m	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,26 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS 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.
+#
+set name=pkg.fmri value=pkg:/[email protected],5.11-0.133
+set name=pkg.renamed value=true
+set name=variant.arch value=sparc
+depend fmri=system/graphics/fbconfig/[email protected] type=require
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pkg/legacy/SUNWefbcf.p5m	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,26 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS 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.
+#
+set name=pkg.fmri value=pkg:/[email protected],5.11-0.133
+set name=pkg.renamed value=true
+set name=variant.arch value=sparc
+depend fmri=system/graphics/fbconfig/[email protected] type=require
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pkg/legacy/SUNWfbc.p5m	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,26 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS 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.
+#
+set name=pkg.fmri value=pkg:/[email protected],5.11-0.133
+set name=pkg.renamed value=true
+set name=variant.arch value=sparc
+depend fmri=system/graphics/[email protected] type=require
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pkg/manifests/system-graphics-fbconfig-fbconfig-ast.p5m	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,38 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS 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.
+#
+set name=pkg.fmri \
+    value=pkg:/system/graphics/fbconfig/fbconfig-ast@$(OSPKGVERS)
+set name=pkg.description \
+    value="Plugins for fbconfig configuration and Oracle VTS diagnostics software for AST graphics"
+set name=pkg.summary \
+    value="AST Graphics Configuration and Diagnostics Software"
+set name=variant.arch value=sparc
+file path=usr/lib/fbconfig/libSUNWast_conf.so.1
+file path=usr/lib/sparcv9/libvtsSUNWast.so.1
+legacy pkg=SUNWastfbcf arch=sparc category=application,graphics \
+    desc="Configuration and diagnostics software for AST graphics" \
+    name="AST Graphics Configuration and Diagnostics Software" \
+    version=11.0.0,REV=2010.10.22
+
+# Requires kernel driver for astfb
+depend fmri=pkg:/driver/graphics/ast type=require
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pkg/manifests/system-graphics-fbconfig-fbconfig-efb.p5m	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,39 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS 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.
+#
+set name=pkg.fmri \
+    value=pkg:/system/graphics/fbconfig/fbconfig-efb@$(OSPKGVERS)
+set name=pkg.description \
+    value="Plugins for fbconfig configuration and Oracle VTS diagnostics software for the Sun XVR-300, XVR-100, and XVR-50 graphics accelerators"
+set name=pkg.summary \
+    value="Sun XVR-300, XVR-100, XVR-50 Graphics Configuration and Diagnostics Software"
+set name=variant.arch value=sparc
+file path=usr/lib/fbconfig/libSUNWefb_conf.so.1
+file path=usr/lib/sparcv9/libvtsSUNWefb.so.1
+legacy pkg=SUNWefbcf arch=sparc category=application,graphics \
+    desc="Configuration software for the Sun XVR-300, XVR-100, XVR-50 graphics accelerator" \
+    hotline="Please contact your local service provider" \
+    name="Sun XVR-300, XVR-100, XVR-50 Graphics Configuration Software" \
+    version=11.0.0,REV=2011.03.15
+
+# Requires kernel driver for efb
+depend fmri=pkg:/driver/graphics/efb type=require
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pkg/manifests/system-graphics-fbconfig.p5m	Mon Apr 25 14:22:03 2011 -0700
@@ -0,0 +1,35 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS 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.
+#
+set name=pkg.fmri value=pkg:/system/graphics/fbconfig@$(OSPKGVERS)
+set name=pkg.description value="Generic frame buffer configuration utility"
+set name=pkg.summary value="Frame Buffer Configuration Utility"
+set name=variant.arch value=sparc
+dir path=usr/lib/fbconfig
+file path=usr/lib/fbconfig/SunModes_xorg.conf
+file path=usr/lib/fbconfig/fbconf_xorg mode=0555
+file path=usr/lib/fbconfig/libfbconf_xorg.so.1
+file path=usr/sbin/fbconfig
+legacy pkg=SUNWfbc arch=sparc category=application,graphics \
+    desc="Generic frame buffer configuration utility" \
+    name="Frame Buffer Configuration Utility" version=11.0.0,REV=2010.08.02
+link path=usr/lib/fbconfig/libfbconf_xorg.so target=libfbconf_xorg.so.1